From 6c3cc6842009f3897c3fb18bef8a6634fe653818 Mon Sep 17 00:00:00 2001
From: 1 <1@123>
Date: 星期三, 04 三月 2026 19:59:11 +0800
Subject: [PATCH] lsh#

---
 rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/InBoundServiceImpl.java |  227 +++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 181 insertions(+), 46 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/InBoundServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/InBoundServiceImpl.java
index 4f19282..c1b6af1 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/InBoundServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/InBoundServiceImpl.java
@@ -25,6 +25,7 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Objects;
 import java.util.stream.Collectors;
@@ -48,7 +49,11 @@
     @Autowired
     private LocService locService;
     @Autowired
+    private LocItemService locItemService;
+    @Autowired
     private TaskService taskService;
+    @Autowired
+    private TaskItemService taskItemService;
 
 
     private BasStation checkStaStatus(String barcode, String sta) {
@@ -75,7 +80,7 @@
             throw new CoolException("绔欑偣鐘舵�佷笉涓虹┖闂�");
         }
         if (!Cools.isEmpty(basStation.getContainerType())) {
-            List<Long> longs1 = JSONObject.parseArray(basStation.getContainerType(), Long.class);
+            List<Integer> longs1 = basStation.getContainerType();
             List<BasContainer> containers = basContainerService.list(
                     new LambdaQueryWrapper<BasContainer>()
                             .in(BasContainer::getContainerType, longs1)
@@ -125,8 +130,13 @@
         if (!basStation.getUseStatus().equals("O")) {
             throw new CoolException("绔欑偣鐘舵�佷笉涓虹┖闂�");
         }
+
+        List<Integer> areaList = basStation.getCrossZoneArea();
+        if (!areaList.contains(Integer.parseInt(area))) {
+            throw new CoolException("褰撳墠绔欑偣涓嶆敮鎸佺洰鏍囧簱鍖�");
+        }
         if (!Cools.isEmpty(basStation.getContainerType())) {
-            List<Long> longs1 = JSONObject.parseArray(basStation.getContainerType(), Long.class);
+            List<Integer> longs1 = basStation.getContainerType();
             List<BasContainer> containers = basContainerService.list(
                     new LambdaQueryWrapper<BasContainer>()
                             .in(BasContainer::getContainerType, longs1)
@@ -136,8 +146,8 @@
             for (BasContainer container : containers) {
                 String codeType = container.getCodeType();  // 鑾峰彇姝e垯琛ㄨ揪寮�
                 if (barcode.matches(codeType)) {  // 鍒ゆ柇鏉$爜鏄惁绗﹀悎杩欎釜姝e垯
-                    List<String> areaList2 = JSONObject.parseArray(container.getAreas(), String.class);
-                    if (!areaList2.contains(area)) {
+                    List<Integer> areaList2 = container.getAreasIds();
+                    if (!areaList2.contains(Integer.parseInt(area))) {
                         matches2 = false;
                         continue;
                     }
@@ -165,65 +175,190 @@
     @Transactional(rollbackFor = Exception.class)
     public synchronized R generateTasks(PdaGeneralParam param, Long loginUserId) {
 
-        DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>().eq(DeviceSite::getSite,param.getTransferStationNo()).orderByDesc(DeviceSite::getId),false);
-        if (Objects.isNull(deviceSite)) {
-            throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
+//        DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>().eq(DeviceSite::getSite,param.getTransferStationNo()).orderByDesc(DeviceSite::getId)
+//        .last("LIMIT 1"));
+//        if (Objects.isNull(deviceSite)) {
+//            throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
+//        }
+        BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
+                .eq(BasStation::getStationName, param.getTransferStationNo()));
+        if (Objects.isNull(station) || (!station.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type) && !station.getUseStatus().equals(LocStsType.LOC_STS_TYPE_D.type)) ) {
+            throw new CoolException("绔欑偣涓嶅瓨鍦ㄦ垨绔欑偣涓嶅浜庣┖搴撱�佺┖鏉跨姸鎬侊紒锛�");
         }
-        DeviceBind deviceBind = deviceBindService.getById(LocUtils.getAreaType(deviceSite.getSite()));
-        if (Cools.isEmpty(deviceBind)) {
-            throw new CoolException("搴撲綅瑙勫垯鏈煡");
+        StringBuilder errorBuilder = new StringBuilder();
+        List<Long> areaTypeList = LocUtils.getAreaTypeList(station.getStationName());
+        if (areaTypeList.isEmpty()) {
+            throw new CoolException("鏈煡璇㈠埌璧风偣鍙叆搴撳尯锛堝簱浣嶈鍒欐湭閰嶇疆锛夛紒锛侊紒");
         }
-        WarehouseAreas warehouseArea = warehouseAreasService.getById(deviceBind.getTypeId());
-        if (Cools.isEmpty(warehouseArea)) {
-            throw new CoolException("鏈壘鍒版墍灞炲簱鍖轰俊鎭�");
-        }
+        for (Long areaType : areaTypeList) {
+            if (errorBuilder.length() > 0) {
+                errorBuilder.append(",");
+            }
+            errorBuilder.append("璺緞ID锛�");
+            errorBuilder.append(areaType);
+            DeviceBind deviceBind = deviceBindService.getById(areaType);
+            if (Cools.isEmpty(deviceBind)) {
+                errorBuilder.append("搴撲綅瑙勫垯鏈煡");
+                continue;
+//                throw new CoolException("搴撲綅瑙勫垯鏈煡");
+            }
+            WarehouseAreas warehouseArea = warehouseAreasService.getById(deviceBind.getTypeId());
+            if (Cools.isEmpty(warehouseArea)) {
+                errorBuilder.append("鏈壘鍒版墍灞炲簱鍖轰俊鎭�");
+                continue;
+//                throw new CoolException("鏈壘鍒版墍灞炲簱鍖轰俊鎭�");
+            }
+
+            DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>()
+                    .eq(DeviceSite::getSite, station.getStationName())
+                    .eq(DeviceSite::getAreaIdEnd, warehouseArea.getId())
+                    .eq(DeviceSite::getType, TaskType.TASK_TYPE_EMPTY_IN.type).last("limit 1"));
+            if (Cools.isEmpty(deviceSite)) {
+                errorBuilder.append("鏃犲彲鐢ㄨ矾寰�");
+                continue;
+//                throw new CoolException("鏃犲彲鐢ㄨ矾寰勶紒锛�");
+            }
 
 //        BasContainer container = basContainerService.getOne(new LambdaUpdateWrapper<BasContainer>()
 //                .eq(BasContainer::getCode, param.getContainerNo()));
 //        if (Objects.isNull(container)) {
 //            throw new CoolException("瀹瑰櫒鏈淮鎶ゅ叆搴擄紝璇风淮鎶ゅ悗鍐嶆搷浣滐紒锛�");
 //        }
-        //楠岃瘉鍩虹淇℃伅
-        checkStaStatus(param.getContainerNo(), param.getTransferStationNo());
-        /**鑾峰彇搴撲綅*/
-        String targetLoc = LocManageUtil.getTargetLoc(warehouseArea.getId(), null);
-        if (Cools.isEmpty(targetLoc)) {
-            throw new CoolException("璇ョ珯鐐瑰搴斿簱鍖烘湭鎵惧埌搴撲綅");
+            //楠岃瘉鍩虹淇℃伅
+            checkStaStatus(param.getContainerNo(), param.getTransferStationNo());
+            /**鑾峰彇搴撲綅*/
+            String targetLoc = LocManageUtil.getTargetLoc(warehouseArea.getId(), null);
+            if (Cools.isEmpty(targetLoc)) {
+                errorBuilder.append("璇ョ珯鐐瑰搴斿簱鍖烘湭鎵惧埌搴撲綅");
+                continue;
+//                throw new CoolException("璇ョ珯鐐瑰搴斿簱鍖烘湭鎵惧埌搴撲綅");
+            }
+
+            String ruleCode = StringUtils.isBlank(param.getTaskNo()) ?
+                    SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, null) : param.getTaskNo();
+            if (StringUtils.isBlank(ruleCode)) {
+                throw new CoolException("缂栫爜閿欒锛氳纭缂栫爜銆孲YS_TASK_CODE銆嶆槸鍚﹀凡鐢熸垚!!");
+            }
+            String stationName = null;
+            if (Cools.isEmpty(deviceSite.getDeviceCode())) {
+                stationName = station.getStationName();
+            } else {
+                BasStation stationCode = basStationService.getById(deviceSite.getDeviceCode());
+                stationName = stationCode.getStationName();
+                if (Cools.isEmpty(stationCode)) {
+                    stationName = station.getStationName();
+                }
+            }
+            Task task = new Task();
+            task.setTaskCode(ruleCode)
+                    .setTaskStatus(TaskStsType.MISSION_INITIAL.id)
+                    .setTaskType(TaskType.TASK_TYPE_EMPTY_IN.type)
+                    .setWarehType(WarehType.WAREHOUSE_TYPE_AGV.val)//lsh寰呬慨鏀�
+                    .setTargLoc(targetLoc)
+                    .setOrgSite(station.getStationName())
+                    .setBarcode(param.getContainerNo())
+                    .setTargSite(stationName)
+                    .setTaskOrigin(StringUtils.isBlank(param.getTaskOrigin()) ? null : param.getTaskOrigin())
+                    .setCreateBy(loginUserId)
+                    .setUpdateBy(loginUserId);
+            if (!taskService.save(task)) {
+                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, param.getContainerNo()))) {
+                throw new CoolException("搴撲綅棰勭害澶辫触锛侊紒");
+            }
+            return R.ok("浠诲姟鐢熸垚瀹屾瘯锛�");
+        }
+        return R.error(errorBuilder.toString()).add(errorBuilder.toString());
+    }
+
+    @Override
+    public R checkAgvStation(PdaGeneralParam param, Long loginUserId) {
+        if (Cools.isEmpty(param.getTransferStationNo())) {
+            return R.error("鏃犲弬鏁�");
+        }
+        BasStation basStation = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationId, param.getTransferStationNo()));
+        if (Cools.isEmpty(basStation)) {
+            return R.error("鏈壘鍒板尮閰嶇珯鐐�");
+        }
+        return R.ok(basStation);
+    }
+
+    @Override
+    public R checkNonOrder(PdaGeneralParam param, Long loginUserId) {
+
+        BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
+                .eq(BasStation::getStationName, param.getTransferStationNo()));
+        if (Objects.isNull(station) || !station.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type) ) {
+            throw new CoolException("鐩爣绔欑偣涓嶅瓨鍦ㄦ垨绔欑偣涓嶅浜庣┖搴撶姸鎬侊紒锛�");
         }
 
-        String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, null);
-        if (StringUtils.isBlank(ruleCode)) {
-            throw new CoolException("缂栫爜閿欒锛氳纭缂栫爜銆孲YS_TASK_CODE銆嶆槸鍚﹀凡鐢熸垚!!");
+        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, param.getLocNo()));
+        if (Objects.isNull(loc) || !loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type) ) {
+            throw new CoolException("璧风偣搴撲綅涓嶅瓨鍦ㄦ垨涓嶅浜庡湪搴撶姸鎬侊紒锛�");
+        }
+        List<LocItem> itemParams = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId()));
+
+        if (itemParams.isEmpty()) {
+            throw new CoolException("璧风偣搴撲綅搴撳瓨鏄庣粏涓虹┖锛屽紓甯革紒锛�");
         }
         Task task = new Task();
-        task.setTaskCode(ruleCode)
-                .setTaskStatus(TaskStsType.GENERATE_IN.id)
-                .setTaskType(TaskType.TASK_TYPE_EMPITY_IN.type)
-                .setWarehType(WarehType.WAREHOUSE_TYPE_AGV.val)//lsh寰呬慨鏀�
-                .setTargLoc(targetLoc)
-                .setOrgSite(deviceSite.getSite())
+        String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, null);
+        if (StringUtils.isBlank(ruleCode)) {
+            throw new CoolException("浠诲姟鍙蜂笉鑳戒负绌猴紒锛�");
+        }
+        task.setOrgLoc(loc.getCode())
+                .setTaskCode(ruleCode)
+                .setOrgLoc(loc.getCode())
+                .setTargSite(station.getStationName())
+                .setResource(TaskResouceType.TASK_RESOUCE_CHECK_TYPE.val)
+                .setTaskType(TaskType.TASK_TYPE_CHECK_OUT.type)
+                .setTaskStatus(TaskStsType.MISSION_INITIAL.id)
+                .setWarehType(WarehType.WAREHOUSE_TYPE_AGV.val)
                 .setBarcode(param.getContainerNo())
-                .setTargSite(deviceSite.getDeviceSite())
+                .setCreateTime(new Date())
+                .setUpdateBy(loginUserId)
+                .setUpdateTime(new Date())
                 .setCreateBy(loginUserId)
-                .setUpdateBy(loginUserId);
-        if (!taskService.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);
+                .setBarcode(loc.getBarcode());
 
-        if (!basStationService.updateById(station)) {
-            throw new CoolException("绔欑偣鐘舵�佹洿鏂板け璐ワ紒锛�");
+        if (!taskService.save(task)) {
+            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, param.getContainerNo()))) {
-            throw new CoolException("搴撲綅棰勭害澶辫触锛侊紒");
+        List<TaskItem> taskItems = new ArrayList<>();
+        for (LocItem item : itemParams) {
+            TaskItem taskItem = new TaskItem();
+            BeanUtils.copyProperties(item, taskItem);
+            taskItem.setTaskId(task.getId())
+                    .setAnfme(item.getAnfme())
+                    .setBatch(item.getBatch())
+                    .setUpdateBy(loginUserId)
+                    .setSourceId(item.getLocId())
+                    .setSourceCode(item.getLocCode())
+                    .setSource(item.getId())
+                    .setUpdateTime(new Date())
+                    .setSplrBatch(item.getBatch())
+                    .setPlatWorkCode(item.getPlatWorkCode())
+                    .setPlatItemId(item.getPlatItemId())
+                    .setOrderType(OrderType.ORDER_IN.type)
+                    .setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_OTHER_IN.type));
+            taskItems.add(taskItem);
         }
-        return R.ok("浠诲姟鐢熸垚瀹屾瘯锛�");
+        if (!taskItemService.saveBatch(taskItems)) {
+            throw new CoolException("浠诲姟鏄庣粏淇濆瓨澶辫触锛侊紒");
+        }
+
+        loc.setUseStatus(LocStsType.LOC_STS_TYPE_R.type);
+        if (!locService.updateById(loc)) {
+            throw new CoolException("搴撲綅棰勭害鍑哄簱澶辫触锛侊紒");
+        }
+        return R.ok();
     }
 
 }
\ No newline at end of file

--
Gitblit v1.9.1