Browse Source

高速云事件验重合并

develop
lau572 3 months ago
parent
commit
2ef54f1439
  1. 38
      zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java

38
zc-business/src/main/java/com/zc/business/service/impl/DcSdhsEventServiceImpl.java

@ -100,22 +100,42 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
String filePath = RuoYiConfig.getUploadPath() + newFileUrl;
ExcelUtil<DcSdhsEvent> util = new ExcelUtil<DcSdhsEvent>(DcSdhsEvent.class);
importData = util.importExcel(new FileInputStream(filePath));
InputStream inputStream = new FileInputStream(filePath);
importData = util.importExcel(inputStream);
inputStream.close();
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.error("导入失败,请检查数据是否有误");
}
redisCache.deleteObject(RedisKeyConstants.SDHS_EVENT);
//redisCache.deleteObject(RedisKeyConstants.SDHS_EVENT);
//根据开始事件验重,如果有时间重复的则本次不导入
List<DcSdhsEvent> eventCache = redisCache.getCacheList(RedisKeyConstants.SDHS_EVENT);
if (eventCache != null && eventCache.size() > 0){
Set<Date> oldStartTime = new HashSet<>();
eventCache.forEach(item -> {
oldStartTime.add(item.getStartTime());
});
if (importData != null && importData.size() > 0) {
List<Date> duplicateData = new ArrayList<>();
for (DcSdhsEvent importDatum : importData) {
if (oldStartTime.contains(importDatum.getStartTime())){
duplicateData.add(importDatum.getStartTime());
}
}
if (duplicateData.size() > 0){
return AjaxResult.error("本次导入含有重复数据",duplicateData);
}
}
}
List<DcSdhsEvent> eventList = new ArrayList<>();
if (importData != null && importData.size() > 0) {
int id = 1;
for (DcSdhsEvent dcSdhsEvent : importData) {
//插入id备用
dcSdhsEvent.setId(id);
//是否多车事故
String carNum = dcSdhsEvent.getCarNum();
if (StringUtils.isNotEmpty(carNum)) {
@ -164,13 +184,15 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService {
}
eventList.add(dcSdhsEvent);
id++;
}
}
//不入数据库, 放入缓存
redisCache.setCacheList(RedisKeyConstants.SDHS_EVENT, eventList);
if (eventList.size() > 0) {
redisCache.setCacheList(RedisKeyConstants.SDHS_EVENT, eventList);
}
Map<String, Object> fileInfo = new HashMap<>();
fileInfo.put("fileName", fileName);

Loading…
Cancel
Save