From 8bf9254ba43e744517d4de2516121da2979fd057 Mon Sep 17 00:00:00 2001 From: liding <756868258@qq.com> Date: 星期二, 01 四月 2025 11:29:51 +0800 Subject: [PATCH] 1.检验项目参数导入 2.对象导入 --- basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardMethodServiceImpl.java | 108 ++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 72 insertions(+), 36 deletions(-) diff --git a/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardMethodServiceImpl.java b/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardMethodServiceImpl.java index e78edbf..4b893f1 100644 --- a/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardMethodServiceImpl.java +++ b/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardMethodServiceImpl.java @@ -171,58 +171,76 @@ } public void addStructureTest(List<Object> structureTestObjectIdList, List<StandardMethod> standardMethodList) { + // 鐢ㄤ簬瀛樺偍鏂板銆佹洿鏂板拰鍒犻櫎鐨勬暟鎹� List<StandardMethod> updateList = new ArrayList<>(); List<Integer> deleteListId = new ArrayList<>(); List<StandardMethod> addList = new ArrayList<>(); - // 鍏堝皢 Excel 鏁版嵁鎸� key 鍒嗙粍 + // 鍏堝皢 Excel 鏁版嵁鎸� code 鍒嗙粍锛屽苟鍚堝苟 field Map<String, StandardMethod> excelDataMap = new HashMap<>(); for (StandardMethod excelMethod : standardMethodList) { String key = generateKey(excelMethod); - excelDataMap.put(key, excelMethod); + if (excelDataMap.containsKey(key)) { + // 濡傛灉宸插瓨鍦ㄧ浉鍚岀殑 code锛屽垯鍚堝苟 field + StandardMethod existingMethod = excelDataMap.get(key); + String mergedField = mergeFields(existingMethod.getField(), excelMethod.getField()); + existingMethod.setField(mergedField); + } else { + // 鍚﹀垯鐩存帴娣诲姞鍒� map 涓� + excelDataMap.put(key, excelMethod); + } } -// if (!structureTestObjectIdList.isEmpty()) { - // 浠� excel 涓殑缁勫悕鏌ヨ鏁版嵁搴撲腑鐨勫垎缁� - List<StandardMethod> allDbMethods = new ArrayList<>(); - for (Object j : structureTestObjectIdList) { - List<StandardMethod> standardMethods = baseMapper.selectList(new LambdaQueryWrapper<StandardMethod>() - .like(StandardMethod::getStructureTestObjectId, "\"" + j + "\"")); - allDbMethods.addAll(standardMethods); - } + // 鏌ヨ鏁版嵁搴撲腑鐨勫垎缁勬暟鎹� + List<StandardMethod> allDbMethods = new ArrayList<>(); + for (Object j : structureTestObjectIdList) { + List<StandardMethod> standardMethods = baseMapper.selectList( + new LambdaQueryWrapper<StandardMethod>() + .apply("JSON_CONTAINS(structure_test_object_id, {0})", j) // MySQL JSON 鏌ヨ + ); + allDbMethods.addAll(standardMethods); + } - // 灏嗘暟鎹簱鏁版嵁鎸� key 鍒嗙粍 - Map<String, StandardMethod> dbDataMap = new HashMap<>(); - for (StandardMethod dbMethod : allDbMethods) { - String key = generateKey(dbMethod); + // 灏嗘暟鎹簱鏁版嵁鎸� code 鍒嗙粍锛屽苟鍚堝苟 field + Map<String, StandardMethod> dbDataMap = new HashMap<>(); + for (StandardMethod dbMethod : allDbMethods) { + String key = generateKey(dbMethod); + if (dbDataMap.containsKey(key)) { + // 濡傛灉宸插瓨鍦ㄧ浉鍚岀殑 code锛屽垯鍚堝苟 field + StandardMethod existingMethod = dbDataMap.get(key); + String mergedField = mergeFields(existingMethod.getField(), dbMethod.getField()); + existingMethod.setField(mergedField); + } else { + // 鍚﹀垯鐩存帴娣诲姞鍒� map 涓� dbDataMap.put(key, dbMethod); } + } - // 澶勭悊鏇存柊鍜屾柊澧� - for (Map.Entry<String, StandardMethod> entry : excelDataMap.entrySet()) { - String key = entry.getKey(); - StandardMethod excelMethod = entry.getValue(); - StandardMethod dbMethod = dbDataMap.get(key); - if (dbMethod != null) { - // 鏇存柊 - excelMethod.setId(dbMethod.getId()); - updateList.add(excelMethod); - } else { - // 鏂板 - addList.add(excelMethod); - } + // 澶勭悊鏇存柊鍜屾柊澧� + for (Map.Entry<String, StandardMethod> entry : excelDataMap.entrySet()) { + String key = entry.getKey(); + StandardMethod excelMethod = entry.getValue(); + StandardMethod dbMethod = dbDataMap.get(key); + if (dbMethod != null) { + // 鏇存柊 + excelMethod.setId(dbMethod.getId()); + updateList.add(excelMethod); + } else { + // 鏂板 + addList.add(excelMethod); } + } - // 澶勭悊鍒犻櫎 - for (Map.Entry<String, StandardMethod> entry : dbDataMap.entrySet()) { - String key = entry.getKey(); - if (!excelDataMap.containsKey(key)) { - StandardMethod dbMethod = entry.getValue(); - deleteListId.add(dbMethod.getId()); - } + // 澶勭悊鍒犻櫎 + for (Map.Entry<String, StandardMethod> entry : dbDataMap.entrySet()) { + String key = entry.getKey(); + if (!excelDataMap.containsKey(key)) { + StandardMethod dbMethod = entry.getValue(); + deleteListId.add(dbMethod.getId()); } + } - + // 鎵ц鎵归噺鎿嶄綔 if (!addList.isEmpty()) { // 鏂板 baseMapper.insertBatchSomeColumn(addList); @@ -241,8 +259,26 @@ } } + private String mergeFields(String field1, String field2) { + if (field1 == null || field1.isEmpty()) { + return field2; + } + if (field2 == null || field2.isEmpty()) { + return field1; + } + + // 浣跨敤 Set 鍘婚噸 + String[] fields1 = field1.split(","); + String[] fields2 = field2.split(","); + Set<String> uniqueFields = new HashSet<>(Arrays.asList(fields1)); + uniqueFields.addAll(Arrays.asList(fields2)); + + // 杩斿洖閫楀彿鎷兼帴鐨勭粨鏋� + return String.join(",", uniqueFields); + } + private String generateKey(StandardMethod method) { - return method.getStructureTestObjectId() + "-" + method.getCode() + "-" + method.getField(); + return method.getCode(); } // 鏍煎紡鍖栨暟鎹� -- Gitblit v1.9.3