lyhzzz пре 2 година
родитељ
комит
214a1ee8fb
1 измењених фајлова са 41 додато и 16 уклоњено
  1. 41 16
      src/main/java/com/fdkankan/sale/service/impl/RepairSupplyService.java

+ 41 - 16
src/main/java/com/fdkankan/sale/service/impl/RepairSupplyService.java

@@ -71,6 +71,9 @@ public class RepairSupplyService {
     }
 
     public List<RepairRegisterPartVo> partInfo(String repairId,Integer type) {
+
+        HashMap<Integer,PartLog> outMap = getPartLogMap(repairId,1);
+
         if(type == 0){  //获取备件出库单
             HashMap<Integer,PriceList> priceMap = new HashMap<>();
             List<RepairRegisterPartVo> parts = new ArrayList<>();
@@ -87,11 +90,19 @@ public class RepairSupplyService {
                     }
                 }
             }
+
             for (Integer partId : priceMap.keySet()) {
                 RepairRegisterPartVo vo = new RepairRegisterPartVo();
                 vo.setPartId(partId);
                 vo.setPartName(priceMap.get(partId).getName());
                 vo.setPartCount(priceMap.get(partId).getCount());
+                PartLog partLog = outMap.get(partId);
+                if(partLog != null){
+                    vo.setPartCount(vo.getPartCount() - partLog.getCount());
+                }
+                if(vo.getPartCount() <=0){
+                    continue;
+                }
                 Part part =  partService.getById(partId);
                 if(part != null){
                     vo.setPartNum(part.getPartNum());
@@ -103,24 +114,11 @@ public class RepairSupplyService {
         }
 
 
-
-        LambdaQueryWrapper<PartLog> wrapper2 = new LambdaQueryWrapper<>();
-        wrapper2.eq(PartLog::getRepairId,repairId);
-        wrapper2.eq(PartLog::getStatus,1);
-        List<PartLog> partLogs = partLogService.list(wrapper2);
-        HashMap<Integer,PartLog> map = new HashMap<>();
-        for (PartLog partLog : partLogs) {
-            if(map.get(partLog.getPartId()) != null){
-                PartLog partLog1 = map.get(partLog.getPartId());
-                partLog1.setCount(partLog1.getCount() + partLog.getCount());
-            }else {
-                map.put(partLog.getPartId(),partLog);
-            }
-        }
+        HashMap<Integer,PartLog> reMap = getPartLogMap(repairId,2);
 
         List<RepairRegisterPartVo> parts = new ArrayList<>();
 
-        for (Integer partId : map.keySet()) {
+        for (Integer partId : outMap.keySet()) {
             Part part =  partService.getById(partId);
             if(part == null){
                 continue;
@@ -128,13 +126,40 @@ public class RepairSupplyService {
             RepairRegisterPartVo vo = new RepairRegisterPartVo();
             vo.setPartId(partId);
             vo.setPartName(part.getPartName());
-            vo.setPartCount(map.get(partId).getCount());
+            vo.setPartCount(outMap.get(partId).getCount());
             vo.setPartNum(part.getPartNum());
+            PartLog partLog = reMap.get(partId);
+            if(partLog != null){
+                vo.setPartCount(vo.getPartCount() - partLog.getCount());
+            }
+            if(vo.getPartCount() <=0){
+                continue;
+            }
+
             parts.add(vo);
         }
         return parts;
+
     }
 
+    private HashMap<Integer,PartLog> getPartLogMap (String repairId,Integer status){
+        LambdaQueryWrapper<PartLog> wrapper2 = new LambdaQueryWrapper<>();
+        wrapper2.eq(PartLog::getRepairId,repairId);
+        wrapper2.eq(PartLog::getStatus,status);
+        List<PartLog> partLogs = partLogService.list(wrapper2);
+        HashMap<Integer,PartLog> outMap = new HashMap<>();
+        for (PartLog partLog : partLogs) {
+            if(outMap.get(partLog.getPartId()) != null){
+                PartLog partLog1 = outMap.get(partLog.getPartId());
+                partLog1.setCount(partLog1.getCount() + partLog.getCount());
+            }else {
+                outMap.put(partLog.getPartId(),partLog);
+            }
+        }
+        return outMap;
+    }
+
+
     public void partOut(Repair param, Long userId) {
         if(StringUtils.isBlank(param.getRepairId())){
             throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);