Răsfoiți Sursa

1.承运订单导入bugfix

lengfaqiang 2 ani în urmă
părinte
comite
a81ef290b5

+ 1 - 0
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/controller/KwtAcceptCarriageOrderController.java

@@ -421,6 +421,7 @@ public class KwtAcceptCarriageOrderController {
         try {
             return acceptCarriageOrderImportService.externalImportExcel(file);
         } catch (Exception e) {
+            log.error("异常错误信息:{}",e.getMessage(),e);
             return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
         }
     }

+ 206 - 113
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/Import/KwtAcceptCarriageOrderImportService.java

@@ -490,59 +490,32 @@ public class KwtAcceptCarriageOrderImportService {
         String acceptCarriageCompany = excelImport.getAcceptCarriageCompany().trim();
         KwsEnterpriseResDto acceptCarriageEnterprise = remoteSystemService.findEnterpriseByName(acceptCarriageCompany);
         Long id = acceptCarriageEnterprise.getId();
-        Map<Long, List<EntAddressResDto>> longListMap = remoteManageService.queryEntAddressByEntIdList(Collections.singletonList(id));
+        List<Long> idsList = new ArrayList<>();
+        idsList.add(id);
+        Map<Long, EntCacheResDto> entTreeByIds = remoteSystemService.queryEntTreeByIds(Collections.singletonList(id));
+        if (entTreeByIds != null && entTreeByIds.get(id) != null) {
+            idsList.add(entTreeByIds.get(id).getId());
+        }
+        idsList = idsList.stream().distinct().collect(Collectors.toList());
+        Map<Long, List<EntAddressResDto>> longListMap = remoteManageService.queryEntAddressByEntIdList(idsList);
         List<EntAddressResDto> addressRes = longListMap.get(id);
         if (CollectionUtils.isNotEmpty(addressRes)) {
-
-            Map<Integer, List<EntAddressResDto>> collect = addressRes.stream().collect(Collectors.groupingBy(EntAddressResDto::getDefaultType));
-            List<EntAddressResDto> loadAddressRes = collect.get(AddressDefaultTypeEnum.SHIPMENT.getCode());
-            Map<String, EntAddressResDto> loadAddressMap = new HashMap<>();
-            if (CollectionUtils.isNotEmpty(loadAddressRes)) {
-                loadAddressMap = loadAddressRes.stream().collect(Collectors.toMap(EntAddressResDto::getName, v -> v));
-            }
-            List<EntAddressResDto> unloadAddressRes = collect.get(AddressDefaultTypeEnum.TAKE.getCode());
-            Map<String, EntAddressResDto> unloadAddressMap = new HashMap<>();
-            if (CollectionUtils.isNotEmpty(unloadAddressRes)) {
-                unloadAddressMap = unloadAddressRes.stream().collect(Collectors.toMap(EntAddressResDto::getName, v -> v));
-            }
-            List<EntAddressResDto> allAddressRes = collect.get(AddressDefaultTypeEnum.BOTH.getCode());
-            Map<String, EntAddressResDto> allAddressResMap = new HashMap<>();
-
-            if (CollectionUtils.isNotEmpty(allAddressRes)) {
-                allAddressResMap = allAddressRes.stream().collect(Collectors.toMap(EntAddressResDto::getName, v -> v));
-            }
-
+            Map<String, EntAddressResDto> addressMap = addressRes.stream().collect(Collectors.toMap(EntAddressResDto::getName, v -> v));
             /**装货地址*/
             KwtLogisticsOrderAddress loadAddress = new KwtLogisticsOrderAddress();
             loadAddress.setId(new IdWorker(NumberConstant.ONE).nextId());
             loadAddress.setLOrderId(lOrderId);
             loadAddress.setAddressType(NumberConstant.ONE);
-            if (loadAddressMap != null || allAddressResMap != null) {
-                EntAddressResDto entAddressResDto = loadAddressMap.get(loadAddressName);
-                EntAddressResDto entAddressResDto1 = allAddressResMap.get(loadAddressName);
-                if (entAddressResDto == null) {
-                    if (entAddressResDto1.getName().equals(loadAddressName)) {
-                        loadAddress.setName(entAddressResDto1.getName());
-                        loadAddress.setContacts(entAddressResDto1.getContacts());
-                        loadAddress.setPhone(entAddressResDto1.getPhone());
-                        loadAddress.setCityCode(entAddressResDto1.getCityCode());
-                        loadAddress.setCityName(entAddressResDto1.getCityName());
-                        loadAddress.setDetailAddress(entAddressResDto1.getDetailAddress());
-                        loadAddress.setLat(entAddressResDto1.getLat());
-                        loadAddress.setLng(entAddressResDto1.getLng());
-                    }
-                } else {
-                    if (entAddressResDto.getName().equals(loadAddressName)) {
-                        loadAddress.setName(entAddressResDto.getName());
-                        loadAddress.setContacts(entAddressResDto.getContacts());
-                        loadAddress.setPhone(entAddressResDto.getPhone());
-                        loadAddress.setCityCode(entAddressResDto.getCityCode());
-                        loadAddress.setCityName(entAddressResDto.getCityName());
-                        loadAddress.setDetailAddress(entAddressResDto.getDetailAddress());
-                        loadAddress.setLat(entAddressResDto.getLat());
-                        loadAddress.setLng(entAddressResDto.getLng());
-                    }
-                }
+            if (addressMap != null && addressMap.get(loadAddressName) != null) {
+                EntAddressResDto entAddressResDto = addressMap.get(loadAddressName);
+                loadAddress.setName(entAddressResDto.getName());
+                loadAddress.setContacts(entAddressResDto.getContacts());
+                loadAddress.setPhone(entAddressResDto.getPhone());
+                loadAddress.setCityCode(entAddressResDto.getCityCode());
+                loadAddress.setCityName(entAddressResDto.getCityName());
+                loadAddress.setDetailAddress(entAddressResDto.getDetailAddress());
+                loadAddress.setLat(entAddressResDto.getLat());
+                loadAddress.setLng(entAddressResDto.getLng());
                 loadAddress.setEntryType(NumberConstant.FOUR);
                 loadAddress.setStatus(NumberConstant.ZERO);
                 loadAddress.setCreateBy(LoginUserHolder.getUserId());
@@ -552,38 +525,21 @@ public class KwtAcceptCarriageOrderImportService {
                 loadAddress.setUpdateTime(date);
                 logisticsOrderAddressMapper.insert(loadAddress);
             }
-
             /**卸货地址*/
             KwtLogisticsOrderAddress unloadAddress = new KwtLogisticsOrderAddress();
             unloadAddress.setId(new IdWorker(NumberConstant.TWO).nextId());
             unloadAddress.setLOrderId(lOrderId);
             unloadAddress.setAddressType(NumberConstant.TWO);
-            if (unloadAddressMap != null || allAddressResMap != null) {
-                EntAddressResDto entAddressResDto = unloadAddressMap.get(unloadAddressName);
-                EntAddressResDto entAddressResDto1 = allAddressResMap.get(unloadAddressName);
-                if (entAddressResDto == null) {
-                    if (entAddressResDto1.getName().equals(unloadAddressName)) {
-                        unloadAddress.setName(entAddressResDto1.getName());
-                        unloadAddress.setContacts(entAddressResDto1.getContacts());
-                        unloadAddress.setPhone(entAddressResDto1.getPhone());
-                        unloadAddress.setCityCode(entAddressResDto1.getCityCode());
-                        unloadAddress.setCityName(entAddressResDto1.getCityName());
-                        unloadAddress.setDetailAddress(entAddressResDto1.getDetailAddress());
-                        unloadAddress.setLat(entAddressResDto1.getLat());
-                        unloadAddress.setLng(entAddressResDto1.getLng());
-                    }
-                } else {
-                    if (entAddressResDto.getName().equals(unloadAddressName)) {
-                        unloadAddress.setName(entAddressResDto.getName());
-                        unloadAddress.setContacts(entAddressResDto.getContacts());
-                        unloadAddress.setPhone(entAddressResDto.getPhone());
-                        unloadAddress.setCityCode(entAddressResDto.getCityCode());
-                        unloadAddress.setCityName(entAddressResDto.getCityName());
-                        unloadAddress.setDetailAddress(entAddressResDto.getDetailAddress());
-                        unloadAddress.setLat(entAddressResDto.getLat());
-                        unloadAddress.setLng(entAddressResDto.getLng());
-                    }
-                }
+            if (addressMap != null && addressMap.get(unloadAddressName) != null) {
+                EntAddressResDto entAddressResDto = addressMap.get(unloadAddressName);
+                unloadAddress.setName(entAddressResDto.getName());
+                unloadAddress.setContacts(entAddressResDto.getContacts());
+                unloadAddress.setPhone(entAddressResDto.getPhone());
+                unloadAddress.setCityCode(entAddressResDto.getCityCode());
+                unloadAddress.setCityName(entAddressResDto.getCityName());
+                unloadAddress.setDetailAddress(entAddressResDto.getDetailAddress());
+                unloadAddress.setLat(entAddressResDto.getLat());
+                unloadAddress.setLng(entAddressResDto.getLng());
                 unloadAddress.setEntryType(NumberConstant.FOUR);
                 unloadAddress.setStatus(NumberConstant.ZERO);
                 unloadAddress.setCreateBy(LoginUserHolder.getUserId());
@@ -593,6 +549,117 @@ public class KwtAcceptCarriageOrderImportService {
                 unloadAddress.setUpdateTime(date);
                 logisticsOrderAddressMapper.insert(unloadAddress);
             }
+            /**按照装卸货地址类型 存储地址*/
+//            insertOrderAddress(addressRes,lOrderId,loadAddressName,unloadAddressName);
+
+        }
+    }
+
+    /**
+     * 按照装卸货地址类型 存储地址
+     * @param addressRes
+     * @param lOrderId
+     * @param loadAddressName
+     * @param unloadAddressName
+     */
+    private void insertOrderAddress(List<EntAddressResDto> addressRes,Long lOrderId, String loadAddressName,String unloadAddressName) {
+        Map<Integer, List<EntAddressResDto>> collect = addressRes.stream().collect(Collectors.groupingBy(EntAddressResDto::getDefaultType));
+        List<EntAddressResDto> loadAddressRes = collect.get(AddressDefaultTypeEnum.SHIPMENT.getCode());
+        Map<String, EntAddressResDto> loadAddressMap = new HashMap<>();
+        if (CollectionUtils.isNotEmpty(loadAddressRes)) {
+            loadAddressMap = loadAddressRes.stream().collect(Collectors.toMap(EntAddressResDto::getName, v -> v));
+        }
+        List<EntAddressResDto> unloadAddressRes = collect.get(AddressDefaultTypeEnum.TAKE.getCode());
+        Map<String, EntAddressResDto> unloadAddressMap = new HashMap<>();
+        if (CollectionUtils.isNotEmpty(unloadAddressRes)) {
+            unloadAddressMap = unloadAddressRes.stream().collect(Collectors.toMap(EntAddressResDto::getName, v -> v));
+        }
+        List<EntAddressResDto> allAddressRes = collect.get(AddressDefaultTypeEnum.BOTH.getCode());
+        Map<String, EntAddressResDto> allAddressResMap = new HashMap<>();
+
+        if (CollectionUtils.isNotEmpty(allAddressRes)) {
+            allAddressResMap = allAddressRes.stream().collect(Collectors.toMap(EntAddressResDto::getName, v -> v));
+        }
+        /**装货地址*/
+        KwtLogisticsOrderAddress loadAddress = new KwtLogisticsOrderAddress();
+        loadAddress.setId(new IdWorker(NumberConstant.ONE).nextId());
+        loadAddress.setLOrderId(lOrderId);
+        loadAddress.setAddressType(NumberConstant.ONE);
+        if (loadAddressMap != null || allAddressResMap != null) {
+            EntAddressResDto entAddressResDto = loadAddressMap.get(loadAddressName);
+            EntAddressResDto entAddressResDto1 = allAddressResMap.get(loadAddressName);
+            if (entAddressResDto == null) {
+                if (entAddressResDto1.getName().equals(loadAddressName)) {
+                    loadAddress.setName(entAddressResDto1.getName());
+                    loadAddress.setContacts(entAddressResDto1.getContacts());
+                    loadAddress.setPhone(entAddressResDto1.getPhone());
+                    loadAddress.setCityCode(entAddressResDto1.getCityCode());
+                    loadAddress.setCityName(entAddressResDto1.getCityName());
+                    loadAddress.setDetailAddress(entAddressResDto1.getDetailAddress());
+                    loadAddress.setLat(entAddressResDto1.getLat());
+                    loadAddress.setLng(entAddressResDto1.getLng());
+                }
+            } else {
+                if (entAddressResDto.getName().equals(loadAddressName)) {
+                    loadAddress.setName(entAddressResDto.getName());
+                    loadAddress.setContacts(entAddressResDto.getContacts());
+                    loadAddress.setPhone(entAddressResDto.getPhone());
+                    loadAddress.setCityCode(entAddressResDto.getCityCode());
+                    loadAddress.setCityName(entAddressResDto.getCityName());
+                    loadAddress.setDetailAddress(entAddressResDto.getDetailAddress());
+                    loadAddress.setLat(entAddressResDto.getLat());
+                    loadAddress.setLng(entAddressResDto.getLng());
+                }
+            }
+            loadAddress.setEntryType(NumberConstant.FOUR);
+            loadAddress.setStatus(NumberConstant.ZERO);
+            loadAddress.setCreateBy(LoginUserHolder.getUserId());
+            Date date = new Date();
+            loadAddress.setCreateTime(date);
+            loadAddress.setUpdateBy(LoginUserHolder.getUserId());
+            loadAddress.setUpdateTime(date);
+            logisticsOrderAddressMapper.insert(loadAddress);
+        }
+
+        /**卸货地址*/
+        KwtLogisticsOrderAddress unloadAddress = new KwtLogisticsOrderAddress();
+        unloadAddress.setId(new IdWorker(NumberConstant.TWO).nextId());
+        unloadAddress.setLOrderId(lOrderId);
+        unloadAddress.setAddressType(NumberConstant.TWO);
+        if (unloadAddressMap != null || allAddressResMap != null) {
+            EntAddressResDto entAddressResDto = unloadAddressMap.get(unloadAddressName);
+            EntAddressResDto entAddressResDto1 = allAddressResMap.get(unloadAddressName);
+            if (entAddressResDto == null) {
+                if (entAddressResDto1.getName().equals(unloadAddressName)) {
+                    unloadAddress.setName(entAddressResDto1.getName());
+                    unloadAddress.setContacts(entAddressResDto1.getContacts());
+                    unloadAddress.setPhone(entAddressResDto1.getPhone());
+                    unloadAddress.setCityCode(entAddressResDto1.getCityCode());
+                    unloadAddress.setCityName(entAddressResDto1.getCityName());
+                    unloadAddress.setDetailAddress(entAddressResDto1.getDetailAddress());
+                    unloadAddress.setLat(entAddressResDto1.getLat());
+                    unloadAddress.setLng(entAddressResDto1.getLng());
+                }
+            } else {
+                if (entAddressResDto.getName().equals(unloadAddressName)) {
+                    unloadAddress.setName(entAddressResDto.getName());
+                    unloadAddress.setContacts(entAddressResDto.getContacts());
+                    unloadAddress.setPhone(entAddressResDto.getPhone());
+                    unloadAddress.setCityCode(entAddressResDto.getCityCode());
+                    unloadAddress.setCityName(entAddressResDto.getCityName());
+                    unloadAddress.setDetailAddress(entAddressResDto.getDetailAddress());
+                    unloadAddress.setLat(entAddressResDto.getLat());
+                    unloadAddress.setLng(entAddressResDto.getLng());
+                }
+            }
+            unloadAddress.setEntryType(NumberConstant.FOUR);
+            unloadAddress.setStatus(NumberConstant.ZERO);
+            unloadAddress.setCreateBy(LoginUserHolder.getUserId());
+            Date date = new Date();
+            unloadAddress.setCreateTime(date);
+            unloadAddress.setUpdateBy(LoginUserHolder.getUserId());
+            unloadAddress.setUpdateTime(date);
+            logisticsOrderAddressMapper.insert(unloadAddress);
         }
     }
 
@@ -718,11 +785,11 @@ public class KwtAcceptCarriageOrderImportService {
                 throw new RuntimeException("第" + number + "行承运企业与托运企业不存在合作关系!");
             }
 
-//            String goodsName = excelImport.getGoodsName().trim();
-//            KwpGoods goods = goodsInfoService.getGoodsByGoodsName(goodsName);
-//            if (goods == null) {
-//                throw new RuntimeException("第" + number + "行货物信息不存在");
-//            }
+            String goodsName = excelImport.getGoodsName().trim();
+            KwpGoods goods = goodsInfoService.getGoodsByGoodsName(goodsName);
+            if (goods == null) {
+                throw new RuntimeException("第" + number + "行货物信息不存在");
+            }
             String goodsModelType = excelImport.getGoodsModel().trim();
             if (!goodsModel.contains(goodsModelType)) {
                 throw new RuntimeException("第" + number + "行商品分类信息不存在");
@@ -773,46 +840,24 @@ public class KwtAcceptCarriageOrderImportService {
             String unloadAddressName = excelImport.getUnloadAddress();
             String loadAddressName = excelImport.getLoadAddress();
             Long id = acceptCarriageEnterprise.getId();
-            Map<Long, List<EntAddressResDto>> longListMap = remoteManageService.queryEntAddressByEntIdList(Collections.singletonList(id));
+            List<Long> idsList = new ArrayList<>();
+            idsList.add(id);
+            Map<Long, EntCacheResDto> entTreeByIds = remoteSystemService.queryEntTreeByIds(Collections.singletonList(id));
+            if (entTreeByIds != null && entTreeByIds.get(id) != null) {
+                idsList.add(entTreeByIds.get(id).getId());
+            }
+            idsList = idsList.stream().distinct().collect(Collectors.toList());
+            Map<Long, List<EntAddressResDto>> longListMap = remoteManageService.queryEntAddressByEntIdList(idsList);
             List<EntAddressResDto> addressRes = longListMap.get(id);
             if (CollectionUtils.isNotEmpty(addressRes)) {
-                Map<Integer, List<EntAddressResDto>> collect = addressRes.stream().collect(Collectors.groupingBy(EntAddressResDto::getDefaultType));
-                List<String> loadAddress = new ArrayList<>();
-                List<String> unloadAddress = new ArrayList<>();
-                List<EntAddressResDto> loadAddressRes = collect.get(AddressDefaultTypeEnum.SHIPMENT.getCode());
-                if (CollectionUtils.isNotEmpty(loadAddressRes)) {
-                    List<String> loadAddressStr = loadAddressRes.stream().map(EntAddressResDto::getName).collect(Collectors.toList());
-                    loadAddress.addAll(loadAddressStr);
-                }
-                List<EntAddressResDto> unloadAddressRes = collect.get(AddressDefaultTypeEnum.TAKE.getCode());
-                if (CollectionUtils.isNotEmpty(unloadAddressRes)) {
-                    List<String> unloadAddressStr = unloadAddressRes.stream().map(EntAddressResDto::getName).collect(Collectors.toList());
-                    unloadAddress.addAll(unloadAddressStr);
-                }
-                List<EntAddressResDto> allAddressRes = collect.get(AddressDefaultTypeEnum.BOTH.getCode());
-                if (CollectionUtils.isNotEmpty(allAddressRes)) {
-                    List<String> allAddress = allAddressRes.stream().map(EntAddressResDto::getName).collect(Collectors.toList());
-                    loadAddress.addAll(allAddress);
-                    unloadAddress.addAll(allAddress);
-                }
-                if (loadAddress.size() < 1) {
+                List<String> addressStr = addressRes.stream().map(EntAddressResDto::getName).collect(Collectors.toList());
+                //checkOrderAddress(addressRes,loadAddressName,unloadAddressName,number);
+                if (!addressStr.contains(loadAddressName)) {
                     throw new RuntimeException("第" + number + "行承运企业在系统中并未维护该装货地址");
                 }
-                if (unloadAddress.size() < 1) {
+                if (!addressStr.contains(unloadAddressName)) {
                     throw new RuntimeException("第" + number + "行承运企业在系统中并未维护该卸货地址");
                 }
-                if (loadAddress.size() > 0) {
-                    loadAddress = loadAddress.stream().distinct().collect(Collectors.toList());
-                    if (!loadAddress.contains(loadAddressName)) {
-                        throw new RuntimeException("第" + number + "行承运企业在系统中并未维护该装货地址");
-                    }
-                }
-                if (unloadAddress.size() > 0) {
-                    unloadAddress = unloadAddress.stream().distinct().collect(Collectors.toList());
-                    if (!unloadAddress.contains(unloadAddressName)) {
-                        throw new RuntimeException("第" + number + "行承运企业在系统中并未维护该卸货地址");
-                    }
-                }
             } else {
                 throw new RuntimeException("第" + number + "行承运企业系统中并未维护装货地址或卸货地址");
             }
@@ -834,7 +879,7 @@ public class KwtAcceptCarriageOrderImportService {
                 Map<Long, EntCacheResDto> map = remoteSystemService.queryEntTreeByIds(Collections.singletonList(LoginUserHolder.getEntId()));
                 if (map != null) {
                     Long loginEntId = map.get(LoginUserHolder.getEntId()).getId();
-                    if (entIds.size() != 1 || (!entIds.get(0).equals( loginEntId))) {
+                    if (entIds.size() != 1 || (!entIds.get(0).equals(loginEntId))) {
                         throw new RuntimeException("存在有承运单位与登录账号不属于同单位!");
                     }
                 } else {
@@ -894,6 +939,54 @@ public class KwtAcceptCarriageOrderImportService {
         });
     }
 
+    /**
+     * 验证地址是不是装卸货地址类型
+     *
+     * @param addressRes
+     * @param loadAddressName
+     * @param unloadAddressName
+     * @param number
+     */
+    private void checkOrderAddress(List<EntAddressResDto> addressRes, String loadAddressName, String unloadAddressName, int number) {
+        Map<Integer, List<EntAddressResDto>> collect = addressRes.stream().collect(Collectors.groupingBy(EntAddressResDto::getDefaultType));
+        List<String> loadAddress = new ArrayList<>();
+        List<String> unloadAddress = new ArrayList<>();
+        List<EntAddressResDto> loadAddressRes = collect.get(AddressDefaultTypeEnum.SHIPMENT.getCode());
+        if (CollectionUtils.isNotEmpty(loadAddressRes)) {
+            List<String> loadAddressStr = loadAddressRes.stream().map(EntAddressResDto::getName).collect(Collectors.toList());
+            loadAddress.addAll(loadAddressStr);
+        }
+        List<EntAddressResDto> unloadAddressRes = collect.get(AddressDefaultTypeEnum.TAKE.getCode());
+        if (CollectionUtils.isNotEmpty(unloadAddressRes)) {
+            List<String> unloadAddressStr = unloadAddressRes.stream().map(EntAddressResDto::getName).collect(Collectors.toList());
+            unloadAddress.addAll(unloadAddressStr);
+        }
+        List<EntAddressResDto> allAddressRes = collect.get(AddressDefaultTypeEnum.BOTH.getCode());
+        if (CollectionUtils.isNotEmpty(allAddressRes)) {
+            List<String> allAddress = allAddressRes.stream().map(EntAddressResDto::getName).collect(Collectors.toList());
+            loadAddress.addAll(allAddress);
+            unloadAddress.addAll(allAddress);
+        }
+        if (loadAddress.size() < 1) {
+            throw new RuntimeException("第" + number + "行承运企业在系统中并未维护该装货地址");
+        }
+        if (unloadAddress.size() < 1) {
+            throw new RuntimeException("第" + number + "行承运企业在系统中并未维护该卸货地址");
+        }
+        if (loadAddress.size() > 0) {
+            loadAddress = loadAddress.stream().distinct().collect(Collectors.toList());
+            if (!loadAddress.contains(loadAddressName)) {
+                throw new RuntimeException("第" + number + "行承运企业在系统中并未维护该装货地址");
+            }
+        }
+        if (unloadAddress.size() > 0) {
+            unloadAddress = unloadAddress.stream().distinct().collect(Collectors.toList());
+            if (!unloadAddress.contains(unloadAddressName)) {
+                throw new RuntimeException("第" + number + "行承运企业在系统中并未维护该卸货地址");
+            }
+        }
+    }
+
     /**
      * @param file 上传文件
      * @desc 文件必填写校验