|
@@ -1,179 +0,0 @@
|
|
|
-package com.fjhx.victoriatourist.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;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.fjhx.kd100.event.Kd100CallbackEvent;
|
|
|
-import com.fjhx.kd100.util.KD100Util;
|
|
|
-import com.fjhx.purchase.entity.purchase.po.Purchase;
|
|
|
-import com.fjhx.purchase.entity.purchase.vo.PurchaseDetailVo;
|
|
|
-import com.fjhx.purchase.service.purchase.PurchaseService;
|
|
|
-import com.fjhx.victoriatourist.entity.logistics.dto.LogisticsInfoDto;
|
|
|
-import com.fjhx.victoriatourist.entity.logistics.dto.LogisticsInfoSelectDto;
|
|
|
-import com.fjhx.victoriatourist.entity.logistics.po.LogisticsDetails;
|
|
|
-import com.fjhx.victoriatourist.entity.logistics.po.LogisticsInfo;
|
|
|
-import com.fjhx.victoriatourist.entity.logistics.vo.LogisticsInfoVo;
|
|
|
-import com.fjhx.victoriatourist.mapper.logistics.MyLogisticsInfoMapper;
|
|
|
-import com.fjhx.victoriatourist.service.logistics.LogisticsDetailsService;
|
|
|
-import com.fjhx.victoriatourist.service.logistics.MyLogisticsInfoService;
|
|
|
-import com.fjhx.victoriatourist.utils.Assert;
|
|
|
-import com.fjhx.victoriatourist.utils.LogisticsConstant;
|
|
|
-import com.obs.services.internal.ServiceException;
|
|
|
-import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.context.event.EventListener;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.function.Function;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-
|
|
|
-/**
|
|
|
- * <p>
|
|
|
- * 物流信息 服务实现类
|
|
|
- * </p>
|
|
|
- *
|
|
|
- * @author
|
|
|
- * @since 2023-04-12
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class MyLogisticsInfoServiceImpl extends ServiceImpl<MyLogisticsInfoMapper, LogisticsInfo> implements MyLogisticsInfoService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- PurchaseService purchaseService;
|
|
|
- @Autowired
|
|
|
- LogisticsDetailsService logisticsDetailsService;
|
|
|
-
|
|
|
- @EventListener
|
|
|
- public void kd100EventListener(Kd100CallbackEvent event) {
|
|
|
- com.fjhx.kd100.entity.logistics.po.LogisticsInfo logisticsInfo = event.getLogisticsInfo();
|
|
|
- //监听物流状态变化
|
|
|
- if (KD100Util.getTableName(LogisticsInfo.class).equals(logisticsInfo.getTableName())) {
|
|
|
- LogisticsInfo byId = getById(logisticsInfo.getBusinessId());
|
|
|
- byId.setLogisticsStatus(logisticsInfo.getState());
|
|
|
- updateById(byId);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Page<LogisticsInfoVo> getPage(LogisticsInfoSelectDto dto) {
|
|
|
- IWrapper<LogisticsInfo> wrapper = getWrapper();
|
|
|
- wrapper.orderByDesc("li", LogisticsInfo::getId);
|
|
|
- Page<LogisticsInfoVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
- return page;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public LogisticsInfoVo detail(Long id) {
|
|
|
- LogisticsInfo LogisticsInfo = this.getById(id);
|
|
|
- LogisticsInfoVo result = BeanUtil.toBean(LogisticsInfo, LogisticsInfoVo.class);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void add(LogisticsInfoDto logisticsInfoDto) {
|
|
|
- Long businessId = logisticsInfoDto.getBusinessId();
|
|
|
- String logisticsCompanyCode = logisticsInfoDto.getLogisticsCompanyCode();
|
|
|
- String code = logisticsInfoDto.getCode();
|
|
|
- List<LogisticsDetails> details = logisticsInfoDto.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();
|
|
|
-
|
|
|
- //根据传入的物流明细列表中的采购明细查 已采购数量/质检合格数量/质检不合格数量
|
|
|
- List<Long> purchaseDetailIds = details.stream().map(LogisticsDetails::getPurchaseDetailId).collect(Collectors.toList());
|
|
|
- IWrapper<LogisticsDetails> wrapper = IWrapper.getWrapper();
|
|
|
- wrapper.in(LogisticsDetails::getPurchaseDetailId, purchaseDetailIds);
|
|
|
- List<PurchaseDetailVo> purchaseDetailVoList = baseMapper.getQualityDetailByPurchaseDetailId(wrapper);
|
|
|
- //根据采购明细id分组
|
|
|
- Map<Long, PurchaseDetailVo> purchaseDetailVoMap = purchaseDetailVoList.stream()
|
|
|
- .collect(Collectors.toMap(PurchaseDetailVo::getId, Function.identity()));
|
|
|
- //遍历物流明细列表检查条件
|
|
|
-
|
|
|
- //获取所有申购id
|
|
|
-// List<Long> applyPurchaseIds = details.stream().map(LogisticsDetails::getApplyPurchaseId).collect(Collectors.toList());
|
|
|
- //查询质检明细信息
|
|
|
-// List<QualityDetailsVo> qualityDetailsByApplyId = qualityDetailsService.getQualityDetailsByApplyId(applyPurchaseIds);
|
|
|
-// Map<Long, QualityDetailsVo> qualityDetailsVoMap = qualityDetailsByApplyId.stream().collect(Collectors.groupingBy(QualityDetailsVo::getApplyId,
|
|
|
-// Collectors.collectingAndThen(Collectors.toList(), value -> value.get(0))));
|
|
|
-//
|
|
|
- details = details.stream()
|
|
|
- .filter(item -> ObjectUtil.defaultIfNull(item.getShipmentQuantity(), BigDecimal.ZERO).compareTo(BigDecimal.ZERO) > 0)
|
|
|
- .peek(item -> {
|
|
|
-// Long applyPurchaseId = item.getApplyPurchaseId();
|
|
|
-// Assert.notEmpty(applyPurchaseId, "申购id不能为空");
|
|
|
-
|
|
|
- //获取质检明细id
|
|
|
- Long purchaseDetailId = item.getPurchaseDetailId();
|
|
|
- Assert.notEmpty(purchaseDetailId, "质检明细id不能为空");
|
|
|
-
|
|
|
-
|
|
|
- //判断发货数量 + SUM(质检合格数量)不能大于“已采购数量”
|
|
|
-// QualityDetailsVo qualityDetailsVo = qualityDetailsVoMap.get(applyPurchaseId);
|
|
|
- PurchaseDetailVo purchaseDetailVo = purchaseDetailVoMap.get(purchaseDetailId);
|
|
|
- //质检合格数量,和已采购数量
|
|
|
- BigDecimal qualifiedQuantity = purchaseDetailVo.getQualifiedCount();
|
|
|
- BigDecimal purchaseQuantity = purchaseDetailVo.getCount();
|
|
|
-// if(ObjectUtil.isNotEmpty(qualityDetailsVo)){
|
|
|
-// if(ObjectUtil.isNotEmpty(qualityDetailsVo.getQualifiedQuantity())) {
|
|
|
-// qualifiedQuantity = qualityDetailsVo.getQualifiedQuantity();
|
|
|
-// }
|
|
|
-// if(ObjectUtil.isNotEmpty(qualityDetailsVo.getPurchaseQuantity())) {
|
|
|
-// purchaseQuantity = qualityDetailsVo.getPurchaseQuantity();
|
|
|
-// }
|
|
|
-// }
|
|
|
- if (item.getShipmentQuantity().add(qualifiedQuantity).compareTo(purchaseQuantity) > 0) {
|
|
|
- throw new ServiceException("发货数量 + 质检合格数量 不能大于“已采购数量”");
|
|
|
- }
|
|
|
-
|
|
|
- item.setLogisticsInfoId(logisticsInfoId);
|
|
|
- item.setLogisticsInfoCode(code);
|
|
|
- item.setReceiptQuantity(BigDecimal.ZERO);
|
|
|
-
|
|
|
- }).collect(Collectors.toList());
|
|
|
- Assert.notEmpty(details, "发货数量全为0");
|
|
|
-
|
|
|
-
|
|
|
- // 物流状态
|
|
|
-// Integer state = KD100Util.getStateAndMonitor(logisticsCompanyCode, code);
|
|
|
- Integer state = KD100Util.monitor(logisticsCompanyCode, code, logisticsInfoId, 1, LogisticsInfo.class).getState();
|
|
|
- logisticsInfoDto.setId(logisticsInfoId);
|
|
|
- logisticsInfoDto.setBusinessType(1);
|
|
|
- logisticsInfoDto.setBusinessCode(purchase.getCode());
|
|
|
- logisticsInfoDto.setLogisticsStatus(state);
|
|
|
- logisticsInfoDto.setStatus(LogisticsConstant.Status.STATUS_0);
|
|
|
- logisticsInfoDto.setInStockStatus(LogisticsConstant.InStockStatus.STATUS_10);
|
|
|
- this.save(logisticsInfoDto);
|
|
|
-
|
|
|
- // 保存明细
|
|
|
- logisticsDetailsService.saveBatch(details);
|
|
|
-//
|
|
|
-// // 保存附件
|
|
|
-// FileClientUtil.bindingFile(logisticsInfoId, logisticsInfoVo.getFileInfos());
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void edit(LogisticsInfoDto logisticsInfoDto) {
|
|
|
- this.updateById(logisticsInfoDto);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void delete(Long id) {
|
|
|
- this.removeById(id);
|
|
|
- }
|
|
|
-
|
|
|
-}
|