package com.gkhy.safePlatform.targetDuty.controller;
|
import java.io.IOException;
|
import java.net.URLEncoder;
|
import java.util.*;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
|
import com.gkhy.safePlatform.targetDuty.entity.TargetDutySummary;
|
import com.gkhy.safePlatform.targetDuty.entity.TargetMng;
|
import com.gkhy.safePlatform.targetDuty.model.dto.resp.TargetDutySummaryExcel;
|
import com.gkhy.safePlatform.targetDuty.service.TargetDutySummaryService;
|
import com.gkhy.safePlatform.targetDuty.utils.DateUtils;
|
import com.gkhy.safePlatform.targetDuty.utils.poihelper.ExcelUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
import com.gkhy.safePlatform.commons.query.PageQuery;
|
import com.gkhy.safePlatform.commons.utils.PageUtils;
|
import com.gkhy.safePlatform.commons.vo.ResultVO;
|
import com.gkhy.safePlatform.commons.enums.ResultCodes;
|
import com.gkhy.safePlatform.targetDuty.model.dto.req.TargetDutySummaryQueryCriteria;
|
|
import java.sql.Timestamp;
|
import java.util.stream.Collectors;
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.Serializable;
|
|
/**
|
* (TargetDutySummary)表控制层
|
*
|
* @author xurui
|
* @since 2022-07-21 15:35:14
|
*/
|
@RestController
|
@RequestMapping("targetDutySummary")
|
public class TargetDutySummaryController {
|
/**
|
* 服务对象
|
*/
|
@Resource
|
private TargetDutySummaryService targetDutySummaryService;
|
|
@Autowired
|
public HttpServletRequest request;
|
|
@Autowired
|
public HttpServletResponse response;
|
|
/**
|
* 分页查询所有数据
|
*
|
* @param pageQuery 查询实体
|
* @return 所有数据
|
*/
|
@PostMapping(value = "/page/list")
|
public ResultVO selectAll(@RequestBody PageQuery<TargetDutySummaryQueryCriteria> pageQuery){
|
PageUtils.checkCheck(pageQuery);
|
return this.targetDutySummaryService.queryAll(pageQuery);
|
}
|
|
|
/**
|
* 通过主键查询单条数据
|
*
|
* @param id 主键
|
* @return 单条数据
|
*/
|
@GetMapping(value = "/selectOne/{id}")
|
public ResultVO selectOne(@PathVariable Serializable id) {
|
return new ResultVO<>(ResultCodes.OK,this.targetDutySummaryService.getById(id));
|
}
|
|
/**
|
* 新增或者修改数据
|
*
|
* @param targetDutySummary 实体对象
|
* @return 修改结果
|
*/
|
@PostMapping(value = "/addOrUpdate")
|
public ResultVO update(@RequestBody TargetDutySummary targetDutySummary) {
|
if (targetDutySummary.getId() == null) {
|
return new ResultVO<>(ResultCodes.OK,targetDutySummaryService.save(targetDutySummary));
|
} else {
|
targetDutySummaryService.update(targetDutySummary,new UpdateWrapper<TargetDutySummary>().eq("id",targetDutySummary.getId()));
|
return new ResultVO<>(ResultCodes.OK);
|
}
|
}
|
|
/**
|
* 删除数据
|
*
|
* @param ids 主键结合
|
* @return 删除结果
|
*/
|
@RequestMapping(value = "/delete",method = RequestMethod.POST)
|
public ResultVO delete(@RequestBody Long[] ids) {
|
if(ids == null){
|
return new ResultVO<>(ResultCodes.CLIENT_PARAM_ILLEGAL);
|
}
|
List<Long> idList = Arrays.asList(ids);
|
this.targetDutySummaryService.removeByIds(idList);
|
return new ResultVO<>(ResultCodes.OK);
|
}
|
|
/**
|
* 导出一览数据
|
*
|
*/
|
@GetMapping(value = "/exportData")
|
public void exportData(TargetDutySummaryQueryCriteria queryCriteria) throws IOException {
|
Map<String,String> map = new LinkedHashMap<>();
|
map.put("1","责任部门");
|
map.put("2","安全目标指标");
|
map.put("3","考核指标");
|
map.put("4","1月");
|
map.put("5","2月");
|
map.put("6","3月");
|
map.put("7","4月");
|
map.put("8","5月");
|
map.put("9","6月");
|
map.put("10","7月");
|
map.put("11","8月");
|
map.put("12","9月");
|
map.put("13","10月");
|
map.put("14","11月");
|
map.put("15","12月");
|
map.put("16","考核结果");
|
|
String key = DateUtils.date2String(new Date(), DateUtils.PATTERN_ALLTIME_NOSIGN) ;
|
String fileName = URLEncoder.encode("目标汇总"+key+".xls", "UTF-8");
|
response.setContentType("application/vnd.ms-excel");
|
response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
|
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
List<TargetDutySummaryExcel> respList = BeanCopyUtils.copyBeanList(targetDutySummaryService.queryAll(queryCriteria), TargetDutySummaryExcel.class);
|
|
ExcelUtil.exportExcel(map,respList , response.getOutputStream(),DateUtils.PATTERN_STANDARD);
|
response.getOutputStream().close();
|
}
|
|
public static void main(String[] args) {
|
TargetDutySummary mng = new TargetDutySummary();
|
mng.setYear("2020");
|
mng.setDepartmentId(1L);
|
mng.setTargetValue("1");
|
mng.setExamineValue("2");
|
mng.setExamineResult(1);
|
|
mng.setYiYue("1");
|
mng.setErYue("3");
|
mng.setSanYue("4");
|
mng.setSiYue("5");
|
mng.setWuYue("6");
|
mng.setLiuYue("7");
|
mng.setQiYue("8");
|
mng.setBaYue("9");
|
mng.setJiuYue("10");
|
mng.setShiYue("11");
|
mng.setShiyiYue("12");
|
mng.setShierYue("13");
|
|
System.out.println(JSONObject.toJSONString(mng));
|
|
}
|
}
|