修复导出相关问题

hyx_2024-10-12_xgfPerson
shanao 2024-09-10 18:09:40 +08:00
parent dceba5c4b2
commit 2b383e1364
2 changed files with 57 additions and 68 deletions

View File

@ -1,11 +1,5 @@
package com.zcloud.entity.accident;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.zcloud.entity.accident.dto.AccidentRecordsExcel;
import com.zcloud.entity.system.Dictionaries;
import com.zcloud.service.system.DictionariesService;
import com.zcloud.util.Jurisdiction;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -13,10 +7,7 @@ import lombok.extern.slf4j.Slf4j;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Date;
/**
*
@ -171,60 +162,60 @@ public class AccidentRecords implements Serializable {
private static final long serialVersionUID = 1L;
public AccidentRecords(AccidentRecordsExcel reader, DictionariesService service) throws Exception {
this.id = IdUtil.getSnowflake(1, 1).nextId();
this.corpinfoId = reader.getCompanyName();
this.incidentNumber = reader.getIncidentNumber();
this.incidentName = reader.getIncidentName();
this.incidentType = findByName(reader.getIncidentType(), service, "8d4140a900184b60836ad1a6490fd510");
this.incidentLevel = findByName(reader.getIncidentLevel(), service, "b61a1edc59c0430c8741c5f51aa26c3c");
this.incidentNature = reader.getIncidentNature();
this.location = reader.getLocation();
this.incidentDate = dateFormat(reader.getIncidentDate());
this.directLoss = reader.getDirectLoss();
this.injured = reader.getInjured();
this.fatalities = reader.getFatalities();
this.seriouslyInjured = reader.getSeriouslyInjured();
this.cause = reader.getCause();
this.summary = reader.getSummary();
this.analysis = reader.getAnalysis();
this.suggestions = reader.getSuggestions();
this.measures = reader.getMeasures();
this.creator = reader.getCreator();
this.reportDate = dateFormat(reader.getReportDate());
this.createdBy = Jurisdiction.getUsername();
this.createdTime = new Date();
}
// 缓存字典 避免频繁请求数据库
public static final Map<String, List<Dictionaries>> dictMap = new ConcurrentHashMap<>();
private String findByName(String bianma, DictionariesService service, String parentId) throws Exception {
if (StrUtil.isEmpty(bianma)) {
return null;
}
if (dictMap.containsKey(parentId)) {
Optional<Dictionaries> optional = dictMap.get(parentId).stream().filter(d -> d.getBIANMA().equals(bianma)).findAny();
return optional.map(Dictionaries::getDICTIONARIES_ID).orElse(null);
}
List<Dictionaries> dict = service.listSubDictByParentId(parentId);
dict = dict == null ? new ArrayList<>() : dict;
dictMap.put(parentId, dict);
return dict.stream().filter(d -> d != null && d.getBIANMA().equals(bianma))
.findAny().map(Dictionaries::getDICTIONARIES_ID).orElse(null);
}
private Date dateFormat(String dateStr) {
if (StrUtil.isEmpty(dateStr)) {
return null;
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
return formatter.parse(dateStr);
} catch (ParseException e) {
log.error("日期转换失败", e);
throw new RuntimeException("日期转换失败支持的格式yyyy-MM-dd HH:mm:ss");
}
}
// public AccidentRecords(AccidentRecordsExcel reader, DictionariesService service) throws Exception {
// this.id = IdUtil.getSnowflake(1, 1).nextId();
// this.corpinfoId = reader.getCompanyName();
// this.incidentNumber = reader.getIncidentNumber();
// this.incidentName = reader.getIncidentName();
// this.incidentType = findByName(reader.getIncidentType(), service, "8d4140a900184b60836ad1a6490fd510");
// this.incidentLevel = findByName(reader.getIncidentLevel(), service, "b61a1edc59c0430c8741c5f51aa26c3c");
// this.incidentNature = reader.getIncidentNature();
// this.location = reader.getLocation();
// this.incidentDate = dateFormat(reader.getIncidentDate());
// this.directLoss = reader.getDirectLoss();
// this.injured = reader.getInjured();
// this.fatalities = reader.getFatalities();
// this.seriouslyInjured = reader.getSeriouslyInjured();
// this.cause = reader.getCause();
// this.summary = reader.getSummary();
// this.analysis = reader.getAnalysis();
// this.suggestions = reader.getSuggestions();
// this.measures = reader.getMeasures();
// this.creator = reader.getCreator();
// this.reportDate = dateFormat(reader.getReportDate());
// this.createdBy = Jurisdiction.getUsername();
// this.createdTime = new Date();
// }
//
// // 缓存字典 避免频繁请求数据库
// public static final Map<String, List<Dictionaries>> dictMap = new ConcurrentHashMap<>();
//
// private String findByName(String bianma, DictionariesService service, String parentId) throws Exception {
// if (StrUtil.isEmpty(bianma)) {
// return null;
// }
//
// if (dictMap.containsKey(parentId)) {
// Optional<Dictionaries> optional = dictMap.get(parentId).stream().filter(d -> d.getBIANMA().equals(bianma)).findAny();
// return optional.map(Dictionaries::getDICTIONARIES_ID).orElse(null);
// }
// List<Dictionaries> dict = service.listSubDictByParentId(parentId);
// dict = dict == null ? new ArrayList<>() : dict;
// dictMap.put(parentId, dict);
// return dict.stream().filter(d -> d != null && d.getBIANMA().equals(bianma))
// .findAny().map(Dictionaries::getDICTIONARIES_ID).orElse(null);
// }
//
// private Date dateFormat(String dateStr) {
// if (StrUtil.isEmpty(dateStr)) {
// return null;
// }
// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// try {
// return formatter.parse(dateStr);
// } catch (ParseException e) {
// log.error("日期转换失败", e);
// throw new RuntimeException("日期转换失败支持的格式yyyy-MM-dd HH:mm:ss");
// }
// }
}

View File

@ -32,8 +32,6 @@ import java.util.stream.Collectors;
public class AccidentRecordsServiceImpl implements AccidentRecordsService {
private final AccidentRecordsMapper accidentRecordsMapper;
//private final SqlSessionFactory sqlSessionFactory;
//private final DictionariesService dictionariesService;
private static final List<Field> HEADER_ALIAS_CACHE;
private final ImgFilesService imgFilesService;