|
|
|
@ -121,7 +121,10 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService {
|
|
|
|
|
|
|
|
|
|
@Value("${hzims.operation.area.report}") |
|
|
|
|
private String area_month_report_key; |
|
|
|
|
|
|
|
|
|
@Value("${hzims.operation.wind.report}") |
|
|
|
|
private String wind_report_month_cache_final; |
|
|
|
|
@Value("${hzims.operation.energy.report}") |
|
|
|
|
private String energy_report_month_cache_final; |
|
|
|
|
private final static String RECENT_YEAR_POWER_DATA = "hzims:operation:key:power:data"; |
|
|
|
|
private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key"; |
|
|
|
|
private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key"; |
|
|
|
@ -153,7 +156,61 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService {
|
|
|
|
|
//根据用户权限获取机构
|
|
|
|
|
return R.data(areaMonthReportVoList.stream().sorted(Comparator.comparing(AreaMonthReportVo::getActualPower, Comparator.reverseOrder())).collect(Collectors.toList())); |
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
public R<List<AreaMonthReportVo>> getReportByType(String date, Integer type){ |
|
|
|
|
List<AreaMonthReportVo> areaMonthReportVoList = this.getAreaMonthReportByType(date, false,type); |
|
|
|
|
if (CollectionUtil.isEmpty(areaMonthReportVoList)) { |
|
|
|
|
return R.fail("选择月份无统计报表数据"); |
|
|
|
|
} |
|
|
|
|
//根据用户权限获取机构
|
|
|
|
|
return R.data(areaMonthReportVoList.stream().sorted(Comparator.comparing(AreaMonthReportVo::getActualPower, Comparator.reverseOrder())).collect(Collectors.toList())); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 导出区域月报 |
|
|
|
|
* |
|
|
|
|
* @param response |
|
|
|
|
* @param date |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public R exportByType(HttpServletResponse response, String date, Integer type) { |
|
|
|
|
List<AreaMonthReportVo> monthReportVoList = this.getAreaMonthReportByType(date, true,type); |
|
|
|
|
// 创建Excel文件
|
|
|
|
|
HSSFWorkbook hssWB = new HSSFWorkbook(); |
|
|
|
|
// 添加sheet页
|
|
|
|
|
HSSFSheet sheet = hssWB.createSheet("运行月报(" + date + ")"); |
|
|
|
|
// 行高
|
|
|
|
|
sheet.setDefaultRowHeight((short) (20 * 25)); |
|
|
|
|
// 列宽
|
|
|
|
|
sheet.setDefaultColumnWidth(20); |
|
|
|
|
this.setFirstHeader(hssWB, sheet); |
|
|
|
|
// 第二行/三行 表头格式设置
|
|
|
|
|
this.setWorkHeader(hssWB, sheet); |
|
|
|
|
if (!CollectionUtil.isEmpty(monthReportVoList)) { |
|
|
|
|
// 数据填充
|
|
|
|
|
this.setWorkData(hssWB, sheet, monthReportVoList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 下载导出
|
|
|
|
|
String filename = "(" + date + ")水电站生产运行月报"; |
|
|
|
|
// 设置头信息
|
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
response.setContentType("application/vnd.ms-excel"); |
|
|
|
|
ServletOutputStream outputStream; |
|
|
|
|
try { |
|
|
|
|
//设置xlsx格式
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename + ".xlsx", "UTF-8")); |
|
|
|
|
//创建一个输出流
|
|
|
|
|
outputStream = response.getOutputStream(); |
|
|
|
|
//写入数据
|
|
|
|
|
hssWB.write(outputStream); |
|
|
|
|
// 关闭
|
|
|
|
|
outputStream.close(); |
|
|
|
|
hssWB.close(); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
return R.data("success"); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 导出区域月报 |
|
|
|
|
* |
|
|
|
@ -1103,6 +1160,37 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取区域月报数据 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<AreaMonthReportVo> getAreaMonthReportByType(String date, boolean isSendFlag,Integer type) { |
|
|
|
|
R<List<Dept>> D = sysClient.getDeptByCurrentUser(); |
|
|
|
|
if (!D.isSuccess() || CollectionUtil.isEmpty(D.getData())) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
List<Long> authList = D.getData().stream().filter(o -> o.getDeptCategory().equals(3)).map(Dept::getId).collect(Collectors.toList()); |
|
|
|
|
if (CollectionUtil.isEmpty(authList)) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
String key = area_month_report_key; |
|
|
|
|
if (type.equals(HomePageConstant.WIND_POWER)){ |
|
|
|
|
key= wind_report_month_cache_final; |
|
|
|
|
} |
|
|
|
|
if (type.equals(HomePageConstant.ENERGY_STORAGE)){ |
|
|
|
|
key= energy_report_month_cache_final; |
|
|
|
|
} |
|
|
|
|
Map<String, List<AreaMonthReportVo>> map = (Map<String, List<AreaMonthReportVo>>) redisTemplate.opsForValue().get(key); |
|
|
|
|
if (MapUtils.isEmpty(map)) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
if (isSendFlag) { |
|
|
|
|
// 发送邮件
|
|
|
|
|
this.sendMonthReport(map, D.getData()); |
|
|
|
|
} |
|
|
|
|
return map.get(date); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 区域-加载月报数据 |
|
|
|
|
* |
|
|
|
|
* @param param |
|
|
|
@ -1133,10 +1221,53 @@ public class AreaMonthReportServiceImpl implements IAreaMonthReportService {
|
|
|
|
|
map.put(mon, list); |
|
|
|
|
}); |
|
|
|
|
// 推送当月报表邮件
|
|
|
|
|
this.sendMonthReport(map, R.getData()); |
|
|
|
|
// this.sendMonthReport(map, R.getData());
|
|
|
|
|
redisTemplate.opsForValue().set(area_month_report_key, map); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 区域-加载月报数据 |
|
|
|
|
* |
|
|
|
|
* @param param |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void loadMonthReportByType(String param, int year,int type) { |
|
|
|
|
// 获取所有机构
|
|
|
|
|
R<List<Dept>> R = sysClient.getDeptList(); |
|
|
|
|
if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (ObjectUtil.isEmpty(type)){ |
|
|
|
|
type=HomePageConstant.HYDROPOWER; |
|
|
|
|
} |
|
|
|
|
String saveKey=area_month_report_key; |
|
|
|
|
if (type==HomePageConstant.WIND_POWER){ |
|
|
|
|
saveKey=wind_report_month_cache_final; |
|
|
|
|
} |
|
|
|
|
if (type==HomePageConstant.ENERGY_STORAGE){ |
|
|
|
|
saveKey=energy_report_month_cache_final; |
|
|
|
|
} |
|
|
|
|
// 查询所有服务类型——"运维服务"、站点类型——"水电站"
|
|
|
|
|
List<StationEntity> stationList = stationService.getStationType(HomePageConstant.HYDROPOWER_SERVETYPE, Collections.singletonList(type), null,true); |
|
|
|
|
if (CollectionUtil.isEmpty(stationList)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 站点近年发电数据
|
|
|
|
|
Map<Long, Map<String, Float>> powerMap = (Map<Long, Map<String, Float>>) redisTemplate.opsForValue().get(RECENT_YEAR_POWER_DATA); |
|
|
|
|
// 存储数据节点 key - 月份 value - 区域数据集合
|
|
|
|
|
Map<String, List<AreaMonthReportVo>> map = new HashMap<>(); |
|
|
|
|
// 月份集合
|
|
|
|
|
List<String> monthList = getMonthList(year, Calendar.getInstance().get(Calendar.MONTH)); |
|
|
|
|
monthList.forEach(mon -> { |
|
|
|
|
List<AreaMonthReportVo> list = this.getAreaReportByMon(R.getData(), powerMap, stationList, mon); |
|
|
|
|
if (CollectionUtil.isEmpty(list)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
map.put(mon, list); |
|
|
|
|
}); |
|
|
|
|
// 推送当月报表邮件
|
|
|
|
|
// this.sendMonthReport(map, R.getData());
|
|
|
|
|
redisTemplate.opsForValue().set(saveKey, map); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 获取近年月份集合 |
|
|
|
|
* |
|
|
|
|