From 1f4e7d0f73a73e7350cf5a1df279d5f30904c5d5 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期三, 06 十二月 2023 08:41:32 +0800
Subject: [PATCH] bug

---
 server/src/main/java/doumeemes/service/business/impl/DeviceServiceImpl.java |   64 +++++++++++++++++++++++--------
 1 files changed, 47 insertions(+), 17 deletions(-)

diff --git a/server/src/main/java/doumeemes/service/business/impl/DeviceServiceImpl.java b/server/src/main/java/doumeemes/service/business/impl/DeviceServiceImpl.java
index b2148a5..d8eb021 100644
--- a/server/src/main/java/doumeemes/service/business/impl/DeviceServiceImpl.java
+++ b/server/src/main/java/doumeemes/service/business/impl/DeviceServiceImpl.java
@@ -241,7 +241,7 @@
         queryDeviceExtDTO1.setRootDepartId(user.getRootDepartment().getId());
         List<DeviceExtListVO> list1= deviceExtService.getListByCondition(queryDeviceExtDTO1);*/
         if(list.size()>0){
-            return ApiResponse.failed("璁惧缂栫爜锛屼笉鍏佽娣诲姞");
+            return ApiResponse.failed("璁惧缂栫爜宸插瓨鍦紝涓嶅厑璁告坊鍔�");
         }
         device.setDeleted(Constants.ZERO);
         device.setCreateTime(new Date());
@@ -293,8 +293,8 @@
         }
         List<String> departName = new ArrayList<>();
         List<String> procedureName = new ArrayList<>();
-        plansList.forEach(s->{
-
+        int num =0;
+        for(DeviceImportDTO s : plansList){
             if (StringUtils.isBlank(s.getDeviceName())
                     || s.getDeviceName().length() > 50
                     || StringUtils.isBlank(s.getDepartName())
@@ -303,11 +303,13 @@
                     || StringUtils.isBlank(s.getFinishWarehouseLocationName())){
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵煎叆鏁版嵁鍐呭鏈夎");
             }
+            if(isRepeatCode(s,num,plansList)){
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鏂囨。涓澶囧彿銆�"+s.getDeviceCode()+"銆戦噸澶嶏紒");
+            }
             departName.add(s.getDepartName());
             procedureName.add(s.getProcedureName());
-        });
-
-
+            num++;
+        }
 
         plansList.forEach(s->{
 
@@ -330,14 +332,14 @@
             if(Objects.isNull(procedures)){
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"宸ュ簭鍚嶇О涓嶅瓨鍦�");
             }
-            QueryDeviceExtDTO queryDeviceExtDTO=new QueryDeviceExtDTO();
-            queryDeviceExtDTO.setDeleted(Constants.ZERO);
-            queryDeviceExtDTO.setCode(s.getDeviceCode());
-            queryDeviceExtDTO.setRootDepartId(user.getRootDepartment().getId());
-            List<DeviceExtListVO> list= deviceExtService.getListByCondition(queryDeviceExtDTO);
-            if(list.size() > 0){
-                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璁惧缂栫爜涓嶅瓨鍦�");
-            }
+//            QueryDeviceExtDTO queryDeviceExtDTO=new QueryDeviceExtDTO();
+//            queryDeviceExtDTO.setDeleted(Constants.ZERO);
+//            queryDeviceExtDTO.setCode(s.getDeviceCode());
+//            queryDeviceExtDTO.setRootDepartId(user.getRootDepartment().getId());
+//            List<DeviceExtListVO> list= deviceExtService.getListByCondition(queryDeviceExtDTO);
+//            if(list.size() > 0){
+//                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璁惧缂栫爜涓嶅瓨鍦�");
+//            }
 
 
 
@@ -368,7 +370,7 @@
             WarehouseLocation finishWarehouseLocations = warehouseLocationMapper.selectOne(warehouseLocationQuery);
 
             if (Objects.isNull(finishWarehouseLocations)){
-                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"宸插畬宸ヨ揣浣嶄笉瀛樺湪");
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"宸插畬宸ヨ揣浣嶄笉鏄贩鍚堝睘鎬�");
             }
 
             Map<String, WarehouseLocation> collect =new HashMap<>();
@@ -385,9 +387,24 @@
             device.setRootDepartId(user.getRootDepartment().getId());
             device.setDepartId(user.getCurComDepartment().getId());
             device.setProcedureId(procedures.getId());
+            device.setCode(StringUtils.isNotBlank(s.getDeviceCode()) ? s.getDeviceCode() : this.getNextCode(user.getCompany().getId()));
 
-            device.setCode(StringUtils.isNotBlank(device.getCode()) ? device.getCode() : this.getNextCode(user.getCompany().getId()));
-            device.setType(StringUtils.isNotBlank(device.getCode()) ? device.getCode().trim().equals("璁惧") ? 1 : 0 : 1);
+
+            Device ttt=new Device();
+            ttt.setDeleted(Constants.ZERO);
+            ttt.setCode(device.getCode());
+            ttt.setRootDepartId(user.getRootDepartment().getId());
+            if(findOne(ttt) !=null){
+                throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"璁惧缂栫爜銆�"+device.getCode()+"閲嶅銆戯紝涓嶅厑璁告坊鍔�");
+            }
+
+
+            if(StringUtils.isNotBlank(s.getType()) && StringUtils.equals("璁惧缁�",s.getType())){
+                device.setType(0);
+            }else{
+                device.setType(1);
+            }
+//            device.setType(StringUtils.isNotBlank(device.getCode()) ? device.getCode().trim().equals("璁惧") ? 1 : 0 : 1);
             device.setName(s.getDeviceName());
             device.setModel(s.getModel());
             device.setStatus(Constants.ZERO);
@@ -413,6 +430,19 @@
         });
     }
 
+    private boolean isRepeatCode(DeviceImportDTO s,int num,List<DeviceImportDTO> plansList) {
+        if(StringUtils.isNotBlank(s.getDeviceCode())){
+            int tNum = 0;
+            for(DeviceImportDTO d :plansList){
+                if(num != tNum && StringUtils.equals(s.getDeviceCode(), d.getDeviceCode())){
+                    return  true;
+                }
+                tNum++;
+            }
+        }
+        return  false;
+    }
+
 
     public synchronized String  getNextCode(Integer comId ){
         String prefix =  "S-" + DateUtil.getDate(new Date(),"yyyyMMdd") +"-";

--
Gitblit v1.9.3