113 lines
4.8 KiB
Plaintext
113 lines
4.8 KiB
Plaintext
package com.sercurityControl.proteam.dutyTask.controller;
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.securityControl.common.core.utils.StringUtils;
|
|
import com.securityControl.common.core.utils.aes.DateTimeHelper;
|
|
import com.securityControl.common.log.annotation.Log;
|
|
import com.securityControl.common.log.enums.BusinessType;
|
|
import com.securityControl.common.log.enums.OperationType;
|
|
import com.sercurityControl.proteam.dutyTask.domain.DutyStatisticsEntity;
|
|
import com.sercurityControl.proteam.dutyTask.service.DutyStatisticsService;
|
|
import com.sercurityControl.proteam.util.ExcelStyleUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.ServletOutputStream;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.net.URLEncoder;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 值班统计
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/pot/dutyStatistics/")
|
|
@Slf4j
|
|
public class DutyStatisticsController {
|
|
|
|
@Resource(name = "DutyStatisticsService")
|
|
private DutyStatisticsService service;
|
|
|
|
Logger logger = LoggerFactory.getLogger(TodayTaskController.class);
|
|
|
|
@PostMapping(value = "getDutyStatisticsList")
|
|
@Log(title = "值班统计", menu = "值班任务->值班统计", businessType = BusinessType.QUERY, details = "值班统计列表")
|
|
public Map<String, Object> getDutyStatisticsList(DutyStatisticsEntity entity) {
|
|
if (StringUtils.isBlank(entity.getCreateTime())) {
|
|
entity.setCreateTime(DateTimeHelper.getNowDate());
|
|
}
|
|
PageHelper.startPage(Integer.parseInt(entity.getPage()), Integer.parseInt(entity.getLimit()));
|
|
Map<String, Object> map = new HashMap<String, Object>(16);
|
|
try {
|
|
PageInfo<DutyStatisticsEntity> pageInfo = service.getDutyStatisticsList(entity);
|
|
map.put("code", 200);
|
|
map.put("msg", "获取数据成功");
|
|
map.put("count", pageInfo.getTotal());
|
|
map.put("curr", Integer.parseInt(entity.getPage()));
|
|
map.put("limit", Integer.parseInt(entity.getLimit()));
|
|
map.put("data", pageInfo.getList());
|
|
} catch (Exception e) {
|
|
map.put("code", 500);
|
|
map.put("msg", "获取数据失败");
|
|
map.put("count", 0);
|
|
map.put("curr", Integer.parseInt(entity.getPage()));
|
|
map.put("limit", Integer.parseInt(entity.getLimit()));
|
|
map.put("data", null);
|
|
logger.error("数据获取失败", e);
|
|
}
|
|
return map;
|
|
}
|
|
|
|
|
|
/**
|
|
* @return void
|
|
* @author cw chen
|
|
* @description 导出值班统计
|
|
* @Param request
|
|
* @Param response
|
|
* @Param params
|
|
* @date 2022-12-21 16:58
|
|
*/
|
|
@GetMapping("exportData")
|
|
@Log(title = "值班统计", menu = "值班任务->值班统计", businessType = BusinessType.EXPORT, details = "值班统计导出", grade = OperationType.EXPORT_BUSINESS)
|
|
public void exportData(HttpServletRequest request, HttpServletResponse response, DutyStatisticsEntity entity) {
|
|
if (StringUtils.isBlank(entity.getCreateTime())) {
|
|
entity.setCreateTime(DateTimeHelper.getNowDate());
|
|
}
|
|
PageHelper.startPage(1, 10000000);
|
|
List<DutyStatisticsEntity> list = new ArrayList<>();
|
|
try {
|
|
PageInfo<DutyStatisticsEntity> pageInfo = service.getDutyStatisticsList(entity);
|
|
list = pageInfo.getList();
|
|
for (int i = 0; i < list.size(); i++) {
|
|
list.get(i).setId((i + 1) + "");
|
|
}
|
|
ExportParams exportParams = new ExportParams("值班统计", "值班统计", ExcelType.XSSF);
|
|
exportParams.setStyle(ExcelStyleUtil.class);
|
|
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, DutyStatisticsEntity.class, list);
|
|
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode("值班统计" + ".xlsx", "UTF-8"));
|
|
ServletOutputStream outputStream = response.getOutputStream();
|
|
workbook.write(outputStream);
|
|
outputStream.close();
|
|
workbook.close();
|
|
} catch (Exception e) {
|
|
logger.error("导出值班统计", e);
|
|
}
|
|
}
|
|
}
|