diff --git a/pom.xml b/pom.xml
index 235ecb1e..cbc42683 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
new file mode 100644
index 00000000..f46e4dab
--- /dev/null
+++ b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java
@@ -0,0 +1,180 @@
+package com.zcloud.controller.accident;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+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 com.zcloud.util.ObjectExcelView;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Controller;
+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.ResponseBody;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.*;
+import java.util.stream.Collectors;
+
+@Controller
+@RequiredArgsConstructor
+@RequestMapping("/accident")
+public class AccidentRecordsController extends BaseController {
+
+ private final AccidentRecordsService accidentRecordsService;
+
+ /**
+ * 分页查询
+ *
+ * @param page 分页参数
+ * @param request 请求参数
+ * @return 返回结果
+ */
+ @ResponseBody
+ @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;
+ }
+
+ /**
+ * 根据id查询
+ *
+ * @param id id
+ * @return 返回结果
+ */
+ @ResponseBody
+ @RequestMapping("/{id}")
+ public Map getById(@PathVariable("id") String id) {
+ Map result = new HashMap<>();
+ result.put("result", "success");
+ result.put("info", accidentRecordsService.getById(Optional.of(id).orElseThrow(() -> new RuntimeException("id不能为空"))));
+ return result;
+ }
+
+ /**
+ * 新增
+ *
+ * @param request 请求参数
+ * @return 返回结果
+ */
+ @ResponseBody
+ @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;
+ }
+
+ /**
+ * 修改
+ *
+ * @param request 请求参数
+ * @return 返回结果
+ */
+ @ResponseBody
+ @RequestMapping("/update")
+ public Map update(HttpServletRequest request) {
+ PageData pageData = new PageData(request);
+ 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;
+ }
+
+ /**
+ * 删除
+ *
+ * @param values id集合
+ * @return 是否成功
+ */
+ @ResponseBody
+ @RequestMapping("/delete/{ids}")
+ public Map delete(@PathVariable("ids") String values) {
+ if (StrUtil.isEmpty(values)) {
+ throw new RuntimeException("id不能为空");
+ }
+ List ids = Arrays.stream(values.split(",")).filter(ObjectUtil::isNotEmpty)
+ .collect(Collectors.toList());
+ accidentRecordsService.delete(ids);
+ Map result = new HashMap<>();
+ result.put("result", "success");
+ return result;
+ }
+
+ /**
+ * 导出excel
+ *
+ * @param request 请求
+ * @return 返回结果
+ */
+ @RequestMapping("/export/excel")
+ public ModelAndView exportExcel(HttpServletRequest request) {
+ Map dataMap = accidentRecordsService.exportExcel(new PageData(request));
+ return new ModelAndView(new ObjectExcelView(), dataMap);
+ }
+
+// /**
+// * 导入excel
+// *
+// * @param file 文件
+// */
+// @RequestMapping("/import/excel")
+// public void importExcel(@RequestParam("file") MultipartFile file) {
+// if (file == null || file.isEmpty()) {
+// throw new RuntimeException("文件不能为空");
+// }
+// accidentRecordsService.importExcel(file);
+// }
+
+ /**
+ * 导入图片
+ *
+ * @param file 文件
+ * @return 是否成功
+ */
+ @ResponseBody
+ @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;
+ }
+
+ /**
+ * 删除图片
+ *
+ * @param request 请求参数
+ * @return 是否成功
+ */
+ @ResponseBody
+ @RequestMapping("/delete/photos")
+ public Map deletePhotos(HttpServletRequest request) {
+ String path = new PageData(request).getString("path");
+ if (StrUtil.isEmpty(path)) {
+ throw new RuntimeException("路径不能为空");
+ }
+ accidentRecordsService.deletePhotos(path);
+ 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..f44e8ca1
--- /dev/null
+++ b/src/main/java/com/zcloud/entity/accident/AccidentRecords.java
@@ -0,0 +1,221 @@
+package com.zcloud.entity.accident;
+
+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.util.Date;
+
+/**
+ * 事故记录表
+ */
+@Slf4j
+@Data
+@NoArgsConstructor
+public class AccidentRecords implements Serializable {
+
+ /**
+ * 主键ID
+ */
+ @NotNull(message = "主键ID不能为null")
+ private String id;
+
+ /**
+ * 事故案号
+ */
+ @Size(max = 50, message = "事故案号最大长度要小于 50")
+ private String incidentNumber;
+
+ /**
+ * 事故名称
+ */
+ @Size(max = 100, message = "事故名称最大长度要小于 100")
+ private String incidentName;
+
+ /**
+ * 事故类型
+ */
+ private String incidentType;
+
+ /**
+ * 所属公司
+ */
+ @Size(max = 100, message = "所属公司最大长度要小于 100")
+ private String corpinfoId;
+
+ /**
+ * 事故级别
+ */
+ @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 Integer 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;
+
+// public AccidentRecords(AccidentRecordsExcel reader, DictionariesService service) throws Exception {
+// this.id = IdUtil.getSnowflake(1, 1).nextId();
+// this.corpinfoId = reader.getCompanyName();
+// this.incidentNumber = reader.getIncidentNumber();
+// this.incidentName = reader.getIncidentName();
+// this.incidentType = findByName(reader.getIncidentType(), service, "8d4140a900184b60836ad1a6490fd510");
+// this.incidentLevel = findByName(reader.getIncidentLevel(), service, "b61a1edc59c0430c8741c5f51aa26c3c");
+// this.incidentNature = reader.getIncidentNature();
+// this.location = reader.getLocation();
+// this.incidentDate = dateFormat(reader.getIncidentDate());
+// this.directLoss = reader.getDirectLoss();
+// this.injured = reader.getInjured();
+// this.fatalities = reader.getFatalities();
+// this.seriouslyInjured = reader.getSeriouslyInjured();
+// this.cause = reader.getCause();
+// this.summary = reader.getSummary();
+// this.analysis = reader.getAnalysis();
+// this.suggestions = reader.getSuggestions();
+// this.measures = reader.getMeasures();
+// this.creator = reader.getCreator();
+// this.reportDate = dateFormat(reader.getReportDate());
+// this.createdBy = Jurisdiction.getUsername();
+// this.createdTime = new Date();
+// }
+//
+// // 缓存字典 避免频繁请求数据库
+// public static final Map> dictMap = new ConcurrentHashMap<>();
+//
+// private String findByName(String bianma, DictionariesService service, String parentId) throws Exception {
+// if (StrUtil.isEmpty(bianma)) {
+// return null;
+// }
+//
+// if (dictMap.containsKey(parentId)) {
+// Optional optional = dictMap.get(parentId).stream().filter(d -> d.getBIANMA().equals(bianma)).findAny();
+// return optional.map(Dictionaries::getDICTIONARIES_ID).orElse(null);
+// }
+// List dict = service.listSubDictByParentId(parentId);
+// dict = dict == null ? new ArrayList<>() : dict;
+// dictMap.put(parentId, dict);
+// return dict.stream().filter(d -> d != null && d.getBIANMA().equals(bianma))
+// .findAny().map(Dictionaries::getDICTIONARIES_ID).orElse(null);
+// }
+//
+// private Date dateFormat(String dateStr) {
+// if (StrUtil.isEmpty(dateStr)) {
+// return null;
+// }
+// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+// try {
+// return formatter.parse(dateStr);
+// } catch (ParseException e) {
+// log.error("日期转换失败", e);
+// throw new RuntimeException("日期转换失败,支持的格式:yyyy-MM-dd HH:mm:ss");
+// }
+// }
+}
\ No newline at end of file
diff --git a/src/main/java/com/zcloud/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/AccidentRecordsExcel.java b/src/main/java/com/zcloud/entity/accident/dto/AccidentRecordsExcel.java
new file mode 100644
index 00000000..3ce42a56
--- /dev/null
+++ b/src/main/java/com/zcloud/entity/accident/dto/AccidentRecordsExcel.java
@@ -0,0 +1,135 @@
+package com.zcloud.entity.accident.dto;
+
+import cn.hutool.core.date.DateUtil;
+import com.zcloud.entity.accident.ExcelValue;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@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;
+
+
+ public void setIncidentDate(Date incidentDate) {
+ this.incidentDate = DateUtil.format(incidentDate, "yyyy年MM月dd日HH时mm分ss秒");
+ }
+
+ public void setReportDate(Date reportDate) {
+ this.reportDate = DateUtil.format(reportDate, "yyyy年MM月dd日HH时mm分ss秒");
+ }
+}
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..aa9012fd
--- /dev/null
+++ b/src/main/java/com/zcloud/mapper/datasource/accident/AccidentRecordsMapper.java
@@ -0,0 +1,61 @@
+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;
+
+
+public interface AccidentRecordsMapper {
+
+ /**
+ * 分页查询
+ *
+ * @param page 条件
+ * @return 结果
+ */
+ List listPage(Page page);
+
+ /**
+ * 根据id查询
+ *
+ * @param id id
+ * @return 结果
+ */
+ PageData getById(String id);
+
+ /**
+ * 新增
+ *
+ * @param accidentRecords 要保存的实体
+ * @return 受影响的行数
+ */
+ int save(AccidentRecords accidentRecords);
+
+ /**
+ * 修改
+ *
+ * @param accidentRecords 要修改的实体
+ * @return 受影响的行数
+ */
+ int updateById(AccidentRecords accidentRecords);
+
+ /**
+ * 删除
+ *
+ * @param ids 主键数组
+ * @return 受影响的行数
+ */
+ int delete(@Param("ids") List ids);
+
+ /**
+ * 导出excel
+ *
+ * @param pd 条件
+ * @return 结果
+ */
+ List listExcel(@Param("pd") PageData pd);
+}
\ 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..8ed30d49
--- /dev/null
+++ b/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java
@@ -0,0 +1,79 @@
+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 java.util.List;
+import java.util.Map;
+
+public interface AccidentRecordsService {
+
+ /**
+ * 分页查询
+ *
+ * @param page 条件
+ * @return 查询结果
+ */
+ List queryPage(Page page);
+
+ /**
+ * 根据主键查询
+ *
+ * @param id 主键
+ * @return 查询结果
+ */
+ PageData getById(String id);
+
+ /**
+ * 新增
+ *
+ * @param accidentRecords 要保存的实体
+ */
+ void save(AccidentRecords accidentRecords);
+
+ /**
+ * 修改
+ *
+ * @param bean 要修改的实体
+ */
+ void update(AccidentRecords bean);
+
+ /**
+ * 删除
+ *
+ * @param ids 主键数组
+ */
+ void delete(List ids);
+
+ /**
+ * 导出Excel
+ *
+ * @param pd 查询条件
+ * @return 组装好的数据
+ */
+ Map exportExcel(PageData pd);
+
+// /**
+// * 导入Excel
+// *
+// * @param file 文件
+// */
+// void importExcel(MultipartFile file);
+
+ /**
+ * 导入图片
+ *
+ * @param file 文件
+ * @return 导入结果
+ */
+ String importPhotos(MultipartFile file);
+
+ /**
+ * 删除图片
+ *
+ * @param path 路径
+ */
+ void deletePhotos(String path);
+}
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..f3777606
--- /dev/null
+++ b/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java
@@ -0,0 +1,187 @@
+package com.zcloud.service.accident.impl;
+
+import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.lang.Assert;
+import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.ReflectUtil;
+import cn.hutool.core.util.StrUtil;
+import com.zcloud.entity.Page;
+import com.zcloud.entity.PageData;
+import com.zcloud.entity.accident.AccidentRecords;
+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.util.Const;
+import com.zcloud.util.Jurisdiction;
+import com.zcloud.util.Smb;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.lang.reflect.Field;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
+
+@Slf4j
+@Service
+@RequiredArgsConstructor
+public class AccidentRecordsServiceImpl implements AccidentRecordsService {
+
+ private final AccidentRecordsMapper accidentRecordsMapper;
+ private static final List HEADER_ALIAS_CACHE;
+ private final ImgFilesService imgFilesService;
+
+ static {
+ HEADER_ALIAS_CACHE = Arrays.stream(ReflectUtil.getFields(AccidentRecordsExcel.class))
+ .filter(field -> field.isAnnotationPresent(ExcelValue.class))
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public List queryPage(Page page) {
+ PageData data = page.getPd();
+ data.put("corpInfoId", Jurisdiction.getCORPINFO_ID());
+ return accidentRecordsMapper.listPage(page);
+ }
+
+ @Override
+ public PageData getById(String id) {
+ return accidentRecordsMapper.getById(id);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void save(AccidentRecords accidentRecords) {
+ accidentRecords.setId(IdUtil.fastSimpleUUID());
+ accidentRecords.setCreatedBy(Jurisdiction.getUsername());
+ Date date = new Date();
+ SimpleDateFormat dateFormat = new SimpleDateFormat(DatePattern.NORM_DATETIME_PATTERN);
+ // 设置成东八区时间
+ dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
+
+ DateUtil.parse(dateFormat.format(date), DatePattern.NORM_DATETIME_PATTERN);
+
+ accidentRecords.setIsDeleted(0);
+ String corpinfoId = StrUtil.isEmpty(accidentRecords.getCorpinfoId()) ? Jurisdiction.getCORPINFO_ID() : accidentRecords.getCorpinfoId();
+ accidentRecords.setCorpinfoId(corpinfoId);
+ Assert.isTrue(accidentRecordsMapper.save(accidentRecords) == 1, "新增事故记录失败");
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ 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(List ids) {
+ Assert.isTrue(accidentRecordsMapper.delete(ids) == ids.size(), "删除事故记录失败");
+ }
+
+ @Override
+ public Map exportExcel(PageData pd) {
+ // 查询数据
+ pd.put("corpInfoId", Jurisdiction.getCORPINFO_ID());
+ List excels = accidentRecordsMapper.listExcel(pd);
+
+ // 检查查询结果是否为空
+ if (excels == null || excels.isEmpty()) {
+ throw new RuntimeException("没有查询到数据");
+ }
+ Map dataMap = new HashMap() {{
+ put("filename", "事故调查");
+ put("titles", HEADER_ALIAS_CACHE.stream().map(field -> field.getAnnotation(ExcelValue.class)
+ .value()).collect(Collectors.toList()));
+ }};
+
+ List varList = excels.stream().map(excel -> {
+ PageData data = new PageData();
+ for (int i = 0; i < HEADER_ALIAS_CACHE.size(); i++) {
+ data.put("var" + (i + 1), ReflectUtil.getFieldValue(excel, HEADER_ALIAS_CACHE.get(i)));
+ }
+ return data;
+ }).collect(Collectors.toList());
+
+ dataMap.put("varList", varList);
+ return dataMap;
+ }
+
+// @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);
+// if (CollUtil.isEmpty(recordsExcels)) {
+// throw new RuntimeException("没有数据");
+// }
+// sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
+// AccidentRecordsMapper mapper = sqlSession.getMapper(AccidentRecordsMapper.class);
+// 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();
+// }
+// }
+// // 避免刷新数据字典不生效 每次导出重新查询字典
+// AccidentRecords.dictMap.clear();
+// sqlSession.commit();
+// } catch (RuntimeException e) {
+// if (sqlSession != null) {
+// sqlSession.rollback();
+// }
+// log.error("导入excel失败", e);
+// throw e;
+// } catch (Exception e) {
+// if (sqlSession != null) {
+// sqlSession.rollback();
+// }
+// log.error("导入excel失败", e);
+// throw new RuntimeException("导入excel失败");
+// } finally {
+// IoUtil.close(sqlSession);
+// }
+// }
+
+ @Override
+ public String importPhotos(MultipartFile file) {
+ String fileName = IdUtil.fastSimpleUUID() + "." + FileUtil.extName(file.getOriginalFilename());
+ PageData pd = new PageData();
+ pd.put("IMGFILES_ID", IdUtil.fastSimpleUUID());
+ pd.put("FOREIGN_KEY", IdUtil.fastSimpleUUID());
+ pd.put("TYPE", 117);
+ try {
+ String path = Const.FILEPATHFILE + IdUtil.fastSimpleUUID() + "/" + DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN);
+ 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 deletePhotos(String 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
new file mode 100644
index 00000000..fcfd5164
--- /dev/null
+++ b/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml
@@ -0,0 +1,322 @@
+
+
+
+
+
+
+
+
+
+ insert into bus_accident
+
+
+ ACCIDENT_ID,
+
+
+ INCIDENT_NUMBER,
+
+
+ INCIDENT_NAME,
+
+
+ INCIDENT_TYPE,
+
+
+ CORPINFO_ID,
+
+
+ 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},
+
+
+ #{corpinfoId},
+
+
+ #{incidentLevel},
+
+
+ #{incidentNature},
+
+
+ #{location},
+
+
+ #{incidentDate},
+
+
+ #{directLoss},
+
+
+ #{injured},
+
+
+ #{fatalities},
+
+
+ #{seriouslyInjured},
+
+
+ #{cause},
+
+
+ #{summary},
+
+
+ #{photos},
+
+
+ #{analysis},
+
+
+ #{suggestions},
+
+
+ #{measures},
+
+
+ #{creator},
+
+
+ #{reportDate},
+
+
+ #{createdBy},
+
+
+ #{createdTime},
+
+
+ #{updatedBy},
+
+
+ #{updatedTime},
+
+
+ #{isDeleted}
+
+
+
+
+
+ UPDATE bus_accident
+
+ incident_number = #{incidentNumber},
+ incident_name = #{incidentName},
+ incident_type = #{incidentType},
+ corpinfo_id = #{corpinfoId},
+ 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 accident_id = #{id} and is_deleted = 0
+
+
+
+ update bus_accident
+ set is_deleted = 1
+ where
+ accident_id IN
+
+ #{item}
+
+
+
+
+
\ No newline at end of file
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..9f28699b
--- /dev/null
+++ b/src/test/java/com/zcloud/service/accident/service/AccidentRecordsServiceTest.java
@@ -0,0 +1,122 @@
+package com.zcloud.service.accident.service;
+
+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() {
+
+ }
+
+ @Test
+ public void testSave() {
+
+ }
+
+ @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);
+ }
+}