d6473e16 康伟

kangwei: 事故案例库后端接口

1 个父辈 0cce2f66
1 package com.skua.modules.safe.controller;
2
3 import java.util.Arrays;
4 import java.util.List;
5 import java.util.Map;
6 import java.io.IOException;
7 import java.io.UnsupportedEncodingException;
8 import java.net.URLDecoder;
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11 import com.skua.core.api.vo.Result;
12 import com.skua.core.aspect.annotation.AutoLog;
13 import com.skua.core.context.BaseContextHandler;
14 import com.skua.core.query.QueryGenerator;
15 import com.skua.core.service.ISequenceService;
16 import com.skua.core.util.ConvertUtils;
17 import com.skua.modules.safe.entity.AccidentCase;
18 import com.skua.modules.safe.service.IAccidentCaseService;
19 import java.util.Date;
20 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
21 import com.baomidou.mybatisplus.core.metadata.IPage;
22 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
23 import lombok.extern.slf4j.Slf4j;
24
25 import org.jeecgframework.poi.excel.ExcelImportUtil;
26 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
27 import org.jeecgframework.poi.excel.entity.ExportParams;
28 import org.jeecgframework.poi.excel.entity.ImportParams;
29 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
30
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.web.bind.annotation.*;
33 import org.springframework.web.multipart.MultipartFile;
34 import org.springframework.web.multipart.MultipartHttpServletRequest;
35 import org.springframework.web.servlet.ModelAndView;
36 import com.alibaba.fastjson.JSON;
37 import io.swagger.annotations.Api;
38 import io.swagger.annotations.ApiOperation;
39
40 /**
41 * <pre>
42 * 事故案例库
43 * </pre>
44 * @author 开发者姓名
45 * @version V0.1, 开发时间
46 */
47 @Slf4j
48 @Api(tags="事故案例库")
49 @RestController("webAccidentCaseController")
50 @RequestMapping("/web/safe/accidentCase")
51 public class AccidentCaseController {
52 @Autowired
53 private IAccidentCaseService accidentCaseService;
54
55 /**
56 * <pre>
57 * 分页列表查询
58 * </pre>
59 * @param accidentCase
60 * @param pageNo
61 * @param pageSize
62 * @param req
63 * @return
64 * @author 开发者姓名, 开发时间
65 * @Description: TODO(这里描述这个方法的需求变更情况)
66 */
67
68 @AutoLog(value = "事故案例库-分页列表查询")
69 @ApiOperation(value="事故案例库-分页列表查询", notes="事故案例库-分页列表查询")
70 @GetMapping(value = "/list")
71 public Result<IPage<AccidentCase>> queryPageList(AccidentCase accidentCase,
72 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
73 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
74 HttpServletRequest req) {
75 Result<IPage<AccidentCase>> result = new Result<IPage<AccidentCase>>();
76 QueryWrapper<AccidentCase> queryWrapper = QueryGenerator.initQueryWrapper(accidentCase, req.getParameterMap());
77 Page<AccidentCase> page = new Page<AccidentCase>(pageNo, pageSize);
78 queryWrapper.orderByDesc("create_time");
79 IPage<AccidentCase> pageList = accidentCaseService.page(page, queryWrapper);
80 result.setSuccess(true);
81 result.setResult(pageList);
82 return result;
83 }
84
85 /**
86 * <pre>
87 * 添加
88 * </pre>
89 * @param accidentCase
90 * @return
91 * @author 开发者姓名, 开发时间
92 * @Description: TODO(这里描述这个方法的需求变更情况)
93 */
94 @AutoLog(value = "事故案例库-添加")
95 @ApiOperation(value="事故案例库-添加", notes="事故案例库-添加")
96 @PostMapping(value = "/add")
97 public Result<AccidentCase> add(@RequestBody AccidentCase accidentCase) {
98 Result<AccidentCase> result = new Result<AccidentCase>();
99 try {
100 accidentCaseService.save(accidentCase);
101 result.success("添加成功!");
102 } catch (Exception e) {
103 log.error(e.getMessage(),e);
104 result.error500("操作失败");
105 }
106 return result;
107 }
108 /**
109 * <pre>
110 * 编辑
111 * </pre>
112 * @param accidentCase
113 * @return
114 * @author 开发者姓名, 开发时间
115 * @Description: TODO(这里描述这个方法的需求变更情况)
116 */
117 @AutoLog(value = "事故案例库-编辑")
118 @ApiOperation(value="事故案例库-编辑", notes="事故案例库-编辑")
119 @PutMapping(value = "/edit")
120 public Result<AccidentCase> edit(@RequestBody AccidentCase accidentCase) {
121 Result<AccidentCase> result = new Result<AccidentCase>();
122 AccidentCase accidentCaseEntity = accidentCaseService.getById(accidentCase.getId());
123 if(accidentCaseEntity==null) {
124 result.error500("未找到对应实体");
125 }else {
126 boolean ok = accidentCaseService.updateById(accidentCase);
127 //TODO 返回false说明什么?
128 if(ok) {
129 result.success("修改成功!");
130 }
131 }
132
133 return result;
134 }
135 /**
136 * <pre>
137 * 通过id删除
138 * </pre>
139 * @param id
140 * @return
141 * @author 开发者姓名, 开发时间
142 * @Description: TODO(这里描述这个方法的需求变更情况)
143 */
144 @AutoLog(value = "事故案例库-通过id删除")
145 @ApiOperation(value="事故案例库-通过id删除", notes="事故案例库-通过id删除")
146 @DeleteMapping(value = "/delete")
147 public Result<?> delete(@RequestParam(name="id",required=true) String id) {
148 try {
149 accidentCaseService.removeById(id);
150 } catch (Exception e) {
151 log.error("删除失败",e.getMessage());
152 return Result.error("删除失败!");
153 }
154 return Result.ok("删除成功!");
155 }
156
157 /**
158 * <pre>
159 * 批量删除
160 * </pre>
161 * @param ids
162 * @return
163 * @author 开发者姓名, 开发时间
164 * @Description: TODO(这里描述这个方法的需求变更情况)
165 */
166 @AutoLog(value = "事故案例库-批量删除")
167 @ApiOperation(value="事故案例库-批量删除", notes="事故案例库-批量删除")
168 @DeleteMapping(value = "/deleteBatch")
169 public Result<AccidentCase> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
170 Result<AccidentCase> result = new Result<AccidentCase>();
171 if(ids==null || "".equals(ids.trim())) {
172 result.error500("参数不识别!");
173 }else {
174 this.accidentCaseService.removeByIds(Arrays.asList(ids.split(",")));
175 result.success("删除成功!");
176 }
177 return result;
178 }
179 /**
180 * <pre>
181 * 通过id查询
182 * </pre>
183 * @param id
184 * @return
185 * @author 开发者姓名, 开发时间
186 * @Description: TODO(这里描述这个方法的需求变更情况)
187 */
188 @AutoLog(value = "事故案例库-通过id查询")
189 @ApiOperation(value="事故案例库-通过id查询", notes="事故案例库-通过id查询")
190 @GetMapping(value = "/queryById")
191 public Result<AccidentCase> queryById(@RequestParam(name="id",required=true) String id) {
192 Result<AccidentCase> result = new Result<AccidentCase>();
193 AccidentCase accidentCase = accidentCaseService.getById(id);
194 if(accidentCase==null) {
195 result.error500("未找到对应实体");
196 }else {
197 result.setResult(accidentCase);
198 result.setSuccess(true);
199 }
200 return result;
201 }
202
203 /**
204 * <pre>
205 * 导出excel
206 * </pre>
207 * @param request
208 * @param response
209 * @return
210 * @author 开发者姓名, 开发时间
211 * @Description: TODO(这里描述这个方法的需求变更情况)
212 */
213
214 @RequestMapping(value = "/exportXls")
215 public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
216 // Step.1 组装查询条件
217 QueryWrapper<AccidentCase> queryWrapper = null;
218 try {
219 String paramsStr = request.getParameter("paramsStr");
220 if (ConvertUtils.isNotEmpty(paramsStr)) {
221 String deString = URLDecoder.decode(paramsStr, "UTF-8");
222 AccidentCase accidentCase = JSON.parseObject(deString, AccidentCase.class);
223 queryWrapper = QueryGenerator.initQueryWrapper(accidentCase, request.getParameterMap());
224 }
225 } catch (UnsupportedEncodingException e) {
226 e.printStackTrace();
227 }
228
229 //Step.2 AutoPoi 导出Excel
230 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
231 List<AccidentCase> pageList = accidentCaseService.list(queryWrapper);
232 //导出文件名称
233 mv.addObject(NormalExcelConstants.FILE_NAME, "事故案例库列表");
234 mv.addObject(NormalExcelConstants.CLASS, AccidentCase.class);
235 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("事故案例库列表数据", "导出人:Jeecg", "导出信息"));
236 mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
237 return mv;
238 }
239
240 /**
241 * <pre>
242 * 通过excel导入数据
243 * </pre>
244 * @param request
245 * @param response
246 * @return
247 * @author 开发者姓名, 开发时间
248 * @Description: TODO(这里描述这个方法的需求变更情况)
249 */
250 @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
251 public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
252 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
253 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
254 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
255 MultipartFile file = entity.getValue();// 获取上传文件对象
256 ImportParams params = new ImportParams();
257 params.setTitleRows(2);
258 params.setHeadRows(1);
259 params.setNeedSave(true);
260 try {
261 List<AccidentCase> listAccidentCases = ExcelImportUtil.importExcel(file.getInputStream(), AccidentCase.class, params);
262 accidentCaseService.saveBatch(listAccidentCases);
263 return Result.ok("文件导入成功!数据行数:" + listAccidentCases.size());
264 } catch (Exception e) {
265 log.error(e.getMessage(),e);
266 return Result.error("文件导入失败:"+e.getMessage());
267 } finally {
268 try {
269 file.getInputStream().close();
270 } catch (IOException e) {
271 e.printStackTrace();
272 }
273 }
274 }
275 return Result.ok("文件导入失败!");
276 }
277
278 }
1 package com.skua.modules.safe.entity;
2
3 import java.io.Serializable;
4 import java.util.Date;
5 import com.baomidou.mybatisplus.annotation.IdType;
6 import com.baomidou.mybatisplus.annotation.TableId;
7 import com.baomidou.mybatisplus.annotation.TableName;
8 import com.baomidou.mybatisplus.annotation.TableField;
9 import com.skua.core.aspect.annotation.Dict;
10 import io.swagger.annotations.ApiModel;
11 import io.swagger.annotations.ApiModelProperty;
12 import lombok.Data;
13 import lombok.EqualsAndHashCode;
14 import lombok.experimental.Accessors;
15 import com.fasterxml.jackson.annotation.JsonFormat;
16 import org.springframework.format.annotation.DateTimeFormat;
17 import org.jeecgframework.poi.excel.annotation.Excel;
18
19 /**
20 * 事故案例库
21 */
22 @Data
23 @TableName("safe_accident_case")
24 @EqualsAndHashCode(callSuper = false)
25 @Accessors(chain = true)
26 @ApiModel(value="safe_accident_case对象", description="事故案例库")
27 public class AccidentCase {
28
29 /**id*/
30 @TableId(type = IdType.ID_WORKER_STR)
31 @ApiModelProperty(value = "id")
32 private String id;
33 /**所属机构*/
34 @Excel(name = "所属机构", width = 15)
35 @ApiModelProperty(value = "所属机构")
36 private String departId;
37 /**事故名称*/
38 @Excel(name = "事故名称", width = 15)
39 @ApiModelProperty(value = "事故名称")
40 private String accidentName;
41 /**事故类型*/
42 @Excel(name = "事故类型", width = 15)
43 @ApiModelProperty(value = "事故类型")
44 @Dict(dicCode = "safe_accident_type")
45 private String accidentType;
46 /**发生时间*/
47 @Excel(name = "发生时间", width = 15)
48 @ApiModelProperty(value = "发生时间")
49 private String accidentTime;
50 /**发生地点*/
51 @Excel(name = "发生地点", width = 15)
52 @ApiModelProperty(value = "发生地点")
53 private String accidentPlace;
54 /**责任部门*/
55 @Excel(name = "责任部门", width = 15)
56 @ApiModelProperty(value = "责任部门")
57 private String dutyDepart;
58 /**责任人员(用户id)*/
59 @Excel(name = "责任人员(用户id)", width = 15)
60 @ApiModelProperty(value = "责任人员(用户id)")
61 private String dutyUser;
62 /**事故描述*/
63 @Excel(name = "事故描述", width = 15)
64 @ApiModelProperty(value = "事故描述")
65 private String accidentDescription;
66 /**事故后果*/
67 @Excel(name = "事故后果", width = 15)
68 @ApiModelProperty(value = "事故后果")
69 private String accidentResult;
70 /**应急措施*/
71 @Excel(name = "应急措施", width = 15)
72 @ApiModelProperty(value = "应急措施")
73 private String measures;
74 /**事故总结*/
75 @Excel(name = "事故总结", width = 15)
76 @ApiModelProperty(value = "事故总结")
77 private String accidentSummary;
78 /**事故照片*/
79 @Excel(name = "事故照片", width = 15)
80 @ApiModelProperty(value = "事故照片")
81 private String accidentImg;
82 /**事故报告文件*/
83 @Excel(name = "事故报告文件", width = 15)
84 @ApiModelProperty(value = "事故报告文件")
85 private String accidentFile;
86 /**备注*/
87 @Excel(name = "备注", width = 15)
88 @ApiModelProperty(value = "备注")
89 private String remark;
90 /**创建人Id*/
91 @Excel(name = "创建人Id", width = 15)
92 @ApiModelProperty(value = "创建人Id")
93 private String createBy;
94 /**上报时间*/
95 @Excel(name = "上报时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
96 @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
97 @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
98 @ApiModelProperty(value = "上报时间")
99 private Date createTime;
100 /**修改人Id*/
101 @Excel(name = "修改人Id", width = 15)
102 @ApiModelProperty(value = "修改人Id")
103 private String updateBy;
104 /**修改时间*/
105 @Excel(name = "修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
106 @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
107 @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
108 @ApiModelProperty(value = "修改时间")
109 private Date updateTime;
110 /**删除标识,1有效,0删除*/
111 @Excel(name = "删除标识,1有效,0删除", width = 15)
112 @ApiModelProperty(value = "删除标识,1有效,0删除")
113 private Integer delFlag;
114 }
1 package com.skua.modules.safe.mapper;
2
3 import java.util.List;
4
5 import org.apache.ibatis.annotations.Param;
6 import com.skua.modules.safe.entity.AccidentCase;
7 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
8
9 /**
10 * 事故案例库
11 */
12 public interface AccidentCaseMapper extends BaseMapper<AccidentCase> {
13
14 }
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 <mapper namespace="com.skua.modules.safe.mapper.AccidentCaseMapper">
4
5 </mapper>
...\ No newline at end of file ...\ No newline at end of file
1 package com.skua.modules.safe.service;
2
3 import com.skua.modules.safe.entity.AccidentCase;
4 import com.baomidou.mybatisplus.extension.service.IService;
5
6 /**
7 * 事故案例库
8 */
9 public interface IAccidentCaseService extends IService<AccidentCase> {
10
11 }
1 package com.skua.modules.safe.service.impl;
2
3 import com.skua.modules.safe.entity.AccidentCase;
4 import com.skua.modules.safe.mapper.AccidentCaseMapper;
5 import com.skua.modules.safe.service.IAccidentCaseService;
6 import org.springframework.stereotype.Service;
7
8 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
9
10 /**
11 * 事故案例库
12 */
13 @Service
14 public class AccidentCaseServiceImpl extends ServiceImpl<AccidentCaseMapper, AccidentCase> implements IAccidentCaseService {
15
16 }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!