24282 hace 1 año
padre
commit
a19c85f4a9

+ 1 - 1
sd-business/src/main/java/com/sd/business/controller/order/OrderController.java

@@ -21,7 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
  * @since 2023-06-30
  */
 @RestController
-@RequestMapping("/order")
+@RequestMapping("/orderInfo")
 public class OrderController {
 
     @Autowired

+ 7 - 0
sd-business/src/main/java/com/sd/business/entity/bom/dto/BomSelectDto.java

@@ -4,6 +4,8 @@ import com.ruoyi.common.core.domain.BaseSelectDto;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.util.List;
+
 /**
  * bom列表查询入参实体
  *
@@ -64,4 +66,9 @@ public class BomSelectDto extends BaseSelectDto {
      */
     private Long bomClassifyId;
 
+    /**
+     * bom分类id
+     */
+    private List<Long> bomClassifyIdList;
+
 }

+ 1 - 1
sd-business/src/main/java/com/sd/business/entity/production/po/ProductionWorkOrder.java

@@ -33,7 +33,7 @@ public class ProductionWorkOrder extends BasePo {
     /**
      * 状态 1待投产
      */
-    private String status;
+    private Integer status;
 
     /**
      * 完成时间

+ 1 - 1
sd-business/src/main/java/com/sd/business/entity/sku/dto/SkuDto.java

@@ -20,6 +20,6 @@ public class SkuDto extends Sku {
 
     @Valid
     @NotEmpty(message = "规格列表不能为空")
-    private List<SkuSpecDto> skuSpecDtoList;
+    private List<SkuSpecDto> skuSpecList;
 
 }

+ 5 - 0
sd-business/src/main/java/com/sd/business/entity/sku/dto/SkuSelectDto.java

@@ -29,4 +29,9 @@ public class SkuSelectDto extends BaseSelectDto {
      */
     private Integer type;
 
+    /**
+     * 品牌
+     */
+    private String brand;
+
 }

+ 5 - 2
sd-business/src/main/java/com/sd/business/entity/sku/dto/SkuSpecDto.java

@@ -6,6 +6,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
 import java.util.List;
 
 /**
@@ -21,13 +22,15 @@ public class SkuSpecDto extends SkuSpec {
     /**
      * 包材
      */
+    @NotNull(message = "包材列表不能为空")
     @Valid
-    private List<SkuSpecLink> principalMaterialSkuSpecLinkList;
+    private List<SkuSpecLink> packagingMaterialList;
 
     /**
      * 快递
      */
+    @NotNull(message = "快递列表不能为空")
     @Valid
-    private List<SkuSpecLink> expressPackingSkuSpecLinkList;
+    private List<SkuSpecLink> expressPackingList;
 
 }

+ 1 - 0
sd-business/src/main/java/com/sd/business/service/bom/impl/BomServiceImpl.java

@@ -71,6 +71,7 @@ public class BomServiceImpl extends ServiceImpl<BomMapper, Bom> implements BomSe
         wrapper.eq("b", Bom::getEmbossingProcess, dto.getEmbossingProcess());
         wrapper.eq("b", Bom::getFrontGrain, dto.getFrontGrain());
         wrapper.eq("b", Bom::getReverseGrain, dto.getReverseGrain());
+        wrapper.eq("b", Bom::getBomClassifyId, dto.getBomClassifyIdList());
         if (StrUtil.isNotBlank(dto.getColour())) {
             List<Long> bomIdList = bomSpecService.listObject(BomSpec::getBomId, i -> i.like(BomSpec::getColour, dto.getColour()));
             if (bomIdList.size() == 0) {

+ 104 - 16
sd-business/src/main/java/com/sd/business/service/production/impl/StockPreparationServiceImpl.java

@@ -1,5 +1,6 @@
 package com.sd.business.service.production.impl;
 
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.constant.StatusConstant;
 import com.ruoyi.common.core.domain.BaseIdPo;
@@ -10,21 +11,26 @@ 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.production.dto.StockPreparationDto;
+import com.sd.business.entity.production.po.ProductionTask;
+import com.sd.business.entity.production.po.ProductionWorkOrder;
 import com.sd.business.entity.production.vo.StockPreparationVo;
+import com.sd.business.entity.sku.po.Sku;
 import com.sd.business.entity.sku.po.SkuSpec;
 import com.sd.business.mapper.production.StockPreparationMapper;
 import com.sd.business.service.order.OrderService;
 import com.sd.business.service.order.OrderSkuService;
+import com.sd.business.service.production.ProductionTaskService;
+import com.sd.business.service.production.ProductionWorkOrderService;
 import com.sd.business.service.production.StockPreparationService;
+import com.sd.business.service.sku.SkuService;
+import com.sd.business.service.sku.SkuSpecService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.math.BigDecimal;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -39,6 +45,18 @@ public class StockPreparationServiceImpl implements StockPreparationService {
     @Autowired
     private OrderService orderService;
 
+    @Autowired
+    private ProductionTaskService productionTaskService;
+
+    @Autowired
+    private ProductionWorkOrderService productionWorkOrderService;
+
+    @Autowired
+    private SkuSpecService skuSpecService;
+
+    @Autowired
+    private SkuService skuService;
+
     @Override
     public List<StockPreparationVo> uncompletedList(StockPreparationDto dto) {
         IWrapper<StockPreparationVo> wrapper = createWrapper(dto);
@@ -65,6 +83,7 @@ public class StockPreparationServiceImpl implements StockPreparationService {
                 .select(BaseIdPo::getId, OrderSku::getStockPreparationStatus, OrderSku::getOrderId)
                 .eq(OrderSku::getStockPreparationStatus, StatusConstant.NO)
                 .in(BaseIdPo::getId, orderSkuIdList));
+
         Date stockPreparationTime = new Date();
         for (OrderSku orderSku : orderSkuList) {
             orderSku.setStockPreparationTime(stockPreparationTime);
@@ -77,33 +96,42 @@ public class StockPreparationServiceImpl implements StockPreparationService {
         Map<Long, List<OrderSku>> map = list.stream().collect(Collectors.groupingBy(OrderSku::getOrderId));
 
         List<OrderInfo> orderInfoList = new ArrayList<>();
+        List<ProductionTask> productionTaskList = new ArrayList<>();
+        List<ProductionWorkOrder> productionWorkOrderList = new ArrayList<>();
+
+        map.forEach((orderId, itemOrderSkuList) -> {
 
-        for (List<OrderSku> tempOrderSku : map.values()) {
             // 订单中未备料数量
-            long count = tempOrderSku.stream()
+            long count = itemOrderSkuList.stream()
                     .map(OrderSku::getStockPreparationStatus)
-                    .filter(item -> item.equals(StatusConstant.NO))
+                    .filter(StatusConstant.NO::equals)
                     .count();
 
-            if (count != 0) {
-                continue;
+            // 存在未备料的订单sku,不执行以下逻辑
+            if (count > 0) {
+                return;
             }
 
             // 订单状态改为 生产中
-            OrderInfo orderInfo = new OrderInfo();
-            orderInfo.setId(tempOrderSku.get(0).getOrderId());
-            orderInfo.setStatus(OrderStatusEnum.REJECT.getKey());
-            orderInfoList.add(orderInfo);
+            addOrderInfo(orderId, orderInfoList);
 
-            // TODO 生成生产任务和生产工单
+            // 添加 生产任务、工单
+            addTaskAndWorkOrder(orderId, itemOrderSkuList, productionTaskList, productionWorkOrderList);
 
-            // TODO 出库
+            // 出库
 
-        }
+
+        });
 
         if (orderInfoList.size() > 0) {
             orderService.updateBatchById(orderInfoList);
         }
+        if (productionTaskList.size() > 0) {
+            productionTaskService.saveBatch(productionTaskList);
+        }
+        if (productionWorkOrderList.size() > 0) {
+            productionWorkOrderService.saveBatch(productionWorkOrderList);
+        }
 
     }
 
@@ -126,4 +154,64 @@ public class StockPreparationServiceImpl implements StockPreparationService {
         return wrapper;
     }
 
+    /**
+     * 订单状态改为 生产中
+     */
+    private void addOrderInfo(Long orderId, List<OrderInfo> orderInfoList) {
+        OrderInfo orderInfo = new OrderInfo();
+        orderInfo.setId(orderId);
+        orderInfo.setStatus(OrderStatusEnum.REJECT.getKey());
+        orderInfoList.add(orderInfo);
+    }
+
+    /**
+     * 添加 生产任务、工单
+     */
+    private void addTaskAndWorkOrder(Long orderId,
+                                     List<OrderSku> orderSkuList,
+                                     List<ProductionTask> productionTaskList,
+                                     List<ProductionWorkOrder> productionWorkOrderList) {
+
+        OrderInfo orderInfo = orderService.getById(orderId);
+        HashMap<Long, ProductionTask> skuSpecIdProductionTaskMap = new HashMap<>();
+        int num = 1;
+
+        for (OrderSku orderSku : orderSkuList) {
+
+            Long skuSpecId = orderSku.getSkuSpecId();
+            BigDecimal quantity = orderSku.getQuantity();
+
+            ProductionTask productionTask = skuSpecIdProductionTaskMap.computeIfAbsent(skuSpecId, item -> {
+                SkuSpec skuSpec = skuSpecService.getById(skuSpecId);
+                Sku sku = skuService.getById(skuSpec.getSkuId());
+
+                ProductionTask tempProductionTask = new ProductionTask();
+                tempProductionTask.setId(IdWorker.getId());
+                tempProductionTask.setOrderId(orderSku.getOrderId());
+                tempProductionTask.setSkuSpecId(skuSpecId);
+                tempProductionTask.setBomSpecId(skuSpec.getBomSpecId());
+                tempProductionTask.setCraftProductionLineId(sku.getCraftProductionLineId());
+                tempProductionTask.setMachinedPanel(skuSpec.getMachinedPanel());
+                tempProductionTask.setProductionQuantity(BigDecimal.ZERO);
+                tempProductionTask.setCompleteQuantity(BigDecimal.ZERO);
+
+                productionTaskList.add(tempProductionTask);
+
+                return tempProductionTask;
+            });
+
+            productionTask.setProductionQuantity(productionTask.getProductionQuantity().add(quantity));
+
+            for (int i = 0; i < quantity.intValue(); i++) {
+                ProductionWorkOrder productionWorkOrder = new ProductionWorkOrder();
+                productionWorkOrder.setProductionTaskId(productionTask.getId());
+                productionWorkOrder.setStatus(1);
+                productionWorkOrder.setCode(orderInfo.getCode() + String.format("-%05d", num));
+                productionWorkOrderList.add(productionWorkOrder);
+                num++;
+            }
+
+        }
+    }
+
 }

+ 95 - 93
sd-business/src/main/java/com/sd/business/service/sku/impl/SkuServiceImpl.java

@@ -2,7 +2,6 @@ package com.sd.business.service.sku.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
-import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.common.core.domain.BaseIdPo;
@@ -59,7 +58,8 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
         wrapper.orderByDesc("s", Sku::getId);
         wrapper.like("s", Sku::getCode, dto.getCode());
         wrapper.like("s", Sku::getName, dto.getName());
-        wrapper.like("s", Sku::getType, dto.getType());
+        wrapper.eq("s", Sku::getType, dto.getType());
+        wrapper.eq("s", Sku::getBrand, dto.getBrand());
         Page<SkuVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
         List<SkuVo> records = page.getRecords();
         if (records.size() == 0) {
@@ -137,47 +137,17 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void add(SkuDto skuDto) {
-        skuDto.setId(IdWorker.getId());
-        skuDto.setSource(1);
-
-        List<SkuSpecDto> skuSpecDtoList = skuDto.getSkuSpecDtoList();
 
-        for (SkuSpecDto skuSpecDto : skuSpecDtoList) {
-            skuSpecDto.setId(IdWorker.getId());
-            skuSpecDto.setSkuId(skuDto.getId());
-        }
-
-        List<SkuSpecLink> skuSpecLinkList = skuSpecDtoList.stream().flatMap(item -> {
-            List<SkuSpecLink> principalMaterialSkuSpecLinkList = item.getPrincipalMaterialSkuSpecLinkList();
-            if (principalMaterialSkuSpecLinkList == null) {
-                principalMaterialSkuSpecLinkList = Collections.emptyList();
-            } else {
-                for (SkuSpecLink skuSpecLink : principalMaterialSkuSpecLinkList) {
-                    skuSpecLink.setId(IdWorker.getId());
-                    skuSpecLink.setSkuId(item.getSkuId());
-                    skuSpecLink.setSkuSpecId(item.getId());
-                    skuSpecLink.setDepartmentId(SecurityUtils.getDeptId());
-                    skuSpecLink.setType(1);
-                }
-            }
+        skuDto.setSource(1);
+        save(skuDto);
 
-            List<SkuSpecLink> expressPackingSkuSpecLinkList = item.getExpressPackingSkuSpecLinkList();
-            if (expressPackingSkuSpecLinkList == null) {
-                expressPackingSkuSpecLinkList = Collections.emptyList();
-            } else {
-                for (SkuSpecLink skuSpecLink : expressPackingSkuSpecLinkList) {
-                    skuSpecLink.setId(IdWorker.getId());
-                    skuSpecLink.setSkuId(item.getSkuId());
-                    skuSpecLink.setSkuSpecId(item.getId());
-                    skuSpecLink.setDepartmentId(SecurityUtils.getDeptId());
-                    skuSpecLink.setType(2);
-                }
-            }
-            return Stream.concat(principalMaterialSkuSpecLinkList.stream(), expressPackingSkuSpecLinkList.stream());
-        }).collect(Collectors.toList());
+        List<SkuSpec> skuSpecList = skuDto.getSkuSpecList().stream()
+                .peek(item -> item.setSkuId(skuDto.getId()))
+                .map(item -> (SkuSpec) item)
+                .collect(Collectors.toList());
+        skuSpecService.saveBatch(skuSpecList);
 
-        save(skuDto);
-        skuSpecService.saveBatch(skuSpecDtoList.stream().map(item -> (SkuSpec) item).collect(Collectors.toList()));
+        List<SkuSpecLink> skuSpecLinkList = createSkuSpecLink(skuDto.getSkuSpecList());
         skuSpecLinkService.saveBatch(skuSpecLinkList);
 
     }
@@ -185,64 +155,19 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void edit(SkuDto skuDto) {
-        Long skuId = skuDto.getId();
-
-        List<SkuSpecDto> skuSpecDtoList = skuDto.getSkuSpecDtoList();
-
-        List<Long> skuSpecIdList = skuSpecDtoList.stream().map(SkuSpec::getId)
-                .filter(ObjectUtil::isNotNull).collect(Collectors.toList());
-
-        List<Long> skuSpecLinkIdList = skuSpecDtoList.stream().flatMap(item -> Stream.concat(
-                item.getPrincipalMaterialSkuSpecLinkList().stream(),
-                item.getExpressPackingSkuSpecLinkList().stream()
-        )).map(BaseIdPo::getId).filter(ObjectUtil::isNotNull).collect(Collectors.toList());
 
-        skuSpecService.remove(q -> q
-                .eq(SkuSpec::getSkuId, skuId)
-                .notIn(ObjectUtil.isNotEmpty(skuSpecIdList), BaseIdPo::getId, skuSpecIdList));
+        Long skuId = skuDto.getId();
+        List<SkuSpecDto> skuSpecDtoList = skuDto.getSkuSpecList();
 
-        skuSpecLinkService.remove(q -> q
-                .eq(SkuSpecLink::getSkuId, skuId)
-                .eq(SkuSpecLink::getDepartmentId, SecurityUtils.getDeptId())
-                .notIn(ObjectUtil.isNotEmpty(skuSpecLinkIdList), BaseIdPo::getId, skuSpecLinkIdList));
+        // 编辑sku
+        updateById(skuDto);
 
-        for (SkuSpecDto skuSpecDto : skuSpecDtoList) {
-            skuSpecDto.setId(IdWorker.getId());
-            skuSpecDto.setSkuId(skuDto.getId());
-        }
+        // 编辑sku规格
+        editSkuSpecList(skuId, skuSpecDtoList);
 
-        List<SkuSpecLink> skuSpecLinkList = skuSpecDtoList.stream().flatMap(item -> {
-            List<SkuSpecLink> principalMaterialSkuSpecLinkList = item.getPrincipalMaterialSkuSpecLinkList();
-            if (principalMaterialSkuSpecLinkList == null) {
-                principalMaterialSkuSpecLinkList = Collections.emptyList();
-            } else {
-                for (SkuSpecLink skuSpecLink : principalMaterialSkuSpecLinkList) {
-                    skuSpecLink.setId(IdWorker.getId());
-                    skuSpecLink.setSkuId(item.getSkuId());
-                    skuSpecLink.setSkuSpecId(item.getId());
-                    skuSpecLink.setDepartmentId(SecurityUtils.getDeptId());
-                    skuSpecLink.setType(1);
-                }
-            }
-
-            List<SkuSpecLink> expressPackingSkuSpecLinkList = item.getExpressPackingSkuSpecLinkList();
-            if (expressPackingSkuSpecLinkList == null) {
-                expressPackingSkuSpecLinkList = Collections.emptyList();
-            } else {
-                for (SkuSpecLink skuSpecLink : expressPackingSkuSpecLinkList) {
-                    skuSpecLink.setId(IdWorker.getId());
-                    skuSpecLink.setSkuId(item.getSkuId());
-                    skuSpecLink.setSkuSpecId(item.getId());
-                    skuSpecLink.setDepartmentId(SecurityUtils.getDeptId());
-                    skuSpecLink.setType(2);
-                }
-            }
-            return Stream.concat(principalMaterialSkuSpecLinkList.stream(), expressPackingSkuSpecLinkList.stream());
-        }).collect(Collectors.toList());
+        // 编辑sku规格关联快递和包材
+        editSkuSpecLinkList(skuId, skuSpecDtoList);
 
-        this.updateById(skuDto);
-        skuSpecService.saveOrUpdateBatch(skuSpecDtoList.stream().map(item -> (SkuSpec) item).collect(Collectors.toList()));
-        skuSpecLinkService.saveOrUpdateBatch(skuSpecLinkList);
     }
 
     @Transactional(rollbackFor = Exception.class)
@@ -253,7 +178,11 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
         skuSpecLinkService.remove(q -> q.eq(SkuSpecLink::getSkuId, id));
     }
 
+    /**
+     * 创建sku规格关联
+     */
     private List<SkuSpecLinkVo> createSkuSpecLinkVoList(List<SkuSpecLink> skuSpecLinkList, Map<Long, BomSpec> bomSpecMap) {
+
         if (ObjectUtil.isEmpty(skuSpecLinkList)) {
             return Collections.emptyList();
         }
@@ -266,6 +195,79 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
             }
             return skuSpecLinkVo;
         }).collect(Collectors.toList());
+
+    }
+
+    /**
+     * 编辑sku规格
+     */
+    private void editSkuSpecList(Long skuId, List<SkuSpecDto> skuSpecDtoList) {
+
+        List<Long> skuSpecIdList = skuSpecDtoList.stream().map(SkuSpec::getId)
+                .filter(ObjectUtil::isNotNull).collect(Collectors.toList());
+
+        skuSpecService.remove(q -> q
+                .eq(SkuSpec::getSkuId, skuId)
+                .notIn(ObjectUtil.isNotEmpty(skuSpecIdList), BaseIdPo::getId, skuSpecIdList));
+
+        List<SkuSpec> skuSpecList = skuSpecDtoList.stream()
+                .peek(item -> item.setSkuId(skuId))
+                .map(item -> (SkuSpec) item)
+                .collect(Collectors.toList());
+        skuSpecService.saveOrUpdateBatch(skuSpecList);
+
+    }
+
+    /**
+     * 编辑sku规格关联快递和包材
+     */
+    private void editSkuSpecLinkList(Long skuId, List<SkuSpecDto> skuSpecDtoList) {
+
+        List<Long> skuSpecLinkIdList = skuSpecDtoList.stream()
+                .flatMap(item -> Stream.concat(
+                        item.getPackagingMaterialList().stream(),
+                        item.getExpressPackingList().stream()))
+                .map(BaseIdPo::getId)
+                .filter(ObjectUtil::isNotNull)
+                .collect(Collectors.toList());
+
+        skuSpecLinkService.remove(q -> q
+                .eq(SkuSpecLink::getSkuId, skuId)
+                .eq(SkuSpecLink::getDepartmentId, SecurityUtils.getDeptId())
+                .notIn(ObjectUtil.isNotEmpty(skuSpecLinkIdList), BaseIdPo::getId, skuSpecLinkIdList));
+
+        List<SkuSpecLink> skuSpecLinkList = createSkuSpecLink(skuSpecDtoList);
+        skuSpecLinkService.saveOrUpdateBatch(skuSpecLinkList);
+
+    }
+
+    /**
+     * 创建sku规格关联快递和包材
+     */
+    private List<SkuSpecLink> createSkuSpecLink(List<SkuSpecDto> skuSpecDtoList) {
+
+        return skuSpecDtoList.stream().flatMap(item -> {
+
+            List<SkuSpecLink> packagingMaterialList = item.getPackagingMaterialList();
+            for (SkuSpecLink skuSpecLink : packagingMaterialList) {
+                skuSpecLink.setSkuId(item.getSkuId());
+                skuSpecLink.setSkuSpecId(item.getId());
+                skuSpecLink.setDepartmentId(SecurityUtils.getDeptId());
+                skuSpecLink.setType(1);
+            }
+
+            List<SkuSpecLink> expressPackingList = item.getExpressPackingList();
+            for (SkuSpecLink skuSpecLink : expressPackingList) {
+                skuSpecLink.setSkuId(item.getSkuId());
+                skuSpecLink.setSkuSpecId(item.getId());
+                skuSpecLink.setDepartmentId(SecurityUtils.getDeptId());
+                skuSpecLink.setType(2);
+            }
+
+            return Stream.concat(packagingMaterialList.stream(), expressPackingList.stream());
+
+        }).collect(Collectors.toList());
+
     }
 
 }

+ 1 - 1
sd-framework/src/main/java/com/sd/framework/controller/SdDictController.java

@@ -17,7 +17,7 @@ public class SdDictController {
     private DictCommonDataService dictCommonDataService;
 
     /**
-     * 申购单分页
+     * 字典对象
      */
     @PostMapping("/allDictMap")
     public Map<String, List<DictCommonData>> allDictMap() {