Quellcode durchsuchen

新增采购退货

fgd vor 1 Jahr
Ursprung
Commit
be6f313126

+ 7 - 0
sd-business/src/main/java/com/sd/business/controller/purchase/PurchaseController.java

@@ -89,4 +89,11 @@ public class PurchaseController {
         purchaseService.purchaseTermination(dto.getId());
     }
 
+    /**
+     * 采购合同下拉框列表
+     */
+    @PostMapping("/getPurchaseSelectList")
+    public Page<PurchaseVo> getPurchaseSelectList(@RequestBody PurchaseSelectDto dto) {
+        return purchaseService.getPurchaseSelectList(dto);
+    }
 }

+ 4 - 0
sd-business/src/main/java/com/sd/business/entity/purchase/dto/PurchaseReturnSelectDto.java

@@ -15,4 +15,8 @@ import lombok.Setter;
 @Setter
 public class PurchaseReturnSelectDto extends BaseSelectDto {
 
+    /**
+     * 流程状态 0未发起 1进行中 2已通过 3已驳回 4已作废
+     */
+    private Integer flowStatus;
 }

+ 2 - 2
sd-business/src/main/java/com/sd/business/entity/purchase/vo/PurchaseReturnBomVo.java

@@ -42,9 +42,9 @@ public class PurchaseReturnBomVo extends PurchaseReturnBom {
     private BigDecimal purchaseQuantity;
 
     /**
-     * 货数量
+     * 可退货数量
      */
-    private BigDecimal arrivalQuantity;
+    private BigDecimal canReturnQuantity;
 
     /**
      * 已退货数量

+ 1 - 1
sd-business/src/main/java/com/sd/business/entity/purchase/vo/PurchaseReturnDetailVo.java

@@ -19,5 +19,5 @@ public class PurchaseReturnDetailVo extends PurchaseReturn {
     /**
      * 退货bom列表
      */
-    List<PurchaseReturnBomVo> returnBomList;
+    List<PurchaseReturnBomVo> purchaseReturnBomList;
 }

+ 3 - 0
sd-business/src/main/java/com/sd/business/flow/OrderFlow.java

@@ -62,6 +62,9 @@ public class OrderFlow extends FlowDelegate {
 
     @Override
     public void end(Long flowId, Long businessId, JSONObject submitData) {
+        OrderInfoDto dto = submitData.toJavaObject(OrderInfoDto.class);
+        orderService.edit(dto);
+
         // 查询委外订单是否存在包材
         Boolean isExist = orderService.isExistOrderSkuBom(businessId);
 

+ 2 - 1
sd-business/src/main/java/com/sd/business/flow/PurchaseReturnFlow.java

@@ -10,6 +10,7 @@ import com.ruoyi.common.utils.SecurityUtils;
 import com.sd.business.entity.purchase.dto.PurchaseReturnDto;
 import com.sd.business.entity.purchase.po.PurchaseReturn;
 import com.sd.business.entity.purchase.po.PurchaseReturnBom;
+import com.sd.business.entity.warehouse.constant.WarehouseConstant;
 import com.sd.business.service.inventory.InventoryService;
 import com.sd.business.service.purchase.PurchaseReturnBomService;
 import com.sd.business.service.purchase.PurchaseReturnService;
@@ -132,7 +133,7 @@ public class PurchaseReturnFlow extends FlowDelegate {
                         PurchaseReturnBom::getReturnQuantity,
                         BigDecimal::add
                 ));
-        inventoryService.unlockPurchaseDefectiveStorage(bomMap);
+        inventoryService.unlockStorage(bomMap, WarehouseConstant.PURCHASE_DEFECTIVE);
     }
 
     /**

+ 19 - 7
sd-business/src/main/java/com/sd/business/service/purchase/impl/PurchaseReturnServiceImpl.java

@@ -71,6 +71,7 @@ public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper,
     public Page<PurchaseReturnVo> getPage(PurchaseReturnSelectDto dto) {
         IWrapper<PurchaseReturn> wrapper = getWrapper();
         wrapper.orderByDesc("pr", PurchaseReturn::getId);
+        wrapper.eq("pr", PurchaseReturn::getFlowStatus, dto.getFlowStatus());
 
         // 查询采购退货数据
         Page<PurchaseReturnVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
@@ -116,11 +117,11 @@ public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper,
         Map<Long, BomSpec> bomSpecMap = bomSpecService.mapKEntity(BaseIdPo::getId, q -> q.in(BaseIdPo::getId, bomSpecIds));
         purchaseReturnBomList.forEach(item -> {
             item.setPurchaseReturnId(purchaseReturnDto.getId());
-            BomSpec bomSpec = bomSpecMap.get(item.getPurchaseBomId());
+            BomSpec bomSpec = bomSpecMap.get(item.getBomSpecId());
             if (bomSpec == null) {
                 throw new ServiceException("未知bom规格id!");
             }
-            Inventory inventory = inventoryMap.get(item.getPurchaseBomId());
+            Inventory inventory = inventoryMap.get(item.getBomSpecId());
             if (inventory == null || inventory.getQuantity().compareTo(item.getReturnQuantity()) < 0) {
                 throw new ServiceException("退货失败,品名为:" + bomSpec.getName() + " 的bom库存不足,库存为:" +
                         (inventory == null ? BigDecimal.ZERO : inventory.getQuantity()));
@@ -133,13 +134,14 @@ public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper,
                         BigDecimal::add
                 ));
 
-        boolean result = inventoryService.lockPurchaseDefectiveStorage(map);
+        boolean result = inventoryService.lockStorage(map, WarehouseConstant.PURCHASE_DEFECTIVE);
         if (!result) {
             throw new ServiceException("库存不足,退货失败");
         }
         purchaseReturnBomService.saveBatch(purchaseReturnBomList);
     }
 
+    @DSTransactional
     @Override
     public void edit(PurchaseReturnDto purchaseReturnDto) {
         // 状态为未发起时, 流程重新发起
@@ -197,13 +199,13 @@ public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper,
         // 对原数据有修改时,更新数据
         if (!lockBomMap.isEmpty() || !unlockBomMap.isEmpty()) {
             if (!lockBomMap.isEmpty()) {
-                boolean result = inventoryService.lockPurchaseDefectiveStorage(lockBomMap);
+                boolean result = inventoryService.lockStorage(lockBomMap, WarehouseConstant.PURCHASE_DEFECTIVE);
                 if (!result) {
                     throw new ServiceException("库存不足,新增退货失败");
                 }
             }
             if (!unlockBomMap.isEmpty()) {
-                inventoryService.unlockPurchaseDefectiveStorage(unlockBomMap);
+                inventoryService.unlockStorage(unlockBomMap, WarehouseConstant.PURCHASE_DEFECTIVE);
             }
             purchaseReturnBomService.editLinked(newPurchaseReturnBomList, PurchaseReturnBom::getPurchaseReturnId, purchaseReturnDto.getId());
         }
@@ -215,7 +217,7 @@ public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper,
         PurchaseReturnDetailVo result = BeanUtil.toBean(purchaseReturn, PurchaseReturnDetailVo.class);
         // 查询bom列表
         List<PurchaseReturnBomVo> purchaseReturnBomList = purchaseReturnBomService.selectListByPurchaseReturnId(purchaseReturn.getId());
-        result.setReturnBomList(purchaseReturnBomList);
+        result.setPurchaseReturnBomList(purchaseReturnBomList);
         return result;
     }
 
@@ -242,7 +244,7 @@ public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper,
             vo.setBomSpecName(bomSpec.getName());
             vo.setUnitPrice(item.getUnitPrice());
             vo.setPurchaseQuantity(item.getPurchaseQuantity());
-            vo.setArrivalQuantity(item.getArrivalQuantity());
+            vo.setCanReturnQuantity(item.getArrivalQuantity().subtract(item.getReturnQuantity()));
             vo.setFinishReturnQuantity(item.getReturnQuantity());
             return vo;
         }).collect(Collectors.toList());
@@ -273,5 +275,15 @@ public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper,
         lockPurchaseDefective.setLockStorage(StatusConstant.YES);
         lockPurchaseDefective.setInOutStorageBomList(inOutStorageBomList);
         inOutStorageService.add(lockPurchaseDefective);
+        // 更新退货数量
+        Map<Long, BigDecimal> returnQuantityMap = purchaseReturnBomList.stream()
+                .collect(Collectors.toMap(
+                        PurchaseReturnBom::getPurchaseBomId,
+                        PurchaseReturnBom::getReturnQuantity,
+                        (v1, v2) -> v2)
+                );
+        List<PurchaseBom> list = purchaseBomService.list(q -> q.in(BaseIdPo::getId, returnQuantityMap.keySet()));
+        list.forEach(item -> item.setReturnQuantity(item.getReturnQuantity().add(returnQuantityMap.get(item.getId()))));
+        purchaseBomService.updateBatchById(list);
     }
 }

+ 5 - 0
sd-business/src/main/resources/mapper/production/ProductionCostMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.sd.business.mapper.production.ProductionCostMapper">
+
+</mapper>