|
@ -2,44 +2,48 @@ package com.epmet.dataaggre.controller; |
|
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
import com.alibaba.excel.EasyExcel; |
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
import com.alibaba.excel.annotation.ExcelProperty; |
|
|
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
import com.epmet.commons.tools.annotation.LoginUser; |
|
|
import com.epmet.commons.tools.annotation.LoginUser; |
|
|
import com.epmet.commons.tools.annotation.RequirePermission; |
|
|
import com.epmet.commons.tools.annotation.RequirePermission; |
|
|
import com.epmet.commons.tools.enums.RequirePermissionEnum; |
|
|
import com.epmet.commons.tools.enums.RequirePermissionEnum; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.security.user.LoginUserUtil; |
|
|
import com.epmet.commons.tools.security.user.LoginUserUtil; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
|
|
import com.epmet.commons.tools.utils.ExcelUtils; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
import com.epmet.dataaggre.dto.govorg.CustomerAgencyDTO; |
|
|
import com.epmet.dataaggre.beans.GridMemberDataAnalysisExcelExportBean; |
|
|
import com.epmet.dataaggre.dto.govorg.CustomerGridDTO; |
|
|
import com.epmet.dataaggre.dto.govorg.CustomerGridDTO; |
|
|
import com.epmet.dataaggre.dto.govorg.form.*; |
|
|
import com.epmet.dataaggre.dto.govorg.form.*; |
|
|
import com.epmet.dataaggre.dto.govorg.result.*; |
|
|
import com.epmet.dataaggre.dto.govorg.result.*; |
|
|
import com.epmet.dataaggre.entity.govorg.CustomerAgencyEntity; |
|
|
import com.epmet.dataaggre.entity.govorg.CustomerAgencyEntity; |
|
|
import com.epmet.dataaggre.entity.govorg.CustomerGridEntity; |
|
|
|
|
|
import com.epmet.dataaggre.enums.GridMemberDataAnalysisEnums; |
|
|
import com.epmet.dataaggre.enums.GridMemberDataAnalysisEnums; |
|
|
import com.epmet.dataaggre.service.AggreGridService; |
|
|
import com.epmet.dataaggre.service.AggreGridService; |
|
|
import com.epmet.dataaggre.service.govorg.GovOrgService; |
|
|
import com.epmet.dataaggre.service.govorg.GovOrgService; |
|
|
import lombok.Data; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.http.HttpStatus; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
import javax.validation.constraints.NotBlank; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
import java.io.FileInputStream; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
|
|
|
import java.net.URLEncoder; |
|
|
import java.nio.file.Files; |
|
|
import java.nio.file.Files; |
|
|
import java.nio.file.Path; |
|
|
import java.nio.file.Path; |
|
|
import java.nio.file.Paths; |
|
|
import java.nio.file.Paths; |
|
|
import java.util.ArrayList; |
|
|
import java.text.SimpleDateFormat; |
|
|
import java.util.Date; |
|
|
import java.util.*; |
|
|
import java.util.List; |
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @Author zxc |
|
|
* @Author zxc |
|
@ -244,13 +248,14 @@ public class GovOrgController { |
|
|
public Result getGridMemberAnalysis4PcWork(@RequestBody GridMemberDataAnalysisFromDTO input) { |
|
|
public Result getGridMemberAnalysis4PcWork(@RequestBody GridMemberDataAnalysisFromDTO input) { |
|
|
ValidatorUtils.validateEntity(input, GridMemberDataAnalysisFromDTO.listGridMemberDatas4PcWork.class); |
|
|
ValidatorUtils.validateEntity(input, GridMemberDataAnalysisFromDTO.listGridMemberDatas4PcWork.class); |
|
|
|
|
|
|
|
|
String agencyId = input.getAgencyId(); |
|
|
String orgId = input.getOrgId(); |
|
|
Date startTime = input.getStartTime(); |
|
|
Date startTime = input.getStartTime(); |
|
|
Date endTime = input.getEndTime(); |
|
|
Date endTime = input.getEndTime(); |
|
|
Integer pageNo = input.getPageNo(); |
|
|
Integer pageNo = input.getPageNo(); |
|
|
Integer pageSize = input.getPageSize(); |
|
|
Integer pageSize = input.getPageSize(); |
|
|
|
|
|
String orgType = input.getOrgType(); |
|
|
|
|
|
|
|
|
PageData<GridMemberDataAnalysisResultDTO> page = aggreGridService.getGridMemberDataAnalysis4PcWork(agencyId, pageNo, pageSize, startTime, endTime); |
|
|
PageData<GridMemberDataAnalysisResultDTO> page = aggreGridService.getGridMemberDataAnalysis4PcWork(orgId, orgType, pageNo, pageSize, startTime, endTime, true); |
|
|
return new Result().ok(page); |
|
|
return new Result().ok(page); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -260,80 +265,96 @@ public class GovOrgController { |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
@PostMapping("pcwork/gridmember-analysis/export") |
|
|
@PostMapping("pcwork/gridmember-analysis/export") |
|
|
public Result exportGridMemberAnalysis4PcWork(@RequestBody GridMemberDataAnalysisFromDTO input) { |
|
|
public void exportGridMemberAnalysis4PcWork(@RequestBody GridMemberDataAnalysisFromDTO input, HttpServletResponse response) { |
|
|
ValidatorUtils.validateEntity(input, GridMemberDataAnalysisFromDTO.listGridMemberDatas4PcWork.class); |
|
|
ValidatorUtils.validateEntity(input, GridMemberDataAnalysisFromDTO.listGridMemberDatas4PcWork.class); |
|
|
|
|
|
|
|
|
String agencyId = input.getAgencyId(); |
|
|
String orgId = input.getOrgId(); |
|
|
Date startTime = input.getStartTime(); |
|
|
Date startTime = input.getStartTime(); |
|
|
Date endTime = input.getEndTime(); |
|
|
Date endTime = input.getEndTime(); |
|
|
|
|
|
String orgType = input.getOrgType(); |
|
|
|
|
|
|
|
|
int pageNo = 0; |
|
|
// 缓存路径
|
|
|
int pageSize = 1000; |
|
|
|
|
|
|
|
|
|
|
|
String tempFileName = UUID.randomUUID().toString().concat(".xlsx"); |
|
|
String tempFileName = UUID.randomUUID().toString().concat(".xlsx"); |
|
|
|
|
|
Path tempFilePath = gridMemberStatsExcelExportDir.resolve(tempFileName); |
|
|
|
|
|
log.info("工作统计excel文件下载路径:{}", tempFilePath.toString()); |
|
|
|
|
|
|
|
|
ExcelWriter excelWriter = EasyExcel.write(tempFileName, GridMemberDataAnalysisExcelExportBean.class).build(); |
|
|
ExcelWriter excelWriter = null; |
|
|
// 这里注意 如果同一个sheet只要创建一次
|
|
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet("模板").build(); |
|
|
|
|
|
|
|
|
|
|
|
PageData<GridMemberDataAnalysisResultDTO> page; |
|
|
|
|
|
do { |
|
|
|
|
|
page = aggreGridService.getGridMemberDataAnalysis4PcWork(agencyId, pageNo, pageSize, startTime, endTime); |
|
|
|
|
|
List<GridMemberDataAnalysisResultDTO> pageList = page.getList(); |
|
|
|
|
|
|
|
|
|
|
|
List<GridMemberDataAnalysisExcelExportBean> exportBeans = ConvertUtils.sourceToTarget(pageList, GridMemberDataAnalysisExcelExportBean.class); |
|
|
|
|
|
|
|
|
|
|
|
excelWriter.write(exportBeans, writeSheet); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} while (page.getList().size() == pageSize); |
|
|
// 组织名称
|
|
|
|
|
|
AtomicReference<String> orgName = new AtomicReference<>(""); |
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 网格员数据分析excel导出bean |
|
|
|
|
|
*/ |
|
|
|
|
|
@Data |
|
|
|
|
|
public class GridMemberDataAnalysisExcelExportBean { |
|
|
|
|
|
@ExcelProperty("姓名") |
|
|
|
|
|
private String staffName; |
|
|
|
|
|
|
|
|
|
|
|
@ExcelProperty("手机号") |
|
|
if ("grid".equals(orgType)) { |
|
|
private String mobile; |
|
|
CustomerGridDTO gridInfo = govOrgService.getGridInfo(orgId); |
|
|
|
|
|
Optional.ofNullable(gridInfo).ifPresent((g) -> orgName.set(g.getGridName())); |
|
|
|
|
|
} else if ("agency".equals(orgType)) { |
|
|
|
|
|
CustomerAgencyEntity agencyInfo = govOrgService.getAgencyInfo(orgId); |
|
|
|
|
|
Optional.ofNullable(agencyInfo).ifPresent((a) -> orgName.set(a.getOrganizationName())); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ExcelProperty("所属网格") |
|
|
// sheet名
|
|
|
private String orgName; |
|
|
String sheetName = getSheetName(orgName.get(), startTime, endTime); |
|
|
|
|
|
|
|
|
// 项目议题等
|
|
|
// 分页导出到缓存excel
|
|
|
@ExcelProperty("项目数") |
|
|
try { |
|
|
private Integer projectCount; |
|
|
excelWriter = EasyExcel.write(tempFilePath.toString(), GridMemberDataAnalysisExcelExportBean.class).build(); |
|
|
|
|
|
// 这里注意 如果同一个sheet只要创建一次
|
|
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet(sheetName).build(); |
|
|
|
|
|
|
|
|
@ExcelProperty("议题转项目数") |
|
|
PageData<GridMemberDataAnalysisResultDTO> page; |
|
|
private Integer issueToProjectCount; |
|
|
|
|
|
|
|
|
|
|
|
@ExcelProperty("议题关闭数") |
|
|
int pageNo = 0; |
|
|
private Integer closedIssueCount; |
|
|
int pageSize = 1000; |
|
|
|
|
|
|
|
|
@ExcelProperty("项目事件响应数") |
|
|
do { |
|
|
private Integer projectResponseCount; |
|
|
page = aggreGridService.getGridMemberDataAnalysis4PcWork(orgId, orgType, pageNo, pageSize, startTime, endTime, false); |
|
|
|
|
|
List<GridMemberDataAnalysisResultDTO> pageList = page.getList(); |
|
|
|
|
|
|
|
|
@ExcelProperty("项目事件吹哨数") |
|
|
List<GridMemberDataAnalysisExcelExportBean> exportBeans = ConvertUtils.sourceToTarget(pageList, GridMemberDataAnalysisExcelExportBean.class); |
|
|
private Integer projectTransferCount; |
|
|
|
|
|
|
|
|
|
|
|
@ExcelProperty("项目事件结案数") |
|
|
excelWriter.write(exportBeans, writeSheet); |
|
|
private Integer projectClosedCount; |
|
|
|
|
|
|
|
|
|
|
|
// 巡查
|
|
|
} while (page.getList().size() == pageSize); |
|
|
@ExcelProperty("巡查次数") |
|
|
|
|
|
private int patrolTimes; |
|
|
|
|
|
|
|
|
|
|
|
@ExcelProperty("巡查时长") |
|
|
} catch (Exception e) { |
|
|
private int totalTime; |
|
|
e.printStackTrace(); |
|
|
|
|
|
log.error("【PC工作端网格员数据统计导出】生成excel失败:{}", ExceptionUtils.getErrorStackTrace(e)); |
|
|
|
|
|
} finally { |
|
|
|
|
|
// 关闭流
|
|
|
|
|
|
Optional.ofNullable(excelWriter).ifPresent((i) -> i.finish()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ExcelProperty("例行工作次数") |
|
|
// 开始下载缓存excel到客户端,然后删除缓存文件
|
|
|
private int patrolRoutineWorkTimes; |
|
|
try { |
|
|
|
|
|
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); |
|
|
|
|
|
response.setHeader("Content-Type", "application/vnd.ms-excel"); |
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(sheetName.concat(".xlsx"), "UTF-8")); |
|
|
|
|
|
|
|
|
|
|
|
IOUtils.copy(new FileInputStream(tempFilePath.toString()), response.getOutputStream()); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error(ExceptionUtils.getErrorStackTrace(e)); |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), "【下载工作统计信息】下载失败"); |
|
|
|
|
|
} finally { |
|
|
|
|
|
try { |
|
|
|
|
|
Files.delete(tempFilePath); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
log.error(ExceptionUtils.getErrorStackTrace(e)); |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), "【下载工作统计信息】删除缓存文件失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getSheetName(String orgName, Date startTime, Date endTime) { |
|
|
|
|
|
StringBuilder sb = new StringBuilder(orgName); |
|
|
|
|
|
String s = orgName; |
|
|
|
|
|
if (startTime == null && endTime != null) { |
|
|
|
|
|
sb.append("截止").append(DateUtils.format(endTime, DateUtils.DATE_PATTERN)); |
|
|
|
|
|
} else if (startTime != null && endTime != null) { |
|
|
|
|
|
sb.append(DateUtils.format(startTime, DateUtils.DATE_PATTERN)) |
|
|
|
|
|
.append("至") |
|
|
|
|
|
.append(DateUtils.format(endTime, DateUtils.DATE_PATTERN)) |
|
|
|
|
|
.append("区间新增值"); |
|
|
|
|
|
} |
|
|
|
|
|
sb.append("的工作统计"); |
|
|
|
|
|
return sb.toString(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|