fix: 产品标准去除重复文件接口
This commit is contained in:
+7
@@ -91,4 +91,11 @@ public class SarBussStandFileController extends BaseController<SarBussStandFile>
|
|||||||
String result = sarBussStandFileEOService.batchUpdateSarBussFileRepeat();
|
String result = sarBussStandFileEOService.batchUpdateSarBussFileRepeat();
|
||||||
return Result.success(result);
|
return Result.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "企标发布稿重复问题,去重处理,产品标准下划线和斜杠问题")
|
||||||
|
@GetMapping("/batchUpdateSarBussFileRepeat2")
|
||||||
|
public ResponseMessage<String> batchUpdateSarBussFileRepeat2() throws Exception {
|
||||||
|
String result = sarBussStandFileEOService.batchUpdateSarBussFileRepeat2();
|
||||||
|
return Result.success(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -23,4 +23,5 @@ public interface ISarBussStandFileService extends IService<SarBussStandFile> {
|
|||||||
ResponseMessage<List<SarBussStandFile>> batchUpdateSarBussFileMQ();
|
ResponseMessage<List<SarBussStandFile>> batchUpdateSarBussFileMQ();
|
||||||
|
|
||||||
String batchUpdateSarBussFileRepeat();
|
String batchUpdateSarBussFileRepeat();
|
||||||
|
String batchUpdateSarBussFileRepeat2();
|
||||||
}
|
}
|
||||||
|
|||||||
+60
@@ -191,6 +191,66 @@ public class SarBussStandFileServiceImpl extends ServiceImpl<SarBussStandFileDao
|
|||||||
}
|
}
|
||||||
return "去重成功";
|
return "去重成功";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String batchUpdateSarBussFileRepeat2() {
|
||||||
|
// 获取所有企标详情的企标ID和发布稿字段
|
||||||
|
LambdaQueryWrapper<SarBussStandAttrInfo> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(SarBussStandAttrInfo::getValidFlag,"0");
|
||||||
|
wrapper.isNotNull(SarBussStandAttrInfo::getFbgbuss);
|
||||||
|
wrapper.ne(SarBussStandAttrInfo::getFbgbuss,"");
|
||||||
|
wrapper.select(SarBussStandAttrInfo::getStandId,SarBussStandAttrInfo::getFbgbuss);
|
||||||
|
List<SarBussStandAttrInfo> allStand = standAttrInfoService.list(wrapper);
|
||||||
|
|
||||||
|
// 转换为Map
|
||||||
|
Map<String,String> fbBussMap = new HashMap<>();
|
||||||
|
allStand.forEach(each -> fbBussMap.put(each.getStandId(),each.getFbgbuss()));
|
||||||
|
// 循环每条数据
|
||||||
|
for (Map.Entry<String, String> entry : fbBussMap.entrySet()) {
|
||||||
|
// 把发布告文件做分割
|
||||||
|
List<String> attIdList = Arrays.asList(entry.getValue().split(","));
|
||||||
|
// 根据发布稿文件查询发布告的具体信息,获取原文件名
|
||||||
|
LambdaQueryWrapper<SarBussStandFile> wrapper1 = new LambdaQueryWrapper<>();
|
||||||
|
wrapper1.eq(SarBussStandFile::getValidFlag,"0");
|
||||||
|
wrapper1.in(SarBussStandFile::getAttId, attIdList);
|
||||||
|
List<SarBussStandFile> sarBussStandFileList = sarStandFileEODao.selectList(wrapper1);
|
||||||
|
sarBussStandFileList.forEach(each -> {
|
||||||
|
String fileName = each.getFileName().replace("/", "").replace("_", "");
|
||||||
|
each.setFileName(fileName);
|
||||||
|
});
|
||||||
|
// 使用 HashMap 记录已经出现过的 fileName
|
||||||
|
Map<String, SarBussStandFile> fileNameMap = new HashMap<>();
|
||||||
|
// 最终的结果列表
|
||||||
|
List<SarBussStandFile> deduplicatedList = new ArrayList<>();
|
||||||
|
// 遍历原始列表
|
||||||
|
for (SarBussStandFile file : sarBussStandFileList) {
|
||||||
|
String fileName = file.getFileName();
|
||||||
|
|
||||||
|
// 如果 fileName 已经在 map 中
|
||||||
|
if (fileNameMap.containsKey(fileName)) {
|
||||||
|
// 比较 createTime,保留更新时间较新的对象
|
||||||
|
SarBussStandFile existingFile = fileNameMap.get(fileName);
|
||||||
|
if (file.getCreationTime().after(existingFile.getCreationTime())) {
|
||||||
|
fileNameMap.put(fileName, file);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 如果 fileName 不存在,将该 fileName 加入 map,并将当前对象加入结果列表
|
||||||
|
fileNameMap.put(fileName, file);
|
||||||
|
deduplicatedList.add(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 如果长度不相等,说明执行了去重,需要修改,重新放回企标详情表中
|
||||||
|
String fbgbuss = deduplicatedList.stream().map(SarBussStandFile::getAttId).collect(Collectors.joining(","));
|
||||||
|
if (fbgbuss.length() != entry.getValue().length()) {
|
||||||
|
LambdaUpdateWrapper<SarBussStandAttrInfo> wrapper2 = new LambdaUpdateWrapper<>();
|
||||||
|
wrapper2.eq(SarBussStandAttrInfo::getStandId,entry.getKey());
|
||||||
|
wrapper2.set(SarBussStandAttrInfo::getFbgbuss,fbgbuss);
|
||||||
|
standAttrInfoService.update(wrapper2);
|
||||||
|
logger.info("出现重复的企标:"+ entry.getKey() + ",去重后发布稿包含:" + fbgbuss + "---去重前发布稿包含:" + entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "去重成功";
|
||||||
|
}
|
||||||
public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
|
public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
|
||||||
Set<Object> seen = ConcurrentHashMap.newKeySet();
|
Set<Object> seen = ConcurrentHashMap.newKeySet();
|
||||||
return t -> seen.add(keyExtractor.apply(t));
|
return t -> seen.add(keyExtractor.apply(t));
|
||||||
|
|||||||
Reference in New Issue
Block a user