c0bc718b sonin

运营月报 优化

1 个父辈 89a6986f
package com.skua.modules.report.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.skua.aop.annotation.CustomExceptionAnno;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
......@@ -11,6 +12,7 @@ import com.skua.modules.custom.service.IFCustomReportDatasetService;
import com.skua.modules.report.service.IOperationReportService;
import com.skua.modules.report.vo.JnhbReportData;
import com.skua.modules.report.vo.ProductDataVO;
import com.skua.modules.system.entity.SysDepart;
import com.skua.modules.system.service.ISysDepartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -65,6 +67,13 @@ public class OperationReportController {
public Result<Object> operationMonthReportCtrl(@RequestParam Map<String,Object> paramsMap) {
// 请求参数
String departId = ConvertUtils.getString(paramsMap.get("departId"));
// 如果是集团,则查询其子集
if ("af880d6a13404a67825e94bc0f2f3808".equals(departId)) {
List<SysDepart> sysDepartList = departService.list(new QueryWrapper<SysDepart>().eq("parent_id", departId).orderByAsc("depart_order"));
for (SysDepart item: sysDepartList) {
departId += "," + item.getId();
}
}
String startTime = ConvertUtils.getString(paramsMap.get("startTime"));
String endTime = ConvertUtils.getString(paramsMap.get("endTime"));
String[] departIdArray = departId.split(",");
......@@ -74,6 +83,7 @@ public class OperationReportController {
List<Map<String, Object>> resMapList = new ArrayList<>();
for (String tmpDepartId : departIdArray) {
String childDepartId = departService.getChildDepartId(tmpDepartId);
SysDepart tmpSysDepart = departService.getById(departId);
// 获取机构子集
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("startTime", startTime);
......@@ -82,6 +92,7 @@ public class OperationReportController {
Map<String, Object> resMap = operationReportService.dataAnalysisOfMonth(paramMap);
resMap.put("departId", tmpDepartId);
resMap.put("departName", sysDepartDictMap.get(tmpDepartId));
resMap.put("departType", tmpSysDepart.getDepartType());
resMapList.add(resMap);
}
return Result.ok(resMapList);
......
......@@ -233,65 +233,67 @@ public class OperationReportServiceImpl implements IOperationReportService {
List<String> departIdList = Arrays.asList(departId.split(","));
// 翻译
Map<String, String> sysDepartDictMap = businessService.dictMap("sys_depart", departIdList);
// reitId => 展示字段名称 + dataTime时间长度 + dataValue数据转换
Map<String, String[]> dictMap0 = new LinkedHashMap<String, String[]>(){{
// 污水水量
put("1816743130490388481", new String[]{"wssl", "10"});
// 污水水量(吨 => 万吨)
put("1816743130490388481", new String[]{"wssl", "10", "/10000"});
// 收费水量
put("1818936220739293185", new String[]{"sfsl", "7"});
// 生产供水量
put("1818218432697643010", new String[]{"scgsl", "10"});
// 污泥处置量
put("1910571063704104961", new String[]{"wnczl", "7"});
put("1818936220739293185", new String[]{"sfsl", "7", ""});
// 生产供水量(吨 => 万吨)
put("1818218432697643010", new String[]{"scgsl", "10", "/10000"});
// 污泥处置量(吨 => 万吨)
put("1910571063704104961", new String[]{"wnczl", "7", "/10000"});
// 实际水费
put("1912415992428384257", new String[]{"sjsf", "7"});
put("1912415992428384257", new String[]{"sjsf", "7", ""});
// 实际水量
put("1818936221372633089", new String[]{"sjsl", "7"});
// 实际药费
put("1818936218910576642", new String[]{"sjyf", "7"});
put("1818936221372633089", new String[]{"sjsl", "7", ""});
// 实际药费(元=>万元)
put("1818936218910576642", new String[]{"sjyf", "7", "/10000"});
// 实际电耗
put("1818936219699105793", new String[]{"sjdh", "7"});
put("1818936219699105793", new String[]{"sjdh", "7", ""});
// 实际药耗
put("1818936218491146241", new String[]{"sjyh", "7"});
put("1818936218491146241", new String[]{"sjyh", "7", ""});
}};
CaseWhen caseWhen0 = new CaseWhen();
for (Map.Entry<String, String[]> entry: dictMap0.entrySet()) {
String reitId = entry.getKey();
String alias = entry.getValue()[0];
int timeLength = Integer.parseInt(entry.getValue()[1]);
caseWhen0.selectCaseWhen("reit_id = '" + reitId + "' and data_time >= '" + startTime.substring(0, timeLength) + "' and data_time <= '" + endTime.substring(0, timeLength) + "'", "item_value", "0", alias);
caseWhen0.selectCaseWhen("reit_id = '" + reitId + "' and data_time >= '" + timeArray[0].substring(0, timeLength) + "' and data_time <= '" + timeArray[1].substring(0, timeLength) + "'", "item_value", "0", "tb_" + alias);
caseWhen0.selectCaseWhen("reit_id = '" + reitId + "' and data_time >= '" + startTime.substring(0, timeLength) + "' and data_time <= '" + endTime.substring(0, timeLength) + "'", "item_value" + entry.getValue()[2], "0", alias);
caseWhen0.selectCaseWhen("reit_id = '" + reitId + "' and data_time >= '" + timeArray[0].substring(0, timeLength) + "' and data_time <= '" + timeArray[1].substring(0, timeLength) + "'", "item_value" + entry.getValue()[2], "0", "tb_" + alias);
}
QueryWrapper<?> queryWrapper0 = new QueryWrapper<>();
queryWrapper0.in("reit_id", dictMap0.keySet())
.in("depart_id", departIdList);
Map<String, Object> queryMap0 = baseService.queryForMap("select " + caseWhen0.print() + " from f_report_itemv", queryWrapper0);
// 年度目标
Map<String, String> dictMap1 = new LinkedHashMap<String, String>(){{
// 数据库字段 => 展示字段名称 + 对比数据展示字段名称
Map<String, String[]> dictMap1 = new LinkedHashMap<String, String[]>(){{
// 目标水量
put("target_water", "mbsl");
put("target_water", new String[]{"mbsl", "sjsl"});
// 目标水费
put("target_cost", "mbsf");
put("target_cost", new String[]{"mbsf", "sjsf"});
// 目标电费
put("target_power_cost", "mbdf");
// 目标药费
put("target_drug * target_water * 10000", "mbyf");
put("target_power_cost", new String[]{"mbdf", "sjdf"});
// 目标药费(万元)
put("target_drug * target_water", new String[]{"mbyf", "sjyf"});
// 目标电耗
put("target_power", "mbdh");
put("target_power", new String[]{"mbdh", "sjdh"});
// 目标药耗
put("target_drug", "mbyh");
put("target_drug", new String[]{"mbyh", "sjyh"});
}};
QueryWrapper<?> queryWrapper1 = new QueryWrapper<>();
queryWrapper1.in("depart_id", departIdList);
CaseWhen caseWhen1 = new CaseWhen();
for (Map.Entry<String, String> entry: dictMap1.entrySet()) {
caseWhen1.selectCaseWhen("target_year = '" + endTime.substring(0, 4) + "'", entry.getKey(), "0", entry.getValue());
caseWhen1.selectCaseWhen("target_year = '" + timeArray[1].substring(0, 4) + "'", entry.getKey(), "0", "tb_" + entry.getValue());
for (Map.Entry<String, String[]> entry: dictMap1.entrySet()) {
caseWhen1.selectCaseWhen("target_year = '" + endTime.substring(0, 4) + "'", entry.getKey(), "0", entry.getValue()[0]);
caseWhen1.selectCaseWhen("target_year = '" + timeArray[1].substring(0, 4) + "'", entry.getKey(), "0", "tb_" + entry.getValue()[0]);
}
Map<String, Object> queryMap1 = baseService.queryForMap("select " + caseWhen1.print() + " from report_target_config", queryWrapper1);
// 实际电费信息
// 实际电费信息(元=>万元)
Map<String, String> dictMap2 = new LinkedHashMap<String, String>(){{
// 实际电费
put("cost", "sjdf");
put("cost/10000", "sjdf");
}};
QueryWrapper<?> queryWrapper2 = new QueryWrapper<>();
queryWrapper2.in("depart_id", departIdList);
......@@ -413,16 +415,36 @@ public class OperationReportServiceImpl implements IOperationReportService {
});
// 封装结果集
Map<String, Object> resMap = new LinkedHashMap<>();
for (String key: queryMap0.keySet()) {
resMap.put(key, queryMap0.get(key));
// 合并 电费信息
Map<String, Object> queryMap0_2 = new LinkedHashMap<String, Object>() {{
putAll(queryMap0);
putAll(queryMap2);
}};
for (String key: queryMap0_2.keySet()) {
resMap.put(key, queryMap0_2.get(key));
if (key.startsWith("tb_")) {
resMap.put(key + "_avg", ConvertUtils.getDouble(queryMap0.get(key), 0) / timeListTb.size());
// 补充平均值信息
resMap.put(key + "_avg", ConvertUtils.getDouble(queryMap0_2.get(key), 0) / timeListTb.size());
// 计算同比百分比
String srcKey = key.replaceAll("tb_", "");
double tbPercentage = (ConvertUtils.getDouble(queryMap0_2.get(srcKey), 0D) - ConvertUtils.getDouble(queryMap0_2.get(key), 0D)) / ConvertUtils.getDouble(queryMap0_2.get(key), 0D) * 100;
resMap.put(srcKey + "_tbPercentage", tbPercentage);
} else {
resMap.put(key + "_avg", ConvertUtils.getDouble(queryMap0.get(key), 0) / timeList.size());
resMap.put(key + "_avg", ConvertUtils.getDouble(queryMap0_2.get(key), 0) / timeList.size());
}
}
resMap.putAll(queryMap1);
resMap.putAll(queryMap2);
// 计算完成年度目标情况
for (String[] valueArray: dictMap1.values()) {
double percentage = ConvertUtils.getDouble(resMap.get(valueArray[1]), 0D) / ConvertUtils.getDouble(resMap.get(valueArray[0]), 0D) * 100;
resMap.put(valueArray[1] + "_targetPercentage", percentage);
}
// 统一保留2位小数
for (String key: resMap.keySet()) {
if (DigitalUtils.isNumeric(ConvertUtils.getString(resMap.get(key)))) {
resMap.put(key, DigitalUtils.nPoint(resMap.get(key), 2));
}
}
resMap.put("sfwwcList", sfwwcList);
resMap.put("sfywcList", sfywcList);
resMap.put("sjslxjList", sjslxjList);
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!