|
@@ -1,6 +1,5 @@
|
|
|
package com.fjhx.service.logistics.impl;
|
|
|
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -20,11 +19,13 @@ import com.fjhx.enums.purchase.PurchaseStatusEnum;
|
|
|
import com.fjhx.enums.stock.InTypeEnum;
|
|
|
import com.fjhx.enums.stock.QualityStatusEnum;
|
|
|
import com.fjhx.mapper.logistics.LogisticsInfoMapper;
|
|
|
-import com.fjhx.params.logistics.*;
|
|
|
+import com.fjhx.params.logistics.DataInfoPageDto;
|
|
|
+import com.fjhx.params.logistics.DataInfoPageVo;
|
|
|
+import com.fjhx.params.logistics.DeliverDetailsVo;
|
|
|
+import com.fjhx.params.logistics.LogisticsInfoVo;
|
|
|
import com.fjhx.params.stock.InStockAdd;
|
|
|
import com.fjhx.params.stock.StockChangeDto;
|
|
|
import com.fjhx.service.apply.ApplyPurchaseService;
|
|
|
-import com.fjhx.service.classify.ClassifyService;
|
|
|
import com.fjhx.service.logistics.LogisticsDetailsService;
|
|
|
import com.fjhx.service.logistics.LogisticsInfoService;
|
|
|
import com.fjhx.service.product.ProductInfoService;
|
|
@@ -84,9 +85,6 @@ public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, L
|
|
|
@Autowired
|
|
|
private QualityDetailsService qualityDetailsService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private ClassifyService classifyService;
|
|
|
-
|
|
|
@Override
|
|
|
public Page<LogisticsInfo> getPage(Map<String, Object> condition) {
|
|
|
|
|
@@ -132,23 +130,32 @@ public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, L
|
|
|
@Transactional(rollbackFor = {Exception.class})
|
|
|
@Override
|
|
|
public void add(LogisticsInfoVo logisticsInfoVo) {
|
|
|
- if (Func.isAnyBlank(logisticsInfoVo.getLogisticsCompanyCode(), logisticsInfoVo.getCode())) {
|
|
|
- throw new ServiceException("物流信息不能为空");
|
|
|
- }
|
|
|
-
|
|
|
+ Long businessId = logisticsInfoVo.getBusinessId();
|
|
|
+ String logisticsCompanyCode = logisticsInfoVo.getLogisticsCompanyCode();
|
|
|
+ String code = logisticsInfoVo.getCode();
|
|
|
List<LogisticsDetails> details = logisticsInfoVo.getDetails();
|
|
|
+
|
|
|
+ Assert.notEmpty(businessId, "业务id不能为空");
|
|
|
+ Assert.notEmpty(logisticsCompanyCode, "物流公司编码不能为空");
|
|
|
+ Assert.notEmpty(code, "物流单号不能为空");
|
|
|
Assert.notEmpty(details, "发货明细不能为空");
|
|
|
|
|
|
+ Purchase purchase = purchaseService.getById(businessId);
|
|
|
+ Assert.notEmpty(purchase, "未知采购id");
|
|
|
+
|
|
|
+ // 物流信息id
|
|
|
+ long logisticsInfoId = IdWorker.getId();
|
|
|
+
|
|
|
// 获取已发货数量map<申购单id, 已发货数量>
|
|
|
- Map<Long, BigDecimal> deliverQuantityMap = logisticsDetailsService.getDeliverQuantityMap(logisticsInfoVo.getBusinessId());
|
|
|
+ Map<Long, BigDecimal> deliverQuantityMap = logisticsDetailsService.getDeliverQuantityMap(businessId);
|
|
|
+
|
|
|
// 获取申购数量
|
|
|
- Map<Long, BigDecimal> applyPurchaseQuantityMap = applyPurchaseService.list(ApplyPurchase::getPurchaseId, logisticsInfoVo.getBusinessId())
|
|
|
+ Map<Long, BigDecimal> applyPurchaseQuantityMap = applyPurchaseService.list(ApplyPurchase::getPurchaseId, businessId)
|
|
|
.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 -> {
|
|
|
+ .filter(item -> ObjectUtil.defaultIfNull(item.getShipmentQuantity(), BigDecimal.ZERO).compareTo(BigDecimal.ZERO) > 0)
|
|
|
+ .peek(item -> {
|
|
|
Long applyPurchaseId = item.getApplyPurchaseId();
|
|
|
Assert.notEmpty(applyPurchaseId, "申购id不能为空");
|
|
|
|
|
@@ -162,26 +169,30 @@ public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, L
|
|
|
throw new ServiceException("发货总数量不能大于发货数量");
|
|
|
}
|
|
|
|
|
|
- })
|
|
|
- .collect(Collectors.toList());
|
|
|
- Assert.notEmpty(details, "发货数量不能全为0");
|
|
|
+ item.setLogisticsInfoId(logisticsInfoId);
|
|
|
+ item.setLogisticsInfoCode(code);
|
|
|
+ item.setReceiptQuantity(BigDecimal.ZERO);
|
|
|
+
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ Assert.notEmpty(details, "发货数量全为0");
|
|
|
+
|
|
|
|
|
|
- Integer state = KD100Util.getStateAndMonitor(logisticsInfoVo.getLogisticsCompanyCode(), logisticsInfoVo.getCode());
|
|
|
+ // 物流状态
|
|
|
+ Integer state = KD100Util.getStateAndMonitor(logisticsCompanyCode, code);
|
|
|
+ logisticsInfoVo.setId(logisticsInfoId);
|
|
|
+ logisticsInfoVo.setBusinessType(1);
|
|
|
+ logisticsInfoVo.setBusinessCode(purchase.getCode());
|
|
|
logisticsInfoVo.setLogisticsStatus(state);
|
|
|
logisticsInfoVo.setStatus(LogisticsConstant.Status.STATUS_0);
|
|
|
logisticsInfoVo.setInStockStatus(LogisticsConstant.InStockStatus.STATUS_10);
|
|
|
save(logisticsInfoVo);
|
|
|
|
|
|
- details.forEach(o -> {
|
|
|
- o.setLogisticsInfoId(logisticsInfoVo.getId());
|
|
|
- o.setLogisticsInfoCode(logisticsInfoVo.getCode());
|
|
|
- o.setReceiptQuantity(BigDecimal.ZERO);
|
|
|
- });
|
|
|
+ // 保存明细
|
|
|
+ logisticsDetailsService.saveBatch(details);
|
|
|
|
|
|
- //保存附件
|
|
|
- FileClientUtil.bindingFile(logisticsInfoVo.getId(), logisticsInfoVo.getFileInfos());
|
|
|
+ // 保存附件
|
|
|
+ FileClientUtil.bindingFile(logisticsInfoId, logisticsInfoVo.getFileInfos());
|
|
|
|
|
|
- logisticsDetailsService.saveBatch(details);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -405,174 +416,27 @@ public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, L
|
|
|
@Override
|
|
|
public Page<DataInfoPageVo> dataInfoPage(DataInfoPageDto dto) {
|
|
|
IWrapper<Object> wrapper = IWrapper.getWrapper(dto);
|
|
|
- return baseMapper.dataInfoPage(dto.getPage(), wrapper);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Page<JdBackPageVo> jdBackPage(JdBackPageDto dto) {
|
|
|
- IWrapper<Object> wrapper = IWrapper.getWrapper(dto)
|
|
|
+ wrapper.eq("sc.business_type", dto.getBusinessType())
|
|
|
.keyword(
|
|
|
- new KeywordData("li", LogisticsInfo::getJdBackOrderId))
|
|
|
- .eq("li", LogisticsInfo::getJdBackStatus, dto.getJdBackStatus());
|
|
|
-
|
|
|
- return baseMapper.jdBackPage(dto.getPage(), wrapper);
|
|
|
+ new KeywordData("sc.business_Code"),
|
|
|
+ new KeywordData("lc.name"),
|
|
|
+ new KeywordData("sc.code")
|
|
|
+ );
|
|
|
+ return baseMapper.dataInfoPage(dto.getPage(), wrapper);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public JdBackDetailsVo jdBackDetails(Long id) {
|
|
|
-
|
|
|
+ public void dataInfoEdit(Long id) {
|
|
|
LogisticsInfo logisticsInfo = getById(id);
|
|
|
+ Assert.notEmpty(logisticsInfo, "没有找到物流信息");
|
|
|
|
|
|
- List<LogisticsDetails> list = logisticsDetailsService.list(q -> q.eq(LogisticsDetails::getLogisticsInfoId, id));
|
|
|
- List<LogisticsDetailsEx> logisticsDetailsExList = BeanUtil.copyToList(list, LogisticsDetailsEx.class);
|
|
|
-
|
|
|
- // 赋值产品编码、名称
|
|
|
- productInfoService.attributeAssign(logisticsDetailsExList, LogisticsDetails::getJdBackProductId, (item, productInfo) -> {
|
|
|
- item.setProductName(productInfo.getName());
|
|
|
- item.setProductCode(productInfo.getCode());
|
|
|
- item.setClassifyId(productInfo.getClassifyId());
|
|
|
- });
|
|
|
-
|
|
|
- // 赋值产品分类
|
|
|
- classifyService.attributeAssign(logisticsDetailsExList, LogisticsDetailsEx::getClassifyId, (item, classify) -> {
|
|
|
- item.setClassifyName(classify.getName());
|
|
|
- });
|
|
|
-
|
|
|
- JdBackDetailsVo jdBackDetailsVo = BeanUtil.toBean(logisticsInfo, JdBackDetailsVo.class);
|
|
|
- jdBackDetailsVo.setLogisticsDetailsList(logisticsDetailsExList);
|
|
|
- return jdBackDetailsVo;
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional(rollbackFor = {Exception.class})
|
|
|
- @Override
|
|
|
- public void jdBackAdd(JdBackAddDto dto) {
|
|
|
-
|
|
|
- List<LogisticsDetails> logisticsDetailsList = dto.getLogisticsDetailsList();
|
|
|
- Assert.notEmpty(logisticsDetailsList, "京东退货明细不能为空");
|
|
|
-
|
|
|
- String code = dto.getCode();
|
|
|
- String logisticsCompanyCode = dto.getLogisticsCompanyCode();
|
|
|
-
|
|
|
- Integer state = null;
|
|
|
- if (ObjectUtil.isAllNotEmpty(code, logisticsCompanyCode)) {
|
|
|
- state = KD100Util.getStateAndMonitor(logisticsCompanyCode, code);
|
|
|
- }
|
|
|
-
|
|
|
- synchronized (this) {
|
|
|
- String jdBackCode = CodeEnum.JD_BACK.getCode();
|
|
|
-
|
|
|
- long id = IdWorker.getId();
|
|
|
-
|
|
|
- int jdBackStatus = 1;
|
|
|
- if (state != null) {
|
|
|
- if (LogisticsConstant.KD100Status.STATUS_3.equals(state)) {
|
|
|
- addJdBackQuality(logisticsDetailsList, dto.getWarehouseId(), id);
|
|
|
- jdBackStatus = 3;
|
|
|
- } else {
|
|
|
- jdBackStatus = 2;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- dto.setId(id);
|
|
|
- dto.setBusinessId(null);
|
|
|
- dto.setBusinessType(4);
|
|
|
- dto.setJdBackCode(jdBackCode);
|
|
|
- dto.setJdBackStatus(jdBackStatus);
|
|
|
- dto.setLogisticsStatus(state);
|
|
|
-
|
|
|
- for (LogisticsDetails logisticsDetails : logisticsDetailsList) {
|
|
|
- logisticsDetails.setLogisticsInfoId(id);
|
|
|
- logisticsDetails.setLogisticsInfoCode(code);
|
|
|
- logisticsDetails.setReceiptQuantity(BigDecimal.ZERO);
|
|
|
- }
|
|
|
-
|
|
|
- save(dto);
|
|
|
- logisticsDetailsService.saveBatch(logisticsDetailsList);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ Integer state = KD100Util.getStateAndMonitor(logisticsInfo.getLogisticsCompanyCode(), logisticsInfo.getCode());
|
|
|
|
|
|
- @Transactional(rollbackFor = {Exception.class})
|
|
|
- @Override
|
|
|
- public void jdBackEdit(JdBackAddDto dto) {
|
|
|
-
|
|
|
- List<LogisticsDetails> logisticsDetailsList = dto.getLogisticsDetailsList();
|
|
|
- Assert.notEmpty(logisticsDetailsList, "京东退货明细不能为空");
|
|
|
-
|
|
|
- LogisticsInfo logisticsInfo = getById(dto.getId());
|
|
|
- Assert.eqTrue(!ObjectUtil.isAllNotEmpty(logisticsInfo.getCode(), logisticsInfo.getLogisticsCompanyCode()), "退货已发起,无法编辑");
|
|
|
-
|
|
|
- String code = dto.getCode();
|
|
|
- String logisticsCompanyCode = dto.getLogisticsCompanyCode();
|
|
|
- Integer state = null;
|
|
|
- if (ObjectUtil.isAllNotEmpty(code, logisticsCompanyCode)) {
|
|
|
- state = KD100Util.getStateAndMonitor(logisticsCompanyCode, code);
|
|
|
- }
|
|
|
-
|
|
|
- synchronized (this) {
|
|
|
-
|
|
|
- int jdBackStatus = 1;
|
|
|
- if (state != null) {
|
|
|
- if (LogisticsConstant.KD100Status.STATUS_3.equals(state)) {
|
|
|
- addJdBackQuality(logisticsDetailsList, dto.getWarehouseId(), dto.getId());
|
|
|
- jdBackStatus = 3;
|
|
|
- } else {
|
|
|
- jdBackStatus = 2;
|
|
|
- }
|
|
|
- }
|
|
|
- dto.setJdBackStatus(jdBackStatus);
|
|
|
- dto.setLogisticsStatus(state);
|
|
|
-
|
|
|
- for (LogisticsDetails logisticsDetails : logisticsDetailsList) {
|
|
|
- logisticsDetails.setLogisticsInfoId(dto.getId());
|
|
|
- logisticsDetails.setLogisticsInfoCode(code);
|
|
|
- logisticsDetails.setReceiptQuantity(BigDecimal.ZERO);
|
|
|
- }
|
|
|
-
|
|
|
- updateById(dto);
|
|
|
- List<Long> notDeleteId = logisticsDetailsList.stream().map(BaseIdEntity::getId).filter(ObjectUtil::isNotEmpty).collect(Collectors.toList());
|
|
|
- if (notDeleteId.size() > 0) {
|
|
|
- logisticsDetailsService.remove(q -> q.eq(LogisticsDetails::getLogisticsInfoId, dto.getId()).notIn(BaseIdEntity::getId, notDeleteId));
|
|
|
- }
|
|
|
- logisticsDetailsService.saveOrUpdateBatch(logisticsDetailsList);
|
|
|
+ if (ObjectUtil.notEqual(state, logisticsInfo.getLogisticsStatus())) {
|
|
|
+ logisticsInfo.setLogisticsStatus(state);
|
|
|
+ updateById(logisticsInfo);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void jdBackDelete(Long id) {
|
|
|
- LogisticsInfo logisticsInfo = getById(id);
|
|
|
- Assert.eqTrue(!ObjectUtil.isAllNotEmpty(logisticsInfo.getCode(), logisticsInfo.getLogisticsCompanyCode()), "退货已发起,无法删除");
|
|
|
-
|
|
|
- removeById(id);
|
|
|
- logisticsDetailsService.remove(LogisticsDetails::getLogisticsInfoId, id);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void addJdBackQuality(List<LogisticsDetails> logisticsDetailsList, Long warehouseId, Long logisticsInfoId) {
|
|
|
- // 添加质检
|
|
|
- QualityInfo qualityInfo = new QualityInfo();
|
|
|
- qualityInfo.setType(2);
|
|
|
- qualityInfo.setCode(CodeEnum.QUALITY.getCode());
|
|
|
- qualityInfo.setStatus(QualityStatusEnum.STATUS_1.getKey());
|
|
|
- qualityInfo.setResultType(StatusConstant.YES);
|
|
|
- qualityInfoService.save(qualityInfo);
|
|
|
-
|
|
|
- // 添加质检明细
|
|
|
- List<QualityDetails> qualityDetailsList = logisticsDetailsList.stream().map(item -> {
|
|
|
- QualityDetails qualityDetails = new QualityDetails();
|
|
|
- qualityDetails.setQualityInfoId(qualityInfo.getId());
|
|
|
- qualityDetails.setLogisticsDetailsId(logisticsInfoId);
|
|
|
- qualityDetails.setProductInfoId(item.getJdBackProductId());
|
|
|
- qualityDetails.setWarehouseId(warehouseId);
|
|
|
- qualityDetails.setTotalQuantity(item.getShipmentQuantity());
|
|
|
- qualityDetails.setQualifiedQuantity(BigDecimal.ZERO);
|
|
|
- qualityDetails.setDisqualificationQuantity(BigDecimal.ZERO);
|
|
|
- return qualityDetails;
|
|
|
- }).collect(Collectors.toList());
|
|
|
-
|
|
|
- qualityDetailsService.saveBatch(qualityDetailsList);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
}
|