e0c9026f 张雷

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

- 添加 ReportTargetConfigSub 实体类
- 创建 IReportTargetConfigSubService 接口及实现类
- 开发 ReportTargetConfigSubController 控制器- 编写 ReportTargetConfigSubMapper 接口及 XML 文件- 在 ReportTargetConfig 中添加费用目标字段
1 个父辈 c8b2a72d
package com.skua.modules.report.controller;
import java.util.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.skua.common.constant.ReportConstant;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.context.BaseContextHandler;
import com.skua.core.query.QueryGenerator;
import com.skua.core.service.ISequenceService;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.report.entity.ReportTargetConfigSub;
import com.skua.modules.report.service.IReportTargetConfigSubService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
* <pre>
* 经营目标拆分
* </pre>
* @author 开发者姓名
* @version V0.1, 开发时间
*/
@Slf4j
@Api(tags="经营目标拆分")
@RestController
@RequestMapping("/report/reportTargetSub")
public class ReportTargetConfigSubController {
@Autowired
private IReportTargetConfigSubService reportTargetConfigSubService;
/**
* <pre>
* 分页列表查询
* </pre>
* @param reportTargetConfigSub
* @param pageNo
* @param pageSize
* @param req
* @return
* @author 开发者姓名, 开发时间
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@AutoLog(value = "经营目标拆分-分页列表查询")
@ApiOperation(value="经营目标拆分-分页列表查询", notes="经营目标拆分-分页列表查询")
@GetMapping(value = "/list")
public Result<IPage<ReportTargetConfigSub>> queryPageList(ReportTargetConfigSub reportTargetConfigSub,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) {
Result<IPage<ReportTargetConfigSub>> result = new Result<IPage<ReportTargetConfigSub>>();
QueryWrapper<ReportTargetConfigSub> queryWrapper = QueryGenerator.initQueryWrapper(reportTargetConfigSub, req.getParameterMap());
Page<ReportTargetConfigSub> page = new Page<ReportTargetConfigSub>(pageNo, pageSize);
IPage<ReportTargetConfigSub> pageList = reportTargetConfigSubService.page(page, queryWrapper);
result.setSuccess(true);
result.setResult(pageList);
return result;
}
@AutoLog(value = "经营目标拆分列表查询")
@ApiOperation(value="经营目标拆分列表查询", notes="经营目标拆分列表查询")
@GetMapping(value = "/getList")
public Result<List<ReportTargetConfigSub>> queryList(ReportTargetConfigSub reportTargetConfigSub) {
Result<List<ReportTargetConfigSub>> result = new Result<List<ReportTargetConfigSub>>();
List<ReportTargetConfigSub> list = reportTargetConfigSubService.getList(reportTargetConfigSub);
result.setSuccess(true);
result.setResult(list);
return result;
}
/**
* <pre>
* 添加
* </pre>
* @param reportTargetConfigSub
* @return
* @author 开发者姓名, 开发时间
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@AutoLog(value = "经营目标拆分-添加")
@ApiOperation(value="经营目标拆分-添加", notes="经营目标拆分-添加")
@PostMapping(value = "/add")
public Result<ReportTargetConfigSub> add(@RequestBody ReportTargetConfigSub reportTargetConfigSub) {
Result<ReportTargetConfigSub> result = new Result<ReportTargetConfigSub>();
try {
reportTargetConfigSubService.save(reportTargetConfigSub);
result.success("添加成功!");
} catch (Exception e) {
log.error(e.getMessage(),e);
result.error500("操作失败");
}
return result;
}
/**
* <pre>
* 编辑
* </pre>
* @param reportTargetConfigSub
* @return
* @author 开发者姓名, 开发时间
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@AutoLog(value = "经营目标拆分-编辑")
@ApiOperation(value="经营目标拆分-编辑", notes="经营目标拆分-编辑")
@PutMapping(value = "/edit")
public Result<ReportTargetConfigSub> edit(@RequestBody ReportTargetConfigSub reportTargetConfigSub) {
Result<ReportTargetConfigSub> result = new Result<ReportTargetConfigSub>();
ReportTargetConfigSub reportTargetConfigSubEntity = reportTargetConfigSubService.getById(reportTargetConfigSub.getId());
if(reportTargetConfigSubEntity==null) {
result.error500("未找到对应实体");
}else {
boolean ok = reportTargetConfigSubService.updateById(reportTargetConfigSub);
//TODO 返回false说明什么?
if(ok) {
result.success("修改成功!");
}
}
return result;
}
/**
* <pre>
* 通过id删除
* </pre>
* @param id
* @return
* @author 开发者姓名, 开发时间
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@AutoLog(value = "经营目标拆分-通过id删除")
@ApiOperation(value="经营目标拆分-通过id删除", notes="经营目标拆分-通过id删除")
@DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name="id",required=true) String id) {
try {
reportTargetConfigSubService.removeById(id);
} catch (Exception e) {
log.error("删除失败",e.getMessage());
return Result.error("删除失败!");
}
return Result.ok("删除成功!");
}
/**
* <pre>
* 批量删除
* </pre>
* @param ids
* @return
* @author 开发者姓名, 开发时间
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@AutoLog(value = "经营目标拆分-批量删除")
@ApiOperation(value="经营目标拆分-批量删除", notes="经营目标拆分-批量删除")
@DeleteMapping(value = "/deleteBatch")
public Result<ReportTargetConfigSub> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
Result<ReportTargetConfigSub> result = new Result<ReportTargetConfigSub>();
if(ids==null || "".equals(ids.trim())) {
result.error500("参数不识别!");
}else {
this.reportTargetConfigSubService.removeByIds(Arrays.asList(ids.split(",")));
result.success("删除成功!");
}
return result;
}
/**
* <pre>
* 通过id查询
* </pre>
* @param id
* @return
* @author 开发者姓名, 开发时间
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@AutoLog(value = "经营目标拆分-通过id查询")
@ApiOperation(value="经营目标拆分-通过id查询", notes="经营目标拆分-通过id查询")
@GetMapping(value = "/queryById")
public Result<ReportTargetConfigSub> queryById(@RequestParam(name="id",required=true) String id) {
Result<ReportTargetConfigSub> result = new Result<ReportTargetConfigSub>();
ReportTargetConfigSub reportTargetConfigSub = reportTargetConfigSubService.getById(id);
if(reportTargetConfigSub==null) {
result.error500("未找到对应实体");
}else {
result.setResult(reportTargetConfigSub);
result.setSuccess(true);
}
return result;
}
/**
* <pre>
* 导出excel
* </pre>
* @param request
* @param response
* @return
* @author 开发者姓名, 开发时间
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
// Step.1 组装查询条件
QueryWrapper<ReportTargetConfigSub> queryWrapper = null;
try {
String paramsStr = request.getParameter("paramsStr");
if (ConvertUtils.isNotEmpty(paramsStr)) {
String deString = URLDecoder.decode(paramsStr, "UTF-8");
ReportTargetConfigSub reportTargetConfigSub = JSON.parseObject(deString, ReportTargetConfigSub.class);
queryWrapper = QueryGenerator.initQueryWrapper(reportTargetConfigSub, request.getParameterMap());
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
//Step.2 AutoPoi 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
List<ReportTargetConfigSub> pageList = reportTargetConfigSubService.list(queryWrapper);
//导出文件名称
mv.addObject(NormalExcelConstants.FILE_NAME, "经营目标拆分列表");
mv.addObject(NormalExcelConstants.CLASS, ReportTargetConfigSub.class);
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("经营目标拆分列表数据", "导出人:Jeecg", "导出信息"));
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
return mv;
}
/**
* <pre>
* 通过excel导入数据
* </pre>
* @param request
* @param response
* @return
* @author 开发者姓名, 开发时间
* @Description: TODO(这里描述这个方法的需求变更情况)
*/
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
ImportParams params = new ImportParams();
params.setTitleRows(2);
params.setHeadRows(1);
params.setNeedSave(true);
try {
List<ReportTargetConfigSub> listReportTargetConfigSubs = ExcelImportUtil.importExcel(file.getInputStream(), ReportTargetConfigSub.class, params);
reportTargetConfigSubService.saveBatch(listReportTargetConfigSubs);
return Result.ok("文件导入成功!数据行数:" + listReportTargetConfigSubs.size());
} catch (Exception e) {
log.error(e.getMessage(),e);
return Result.error("文件导入失败:"+e.getMessage());
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.ok("文件导入失败!");
}
@AutoLog(value = "报表批量添加拆分目标")
@ApiOperation(value = "报表批量添加拆分目标", notes = "报表批量添加拆分目标")
@PostMapping(value = "/batchSave")
public Result batchSave(@RequestBody List<Map<String, String>> dataList) {
List<ReportTargetConfigSub> reportTargetConfigSubList = new ArrayList<>();
String departId = ConvertUtils.getString(dataList.get(0).get("departId"));
String dataType = ConvertUtils.getString(dataList.get(0).get("dataType"));
String year = ConvertUtils.getString(dataList.get(0).get("dataTime")).split("-")[0];
for (Map<String, String> data : dataList) {
ReportTargetConfigSub reportTargetConfigSub = new ReportTargetConfigSub();
reportTargetConfigSub.setTargetTime(ConvertUtils.getString(data.get("dataTime")));
reportTargetConfigSub.setDepartId(ConvertUtils.getString(data.get("departId")));
reportTargetConfigSub.setTargetType(ConvertUtils.getString(data.get("dataType")));
reportTargetConfigSub.setTargetValue(ConvertUtils.getString(data.get("dataValue")));
reportTargetConfigSubList.add(reportTargetConfigSub);
}
boolean ok = reportTargetConfigSubService.batchDeleteData(departId,year,dataType);
if(ok){
reportTargetConfigSubService.saveBatch(reportTargetConfigSubList);
}
return Result.ok("批量添加成功");
}
}
......@@ -36,6 +36,10 @@ public class ReportTargetConfig {
@Excel(name = "水量目标", width = 15)
@ApiModelProperty(value = "水量目标")
private String targetWater;
/**费用目标*/
@Excel(name = "费用目标", width = 15)
@ApiModelProperty(value = "费用目标")
private String targetCost;
/**电量目标*/
@Excel(name = "电量目标", width = 15)
@ApiModelProperty(value = "电量目标")
......
package com.skua.modules.report.entity;
import java.io.Serializable;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
/**
* 经营目标拆分
*/
@Data
@TableName("report_target_config_sub")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="report_target_config_sub对象", description="经营目标拆分")
public class ReportTargetConfigSub {
/**主键id*/
@TableId(type = IdType.ID_WORKER_STR)
@ApiModelProperty(value = "主键id")
private String id;
/**所属厂区*/
@Excel(name = "所属厂区", width = 15)
@ApiModelProperty(value = "所属厂区")
private String departId;
/**目标时间*/
@Excel(name = "目标时间", width = 15)
@ApiModelProperty(value = "目标时间")
private String targetTime;
/**目标类型*/
@Excel(name = "目标类型", width = 15)
@ApiModelProperty(value = "目标类型")
private String targetType;
/**目标值*/
@Excel(name = "目标值", width = 15)
@ApiModelProperty(value = "目标值")
private String targetValue;
/**创建人Id*/
@Excel(name = "创建人Id", width = 15)
@ApiModelProperty(value = "创建人Id")
private String createBy;
/**创建时间*/
@Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间")
private Date createTime;
/**修改人Id*/
@Excel(name = "修改人Id", width = 15)
@ApiModelProperty(value = "修改人Id")
private String updateBy;
/**修改时间*/
@Excel(name = "修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "修改时间")
private Date updateTime;
/**删除标识*/
@Excel(name = "删除标识", width = 15)
@ApiModelProperty(value = "删除标识")
private Integer delFlag;
}
package com.skua.modules.report.mapper;
import com.skua.tool.annotation.Anonymous;
import org.apache.ibatis.annotations.Param;
import com.skua.modules.report.entity.ReportTargetConfigSub;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
/**
* 经营目标拆分
*/
public interface ReportTargetConfigSubMapper extends BaseMapper<ReportTargetConfigSub> {
void batchDeleteData(@Param("departId") String departId, @Param("year") String year, @Param("type") String type);
@Anonymous
List<ReportTargetConfigSub> getList(@Param("departId") String departId, @Param("year") String year, @Param("targetType") String targetType);
}
<?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.skua.modules.report.mapper.ReportTargetConfigSubMapper">
<delete id="batchDeleteData">
DELETE FROM report_target_config_sub
WHERE depart_id = #{departId} AND target_type = #{type} AND target_time like concat(#{year},'%')
</delete>
<select id="getList" resultType="com.skua.modules.report.entity.ReportTargetConfigSub">
SELECT * FROM report_target_config_sub
WHERE depart_id = #{departId} AND target_type = #{targetType} AND target_time like concat(#{year},'%')
</select>
</mapper>
package com.skua.modules.report.service;
import com.skua.modules.report.entity.ReportTargetConfigSub;
import com.baomidou.mybatisplus.extension.service.IService;
import com.skua.tool.annotation.Anonymous;
import java.util.List;
/**
* 经营目标拆分
*/
public interface IReportTargetConfigSubService extends IService<ReportTargetConfigSub> {
boolean batchDeleteData(String departId, String year, String type);
List<ReportTargetConfigSub> getList(ReportTargetConfigSub reportTargetConfigSub);
}
package com.skua.modules.report.service.impl;
import com.skua.modules.report.entity.ReportTargetConfigSub;
import com.skua.modules.report.mapper.ReportTargetConfigSubMapper;
import com.skua.modules.report.service.IReportTargetConfigSubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Collections;
import java.util.List;
/**
* 经营目标拆分
*/
@Service
public class ReportTargetConfigSubServiceImpl extends ServiceImpl<ReportTargetConfigSubMapper, ReportTargetConfigSub> implements IReportTargetConfigSubService {
@Autowired
ReportTargetConfigSubMapper reportTargetSubMapper;
@Override
public boolean batchDeleteData(String departId, String year, String type) {
reportTargetSubMapper.batchDeleteData(departId,year,type);
return true;
}
@Override
public List<ReportTargetConfigSub> getList(ReportTargetConfigSub reportTargetConfigSub) {
return reportTargetSubMapper.getList(reportTargetConfigSub.getDepartId(), reportTargetConfigSub.getTargetTime(),
reportTargetConfigSub.getTargetType());
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!