From 73f05b763878b03725e347c7da4c916481cc5831 Mon Sep 17 00:00:00 2001 From: wangpeng Date: Fri, 30 Aug 2024 18:04:21 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BA=8B=E6=95=85?= =?UTF-8?q?=E8=B0=83=E6=9F=A5=E7=AE=A1=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accident/AccidentRecordsController.java | 74 +++++ .../entity/accident/AccidentRecords.java | 162 ++++++++++ .../accident/dto/AccidentRecordsDto.java | 136 ++++++++ .../entity/accident/validated/Create.java | 4 + .../entity/accident/validated/Update.java | 4 + .../accident/AccidentRecordsMapper.java | 21 ++ .../accident/AccidentRecordsService.java | 20 ++ .../impl/AccidentRecordsServiceImpl.java | 60 ++++ .../accident/AccidentRecordsMapper.xml | 300 ++++++++++++++++++ 9 files changed, 781 insertions(+) create mode 100644 src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java create mode 100644 src/main/java/com/zcloud/entity/accident/AccidentRecords.java create mode 100644 src/main/java/com/zcloud/entity/accident/dto/AccidentRecordsDto.java create mode 100644 src/main/java/com/zcloud/entity/accident/validated/Create.java create mode 100644 src/main/java/com/zcloud/entity/accident/validated/Update.java create mode 100644 src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java create mode 100644 src/main/java/com/zcloud/service/accident/AccidentRecordsService.java create mode 100644 src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java create mode 100644 src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml diff --git a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java new file mode 100644 index 00000000..d391fac8 --- /dev/null +++ b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java @@ -0,0 +1,74 @@ +package com.zcloud.controller.accident; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.lang.Assert; +import com.zcloud.controller.base.BaseController; +import com.zcloud.entity.Page; +import com.zcloud.entity.PageData; +import com.zcloud.entity.accident.AccidentRecords; +import com.zcloud.service.accident.AccidentRecordsService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + +@RequiredArgsConstructor +@RestController("/accident") +public class AccidentRecordsController extends BaseController { + + private final AccidentRecordsService accidentRecordsService; + + @RequestMapping(value = "/page") + public Map queryPage(Page page, HttpServletRequest request) { + page.setPd(new PageData(request)); + Map result = new HashMap<>(); + result.put("result", "success"); + result.put("varList", accidentRecordsService.queryPage(page)); + result.put("page", page); + return result; + } + + @RequestMapping("/{id}") + public Map getById(@PathVariable("id") Long id) { + Assert.notNull(id, "id不能为空"); + Map result = new HashMap<>(); + result.put("result", "success"); + result.put("info", accidentRecordsService.getById(id)); + return result; + } + + @RequestMapping("/save") + public Map save(HttpServletRequest request) { + AccidentRecords accidentRecords = BeanUtil.mapToBean(new PageData(request), AccidentRecords.class, true); + accidentRecordsService.save(accidentRecords); + Map result = new HashMap<>(); + result.put("result", "success"); + return result; + } + + @RequestMapping("/update") + public Map update(HttpServletRequest request) { + AccidentRecords accidentRecords = BeanUtil.mapToBean(new PageData(request), AccidentRecords.class, true); + accidentRecordsService.update(accidentRecords); + Map result = new HashMap<>(); + result.put("result", "success"); + return result; + } + + @RequestMapping("/delete/{ids}") + public Map delete(@PathVariable("ids") String values) { + Assert.notEmpty(values, "ids不能为空"); + Long[] ids = Arrays.stream(values.split(",")).map(Convert::toLong).collect(Collectors.toList()).toArray(new Long[]{}); + accidentRecordsService.delete(ids); + 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 new file mode 100644 index 00000000..19622124 --- /dev/null +++ b/src/main/java/com/zcloud/entity/accident/AccidentRecords.java @@ -0,0 +1,162 @@ +package com.zcloud.entity.accident; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.io.Serializable; +import java.util.Date; + +/** + * 事故记录表 + */ +@Data +@NoArgsConstructor +public class AccidentRecords implements Serializable { + + /** + * 主键ID + */ + @NotNull(message = "主键ID不能为null") + private Long id; + + /** + * 事故案号 + */ + @Size(max = 50,message = "事故案号最大长度要小于 50") + private String incidentNumber; + + /** + * 事故名称 + */ + @Size(max = 100,message = "事故名称最大长度要小于 100") + private String incidentName; + + /** + * 事故类型 + */ + private Integer incidentType; + + /** + * 所属公司 + */ + @Size(max = 100,message = "所属公司最大长度要小于 100") + private String companyName; + + /** + * 事故级别 + */ + @Size(max = 50,message = "事故级别最大长度要小于 50") + private String incidentLevel; + + /** + * 事故性质 + */ + @Size(max = 50,message = "事故性质最大长度要小于 50") + private String incidentNature; + + /** + * 事故发生地点 + */ + @Size(max = 200,message = "事故发生地点最大长度要小于 200") + private String location; + + /** + * 事故发生时间 + */ + private Date incidentDate; + + /** + * 直接经济损失(万元) + */ + @Size(max = 100,message = "直接经济损失(万元)最大长度要小于 100") + private String directLoss; + + /** + * 受伤人数 + */ + private Integer injured; + + /** + * 死亡人数 + */ + private Integer fatalities; + + /** + * 重伤人数 + */ + private Integer seriouslyInjured; + + /** + * 事故起因 + */ + @Size(max = 200,message = "事故起因最大长度要小于 200") + private String cause; + + /** + * 事故概述 + */ + private String summary; + + /** + * 事故照片(可以存储图片路径或使用 BLOB 类型存储图片本身) + */ + private String photos; + + /** + * 原因分析及责任认定 + */ + private String analysis; + + /** + * 考核建议 + */ + private String suggestions; + + /** + * 整改措施 + */ + private String measures; + + /** + * 填表人 + */ + @Size(max = 50,message = "填表人最大长度要小于 50") + private String creator; + + /** + * 报出日期 + */ + private Date reportDate; + + /** + * 创建人 + */ + @Size(max = 50,message = "创建人最大长度要小于 50") + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 修改人 + */ + @Size(max = 50,message = "修改人最大长度要小于 50") + private String updatedBy; + + /** + * 修改时间 + */ + private Date updatedTime; + + /** + * 逻辑删除标志,0=未删除,1=已删除 + */ + @NotNull(message = "逻辑删除标志,0=未删除,1=已删除不能为null") + private Integer isDeleted; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/zcloud/entity/accident/dto/AccidentRecordsDto.java b/src/main/java/com/zcloud/entity/accident/dto/AccidentRecordsDto.java new file mode 100644 index 00000000..4bd85622 --- /dev/null +++ b/src/main/java/com/zcloud/entity/accident/dto/AccidentRecordsDto.java @@ -0,0 +1,136 @@ +package com.zcloud.entity.accident.dto; + +import cn.hutool.core.date.DatePattern; +import com.zcloud.entity.accident.validated.Create; +import com.zcloud.entity.accident.validated.Update; +import lombok.Data; +import org.hibernate.validator.constraints.Range; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Null; +import javax.validation.constraints.Size; +import java.io.Serializable; +import java.util.Date; + +@Data +public class AccidentRecordsDto implements Serializable { + + /** + * 主键ID + */ + @NotNull(message = "主键ID不能为null", groups = Update.class) + @Null(message = "主键ID必须null", groups = Create.class) + private Long id; + + /** + * 事故案号 + */ + @Size(max = 50, message = "事故案号最大长度要小于 50", groups = {Create.class, Update.class}) + private String incidentNumber; + + /** + * 事故名称 + */ + @Size(max = 100, message = "事故名称最大长度要小于 100", groups = {Create.class, Update.class}) + private String incidentName; + + /** + * 事故类型 + */ + @Range(min = 1, max = 21, message = "事故类型范围在1-21之间", groups = {Create.class, Update.class}) + private Integer incidentType; + + /** + * 所属公司 + */ + @Size(max = 100, message = "所属公司最大长度要小于 100", groups = {Create.class, Update.class}) + private String companyName; + + /** + * 事故级别 + */ + @Size(max = 50, message = "事故级别最大长度要小于 50", groups = {Create.class, Update.class}) + private String incidentLevel; + + /** + * 事故性质 + */ + @Size(max = 50, message = "事故性质最大长度要小于 50", groups = {Create.class, Update.class}) + private String incidentNature; + + /** + * 事故发生地点 + */ + @Size(max = 200, message = "事故发生地点最大长度要小于 200", groups = {Create.class, Update.class}) + private String location; + + /** + * 事故发生时间 + */ + @DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN) + private Date incidentDate; + + /** + * 直接经济损失(万元) + */ + @Size(max = 100, message = "直接经济损失(万元)最大长度要小于 100", groups = {Create.class, Update.class}) + private String directLoss; + + /** + * 受伤人数 + */ + private Integer injured; + + /** + * 死亡人数 + */ + private Integer fatalities; + + /** + * 重伤人数 + */ + private Integer seriouslyInjured; + + /** + * 事故起因 + */ + @Size(max = 200, message = "事故起因最大长度要小于 200", groups = {Create.class, Update.class}) + private String cause; + + /** + * 事故概述 + */ + private String summary; + + /** + * 事故照片(可以存储图片路径或使用 BLOB 类型存储图片本身) + */ + private String photos; + + /** + * 原因分析及责任认定 + */ + private String analysis; + + /** + * 考核建议 + */ + private String suggestions; + + /** + * 整改措施 + */ + private String measures; + + /** + * 填表人 + */ + @Size(max = 50, message = "填表人最大长度要小于 50", groups = {Create.class, Update.class}) + private String creator; + + /** + * 报出日期 + */ + private Date reportDate; +} diff --git a/src/main/java/com/zcloud/entity/accident/validated/Create.java b/src/main/java/com/zcloud/entity/accident/validated/Create.java new file mode 100644 index 00000000..e5bcbe1e --- /dev/null +++ b/src/main/java/com/zcloud/entity/accident/validated/Create.java @@ -0,0 +1,4 @@ +package com.zcloud.entity.accident.validated; + +public interface Create { +} diff --git a/src/main/java/com/zcloud/entity/accident/validated/Update.java b/src/main/java/com/zcloud/entity/accident/validated/Update.java new file mode 100644 index 00000000..e8e51888 --- /dev/null +++ b/src/main/java/com/zcloud/entity/accident/validated/Update.java @@ -0,0 +1,4 @@ +package com.zcloud.entity.accident.validated; + +public interface Update { +} diff --git a/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java b/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java new file mode 100644 index 00000000..d55f9a9e --- /dev/null +++ b/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java @@ -0,0 +1,21 @@ +package com.zcloud.mapper.datasource.accident; + +import com.zcloud.entity.Page; +import com.zcloud.entity.PageData; +import com.zcloud.entity.accident.AccidentRecords; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface AccidentRecordsMapper { + + List listPage(Page page); + + PageData getById(Long id); + + int save(AccidentRecords accidentRecords); + + int updateById(AccidentRecords accidentRecords); + + int delete(@Param("ids") Long[] ids); +} \ No newline at end of file diff --git a/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java b/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java new file mode 100644 index 00000000..6e005c73 --- /dev/null +++ b/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java @@ -0,0 +1,20 @@ +package com.zcloud.service.accident; + +import com.zcloud.entity.Page; +import com.zcloud.entity.PageData; +import com.zcloud.entity.accident.AccidentRecords; + +import java.util.List; + +public interface AccidentRecordsService { + + List queryPage(Page page); + + PageData getById(Long id); + + void save(AccidentRecords accidentRecords); + + void update(AccidentRecords bean); + + void delete(Long[] ids); +} diff --git a/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java b/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java new file mode 100644 index 00000000..7329da0b --- /dev/null +++ b/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java @@ -0,0 +1,60 @@ +package com.zcloud.service.accident.impl; + +import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.IdUtil; +import com.zcloud.entity.Page; +import com.zcloud.entity.PageData; +import com.zcloud.entity.accident.AccidentRecords; +import com.zcloud.entity.accident.validated.Create; +import com.zcloud.entity.accident.validated.Update; +import com.zcloud.mapper.datasource.accident.AccidentRecordsMapper; +import com.zcloud.service.accident.AccidentRecordsService; +import com.zcloud.util.Jurisdiction; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +import java.util.Date; +import java.util.List; + +@Service +@RequiredArgsConstructor +public class AccidentRecordsServiceImpl implements AccidentRecordsService { + + private final AccidentRecordsMapper accidentRecordsMapper; + + @Override + public List queryPage(Page page) { + return accidentRecordsMapper.listPage(page); + } + + @Override + public PageData getById(Long id) { + return accidentRecordsMapper.getById(id); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(@Validated(Create.class) AccidentRecords accidentRecords) { + accidentRecords.setId(IdUtil.getSnowflake(1, 1).nextId()); + accidentRecords.setCreatedBy(Jurisdiction.getUsername()); + accidentRecords.setCreatedTime(new Date()); + accidentRecords.setIsDeleted(0); + Assert.isTrue(accidentRecordsMapper.save(accidentRecords) == 1, "新增事故记录失败"); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(@Validated(Update.class) AccidentRecords accidentRecords) { + accidentRecords.setUpdatedBy(Jurisdiction.getUsername()); + accidentRecords.setUpdatedTime(new Date()); + Assert.isTrue(accidentRecordsMapper.updateById(accidentRecords) == 1, "更新事故记录失败"); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(Long[] ids) { + Assert.isTrue(accidentRecordsMapper.delete(ids) == ids.length, "删除事故记录失败"); + } +} diff --git a/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml b/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml new file mode 100644 index 00000000..1994e374 --- /dev/null +++ b/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml @@ -0,0 +1,300 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id, incident_number, incident_name, incident_type, company_name, incident_level, + incident_nature, `location`, incident_date, direct_loss, injured, fatalities, seriously_injured, + cause, summary, photos, analysis, suggestions, measures, creator, report_date, created_by, + created_time, updated_by, updated_time, is_deleted + + + + + + + + insert into accident_records + + + id, + + + incident_number, + + + incident_name, + + + incident_type, + + + company_name, + + + incident_level, + + + incident_nature, + + + location, + + + incident_date, + + + direct_loss, + + + injured, + + + fatalities, + + + seriously_injured, + + + cause, + + + summary, + + + photos, + + + analysis, + + + suggestions, + + + measures, + + + creator, + + + report_date, + + + created_by, + + + created_time, + + + updated_by, + + + updated_time, + + + is_deleted + + + values + + + id, + + + #{incidentNumber}, + + + #{incidentName}, + + + #{incidentType}, + + + #{companyName}, + + + #{incidentLevel}, + + + #{incidentNature}, + + + #{location}, + + + #{incidentDate}, + + + #{directLoss}, + + + #{injured}, + + + #{fatalities}, + + + #{seriouslyInjured}, + + + #{cause}, + + + #{summary}, + + + #{photos}, + + + #{analysis}, + + + #{suggestions}, + + + #{measures}, + + + #{creator}, + + + #{reportDate}, + + + #{createdBy}, + + + #{createdTime}, + + + #{updatedBy}, + + + #{updatedTime}, + + + #{isDeleted} + + + + + + UPDATE accident_records + + incident_number = #{incidentNumber}, + incident_name = #{incidentName}, + incident_type = #{incidentType}, + company_name = #{companyName}, + incident_level = #{incidentLevel}, + incident_nature = #{incidentNature}, + location = #{location}, + incident_date = #{incidentDate}, + direct_loss = #{directLoss}, + injured = #{injured}, + fatalities = #{fatalities}, + seriously_injured = #{seriouslyInjured}, + cause = #{cause}, + summary = #{summary}, + photos = #{photos}, + analysis = #{analysis}, + suggestions = #{suggestions}, + measures = #{measures}, + creator = #{creator}, + report_date = #{reportDate}, + created_by = #{createdBy}, + created_time = #{createdTime}, + updated_by = #{updatedBy}, + updated_time = #{updatedTime}, + is_deleted = #{isDeleted} + + WHERE id = #{id} and is_deleted = 0 + + + + update accident_records + set is_deleted = 1 + where + id IN + + #{item} + + + \ No newline at end of file From 70c1ee4c3fa8e8e47acc422690481411dbf79498 Mon Sep 17 00:00:00 2001 From: wangpeng Date: Fri, 30 Aug 2024 18:07:30 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BA=8B=E6=95=85?= =?UTF-8?q?=E8=B0=83=E6=9F=A5=E7=AE=A1=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zcloud/controller/accident/AccidentRecordsController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java index d391fac8..cbf62b3e 100644 --- a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java +++ b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java @@ -25,6 +25,7 @@ public class AccidentRecordsController extends BaseController { private final AccidentRecordsService accidentRecordsService; + @RequestMapping(value = "/page") public Map queryPage(Page page, HttpServletRequest request) { page.setPd(new PageData(request)); From c15fdba0a743c1b56cdf21e41055b98fc58c5082 Mon Sep 17 00:00:00 2001 From: wangpeng Date: Mon, 2 Sep 2024 16:11:56 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=20excel=20=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=20=E5=AF=BC=E5=87=BA=20=E7=9B=B8=E5=85=B3=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../accident/AccidentRecordsController.java | 30 +++- .../controller/system/UsersController.java | 5 - .../entity/accident/AccidentRecords.java | 95 ++++++++++-- .../zcloud/entity/accident/ExcelValue.java | 16 +++ .../accident/dto/AccidentRecordsDto.java | 136 ------------------ .../accident/dto/AccidentRecordsExcel.java | 124 ++++++++++++++++ .../accident/AccidentRecordsMapper.java | 5 + .../accident/AccidentRecordsService.java | 6 + .../impl/AccidentRecordsServiceImpl.java | 90 +++++++++++- .../accident/AccidentRecordsMapper.xml | 123 +++++++++------- 11 files changed, 413 insertions(+), 219 deletions(-) create mode 100644 src/main/java/com/zcloud/entity/accident/ExcelValue.java delete mode 100644 src/main/java/com/zcloud/entity/accident/dto/AccidentRecordsDto.java create mode 100644 src/main/java/com/zcloud/entity/accident/dto/AccidentRecordsExcel.java diff --git a/pom.xml b/pom.xml index 6576b988..06b1148c 100644 --- a/pom.xml +++ b/pom.xml @@ -215,7 +215,7 @@ aliyun-java-sdk-core 3.3.1 - + com.aliyun aliyun-java-sdk-dysmsapi 1.0.0 diff --git a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java index cbf62b3e..f2718233 100644 --- a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java +++ b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java @@ -2,7 +2,6 @@ package com.zcloud.controller.accident; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.convert.Convert; -import cn.hutool.core.lang.Assert; import com.zcloud.controller.base.BaseController; import com.zcloud.entity.Page; import com.zcloud.entity.PageData; @@ -11,12 +10,16 @@ import com.zcloud.service.accident.AccidentRecordsService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; @RequiredArgsConstructor @@ -25,7 +28,6 @@ public class AccidentRecordsController extends BaseController { private final AccidentRecordsService accidentRecordsService; - @RequestMapping(value = "/page") public Map queryPage(Page page, HttpServletRequest request) { page.setPd(new PageData(request)); @@ -38,16 +40,16 @@ public class AccidentRecordsController extends BaseController { @RequestMapping("/{id}") public Map getById(@PathVariable("id") Long id) { - Assert.notNull(id, "id不能为空"); Map result = new HashMap<>(); result.put("result", "success"); - result.put("info", accidentRecordsService.getById(id)); + result.put("info", accidentRecordsService.getById(Optional.of(id).orElseThrow(() -> new RuntimeException("id不能为空")))); return result; } @RequestMapping("/save") public Map save(HttpServletRequest request) { AccidentRecords accidentRecords = BeanUtil.mapToBean(new PageData(request), AccidentRecords.class, true); + accidentRecords.setCorpinfoId(Optional.of(accidentRecords.getCorpinfoId()).orElseThrow(() -> new RuntimeException("所属公司不能为空"))); accidentRecordsService.save(accidentRecords); Map result = new HashMap<>(); result.put("result", "success"); @@ -57,6 +59,8 @@ public class AccidentRecordsController extends BaseController { @RequestMapping("/update") public Map update(HttpServletRequest request) { AccidentRecords accidentRecords = BeanUtil.mapToBean(new PageData(request), AccidentRecords.class, true); + accidentRecords.setId(Optional.of(accidentRecords.getId()).orElseThrow(() -> new RuntimeException("id不能为空"))); + accidentRecords.setCorpinfoId(Optional.of(accidentRecords.getCorpinfoId()).orElseThrow(() -> new RuntimeException("所属公司不能为空"))); accidentRecordsService.update(accidentRecords); Map result = new HashMap<>(); result.put("result", "success"); @@ -65,11 +69,25 @@ public class AccidentRecordsController extends BaseController { @RequestMapping("/delete/{ids}") public Map delete(@PathVariable("ids") String values) { - Assert.notEmpty(values, "ids不能为空"); - Long[] ids = Arrays.stream(values.split(",")).map(Convert::toLong).collect(Collectors.toList()).toArray(new Long[]{}); + String[] split = Optional.of(values).orElseThrow(() -> new RuntimeException("ids不能为空")).split(","); + Long[] ids = Arrays.stream(split).map(Convert::toLong).collect(Collectors.toList()).toArray(new Long[]{}); accidentRecordsService.delete(ids); Map result = new HashMap<>(); result.put("result", "success"); return result; } + + @RequestMapping("/export/excel") + public void exportExcel(HttpServletRequest request ,HttpServletResponse response) { + PageData pd = new PageData(request); + accidentRecordsService.exportExcel(pd,response); + } + + @RequestMapping("/import/excel") + public void importExcel(@RequestParam("file") MultipartFile file) { + if (file == null || file.isEmpty()) { + throw new RuntimeException("文件不能为空"); + } + accidentRecordsService.importExcel(file); + } } diff --git a/src/main/java/com/zcloud/controller/system/UsersController.java b/src/main/java/com/zcloud/controller/system/UsersController.java index 098ad1d2..5cd7b3ae 100644 --- a/src/main/java/com/zcloud/controller/system/UsersController.java +++ b/src/main/java/com/zcloud/controller/system/UsersController.java @@ -7,17 +7,14 @@ import java.util.*; import javax.servlet.http.HttpServletResponse; import com.zcloud.entity.system.Dictionaries; -import com.zcloud.entity.system.User; import com.zcloud.service.bus.*; import com.zcloud.service.system.*; import com.zcloud.util.*; import org.apache.commons.collections.map.ListOrderedMap; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateUtils; -import org.apache.fop.layoutmgr.PaddingElement; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.crypto.hash.SimpleHash; -import org.hyperic.sigar.pager.PageList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; @@ -33,8 +30,6 @@ import com.zcloud.entity.PageData; import com.zcloud.entity.system.Role; import net.sf.json.JSONArray; -import sun.security.krb5.internal.PAData; -import sun.util.logging.resources.logging; /** * 说明:系统用户处理类 diff --git a/src/main/java/com/zcloud/entity/accident/AccidentRecords.java b/src/main/java/com/zcloud/entity/accident/AccidentRecords.java index 19622124..58987287 100644 --- a/src/main/java/com/zcloud/entity/accident/AccidentRecords.java +++ b/src/main/java/com/zcloud/entity/accident/AccidentRecords.java @@ -1,16 +1,27 @@ package com.zcloud.entity.accident; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.zcloud.entity.PageData; +import com.zcloud.entity.accident.dto.AccidentRecordsExcel; +import com.zcloud.service.system.DictionariesService; +import com.zcloud.util.Jurisdiction; import lombok.Data; import lombok.NoArgsConstructor; +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.Date; +import java.util.Optional; /** * 事故记录表 */ +@Slf4j @Data @NoArgsConstructor public class AccidentRecords implements Serializable { @@ -24,13 +35,13 @@ public class AccidentRecords implements Serializable { /** * 事故案号 */ - @Size(max = 50,message = "事故案号最大长度要小于 50") + @Size(max = 50, message = "事故案号最大长度要小于 50") private String incidentNumber; /** * 事故名称 */ - @Size(max = 100,message = "事故名称最大长度要小于 100") + @Size(max = 100, message = "事故名称最大长度要小于 100") private String incidentName; /** @@ -41,25 +52,25 @@ public class AccidentRecords implements Serializable { /** * 所属公司 */ - @Size(max = 100,message = "所属公司最大长度要小于 100") - private String companyName; + @Size(max = 100, message = "所属公司最大长度要小于 100") + private String corpinfoId; /** * 事故级别 */ - @Size(max = 50,message = "事故级别最大长度要小于 50") - private String incidentLevel; + @Size(max = 50, message = "事故级别最大长度要小于 50") + private Integer incidentLevel; /** * 事故性质 */ - @Size(max = 50,message = "事故性质最大长度要小于 50") + @Size(max = 50, message = "事故性质最大长度要小于 50") private String incidentNature; /** * 事故发生地点 */ - @Size(max = 200,message = "事故发生地点最大长度要小于 200") + @Size(max = 200, message = "事故发生地点最大长度要小于 200") private String location; /** @@ -70,8 +81,8 @@ public class AccidentRecords implements Serializable { /** * 直接经济损失(万元) */ - @Size(max = 100,message = "直接经济损失(万元)最大长度要小于 100") - private String directLoss; + @Size(max = 100, message = "直接经济损失(万元)最大长度要小于 100") + private Integer directLoss; /** * 受伤人数 @@ -91,7 +102,7 @@ public class AccidentRecords implements Serializable { /** * 事故起因 */ - @Size(max = 200,message = "事故起因最大长度要小于 200") + @Size(max = 200, message = "事故起因最大长度要小于 200") private String cause; /** @@ -122,7 +133,7 @@ public class AccidentRecords implements Serializable { /** * 填表人 */ - @Size(max = 50,message = "填表人最大长度要小于 50") + @Size(max = 50, message = "填表人最大长度要小于 50") private String creator; /** @@ -133,7 +144,7 @@ public class AccidentRecords implements Serializable { /** * 创建人 */ - @Size(max = 50,message = "创建人最大长度要小于 50") + @Size(max = 50, message = "创建人最大长度要小于 50") private String createdBy; /** @@ -144,7 +155,7 @@ public class AccidentRecords implements Serializable { /** * 修改人 */ - @Size(max = 50,message = "修改人最大长度要小于 50") + @Size(max = 50, message = "修改人最大长度要小于 50") private String updatedBy; /** @@ -159,4 +170,60 @@ public class AccidentRecords implements Serializable { private Integer isDeleted; private static final long serialVersionUID = 1L; + + public AccidentRecords(AccidentRecordsExcel reader, DictionariesService service) { + 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); + this.incidentLevel = findByName(reader.getIncidentLevel(), service); + 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(); + } + + private Integer findByName(String name, DictionariesService service) { + if (StrUtil.isEmpty(name)) { + return null; + } + PageData pageData = new PageData(); + pageData.put("NAME", name); + try { + PageData data = service.findByName(pageData); + return Optional.ofNullable(data).map(pd -> (Integer) pd.get("BIANMA")).orElseThrow(() -> new RuntimeException("未找到字典数据:" + name)); + } catch (RuntimeException e) { + log.error("转换字典失败", e); + throw e; + } catch (Exception e) { + log.error("获取字典失败", e); + throw new RuntimeException("获取字典失败"); + } + } + + 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/entity/accident/ExcelValue.java b/src/main/java/com/zcloud/entity/accident/ExcelValue.java new file mode 100644 index 00000000..07824770 --- /dev/null +++ b/src/main/java/com/zcloud/entity/accident/ExcelValue.java @@ -0,0 +1,16 @@ +package com.zcloud.entity.accident; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target(FIELD) +@Retention(RUNTIME) +@Documented +public @interface ExcelValue { + + String value(); +} diff --git a/src/main/java/com/zcloud/entity/accident/dto/AccidentRecordsDto.java b/src/main/java/com/zcloud/entity/accident/dto/AccidentRecordsDto.java deleted file mode 100644 index 4bd85622..00000000 --- a/src/main/java/com/zcloud/entity/accident/dto/AccidentRecordsDto.java +++ /dev/null @@ -1,136 +0,0 @@ -package com.zcloud.entity.accident.dto; - -import cn.hutool.core.date.DatePattern; -import com.zcloud.entity.accident.validated.Create; -import com.zcloud.entity.accident.validated.Update; -import lombok.Data; -import org.hibernate.validator.constraints.Range; -import org.springframework.format.annotation.DateTimeFormat; - -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Null; -import javax.validation.constraints.Size; -import java.io.Serializable; -import java.util.Date; - -@Data -public class AccidentRecordsDto implements Serializable { - - /** - * 主键ID - */ - @NotNull(message = "主键ID不能为null", groups = Update.class) - @Null(message = "主键ID必须null", groups = Create.class) - private Long id; - - /** - * 事故案号 - */ - @Size(max = 50, message = "事故案号最大长度要小于 50", groups = {Create.class, Update.class}) - private String incidentNumber; - - /** - * 事故名称 - */ - @Size(max = 100, message = "事故名称最大长度要小于 100", groups = {Create.class, Update.class}) - private String incidentName; - - /** - * 事故类型 - */ - @Range(min = 1, max = 21, message = "事故类型范围在1-21之间", groups = {Create.class, Update.class}) - private Integer incidentType; - - /** - * 所属公司 - */ - @Size(max = 100, message = "所属公司最大长度要小于 100", groups = {Create.class, Update.class}) - private String companyName; - - /** - * 事故级别 - */ - @Size(max = 50, message = "事故级别最大长度要小于 50", groups = {Create.class, Update.class}) - private String incidentLevel; - - /** - * 事故性质 - */ - @Size(max = 50, message = "事故性质最大长度要小于 50", groups = {Create.class, Update.class}) - private String incidentNature; - - /** - * 事故发生地点 - */ - @Size(max = 200, message = "事故发生地点最大长度要小于 200", groups = {Create.class, Update.class}) - private String location; - - /** - * 事故发生时间 - */ - @DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN) - private Date incidentDate; - - /** - * 直接经济损失(万元) - */ - @Size(max = 100, message = "直接经济损失(万元)最大长度要小于 100", groups = {Create.class, Update.class}) - private String directLoss; - - /** - * 受伤人数 - */ - private Integer injured; - - /** - * 死亡人数 - */ - private Integer fatalities; - - /** - * 重伤人数 - */ - private Integer seriouslyInjured; - - /** - * 事故起因 - */ - @Size(max = 200, message = "事故起因最大长度要小于 200", groups = {Create.class, Update.class}) - private String cause; - - /** - * 事故概述 - */ - private String summary; - - /** - * 事故照片(可以存储图片路径或使用 BLOB 类型存储图片本身) - */ - private String photos; - - /** - * 原因分析及责任认定 - */ - private String analysis; - - /** - * 考核建议 - */ - private String suggestions; - - /** - * 整改措施 - */ - private String measures; - - /** - * 填表人 - */ - @Size(max = 50, message = "填表人最大长度要小于 50", groups = {Create.class, Update.class}) - private String creator; - - /** - * 报出日期 - */ - private Date reportDate; -} diff --git a/src/main/java/com/zcloud/entity/accident/dto/AccidentRecordsExcel.java b/src/main/java/com/zcloud/entity/accident/dto/AccidentRecordsExcel.java new file mode 100644 index 00000000..1fb330fd --- /dev/null +++ b/src/main/java/com/zcloud/entity/accident/dto/AccidentRecordsExcel.java @@ -0,0 +1,124 @@ +package com.zcloud.entity.accident.dto; + +import com.zcloud.entity.accident.ExcelValue; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class AccidentRecordsExcel implements Serializable { + + /** + * 事故案号 + */ + @ExcelValue(value = " 事故案号") + private String incidentNumber; + + /** + * 事故名称 + */ + @ExcelValue(value = " 事故名称") + private String incidentName; + + /** + * 事故类型 + */ + @ExcelValue(value = " 事故类型") + private String incidentType; + + /** + * 所属公司 + */ + @ExcelValue(value = "所属公司") + private String companyName; + + /** + * 事故级别 + */ + @ExcelValue(value = "事故级别") + private String incidentLevel; + + /** + * 事故性质 + */ + @ExcelValue(value = "事故性质") + private String incidentNature; + + /** + * 事故发生地点 + */ + @ExcelValue(value = "事故发生地点") + private String location; + + /** + * 事故发生时间 + */ + @ExcelValue(value = "事故发生时间") + private String incidentDate; + + /** + * 直接经济损失(万元) + */ + @ExcelValue(value = "直接经济损失(万元)") + private Integer directLoss; + + /** + * 受伤人数 + */ + @ExcelValue(value = "受伤人数") + private Integer injured; + + /** + * 死亡人数 + */ + @ExcelValue(value = "死亡人数") + private Integer fatalities; + + /** + * 重伤人数 + */ + @ExcelValue(value = "重伤人数") + private Integer seriouslyInjured; + + /** + * 事故起因 + */ + @ExcelValue(value = "事故起因") + private String cause; + + /** + * 事故概述 + */ + @ExcelValue(value = "事故概述") + private String summary; + + /** + * 原因分析及责任认定 + */ + @ExcelValue(value = "原因分析及责任认定") + private String analysis; + + /** + * 考核建议 + */ + @ExcelValue(value = "考核建议") + private String suggestions; + + /** + * 整改措施 + */ + @ExcelValue(value = "整改措施") + private String measures; + + /** + * 填表人 + */ + @ExcelValue(value = "填表人") + private String creator; + + /** + * 报出日期 + */ + @ExcelValue(value = "报出日期") + private String reportDate; +} diff --git a/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java b/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java index d55f9a9e..db023cbb 100644 --- a/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java +++ b/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java @@ -3,6 +3,7 @@ package com.zcloud.mapper.datasource.accident; import com.zcloud.entity.Page; import com.zcloud.entity.PageData; import com.zcloud.entity.accident.AccidentRecords; +import com.zcloud.entity.accident.dto.AccidentRecordsExcel; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -18,4 +19,8 @@ public interface AccidentRecordsMapper { int updateById(AccidentRecords accidentRecords); int delete(@Param("ids") Long[] ids); + + List listExcel(PageData pd); + + void saveExcel(AccidentRecordsExcel records, long id, String username); } \ No newline at end of file diff --git a/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java b/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java index 6e005c73..b718fe9e 100644 --- a/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java +++ b/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java @@ -3,7 +3,9 @@ package com.zcloud.service.accident; import com.zcloud.entity.Page; import com.zcloud.entity.PageData; import com.zcloud.entity.accident.AccidentRecords; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; import java.util.List; public interface AccidentRecordsService { @@ -17,4 +19,8 @@ public interface AccidentRecordsService { void update(AccidentRecords bean); void delete(Long[] ids); + + void exportExcel(PageData pd, HttpServletResponse response); + + void importExcel(MultipartFile 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 7329da0b..20593392 100644 --- a/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java +++ b/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java @@ -1,31 +1,59 @@ package com.zcloud.service.accident.impl; import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ReflectUtil; +import cn.hutool.core.util.URLUtil; +import cn.hutool.poi.excel.ExcelReader; +import cn.hutool.poi.excel.ExcelUtil; +import cn.hutool.poi.excel.ExcelWriter; import com.zcloud.entity.Page; import com.zcloud.entity.PageData; import com.zcloud.entity.accident.AccidentRecords; -import com.zcloud.entity.accident.validated.Create; -import com.zcloud.entity.accident.validated.Update; +import com.zcloud.entity.accident.ExcelValue; +import com.zcloud.entity.accident.dto.AccidentRecordsExcel; import com.zcloud.mapper.datasource.accident.AccidentRecordsMapper; import com.zcloud.service.accident.AccidentRecordsService; +import com.zcloud.service.system.DictionariesService; import com.zcloud.util.Jurisdiction; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.session.ExecutorType; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +@Slf4j @Service @RequiredArgsConstructor public class AccidentRecordsServiceImpl implements AccidentRecordsService { private final AccidentRecordsMapper accidentRecordsMapper; + private final SqlSessionFactory sqlSessionFactory; + private final DictionariesService dictionariesService; + private static final Map HEADER_ALIAS_CACHE; + + static { + HEADER_ALIAS_CACHE = Arrays.stream(ReflectUtil.getFields(AccidentRecordsExcel.class)) + .filter(field -> field.isAnnotationPresent(ExcelValue.class)) + .collect(Collectors.toMap(Field::getName, field -> field.getAnnotation(ExcelValue.class).value())); + } @Override public List queryPage(Page page) { + page.getPd().put("corpInfoId", Jurisdiction.getCORPINFO_ID()); return accidentRecordsMapper.listPage(page); } @@ -36,7 +64,7 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { @Override @Transactional(rollbackFor = Exception.class) - public void save(@Validated(Create.class) AccidentRecords accidentRecords) { + public void save(AccidentRecords accidentRecords) { accidentRecords.setId(IdUtil.getSnowflake(1, 1).nextId()); accidentRecords.setCreatedBy(Jurisdiction.getUsername()); accidentRecords.setCreatedTime(new Date()); @@ -46,7 +74,7 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { @Override @Transactional(rollbackFor = Exception.class) - public void update(@Validated(Update.class) AccidentRecords accidentRecords) { + public void update(AccidentRecords accidentRecords) { accidentRecords.setUpdatedBy(Jurisdiction.getUsername()); accidentRecords.setUpdatedTime(new Date()); Assert.isTrue(accidentRecordsMapper.updateById(accidentRecords) == 1, "更新事故记录失败"); @@ -57,4 +85,56 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { public void delete(Long[] ids) { Assert.isTrue(accidentRecordsMapper.delete(ids) == ids.length, "删除事故记录失败"); } + + @Override + public void exportExcel(PageData pd, HttpServletResponse response) { + // 查询数据 + pd.put("corpInfoId", Jurisdiction.getCORPINFO_ID()); + List list = accidentRecordsMapper.listExcel(pd); + + // 检查查询结果是否为空 + if (list == null || list.isEmpty()) { + throw new RuntimeException("没有查询到数据"); + } + + // 设置响应头 + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + URLUtil.encode("事故调查表", CharsetUtil.UTF_8) + ".xlsx"); + + try (ExcelWriter writer = ExcelUtil.getBigWriter()) { + writer.setHeaderAlias(HEADER_ALIAS_CACHE) + .setOnlyAlias(true) + .write(list, true) + .flush(response.getOutputStream()); + } catch (IOException e) { + log.error("导出excel失败", e); + throw new RuntimeException("导出excel失败"); + } + } + + @Override + public void importExcel(MultipartFile file) { + // ExecutorType.BATCH: 这个执行器会批量执行所有更新语句。 + SqlSession sqlSession = null; + try (ExcelReader reader = ExcelUtil.getReader(file.getInputStream())) { + // 标记别名 + HEADER_ALIAS_CACHE.forEach((k, v) -> reader.addHeaderAlias(v, k)); + List recordsExcels = reader.readAll(AccidentRecordsExcel.class); + sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); + AccidentRecordsMapper mapper = sqlSession.getMapper(AccidentRecordsMapper.class); + recordsExcels.forEach(accidentRecord -> mapper.save(new AccidentRecords(accidentRecord, dictionariesService))); + sqlSession.commit(); + } catch (Exception e) { + if (sqlSession != null) { + sqlSession.rollback(); + } + log.error("导入excel失败", e); + throw new RuntimeException("导入excel失败"); + } finally { + if (sqlSession != null) { + sqlSession.close(); + } + } + } } diff --git a/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml b/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml index 1994e374..4f5a3154 100644 --- a/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml +++ b/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml @@ -1,68 +1,35 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - id, incident_number, incident_name, incident_type, company_name, incident_level, - incident_nature, `location`, incident_date, direct_loss, injured, fatalities, seriously_injured, - cause, summary, photos, analysis, suggestions, measures, creator, report_date, created_by, - created_time, updated_by, updated_time, is_deleted - @@ -106,8 +75,8 @@ incident_type, - - company_name, + + corpinfo_id, incident_level, @@ -187,8 +156,8 @@ #{incidentType}, - - #{companyName}, + + #{corpinfoId}, #{incidentLevel}, @@ -262,7 +231,7 @@ incident_number = #{incidentNumber}, incident_name = #{incidentName}, incident_type = #{incidentType}, - company_name = #{companyName}, + corpinfo_id = #{corpinfoId}, incident_level = #{incidentLevel}, incident_nature = #{incidentNature}, location = #{location}, @@ -297,4 +266,54 @@ #{item} + + \ No newline at end of file From cbebfd71500c8baadb4adbbf28ec6cfa8d8bf4d7 Mon Sep 17 00:00:00 2001 From: shanao Date: Mon, 2 Sep 2024 16:18:33 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zcloud/controller/accident/AccidentRecordsController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java index f2718233..6c787021 100644 --- a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java +++ b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java @@ -78,9 +78,9 @@ public class AccidentRecordsController extends BaseController { } @RequestMapping("/export/excel") - public void exportExcel(HttpServletRequest request ,HttpServletResponse response) { + public void exportExcel(HttpServletRequest request, HttpServletResponse response) { PageData pd = new PageData(request); - accidentRecordsService.exportExcel(pd,response); + accidentRecordsService.exportExcel(pd, response); } @RequestMapping("/import/excel") From eba66601982c967994598dc38282673eecc4cfa6 Mon Sep 17 00:00:00 2001 From: shanao Date: Mon, 2 Sep 2024 18:07:40 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=20=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accident/AccidentRecordsController.java | 20 +++ .../accident/AccidentRecordsService.java | 54 +++++++ .../impl/AccidentRecordsServiceImpl.java | 31 +++- .../service/AccidentRecordsServiceTest.java | 136 ++++++++++++++++++ 4 files changed, 237 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/zcloud/service/accident/service/AccidentRecordsServiceTest.java diff --git a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java index 6c787021..29a8d962 100644 --- a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java +++ b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java @@ -2,6 +2,7 @@ package com.zcloud.controller.accident; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.StrUtil; import com.zcloud.controller.base.BaseController; import com.zcloud.entity.Page; import com.zcloud.entity.PageData; @@ -90,4 +91,23 @@ public class AccidentRecordsController extends BaseController { } accidentRecordsService.importExcel(file); } + + @RequestMapping("/import/photos") + public Map importPhotos(@RequestParam("file") MultipartFile file) { + if (file == null || file.isEmpty()) { + throw new RuntimeException("文件不能为空"); + } + Map result = new HashMap<>(); + result.put("result", "success"); // 路径 + result.put("path", accidentRecordsService.importPhotos(file)); + return result; + } + + @RequestMapping("/view/photos/{path}") + public void viewPhotos(@PathVariable("path") String path, HttpServletResponse response) { + if (StrUtil.isEmpty(path)) { + throw new RuntimeException("路径不能为空"); + } + accidentRecordsService.viewPhotos(path, response); + } } diff --git a/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java b/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java index b718fe9e..b70186e3 100644 --- a/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java +++ b/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java @@ -10,17 +10,71 @@ import java.util.List; public interface AccidentRecordsService { + /** + * 分页查询 + * + * @param page 条件 + * @return 查询结果 + */ List queryPage(Page page); + /** + * 根据主键查询 + * + * @param id 主键 + * @return 查询结果 + */ PageData getById(Long id); + /** + * 新增 + * + * @param accidentRecords 要保存的实体 + */ void save(AccidentRecords accidentRecords); + /** + * 修改 + * + * @param bean 要修改的实体 + */ void update(AccidentRecords bean); + /** + * 删除 + * + * @param ids 主键数组 + */ void delete(Long[] ids); + /** + * 导出Excel + * + * @param pd 查询条件 + * @param response 响应 + */ void exportExcel(PageData pd, HttpServletResponse response); + /** + * 导入Excel + * + * @param file 文件 + */ void importExcel(MultipartFile file); + + /** + * 导入图片 + * + * @param file 文件 + * @return 导入结果 + */ + String importPhotos(MultipartFile file); + + /** + * 查看图片 + * + * @param path 路径 + * @param response 响应 + */ + void viewPhotos(String path, HttpServletResponse response); } 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 20593392..d405ec89 100644 --- a/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java +++ b/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java @@ -1,10 +1,9 @@ package com.zcloud.service.accident.impl; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.CharsetUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.ReflectUtil; -import cn.hutool.core.util.URLUtil; +import cn.hutool.core.util.*; +import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelWriter; @@ -19,6 +18,8 @@ import com.zcloud.service.system.DictionariesService; import com.zcloud.util.Jurisdiction; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -28,6 +29,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.Field; import java.util.Arrays; import java.util.Date; @@ -137,4 +139,25 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { } } } + + @Override + public String importPhotos(MultipartFile file) { + String fileName = StrUtil.format("{}.{}", IdUtil.getSnowflake(1, 1).nextId(), + FilenameUtils.getExtension(file.getOriginalFilename())); + try (InputStream inputStream = file.getInputStream()) { + FileUtils.copyInputStreamToFile(inputStream, FileUtil.touch("./image/" + fileName)); + return "./image/" + fileName; + } catch (IOException e) { + log.error("导入图片失败", e); + throw new RuntimeException("导入图片失败"); + } + } + + @Override + public void viewPhotos(String path, HttpServletResponse response) { + if (!FileUtil.exist(path)) { + throw new RuntimeException("图片不存在"); + } + ServletUtil.write(response, FileUtil.touch(path)); + } } diff --git a/src/test/java/com/zcloud/service/accident/service/AccidentRecordsServiceTest.java b/src/test/java/com/zcloud/service/accident/service/AccidentRecordsServiceTest.java new file mode 100644 index 00000000..a9a52001 --- /dev/null +++ b/src/test/java/com/zcloud/service/accident/service/AccidentRecordsServiceTest.java @@ -0,0 +1,136 @@ +package com.zcloud.service.accident.service; + +import cn.hutool.core.util.IdUtil; +import com.zcloud.entity.Page; +import com.zcloud.entity.PageData; +import com.zcloud.entity.accident.AccidentRecords; +import com.zcloud.entity.accident.dto.AccidentRecordsExcel; +import com.zcloud.mapper.datasource.accident.AccidentRecordsMapper; +import com.zcloud.service.accident.impl.AccidentRecordsServiceImpl; +import com.zcloud.util.Jurisdiction; +import org.apache.commons.io.FilenameUtils; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.*; + +@SpringBootTest +@RunWith(SpringRunner.class) +public class AccidentRecordsServiceTest { + + @Autowired + @InjectMocks + private AccidentRecordsServiceImpl accidentRecordsService; + + @MockBean + private AccidentRecordsMapper accidentRecordsMapper; + +// @MockBean +// private DictionariesService dictionariesService; +// +// @MockBean +// private SqlSessionFactory sqlSessionFactory; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testQueryPage() { + Page page = new Page(); + List expectedList = new ArrayList<>(); + when(accidentRecordsMapper.listPage(page)).thenReturn(expectedList); + + List resultList = accidentRecordsService.queryPage(page); + + assertEquals(expectedList, resultList); + verify(accidentRecordsMapper, times(1)).listPage(page); + } + + @Test + public void testGetById() { + Long id = 1L; + PageData expectedPageData = new PageData(); + when(accidentRecordsMapper.getById(id)).thenReturn(expectedPageData); + + PageData resultPageData = accidentRecordsService.getById(id); + + assertEquals(expectedPageData, resultPageData); + verify(accidentRecordsMapper, times(1)).getById(id); + } + + @Test + public void testSave() { + AccidentRecords accidentRecords = new AccidentRecords(); + accidentRecords.setId(IdUtil.getSnowflake(1, 1).nextId()); + accidentRecords.setCreatedBy("测试"); + accidentRecords.setCreatedTime(new Date()); + accidentRecords.setIsDeleted(0); + + accidentRecordsService.save(accidentRecords); + } + + @Test + public void testUpdate() { + AccidentRecords accidentRecords = new AccidentRecords(); + accidentRecords.setUpdatedBy(Jurisdiction.getUsername()); + accidentRecords.setUpdatedTime(new Date()); + + accidentRecordsService.update(accidentRecords); + + verify(accidentRecordsMapper, times(1)).updateById(accidentRecords); + } + + @Test + public void testDelete() { + Long[] ids = {1L, 2L}; + + accidentRecordsService.delete(ids); + + verify(accidentRecordsMapper, times(1)).delete(ids); + } + + @Test + public void testExportExcel() throws Exception { + PageData pd = new PageData(); + List expectedList = new ArrayList<>(); + when(accidentRecordsMapper.listExcel(pd)).thenReturn(expectedList); + + HttpServletResponse response = mock(HttpServletResponse.class); + accidentRecordsService.exportExcel(pd, response); + + verify(response, times(1)).setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + verify(response, times(1)).setCharacterEncoding("utf-8"); + verify(response, times(1)).setHeader("Content-Disposition", "attachment;filename*=utf-8''事故调查表.xlsx"); + } + +// @Test +// public void testImportExcel() throws Exception { +// InputStream inputStream = new ByteArrayInputStream(ExcelUtil.write(new ArrayList<>(), true).getBytes()); +// MultipartFile file = mock(MultipartFile.class); +// when(file.getInputStream()).thenReturn(inputStream); +// +// accidentRecordsService.importExcel(file); +// +// verify(sqlSessionFactory, times(1)).openSession(ExecutorType.BATCH, false); +// } + + public static void main(String[] args) { + String extension = FilenameUtils.getExtension("akjsfhahjf.apk"); + System.out.println(extension); + } +} From 7f1a65f3f78bcb1765e2628ad7efa7cdb74a82ac Mon Sep 17 00:00:00 2001 From: shanao Date: Tue, 3 Sep 2024 17:08:02 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accident/AccidentRecordsController.java | 57 ++++++++++++++++++- .../accident/AccidentRecordsMapper.java | 39 ++++++++++++- .../accident/AccidentRecordsMapper.xml | 4 +- 3 files changed, 94 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java index 29a8d962..d1a6e97c 100644 --- a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java +++ b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java @@ -29,6 +29,13 @@ public class AccidentRecordsController extends BaseController { private final AccidentRecordsService accidentRecordsService; + /** + * 分页查询 + * + * @param page 分页参数 + * @param request 请求参数 + * @return 返回结果 + */ @RequestMapping(value = "/page") public Map queryPage(Page page, HttpServletRequest request) { page.setPd(new PageData(request)); @@ -39,6 +46,12 @@ public class AccidentRecordsController extends BaseController { return result; } + /** + * 根据id查询 + * + * @param id id + * @return 返回结果 + */ @RequestMapping("/{id}") public Map getById(@PathVariable("id") Long id) { Map result = new HashMap<>(); @@ -47,6 +60,12 @@ public class AccidentRecordsController extends BaseController { return result; } + /** + * 新增 + * + * @param request 请求参数 + * @return 返回结果 + */ @RequestMapping("/save") public Map save(HttpServletRequest request) { AccidentRecords accidentRecords = BeanUtil.mapToBean(new PageData(request), AccidentRecords.class, true); @@ -57,6 +76,12 @@ public class AccidentRecordsController extends BaseController { return result; } + /** + * 修改 + * + * @param request 请求参数 + * @return 返回结果 + */ @RequestMapping("/update") public Map update(HttpServletRequest request) { AccidentRecords accidentRecords = BeanUtil.mapToBean(new PageData(request), AccidentRecords.class, true); @@ -68,6 +93,12 @@ public class AccidentRecordsController extends BaseController { return result; } + /** + * 删除 + * + * @param values id集合 + * @return 是否成功 + */ @RequestMapping("/delete/{ids}") public Map delete(@PathVariable("ids") String values) { String[] split = Optional.of(values).orElseThrow(() -> new RuntimeException("ids不能为空")).split(","); @@ -78,12 +109,22 @@ public class AccidentRecordsController extends BaseController { return result; } + /** + * 导出excel + * + * @param request 请求 + * @param response 响应 + */ @RequestMapping("/export/excel") public void exportExcel(HttpServletRequest request, HttpServletResponse response) { - PageData pd = new PageData(request); - accidentRecordsService.exportExcel(pd, response); + accidentRecordsService.exportExcel(new PageData(request), response); } + /** + * 导入excel + * + * @param file 文件 + */ @RequestMapping("/import/excel") public void importExcel(@RequestParam("file") MultipartFile file) { if (file == null || file.isEmpty()) { @@ -92,6 +133,12 @@ public class AccidentRecordsController extends BaseController { accidentRecordsService.importExcel(file); } + /** + * 导入图片 + * + * @param file 文件 + * @return 是否成功 + */ @RequestMapping("/import/photos") public Map importPhotos(@RequestParam("file") MultipartFile file) { if (file == null || file.isEmpty()) { @@ -103,6 +150,12 @@ public class AccidentRecordsController extends BaseController { return result; } + /** + * 查看图片 + * + * @param path 路径 + * @param response 响应 + */ @RequestMapping("/view/photos/{path}") public void viewPhotos(@PathVariable("path") String path, HttpServletResponse response) { if (StrUtil.isEmpty(path)) { diff --git a/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java b/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java index db023cbb..bb753499 100644 --- a/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java +++ b/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java @@ -8,19 +8,54 @@ import org.apache.ibatis.annotations.Param; import java.util.List; + public interface AccidentRecordsMapper { + /** + * 分页查询 + * + * @param page 条件 + * @return 结果 + */ List listPage(Page page); + /** + * 根据id查询 + * + * @param id id + * @return 结果 + */ PageData getById(Long id); + /** + * 新增 + * + * @param accidentRecords 要保存的实体 + * @return 受影响的行数 + */ int save(AccidentRecords accidentRecords); + /** + * 修改 + * + * @param accidentRecords 要修改的实体 + * @return 受影响的行数 + */ int updateById(AccidentRecords accidentRecords); + /** + * 删除 + * + * @param ids 主键数组 + * @return 受影响的行数 + */ int delete(@Param("ids") Long[] ids); + /** + * 导出excel + * + * @param pd 条件 + * @return 结果 + */ List listExcel(PageData pd); - - void saveExcel(AccidentRecordsExcel records, long id, String username); } \ No newline at end of file diff --git a/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml b/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml index 4f5a3154..0a36edb8 100644 --- a/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml +++ b/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml @@ -2,7 +2,7 @@ - select id, CORP_NAME as companyName, location, incident_date, incident_name from accident_records as ar left join bus_corp_info as bci on ar.corpinfo_id = bci.CORPINFO_ID @@ -288,7 +288,7 @@ suggestions, measures, ar.creator, - date_format(report_date, '%Y年%m月%d日') as 'reportDate' + date_format(report_date, '%Y年%m月%d日%H时%I分%s秒') as 'reportDate' from accident_records as ar left join bus_corp_info as bci on ar.corpinfo_id = bci.CORPINFO_ID From 3e594ab70e832836f3073ecf39860c6ffd81e4c2 Mon Sep 17 00:00:00 2001 From: shanao Date: Tue, 3 Sep 2024 17:51:31 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/AccidentRecordsServiceImpl.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 d405ec89..40639f60 100644 --- a/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java +++ b/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java @@ -1,5 +1,6 @@ package com.zcloud.service.accident.impl; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.*; @@ -123,10 +124,24 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { // 标记别名 HEADER_ALIAS_CACHE.forEach((k, v) -> reader.addHeaderAlias(v, k)); List recordsExcels = reader.readAll(AccidentRecordsExcel.class); + if (CollUtil.isEmpty(recordsExcels)) { + throw new RuntimeException("没有数据"); + } sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); AccidentRecordsMapper mapper = sqlSession.getMapper(AccidentRecordsMapper.class); - recordsExcels.forEach(accidentRecord -> mapper.save(new AccidentRecords(accidentRecord, dictionariesService))); + for (int i = 0; i < recordsExcels.size(); i++) { + mapper.save(new AccidentRecords(recordsExcels.get(i), dictionariesService)); + if ((i + 1) % 300 == 0 || i == recordsExcels.size() - 1) { + sqlSession.flushStatements(); + } + } sqlSession.commit(); + } catch (RuntimeException e) { + if (sqlSession != null) { + sqlSession.rollback(); + } + log.error("导入excel失败", e); + throw e; } catch (Exception e) { if (sqlSession != null) { sqlSession.rollback(); From a5b76b25df212d143b6d911fca23e3f2c287ab85 Mon Sep 17 00:00:00 2001 From: shanao Date: Fri, 6 Sep 2024 19:38:32 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accident/AccidentRecordsController.java | 18 +++++++++--------- .../entity/accident/AccidentRecords.java | 10 +++++----- .../accident/AccidentRecordsMapper.java | 2 +- .../accident/AccidentRecordsService.java | 2 +- .../impl/AccidentRecordsServiceImpl.java | 16 ++++++++++------ .../accident/AccidentRecordsMapper.xml | 10 +++++----- .../service/AccidentRecordsServiceTest.java | 4 ++-- 7 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java index d1a6e97c..39644d59 100644 --- a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java +++ b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java @@ -2,6 +2,7 @@ package com.zcloud.controller.accident; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.zcloud.controller.base.BaseController; import com.zcloud.entity.Page; @@ -17,14 +18,12 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; +@RestController @RequiredArgsConstructor -@RestController("/accident") +@RequestMapping("/accident") public class AccidentRecordsController extends BaseController { private final AccidentRecordsService accidentRecordsService; @@ -69,7 +68,6 @@ public class AccidentRecordsController extends BaseController { @RequestMapping("/save") public Map save(HttpServletRequest request) { AccidentRecords accidentRecords = BeanUtil.mapToBean(new PageData(request), AccidentRecords.class, true); - accidentRecords.setCorpinfoId(Optional.of(accidentRecords.getCorpinfoId()).orElseThrow(() -> new RuntimeException("所属公司不能为空"))); accidentRecordsService.save(accidentRecords); Map result = new HashMap<>(); result.put("result", "success"); @@ -86,7 +84,6 @@ public class AccidentRecordsController extends BaseController { public Map update(HttpServletRequest request) { AccidentRecords accidentRecords = BeanUtil.mapToBean(new PageData(request), AccidentRecords.class, true); accidentRecords.setId(Optional.of(accidentRecords.getId()).orElseThrow(() -> new RuntimeException("id不能为空"))); - accidentRecords.setCorpinfoId(Optional.of(accidentRecords.getCorpinfoId()).orElseThrow(() -> new RuntimeException("所属公司不能为空"))); accidentRecordsService.update(accidentRecords); Map result = new HashMap<>(); result.put("result", "success"); @@ -101,8 +98,11 @@ public class AccidentRecordsController extends BaseController { */ @RequestMapping("/delete/{ids}") public Map delete(@PathVariable("ids") String values) { - String[] split = Optional.of(values).orElseThrow(() -> new RuntimeException("ids不能为空")).split(","); - Long[] ids = Arrays.stream(split).map(Convert::toLong).collect(Collectors.toList()).toArray(new Long[]{}); + if (StrUtil.isEmpty(values)) { + throw new RuntimeException("id不能为空"); + } + List ids = Arrays.stream(values.split(",")).map(Convert::toLong).filter(ObjectUtil::isNotEmpty) + .collect(Collectors.toList()); accidentRecordsService.delete(ids); Map result = new HashMap<>(); result.put("result", "success"); diff --git a/src/main/java/com/zcloud/entity/accident/AccidentRecords.java b/src/main/java/com/zcloud/entity/accident/AccidentRecords.java index 58987287..76e069a8 100644 --- a/src/main/java/com/zcloud/entity/accident/AccidentRecords.java +++ b/src/main/java/com/zcloud/entity/accident/AccidentRecords.java @@ -47,7 +47,7 @@ public class AccidentRecords implements Serializable { /** * 事故类型 */ - private Integer incidentType; + private String incidentType; /** * 所属公司 @@ -59,7 +59,7 @@ public class AccidentRecords implements Serializable { * 事故级别 */ @Size(max = 50, message = "事故级别最大长度要小于 50") - private Integer incidentLevel; + private String incidentLevel; /** * 事故性质 @@ -171,7 +171,7 @@ public class AccidentRecords implements Serializable { private static final long serialVersionUID = 1L; - public AccidentRecords(AccidentRecordsExcel reader, DictionariesService service) { + public AccidentRecords(AccidentRecordsExcel reader, DictionariesService service) throws RuntimeException { this.id = IdUtil.getSnowflake(1, 1).nextId(); this.corpinfoId = reader.getCompanyName(); this.incidentNumber = reader.getIncidentNumber(); @@ -196,7 +196,7 @@ public class AccidentRecords implements Serializable { this.createdTime = new Date(); } - private Integer findByName(String name, DictionariesService service) { + private String findByName(String name, DictionariesService service) { if (StrUtil.isEmpty(name)) { return null; } @@ -204,7 +204,7 @@ public class AccidentRecords implements Serializable { pageData.put("NAME", name); try { PageData data = service.findByName(pageData); - return Optional.ofNullable(data).map(pd -> (Integer) pd.get("BIANMA")).orElseThrow(() -> new RuntimeException("未找到字典数据:" + name)); + return Optional.ofNullable(data).map(pd -> pd.getString("BIANMA")).orElseThrow(() -> new RuntimeException("未找到字典数据:" + name)); } catch (RuntimeException e) { log.error("转换字典失败", e); throw e; diff --git a/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java b/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java index bb753499..44e73793 100644 --- a/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java +++ b/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java @@ -49,7 +49,7 @@ public interface AccidentRecordsMapper { * @param ids 主键数组 * @return 受影响的行数 */ - int delete(@Param("ids") Long[] ids); + int delete(@Param("ids") List ids); /** * 导出excel diff --git a/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java b/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java index b70186e3..a87167a9 100644 --- a/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java +++ b/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java @@ -45,7 +45,7 @@ public interface AccidentRecordsService { * * @param ids 主键数组 */ - void delete(Long[] ids); + void delete(List ids); /** * 导出Excel 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 40639f60..a3bfe6b0 100644 --- a/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java +++ b/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java @@ -2,6 +2,7 @@ package com.zcloud.service.accident.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.IoUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.*; import cn.hutool.extra.servlet.ServletUtil; @@ -56,7 +57,8 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { @Override public List queryPage(Page page) { - page.getPd().put("corpInfoId", Jurisdiction.getCORPINFO_ID()); + PageData data = page.getPd(); + data.put("corpInfoId", Jurisdiction.getCORPINFO_ID()); return accidentRecordsMapper.listPage(page); } @@ -72,6 +74,8 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { accidentRecords.setCreatedBy(Jurisdiction.getUsername()); accidentRecords.setCreatedTime(new Date()); accidentRecords.setIsDeleted(0); + String corpinfoId = StrUtil.isEmpty(accidentRecords.getCorpinfoId()) ? Jurisdiction.getCORPINFO_ID() : accidentRecords.getCorpinfoId(); + accidentRecords.setCorpinfoId(corpinfoId); Assert.isTrue(accidentRecordsMapper.save(accidentRecords) == 1, "新增事故记录失败"); } @@ -80,13 +84,15 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { public void update(AccidentRecords accidentRecords) { accidentRecords.setUpdatedBy(Jurisdiction.getUsername()); accidentRecords.setUpdatedTime(new Date()); + String corpinfoId = StrUtil.isEmpty(accidentRecords.getCorpinfoId()) ? Jurisdiction.getCORPINFO_ID() : accidentRecords.getCorpinfoId(); + accidentRecords.setCorpinfoId(corpinfoId); Assert.isTrue(accidentRecordsMapper.updateById(accidentRecords) == 1, "更新事故记录失败"); } @Override @Transactional(rollbackFor = Exception.class) - public void delete(Long[] ids) { - Assert.isTrue(accidentRecordsMapper.delete(ids) == ids.length, "删除事故记录失败"); + public void delete(List ids) { + Assert.isTrue(accidentRecordsMapper.delete(ids) == ids.size(), "删除事故记录失败"); } @Override @@ -149,9 +155,7 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { log.error("导入excel失败", e); throw new RuntimeException("导入excel失败"); } finally { - if (sqlSession != null) { - sqlSession.close(); - } + IoUtil.close(sqlSession); } } diff --git a/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml b/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml index 0a36edb8..ac15f802 100644 --- a/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml +++ b/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml @@ -3,7 +3,7 @@ select id, - incident_number, - incident_name, - incident_type, - incident_level, + incident_number as incidentNumber, + incident_name as incidentName, + incident_type as incidentName, + incident_level as incidentLevel, CORP_NAME as companyName, - incident_nature, - `location`, - incident_date, - direct_loss, - injured, - fatalities, - seriously_injured, - cause, - summary, - photos, - analysis, - suggestions, - measures, - ar.creator, - report_date + incident_nature as incidentNature, + `location` as location, + incident_date as incidentDate, + direct_loss as directLoss, + injured as injured, + fatalities as fatalities, + seriously_injured as seriouslyInjured, + cause as cause, + summary as summary, + photos as photos, + analysis as analysis, + suggestions as suggestions, + measures as measures, + ar.creator as creator, + report_date as reportDate from accident_records as ar left join bus_corp_info as bci on ar.corpinfo_id = bci.CORPINFO_ID where ar.id = #{id} From c6ea9844caeb8eb37d5ecbc1af3e11af76a67301 Mon Sep 17 00:00:00 2001 From: shanao Date: Mon, 9 Sep 2024 18:05:42 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=B9=E5=BC=8F=E4=B8=BASftp=20=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=B2=A1=E6=9C=89=E8=B0=83=E9=80=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accident/AccidentRecordsController.java | 23 ++------- .../entity/accident/AccidentRecords.java | 39 ++++++++------- .../accident/AccidentRecordsService.java | 8 --- .../impl/AccidentRecordsServiceImpl.java | 50 +++++++++++-------- .../accident/AccidentRecordsMapper.xml | 24 ++++----- 5 files changed, 65 insertions(+), 79 deletions(-) diff --git a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java index 78fa1773..e280acf0 100644 --- a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java +++ b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java @@ -140,7 +140,7 @@ public class AccidentRecordsController extends BaseController { * @return 是否成功 */ @RequestMapping("/import/photos") - public Map importPhotos(@RequestParam MultipartFile file) { + public Map importPhotos(@RequestParam("file") MultipartFile file) { if (file == null || file.isEmpty()) { throw new RuntimeException("文件不能为空"); } @@ -153,11 +153,12 @@ public class AccidentRecordsController extends BaseController { /** * 删除图片 * - * @param path 文件路径 + * @param request 请求参数 * @return 是否成功 */ - @RequestMapping("/delete/photos/{path}") - public Map deletePhotos(@PathVariable("path") String path) { + @RequestMapping("/delete/photos") + public Map deletePhotos(HttpServletRequest request) { + String path = new PageData(request).getString("path"); if (StrUtil.isEmpty(path)) { throw new RuntimeException("路径不能为空"); } @@ -166,18 +167,4 @@ public class AccidentRecordsController extends BaseController { result.put("result", "success"); // 路径 return result; } - - /** - * 查看图片 - * - * @param path 路径 - * @param response 响应 - */ - @RequestMapping("/view/photos/{path}") - public void viewPhotos(@PathVariable("path") String path, HttpServletResponse response) { - if (StrUtil.isEmpty(path)) { - throw new RuntimeException("路径不能为空"); - } - accidentRecordsService.viewPhotos(path, response); - } } diff --git a/src/main/java/com/zcloud/entity/accident/AccidentRecords.java b/src/main/java/com/zcloud/entity/accident/AccidentRecords.java index 76e069a8..caaaf76f 100644 --- a/src/main/java/com/zcloud/entity/accident/AccidentRecords.java +++ b/src/main/java/com/zcloud/entity/accident/AccidentRecords.java @@ -2,8 +2,8 @@ package com.zcloud.entity.accident; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; -import com.zcloud.entity.PageData; 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; @@ -15,8 +15,8 @@ import javax.validation.constraints.Size; import java.io.Serializable; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Optional; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; /** * 事故记录表 @@ -171,13 +171,13 @@ public class AccidentRecords implements Serializable { private static final long serialVersionUID = 1L; - public AccidentRecords(AccidentRecordsExcel reader, DictionariesService service) throws RuntimeException { + 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); - this.incidentLevel = findByName(reader.getIncidentLevel(), service); + 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()); @@ -196,22 +196,23 @@ public class AccidentRecords implements Serializable { this.createdTime = new Date(); } - private String findByName(String name, DictionariesService service) { - if (StrUtil.isEmpty(name)) { + // 缓存字典 避免频繁请求数据库 + public static final Map> dictMap = new ConcurrentHashMap<>(); + + private String findByName(String bianma, DictionariesService service, String parentId) throws Exception { + if (StrUtil.isEmpty(bianma)) { return null; } - PageData pageData = new PageData(); - pageData.put("NAME", name); - try { - PageData data = service.findByName(pageData); - return Optional.ofNullable(data).map(pd -> pd.getString("BIANMA")).orElseThrow(() -> new RuntimeException("未找到字典数据:" + name)); - } catch (RuntimeException e) { - log.error("转换字典失败", e); - throw e; - } catch (Exception e) { - log.error("获取字典失败", e); - throw new RuntimeException("获取字典失败"); + + 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) { diff --git a/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java b/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java index 0ccf466f..3fd14b99 100644 --- a/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java +++ b/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java @@ -70,14 +70,6 @@ public interface AccidentRecordsService { */ String importPhotos(MultipartFile file); - /** - * 查看图片 - * - * @param path 路径 - * @param response 响应 - */ - void viewPhotos(String path, HttpServletResponse response); - /** * 删除图片 * 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 11aedceb..0688b484 100644 --- a/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java +++ b/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java @@ -1,11 +1,9 @@ package com.zcloud.service.accident.impl; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.*; -import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelWriter; @@ -16,11 +14,11 @@ import com.zcloud.entity.accident.ExcelValue; import com.zcloud.entity.accident.dto.AccidentRecordsExcel; import com.zcloud.mapper.datasource.accident.AccidentRecordsMapper; import com.zcloud.service.accident.AccidentRecordsService; +import com.zcloud.service.bus.ImgFilesService; import com.zcloud.service.system.DictionariesService; -import com.zcloud.util.Jurisdiction; +import com.zcloud.util.*; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; @@ -31,8 +29,9 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.io.InputStream; import java.lang.reflect.Field; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.Arrays; import java.util.Date; import java.util.List; @@ -48,6 +47,7 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { private final SqlSessionFactory sqlSessionFactory; private final DictionariesService dictionariesService; private static final Map HEADER_ALIAS_CACHE; + private final ImgFilesService imgFilesService; static { HEADER_ALIAS_CACHE = Arrays.stream(ReflectUtil.getFields(AccidentRecordsExcel.class)) @@ -72,7 +72,8 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { public void save(AccidentRecords accidentRecords) { accidentRecords.setId(IdUtil.getSnowflake(1, 1).nextId()); accidentRecords.setCreatedBy(Jurisdiction.getUsername()); - accidentRecords.setCreatedTime(new Date()); + Date date = Date.from(LocalDateTime.now().toInstant(ZoneOffset.of("+08:00"))); + accidentRecords.setCreatedTime(date); accidentRecords.setIsDeleted(0); String corpinfoId = StrUtil.isEmpty(accidentRecords.getCorpinfoId()) ? Jurisdiction.getCORPINFO_ID() : accidentRecords.getCorpinfoId(); accidentRecords.setCorpinfoId(corpinfoId); @@ -83,7 +84,8 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { @Transactional(rollbackFor = Exception.class) public void update(AccidentRecords accidentRecords) { accidentRecords.setUpdatedBy(Jurisdiction.getUsername()); - accidentRecords.setUpdatedTime(new Date()); + Date date = Date.from(LocalDateTime.now().toInstant(ZoneOffset.of("+08:00"))); + accidentRecords.setUpdatedTime(date); String corpinfoId = StrUtil.isEmpty(accidentRecords.getCorpinfoId()) ? Jurisdiction.getCORPINFO_ID() : accidentRecords.getCorpinfoId(); accidentRecords.setCorpinfoId(corpinfoId); Assert.isTrue(accidentRecordsMapper.updateById(accidentRecords) == 1, "更新事故记录失败"); @@ -141,6 +143,8 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { sqlSession.flushStatements(); } } + // 避免刷新数据字典不生效 每次导出重新查询字典 + AccidentRecords.dictMap.clear(); sqlSession.commit(); } catch (RuntimeException e) { if (sqlSession != null) { @@ -161,27 +165,29 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { @Override public String importPhotos(MultipartFile file) { - String fileName = StrUtil.format("{}.{}", IdUtil.getSnowflake(1, 1).nextId(), - FilenameUtils.getExtension(file.getOriginalFilename())); - try (InputStream inputStream = file.getInputStream()) { - FileUtils.copyInputStreamToFile(inputStream, FileUtil.touch("./image/" + fileName)); - return "./image/" + fileName; - } catch (IOException e) { + String fileName = UuidUtil.get32UUID() + "." + FilenameUtils.getExtension(file.getOriginalFilename()); + PageData pd = new PageData(); + pd.put("IMGFILES_ID", UuidUtil.get32UUID()); + pd.put("FOREIGN_KEY", UuidUtil.get32UUID()); + pd.put("TYPE", 117); + try { + String path = Const.FILEPATHFILE + UuidUtil.get32UUID() + "/" + DateUtil.getDays(); + Smb.sshSftp(file, fileName, path); + pd.put("FILEPATH", path + "/" + fileName); + imgFilesService.save(pd); + return pd.getString("FILEPATH"); + } catch (Exception e) { log.error("导入图片失败", e); throw new RuntimeException("导入图片失败"); } } - @Override - public void viewPhotos(String path, HttpServletResponse response) { - if (!FileUtil.exist(path)) { - throw new RuntimeException("图片不存在"); - } - ServletUtil.write(response, FileUtil.touch(path)); - } - @Override public void deletePhotos(String path) { - FileUtil.del("./image/" + path); + try { + Smb.deleteFile(path); + } catch (Exception e) { + throw new RuntimeException("图片删除失败"); + } } } diff --git a/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml b/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml index 3c926481..ba1700c9 100644 --- a/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml +++ b/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml @@ -3,7 +3,7 @@ @@ -64,7 +64,7 @@ insert into accident_records - id, + accident_id, incident_number, @@ -145,7 +145,7 @@ values - id, + #{id}, #{incidentNumber}, @@ -254,14 +254,14 @@ updated_time = #{updatedTime}, is_deleted = #{isDeleted} - WHERE id = #{id} and is_deleted = 0 + WHERE accident_id = #{id} and is_deleted = 0 update accident_records set is_deleted = 1 where - id IN + accident_id IN #{item} @@ -270,10 +270,10 @@ - select incident_number, - incident_name, - (select NAME from sys_dictionaries - where DICTIONARIES_ID = '8d4140a900184b60836ad1a6490fd510' and BIANMA = incident_type) as 'incidentType', - (select NAME from sys_dictionaries - where DICTIONARIES_ID = 'b61a1edc59c0430c8741c5f51aa26c3c' and BIANMA = incident_level) as 'incidentLevel', - CORP_NAME as 'companyName', - incident_nature , - `location`, + - select cast(accident_id AS CHAR) as id, CORP_NAME as companyName, location, date_format(incident_date,'%Y-%m-%d %H:%I:%s') as 'incidentDate', incident_name as 'incidentName' - from accident_records as ar - left join bus_corp_info as bci on ar.corpinfo_id = bci.CORPINFO_ID + select ACCIDENT_ID as id, CORP_NAME as companyName, LOCATION as 'location', INCIDENT_DATE as 'incidentDate', INCIDENT_NAME as 'incidentName' + from bus_accident as ar + left join bus_corp_info as bci on ar.CORPINFO_ID = bci.CORPINFO_ID - and ar.corpinfo_id = #{pd.corpInfoId} + and ar.CORPINFO_ID = #{pd.corpInfoId} - and incident_name like concat('%', #{pd.incidentName}, '%') + and INCIDENT_NAME like concat('%', #{pd.incidentName}, '%') - and incident_date between #{pd.startTime} and #{pd.endTime} + and INCIDENT_DATE between #{pd.startTime} and #{pd.endTime} - and location like concat('%', #{pd.location}, '%') + and LOCATION like concat('%', #{pd.location}, '%') - and incident_level like concat('%', #{pd.incidentLevel}, '%') + and INCIDENT_LEVEL = #{pd.incidentLevel} - - and incident_type = #{pd.incidentType} + + and INCIDENT_TYPE = #{pd.incidentType} - and is_deleted = 0 + and IS_DELETED = 0 - order by incident_date desc , companyName + order by INCIDENT_DATE desc , companyName - insert into accident_records + insert into bus_accident - accident_id, + ACCIDENT_ID, - incident_number, + INCIDENT_NUMBER, - incident_name, + INCIDENT_NAME, - incident_type, + INCIDENT_TYPE, - corpinfo_id, + CORPINFO_ID, - incident_level, + INCIDENT_LEVEL, - incident_nature, + INCIDENT_NATURE, - location, + LOCATION, - incident_date, + INCIDENT_DATE, - direct_loss, + DIRECT_LOSS, - injured, + INJURED, - fatalities, + FATALITIES, - seriously_injured, + SERIOUSLY_INJURED, - cause, + CAUSE, - summary, + SUMMARY, - photos, + PHOTOS, - analysis, + ANALYSIS, - suggestions, + SUGGESTIONS, - measures, + MEASURES, - creator, + CREATOR, - report_date, + REPORT_DATE, - created_by, + CREATED_BY, - created_time, + CREATED_TIME, - updated_by, + UPDATED_BY, - updated_time, + UPDATED_TIME, - is_deleted + IS_DELETED values @@ -226,7 +226,7 @@ - UPDATE accident_records + UPDATE bus_accident incident_number = #{incidentNumber}, incident_name = #{incidentName}, @@ -258,7 +258,7 @@ - update accident_records + update bus_accident set is_deleted = 1 where accident_id IN @@ -268,32 +268,31 @@