|
@@ -9,10 +9,18 @@ import com.ruoyi.common.constant.StatusConstant;
|
|
|
import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.sd.business.entity.bom.po.BomSpec;
|
|
|
+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.order.enums.OrderExceptionTypeEnum;
|
|
|
+import com.sd.business.entity.order.enums.OrderStatusEnum;
|
|
|
import com.sd.business.entity.order.po.OrderInfo;
|
|
|
import com.sd.business.entity.order.po.OrderSku;
|
|
|
+import com.sd.business.entity.order.po.OrderSkuBom;
|
|
|
import com.sd.business.entity.sku.po.SkuSpec;
|
|
|
+import com.sd.business.entity.warehouse.constant.WarehouseConstant;
|
|
|
import com.sd.business.entity.work.constant.MaterialsConstant;
|
|
|
import com.sd.business.entity.work.dto.WorkOrderDto;
|
|
|
import com.sd.business.entity.work.dto.WorkOrderSelectDto;
|
|
@@ -24,7 +32,9 @@ import com.sd.business.entity.work.vo.WorkOrderDetailVo;
|
|
|
import com.sd.business.entity.work.vo.WorkOrderVo;
|
|
|
import com.sd.business.mapper.work.WorkOrderMapper;
|
|
|
import com.sd.business.service.bom.BomSpecService;
|
|
|
+import com.sd.business.service.in.InOutStorageService;
|
|
|
import com.sd.business.service.order.OrderInfoService;
|
|
|
+import com.sd.business.service.order.OrderSkuBomService;
|
|
|
import com.sd.business.service.order.OrderSkuService;
|
|
|
import com.sd.business.service.sku.SkuSpecService;
|
|
|
import com.sd.business.service.work.WorkOrderDetailService;
|
|
@@ -46,6 +56,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
@@ -82,6 +94,12 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
@Autowired
|
|
|
private WorkOrderDetailService workOrderDetailService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private InOutStorageService inStorageService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderSkuBomService orderSkuBomService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<WorkOrderVo> getPage(WorkOrderSelectDto dto) {
|
|
|
|
|
@@ -238,6 +256,40 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void syncScheduling(Long id) {
|
|
|
+ WorkOrder workOrder = getById(id);
|
|
|
+ Assert.notNull(workOrder, "排版工单不存在");
|
|
|
+ Assert.eqZero(workOrder.getSyncProduction(), "排版已同步生产");
|
|
|
+ Assert.notNull(workOrder.getMasterInventoryId(), "未选择转印布");
|
|
|
+ Assert.notNull(workOrder.getPrintingPaperInventoryId(), "未选择打印纸");
|
|
|
+
|
|
|
+ workOrder.setSyncProduction(StatusConstant.YES);
|
|
|
+ updateById(workOrder);
|
|
|
+
|
|
|
+ // 原料出库
|
|
|
+ ingredientsOut(workOrder);
|
|
|
+
|
|
|
+ // 余料入库
|
|
|
+ surplusIn(workOrder);
|
|
|
+
|
|
|
+ // 获取工单明细
|
|
|
+ List<WorkOrderDetail> list = workOrderDetailService.list(q -> q.eq(WorkOrderDetail::getWorkOrderId, workOrder.getId()));
|
|
|
+
|
|
|
+ // 包材出库
|
|
|
+ packagingMaterialOut(workOrder, list);
|
|
|
+
|
|
|
+ // 订单状态改为生产中
|
|
|
+ Set<Long> orderInfoIdList = list.stream().map(WorkOrderDetail::getOrderInfoId).collect(Collectors.toSet());
|
|
|
+ orderInfoService.update(q -> q
|
|
|
+ .in(BaseIdPo::getId, orderInfoIdList)
|
|
|
+ .eq(OrderInfo::getStatus, OrderStatusEnum.SCHEDULING.getKey())
|
|
|
+ .set(OrderInfo::getStatus, OrderStatusEnum.IN_PRODUCTION.getKey())
|
|
|
+ );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 排版
|
|
|
*/
|
|
@@ -576,4 +628,116 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
void run(Long bomSpecId, Long printingPaperBomSpecId, List<OrderSku> list, Map<Long, SkuSpec> skuSpecMap);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 原料出库
|
|
|
+ */
|
|
|
+ private void ingredientsOut(WorkOrder workOrder) {
|
|
|
+ InOutStorageDto inOutStorageDto = new InOutStorageDto();
|
|
|
+ inOutStorageDto.setType(InOutTypeEnum.OUT.getKey());
|
|
|
+ inOutStorageDto.setDetailType(OutDetailTypeEnum.PRODUCTION.getKey());
|
|
|
+ inOutStorageDto.setClassifyType(1);
|
|
|
+ inOutStorageDto.setWarehouseId(WarehouseConstant.SEMI_FINISHED_PRODUCT);
|
|
|
+ inOutStorageDto.setRemark("生产工单【" + workOrder.getCode() + "】原料出库");
|
|
|
+ List<InOutStorageBom> inOutStorageBomList = new ArrayList<>();
|
|
|
+ inOutStorageDto.setInOutStorageBomList(inOutStorageBomList);
|
|
|
+
|
|
|
+ // 转印布
|
|
|
+ InOutStorageBom master = new InOutStorageBom();
|
|
|
+ master.setBomSpecId(workOrder.getMasterBomSpecId());
|
|
|
+ master.setQuantity(BigDecimal.ONE);
|
|
|
+ master.setMeter(workOrder.getMasterLength());
|
|
|
+ inOutStorageBomList.add(master);
|
|
|
+
|
|
|
+ // 打印纸
|
|
|
+ InOutStorageBom printingPaper = new InOutStorageBom();
|
|
|
+ printingPaper.setBomSpecId(workOrder.getPrintingPaperBomSpecId());
|
|
|
+ printingPaper.setQuantity(BigDecimal.ONE);
|
|
|
+ printingPaper.setMeter(workOrder.getPrintingPaperLength());
|
|
|
+ inOutStorageBomList.add(printingPaper);
|
|
|
+
|
|
|
+ inStorageService.add(inOutStorageDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 余料入库
|
|
|
+ */
|
|
|
+ private void surplusIn(WorkOrder workOrder) {
|
|
|
+
|
|
|
+ List<InOutStorageBom> inOutStorageBomList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 转印布
|
|
|
+ BigDecimal masterMeter = workOrder.getMasterLength().subtract(workOrder.getMaxLength()).divide(new BigDecimal("100"));
|
|
|
+ if (masterMeter.compareTo(new BigDecimal("0.4")) >= 0) {
|
|
|
+ InOutStorageBom master = new InOutStorageBom();
|
|
|
+ master.setBomSpecId(workOrder.getMasterBomSpecId());
|
|
|
+ master.setQuantity(BigDecimal.ONE);
|
|
|
+ master.setMeter(masterMeter);
|
|
|
+ inOutStorageBomList.add(master);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 打印纸
|
|
|
+ BigDecimal printingPaperMeter = workOrder.getPrintingPaperLength().subtract(workOrder.getMaxLength()).divide(new BigDecimal("100"));
|
|
|
+ if (printingPaperMeter.compareTo(new BigDecimal("0.4")) >= 0) {
|
|
|
+ InOutStorageBom printingPaper = new InOutStorageBom();
|
|
|
+ printingPaper.setBomSpecId(workOrder.getPrintingPaperBomSpecId());
|
|
|
+ printingPaper.setQuantity(BigDecimal.ONE);
|
|
|
+ printingPaper.setMeter(printingPaperMeter);
|
|
|
+ inOutStorageBomList.add(printingPaper);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!inOutStorageBomList.isEmpty()) {
|
|
|
+ InOutStorageDto inOutStorageDto = new InOutStorageDto();
|
|
|
+ inOutStorageDto.setType(InOutTypeEnum.IN.getKey());
|
|
|
+ inOutStorageDto.setDetailType(InDetailTypeEnum.GIVE_BACK.getKey());
|
|
|
+ inOutStorageDto.setClassifyType(1);
|
|
|
+ inOutStorageDto.setWarehouseId(WarehouseConstant.SEMI_FINISHED_PRODUCT);
|
|
|
+ inOutStorageDto.setRemark("生产工单【" + workOrder.getCode() + "】余料入库");
|
|
|
+ inOutStorageDto.setInOutStorageBomList(inOutStorageBomList);
|
|
|
+ inStorageService.add(inOutStorageDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 包材出库
|
|
|
+ */
|
|
|
+ private void packagingMaterialOut(WorkOrder workOrder, List<WorkOrderDetail> list) {
|
|
|
+ InOutStorageDto inOutStorageDto = new InOutStorageDto();
|
|
|
+ inOutStorageDto.setType(InOutTypeEnum.OUT.getKey());
|
|
|
+ inOutStorageDto.setDetailType(OutDetailTypeEnum.PRODUCTION.getKey());
|
|
|
+ inOutStorageDto.setClassifyType(2);
|
|
|
+ inOutStorageDto.setWarehouseId(WarehouseConstant.PACKAGING_MATERIAL);
|
|
|
+ inOutStorageDto.setRemark("生产工单【" + workOrder.getCode() + "】包材出库");
|
|
|
+
|
|
|
+ Map<Long, InOutStorageBom> map = new HashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+ // 通过工单找到订单sku包材配置
|
|
|
+ List<Long> orderSkuIdList = list.stream().map(WorkOrderDetail::getOrderSkuId).collect(Collectors.toList());
|
|
|
+ Map<Long, List<OrderSkuBom>> orderSkuMap = orderSkuBomService.mapKGroup(OrderSkuBom::getOrderSkuId,
|
|
|
+ q -> q.in(OrderSkuBom::getOrderSkuId, orderSkuIdList));
|
|
|
+
|
|
|
+ // 循环订单sku id
|
|
|
+ for (Long orderSkuId : orderSkuIdList) {
|
|
|
+
|
|
|
+ // 获取订单skuId的包材
|
|
|
+ List<OrderSkuBom> orderSkuBomList = orderSkuMap.getOrDefault(orderSkuId, Collections.emptyList());
|
|
|
+
|
|
|
+ // 循环包材,添加入库数量
|
|
|
+ for (OrderSkuBom orderSkuBom : orderSkuBomList) {
|
|
|
+ InOutStorageBom inOutStorageBom = map.computeIfAbsent(orderSkuBom.getBomSpecId(), bomSpecId -> {
|
|
|
+ InOutStorageBom tempInOutStorageBom = new InOutStorageBom();
|
|
|
+ tempInOutStorageBom.setBomSpecId(bomSpecId);
|
|
|
+ tempInOutStorageBom.setQuantity(BigDecimal.ZERO);
|
|
|
+ return tempInOutStorageBom;
|
|
|
+ });
|
|
|
+ inOutStorageBom.setQuantity(inOutStorageBom.getQuantity().add(orderSkuBom.getQuantity()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ inOutStorageDto.setInOutStorageBomList(new ArrayList<>(map.values()));
|
|
|
+
|
|
|
+ // 执行入库操作
|
|
|
+ inStorageService.add(inOutStorageDto);
|
|
|
+ }
|
|
|
+
|
|
|
}
|