|
@@ -8,7 +8,6 @@ import com.google.common.collect.HashBasedTable;
|
|
|
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.order.po.OrderSku;
|
|
|
import com.sd.business.entity.sku.po.SkuSpec;
|
|
|
import com.sd.business.entity.work.dto.WorkOrderSelectDto;
|
|
@@ -17,12 +16,15 @@ import com.sd.business.entity.work.po.WorkOrder;
|
|
|
import com.sd.business.entity.work.po.WorkOrderDetail;
|
|
|
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.order.OrderSkuService;
|
|
|
import com.sd.business.service.sku.SkuSpecService;
|
|
|
import com.sd.business.service.work.WorkOrderDetailService;
|
|
|
import com.sd.business.service.work.WorkOrderService;
|
|
|
import com.sd.business.util.CodeEnum;
|
|
|
+import com.sd.business.util.packing.GA;
|
|
|
+import com.sd.business.util.packing.entity.PlaceItem;
|
|
|
+import com.sd.business.util.packing.entity.Solution;
|
|
|
+import com.sd.business.util.packing.model.Item;
|
|
|
import com.sd.framework.util.Assert;
|
|
|
import com.sd.framework.util.TransactionUtil;
|
|
|
import com.sd.framework.util.sql.Sql;
|
|
@@ -49,13 +51,16 @@ import java.util.stream.Collectors;
|
|
|
public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder> implements WorkOrderService {
|
|
|
|
|
|
private static final ReentrantLock schedulingLock = new ReentrantLock();
|
|
|
+ private static final double reserve = 5.5;
|
|
|
+ private static final int master_length = 4300;
|
|
|
+ private static final int master_width = 163;
|
|
|
|
|
|
@Autowired
|
|
|
private SkuSpecService skuSpecService;
|
|
|
- @Autowired
|
|
|
- private BomSpecService bomSpecService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private OrderSkuService orderSkuService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private WorkOrderDetailService workOrderDetailService;
|
|
|
|
|
@@ -87,37 +92,46 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
|
|
|
@Override
|
|
|
public void scheduling() {
|
|
|
+ boolean b = schedulingLock.tryLock();
|
|
|
|
|
|
- // 查找未排版完成的订单sku
|
|
|
- List<OrderSku> list = orderSkuService.list(q -> q.eq(OrderSku::getCompleteScheduling, StatusConstant.NO));
|
|
|
-
|
|
|
- if (list.isEmpty()) {
|
|
|
- return;
|
|
|
+ if (!b) {
|
|
|
+ throw new ServiceException("正在排版中,请稍后刷新数据");
|
|
|
}
|
|
|
|
|
|
- // 根据主材和打印纸区分订单sku
|
|
|
- HashBasedTable<Long, Long, List<OrderSku>> map = HashBasedTable.create();
|
|
|
- for (OrderSku orderSku : list) {
|
|
|
+ try {
|
|
|
|
|
|
- List<OrderSku> itemList = map.get(orderSku.getBomSpecId(), orderSku.getPrintingPaperBomSpecId());
|
|
|
+ // 查找未排版完成的订单sku
|
|
|
+ List<OrderSku> list = orderSkuService.list(q -> q.eq(OrderSku::getCompleteScheduling, StatusConstant.NO));
|
|
|
|
|
|
- if (itemList == null) {
|
|
|
- itemList = new ArrayList<>();
|
|
|
- map.put(orderSku.getBomSpecId(), orderSku.getPrintingPaperBomSpecId(), itemList);
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- itemList.add(orderSku);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- for (Long bomSpecId : map.rowKeySet()) {
|
|
|
- for (Long printingPaperBomSpecId : map.columnKeySet()) {
|
|
|
- List<OrderSku> orderSkuList = map.get(bomSpecId, printingPaperBomSpecId);
|
|
|
- scheduling(bomSpecId, printingPaperBomSpecId, orderSkuList);
|
|
|
+ // 根据主材和打印纸区分订单sku
|
|
|
+ HashBasedTable<Long, Long, List<OrderSku>> map = HashBasedTable.create();
|
|
|
+ for (OrderSku orderSku : list) {
|
|
|
+ List<OrderSku> itemList = map.get(orderSku.getBomSpecId(), orderSku.getPrintingPaperBomSpecId());
|
|
|
+ if (itemList == null) {
|
|
|
+ itemList = new ArrayList<>();
|
|
|
+ map.put(orderSku.getBomSpecId(), orderSku.getPrintingPaperBomSpecId(), itemList);
|
|
|
+ }
|
|
|
+ itemList.add(orderSku);
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+ // 排版
|
|
|
+ for (Long bomSpecId : map.rowKeySet()) {
|
|
|
+ for (Long printingPaperBomSpecId : map.columnKeySet()) {
|
|
|
+ List<OrderSku> orderSkuList = map.get(bomSpecId, printingPaperBomSpecId);
|
|
|
+ scheduling(bomSpecId, printingPaperBomSpecId, orderSkuList);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("排版业务发生异常", e);
|
|
|
+ throw new ServiceException("排版业务发生异常");
|
|
|
+ } finally {
|
|
|
+ schedulingLock.unlock();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -129,53 +143,38 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
*/
|
|
|
private void scheduling(Long bomSpecId, Long printingPaperBomSpecId, List<OrderSku> list) {
|
|
|
|
|
|
-
|
|
|
- boolean b = schedulingLock.tryLock();
|
|
|
-
|
|
|
- if (!b) {
|
|
|
- throw new ServiceException("正在排版中,请稍后刷新数据");
|
|
|
+ if (ObjectUtil.isNotEmpty(list)) {
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- try {
|
|
|
+ // 固定排版订单
|
|
|
+ List<OrderSku> fixationList = new ArrayList<>();
|
|
|
|
|
|
- if (ObjectUtil.isNotEmpty(list)) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 固定排版订单
|
|
|
- List<OrderSku> fixationList = new ArrayList<>();
|
|
|
+ // 不固定排版订单
|
|
|
+ List<OrderSku> notFixationList = new ArrayList<>();
|
|
|
|
|
|
- // 不固定排版订单
|
|
|
- List<OrderSku> notFixationList = new ArrayList<>();
|
|
|
+ // 获取需要排版的sku规格
|
|
|
+ List<Long> skuSpecIdList = list.stream().map(OrderSku::getSkuSpecId).collect(Collectors.toList());
|
|
|
+ Map<Long, SkuSpec> skuSpecMap = skuSpecService.mapKEntity(BaseIdPo::getId, q -> q.in(BaseIdPo::getId, skuSpecIdList));
|
|
|
|
|
|
- List<Long> skuSpecIdList = list.stream().map(OrderSku::getSkuSpecId).collect(Collectors.toList());
|
|
|
- Map<Long, SkuSpec> skuSpecMap = skuSpecService.mapKEntity(BaseIdPo::getId, q -> q.in(BaseIdPo::getId, skuSpecIdList));
|
|
|
-
|
|
|
- for (OrderSku orderSku : list) {
|
|
|
- Long skuSpecId = orderSku.getSkuSpecId();
|
|
|
- SkuSpec skuSpec = skuSpecMap.get(skuSpecId);
|
|
|
- boolean fixation = WorkOrderFixationSpecEnum.isFixation(skuSpec.getLength(), skuSpec.getWidth());
|
|
|
-
|
|
|
- if (fixation) {
|
|
|
- fixationList.add(orderSku);
|
|
|
- } else {
|
|
|
- notFixationList.add(orderSku);
|
|
|
- }
|
|
|
+ for (OrderSku orderSku : list) {
|
|
|
+ Long skuSpecId = orderSku.getSkuSpecId();
|
|
|
+ SkuSpec skuSpec = skuSpecMap.get(skuSpecId);
|
|
|
+ boolean fixation = WorkOrderFixationSpecEnum.isFixation(skuSpec.getLength(), skuSpec.getWidth());
|
|
|
|
|
|
+ if (fixation) {
|
|
|
+ fixationList.add(orderSku);
|
|
|
+ } else {
|
|
|
+ notFixationList.add(orderSku);
|
|
|
}
|
|
|
|
|
|
- // 固定排版
|
|
|
- fixationScheduling(bomSpecId, printingPaperBomSpecId, skuSpecMap, fixationList);
|
|
|
+ }
|
|
|
|
|
|
- // 非固定排版
|
|
|
- notFixationScheduling(bomSpecId, printingPaperBomSpecId, skuSpecMap, notFixationList);
|
|
|
+ // 固定排版
|
|
|
+ fixationScheduling(bomSpecId, printingPaperBomSpecId, skuSpecMap, fixationList);
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("排版业务发生异常", e);
|
|
|
- throw new ServiceException("排版业务发生异常");
|
|
|
- } finally {
|
|
|
- schedulingLock.unlock();
|
|
|
- }
|
|
|
+ // 非固定排版
|
|
|
+ notFixationScheduling(bomSpecId, printingPaperBomSpecId, skuSpecMap, notFixationList);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -224,18 +223,72 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- BomSpec bomSpec = bomSpecService.getById(bomSpecId);
|
|
|
- if (bomSpec == null) {
|
|
|
- throw new ServiceException("未知主材规格,id:" + bomSpecId);
|
|
|
- }
|
|
|
+ Item[] items = list.stream().flatMap(item -> {
|
|
|
+ Long skuSpecId = item.getSkuSpecId();
|
|
|
+ SkuSpec skuSpec = skuSpecMap.get(skuSpecId);
|
|
|
+ if (skuSpec == null) {
|
|
|
+ throw new ServiceException("未知sku规格,id:" + skuSpecId);
|
|
|
+ }
|
|
|
|
|
|
- if (bomSpec.getLength() == null) {
|
|
|
- throw new ServiceException("品号为【" + bomSpec.getCode() + "】的sku未定义长度");
|
|
|
- }
|
|
|
- if (bomSpec.getWidth() == null) {
|
|
|
- throw new ServiceException("品号为【" + bomSpec.getCode() + "】的sku未定义宽度");
|
|
|
+ int schedulingNum = item.getQuantity().subtract(item.getSchedulingNum()).intValue();
|
|
|
+
|
|
|
+ List<Item> itemList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < schedulingNum; i++) {
|
|
|
+ Long orderSkuId = item.getId();
|
|
|
+ double length = skuSpec.getLength().doubleValue() + reserve;
|
|
|
+ double width = skuSpec.getWidth().doubleValue() + reserve;
|
|
|
+
|
|
|
+ itemList.add(new Item(orderSkuId, length, width));
|
|
|
+ }
|
|
|
+
|
|
|
+ return itemList.stream();
|
|
|
+ }).toArray(Item[]::new);
|
|
|
+
|
|
|
+ Solution solve = GA.solve(master_length, master_width, items);
|
|
|
+
|
|
|
+ List<PlaceItem> placeItemList = solve.getPlaceItemList();
|
|
|
+ if (placeItemList.size() == list.size()) {
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
+ 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.setProductionBatchNumber(1);
|
|
|
+ workOrder.setType(2);
|
|
|
+ workOrder.setMasterBomSpecId(bomSpecId);
|
|
|
+ workOrder.setPrintingPaperBomSpecId(printingPaperBomSpecId);
|
|
|
+ workOrder.setSchedulingNum(new BigDecimal(placeItemList.size()));
|
|
|
+ workOrder.setUseRatio(BigDecimal.valueOf(solve.getRate() * 100));
|
|
|
+ workOrder.setMaxLength(BigDecimal.valueOf(solve.getMaxLength()));
|
|
|
+ workOrder.setSyncProduction(StatusConstant.NO);
|
|
|
+ workOrder.setIntegrity(StatusConstant.YES);
|
|
|
+
|
|
|
+ // 生产工单明细
|
|
|
+ List<WorkOrderDetail> workOrderDetailList = placeItemList.stream().map(item -> {
|
|
|
+ OrderSku orderSku = map.get(item.getId());
|
|
|
+ orderSku.setSchedulingNum(orderSku.getSchedulingNum().add(BigDecimal.ONE));
|
|
|
+
|
|
|
+ WorkOrderDetail workOrderDetail = new WorkOrderDetail();
|
|
|
+ workOrderDetail.setProductionBatchNumber(1);
|
|
|
+ workOrderDetail.setWorkOrderId(workOrder.getId());
|
|
|
+ workOrderDetail.setOrderInfoId(orderSku.getOrderId());
|
|
|
+ workOrderDetail.setOrderSkuId(item.getId());
|
|
|
+ workOrderDetail.setX(BigDecimal.valueOf(item.getX()));
|
|
|
+ workOrderDetail.setY(BigDecimal.valueOf(item.getY()));
|
|
|
+ return workOrderDetail;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 保存数据
|
|
|
+ TransactionUtil.execute(() -> {
|
|
|
+ orderSkuService.updateBatchById(list);
|
|
|
+ save(workOrder);
|
|
|
+ workOrderDetailService.saveBatch(workOrderDetailList);
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -259,7 +312,7 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 生成工单
|
|
|
+ // 生产工单
|
|
|
WorkOrder workOrder = new WorkOrder();
|
|
|
workOrder.setId(IdWorker.getId());
|
|
|
workOrder.setCode(CodeEnum.WORK_ORDER_CODE.getCode());
|
|
@@ -271,7 +324,7 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
workOrder.setPrintingPaperBomSpecId(printingPaperBomSpecId);
|
|
|
workOrder.setSchedulingNum(new BigDecimal(schedulingNum));
|
|
|
workOrder.setSyncProduction(StatusConstant.NO);
|
|
|
- workOrder.setIntegrity(StatusConstant.NO);
|
|
|
+ workOrder.setIntegrity(StatusConstant.YES);
|
|
|
|
|
|
// 生产工单明细
|
|
|
List<WorkOrderDetail> workOrderDetailList = new ArrayList<>();
|