上传 excel 导入 导出 相关代码

hyx_2024-10-12_xgfPerson
wangpeng 2024-09-02 16:11:56 +08:00
parent 70c1ee4c3f
commit c15fdba0a7
11 changed files with 413 additions and 219 deletions

View File

@ -215,7 +215,7 @@
<artifactId>aliyun-java-sdk-core</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-dysmsapi</artifactId>
<version>1.0.0</version>

View File

@ -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<String, Object> queryPage(Page page, HttpServletRequest request) {
page.setPd(new PageData(request));
@ -38,16 +40,16 @@ public class AccidentRecordsController extends BaseController {
@RequestMapping("/{id}")
public Map<String, Object> getById(@PathVariable("id") Long id) {
Assert.notNull(id, "id不能为空");
Map<String, Object> 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<String, Object> 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<String, Object> result = new HashMap<>();
result.put("result", "success");
@ -57,6 +59,8 @@ public class AccidentRecordsController extends BaseController {
@RequestMapping("/update")
public Map<String, Object> 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<String, Object> result = new HashMap<>();
result.put("result", "success");
@ -65,11 +69,25 @@ public class AccidentRecordsController extends BaseController {
@RequestMapping("/delete/{ids}")
public Map<String, Object> 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<String, Object> 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);
}
}

View File

@ -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;
/**
*

View File

@ -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");
}
}
}

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<AccidentRecordsExcel> listExcel(PageData pd);
void saveExcel(AccidentRecordsExcel records, long id, String username);
}

View File

@ -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);
}

View File

@ -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<String, String> 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<PageData> 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<AccidentRecordsExcel> 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<AccidentRecordsExcel> 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();
}
}
}
}

View File

@ -1,68 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zcloud.mapper.datasource.accident.AccidentRecordsMapper">
<resultMap id="BaseResultMap" type="com.zcloud.entity.accident.AccidentRecords">
<!--@mbg.generated-->
<!--@Table accident_records-->
<id column="id" jdbcType="BIGINT" property="id" />
<result column="incident_number" jdbcType="VARCHAR" property="incidentNumber" />
<result column="incident_name" jdbcType="VARCHAR" property="incidentName" />
<result column="incident_type" jdbcType="BOOLEAN" property="incidentType" />
<result column="company_name" jdbcType="VARCHAR" property="companyName" />
<result column="incident_level" jdbcType="VARCHAR" property="incidentLevel" />
<result column="incident_nature" jdbcType="VARCHAR" property="incidentNature" />
<result column="location" jdbcType="VARCHAR" property="location" />
<result column="incident_date" jdbcType="TIMESTAMP" property="incidentDate" />
<result column="direct_loss" jdbcType="VARCHAR" property="directLoss" />
<result column="injured" jdbcType="INTEGER" property="injured" />
<result column="fatalities" jdbcType="INTEGER" property="fatalities" />
<result column="seriously_injured" jdbcType="INTEGER" property="seriouslyInjured" />
<result column="cause" jdbcType="VARCHAR" property="cause" />
<result column="summary" jdbcType="LONGVARCHAR" property="summary" />
<result column="photos" jdbcType="LONGVARCHAR" property="photos" />
<result column="analysis" jdbcType="LONGVARCHAR" property="analysis" />
<result column="suggestions" jdbcType="LONGVARCHAR" property="suggestions" />
<result column="measures" jdbcType="LONGVARCHAR" property="measures" />
<result column="creator" jdbcType="VARCHAR" property="creator" />
<result column="report_date" jdbcType="DATE" property="reportDate" />
<result column="created_by" jdbcType="VARCHAR" property="createdBy" />
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime" />
<result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
<result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime" />
<result column="is_deleted" jdbcType="BOOLEAN" property="isDeleted" />
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
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
</sql>
<select id="listPage" parameterType="page" resultType="pd">
select id, company_name, location, incident_date, incident_name
from accident_records
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
<where>
<if test="pd.corpInfoId != null and pd.corpInfoId != ''">
and ar.corpinfo_id = #{pd.corpInfoId}
</if>
<if test="pd.incidentName != null and pd.incidentName != ''">
and incident_number like concat('%', #{pd.incidentName}, '%')
and incident_name like concat('%', #{pd.incidentName}, '%')
</if>
<if test="pd.incidentDates != null and pd.incidentDates.size() == 2">
and incident_date between #{pd.incidentDates[0]} and #{pd.incidentDates[1]}
</if>
<if test="pd.location != null and pd.location != ''">
and incident_number like concat('%', #{pd.location}, '%')
and location like concat('%', #{pd.location}, '%')
</if>
<if test="pd.incidentLevel != null and pd.incidentLevel != ''">
and incident_number like concat('%', #{pd.incidentLevel}, '%')
and incident_level like concat('%', #{pd.incidentLevel}, '%')
</if>
<if test="pd.incidentType != null">
and incidentType = #{pd.incidentType}
and incident_type = #{pd.incidentType}
</if>
<if test="1 == 1">
and is_deleted = 0
</if>
</where>
order by incident_date desc , company_name
order by incident_date desc , companyName
</select>
<select id="getById" resultType="com.zcloud.entity.PageData">
@ -70,8 +37,8 @@
incident_number,
incident_name,
incident_type,
company_name,
incident_level,
CORP_NAME as companyName,
incident_nature,
`location`,
incident_date,
@ -87,8 +54,10 @@
measures,
creator,
report_date
from accident_records
where id = #{id} and is_deleted = 0;
from accident_records as ar
left join bus_corp_info as bci on ar.corpinfo_id = bci.CORPINFO_ID
where ar.id = #{id}
and ar.is_deleted = 0;
</select>
<insert id="save" parameterType="com.zcloud.entity.accident.AccidentRecords">
@ -106,8 +75,8 @@
<if test="incidentType != null">
incident_type,
</if>
<if test="companyName != null">
company_name,
<if test="corpinfoId != null">
corpinfo_id,
</if>
<if test="incidentLevel != null">
incident_level,
@ -187,8 +156,8 @@
<if test="incidentType != null">
#{incidentType},
</if>
<if test="companyName != null">
#{companyName},
<if test="corpinfoId != null">
#{corpinfoId},
</if>
<if test="incidentLevel != null">
#{incidentLevel},
@ -262,7 +231,7 @@
<if test="incidentNumber != null">incident_number = #{incidentNumber},</if>
<if test="incidentName != null">incident_name = #{incidentName},</if>
<if test="incidentType != null">incident_type = #{incidentType},</if>
<if test="companyName != null">company_name = #{companyName},</if>
<if test="corpinfoId != null">corpinfo_id = #{corpinfoId},</if>
<if test="incidentLevel != null">incident_level = #{incidentLevel},</if>
<if test="incidentNature != null">incident_nature = #{incidentNature},</if>
<if test="location != null">location = #{location},</if>
@ -297,4 +266,54 @@
#{item}
</foreach>
</update>
<select id="listExcel" resultType="com.zcloud.entity.accident.dto.AccidentRecordsExcel">
select incident_number,
incident_name,
(select NAME from sys_dictionaries_corp
where DICTIONARIES_ID = '' and incident_type = BIANMA) as 'incidentType',
(select NAME from sys_dictionaries_corp
where DICTIONARIES_ID = '' and incident_level = BIANMA) as 'incidentLevel',
CORP_NAME as 'companyName',
incident_nature ,
`location`,
date_format(incident_date, '%Y年%m月%d日%H时%I分%s秒') as 'incidentDate',
direct_loss,
injured,
fatalities,
seriously_injured,
cause,
summary,
analysis,
suggestions,
measures,
ar.creator,
date_format(report_date, '%Y年%m月%d日') as 'reportDate'
from accident_records as ar
left join bus_corp_info as bci on ar.corpinfo_id = bci.CORPINFO_ID
<where>
<if test="pd.corpInfoId != null and pd.corpInfoId != ''">
and ar.corpinfo_id = #{pd.corpInfoId}
</if>
<if test="pd.incidentName != null and pd.incidentName != ''">
and incident_name like concat('%', #{pd.incidentName}, '%')
</if>
<if test="pd.incidentDates != null and pd.incidentDates.size() == 2">
and incident_date between #{pd.incidentDates[0]} and #{pd.incidentDates[1]}
</if>
<if test="pd.location != null and pd.location != ''">
and location like concat('%', #{pd.location}, '%')
</if>
<if test="pd.incidentLevel != null and pd.incidentLevel != ''">
and incident_level like concat('%', #{pd.incidentLevel}, '%')
</if>
<if test="pd.incidentType != null">
and incident_type = #{pd.incidentType}
</if>
<if test="1 == 1">
and is_deleted = 0
</if>
</where>
order by incident_date desc, companyName
</select>
</mapper>