From 438c1612a0b0b212e21d25249ccdebac6a326842 Mon Sep 17 00:00:00 2001
From: zc <zyzc>
Date: 星期六, 15 十一月 2025 15:27:08 +0800
Subject: [PATCH] 小数点保留后两位

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java |  113 ++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 72 insertions(+), 41 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
index 414becc..eba84ff 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
@@ -23,6 +23,7 @@
 import com.vincent.rsf.server.system.utils.SerialRuleUtils;
 import com.vincent.rsf.server.system.utils.SystemAuthUtils;
 import lombok.Synchronized;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -34,6 +35,7 @@
 import java.util.*;
 import java.util.stream.Collectors;
 
+@Slf4j
 @Service("taskService")
 public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements TaskService {
 
@@ -91,6 +93,8 @@
     private CheckDiffService checkDiffService;
     @Autowired
     private CheckDiffItemService checkDiffItemService;
+    @Autowired
+    private BasContainerService basContainerService;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -285,7 +289,7 @@
         if (Objects.isNull(deviceSite)) {
             throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
         }
-        DeviceBind deviceBind = deviceBindService.getById(LocUtils.getAreaType(Integer.valueOf(deviceSite.getSite())));
+        DeviceBind deviceBind = deviceBindService.getById(LocUtils.getAreaType(deviceSite.getSite()));
         if (Cools.isEmpty(deviceBind)) {
             throw new CoolException("搴撲綅瑙勫垯鏈煡");
         }
@@ -303,8 +307,10 @@
             throw new CoolException("璇锋鏌ョ粍鎷栫姸鎬佹槸鍚﹀畬鎴愶紒锛�");
         }
         waitPakins.forEach(pakin -> {
+            BasContainer container = basContainerService.getOne(new LambdaUpdateWrapper<BasContainer>()
+                    .eq(BasContainer::getCode, pakin.getBarcode()));
             /**鑾峰彇搴撲綅*/
-            String targetLoc = LocManageUtil.getTargetLoc(warehouseArea.getId());
+            String targetLoc = LocManageUtil.getTargetLoc(warehouseArea.getId(), container.getContainerType());
             if (Cools.isEmpty(targetLoc)) {
                 throw new CoolException("璇ョ珯鐐瑰搴斿簱鍖烘湭鎵惧埌搴撲綅");
             }
@@ -345,6 +351,18 @@
             if (!this.save(task)) {
                 throw new CoolException("浠诲姟淇濆瓨澶辫触锛侊紒");
             }
+            BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
+                    .eq(BasStation::getStationName, deviceSite.getSite()));
+            if (Objects.isNull(station) || !station.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type)) {
+                throw new CoolException("绔欑偣涓嶅瓨鍦ㄦ垨绔欑偣涓嶅浜庣┖搴撶姸鎬侊紒锛�");
+            }
+            station.setUseStatus(LocStsType.LOC_STS_TYPE_R.type);
+
+            if (!basStationService.updateById(station)) {
+                 throw new CoolException("绔欑偣鐘舵�佹洿鏂板け璐ワ紒锛�");
+             }
+
+
             if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getCode, task.getTargLoc())
                     .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type).set(Loc::getBarcode, pakin.getBarcode()))) {
                 throw new CoolException("搴撲綅棰勭害澶辫触锛侊紒");
@@ -406,22 +424,24 @@
      */
     @Synchronized
     @Override
-    @Transactional(rollbackFor = Exception.class)
     public void complateInTask(List<Task> tasks) throws Exception {
         Long loginUserId = SystemAuthUtils.getLoginUserId();
         for (Task task : tasks) {
-            if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) {
-                //1.鍏ュ簱
-                complateInstock(task, loginUserId);
-            } else if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
-                //53.鎷f枡鍐嶅叆搴�
-                //57.鐩樼偣鍐嶅叆搴�
-                pickComplateInStock(task, loginUserId);
-            } else if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
-                //绉诲簱
-                moveInStock(task, loginUserId);
+            try {
+                if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) {
+                    //1.鍏ュ簱
+                    complateInstock(task, loginUserId);
+                } else if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
+                    //53.鎷f枡鍐嶅叆搴�
+                    //57.鐩樼偣鍐嶅叆搴�
+                    pickComplateInStock(task, loginUserId);
+                } else if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+                    //绉诲簱
+                    moveInStock(task, loginUserId);
+                }
+            } catch (Exception ex) {
+                log.error(ex.getMessage(), ex);
             }
-
         }
     }
 
@@ -590,7 +610,7 @@
                 //鏇存柊搴撲綅鏄庣粏
                 saveLocItem(taskItems, task.getId(), loginUserId);
             } catch (Exception e) {
-                throw new CoolException("搴撲綅鏄庣粏鏇存柊澶辫触锛侊紒");
+                throw new CoolException("浠诲姟鍙凤細" + task.getTaskCode() +  "搴撲綅鏄庣粏鏇存柊澶辫触锛侊紒");
             }
 
             if (!locItemService.remove(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocCode, task.getOrgLoc()))) {
@@ -635,7 +655,6 @@
      */
     @Synchronized
     @Override
-    @Transactional(rollbackFor = Exception.class)
     public void completeTask(List<Task> tasks) {
         Long loginUserId = SystemAuthUtils.getLoginUserId();
         for (Task task : tasks) {
@@ -643,7 +662,8 @@
             try {
                 complateOutStock(task, loginUserId);
             } catch (Exception e) {
-                throw new CoolException(e.getMessage());
+                log.error(e.getMessage(), e);
+//                throw new CoolException(e.getMessage());
             }
         }
     }
@@ -663,9 +683,9 @@
         if (Objects.isNull(loc)) {
             throw new CoolException("搴撳瓨涓嶅瓨鍦紒锛�");
         }
-        if (!loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_S.type)) {
-            throw new CoolException("褰撳墠搴撲綅鐘舵�佷笉澶勪簬S.鍏ュ簱棰勭害锛屼笉鍙墽琛屽叆搴撴搷浣滐紒");
-        }
+//        if (!loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_S.type)) {
+//            throw new CoolException("褰撳墠搴撲綅鐘舵�佷笉澶勪簬S.鍏ュ簱棰勭害锛屼笉鍙墽琛屽叆搴撴搷浣滐紒");
+//        }
 
         loc.setUseStatus(LocStsType.LOC_STS_TYPE_F.type)
                 .setBarcode(task.getBarcode())
@@ -848,7 +868,7 @@
                             if (Objects.isNull(waveItem)) {
                                 throw new CoolException("娉㈡鏄庣粏涓嶅瓨鍦紒锛�");
                             }
-                            Double workQty = Math.round((waveItem.getWorkQty() - item.getAnfme()) * 10000) / 10000.0;
+                            Double workQty = Math.round((waveItem.getWorkQty() - item.getAnfme()) * 100) / 100.0;
                             waveItem.setWorkQty(workQty).setExceStatus(WaveItemExceStatus.WAVE_ITEM_EXCE_STATUS_UN.val);
                             if (!waveItemService.updateById(waveItem)) {
                                 throw new CoolException("娉㈡鏄庣粏鏇存柊澶辫触锛侊紒");
@@ -872,7 +892,7 @@
                             if (Objects.isNull(wkOrder)) {
                                 throw new CoolException("鏁版嵁閿欒锛氬崟鎹凡涓嶅瓨鍦紒锛�");
                             }
-                            Double workQty = Math.round((wkOrder.getWorkQty() - item.getAnfme()) * 10000) / 10000.0;
+                            Double workQty = Math.round((wkOrder.getWorkQty() - item.getAnfme()) * 100) / 100.0;
 
                             wkOrder.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val)
                                     .setWorkQty(workQty.compareTo(0.00) > 0 ? workQty : 0.00)
@@ -887,7 +907,7 @@
                                 throw new CoolException("鏁版嵁閿欒锛氬崟鎹槑缁嗗凡涓嶅瓨鍦紒锛�");
                             }
 
-                            Double workItmQty = Math.round((orderItem.getWorkQty() - item.getAnfme()) * 10000) / 10000.0;
+                            Double workItmQty = Math.round((orderItem.getWorkQty() - item.getAnfme()) * 100) / 100.0;
                             orderItem.setWorkQty(workItmQty);
 
                             if (!outStockItemService.updateById(orderItem)) {
@@ -970,7 +990,7 @@
                 .setTaskStatus(TaskStsType.GENERATE_IN.id);
 
         TaskInParam param = new TaskInParam();
-        param.setSourceStaNo(Integer.parseInt(task.getTargSite()))
+        param.setSourceStaNo(task.getTargSite())
                 .setIoType(type)
                 .setLocType1(Integer.parseInt(loc.getType()));
         //鑾峰彇鏂板簱浣�
@@ -979,7 +999,8 @@
         if (Objects.isNull(locInfo)) {
             throw new CoolException("鑾峰彇搴撲綅澶辫触锛侊紒");
         }
-        task.setTargLoc(locInfo.getLocNo());
+        task.setTargLoc(locInfo.getLocNo())
+                .setOrgSite(task.getTargSite());
 
         if (!this.updateById(task)) {
             throw new CoolException("浠诲姟鐘舵�佹洿鏂板け璐ワ紒锛�");
@@ -999,7 +1020,7 @@
                 if (taskItem.getMatnrId().equals(working.getMatnrId())) {
                     Double minQty = taskItem.getAnfme();
                     if (!task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
-                        minQty = Math.round((working.getAnfme() - taskItem.getAnfme()) * 10000) / 10000.0;
+                        minQty = Math.round((working.getAnfme() - taskItem.getAnfme()) * 100) / 100.0;
                     }
                     if (minQty.compareTo(0.0) > 0) {
                         taskItem.setAnfme(minQty);
@@ -1008,7 +1029,7 @@
                         }
                     } else {
                         if (!taskItemService.removeById(taskItem)) {
-                            throw new CoolException("浠诲姟鏄庣粏淇敼澶辫触锛侊紒");
+                            log.error("浠诲姟鏄庣粏淇敼澶辫触锛侊紒");
                         }
                     }
                 }
@@ -1138,19 +1159,28 @@
                     if (Objects.isNull(waveItem)) {
                         throw new CoolException("娉㈡鏄庣粏涓嶅瓨鍦紒锛�");
                     }
-                    try {
-                        saveOutStockItem(maps.get(key), null, waveItem, null, loginUserId);
-                    } catch (Exception e) {
-                        throw new CoolException(e.getMessage());
-                    }
-                } else if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val)
-                        || task.getResource().equals(TaskResouceType.TASK_RESOUCE_CHECK_TYPE.val)) {
+//                    try {
+//                        saveOutStockItem(maps.get(key), null, waveItem, null, loginUserId);
+//                    } catch (Exception e) {
+//                        throw new CoolException(e.getMessage());
+//                    }
+                } else if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val)) {
                     WkOrderItem orderItem = asnOrderItemService.getById(key);
                     if (Objects.isNull(orderItem)) {
                         throw new CoolException("鍗曟嵁鏄庣粏涓嶅瓨鍦紒锛�");
                     }
                     try {
-                        saveOutStockItem(maps.get(key), orderItem, null, null, loginUserId);
+                        saveOutStockItem(maps.get(key), orderItem,  loginUserId);
+                    } catch (Exception e) {
+                        throw new CoolException(e.getMessage());
+                    }
+                } else if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_CHECK_TYPE.val)) {
+                    WkOrderItem orderItem = asnOrderItemService.getById(key);
+                    if (Objects.isNull(orderItem)) {
+                        throw new CoolException("鍗曟嵁鏄庣粏涓嶅瓨鍦紒锛�");
+                    }
+                    try {
+                        saveOutStockItem(maps.get(key), null, null, orderItem, loginUserId);
                     } catch (Exception e) {
                         throw new CoolException(e.getMessage());
                     }
@@ -1207,7 +1237,7 @@
      * @version 1.0
      */
     @Transactional(rollbackFor = Exception.class)
-    public void saveOutStockItem(List<TaskItem> taskItems, CheckDiffItem diffItem, Long loginUserId) {
+    public void saveOutStockItem(List<TaskItem> taskItems, WkOrderItem diffItem, Long loginUserId) {
         try {
             saveOutStockItem(taskItems, null, null, diffItem, loginUserId);
         } catch (Exception e) {
@@ -1221,8 +1251,9 @@
      * @description: 鍑哄簱淇℃伅淇濆瓨鑷冲簱瀛樻槑缁嗚〃
      * @version 1.0
      */
+    @Override
     @Transactional(rollbackFor = Exception.class)
-    public void saveOutStockItem(List<TaskItem> taskItems, WkOrderItem orderItem, WaveItem waveItem, CheckDiffItem diffItem, Long loginUserId) throws Exception {
+    public void saveOutStockItem(List<TaskItem> taskItems, WkOrderItem orderItem, WaveItem waveItem, WkOrderItem diffItem, Long loginUserId) throws Exception {
         Stock stock = new Stock();
         String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_STOCK_CODE, null);
         if (StringUtils.isBlank(ruleCode)) {
@@ -1238,7 +1269,7 @@
             stock.setSourceId(waveItem.getId()).setType(OrderType.ORDER_OUT.type);
         } else if (!Objects.isNull(orderItem) && StringUtils.isNotBlank(orderItem.getId() + "")) {
             WkOrder wkOrder = asnOrderService.getById(orderItem.getOrderId());
-            Double qty = Math.round((wkOrder.getQty() + sum) * 10000) / 10000.0;
+            Double qty = Math.round((wkOrder.getQty() + sum) * 100) / 100.0;
             wkOrder.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_WORKING.val)
                     .setQty(qty);
             if (!asnOrderService.updateById(wkOrder)) {
@@ -1362,8 +1393,8 @@
         if (Objects.isNull(itemServiceOne)) {
             throw new CoolException("鏁版嵁閿欒锛氳鏌ョ湅璇疯揣鍖哄簱瀛樻槸鍚﹀瓨鍦紒锛�");
         }
-        Double workQty = Math.round((itemServiceOne.getWorkQty() - pakinItem.getAnfme()) * 10000) / 10000.0;
-        Double qty = Math.round((itemServiceOne.getQty() + pakinItem.getAnfme()) * 10000) / 10000.0;
+        Double workQty = Math.round((itemServiceOne.getWorkQty() - pakinItem.getAnfme()) * 100) / 100.0;
+        Double qty = Math.round((itemServiceOne.getQty() + pakinItem.getAnfme()) * 100) / 100.0;
         itemServiceOne.setWorkQty(workQty).setQty(qty);
 
         if (!waitPakinService.update(new LambdaUpdateWrapper<WaitPakin>()
@@ -1422,7 +1453,7 @@
                         .setType(taskItem.getOrderType());
                 locItems.add(item);
             } else {
-                locItem.setAnfme(Math.round((locItem.getAnfme() + taskItem.getAnfme()) * 10000) / 10000.0)
+                locItem.setAnfme(Math.round((locItem.getAnfme() + taskItem.getAnfme()) * 100) / 100.0)
                         .setUpdateTime(new Date());
                 locItems.add(locItem);
             }

--
Gitblit v1.9.1