From 2b383e136460629bcbfcdf7dfc7cde4cce0f72c6 Mon Sep 17 00:00:00 2001 From: shanao Date: Tue, 10 Sep 2024 18:09:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AF=BC=E5=87=BA=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/accident/AccidentRecords.java | 123 ++++++++---------- .../impl/AccidentRecordsServiceImpl.java | 2 - 2 files changed, 57 insertions(+), 68 deletions(-) diff --git a/src/main/java/com/zcloud/entity/accident/AccidentRecords.java b/src/main/java/com/zcloud/entity/accident/AccidentRecords.java index caaaf76f..8810b955 100644 --- a/src/main/java/com/zcloud/entity/accident/AccidentRecords.java +++ b/src/main/java/com/zcloud/entity/accident/AccidentRecords.java @@ -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> 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 optional = dictMap.get(parentId).stream().filter(d -> d.getBIANMA().equals(bianma)).findAny(); - return optional.map(Dictionaries::getDICTIONARIES_ID).orElse(null); - } - List 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> 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 optional = dictMap.get(parentId).stream().filter(d -> d.getBIANMA().equals(bianma)).findAny(); +// return optional.map(Dictionaries::getDICTIONARIES_ID).orElse(null); +// } +// List 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"); +// } +// } } \ No newline at end of file diff --git a/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java b/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java index 4a28e89b..bb3c35c2 100644 --- a/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java +++ b/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java @@ -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 HEADER_ALIAS_CACHE; private final ImgFilesService imgFilesService;