e0c9026f 张雷

feat(report): 新增经营目标拆分功能

- 添加 ReportTargetConfigSub 实体类
- 创建 IReportTargetConfigSubService 接口及实现类
- 开发 ReportTargetConfigSubController 控制器- 编写 ReportTargetConfigSubMapper 接口及 XML 文件- 在 ReportTargetConfig 中添加费用目标字段
1 个父辈 c8b2a72d
1 package com.skua.modules.report.controller;
2
3 import java.util.*;
4 import java.io.IOException;
5 import java.io.UnsupportedEncodingException;
6 import java.net.URLDecoder;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
9
10 import com.skua.common.constant.ReportConstant;
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.report.entity.ReportTargetConfigSub;
18 import com.skua.modules.report.service.IReportTargetConfigSubService;
19 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
20 import com.baomidou.mybatisplus.core.metadata.IPage;
21 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
22 import lombok.extern.slf4j.Slf4j;
23
24 import org.jeecgframework.poi.excel.ExcelImportUtil;
25 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
26 import org.jeecgframework.poi.excel.entity.ExportParams;
27 import org.jeecgframework.poi.excel.entity.ImportParams;
28 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
29
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.web.bind.annotation.*;
32 import org.springframework.web.multipart.MultipartFile;
33 import org.springframework.web.multipart.MultipartHttpServletRequest;
34 import org.springframework.web.servlet.ModelAndView;
35 import com.alibaba.fastjson.JSON;
36 import io.swagger.annotations.Api;
37 import io.swagger.annotations.ApiOperation;
38
39 /**
40 * <pre>
41 * 经营目标拆分
42 * </pre>
43 * @author 开发者姓名
44 * @version V0.1, 开发时间
45 */
46 @Slf4j
47 @Api(tags="经营目标拆分")
48 @RestController
49 @RequestMapping("/report/reportTargetSub")
50 public class ReportTargetConfigSubController {
51 @Autowired
52 private IReportTargetConfigSubService reportTargetConfigSubService;
53
54 /**
55 * <pre>
56 * 分页列表查询
57 * </pre>
58 * @param reportTargetConfigSub
59 * @param pageNo
60 * @param pageSize
61 * @param req
62 * @return
63 * @author 开发者姓名, 开发时间
64 * @Description: TODO(这里描述这个方法的需求变更情况)
65 */
66
67 @AutoLog(value = "经营目标拆分-分页列表查询")
68 @ApiOperation(value="经营目标拆分-分页列表查询", notes="经营目标拆分-分页列表查询")
69 @GetMapping(value = "/list")
70 public Result<IPage<ReportTargetConfigSub>> queryPageList(ReportTargetConfigSub reportTargetConfigSub,
71 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
72 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
73 HttpServletRequest req) {
74 Result<IPage<ReportTargetConfigSub>> result = new Result<IPage<ReportTargetConfigSub>>();
75 QueryWrapper<ReportTargetConfigSub> queryWrapper = QueryGenerator.initQueryWrapper(reportTargetConfigSub, req.getParameterMap());
76 Page<ReportTargetConfigSub> page = new Page<ReportTargetConfigSub>(pageNo, pageSize);
77 IPage<ReportTargetConfigSub> pageList = reportTargetConfigSubService.page(page, queryWrapper);
78 result.setSuccess(true);
79 result.setResult(pageList);
80 return result;
81 }
82
83 @AutoLog(value = "经营目标拆分列表查询")
84 @ApiOperation(value="经营目标拆分列表查询", notes="经营目标拆分列表查询")
85 @GetMapping(value = "/getList")
86 public Result<List<ReportTargetConfigSub>> queryList(ReportTargetConfigSub reportTargetConfigSub) {
87 Result<List<ReportTargetConfigSub>> result = new Result<List<ReportTargetConfigSub>>();
88 List<ReportTargetConfigSub> list = reportTargetConfigSubService.getList(reportTargetConfigSub);
89 result.setSuccess(true);
90 result.setResult(list);
91 return result;
92 }
93
94 /**
95 * <pre>
96 * 添加
97 * </pre>
98 * @param reportTargetConfigSub
99 * @return
100 * @author 开发者姓名, 开发时间
101 * @Description: TODO(这里描述这个方法的需求变更情况)
102 */
103 @AutoLog(value = "经营目标拆分-添加")
104 @ApiOperation(value="经营目标拆分-添加", notes="经营目标拆分-添加")
105 @PostMapping(value = "/add")
106 public Result<ReportTargetConfigSub> add(@RequestBody ReportTargetConfigSub reportTargetConfigSub) {
107 Result<ReportTargetConfigSub> result = new Result<ReportTargetConfigSub>();
108 try {
109 reportTargetConfigSubService.save(reportTargetConfigSub);
110 result.success("添加成功!");
111 } catch (Exception e) {
112 log.error(e.getMessage(),e);
113 result.error500("操作失败");
114 }
115 return result;
116 }
117 /**
118 * <pre>
119 * 编辑
120 * </pre>
121 * @param reportTargetConfigSub
122 * @return
123 * @author 开发者姓名, 开发时间
124 * @Description: TODO(这里描述这个方法的需求变更情况)
125 */
126 @AutoLog(value = "经营目标拆分-编辑")
127 @ApiOperation(value="经营目标拆分-编辑", notes="经营目标拆分-编辑")
128 @PutMapping(value = "/edit")
129 public Result<ReportTargetConfigSub> edit(@RequestBody ReportTargetConfigSub reportTargetConfigSub) {
130 Result<ReportTargetConfigSub> result = new Result<ReportTargetConfigSub>();
131 ReportTargetConfigSub reportTargetConfigSubEntity = reportTargetConfigSubService.getById(reportTargetConfigSub.getId());
132 if(reportTargetConfigSubEntity==null) {
133 result.error500("未找到对应实体");
134 }else {
135 boolean ok = reportTargetConfigSubService.updateById(reportTargetConfigSub);
136 //TODO 返回false说明什么?
137 if(ok) {
138 result.success("修改成功!");
139 }
140 }
141
142 return result;
143 }
144 /**
145 * <pre>
146 * 通过id删除
147 * </pre>
148 * @param id
149 * @return
150 * @author 开发者姓名, 开发时间
151 * @Description: TODO(这里描述这个方法的需求变更情况)
152 */
153 @AutoLog(value = "经营目标拆分-通过id删除")
154 @ApiOperation(value="经营目标拆分-通过id删除", notes="经营目标拆分-通过id删除")
155 @DeleteMapping(value = "/delete")
156 public Result<?> delete(@RequestParam(name="id",required=true) String id) {
157 try {
158 reportTargetConfigSubService.removeById(id);
159 } catch (Exception e) {
160 log.error("删除失败",e.getMessage());
161 return Result.error("删除失败!");
162 }
163 return Result.ok("删除成功!");
164 }
165
166 /**
167 * <pre>
168 * 批量删除
169 * </pre>
170 * @param ids
171 * @return
172 * @author 开发者姓名, 开发时间
173 * @Description: TODO(这里描述这个方法的需求变更情况)
174 */
175 @AutoLog(value = "经营目标拆分-批量删除")
176 @ApiOperation(value="经营目标拆分-批量删除", notes="经营目标拆分-批量删除")
177 @DeleteMapping(value = "/deleteBatch")
178 public Result<ReportTargetConfigSub> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
179 Result<ReportTargetConfigSub> result = new Result<ReportTargetConfigSub>();
180 if(ids==null || "".equals(ids.trim())) {
181 result.error500("参数不识别!");
182 }else {
183 this.reportTargetConfigSubService.removeByIds(Arrays.asList(ids.split(",")));
184 result.success("删除成功!");
185 }
186 return result;
187 }
188 /**
189 * <pre>
190 * 通过id查询
191 * </pre>
192 * @param id
193 * @return
194 * @author 开发者姓名, 开发时间
195 * @Description: TODO(这里描述这个方法的需求变更情况)
196 */
197 @AutoLog(value = "经营目标拆分-通过id查询")
198 @ApiOperation(value="经营目标拆分-通过id查询", notes="经营目标拆分-通过id查询")
199 @GetMapping(value = "/queryById")
200 public Result<ReportTargetConfigSub> queryById(@RequestParam(name="id",required=true) String id) {
201 Result<ReportTargetConfigSub> result = new Result<ReportTargetConfigSub>();
202 ReportTargetConfigSub reportTargetConfigSub = reportTargetConfigSubService.getById(id);
203 if(reportTargetConfigSub==null) {
204 result.error500("未找到对应实体");
205 }else {
206 result.setResult(reportTargetConfigSub);
207 result.setSuccess(true);
208 }
209 return result;
210 }
211
212 /**
213 * <pre>
214 * 导出excel
215 * </pre>
216 * @param request
217 * @param response
218 * @return
219 * @author 开发者姓名, 开发时间
220 * @Description: TODO(这里描述这个方法的需求变更情况)
221 */
222
223 @RequestMapping(value = "/exportXls")
224 public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
225 // Step.1 组装查询条件
226 QueryWrapper<ReportTargetConfigSub> queryWrapper = null;
227 try {
228 String paramsStr = request.getParameter("paramsStr");
229 if (ConvertUtils.isNotEmpty(paramsStr)) {
230 String deString = URLDecoder.decode(paramsStr, "UTF-8");
231 ReportTargetConfigSub reportTargetConfigSub = JSON.parseObject(deString, ReportTargetConfigSub.class);
232 queryWrapper = QueryGenerator.initQueryWrapper(reportTargetConfigSub, request.getParameterMap());
233 }
234 } catch (UnsupportedEncodingException e) {
235 e.printStackTrace();
236 }
237
238 //Step.2 AutoPoi 导出Excel
239 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
240 List<ReportTargetConfigSub> pageList = reportTargetConfigSubService.list(queryWrapper);
241 //导出文件名称
242 mv.addObject(NormalExcelConstants.FILE_NAME, "经营目标拆分列表");
243 mv.addObject(NormalExcelConstants.CLASS, ReportTargetConfigSub.class);
244 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("经营目标拆分列表数据", "导出人:Jeecg", "导出信息"));
245 mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
246 return mv;
247 }
248
249 /**
250 * <pre>
251 * 通过excel导入数据
252 * </pre>
253 * @param request
254 * @param response
255 * @return
256 * @author 开发者姓名, 开发时间
257 * @Description: TODO(这里描述这个方法的需求变更情况)
258 */
259 @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
260 public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
261 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
262 Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
263 for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
264 MultipartFile file = entity.getValue();// 获取上传文件对象
265 ImportParams params = new ImportParams();
266 params.setTitleRows(2);
267 params.setHeadRows(1);
268 params.setNeedSave(true);
269 try {
270 List<ReportTargetConfigSub> listReportTargetConfigSubs = ExcelImportUtil.importExcel(file.getInputStream(), ReportTargetConfigSub.class, params);
271 reportTargetConfigSubService.saveBatch(listReportTargetConfigSubs);
272 return Result.ok("文件导入成功!数据行数:" + listReportTargetConfigSubs.size());
273 } catch (Exception e) {
274 log.error(e.getMessage(),e);
275 return Result.error("文件导入失败:"+e.getMessage());
276 } finally {
277 try {
278 file.getInputStream().close();
279 } catch (IOException e) {
280 e.printStackTrace();
281 }
282 }
283 }
284 return Result.ok("文件导入失败!");
285 }
286
287 @AutoLog(value = "报表批量添加拆分目标")
288 @ApiOperation(value = "报表批量添加拆分目标", notes = "报表批量添加拆分目标")
289 @PostMapping(value = "/batchSave")
290 public Result batchSave(@RequestBody List<Map<String, String>> dataList) {
291 List<ReportTargetConfigSub> reportTargetConfigSubList = new ArrayList<>();
292 String departId = ConvertUtils.getString(dataList.get(0).get("departId"));
293 String dataType = ConvertUtils.getString(dataList.get(0).get("dataType"));
294 String year = ConvertUtils.getString(dataList.get(0).get("dataTime")).split("-")[0];
295 for (Map<String, String> data : dataList) {
296 ReportTargetConfigSub reportTargetConfigSub = new ReportTargetConfigSub();
297 reportTargetConfigSub.setTargetTime(ConvertUtils.getString(data.get("dataTime")));
298 reportTargetConfigSub.setDepartId(ConvertUtils.getString(data.get("departId")));
299 reportTargetConfigSub.setTargetType(ConvertUtils.getString(data.get("dataType")));
300 reportTargetConfigSub.setTargetValue(ConvertUtils.getString(data.get("dataValue")));
301 reportTargetConfigSubList.add(reportTargetConfigSub);
302 }
303 boolean ok = reportTargetConfigSubService.batchDeleteData(departId,year,dataType);
304 if(ok){
305 reportTargetConfigSubService.saveBatch(reportTargetConfigSubList);
306 }
307 return Result.ok("批量添加成功");
308 }
309
310 }
...@@ -36,6 +36,10 @@ public class ReportTargetConfig { ...@@ -36,6 +36,10 @@ public class ReportTargetConfig {
36 @Excel(name = "水量目标", width = 15) 36 @Excel(name = "水量目标", width = 15)
37 @ApiModelProperty(value = "水量目标") 37 @ApiModelProperty(value = "水量目标")
38 private String targetWater; 38 private String targetWater;
39 /**费用目标*/
40 @Excel(name = "费用目标", width = 15)
41 @ApiModelProperty(value = "费用目标")
42 private String targetCost;
39 /**电量目标*/ 43 /**电量目标*/
40 @Excel(name = "电量目标", width = 15) 44 @Excel(name = "电量目标", width = 15)
41 @ApiModelProperty(value = "电量目标") 45 @ApiModelProperty(value = "电量目标")
......
1 package com.skua.modules.report.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 io.swagger.annotations.ApiModel;
10 import io.swagger.annotations.ApiModelProperty;
11 import lombok.Data;
12 import lombok.EqualsAndHashCode;
13 import lombok.experimental.Accessors;
14 import com.fasterxml.jackson.annotation.JsonFormat;
15 import org.springframework.format.annotation.DateTimeFormat;
16 import org.jeecgframework.poi.excel.annotation.Excel;
17
18 /**
19 * 经营目标拆分
20 */
21 @Data
22 @TableName("report_target_config_sub")
23 @EqualsAndHashCode(callSuper = false)
24 @Accessors(chain = true)
25 @ApiModel(value="report_target_config_sub对象", description="经营目标拆分")
26 public class ReportTargetConfigSub {
27
28 /**主键id*/
29 @TableId(type = IdType.ID_WORKER_STR)
30 @ApiModelProperty(value = "主键id")
31 private String id;
32 /**所属厂区*/
33 @Excel(name = "所属厂区", width = 15)
34 @ApiModelProperty(value = "所属厂区")
35 private String departId;
36 /**目标时间*/
37 @Excel(name = "目标时间", width = 15)
38 @ApiModelProperty(value = "目标时间")
39 private String targetTime;
40 /**目标类型*/
41 @Excel(name = "目标类型", width = 15)
42 @ApiModelProperty(value = "目标类型")
43 private String targetType;
44 /**目标值*/
45 @Excel(name = "目标值", width = 15)
46 @ApiModelProperty(value = "目标值")
47 private String targetValue;
48 /**创建人Id*/
49 @Excel(name = "创建人Id", width = 15)
50 @ApiModelProperty(value = "创建人Id")
51 private String createBy;
52 /**创建时间*/
53 @Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
54 @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
55 @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
56 @ApiModelProperty(value = "创建时间")
57 private Date createTime;
58 /**修改人Id*/
59 @Excel(name = "修改人Id", width = 15)
60 @ApiModelProperty(value = "修改人Id")
61 private String updateBy;
62 /**修改时间*/
63 @Excel(name = "修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
64 @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
65 @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
66 @ApiModelProperty(value = "修改时间")
67 private Date updateTime;
68 /**删除标识*/
69 @Excel(name = "删除标识", width = 15)
70 @ApiModelProperty(value = "删除标识")
71 private Integer delFlag;
72 }
1 package com.skua.modules.report.mapper;
2
3 import com.skua.tool.annotation.Anonymous;
4 import org.apache.ibatis.annotations.Param;
5 import com.skua.modules.report.entity.ReportTargetConfigSub;
6 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
7
8 import java.util.List;
9
10 /**
11 * 经营目标拆分
12 */
13 public interface ReportTargetConfigSubMapper extends BaseMapper<ReportTargetConfigSub> {
14
15 void batchDeleteData(@Param("departId") String departId, @Param("year") String year, @Param("type") String type);
16
17 @Anonymous
18 List<ReportTargetConfigSub> getList(@Param("departId") String departId, @Param("year") String year, @Param("targetType") String targetType);
19 }
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.report.mapper.ReportTargetConfigSubMapper">
4
5 <delete id="batchDeleteData">
6 DELETE FROM report_target_config_sub
7 WHERE depart_id = #{departId} AND target_type = #{type} AND target_time like concat(#{year},'%')
8 </delete>
9
10 <select id="getList" resultType="com.skua.modules.report.entity.ReportTargetConfigSub">
11 SELECT * FROM report_target_config_sub
12 WHERE depart_id = #{departId} AND target_type = #{targetType} AND target_time like concat(#{year},'%')
13 </select>
14
15 </mapper>
1 package com.skua.modules.report.service;
2
3 import com.skua.modules.report.entity.ReportTargetConfigSub;
4 import com.baomidou.mybatisplus.extension.service.IService;
5 import com.skua.tool.annotation.Anonymous;
6
7 import java.util.List;
8
9 /**
10 * 经营目标拆分
11 */
12 public interface IReportTargetConfigSubService extends IService<ReportTargetConfigSub> {
13
14 boolean batchDeleteData(String departId, String year, String type);
15
16 List<ReportTargetConfigSub> getList(ReportTargetConfigSub reportTargetConfigSub);
17 }
1 package com.skua.modules.report.service.impl;
2
3 import com.skua.modules.report.entity.ReportTargetConfigSub;
4 import com.skua.modules.report.mapper.ReportTargetConfigSubMapper;
5 import com.skua.modules.report.service.IReportTargetConfigSubService;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.stereotype.Service;
8
9 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
10
11 import java.util.Collections;
12 import java.util.List;
13
14 /**
15 * 经营目标拆分
16 */
17 @Service
18 public class ReportTargetConfigSubServiceImpl extends ServiceImpl<ReportTargetConfigSubMapper, ReportTargetConfigSub> implements IReportTargetConfigSubService {
19
20 @Autowired
21 ReportTargetConfigSubMapper reportTargetSubMapper;
22
23 @Override
24 public boolean batchDeleteData(String departId, String year, String type) {
25 reportTargetSubMapper.batchDeleteData(departId,year,type);
26 return true;
27 }
28
29 @Override
30 public List<ReportTargetConfigSub> getList(ReportTargetConfigSub reportTargetConfigSub) {
31 return reportTargetSubMapper.getList(reportTargetConfigSub.getDepartId(), reportTargetConfigSub.getTargetTime(),
32 reportTargetConfigSub.getTargetType());
33 }
34
35 }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!