diff --git a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java index d1f125a8..2e9beef3 100644 --- a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java +++ b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java @@ -1,6 +1,6 @@ package com.zcloud.controller.accident; -import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.zcloud.controller.base.BaseController; @@ -38,7 +38,11 @@ public class AccidentRecordsController extends BaseController { @ResponseBody @RequestMapping(value = "/page") public Map queryPage(Page page, HttpServletRequest request) { - page.setPd(new PageData(request)); + PageData data = new PageData(request); + if (ObjectUtil.isEmpty(data.get("type"))) { + throw new RuntimeException("type不能为空"); + } + page.setPd(data); Map result = new HashMap<>(); result.put("result", "success"); result.put("varList", accidentRecordsService.queryPage(page)); @@ -70,11 +74,8 @@ public class AccidentRecordsController extends BaseController { @ResponseBody @RequestMapping("/save") public Map save(HttpServletRequest request) { - PageData pageData = new PageData(request); - if (CollUtil.isEmpty(pageData)){ - throw new RuntimeException("参数不能为空"); - } - accidentRecordsService.save(pageData); + AccidentRecords accidentRecords = BeanUtil.mapToBean(new PageData(request), AccidentRecords.class, true); + accidentRecordsService.save(accidentRecords); Map result = new HashMap<>(); result.put("result", "success"); return result; @@ -90,13 +91,9 @@ public class AccidentRecordsController extends BaseController { @RequestMapping("/update") public Map update(HttpServletRequest request) { PageData pageData = new PageData(request); - if (CollUtil.isEmpty(pageData)){ - throw new RuntimeException("参数不能为空"); - } - if (pageData.get("id") == null) { - throw new RuntimeException("id不能为空"); - } - accidentRecordsService.update(pageData); + AccidentRecords accidentRecords = BeanUtil.mapToBean(pageData, AccidentRecords.class, true); + accidentRecords.setId(Optional.of(accidentRecords.getId()).orElseThrow(() -> new RuntimeException("id不能为空"))); + accidentRecordsService.update(accidentRecords); Map result = new HashMap<>(); result.put("result", "success"); return result; diff --git a/src/main/java/com/zcloud/entity/accident/AccidentRecords.java b/src/main/java/com/zcloud/entity/accident/AccidentRecords.java index f44e8ca1..3fc74355 100644 --- a/src/main/java/com/zcloud/entity/accident/AccidentRecords.java +++ b/src/main/java/com/zcloud/entity/accident/AccidentRecords.java @@ -1,5 +1,9 @@ package com.zcloud.entity.accident; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import com.zcloud.entity.PageData; import lombok.Data; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -35,6 +39,11 @@ public class AccidentRecords implements Serializable { @Size(max = 100, message = "事故名称最大长度要小于 100") private String incidentName; + /** + * 1事件/2事故 + */ + private String type; + /** * 事故类型 */ @@ -106,6 +115,11 @@ public class AccidentRecords implements Serializable { */ private String photos; + /** + * 附件地址 + */ + private String attachmentAddress; + /** * 原因分析及责任认定 */ @@ -162,6 +176,37 @@ public class AccidentRecords implements Serializable { private static final long serialVersionUID = 1L; + public AccidentRecords(PageData data) { + setIncidentNumber(data.getString("incidentNumber")); + setId(data.getString("id")); + setIncidentName(data.getString("incidentName")); + setIncidentType(data.getString("incidentType")); + setIncidentLevel(data.getString("incidentLevel")); + setLocation(data.getString("location")); + setFatalities(toInt(data.get("fatalities"))); + DateTime time = DateUtil.parse(data.getString("incidentDate"), "yyyy-MM-dd HH:mm:ss"); + setIncidentDate(time); + DateTime time1 = DateUtil.parse(data.getString("incidentDate"), "yyyy-MM-dd HH:mm:ss"); + setReportDate(time1); + setDirectLoss(toInt(data.get("directLoss"))); + setInjured(toInt(data.get("injured"))); + setSeriouslyInjured(toInt(data.get("seriouslyInjured"))); + setCause(data.getString("cause")); + setSummary(data.getString("summary")); + setAnalysis(data.getString("analysis")); + setAttachmentAddress(data.getString("attachmentAddress")); + setType(data.getString("type")); + setSuggestions(data.getString("suggestions")); + setMeasures(data.getString("measures")); + setCreator(data.getString("creator")); + setPhotos(data.getString("photos")); + } + + private Integer toInt(Object object) { + Integer i = Convert.toInt(object); + return i == null ? 0 : i; + } + // public AccidentRecords(AccidentRecordsExcel reader, DictionariesService service) throws Exception { // this.id = IdUtil.getSnowflake(1, 1).nextId(); // this.corpinfoId = reader.getCompanyName(); 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 7cae2184..91b10f12 100644 --- a/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java +++ b/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java @@ -1,8 +1,6 @@ package com.zcloud.service.accident.impl; -import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DatePattern; -import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.lang.Assert; @@ -59,69 +57,23 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { @Override @Transactional(rollbackFor = Exception.class) - public void save(PageData pageData) { - AccidentRecords accidentRecords = new AccidentRecords(); + public void save(AccidentRecords accidentRecords) { accidentRecords.setId(IdUtil.fastSimpleUUID()); accidentRecords.setCreatedBy(Jurisdiction.getUsername()); - accidentRecords.setIsDeleted(0); String corpinfoId = StrUtil.isEmpty(accidentRecords.getCorpinfoId()) ? Jurisdiction.getCORPINFO_ID() : accidentRecords.getCorpinfoId(); accidentRecords.setCorpinfoId(corpinfoId); - accidentRecords.setIncidentNumber(pageData.getString("incidentNumber")); - accidentRecords.setIncidentName(pageData.getString("incidentName")); - accidentRecords.setIncidentType(pageData.getString("incidentType")); - accidentRecords.setIncidentLevel(pageData.getString("incidentLevel")); - accidentRecords.setLocation(pageData.getString("location")); - accidentRecords.setFatalities(Convert.toInt(pageData.get("fatalities"))); - - DateTime time = DateUtil.parse(pageData.getString("incidentDate"), "yyyy-MM-dd HH:mm:ss"); - accidentRecords.setIncidentDate(time); - DateTime time1 = DateUtil.parse(pageData.getString("incidentDate"), "yyyy-MM-dd HH:mm:ss"); - accidentRecords.setReportDate(time1); - - accidentRecords.setDirectLoss(Convert.toInt(pageData.get("directLoss"))); - accidentRecords.setInjured(Convert.toInt(pageData.get("injured"))); - accidentRecords.setSeriouslyInjured(Convert.toInt(pageData.get("seriouslyInjured"))); - accidentRecords.setCause(pageData.getString("cause")); - accidentRecords.setSummary(pageData.getString("summary")); - accidentRecords.setAnalysis(pageData.getString("analysis")); - accidentRecords.setSuggestions(pageData.getString("suggestions")); - accidentRecords.setMeasures(pageData.getString("measures")); - accidentRecords.setCreator(pageData.getString("creator")); - accidentRecords.setPhotos(pageData.getString("photos")); + accidentRecords.setCreatedTime(new Date()); Assert.isTrue(accidentRecordsMapper.save(accidentRecords) == 1, "新增事故记录失败"); } @Override @Transactional(rollbackFor = Exception.class) - public void update(PageData pageData) { - AccidentRecords accidentRecords = new AccidentRecords(); - accidentRecords.setIncidentNumber(pageData.getString("incidentNumber")); - accidentRecords.setId(pageData.getString("id")); - accidentRecords.setIncidentName(pageData.getString("incidentName")); - accidentRecords.setIncidentType(pageData.getString("incidentType")); - accidentRecords.setIncidentLevel(pageData.getString("incidentLevel")); - accidentRecords.setLocation(pageData.getString("location")); - accidentRecords.setFatalities(Convert.toInt(pageData.get("fatalities"))); - - DateTime time = DateUtil.parse(pageData.getString("incidentDate"), "yyyy-MM-dd HH:mm:ss"); - accidentRecords.setIncidentDate(time); - DateTime time1 = DateUtil.parse(pageData.getString("incidentDate"), "yyyy-MM-dd HH:mm:ss"); - accidentRecords.setReportDate(time1); - - accidentRecords.setDirectLoss(Convert.toInt(pageData.get("directLoss"))); - accidentRecords.setInjured(Convert.toInt(pageData.get("injured"))); - accidentRecords.setSeriouslyInjured(Convert.toInt(pageData.get("seriouslyInjured"))); - accidentRecords.setCause(pageData.getString("cause")); - accidentRecords.setSummary(pageData.getString("summary")); - accidentRecords.setAnalysis(pageData.getString("analysis")); - accidentRecords.setSuggestions(pageData.getString("suggestions")); - accidentRecords.setMeasures(pageData.getString("measures")); - accidentRecords.setCreator(pageData.getString("creator")); - accidentRecords.setPhotos(pageData.getString("creator")); + public void update(AccidentRecords accidentRecords) { accidentRecords.setUpdatedBy(Jurisdiction.getUsername()); accidentRecords.setUpdatedTime(new Date()); - accidentRecords.setPhotos(pageData.getString("photos") == null ? null : pageData.getString("photos")); + // 不支持修改类型 + accidentRecords.setType(null); String corpinfoId = StrUtil.isEmpty(accidentRecords.getCorpinfoId()) ? Jurisdiction.getCORPINFO_ID() : accidentRecords.getCorpinfoId(); accidentRecords.setCorpinfoId(corpinfoId); Assert.isTrue(accidentRecordsMapper.updateById(accidentRecords) == 1, "更新事故记录失败"); diff --git a/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml b/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml index fcfd5164..c1d452d0 100644 --- a/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml +++ b/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml @@ -3,7 +3,8 @@