|
@@ -25,10 +25,12 @@ import com.sd.business.entity.bom.bo.BomSpecBo;
|
|
|
import com.sd.business.entity.bom.bo.BomSpecOrderConsumptionBo;
|
|
|
import com.sd.business.entity.bom.po.Bom;
|
|
|
import com.sd.business.entity.bom.po.BomSpec;
|
|
|
+import com.sd.business.entity.department.constant.DepartmentConstant;
|
|
|
import com.sd.business.entity.department.po.Department;
|
|
|
import com.sd.business.entity.in.dto.InOutStorageDto;
|
|
|
import com.sd.business.entity.in.emums.InDetailTypeEnum;
|
|
|
import com.sd.business.entity.in.emums.InOutTypeEnum;
|
|
|
+import com.sd.business.entity.in.emums.OutDetailTypeEnum;
|
|
|
import com.sd.business.entity.in.po.InOutStorageBom;
|
|
|
import com.sd.business.entity.inventory.po.Inventory;
|
|
|
import com.sd.business.entity.order.dto.*;
|
|
@@ -42,6 +44,7 @@ import com.sd.business.entity.price.po.PriceBillingStandardDetail;
|
|
|
import com.sd.business.entity.production.po.ProductionWorkOrder;
|
|
|
import com.sd.business.entity.production.vo.OutBomVo;
|
|
|
import com.sd.business.entity.sku.po.SkuSpec;
|
|
|
+import com.sd.business.entity.sku.po.SkuSpecLink;
|
|
|
import com.sd.business.entity.statement.po.StatementOfAccount;
|
|
|
import com.sd.business.entity.statement.vo.StatementOrderClassifyTotalCountVo;
|
|
|
import com.sd.business.entity.warehouse.constant.WarehouseConstant;
|
|
@@ -56,6 +59,7 @@ import com.sd.business.service.order.*;
|
|
|
import com.sd.business.service.price.PriceBillingStandardDetailService;
|
|
|
import com.sd.business.service.price.PriceBillingStandardService;
|
|
|
import com.sd.business.service.production.ProductionWorkOrderService;
|
|
|
+import com.sd.business.service.sku.SkuSpecLinkService;
|
|
|
import com.sd.business.service.sku.SkuSpecService;
|
|
|
import com.sd.business.service.statement.StatementOfAccountService;
|
|
|
import com.sd.business.util.CodeEnum;
|
|
@@ -141,6 +145,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
|
|
|
private ProductionWorkOrderService productionWorkOrderService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private SkuSpecLinkService skuSpecLinkService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private HttpServletResponse response;
|
|
|
|
|
|
@Override
|
|
@@ -1167,6 +1174,183 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<OrderPackageBomVo> getSkuSpecPackageBomList(SkuSpecPackageBomDto dto) {
|
|
|
+ List<SkuSpecPriceDto> skuSpecList = dto.getSkuSpecList();
|
|
|
+ List<Long> skuSpecIds = skuSpecList.stream().map(SkuSpecPriceDto::getSkuSpecId).collect(Collectors.toList());
|
|
|
+ Map<Long, List<SkuSpecLink>> skuSpecMap = skuSpecLinkService.mapKGroup(
|
|
|
+ SkuSpecLink::getSkuSpecId,
|
|
|
+ q -> q.in(SkuSpecLink::getSkuSpecId, skuSpecIds).eq(SkuSpecLink::getType, 2));
|
|
|
+ if (ObjectUtil.isEmpty(skuSpecMap)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<Long> bomSpecIds = skuSpecMap.values().stream()
|
|
|
+ .flatMap(item -> item.stream().map(SkuSpecLink::getBomSpecId))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Map<Long, BomSpec> bomSpecPriceMap = bomSpecService.mapKEntity(
|
|
|
+ BaseIdPo::getId, q -> q.in(BaseIdPo::getId, bomSpecIds));
|
|
|
+
|
|
|
+ List<OrderPackageBomVo> list = new ArrayList<>();
|
|
|
+ for (SkuSpecPriceDto skuSpecPriceDto : skuSpecList) {
|
|
|
+ List<SkuSpecLink> skuSpecLinkList = skuSpecMap.getOrDefault(skuSpecPriceDto.getSkuSpecId(), Collections.emptyList());
|
|
|
+ List<OrderPackageBomVo> packageBomVoList = skuSpecLinkList.stream().map(item -> {
|
|
|
+ BomSpec bomSpec = bomSpecPriceMap.get(item.getBomSpecId());
|
|
|
+ OrderPackageBomVo orderPackageBomVo = new OrderPackageBomVo();
|
|
|
+ orderPackageBomVo.setBomSpecName(bomSpec.getName());
|
|
|
+ orderPackageBomVo.setBomSpecCode(bomSpec.getCode());
|
|
|
+ orderPackageBomVo.setCostPrice(bomSpec.getCostPrice());
|
|
|
+ orderPackageBomVo.setInternalSellingPrice(bomSpec.getInternalSellingPrice());
|
|
|
+ orderPackageBomVo.setBomSpecId(item.getBomSpecId());
|
|
|
+ orderPackageBomVo.setQuantity(item.getQuantity().multiply(skuSpecPriceDto.getQuantity()));
|
|
|
+ return orderPackageBomVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ list.addAll(packageBomVoList);
|
|
|
+ }
|
|
|
+ // 合并相同bom
|
|
|
+ Map<Long, OrderPackageBomVo> bomVoMap = list.stream().collect(Collectors.toMap(
|
|
|
+ OrderPackageBom::getBomSpecId,
|
|
|
+ Function.identity(),
|
|
|
+ (v1, v2) -> {
|
|
|
+ v1.setQuantity(v1.getQuantity().add(v2.getQuantity()));
|
|
|
+ return v1;
|
|
|
+ }));
|
|
|
+ return new ArrayList<>(bomVoMap.values());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void editOrderPackageBom(OrderInfoDto dto) {
|
|
|
+ OrderInfo orderInfo = this.getById(dto.getId());
|
|
|
+ if (orderInfo == null) {
|
|
|
+ throw new ServiceException("未知订单");
|
|
|
+ }
|
|
|
+ // 生产中和生产完成的订单快递包材归还入库
|
|
|
+ if (ObjectUtil.equals(orderInfo.getStatus(), OrderStatusEnum.IN_PRODUCTION.getKey())
|
|
|
+ || ObjectUtil.equals(orderInfo.getStatus(), OrderStatusEnum.COMPLETION_PRODUCTION.getKey())) {
|
|
|
+ this.orderPackageBomInOutStorage(dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<OrderPackageBomDto> tempOrderPackageBomList = dto.getOrderPackageBomList();
|
|
|
+ BigDecimal totalAmount = orderInfo.getTotalAmount();
|
|
|
+ BigDecimal oldDeliveryMaterialsFee = orderInfo.getDeliveryMaterialsFee();
|
|
|
+ BigDecimal newDeliveryMaterialsFee = BigDecimal.ZERO;
|
|
|
+ if (ObjectUtil.isEmpty(tempOrderPackageBomList)) {
|
|
|
+ orderPackageBomService.remove(q -> q.eq(OrderPackageBom::getOrderId, orderInfo.getId()));
|
|
|
+ } else {
|
|
|
+ List<OrderPackageBom> orderPackageBomList = tempOrderPackageBomList.stream()
|
|
|
+ .peek(item -> item.setOrderId(dto.getId()))
|
|
|
+ .map(item -> (OrderPackageBom) item)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ orderPackageBomService.editLinked(orderPackageBomList, OrderPackageBom::getOrderId, orderInfo.getId());
|
|
|
+ newDeliveryMaterialsFee = orderPackageBomList.stream()
|
|
|
+ .map(item -> item.getInternalSellingPrice().multiply(item.getQuantity()))
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+ orderInfo.setDeliveryMaterialsFee(newDeliveryMaterialsFee);
|
|
|
+ List<OrderSku> orderSkuList = orderSkuService.list(q -> q.eq(OrderSku::getOrderId, orderInfo.getId()));
|
|
|
+ orderSkuList.forEach(item ->
|
|
|
+ item.setDeliveryMaterialsFee(orderInfo.getDeliveryMaterialsFee()
|
|
|
+ .divide(new BigDecimal(orderSkuList.size()), 2, RoundingMode.HALF_UP)
|
|
|
+ .divide(item.getQuantity(), 2, RoundingMode.HALF_UP))
|
|
|
+ );
|
|
|
+ orderInfo.setTotalAmount(totalAmount.subtract(oldDeliveryMaterialsFee).add(newDeliveryMaterialsFee));
|
|
|
+ this.updateById(orderInfo);
|
|
|
+ orderSkuService.updateBatchById(orderSkuList);
|
|
|
+ ObsFileUtil.editFile(dto.getOuterBoxSelfAdhesiveStickerFile(), dto.getId(), 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单修改快递包材出入库操作
|
|
|
+ * @param dto
|
|
|
+ */
|
|
|
+ private void orderPackageBomInOutStorage(OrderInfoDto dto) {
|
|
|
+ List<OrderPackageBom> oldOrderPackageBomList = orderPackageBomService.list(q -> q.eq(OrderPackageBom::getOrderId, dto.getId()));
|
|
|
+ List<OrderPackageBomDto> newOrderPackageBomList = dto.getOrderPackageBomList();
|
|
|
+
|
|
|
+ // 旧bom
|
|
|
+ Map<Long, BigDecimal> oldBomMap = oldOrderPackageBomList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ OrderPackageBom::getBomSpecId,
|
|
|
+ OrderPackageBom::getQuantity,
|
|
|
+ BigDecimal::add
|
|
|
+ ));
|
|
|
+ Map<Long, BigDecimal> newBomMap = newOrderPackageBomList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ OrderPackageBom::getBomSpecId,
|
|
|
+ OrderPackageBom::getQuantity,
|
|
|
+ BigDecimal::add
|
|
|
+ ));
|
|
|
+ // 查询所有bom进行对比
|
|
|
+ Set<Long> bomIds = new HashSet<>(oldBomMap.keySet());
|
|
|
+ bomIds.addAll(newBomMap.keySet());
|
|
|
+ Map<Long, BigDecimal> outBomMap = new HashMap<>();
|
|
|
+ Map<Long, BigDecimal> inBomMap = new HashMap<>();
|
|
|
+ for (Long bomId : bomIds) {
|
|
|
+ BigDecimal oldReturnQuantity = oldBomMap.get(bomId);
|
|
|
+ BigDecimal newReturnQuantity = newBomMap.get(bomId);
|
|
|
+ // 旧bom没有,出库库存,反之则归还库存
|
|
|
+ if (oldReturnQuantity == null) {
|
|
|
+ outBomMap.put(bomId, newReturnQuantity);
|
|
|
+ continue;
|
|
|
+ } else if (newReturnQuantity == null) {
|
|
|
+ inBomMap.put(bomId, oldReturnQuantity);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 都有值,判断数量
|
|
|
+ if (oldReturnQuantity.compareTo(newReturnQuantity) == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 旧bom大于新bom则归还入库,反之出库库存
|
|
|
+ if (oldReturnQuantity.compareTo(newReturnQuantity) > 0) {
|
|
|
+ inBomMap.put(bomId, oldReturnQuantity.subtract(newReturnQuantity));
|
|
|
+ } else {
|
|
|
+ outBomMap.put(bomId, newReturnQuantity.subtract(oldReturnQuantity));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!outBomMap.isEmpty()) {
|
|
|
+ // 包材从包材仓出库
|
|
|
+ List<InOutStorageBom> outStorageBomList = outBomMap.entrySet().stream()
|
|
|
+ .map(item -> {
|
|
|
+ InOutStorageBom inOutStorageBom = new InOutStorageBom();
|
|
|
+ inOutStorageBom.setBomSpecId(item.getKey());
|
|
|
+ inOutStorageBom.setQuantity(item.getValue());
|
|
|
+ return inOutStorageBom;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ InOutStorageDto inOutStorageDto = new InOutStorageDto();
|
|
|
+ inOutStorageDto.setType(InOutTypeEnum.OUT.getKey());
|
|
|
+ inOutStorageDto.setDetailType(OutDetailTypeEnum.PRODUCTION.getKey());
|
|
|
+ inOutStorageDto.setWarehouseId(WarehouseConstant.PACKAGING_MATERIAL);
|
|
|
+ inOutStorageDto.setDepartmentId(DepartmentConstant.SD_SPORTS);
|
|
|
+ inOutStorageDto.setApplicant(SecurityUtils.getLoginUser().getUser().getNickName());
|
|
|
+ inOutStorageDto.setInOutStorageBomList(outStorageBomList);
|
|
|
+ inOutStorageDto.setLockStorage(StatusConstant.NO);
|
|
|
+ inOutStorageService.add(inOutStorageDto);
|
|
|
+ }
|
|
|
+ if (!inBomMap.isEmpty()) {
|
|
|
+ // 包材归还入库
|
|
|
+ List<InOutStorageBom> inOutStorageBomList = inBomMap.entrySet()
|
|
|
+ .stream()
|
|
|
+ .map(item -> {
|
|
|
+ InOutStorageBom inOutStorageBom = new InOutStorageBom();
|
|
|
+ inOutStorageBom.setBomSpecId(item.getKey());
|
|
|
+ inOutStorageBom.setQuantity(item.getValue());
|
|
|
+ return inOutStorageBom;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ InOutStorageDto packagingMaterialInOutStorageDto = new InOutStorageDto();
|
|
|
+ packagingMaterialInOutStorageDto.setType(InOutTypeEnum.IN.getKey());
|
|
|
+ packagingMaterialInOutStorageDto.setDetailType(InDetailTypeEnum.RETURN_GOODS.getKey());
|
|
|
+ packagingMaterialInOutStorageDto.setWarehouseId(WarehouseConstant.PACKAGING_MATERIAL);
|
|
|
+ packagingMaterialInOutStorageDto.setDepartmentId(DepartmentConstant.SD_SPORTS);
|
|
|
+ packagingMaterialInOutStorageDto.setApplicant(SecurityUtils.getLoginUser().getUser().getNickName());
|
|
|
+ packagingMaterialInOutStorageDto.setRemark("订单产品快递包装修改:" + dto.getCode()
|
|
|
+ + (StrUtil.isBlank(dto.getWlnCode()) ? StringPool.EMPTY : "(" + dto.getWlnCode() + ")")
|
|
|
+ + " 包材归还入库");
|
|
|
+ packagingMaterialInOutStorageDto.setInOutStorageBomList(inOutStorageBomList);
|
|
|
+ inOutStorageService.add(packagingMaterialInOutStorageDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 订单导出
|
|
|
* @param id
|