|
|
@ -2,9 +2,7 @@ package com.epmet.dataaggre.service.govorg.impl; |
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil; |
|
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams; |
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
|
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.dingtalk.api.request.OapiRobotSendRequest; |
|
|
|
import com.epmet.commons.dynamic.datasource.annotation.DataSource; |
|
|
@ -16,10 +14,11 @@ import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.ExcelUtils; |
|
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dataaggre.constant.DataSourceConstant; |
|
|
@ -31,6 +30,7 @@ import com.epmet.dataaggre.dto.govorg.form.*; |
|
|
|
import com.epmet.dataaggre.dto.govorg.result.*; |
|
|
|
import com.epmet.dataaggre.dto.resigroup.result.OrgInfoCommonDTO; |
|
|
|
import com.epmet.dataaggre.entity.govorg.CustomerAgencyEntity; |
|
|
|
import com.epmet.dataaggre.excel.GridLivelyDetailExcel; |
|
|
|
import com.epmet.dataaggre.excel.GridLivelyExcel; |
|
|
|
import com.epmet.dataaggre.service.commonservice.AreaCodeService; |
|
|
|
import com.epmet.dataaggre.service.datastats.DataStatsService; |
|
|
@ -51,6 +51,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile; |
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.OutputStream; |
|
|
@ -677,13 +678,131 @@ public class GovOrgServiceImpl implements GovOrgService { |
|
|
|
return subList; |
|
|
|
} |
|
|
|
|
|
|
|
private GridLivelyDetailExcel gridActiveList(GridLivelyFormDTO formDTO) { |
|
|
|
GridLivelyDetailExcel result = new GridLivelyDetailExcel(); |
|
|
|
LinkedList<GridLivelyExcel> livelyExcelList = new LinkedList<>(); |
|
|
|
List<GridLivelyDetailExcel.LivelyGrid> livelyGrid = new ArrayList<>(); |
|
|
|
List<GridLivelyDetailExcel.OrdinaryGrid> ordinaryGrid = new ArrayList<>(); |
|
|
|
List<GridLivelyDetailExcel.LazyGrid> lazyGrid = new ArrayList<>(); |
|
|
|
//用于存放存在例行工作或上报事件的网格Id,供后边寻找活跃度为0的僵尸网格使用
|
|
|
|
Set<String> gridSet = new HashSet<>(); |
|
|
|
//0.查询当前组织的直属下级组织列表及组织下的网格总数
|
|
|
|
LinkedList<GridLivelyResultDTO> subList = customerAgencyDao.subAgencyListAndGridSumNum(formDTO.getAgencyId()); |
|
|
|
//1.查询当前组织下所有网格列表
|
|
|
|
List<GridInfoResultDTO> gridList = customerGridDao.selectAgencyGridList(formDTO.getAgencyId()); |
|
|
|
Map<String, GridInfoResultDTO> gridMap = gridList.stream().collect(Collectors.toMap(GridInfoResultDTO :: getGridId, v -> v, (v1, v2) -> v1)); |
|
|
|
//2.查询直属下级组织下网格在查询时间段内存在例行工作次数的网格,一天一条
|
|
|
|
List<GridDateIdResultDTO> workList = epmetUserService.getGridDateRoutineWorkList(formDTO); |
|
|
|
//3.查询直属下级组织下网格在查询时间段内存在上报事件(直接立项)数的网格,一天一条
|
|
|
|
List<GridDateIdResultDTO> projectList = dataStatsService.getGridDateProjectIncrList(formDTO); |
|
|
|
//4.汇总数据,一个网格一天只记录一条数据,这条数据可能是例行工作的也可能是上报事件的,也可能某一天两个数都有,但只记录一条
|
|
|
|
Set<String> map = workList.stream().map(o -> o.getGridId() + o.getDateId()).collect(Collectors.toSet()); |
|
|
|
projectList.stream().filter(pro -> !map.contains(pro.getGridId() + pro.getDateId())).forEach(p -> workList.add(p)); |
|
|
|
//5.按组织封装数据
|
|
|
|
//计算百分比使用,保留小数点后两位
|
|
|
|
NumberFormat numberFormat = NumberFormat.getInstance(); |
|
|
|
numberFormat.setMaximumFractionDigits(NumConstant.TWO); |
|
|
|
subList.forEach(sub -> { |
|
|
|
//5-1.组装存在活跃度的数据【网格活跃天数大于0的】
|
|
|
|
Map<String, Integer> hash = new HashMap<>(); |
|
|
|
workList.forEach(w -> { |
|
|
|
if (w.getPids().contains(sub.getAgencyId())) { |
|
|
|
if (hash.containsKey(w.getGridId())) { |
|
|
|
hash.put(w.getGridId(), hash.get(w.getGridId()) + NumConstant.ONE); |
|
|
|
} else { |
|
|
|
hash.put(w.getGridId(), NumConstant.ONE); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
//活跃网格数、普通网格数、僵尸网格数
|
|
|
|
int gridLivelyNum = 0; |
|
|
|
int gridOrdinaryNum = 0; |
|
|
|
for (Map.Entry<String, Integer> ma : hash.entrySet()){ |
|
|
|
gridSet.add(ma.getKey()); |
|
|
|
if (ma.getValue() >= NumConstant.FIVE) {//活跃网格
|
|
|
|
gridLivelyNum++; |
|
|
|
GridLivelyDetailExcel.LivelyGrid lively = new GridLivelyDetailExcel.LivelyGrid(); |
|
|
|
lively.setAgencyId(sub.getAgencyId()); |
|
|
|
lively.setAgencyName(sub.getAgencyName()); |
|
|
|
lively.setGridId(ma.getKey()); |
|
|
|
lively.setGridName(null!=gridMap.get(ma.getKey())?gridMap.get(ma.getKey()).getGridName():""); |
|
|
|
lively.setDatyNum(ma.getValue()); |
|
|
|
livelyGrid.add(lively); |
|
|
|
} else if (ma.getValue() >= NumConstant.TWO && ma.getValue() < NumConstant.FIVE) {//正常网格
|
|
|
|
gridOrdinaryNum++; |
|
|
|
GridLivelyDetailExcel.OrdinaryGrid ordinary = new GridLivelyDetailExcel.OrdinaryGrid(); |
|
|
|
ordinary.setAgencyId(sub.getAgencyId()); |
|
|
|
ordinary.setAgencyName(sub.getAgencyName()); |
|
|
|
ordinary.setGridId(ma.getKey()); |
|
|
|
ordinary.setGridName(null!=gridMap.get(ma.getKey())?gridMap.get(ma.getKey()).getGridName():""); |
|
|
|
ordinary.setDatyNum(ma.getValue()); |
|
|
|
ordinaryGrid.add(ordinary); |
|
|
|
}else if (ma.getValue() < NumConstant.TWO) {//部分僵尸网格[这是活跃天数为1的,还有部分活跃天数为0的]
|
|
|
|
GridLivelyDetailExcel.LazyGrid lazy = new GridLivelyDetailExcel.LazyGrid(); |
|
|
|
lazy.setAgencyId(sub.getAgencyId()); |
|
|
|
lazy.setAgencyName(sub.getAgencyName()); |
|
|
|
lazy.setGridId(ma.getKey()); |
|
|
|
lazy.setGridName(null!=gridMap.get(ma.getKey())?gridMap.get(ma.getKey()).getGridName():""); |
|
|
|
lazy.setDatyNum(ma.getValue()); |
|
|
|
lazyGrid.add(lazy); |
|
|
|
} |
|
|
|
} |
|
|
|
GridLivelyExcel gridLively = new GridLivelyExcel(); |
|
|
|
gridLively.setAgencyId(sub.getAgencyId()); |
|
|
|
gridLively.setAgencyName(sub.getAgencyName()); |
|
|
|
gridLively.setGridSumNum(sub.getGridSumNum()); |
|
|
|
gridLively.setGridLivelyNum(gridLivelyNum); |
|
|
|
gridLively.setGridLivelyRatio((sub.getGridSumNum() == 0 || gridLivelyNum > sub.getGridSumNum()) ? "0%" : numberFormat.format(((float) gridLivelyNum / (float) sub.getGridSumNum()) * 100) + "%"); |
|
|
|
gridLively.setGridOrdinaryNum(gridOrdinaryNum); |
|
|
|
gridLively.setGridOrdinaryRatio((sub.getGridSumNum() == 0 || gridOrdinaryNum > sub.getGridSumNum()) ? "0%" : numberFormat.format(((float) gridOrdinaryNum / (float) sub.getGridSumNum()) * 100) + "%"); |
|
|
|
int gridLazyNum = sub.getGridSumNum() - gridLivelyNum - gridOrdinaryNum; |
|
|
|
gridLively.setGridLazyNum(gridLazyNum < 0 ? 0 : gridLazyNum); |
|
|
|
gridLively.setGridLazyRatio((sub.getGridSumNum() == 0 || gridLazyNum < 0) ? "0%" : numberFormat.format(((float) gridLazyNum / (float) sub.getGridSumNum()) * 100) + "%"); |
|
|
|
livelyExcelList.add(gridLively); |
|
|
|
|
|
|
|
//5-2.组装不存在活跃度的数据【网格活跃天数为0的】
|
|
|
|
gridList.forEach(g->{ |
|
|
|
if(g.getPids().contains(sub.getAgencyId())&&!gridSet.contains(g.getGridId())){ |
|
|
|
GridLivelyDetailExcel.LazyGrid lazy = new GridLivelyDetailExcel.LazyGrid(); |
|
|
|
lazy.setAgencyId(sub.getAgencyId()); |
|
|
|
lazy.setAgencyName(sub.getAgencyName()); |
|
|
|
lazy.setGridId(g.getGridId()); |
|
|
|
lazy.setGridName(null!=gridMap.get(g.getGridId())?gridMap.get(g.getGridId()).getGridName():""); |
|
|
|
lazy.setDatyNum(NumConstant.ZERO); |
|
|
|
lazyGrid.add(lazy); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
//5-3.网格运行情况合计
|
|
|
|
if (!CollectionUtils.isEmpty(livelyExcelList)){ |
|
|
|
GridLivelyExcel gridLively = new GridLivelyExcel(); |
|
|
|
gridLively.setAgencyName("合计"); |
|
|
|
gridLively.setGridSumNum(livelyExcelList.stream().mapToInt(GridLivelyExcel::getGridSumNum).sum()); |
|
|
|
gridLively.setGridLivelyNum(livelyExcelList.stream().mapToInt(GridLivelyExcel::getGridLivelyNum).sum()); |
|
|
|
gridLively.setGridLivelyRatio((gridLively.getGridSumNum() == 0 || gridLively.getGridLivelyNum() > gridLively.getGridSumNum()) ? "0%" : numberFormat.format(((float) gridLively.getGridLivelyNum() / (float) gridLively.getGridSumNum()) * 100) + "%"); |
|
|
|
gridLively.setGridOrdinaryNum(livelyExcelList.stream().mapToInt(GridLivelyExcel::getGridOrdinaryNum).sum()); |
|
|
|
gridLively.setGridOrdinaryRatio((gridLively.getGridSumNum() == 0 || gridLively.getGridOrdinaryNum() > gridLively.getGridSumNum()) ? "0%" : numberFormat.format(((float) gridLively.getGridOrdinaryNum() / (float) gridLively.getGridSumNum()) * 100) + "%"); |
|
|
|
gridLively.setGridLazyNum(livelyExcelList.stream().mapToInt(GridLivelyExcel::getGridLazyNum).sum()); |
|
|
|
gridLively.setGridLazyRatio((gridLively.getGridSumNum() == 0 || gridLively.getGridLazyNum() > gridLively.getGridSumNum()) ? "0%" : numberFormat.format(((float) gridLively.getGridLazyNum() / (float) gridLively.getGridSumNum()) * 100) + "%"); |
|
|
|
livelyExcelList.add(gridLively); |
|
|
|
} |
|
|
|
|
|
|
|
//6.封装并返回
|
|
|
|
result.setLivelyExcelList(livelyExcelList); |
|
|
|
result.setLivelyGrid(livelyGrid); |
|
|
|
result.setOrdinaryGrid(ordinaryGrid); |
|
|
|
result.setLazyGrid(lazyGrid); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 查询组织的直属下级组织下网格活跃度统计--文件导出 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
public void grdiLivelyExport(HttpServletResponse response, GridLivelyFormDTO formDTO) { |
|
|
|
ExcelWriter excelWriter = null; |
|
|
|
//easyExcel导出
|
|
|
|
/*ExcelWriter excelWriter = null; |
|
|
|
try { |
|
|
|
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel("网格活跃度统计表.xlsx", response)).build(); |
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet(excelSheetName(formDTO)).build(); |
|
|
@ -696,7 +815,73 @@ public class GovOrgServiceImpl implements GovOrgService { |
|
|
|
if (excelWriter != null) { |
|
|
|
excelWriter.finish(); |
|
|
|
} |
|
|
|
}*/ |
|
|
|
//easyPoi导出
|
|
|
|
//1.获取当前组织缓存信息
|
|
|
|
AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(formDTO.getAgencyId()); |
|
|
|
if (null == agencyInfo) { |
|
|
|
throw new RenException(String.format("获取组织缓存信息失败%s", formDTO.getAgencyId())); |
|
|
|
} |
|
|
|
//2.查询网格活跃度数据
|
|
|
|
GridLivelyDetailExcel resultDTO = gridActiveList(formDTO); |
|
|
|
if(null==resultDTO||CollectionUtils.isEmpty(resultDTO.getLivelyExcelList())){ |
|
|
|
log.warn(String.format("网格员活跃度统计数据为空,入参【%s】", JSON.toJSONString(formDTO))); |
|
|
|
return; |
|
|
|
} |
|
|
|
//3.生成多sheet页excel文件并写入数据导出文件
|
|
|
|
List<Map<String,Object>> headerList = new ArrayList<>(); |
|
|
|
String titleName = excelTitleName(formDTO.getStartTime(), formDTO.getEndTime(), agencyInfo.getOrganizationName()+"网格活跃度统计表"); |
|
|
|
headerList.add(getHaderMap(resultDTO.getLivelyExcelList(), titleName, "各街镇网格运行情况", GridLivelyExcel.class)); |
|
|
|
titleName = excelTitleName(formDTO.getStartTime(), formDTO.getEndTime(), agencyInfo.getOrganizationName()+"活跃网格明细"); |
|
|
|
headerList.add(getHaderMap(resultDTO.getLivelyGrid(), titleName, "活跃网格统计", GridLivelyDetailExcel.LivelyGrid.class)); |
|
|
|
titleName = excelTitleName(formDTO.getStartTime(), formDTO.getEndTime(), agencyInfo.getOrganizationName()+"正常运行网格明细"); |
|
|
|
headerList.add(getHaderMap(resultDTO.getOrdinaryGrid(), titleName, "正常运行网格统计", GridLivelyDetailExcel.OrdinaryGrid.class)); |
|
|
|
titleName = excelTitleName(formDTO.getStartTime(), formDTO.getEndTime(), agencyInfo.getOrganizationName()+"僵尸网格明细"); |
|
|
|
headerList.add(getHaderMap(resultDTO.getLazyGrid(), titleName, "僵尸网格统计", GridLivelyDetailExcel.LazyGrid.class)); |
|
|
|
try { |
|
|
|
Workbook workbook = ExcelExportUtil.exportExcel(headerList, ExcelType.XSSF); |
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
response.setHeader("content-Type", "application/vnd.ms-excel"); |
|
|
|
String fileName = excelTitleName(formDTO.getStartTime(), formDTO.getEndTime(), agencyInfo.getOrganizationName()+"网格活跃度统计.xls"); |
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" +fileName); |
|
|
|
ServletOutputStream out = response.getOutputStream(); |
|
|
|
workbook.write(out); |
|
|
|
out.flush(); |
|
|
|
out.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("网格活跃度导出失败", e); |
|
|
|
} |
|
|
|
} |
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* data 业务数据集合 |
|
|
|
* title sheet页主标题 |
|
|
|
* name sheet页名称 |
|
|
|
* cl sheet页列头对应实体类 |
|
|
|
* @Description 生成多sheet页excel文件模板数据 |
|
|
|
**/ |
|
|
|
private Map<String, Object> getHaderMap(Collection<?> data, String title, String name, Class<?> cl){ |
|
|
|
Map<String,Object> map = new HashMap<>(); |
|
|
|
map.put("data",data); |
|
|
|
ExportParams param1 = new ExportParams(title, name); |
|
|
|
map.put("title", param1); |
|
|
|
map.put("entity", cl); |
|
|
|
return map; |
|
|
|
} |
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description excel文件sheet页主标题拼接 |
|
|
|
**/ |
|
|
|
private String excelTitleName(String startTime, String endTime, String name){ |
|
|
|
StringBuilder titleName = new StringBuilder(); |
|
|
|
SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMdd"); |
|
|
|
SimpleDateFormat format2 = new SimpleDateFormat("yyyy年MM月dd日"); |
|
|
|
try{ |
|
|
|
titleName.append("(").append(format2.format(format1.parse(startTime))).append("至").append(format2.format(format1.parse(endTime))).append(")").append(name); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return titleName.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
private String excelSheetName(GridLivelyFormDTO formDTO){ |
|
|
|