|
@@ -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);
|