|
@@ -1,19 +1,27 @@
|
|
|
package com.fjhx.service.logistics.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.base.BaseIdEntity;
|
|
|
import com.fjhx.constants.logistics.LogisticsConstant;
|
|
|
import com.fjhx.entity.apply.ApplyPurchase;
|
|
|
+import com.fjhx.entity.logistics.LogisticsDetails;
|
|
|
import com.fjhx.entity.logistics.LogisticsInfo;
|
|
|
+import com.fjhx.entity.product.ProductInfo;
|
|
|
import com.fjhx.entity.purchase.Purchase;
|
|
|
import com.fjhx.enums.purchase.PurchaseStatusEnum;
|
|
|
import com.fjhx.mapper.logistics.LogisticsInfoMapper;
|
|
|
import com.fjhx.params.logistics.DeliverDetailsVo;
|
|
|
import com.fjhx.params.logistics.LogisticsInfoVo;
|
|
|
+import com.fjhx.service.apply.ApplyPurchaseService;
|
|
|
import com.fjhx.service.logistics.LogisticsDetailsService;
|
|
|
import com.fjhx.service.logistics.LogisticsInfoService;
|
|
|
+import com.fjhx.service.product.ProductInfoService;
|
|
|
+import com.fjhx.service.purchase.PurchaseService;
|
|
|
import com.fjhx.uitl.kd100.KD100Util;
|
|
|
+import com.fjhx.utils.Assert;
|
|
|
import com.fjhx.utils.FileClientUtil;
|
|
|
import com.fjhx.utils.UserClientUtil;
|
|
|
import com.fjhx.utils.wrapperUtil.IWrapper;
|
|
@@ -42,6 +50,15 @@ public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, L
|
|
|
@Autowired
|
|
|
private LogisticsDetailsService logisticsDetailsService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ApplyPurchaseService applyPurchaseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductInfoService productInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PurchaseService purchaseService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<LogisticsInfo> getPage(Map<String, Object> condition) {
|
|
|
|
|
@@ -90,6 +107,37 @@ public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, L
|
|
|
throw new ServiceException("物流信息不能为空");
|
|
|
}
|
|
|
|
|
|
+ List<LogisticsDetails> details = logisticsInfoVo.getDetails();
|
|
|
+ Assert.notEmpty(details, "发货明细不能为空");
|
|
|
+
|
|
|
+ // 获取已发货数量map<申购单id, 已发货数量>
|
|
|
+ Map<Long, BigDecimal> deliverQuantityMap = logisticsDetailsService.getDeliverQuantityMap(logisticsInfoVo.getBusinessId());
|
|
|
+ // 获取申购数量
|
|
|
+ Map<Long, BigDecimal> applyPurchaseQuantityMap = applyPurchaseService.list(ApplyPurchase::getPurchaseId, logisticsInfoVo.getBusinessId())
|
|
|
+ .stream().collect(Collectors.toMap(BaseIdEntity::getId, ApplyPurchase::getQuantity, BigDecimal::add));
|
|
|
+
|
|
|
+ details = details.stream()
|
|
|
+ .filter(item ->
|
|
|
+ ObjectUtil.isNotEmpty(item.getShipmentQuantity()) && item.getShipmentQuantity().compareTo(BigDecimal.ZERO) > 0
|
|
|
+ ).peek(item -> {
|
|
|
+ Long applyPurchaseId = item.getApplyPurchaseId();
|
|
|
+ Assert.notEmpty(applyPurchaseId, "申购id不能为空");
|
|
|
+
|
|
|
+ // 获取已发货数量
|
|
|
+ BigDecimal deliverQuantity = ObjectUtil.defaultIfNull(deliverQuantityMap.get(applyPurchaseId), BigDecimal.ZERO);
|
|
|
+ // 获取申购数量
|
|
|
+ BigDecimal applyQuantity = ObjectUtil.defaultIfNull(applyPurchaseQuantityMap.get(applyPurchaseId), BigDecimal.ZERO);
|
|
|
+
|
|
|
+ // 判断申购数量是否大于发货数量
|
|
|
+ if (deliverQuantity.add(item.getShipmentQuantity()).compareTo(applyQuantity) > 0) {
|
|
|
+ throw new ServiceException("发货总数量不能大于发货数量");
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Assert.notEmpty(details, "发货数量不能全为0");
|
|
|
+
|
|
|
+
|
|
|
Integer state = -1;
|
|
|
// 查询快递100的物流信息
|
|
|
try {
|
|
@@ -103,21 +151,22 @@ public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, L
|
|
|
// 如果不是已签收状态,则开启订阅(物流状态跟踪并推送)
|
|
|
KD100Util.subscribe(logisticsInfoVo.getLogisticsCompanyCode(), logisticsInfoVo.getCode(), new Date());
|
|
|
}
|
|
|
+
|
|
|
logisticsInfoVo.setLogisticsStatus(state);
|
|
|
logisticsInfoVo.setStatus(LogisticsConstant.Status.STATUS_0);
|
|
|
logisticsInfoVo.setInStockStatus(LogisticsConstant.InStockStatus.STATUS_10);
|
|
|
save(logisticsInfoVo);
|
|
|
|
|
|
- logisticsInfoVo.getDetails().forEach(o -> {
|
|
|
+ details.forEach(o -> {
|
|
|
o.setLogisticsInfoId(logisticsInfoVo.getId());
|
|
|
o.setLogisticsInfoCode(logisticsInfoVo.getCode());
|
|
|
- o.setReceiptQuantity(new BigDecimal(BigDecimal.ZERO.intValue()));
|
|
|
+ o.setReceiptQuantity(BigDecimal.ZERO);
|
|
|
});
|
|
|
|
|
|
//保存附件
|
|
|
FileClientUtil.bindingFile(logisticsInfoVo.getId(), logisticsInfoVo.getFileInfos());
|
|
|
|
|
|
- logisticsDetailsService.saveBatch(logisticsInfoVo.getDetails());
|
|
|
+ logisticsDetailsService.saveBatch(details);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -187,8 +236,74 @@ public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, L
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<DeliverDetailsVo> deliverDetails(Long businessId) {
|
|
|
+ public List<DeliverDetailsVo> deliverDetails(Long id) {
|
|
|
+
|
|
|
+ // 获取采购的产品
|
|
|
+ List<ApplyPurchase> applyPurchaseList = applyPurchaseService.list(q -> q.eq(ApplyPurchase::getPurchaseId, id));
|
|
|
+ if (applyPurchaseList.size() == 0) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 产品id列表
|
|
|
+ List<Long> productIdList = applyPurchaseList.stream().map(ApplyPurchase::getGoodsId).collect(Collectors.toList());
|
|
|
+ // 采购map
|
|
|
+ Map<Long, ProductInfo> productMap = productInfoService.getKEntity(BaseIdEntity::getId, q -> q.in(BaseIdEntity::getId, productIdList));
|
|
|
+
|
|
|
+ // 获取已发货数量
|
|
|
+ Map<Long, BigDecimal> deliverQuantityMap = logisticsDetailsService.getDeliverQuantityMap(id);
|
|
|
+
|
|
|
+ return applyPurchaseList.stream().map(item -> {
|
|
|
+ DeliverDetailsVo deliverDetailsVo = new DeliverDetailsVo();
|
|
|
+
|
|
|
+ // 赋值申购信息
|
|
|
+ deliverDetailsVo.setProductId(item.getGoodsId());
|
|
|
+ deliverDetailsVo.setPurchaseId(item.getPurchaseId());
|
|
|
+ deliverDetailsVo.setApplyPurchaseId(item.getId());
|
|
|
+ deliverDetailsVo.setPurchaseQuantity(item.getQuantity());
|
|
|
+
|
|
|
+ // 赋值产品信息
|
|
|
+ ProductInfo productInfo = productMap.get(item.getGoodsId());
|
|
|
+ if (productInfo != null) {
|
|
|
+ deliverDetailsVo.setProductName(productInfo.getName());
|
|
|
+ deliverDetailsVo.setProductCode(productInfo.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 赋值已发货数量
|
|
|
+ deliverDetailsVo.setDeliverQuantity(ObjectUtil.defaultIfNull(deliverQuantityMap.get(item.getId()), BigDecimal.ZERO));
|
|
|
+ return deliverDetailsVo;
|
|
|
+
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void arrivalNotice(LogisticsInfoVo entity) {
|
|
|
+
|
|
|
+ // 采购id
|
|
|
+ Long purchaseId = entity.getPurchaseId();
|
|
|
+ Assert.notEmpty(purchaseId, "采购id不能为空");
|
|
|
+
|
|
|
+ entity.setStatus(LogisticsConstant.Status.STATUS_1);
|
|
|
+ updateById(entity);
|
|
|
+
|
|
|
+ // // 获取已发货数量
|
|
|
+ // Map<Long, BigDecimal> deliverQuantityMap = logisticsDetailsService.getDeliverQuantityMap(purchaseId);
|
|
|
+ //
|
|
|
+ // List<ApplyPurchase> list = applyPurchaseService.list(q -> q.eq(ApplyPurchase::getPurchaseId, purchaseId));
|
|
|
+ // for (ApplyPurchase applyPurchase : list) {
|
|
|
+ // Long id = applyPurchase.getId();
|
|
|
+ //
|
|
|
+ // // 获取已申购数量
|
|
|
+ // BigDecimal bigDecimal = deliverQuantityMap.get(id);
|
|
|
+ //
|
|
|
+ // }
|
|
|
+
|
|
|
+ // TODO 判断部分到货还是全部到货
|
|
|
+ Purchase purchase = new Purchase();
|
|
|
+ purchase.setId(purchaseId);
|
|
|
+ purchase.setStatus(PurchaseStatusEnum.STATUS_40.getKey());
|
|
|
+ purchaseService.updateById(purchase);
|
|
|
+
|
|
|
|
|
|
- return null;
|
|
|
}
|
|
|
+
|
|
|
}
|