5c4f0c8c sonin

运营月报 优化

1 个父辈 5c551cb5
......@@ -2,9 +2,11 @@ package com.skua.tool.util;
import com.skua.common.constant.BusinessConstant;
import com.skua.core.util.ConvertUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 请求参数工具类
......@@ -14,6 +16,14 @@ import java.util.List;
*/
public class ParamUtils {
/**
* 时间范围参数处理
*
* @param startTime
* @param endTime
* @param timeType
* @return
*/
public static List<String> timeRangeParamFunc(String startTime, String endTime, String timeType) {
List<String> timeList = new ArrayList<>(), intervalTimeList;
if ("day".equalsIgnoreCase(timeType)) {
......@@ -40,4 +50,30 @@ public class ParamUtils {
return timeList;
}
/**
* 统一保留小数位数
*
* @param paramMap
* @param nPoint
*/
public static void retainDecimalFunc(Map<String, Object> paramMap, int nPoint) {
for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
if (entry.getValue() instanceof List) {
((List) entry.getValue()).forEach(item -> {
if (item instanceof Map) {
retainDecimalFunc((Map<String, Object>) item, nPoint);
} else {
if (DigitalUtils.isNumeric(ConvertUtils.getString(item))) {
paramMap.put(entry.getKey(), DigitalUtils.nPoint(item, nPoint));
}
}
});
} else {
if (DigitalUtils.isNumeric(ConvertUtils.getString(entry.getValue()))) {
paramMap.put(entry.getKey(), DigitalUtils.nPoint(entry.getValue(), nPoint));
}
}
}
}
}
......
......@@ -17,6 +17,7 @@ import com.skua.tool.dfs.CaseWhen;
import com.skua.tool.util.DateUtils;
import com.skua.tool.util.DigitalUtils;
import com.skua.tool.util.JSUtils;
import com.skua.tool.util.ParamUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
......@@ -228,7 +229,6 @@ public class OperationReportServiceImpl implements IOperationReportService {
List<String> timeList = DateUtils.intervalByDay(startTime, endTime, BusinessConstant.dateFormat.substring(0, 10));
// 同比时间
String[] timeArray = DateUtils.tbTime(startTime, endTime);
List<String> tbTimeList = DateUtils.intervalByDay(timeArray[0], timeArray[1], BusinessConstant.dateFormat.substring(0, 10));
String departId = ConvertUtils.getString(paramMap.get("departId"));
List<String> departIdList = Arrays.asList(departId.split(","));
// 翻译
......@@ -286,7 +286,7 @@ public class OperationReportServiceImpl implements IOperationReportService {
// 数据库字段 => 展示字段名称 + 对比数据展示字段名称
Map<String, String[]> dictMap1 = new LinkedHashMap<String, String[]>(){{
// 目标实际水量
put("target_water", new String[]{"mbsl", "sjsl"});
put("target_water", new String[]{"mbsl", "sfsl"});
// 目标实际水费
put("target_cost", new String[]{"mbsf", "sjsf"});
// 目标水费收入
......@@ -296,9 +296,9 @@ public class OperationReportServiceImpl implements IOperationReportService {
// 目标药费(万元)
put("target_drug * target_water", new String[]{"mbyf", "sjyf"});
// 目标电耗
put("target_power", new String[]{"mbdh", "sjdh"});
put("target_power / " + timeList.size(), new String[]{"mbdh", "sjdh"});
// 目标药耗
put("target_drug", new String[]{"mbyh", "sjyh"});
put("target_drug / " + timeList.size(), new String[]{"mbyh", "sjyh"});
}};
QueryWrapper<?> queryWrapper1 = new QueryWrapper<>();
queryWrapper1.in("depart_id", departIdList);
......@@ -309,9 +309,10 @@ public class OperationReportServiceImpl implements IOperationReportService {
Map<String, Object> queryMap1 = baseService.queryForMap("select " + caseWhen1.print() + " from report_target_config", queryWrapper1);
// 年度目标 序时情况
Map<String, String[]> dictMap1_1 = new LinkedHashMap<String, String[]>(){{
put("sl", new String[]{"xssl", "sjsl"});
put("sl", new String[]{"xssl", "sfsl"});
put("fy", new String[]{"xssf", "sjsf"});
put("sf", new String[]{"xssfsr", "sfsr"});
put("df", new String[]{"xsdf", "sjdf"});
}};
QueryWrapper<?> queryWrapper1_1 = new QueryWrapper<>();
queryWrapper1_1.in("depart_id", departIdList);
......@@ -320,6 +321,9 @@ public class OperationReportServiceImpl implements IOperationReportService {
caseWhen1_1.selectCaseWhen("target_time >= '" + startTime.substring(0, 7) + "' and target_time <= '" + endTime.substring(0, 7) + "' and target_type = '" + entry.getKey() + "'", "target_value", "0", entry.getValue()[0]);
}
Map<String, Object> queryMap1_1 = baseService.queryForMap("select " + caseWhen1_1.print() + " from report_target_config_sub", queryWrapper1_1);
// 补充序时药费,取值= 目标药费 * 月数
queryMap1_1.put("xsyf", ConvertUtils.getDouble(queryMap1.get("mbyf"), 0D) * timeList.size() / 12);
dictMap1_1.put("", new String[]{"xsyf", "sjyf"});
// 详情信息
QueryWrapper<?> queryWrapper3 = new QueryWrapper<>();
queryWrapper3.in("aaa.depart_id", departIdList);
......@@ -359,7 +363,7 @@ public class OperationReportServiceImpl implements IOperationReportService {
put("departId", tmpDepartId);
put("departName", tmpDepartName);
put("sjsf", item.get("sjsf"));
put("xssf", item.get("mbsf"));
put("xssf", item.get("xssf"));
}});
}
// 实际水量 同比下降
......@@ -375,13 +379,13 @@ public class OperationReportServiceImpl implements IOperationReportService {
}});
}
// 电费 超标
if (ConvertUtils.getDouble(item.get("sjdf"), 0D) > ConvertUtils.getDouble(item.get("mbdf"), 0D) * timeList.size() / 12) {
Double value = ConvertUtils.getDouble(item.get("sjdf"), 0D) / ConvertUtils.getDouble(item.get("mbdf"), 0D) * 100;
if (ConvertUtils.getDouble(item.get("sjdf"), 0D) > ConvertUtils.getDouble(item.get("xsdf"), 0D)) {
Double value = ConvertUtils.getDouble(item.get("sjdf"), 0D) / ConvertUtils.getDouble(item.get("xsdf"), 0D) * 100;
dfcbList.add(new LinkedHashMap<String, Object>(){{
put("departId", tmpDepartId);
put("departName", tmpDepartName);
put("sjdf", item.get("sjdf"));
put("mbdf", item.get("mbdf"));
put("xsdf", item.get("xsdf"));
put("sjdf_xsPercentage", (Double.isInfinite(value) || Double.isNaN(value)) ? null : value);
put("reason", "");
}});
......@@ -393,7 +397,7 @@ public class OperationReportServiceImpl implements IOperationReportService {
put("departId", tmpDepartId);
put("departName", tmpDepartName);
put("sjyf", item.get("sjyf"));
put("mbyf", item.get("mbyf"));
put("xsyf", ConvertUtils.getDouble(item.get("mbyf"), 0) * timeList.size() / 12);
put("sjyf_xsPercentage", (Double.isInfinite(value) || Double.isNaN(value)) ? null : value);
put("reason", "");
}});
......@@ -404,7 +408,9 @@ public class OperationReportServiceImpl implements IOperationReportService {
put("departId", tmpDepartId);
put("departName", tmpDepartName);
put("sjdh", item.get("sjdh"));
// 序时 = 目标
put("mbdh", item.get("mbdh"));
put("xsdh", item.get("mbdh"));
put("reason", "");
}});
}
......@@ -414,7 +420,9 @@ public class OperationReportServiceImpl implements IOperationReportService {
put("departId", tmpDepartId);
put("departName", tmpDepartName);
put("sjyh", item.get("sjyh"));
// 序时 = 目标
put("mbyh", item.get("mbyh"));
put("xsyh", item.get("mbyh"));
put("reason", "");
}});
}
......@@ -442,22 +450,20 @@ public class OperationReportServiceImpl implements IOperationReportService {
// 封装结果集
Map<String, Object> resMap = new LinkedHashMap<>();
// 合并 电费信息
Map<String, Object> queryMap0_2 = new LinkedHashMap<String, Object>() {{
Map<String, Object> tmpQueryMap0 = new LinkedHashMap<String, Object>() {{
putAll(queryMap0);
putAll(queryMap0_1);
}};
for (String key: queryMap0_2.keySet()) {
resMap.put(key, queryMap0_2.get(key));
for (String key: tmpQueryMap0.keySet()) {
resMap.put(key, tmpQueryMap0.get(key));
// 计算同比百分比
if (key.startsWith("tb_")) {
// 补充平均值信息
resMap.put(key + "_avg", ConvertUtils.getDouble(queryMap0_2.get(key), 0) / tbTimeList.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;
Double tbPercentage = (ConvertUtils.getDouble(tmpQueryMap0.get(srcKey), 0D) - ConvertUtils.getDouble(tmpQueryMap0.get(key), 0D)) / ConvertUtils.getDouble(tmpQueryMap0.get(key), 0D) * 100;
resMap.put(srcKey + "_tbPercentage", (Double.isInfinite(tbPercentage) || Double.isNaN(tbPercentage)) ? null : tbPercentage);
} else {
resMap.put(key + "_avg", ConvertUtils.getDouble(queryMap0_2.get(key), 0) / timeList.size());
}
// 补充平均值信息
resMap.put(key + "_avg", ConvertUtils.getDouble(tmpQueryMap0.get(key), 0) / timeList.size());
}
resMap.putAll(queryMap1);
resMap.putAll(queryMap1_1);
......@@ -470,12 +476,6 @@ public class OperationReportServiceImpl implements IOperationReportService {
Double xsPercentage = ConvertUtils.getDouble(resMap.get(valueArray[1]), 0D) / ConvertUtils.getDouble(resMap.get(valueArray[0]), 0D) * 100;
resMap.put(valueArray[1] + "_xsPercentage", (Double.isInfinite(xsPercentage) || Double.isNaN(xsPercentage)) ? null : xsPercentage);
}
// 统一保留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("sfsrwwcList", sfsrwwcList);
resMap.put("sjsfywcList", sjsfywcList);
resMap.put("sjslxjList", sjslxjList);
......@@ -483,6 +483,8 @@ public class OperationReportServiceImpl implements IOperationReportService {
resMap.put("yfcbList", yfcbList);
resMap.put("dhcbList", dhcbList);
resMap.put("yhcbList", yhcbList);
// 统一保留2位小数
ParamUtils.retainDecimalFunc(resMap, 2);
resMap.put("priorityWorkItemList", priorityWorkItemList);
resMap.put("hiddenDangerInspectionList", hiddenDangerInspectionList);
return resMap;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!