Browse Source

对账单新增无理由成品出库,同步出库单生产完成时间调整

fgd 1 year ago
parent
commit
0630cb7e63

+ 15 - 0
sd-business/src/main/java/com/sd/business/controller/statement/StatementOfAccountMergeController.java

@@ -125,4 +125,19 @@ public class StatementOfAccountMergeController {
         statementOfAccountMergeService.exportDeliveryOfGoodsExcel(idList);
     }
 
+    /**
+     * 获取无理由订单没有销货出库的订单列表
+     */
+    @PostMapping("/getNotSalesOutOfWarehouseOrder")
+    public List<Long> getNotSalesOutOfWarehouseOrder(@RequestBody GetDocumentDto dto) {
+        return statementOfAccountMergeService.getNotSalesOutOfWarehouseOrder(dto);
+    }
+
+    /**
+     * 无理由订单成品出库
+     */
+    @PostMapping("/salesOutOfWarehouse")
+    public void salesOutOfWarehouse(@RequestBody List<Long> idList) {
+        statementOfAccountMergeService.salesOutOfWarehouseByOrderIds(idList);
+    }
 }

+ 5 - 0
sd-business/src/main/java/com/sd/business/service/inventory/InventoryFinishedOrderService.java

@@ -71,4 +71,9 @@ public interface InventoryFinishedOrderService extends BaseService<InventoryFini
      * @param orderIdList
      */
     void noSourceSaleOutOfWarehouse(List<Long> orderIdList);
+
+    /**
+     * 根据订单id列表查询没有销货出库的订单
+     */
+    List<Long> getNotSalesOutOfWarehouseOrderByIds(List<Long> orderIdList);
 }

+ 9 - 0
sd-business/src/main/java/com/sd/business/service/inventory/impl/InventoryFinishedOrderServiceImpl.java

@@ -385,4 +385,13 @@ public class InventoryFinishedOrderServiceImpl extends ServiceImpl<InventoryFini
         inventoryFinishedOrderDetailService.saveBatch(finishedOrderDetailList);
     }
 
+    @Override
+    public List<Long> getNotSalesOutOfWarehouseOrderByIds(List<Long> orderIdList) {
+        List<InventoryFinishedOrder> list = this.list(q -> q.in(InventoryFinishedOrder::getOrderInfoId, orderIdList)
+                .eq(InventoryFinishedOrder::getStatus, StatusConstant.NO));
+        List<Long> notInInventoryOrderIds = list.stream().map(InventoryFinishedOrder::getOrderInfoId).collect(Collectors.toList());
+        orderIdList.removeAll(notInInventoryOrderIds);
+        return orderIdList;
+    }
+
 }

+ 3 - 2
sd-business/src/main/java/com/sd/business/service/order/impl/OrderServiceImpl.java

@@ -319,7 +319,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
         // 委外订单修改金额
         if (ObjectUtil.equals(orderDto.getType(), 2)) {
             orderDto.setProductTotalAmount(BigDecimal.ZERO);
-            orderDto.setLssueFee(BigDecimal.ZERO);
             orderDto.setDeliveryMaterialsFee(BigDecimal.ZERO);
             orderDto.setManagementFee(BigDecimal.ZERO);
             orderDto.setPackingLabor(orderDto.getPackingLabor().multiply(new BigDecimal(2)));
@@ -559,8 +558,10 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
         // 订单为委外订单时,订单分类为委外订单,订单费用修改
         if (Objects.equals(dto.getType(), 2)) {
             dto.setClassify(OrderClassifyEnum.OUTSOURCE_ORDER.getKey());
+            if (!Objects.equals(dto.getSource(), 1)) {
+                dto.setLssueFee(BigDecimal.ZERO);
+            }
             dto.setProductTotalAmount(BigDecimal.ZERO);
-            dto.setLssueFee(BigDecimal.ZERO);
             dto.setDeliveryMaterialsFee(BigDecimal.ZERO);
             dto.setManagementFee(BigDecimal.ZERO);
             dto.setPackingLabor(dto.getPackingLabor().multiply(new BigDecimal(2)));

+ 4 - 1
sd-business/src/main/java/com/sd/business/service/production/impl/ProductionOrderServiceImpl.java

@@ -1,5 +1,6 @@
 package com.sd.business.service.production.impl;
 
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.core.domain.BasePo;
@@ -73,13 +74,15 @@ public class ProductionOrderServiceImpl implements ProductionOrderService {
 
         IWrapper<ProductionOrderVo> wrapper = IWrapper.getWrapper();
         wrapper.in("oi", OrderInfo::getStatus, OrderStatusEnum.IN_PRODUCTION.getKey(), OrderStatusEnum.COMPLETION_PRODUCTION.getKey());
-        wrapper.like("oi", OrderInfo::getCode, dto.getCode());
         wrapper.like("oi", OrderInfo::getWlnCode, dto.getWlnCode());
         wrapper.eq("oi", OrderInfo::getDepartmentId, dto.getDepartmentId());
         wrapper.in("oi", OrderInfo::getTag, dto.getTagList());
         wrapper.ge("oi", OrderInfo::getDeliveryTime, dto.getBeginTime());
         wrapper.le("oi", OrderInfo::getDeliveryTime, dto.getEndTime());
         wrapper.eq("oi", OrderInfo::getStatus, dto.getStatus());
+        if (StrUtil.isNotBlank(dto.getCode())) {
+            wrapper.and(q -> q.like("oi", OrderInfo::getCode, dto.getCode()).or().like("oi", OrderInfo::getWlnCode, dto.getCode()));
+        }
 
         Page<ProductionOrderVo> page = productionOrderMapper.getPage(dto.getPage(), wrapper);
         List<ProductionOrderVo> records = page.getRecords();

+ 12 - 0
sd-business/src/main/java/com/sd/business/service/statement/StatementOfAccountMergeService.java

@@ -74,4 +74,16 @@ public interface StatementOfAccountMergeService {
      */
     void exportDeliveryOfGoodsExcel(List<Long> idList);
 
+    /**
+     * 获取无理由订单没有销货出库的订单列表
+     *
+     * @param dto
+     * @return
+     */
+    List<Long> getNotSalesOutOfWarehouseOrder(GetDocumentDto dto);
+
+    /**
+     * 无理由订单成品出库
+     */
+    void salesOutOfWarehouseByOrderIds(List<Long> idList);
 }

+ 37 - 0
sd-business/src/main/java/com/sd/business/service/statement/impl/StatementOfAccountMergeServiceImpl.java

@@ -14,6 +14,7 @@ import com.ruoyi.common.core.domain.BasePo;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.PageUtils;
 import com.sd.business.entity.excel.enums.ExcelTypeEnum;
+import com.sd.business.entity.inventory.po.InventoryFinishedOrder;
 import com.sd.business.entity.inventory.po.InventoryFinishedOrderDetail;
 import com.sd.business.entity.order.enums.OrderClassifyEnum;
 import com.sd.business.entity.order.po.OrderInfo;
@@ -28,6 +29,8 @@ import com.sd.business.entity.statement.vo.*;
 import com.sd.business.service.department.DepartmentService;
 import com.sd.business.service.excel.ExcelGenerateLogService;
 import com.sd.business.service.inventory.InventoryFinishedOrderDetailService;
+import com.sd.business.service.inventory.InventoryFinishedOrderService;
+import com.sd.business.service.inventory.InventoryFinishedService;
 import com.sd.business.service.order.OrderService;
 import com.sd.business.service.order.OrderSkuProductionCostService;
 import com.sd.business.service.order.OrderSkuService;
@@ -93,6 +96,12 @@ public class StatementOfAccountMergeServiceImpl implements StatementOfAccountMer
     private InventoryFinishedOrderDetailService inventoryFinishedOrderDetailService;
 
     @Autowired
+    private InventoryFinishedService inventoryFinishedService;
+
+    @Autowired
+    private InventoryFinishedOrderService inventoryFinishedOrderService;
+
+    @Autowired
     private OutboundOrderService outboundOrderService;
 
     @Override
@@ -528,6 +537,34 @@ public class StatementOfAccountMergeServiceImpl implements StatementOfAccountMer
         ExcelUtil.export(response, "货物交接单", "货物交接单明细", deliveryOfGoodsVOList, DeliveryOfGoodsVO.class);
     }
 
+    @Override
+    public List<Long> getNotSalesOutOfWarehouseOrder(GetDocumentDto dto) {
+        List<OrderInfo> orderList = orderService.list(q -> q.in(OrderInfo::getStatementOfAccountId, getIdList(dto))
+                .eq(OrderInfo::getClassify, OrderClassifyEnum.NO_REASON_ORDER.getKey()));
+        if (orderList.isEmpty()) {
+            return Collections.emptyList();
+        }
+        List<Long> orderIds = orderList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
+        return inventoryFinishedOrderService.getNotSalesOutOfWarehouseOrderByIds(orderIds);
+    }
+
+    @Override
+    public void salesOutOfWarehouseByOrderIds (List<Long> idList) {
+        Assert.notEmpty(idList, "订单id不能为空");
+        // 查询在成品库的订单
+        List<InventoryFinishedOrder> list = inventoryFinishedOrderService.list(q -> q
+                .in(InventoryFinishedOrder::getOrderInfoId, idList)
+                .eq(InventoryFinishedOrder::getStatus, StatusConstant.YES));
+        List<Long> orderIds = list.stream().map(InventoryFinishedOrder::getOrderInfoId).collect(Collectors.toList());
+        // 筛选出不在库订单
+        idList.removeAll(orderIds);
+        if (!idList.isEmpty()) {
+            List<OrderInfo> orderInfoList = orderService.listByIds(idList);
+            String orderCodes = orderInfoList.stream().map(OrderInfo::getWlnCode).collect(Collectors.joining(","));
+            throw new ServiceException("订单:" + orderCodes + "未在成品库中");
+        }
+        inventoryFinishedService.saleOutOfWarehouse(orderIds);
+    }
 
     private List<Long> getIdList(GetDocumentDto dto) {
 

+ 16 - 7
sd-wln/src/main/java/com/sd/wln/service/impl/WlnStatementOfAccountImpl.java

@@ -147,13 +147,22 @@ public class WlnStatementOfAccountImpl implements WlnStatementOfAccount {
         final Long finalUserId = userId;
 
         // 订单生产完成时,一键完成生产任务
-        productionWorkOrderService.update(q -> q
-                .in(ProductionWorkOrder::getOrderId, orderIdList)
-                .notIn(ProductionWorkOrder::getStatus, WorkOrderStatusEnum.PRODUCTION_ANOMALY.getKey(), WorkOrderStatusEnum.RESCHEDULE.getKey())
-                .set(ProductionWorkOrder::getStatus, WorkOrderStatusEnum.PRODUCTION_COMPLETION.getKey())
-                .set(ProductionWorkOrder::getCompleteTime, date)
-                .set(BasePo::getUpdateTime, date)
-                .set(BasePo::getUpdateUser, finalUserId));
+        if (!orderIdList.isEmpty()) {
+            Map<Long, Date> oredrCompleteTimeMap = editOrderList.stream().collect(Collectors.toMap(BaseIdPo::getId, OrderInfo::getShippingTime));
+
+            List<ProductionWorkOrder> list = productionWorkOrderService.list(q -> q
+                    .in(ProductionWorkOrder::getOrderId, orderIdList)
+                    .notIn(ProductionWorkOrder::getStatus, WorkOrderStatusEnum.PRODUCTION_ANOMALY.getKey()));
+
+            list.forEach(item -> {
+                item.setStatus(WorkOrderStatusEnum.PRODUCTION_COMPLETION.getKey());
+                item.setCompleteTime(oredrCompleteTimeMap.getOrDefault(item.getOrderId(), date));
+                item.setUpdateTime(date);
+                item.setUpdateUser(finalUserId);
+            });
+
+            productionWorkOrderService.updateBatchById(list);
+        }
 
         // 保存对账单
         if (!saveStatementOfAccountList.isEmpty()) {