24282 há 1 ano atrás
pai
commit
cef3a6c26d

+ 8 - 0
sd-business/src/main/java/com/sd/business/controller/work/WorkOrderController.java

@@ -85,4 +85,12 @@ public class WorkOrderController {
         workOrderService.syncScheduling(dto.getId());
     }
 
+    /**
+     * 重新排版
+     */
+    @PostMapping("/reschedule")
+    public void reschedule(@RequestBody BaseSelectDto dto) {
+        workOrderService.reschedule(dto.getId());
+    }
+
 }

+ 1 - 0
sd-business/src/main/java/com/sd/business/entity/work/vo/WorkOrderVo.java

@@ -40,6 +40,7 @@ public class WorkOrderVo extends WorkOrder {
      * 工单详情
      */
     private List<WorkOrderDetailVo> workOrderDetailList;
+
     /**
      * 公海工单
      */

+ 45 - 27
sd-business/src/main/java/com/sd/business/service/order/impl/OrderInfoServiceImpl.java

@@ -373,31 +373,40 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
         if (!b) {
             throw new ServiceException("正在排版中,无法删除订单");
         }
-        WorkOrderServiceImpl.schedulingLock.unlock();
 
-        OrderInfo orderInfo = getById(id);
-
-        if (orderInfo == null) {
-            throw new ServiceException("未找到订单");
-        }
+        try {
+            OrderInfo orderInfo = getById(id);
 
-        if (Objects.equals(orderInfo.getDelFlag(), StatusConstant.NOT_DELETED)
-                && orderInfo.getStatus() > OrderStatusEnum.SCHEDULING.getKey()) {
-            throw new ServiceException("订单已排单生产,无法删除");
-        }
-
-        // 删除订单重新排单
-        reschedule(id);
+            if (orderInfo == null) {
+                throw new ServiceException("未找到订单");
+            }
 
-        List<Long> orderSkuIdList = orderSkuService.listObject(BaseIdPo::getId, q -> q.eq(OrderSku::getOrderId, id));
+            if (Objects.equals(orderInfo.getDelFlag(), StatusConstant.NOT_DELETED)
+                    && orderInfo.getStatus() > OrderStatusEnum.SCHEDULING.getKey()) {
+                throw new ServiceException("订单已排单生产,无法删除");
+            }
 
-        removeById(id);
-        orderSkuService.remove(q -> q.eq(OrderSku::getOrderId, id));
-        orderSkuBomService.remove(q -> q.eq(OrderSkuBom::getOrderId, id));
-        orderPackageBomService.remove(q -> q.eq(OrderPackageBom::getOrderId, id));
-        orderSkuProductionCostService.remove(q -> q.eq(OrderSkuProductionCost::getOrderId, id));
-        ObsFileUtil.removeFile(id);
-        ObsFileUtil.removeFile(orderSkuIdList);
+            // 删除订单重新排单
+            reschedule(id);
+
+            List<Long> orderSkuIdList = orderSkuService.listObject(BaseIdPo::getId, q -> q.eq(OrderSku::getOrderId, id));
+
+            removeById(id);
+            orderSkuService.remove(q -> q.eq(OrderSku::getOrderId, id));
+            orderSkuBomService.remove(q -> q.eq(OrderSkuBom::getOrderId, id));
+            orderPackageBomService.remove(q -> q.eq(OrderPackageBom::getOrderId, id));
+            orderSkuProductionCostService.remove(q -> q.eq(OrderSkuProductionCost::getOrderId, id));
+            ObsFileUtil.removeFile(id);
+            ObsFileUtil.removeFile(orderSkuIdList);
+
+        } catch (ServiceException e) {
+            throw e;
+        } catch (Exception e) {
+            log.error("删除订单失败", e);
+            throw new ServiceException("删除订单失败");
+        } finally {
+            WorkOrderServiceImpl.schedulingLock.unlock();
+        }
     }
 
     @DSTransactional
@@ -894,10 +903,12 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
 
             // 固定尺寸排版
             if (Objects.equals(workOrder.getType(), 1)) {
-                WorkOrderDetail workOrderDetail = tempWorkOrderDetailList.get(0);
 
-                WorkOrderFixationSpecEnum workOrderFixationSpecEnum = WorkOrderFixationSpecEnum
-                        .getEnum(workOrderDetail.getLength(), workOrderDetail.getLength());
+                String[] split = workOrder.getFixationSpec().split("\\*");
+                BigDecimal length = new BigDecimal(split[0]);
+                BigDecimal width = new BigDecimal(split[1]);
+
+                WorkOrderFixationSpecEnum workOrderFixationSpecEnum = WorkOrderFixationSpecEnum.getEnum(length, width);
 
                 FixationStrategy fixationStrategy = FixationFactory.get(workOrderFixationSpecEnum);
 
@@ -937,19 +948,26 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
                 workOrder.setUseRatio(BigDecimal.valueOf(solve.getUseRatio() * 100));
                 workOrder.setMaxLength(BigDecimal.valueOf(solve.getMaxLength()));
 
-                Map<Long, PlaceItem> collect = placeItemList.stream().collect(Collectors.toMap(PlaceItem::getId, Function.identity()));
+                Map<Long, PlaceItem> placeItemMap = placeItemList.stream().collect(Collectors.toMap(PlaceItem::getId, Function.identity()));
 
                 tempWorkOrderDetailList = tempWorkOrderDetailList.stream()
                         .filter(item -> {
-                            PlaceItem placeItem = collect.get(item.getId());
+                            PlaceItem placeItem = placeItemMap.get(item.getId());
                             if (placeItem == null) {
                                 workOrderDetailService.removeById(item.getId());
+
+                                Long orderSkuId = item.getOrderSkuId();
+                                OrderSku orderSku = orderSkuService.getById(orderSkuId);
+                                orderSku.setSchedulingNum(orderSku.getSchedulingNum().subtract(BigDecimal.ONE));
+                                orderSku.setCompleteScheduling(StatusConstant.NO);
+                                orderSkuService.updateById(orderSku);
+
                                 return false;
                             }
                             return true;
                         })
                         .peek(item -> {
-                            PlaceItem placeItem = collect.get(item.getId());
+                            PlaceItem placeItem = placeItemMap.get(item.getId());
                             item.setX(BigDecimal.valueOf(placeItem.getX()));
                             item.setY(BigDecimal.valueOf(placeItem.getY()));
                             item.setLength(BigDecimal.valueOf(placeItem.getLength() - MaterialsConstant.RESERVE));

+ 5 - 0
sd-business/src/main/java/com/sd/business/service/work/WorkOrderService.java

@@ -53,4 +53,9 @@ public interface WorkOrderService extends BaseService<WorkOrder> {
      */
     void syncScheduling(Long id);
 
+    /**
+     * 重新排版
+     */
+    void reschedule(Long id);
+
 }

+ 147 - 15
sd-business/src/main/java/com/sd/business/service/work/impl/WorkOrderServiceImpl.java

@@ -61,8 +61,10 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.locks.ReentrantLock;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -174,7 +176,7 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
         vo.setWorkOrderDetailList(workOrderDetailList);
 
         // 公海订单
-        List<OrderSku> orderSkuList = getNotSchedulingSku(vo.getMasterBomSpecId(), vo.getPrintingPaperBomSpecId());
+        List<OrderSku> orderSkuList = getNotSchedulingSku(vo.getMasterBomSpecId(), vo.getPrintingPaperBomSpecId(), null, null);
         List<OpenSeaWorkOrderVo> openSeaWorkOrderList = getOpenSeaWorkOrderList(orderSkuList);
         orderInfoService.attributeAssign(openSeaWorkOrderList, OpenSeaWorkOrderVo::getOrderInfoId, (item, orderInfo) -> {
             item.setOrderCode(orderInfo.getCode());
@@ -200,13 +202,22 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
 
     @Override
     public void schedulingRemaining() {
-        commonScheduling((bomSpecId, printingPaperBomSpecId, notFixationList, skuSpecMap) ->
-                notFixationScheduling(bomSpecId, printingPaperBomSpecId, notFixationList, skuSpecMap, false));
+        commonScheduling((bomSpecId, printingPaperBomSpecId, notFixationList, skuSpecMap) -> {
+
+            WorkOrder workOrder = new WorkOrder();
+            workOrder.setId(IdWorker.getId());
+            workOrder.setCode(CodeEnum.WORK_ORDER_CODE.getCode());
+            workOrder.setType(2);
+            workOrder.setMasterBomSpecId(bomSpecId);
+            workOrder.setPrintingPaperBomSpecId(printingPaperBomSpecId);
+
+            notFixationScheduling(workOrder, notFixationList, skuSpecMap, false);
+        });
     }
 
     @Override
     public Integer notSchedulingSkuNum() {
-        List<OrderSku> orderSkuList = getNotSchedulingSku(null, null);
+        List<OrderSku> orderSkuList = getNotSchedulingSku(null, null, null, null);
         return orderSkuList.stream()
                 .mapToInt(item -> item.getQuantity().subtract(item.getSchedulingNum()).intValue())
                 .sum();
@@ -305,6 +316,38 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
 
     }
 
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void reschedule(Long id) {
+
+        boolean b = schedulingLock.tryLock();
+
+        if (!b) {
+            throw new ServiceException("正在排版中,请稍后刷新数据");
+        }
+
+        try {
+
+            WorkOrder workOrder = getById(id);
+            if (Objects.equals(workOrder.getSyncProduction(), StatusConstant.YES)) {
+                throw new ServiceException("工单已同步生产,无法同步生产");
+            }
+
+            List<WorkOrderDetail> workOrderDetailList = workOrderDetailService.list(q -> q.eq(WorkOrderDetail::getWorkOrderId, id));
+
+            // 排版
+            reschedule(workOrder, workOrderDetailList);
+
+        } catch (ServiceException e) {
+            throw e;
+        } catch (Exception e) {
+            log.error("排版异常", e);
+            throw new ServiceException("排版异常");
+        } finally {
+            schedulingLock.unlock();
+        }
+    }
+
     /**
      * 排版
      */
@@ -333,8 +376,16 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
         }
         // 固定排版
         fixationScheduling(bomSpecId, printingPaperBomSpecId, fixationList, skuSpecMap);
+
+        WorkOrder workOrder = new WorkOrder();
+        workOrder.setId(IdWorker.getId());
+        workOrder.setCode(CodeEnum.WORK_ORDER_CODE.getCode());
+        workOrder.setType(2);
+        workOrder.setMasterBomSpecId(bomSpecId);
+        workOrder.setPrintingPaperBomSpecId(printingPaperBomSpecId);
+
         // 非固定排版
-        notFixationScheduling(bomSpecId, printingPaperBomSpecId, notFixationList, skuSpecMap, true);
+        notFixationScheduling(workOrder, notFixationList, skuSpecMap, true);
     }
 
     /**
@@ -465,7 +516,7 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
     /**
      * 非固定排版
      */
-    private void notFixationScheduling(Long bomSpecId, Long printingPaperBomSpecId, List<OrderSku> list,
+    private void notFixationScheduling(WorkOrder workOrder, List<OrderSku> list,
                                        Map<Long, SkuSpec> skuSpecMap, boolean carpeting) {
 
         if (ObjectUtil.isEmpty(list)) {
@@ -502,13 +553,6 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
         Map<Long, OrderSku> map = list.stream().collect(Collectors.toMap(BaseIdPo::getId, item -> item));
 
         // 生产工单
-        WorkOrder workOrder = new WorkOrder();
-        workOrder.setId(IdWorker.getId());
-        workOrder.setCode(CodeEnum.WORK_ORDER_CODE.getCode());
-        workOrder.setType(2);
-        workOrder.setMasterBomSpecId(bomSpecId);
-        workOrder.setPrintingPaperBomSpecId(printingPaperBomSpecId);
-
         workOrder.setSchedulingNum(new BigDecimal(placeItemList.size()));
         workOrder.setUsedArea(BigDecimal.valueOf(solve.getTotal()));
         workOrder.setUseRatio(BigDecimal.valueOf(solve.getUseRatio() * 100));
@@ -561,7 +605,7 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
         try {
 
             // 查找未排版完成的订单sku
-            List<OrderSku> list = getNotSchedulingSku(null, null);
+            List<OrderSku> list = getNotSchedulingSku(null, null, null, null);
 
             if (list.isEmpty()) {
                 return;
@@ -615,15 +659,18 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
     /**
      * 获取未排版订单sku
      */
-    private List<OrderSku> getNotSchedulingSku(Long bomSpecId, Long printingPaperBomSpecId) {
+    private List<OrderSku> getNotSchedulingSku(Long bomSpecId, Long printingPaperBomSpecId, BigDecimal length, BigDecimal width) {
         return Sql.create(OrderSku.class)
                 .selectAll(OrderSku.class)
                 .from(OrderInfo.class)
                 .innerJoin(OrderSku.class, OrderSku::getOrderId, OrderInfo::getId)
+                .leftJoin(SkuSpec.class, OrderSku::getSkuSpecId)
                 .eq(OrderInfo::getExceptionType, OrderExceptionTypeEnum.NORMAL.getKey())
                 .eq(OrderSku::getCompleteScheduling, StatusConstant.NO)
                 .eq(OrderSku::getBomSpecId, bomSpecId)
                 .eq(OrderSku::getPrintingPaperBomSpecId, printingPaperBomSpecId)
+                .eq(SkuSpec::getLength, length)
+                .eq(SkuSpec::getWidth, width)
                 .list();
     }
 
@@ -756,6 +803,91 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
         inStorageService.add(inOutStorageDto);
     }
 
+
+    /**
+     * 重新排单
+     */
+    private void reschedule(WorkOrder workOrder, List<WorkOrderDetail> workOrderDetailList) {
+
+        // 固定尺寸排版
+        if (Objects.equals(workOrder.getType(), 1)) {
+
+            String[] split = workOrder.getFixationSpec().split("\\*");
+            BigDecimal length = new BigDecimal(split[0]);
+            BigDecimal width = new BigDecimal(split[1]);
+
+            WorkOrderFixationSpecEnum workOrderFixationSpecEnum = WorkOrderFixationSpecEnum.getEnum(length, width);
+
+            FixationStrategy fixationStrategy = FixationFactory.get(workOrderFixationSpecEnum);
+
+            for (WorkOrderDetail orderDetail : workOrderDetailList) {
+                CoordinateBo coordinateBo = fixationStrategy.next();
+
+                orderDetail.setLength(coordinateBo.getLength());
+                orderDetail.setWidth(coordinateBo.getWidth());
+                orderDetail.setBleedingLength(coordinateBo.getBleedingLength());
+                orderDetail.setBleedingWidth(coordinateBo.getBleedingWidth());
+                orderDetail.setRotate(coordinateBo.getHasRotate() ? StatusConstant.YES : StatusConstant.NO);
+                orderDetail.setX(coordinateBo.getX());
+                orderDetail.setY(coordinateBo.getY());
+            }
+
+            List<OrderSku> notSchedulingSku = getNotSchedulingSku(workOrder.getMasterBomSpecId(),
+                    workOrder.getPrintingPaperBomSpecId(), length, width);
+
+            for (OrderSku orderSku : notSchedulingSku) {
+
+                if (fixationStrategy.hasNext()) {
+
+                    int number = orderSku.getQuantity().subtract(orderSku.getSchedulingNum()).intValue();
+                    for (int i = 0; i < number; i++) {
+                        if (fixationStrategy.hasNext()) {
+                            addWorkOrderDetail(fixationStrategy, workOrder, workOrderDetailList, orderSku);
+                            orderSku.setSchedulingNum(orderSku.getSchedulingNum().add(BigDecimal.ONE));
+                            orderSku.setCompleteScheduling(orderSku.getSchedulingNum()
+                                    .compareTo(orderSku.getQuantity()) == 0 ? StatusConstant.YES : StatusConstant.NO);
+                        } else {
+                            break;
+                        }
+                    }
+
+                } else {
+                    break;
+                }
+            }
+
+            workOrder.setSchedulingNum(fixationStrategy.getSchedulingNum());
+            workOrder.setUsedArea(fixationStrategy.getUsedArea());
+            workOrder.setUseRatio(fixationStrategy.getUseRatio());
+            workOrder.setMaxLength(fixationStrategy.getMaxLength());
+
+            orderSkuService.updateBatchById(notSchedulingSku);
+            save(workOrder);
+            workOrderDetailService.saveBatch(workOrderDetailList);
+        }
+        // 非固定尺寸排版
+        else {
+            List<Long> orderSkuIdList = workOrderDetailList.stream().map(WorkOrderDetail::getOrderSkuId).collect(Collectors.toList());
+            Map<Long, OrderSku> map = orderSkuService.listByIds(orderSkuIdList).stream()
+                    .collect(Collectors.toMap(BaseIdPo::getId, Function.identity(), (t1, t2) -> t1));
+
+            for (WorkOrderDetail workOrderDetail : workOrderDetailList) {
+                OrderSku orderSku = map.get(workOrderDetail.getOrderSkuId());
+                orderSku.setSchedulingNum(orderSku.getSchedulingNum().subtract(BigDecimal.ONE));
+                orderSku.setCompleteScheduling(StatusConstant.NO);
+            }
+            orderSkuService.updateBatchById(map.values());
+            workOrderDetailService.remove(q -> q.eq(WorkOrderDetail::getWorkOrderId, workOrder.getId()));
+
+            List<OrderSku> notSchedulingSku = getNotSchedulingSku(workOrder.getMasterBomSpecId(),
+                    workOrder.getPrintingPaperBomSpecId(), null, null);
+
+            Set<Long> skuSpecIdSet = notSchedulingSku.stream().map(OrderSku::getSkuSpecId).collect(Collectors.toSet());
+            Map<Long, SkuSpec> skuSpecMap = skuSpecService.mapKEntity(BaseIdPo::getId, q -> q.in(BaseIdPo::getId, skuSpecIdSet));
+            notFixationScheduling(workOrder, notSchedulingSku, skuSpecMap, false);
+        }
+    }
+
     @FunctionalInterface
     private interface CommonSchedulingFunInterface {
         void run(Long bomSpecId, Long printingPaperBomSpecId, List<OrderSku> list, Map<Long, SkuSpec> skuSpecMap);