Sfoglia il codice sorgente

新增生产任务和完成生产任务功能

fgd 1 anno fa
parent
commit
156549edd7

+ 12 - 2
sd-business/src/main/java/com/sd/business/flow/OrderFlow.java

@@ -13,6 +13,7 @@ import com.sd.business.entity.order.po.OrderFlowExample;
 import com.sd.business.entity.order.po.OrderInfo;
 import com.sd.business.service.order.OrderFlowExampleService;
 import com.sd.business.service.order.OrderService;
+import com.sd.business.service.production.ProductionTaskService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -30,6 +31,9 @@ public class OrderFlow extends FlowDelegate {
     @Autowired
     private OrderFlowExampleService orderFlowExampleService;
 
+    @Autowired
+    private ProductionTaskService productionTaskService;
+
     @Override
     public String getFlowKey() {
         return "order";
@@ -58,15 +62,21 @@ public class OrderFlow extends FlowDelegate {
 
     @Override
     public void end(Long flowId, Long businessId, JSONObject submitData) {
+        // 查询委外订单是否存在包材
+        Boolean isExist = orderService.isExistOrderSkuBom(businessId);
 
         orderService.update(q -> q
                 .eq(BaseIdPo::getId, businessId)
                 .set(OrderInfo::getFlowStatus, FlowStatusEnum.PASS.getKey())
-                // 判断委外订单是否存在包材,不存在则直接修改为生产中
-                .set(OrderInfo::getStatus, orderService.isExistOrderSkuBom(businessId) ? OrderStatusEnum.IN_PRODUCTION.getKey() : OrderStatusEnum.STOCK_PREPARATION.getKey())
+                // 委外订单不存在包材则直接修改为生产中
+                .set(OrderInfo::getStatus, !isExist ? OrderStatusEnum.IN_PRODUCTION.getKey() : OrderStatusEnum.STOCK_PREPARATION.getKey())
                 .set(BasePo::getUpdateTime, new Date())
                 .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
         );
+        if (!isExist) {
+            // 生成生产任务和工单
+            productionTaskService.addTaskAndWorkOrder(businessId);
+        }
 
         orderFlowExampleService.update(q -> q.eq(OrderFlowExample::getOrderId, businessId)
                 .eq(OrderFlowExample::getFlowId, flowId)

+ 26 - 0
sd-business/src/main/java/com/sd/business/service/order/impl/OrderServiceImpl.java

@@ -10,6 +10,7 @@ import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.file.utils.ObsFileUtil;
+import com.fjhx.flow.enums.FlowStatusEnum;
 import com.ruoyi.common.annotation.LogicIgnore;
 import com.ruoyi.common.constant.StatusConstant;
 import com.ruoyi.common.core.domain.BaseIdPo;
@@ -48,6 +49,7 @@ import com.sd.business.service.inventory.InventoryService;
 import com.sd.business.service.order.*;
 import com.sd.business.service.price.PriceBillingStandardDetailService;
 import com.sd.business.service.price.PriceBillingStandardService;
+import com.sd.business.service.production.ProductionTaskService;
 import com.sd.business.service.sku.SkuSpecService;
 import com.sd.business.service.statement.StatementOfAccountService;
 import com.sd.business.util.CodeEnum;
@@ -113,6 +115,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
     @Autowired
     private ISysUserService sysUserService;
 
+    @Autowired
+    private ProductionTaskService productionTaskService;
+
     @Override
     public Page<OrderInfoVo> getPage(OrderSelectDto dto) {
         IWrapper<OrderInfo> wrapper = getWrapper();
@@ -285,6 +290,17 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
                 .collect(Collectors.toList());
         orderSkuBomService.saveBatch(orderSkuBomList);
 
+        // 是委外订单并且没有包材时,修改订单状态为生产中,并生成生产任务和工单
+        if (ObjectUtil.notEqual(orderDto.getStatus(), OrderStatusEnum.DRAFT.getKey())
+                && ObjectUtil.equal(orderDto.getFlowStatus(), FlowStatusEnum.PASS.getKey())
+                && ObjectUtil.equals(orderDto.getType(), 2)
+                && ObjectUtil.isEmpty(orderSkuBomList)) {
+            orderDto.setStatus(OrderStatusEnum.IN_PRODUCTION.getKey());
+            // 生成生产任务和工单
+            productionTaskService.addTaskAndWorkOrder(orderDto.getId());
+            this.update(q -> q.set(OrderInfo::getStatus, OrderStatusEnum.IN_PRODUCTION.getKey()).eq(BaseIdPo::getId, orderDto.getId()));
+        }
+
         // 保存订单包装信息
         if (ObjectUtil.isNotEmpty(orderDto.getOrderPackageBomList())) {
             List<OrderPackageBomDto> tempOrderPackageBomList = orderDto.getOrderPackageBomList();
@@ -336,6 +352,16 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
                 .collect(Collectors.toList());
         orderSkuBomService.editLinked(orderSkuBomList, OrderSkuBom::getOrderId, dto.getId());
 
+        // 是委外订单并且没有包材时,修改订单状态为生产中,并生成生产任务和工单
+        if (ObjectUtil.equals(dto.getStatus(), OrderStatusEnum.STOCK_PREPARATION.getKey())
+                && ObjectUtil.equals(dto.getType(), 2)
+                && ObjectUtil.isEmpty(orderSkuBomList)) {
+            dto.setStatus(OrderStatusEnum.IN_PRODUCTION.getKey());
+            // 生成生产任务和工单
+            productionTaskService.addTaskAndWorkOrder(dto.getId());
+            this.update(q -> q.set(OrderInfo::getStatus, OrderStatusEnum.IN_PRODUCTION.getKey()).eq(BaseIdPo::getId, dto.getId()));
+        }
+
         // 更新订单产品包装信息
         if (ObjectUtil.isNotEmpty(dto.getOrderPackageBomList())) {
             List<OrderPackageBomDto> tempOrderPackageBomList = dto.getOrderPackageBomList();

+ 20 - 0
sd-business/src/main/java/com/sd/business/service/production/ProductionTaskService.java

@@ -2,10 +2,14 @@ package com.sd.business.service.production;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.core.service.BaseService;
+import com.sd.business.entity.production.dto.ProductionTaskDto;
 import com.sd.business.entity.production.dto.ProductionTaskSelectDto;
 import com.sd.business.entity.production.po.ProductionTask;
 import com.sd.business.entity.production.vo.ProductionTaskVo;
 
+import java.util.Date;
+import java.util.List;
+
 
 /**
  * <p>
@@ -22,4 +26,20 @@ public interface ProductionTaskService extends BaseService<ProductionTask> {
      */
     Page<ProductionTaskVo> getPage(ProductionTaskSelectDto dto);
 
+
+    /**
+     * 根据订单生成生产任务和工单
+     * @param orderId
+     */
+    void addTaskAndWorkOrder(Long orderId);
+
+    /**
+     * 完成生产任务
+     */
+    void completeTask(Long orderId, Date completeTime);
+
+    /**
+     * 批量完成生产任务
+     */
+    void completeTaskBatch(List<ProductionTaskDto> productionTaskDtoList);
 }

+ 12 - 0
sd-business/src/main/java/com/sd/business/service/production/impl/ProductionOrderServiceImpl.java

@@ -18,6 +18,7 @@ import com.sd.business.entity.production.po.ProductionTask;
 import com.sd.business.entity.production.vo.ProductionOrderDetailVo;
 import com.sd.business.entity.production.vo.ProductionOrderScheduleVo;
 import com.sd.business.entity.production.vo.ProductionOrderVo;
+import com.sd.business.entity.statement.dto.StatementOfAccountDto;
 import com.sd.business.mapper.production.ProductionOrderMapper;
 import com.sd.business.service.bom.BomSpecService;
 import com.sd.business.service.order.OrderPackageBomService;
@@ -27,6 +28,7 @@ import com.sd.business.service.production.ProductionOrderService;
 import com.sd.business.service.production.ProductionTaskService;
 import com.sd.business.service.sku.SkuService;
 import com.sd.business.service.sku.SkuSpecService;
+import com.sd.business.service.statement.StatementOfAccountService;
 import com.sd.framework.util.Assert;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -62,6 +64,9 @@ public class ProductionOrderServiceImpl implements ProductionOrderService {
     @Autowired
     private OrderPackageBomService orderPackageBomService;
 
+    @Autowired
+    private StatementOfAccountService statementOfAccountService;
+
     @Override
     public Page<ProductionOrderVo> getPage(ProductionOrderDto dto) {
 
@@ -155,6 +160,13 @@ public class ProductionOrderServiceImpl implements ProductionOrderService {
                 .set(OrderInfo::getShippingTime, date)
                 .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
                 .set(BasePo::getUpdateTime, date));
+
+        // 订单生产完成时,生产任务一键完成,并生成对账单
+        productionTaskService.completeTask(orderId, date);
+        StatementOfAccountDto statement = new StatementOfAccountDto();
+        statement.setDepartmentId(orderInfo.getDepartmentId());
+        statement.setOrderIdList(Collections.singletonList(orderInfo.getId()));
+        statementOfAccountService.add(statement);
     }
 
     private List<ProductionOrderDetailVo.SkuSpec> getSkuSpecList(Long orderId) {

+ 134 - 0
sd-business/src/main/java/com/sd/business/service/production/impl/ProductionTaskServiceImpl.java

@@ -1,15 +1,34 @@
 package com.sd.business.service.production.impl;
 
+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.exception.ServiceException;
 import com.ruoyi.common.utils.wrapper.IWrapper;
+import com.sd.business.entity.order.po.OrderInfo;
+import com.sd.business.entity.order.po.OrderSku;
+import com.sd.business.entity.production.dto.ProductionTaskDto;
 import com.sd.business.entity.production.dto.ProductionTaskSelectDto;
 import com.sd.business.entity.production.po.ProductionTask;
+import com.sd.business.entity.production.po.ProductionWorkOrder;
 import com.sd.business.entity.production.vo.ProductionTaskVo;
+import com.sd.business.entity.sku.po.Sku;
+import com.sd.business.entity.sku.po.SkuSpec;
 import com.sd.business.mapper.production.ProductionTaskMapper;
+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.sku.SkuService;
+import com.sd.business.service.sku.SkuSpecService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.Collectors;
+
 
 /**
  * <p>
@@ -22,6 +41,21 @@ import org.springframework.stereotype.Service;
 @Service
 public class ProductionTaskServiceImpl extends ServiceImpl<ProductionTaskMapper, ProductionTask> implements ProductionTaskService {
 
+    @Autowired
+    private ProductionWorkOrderService productionWorkOrderService;
+
+    @Autowired
+    private OrderService orderService;
+
+    @Autowired
+    private OrderSkuService orderSkuService;
+
+    @Autowired
+    private SkuService skuService;
+
+    @Autowired
+    private SkuSpecService skuSpecService;
+
     @Override
     public Page<ProductionTaskVo> getPage(ProductionTaskSelectDto dto) {
         IWrapper<ProductionTask> wrapper = getWrapper();
@@ -30,4 +64,104 @@ public class ProductionTaskServiceImpl extends ServiceImpl<ProductionTaskMapper,
         return page;
     }
 
+    @Override
+    public void addTaskAndWorkOrder(Long orderId) {
+        OrderInfo orderInfo = orderService.getById(orderId);
+        if (orderInfo == null) {
+            throw new ServiceException("未知订单");
+        }
+
+        List<ProductionTask> productionTaskList = new ArrayList<>();
+        List<ProductionWorkOrder> productionWorkOrderList = new ArrayList<>();
+
+        List<OrderSku> orderSkuList = orderSkuService.list(q -> q.eq(OrderSku::getOrderId, orderId));
+
+        Map<String, ProductionTask> skuSpecIdProductionTaskMap = new HashMap<>();
+
+        int num = 1;
+
+        for (OrderSku orderSku : orderSkuList) {
+
+            Long skuSpecId = orderSku.getSkuSpecId();
+            Long bomSpecId = orderSku.getBomSpecId();
+            Integer printType = orderSku.getPrintType();
+            BigDecimal quantity = orderSku.getQuantity();
+
+            ProductionTask productionTask = skuSpecIdProductionTaskMap.computeIfAbsent(
+                    skuSpecId + ":" + bomSpecId + ":" + printType,
+                    item -> {
+                        SkuSpec skuSpec = skuSpecService.getById(skuSpecId);
+                        Sku sku = skuService.getById(skuSpec.getSkuId());
+
+                        ProductionTask tempProductionTask = new ProductionTask();
+                        tempProductionTask.setId(IdWorker.getId());
+                        tempProductionTask.setOrderId(orderId);
+                        tempProductionTask.setSkuSpecId(skuSpecId);
+                        tempProductionTask.setBomSpecId(bomSpecId);
+                        tempProductionTask.setCraftProductionLineId(sku.getCraftProductionLineId());
+                        tempProductionTask.setMachinedPanel(skuSpec.getMachinedPanel());
+                        tempProductionTask.setPrintType(printType);
+                        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.setCode(orderInfo.getCode() + String.format("-%05d", num));
+                productionWorkOrder.setStatus(0);
+                productionWorkOrderList.add(productionWorkOrder);
+                num++;
+            }
+
+        }
+
+        if (productionTaskList.size() > 0) {
+            this.saveBatch(productionTaskList);
+        }
+
+        if (productionWorkOrderList.size() > 0) {
+            productionWorkOrderService.saveBatch(productionWorkOrderList);
+        }
+    }
+
+    @Override
+    public void completeTask(Long orderId, Date completeTime) {
+        List<ProductionTask> list = this.list(q -> q.eq(ProductionTask::getOrderId, orderId));
+        if (ObjectUtil.isEmpty(list)) {
+            return;
+        }
+        List<ProductionTask> productionTaskList = list.stream().peek(item -> {
+            item.setCompleteQuantity(item.getProductionQuantity());
+            item.setCompleteTime(completeTime);
+        }).collect(Collectors.toList());
+        // 更新生产任务
+        this.updateBatchById(productionTaskList);
+    }
+
+    @Override
+    public void completeTaskBatch(List<ProductionTaskDto> productionTaskDtoList) {
+        List<ProductionTask> productionTaskList = new ArrayList<>();
+        for (ProductionTaskDto dto : productionTaskDtoList) {
+            List<ProductionTask> list = this.list(q -> q.eq(ProductionTask::getOrderId, dto.getOrderId()));
+            if (ObjectUtil.isEmpty(list)) {
+                continue;
+            }
+            List<ProductionTask> taskList = list.stream().peek(item -> {
+                item.setCompleteQuantity(item.getProductionQuantity());
+                item.setCompleteTime(dto.getCompleteTime());
+            }).collect(Collectors.toList());
+            productionTaskList.addAll(taskList);
+        }
+        if (ObjectUtil.isEmpty(productionTaskList)) {
+            // 更新生产任务
+            this.updateBatchById(productionTaskList);
+        }
+    }
 }

+ 19 - 6
sd-business/src/main/java/com/sd/business/service/statement/impl/StatementOfAccountServiceImpl.java

@@ -177,18 +177,31 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void add(StatementOfAccountDto statementOfAccountDto) {
-
         List<Long> orderIdList = statementOfAccountDto.getOrderIdList();
 
-        statementOfAccountDto.setCode(CodeEnum.STATEMENT_OF_ACCOUNT_CODE.getCode());
-        statementOfAccountDto.setType(1);
-        statementOfAccountDto.setTimePeriod(new Date());
-        this.save(statementOfAccountDto);
+        // 判断当前事业部今日是否生成对账单
+        Long departmentId = statementOfAccountDto.getDepartmentId();
+        Date date = new Date();
+        Date beginDate = DateUtil.beginOfDay(date);
+        Date endDate = DateUtil.endOfDay(date);
+        StatementOfAccount statementOfAccount = this.getOne(q -> q
+                .eq(StatementOfAccount::getDepartmentId, departmentId)
+                .between(StatementOfAccount::getTimePeriod, beginDate, endDate));
+
+        if (statementOfAccount == null) {
+            statementOfAccount = new StatementOfAccount();
+            statementOfAccount.setDepartmentId(departmentId);
+            statementOfAccount.setCode(CodeEnum.STATEMENT_OF_ACCOUNT_CODE.getCode());
+            statementOfAccount.setType(2);
+            statementOfAccount.setTimePeriod(new Date());
+            this.save(statementOfAccount);
+        }
+        Long accountId = statementOfAccount.getId();
 
         if (ObjectUtil.isNotEmpty(orderIdList)) {
             orderService.update(q -> q
                     .in(BaseIdPo::getId, orderIdList)
-                    .set(OrderInfo::getStatementOfAccountId, statementOfAccountDto.getId())
+                    .set(OrderInfo::getStatementOfAccountId, accountId)
             );
         }
 

+ 13 - 0
sd-wln/src/main/java/com/sd/wln/service/impl/WlnStatementOfAccountImpl.java

@@ -6,9 +6,11 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.sd.business.entity.order.enums.OrderStatusEnum;
 import com.sd.business.entity.order.po.OrderInfo;
 import com.sd.business.entity.outbound.po.OutboundOrder;
+import com.sd.business.entity.production.dto.ProductionTaskDto;
 import com.sd.business.entity.statement.po.StatementOfAccount;
 import com.sd.business.service.order.OrderService;
 import com.sd.business.service.outbound.OutboundOrderService;
+import com.sd.business.service.production.ProductionTaskService;
 import com.sd.business.service.statement.StatementOfAccountService;
 import com.sd.wln.service.WlnStatementOfAccount;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -30,12 +32,16 @@ public class WlnStatementOfAccountImpl implements WlnStatementOfAccount {
     @Autowired
     private OrderService orderService;
 
+    @Autowired
+    private ProductionTaskService productionTaskService;
+
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void createStatementOfAccount() {
 
         List<StatementOfAccount> saveStatementOfAccountList = new ArrayList<>();
         List<OrderInfo> editOrderInfoList = new ArrayList<>();
+        List<ProductionTaskDto> editProductionTaskList = new ArrayList<>();
 
         // 获取没绑定对账单的订单
         List<OrderInfo> orderList = orderService.list(q -> q
@@ -103,11 +109,18 @@ public class WlnStatementOfAccountImpl implements WlnStatementOfAccount {
             if (order.getStatus().equals(OrderStatusEnum.IN_PRODUCTION.getKey())) {
                 editOrderInfo.setStatus(OrderStatusEnum.COMPLETION_PRODUCTION.getKey());
                 editOrderInfo.setShippingTime(map.get(order.getWlnCode()));
+                // 添加生产任务信息
+                ProductionTaskDto productionTaskDto = new ProductionTaskDto();
+                productionTaskDto.setOrderId(order.getId());
+                productionTaskDto.setCompleteTime(map.get(order.getWlnCode()));
+                editProductionTaskList.add(productionTaskDto);
             }
             editOrderInfoList.add(editOrderInfo);
         }
 
         orderService.updateBatchById(editOrderInfoList);
+        // 订单生产完成时,生产任务一键完成
+        productionTaskService.completeTaskBatch(editProductionTaskList);
 
         if (saveStatementOfAccountList.size() > 0) {
             statementOfAccountService.saveBatch(saveStatementOfAccountList);