From 64b432916af9c9218ab3f3eca614e26c542142ae Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期二, 07 十一月 2023 15:47:13 +0800
Subject: [PATCH] bug

---
 server/src/main/java/doumeemes/service/business/impl/DeviceServiceImpl.java |  134 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 103 insertions(+), 31 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 dc253be..d8eb021 100644
--- a/server/src/main/java/doumeemes/service/business/impl/DeviceServiceImpl.java
+++ b/server/src/main/java/doumeemes/service/business/impl/DeviceServiceImpl.java
@@ -1,6 +1,7 @@
 package doumeemes.service.business.impl;
 
 import com.baomidou.mybatisplus.extension.api.R;
+import doumeemes.biz.system.SystemDictBiz;
 import doumeemes.core.constants.ResponseStatus;
 import doumeemes.core.exception.BusinessException;
 import doumeemes.core.model.ApiResponse;
@@ -17,6 +18,8 @@
 import doumeemes.dao.ext.dto.DeviceImportDTO;
 import doumeemes.dao.ext.dto.QueryDeviceExtDTO;
 import doumeemes.dao.ext.vo.DeviceExtListVO;
+import doumeemes.dao.system.SystemDictDataMapper;
+import doumeemes.dao.system.model.SystemDictData;
 import doumeemes.service.business.DeviceService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -62,6 +65,13 @@
 
     @Autowired
     private WarehouseLocationMapper  warehouseLocationMapper;
+
+    @Autowired
+    private WarehouseMapper  warehouseMapper;
+
+
+    @Autowired
+    private SystemDictDataMapper systemDictDataMapper;
 
     @Override
     public Integer create(Device device) {
@@ -231,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());
@@ -283,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())
@@ -293,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->{
 
@@ -320,26 +332,50 @@
             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(),"璁惧缂栫爜涓嶅瓨鍦�");
+//            }
+
+
 
             QueryWrapper<WarehouseLocation> warehouseLocationQuery = new QueryWrapper<>();
             warehouseLocationQuery.lambda()
                                     .eq(WarehouseLocation::getRootDepartId,department.getRootId())
-                                    .in(WarehouseLocation::getUnionName
-                                            ,Arrays.asList(s.getFinishWarehouseLocationName(),s.getProduceWarehouseLocationName()));
-            if(Objects.equals(list.size(),2)){
-                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"搴撲綅淇℃伅宸插瓨鍦�");
-            }
-            List<WarehouseLocation> warehouseLocations = warehouseLocationMapper.selectList(warehouseLocationQuery);
+                                    .eq(WarehouseLocation::getUnionName
+                                            ,s.getProduceWarehouseLocationName()).last("limit 1");
 
-            Map<String, WarehouseLocation> collect = warehouseLocations.stream().collect(Collectors.toMap(w -> w.getUnionName(), w -> w));
+            WarehouseLocation warehouseLocation = warehouseLocationMapper.selectOne(warehouseLocationQuery);
+
+            if (Objects.isNull(warehouseLocation)){
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"寰呯敓浜ц揣浣嶄笉瀛樺湪");
+            }
+
+            QueryWrapper<SystemDictData> systemDictDataQuery = new QueryWrapper<>();
+            systemDictDataQuery.lambda()
+                    .eq(SystemDictData::getDictId,3)
+                    .eq(SystemDictData::getCode,"娣峰悎");
+            SystemDictData systemDictData = systemDictDataMapper.selectOne(systemDictDataQuery);
+
+            warehouseLocationQuery.clear();
+            warehouseLocationQuery.lambda()
+                                    .eq(WarehouseLocation::getRootDepartId,department.getRootId())
+                                    .eq(WarehouseLocation::getSystemDicDataId,systemDictData.getId())
+                                    .eq(WarehouseLocation::getUnionName,s.getFinishWarehouseLocationName()).last("limit 1");
+
+            WarehouseLocation finishWarehouseLocations = warehouseLocationMapper.selectOne(warehouseLocationQuery);
+
+            if (Objects.isNull(finishWarehouseLocations)){
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"宸插畬宸ヨ揣浣嶄笉鏄贩鍚堝睘鎬�");
+            }
+
+            Map<String, WarehouseLocation> collect =new HashMap<>();
+            collect.put(warehouseLocation.getUnionName(),warehouseLocation);
+            collect.put(finishWarehouseLocations.getUnionName(),finishWarehouseLocations);
 
             Device device = new Device();
             device.setDeleted(Constants.ZERO);
@@ -348,29 +384,65 @@
             device.setUpdateUser(user.getId());
             device.setUpdateTime(new Date());
 //            device.setRemark();
-            device.setRootDepartId(department.getRootId());
-            device.setDepartId(procedures.getId());
+            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);
-//            device.setSupplier();
             device.setStationCode(s.getStationCode());
-//            device.setGroupId();
-//            device.setSerialNum();
-            device.setProduceWarehouseLocationId(Optional.ofNullable(collect.get(s.getProduceWarehouseLocationName())).map(m->m.getId()).orElse(null));
-            device.setFinishWarehouseLocationId(Optional.ofNullable(collect.get(s.getFinishWarehouseLocationName())).map(m->m.getId()).orElse(null));
+            device.setProduceWarehouseLocationId(Optional.ofNullable(collect.get(s.getProduceWarehouseLocationName())).map(m->m.getId()).orElseThrow(null));
+            device.setFinishWarehouseLocationId(Optional.ofNullable(collect.get(s.getFinishWarehouseLocationName())).map(m->m.getId()).orElseThrow(null));
             deviceMapper.insert(device);
             if(StringUtils.isNotBlank(s.getUserIds())){
-                this.dealDeviceUserId(Constants.ZERO,device.getUserIds().trim(),device.getId(),user);
+
+                QueryWrapper<CompanyUser>  companyUserQuery = new QueryWrapper<>();
+
+                companyUserQuery.lambda()
+                                .eq(CompanyUser::getComDepartId,user.getComDepartment().getId())
+                                .in(CompanyUser::getPhone,Arrays.asList(s.getUserIds().split("[.,;锛宂")));
+                List<CompanyUser> list1 = companyUserService.findList(companyUserQuery);
+                if (!CollectionUtils.isEmpty(list1)){
+                    List<String> collect1 = list1.stream().map(c -> c.getId().toString()).collect(Collectors.toList());
+                    this.dealDeviceUserId(Constants.ZERO,StringUtils.join(collect1,","),device.getId(),user);
+                }
+
             }
 
         });
     }
 
+    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