5c4f0c8c sonin

运营月报 优化

1 个父辈 5c551cb5
...@@ -2,9 +2,11 @@ package com.skua.tool.util; ...@@ -2,9 +2,11 @@ package com.skua.tool.util;
2 2
3 3
4 import com.skua.common.constant.BusinessConstant; 4 import com.skua.common.constant.BusinessConstant;
5 import com.skua.core.util.ConvertUtils;
5 6
6 import java.util.ArrayList; 7 import java.util.ArrayList;
7 import java.util.List; 8 import java.util.List;
9 import java.util.Map;
8 10
9 /** 11 /**
10 * 请求参数工具类 12 * 请求参数工具类
...@@ -14,6 +16,14 @@ import java.util.List; ...@@ -14,6 +16,14 @@ import java.util.List;
14 */ 16 */
15 public class ParamUtils { 17 public class ParamUtils {
16 18
19 /**
20 * 时间范围参数处理
21 *
22 * @param startTime
23 * @param endTime
24 * @param timeType
25 * @return
26 */
17 public static List<String> timeRangeParamFunc(String startTime, String endTime, String timeType) { 27 public static List<String> timeRangeParamFunc(String startTime, String endTime, String timeType) {
18 List<String> timeList = new ArrayList<>(), intervalTimeList; 28 List<String> timeList = new ArrayList<>(), intervalTimeList;
19 if ("day".equalsIgnoreCase(timeType)) { 29 if ("day".equalsIgnoreCase(timeType)) {
...@@ -40,4 +50,30 @@ public class ParamUtils { ...@@ -40,4 +50,30 @@ public class ParamUtils {
40 return timeList; 50 return timeList;
41 } 51 }
42 52
53 /**
54 * 统一保留小数位数
55 *
56 * @param paramMap
57 * @param nPoint
58 */
59 public static void retainDecimalFunc(Map<String, Object> paramMap, int nPoint) {
60 for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
61 if (entry.getValue() instanceof List) {
62 ((List) entry.getValue()).forEach(item -> {
63 if (item instanceof Map) {
64 retainDecimalFunc((Map<String, Object>) item, nPoint);
65 } else {
66 if (DigitalUtils.isNumeric(ConvertUtils.getString(item))) {
67 paramMap.put(entry.getKey(), DigitalUtils.nPoint(item, nPoint));
68 }
69 }
70 });
71 } else {
72 if (DigitalUtils.isNumeric(ConvertUtils.getString(entry.getValue()))) {
73 paramMap.put(entry.getKey(), DigitalUtils.nPoint(entry.getValue(), nPoint));
74 }
75 }
76 }
77 }
78
43 } 79 }
......
...@@ -17,6 +17,7 @@ import com.skua.tool.dfs.CaseWhen; ...@@ -17,6 +17,7 @@ import com.skua.tool.dfs.CaseWhen;
17 import com.skua.tool.util.DateUtils; 17 import com.skua.tool.util.DateUtils;
18 import com.skua.tool.util.DigitalUtils; 18 import com.skua.tool.util.DigitalUtils;
19 import com.skua.tool.util.JSUtils; 19 import com.skua.tool.util.JSUtils;
20 import com.skua.tool.util.ParamUtils;
20 import org.apache.commons.lang.StringUtils; 21 import org.apache.commons.lang.StringUtils;
21 import org.springframework.beans.factory.annotation.Autowired; 22 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.jdbc.core.BeanPropertyRowMapper; 23 import org.springframework.jdbc.core.BeanPropertyRowMapper;
...@@ -228,7 +229,6 @@ public class OperationReportServiceImpl implements IOperationReportService { ...@@ -228,7 +229,6 @@ public class OperationReportServiceImpl implements IOperationReportService {
228 List<String> timeList = DateUtils.intervalByDay(startTime, endTime, BusinessConstant.dateFormat.substring(0, 10)); 229 List<String> timeList = DateUtils.intervalByDay(startTime, endTime, BusinessConstant.dateFormat.substring(0, 10));
229 // 同比时间 230 // 同比时间
230 String[] timeArray = DateUtils.tbTime(startTime, endTime); 231 String[] timeArray = DateUtils.tbTime(startTime, endTime);
231 List<String> tbTimeList = DateUtils.intervalByDay(timeArray[0], timeArray[1], BusinessConstant.dateFormat.substring(0, 10));
232 String departId = ConvertUtils.getString(paramMap.get("departId")); 232 String departId = ConvertUtils.getString(paramMap.get("departId"));
233 List<String> departIdList = Arrays.asList(departId.split(",")); 233 List<String> departIdList = Arrays.asList(departId.split(","));
234 // 翻译 234 // 翻译
...@@ -286,7 +286,7 @@ public class OperationReportServiceImpl implements IOperationReportService { ...@@ -286,7 +286,7 @@ public class OperationReportServiceImpl implements IOperationReportService {
286 // 数据库字段 => 展示字段名称 + 对比数据展示字段名称 286 // 数据库字段 => 展示字段名称 + 对比数据展示字段名称
287 Map<String, String[]> dictMap1 = new LinkedHashMap<String, String[]>(){{ 287 Map<String, String[]> dictMap1 = new LinkedHashMap<String, String[]>(){{
288 // 目标实际水量 288 // 目标实际水量
289 put("target_water", new String[]{"mbsl", "sjsl"}); 289 put("target_water", new String[]{"mbsl", "sfsl"});
290 // 目标实际水费 290 // 目标实际水费
291 put("target_cost", new String[]{"mbsf", "sjsf"}); 291 put("target_cost", new String[]{"mbsf", "sjsf"});
292 // 目标水费收入 292 // 目标水费收入
...@@ -296,9 +296,9 @@ public class OperationReportServiceImpl implements IOperationReportService { ...@@ -296,9 +296,9 @@ public class OperationReportServiceImpl implements IOperationReportService {
296 // 目标药费(万元) 296 // 目标药费(万元)
297 put("target_drug * target_water", new String[]{"mbyf", "sjyf"}); 297 put("target_drug * target_water", new String[]{"mbyf", "sjyf"});
298 // 目标电耗 298 // 目标电耗
299 put("target_power", new String[]{"mbdh", "sjdh"}); 299 put("target_power / " + timeList.size(), new String[]{"mbdh", "sjdh"});
300 // 目标药耗 300 // 目标药耗
301 put("target_drug", new String[]{"mbyh", "sjyh"}); 301 put("target_drug / " + timeList.size(), new String[]{"mbyh", "sjyh"});
302 }}; 302 }};
303 QueryWrapper<?> queryWrapper1 = new QueryWrapper<>(); 303 QueryWrapper<?> queryWrapper1 = new QueryWrapper<>();
304 queryWrapper1.in("depart_id", departIdList); 304 queryWrapper1.in("depart_id", departIdList);
...@@ -309,9 +309,10 @@ public class OperationReportServiceImpl implements IOperationReportService { ...@@ -309,9 +309,10 @@ public class OperationReportServiceImpl implements IOperationReportService {
309 Map<String, Object> queryMap1 = baseService.queryForMap("select " + caseWhen1.print() + " from report_target_config", queryWrapper1); 309 Map<String, Object> queryMap1 = baseService.queryForMap("select " + caseWhen1.print() + " from report_target_config", queryWrapper1);
310 // 年度目标 序时情况 310 // 年度目标 序时情况
311 Map<String, String[]> dictMap1_1 = new LinkedHashMap<String, String[]>(){{ 311 Map<String, String[]> dictMap1_1 = new LinkedHashMap<String, String[]>(){{
312 put("sl", new String[]{"xssl", "sjsl"}); 312 put("sl", new String[]{"xssl", "sfsl"});
313 put("fy", new String[]{"xssf", "sjsf"}); 313 put("fy", new String[]{"xssf", "sjsf"});
314 put("sf", new String[]{"xssfsr", "sfsr"}); 314 put("sf", new String[]{"xssfsr", "sfsr"});
315 put("df", new String[]{"xsdf", "sjdf"});
315 }}; 316 }};
316 QueryWrapper<?> queryWrapper1_1 = new QueryWrapper<>(); 317 QueryWrapper<?> queryWrapper1_1 = new QueryWrapper<>();
317 queryWrapper1_1.in("depart_id", departIdList); 318 queryWrapper1_1.in("depart_id", departIdList);
...@@ -320,6 +321,9 @@ public class OperationReportServiceImpl implements IOperationReportService { ...@@ -320,6 +321,9 @@ public class OperationReportServiceImpl implements IOperationReportService {
320 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]); 321 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]);
321 } 322 }
322 Map<String, Object> queryMap1_1 = baseService.queryForMap("select " + caseWhen1_1.print() + " from report_target_config_sub", queryWrapper1_1); 323 Map<String, Object> queryMap1_1 = baseService.queryForMap("select " + caseWhen1_1.print() + " from report_target_config_sub", queryWrapper1_1);
324 // 补充序时药费,取值= 目标药费 * 月数
325 queryMap1_1.put("xsyf", ConvertUtils.getDouble(queryMap1.get("mbyf"), 0D) * timeList.size() / 12);
326 dictMap1_1.put("", new String[]{"xsyf", "sjyf"});
323 // 详情信息 327 // 详情信息
324 QueryWrapper<?> queryWrapper3 = new QueryWrapper<>(); 328 QueryWrapper<?> queryWrapper3 = new QueryWrapper<>();
325 queryWrapper3.in("aaa.depart_id", departIdList); 329 queryWrapper3.in("aaa.depart_id", departIdList);
...@@ -359,7 +363,7 @@ public class OperationReportServiceImpl implements IOperationReportService { ...@@ -359,7 +363,7 @@ public class OperationReportServiceImpl implements IOperationReportService {
359 put("departId", tmpDepartId); 363 put("departId", tmpDepartId);
360 put("departName", tmpDepartName); 364 put("departName", tmpDepartName);
361 put("sjsf", item.get("sjsf")); 365 put("sjsf", item.get("sjsf"));
362 put("xssf", item.get("mbsf")); 366 put("xssf", item.get("xssf"));
363 }}); 367 }});
364 } 368 }
365 // 实际水量 同比下降 369 // 实际水量 同比下降
...@@ -375,13 +379,13 @@ public class OperationReportServiceImpl implements IOperationReportService { ...@@ -375,13 +379,13 @@ public class OperationReportServiceImpl implements IOperationReportService {
375 }}); 379 }});
376 } 380 }
377 // 电费 超标 381 // 电费 超标
378 if (ConvertUtils.getDouble(item.get("sjdf"), 0D) > ConvertUtils.getDouble(item.get("mbdf"), 0D) * timeList.size() / 12) { 382 if (ConvertUtils.getDouble(item.get("sjdf"), 0D) > ConvertUtils.getDouble(item.get("xsdf"), 0D)) {
379 Double value = ConvertUtils.getDouble(item.get("sjdf"), 0D) / ConvertUtils.getDouble(item.get("mbdf"), 0D) * 100; 383 Double value = ConvertUtils.getDouble(item.get("sjdf"), 0D) / ConvertUtils.getDouble(item.get("xsdf"), 0D) * 100;
380 dfcbList.add(new LinkedHashMap<String, Object>(){{ 384 dfcbList.add(new LinkedHashMap<String, Object>(){{
381 put("departId", tmpDepartId); 385 put("departId", tmpDepartId);
382 put("departName", tmpDepartName); 386 put("departName", tmpDepartName);
383 put("sjdf", item.get("sjdf")); 387 put("sjdf", item.get("sjdf"));
384 put("mbdf", item.get("mbdf")); 388 put("xsdf", item.get("xsdf"));
385 put("sjdf_xsPercentage", (Double.isInfinite(value) || Double.isNaN(value)) ? null : value); 389 put("sjdf_xsPercentage", (Double.isInfinite(value) || Double.isNaN(value)) ? null : value);
386 put("reason", ""); 390 put("reason", "");
387 }}); 391 }});
...@@ -393,7 +397,7 @@ public class OperationReportServiceImpl implements IOperationReportService { ...@@ -393,7 +397,7 @@ public class OperationReportServiceImpl implements IOperationReportService {
393 put("departId", tmpDepartId); 397 put("departId", tmpDepartId);
394 put("departName", tmpDepartName); 398 put("departName", tmpDepartName);
395 put("sjyf", item.get("sjyf")); 399 put("sjyf", item.get("sjyf"));
396 put("mbyf", item.get("mbyf")); 400 put("xsyf", ConvertUtils.getDouble(item.get("mbyf"), 0) * timeList.size() / 12);
397 put("sjyf_xsPercentage", (Double.isInfinite(value) || Double.isNaN(value)) ? null : value); 401 put("sjyf_xsPercentage", (Double.isInfinite(value) || Double.isNaN(value)) ? null : value);
398 put("reason", ""); 402 put("reason", "");
399 }}); 403 }});
...@@ -404,7 +408,9 @@ public class OperationReportServiceImpl implements IOperationReportService { ...@@ -404,7 +408,9 @@ public class OperationReportServiceImpl implements IOperationReportService {
404 put("departId", tmpDepartId); 408 put("departId", tmpDepartId);
405 put("departName", tmpDepartName); 409 put("departName", tmpDepartName);
406 put("sjdh", item.get("sjdh")); 410 put("sjdh", item.get("sjdh"));
411 // 序时 = 目标
407 put("mbdh", item.get("mbdh")); 412 put("mbdh", item.get("mbdh"));
413 put("xsdh", item.get("mbdh"));
408 put("reason", ""); 414 put("reason", "");
409 }}); 415 }});
410 } 416 }
...@@ -414,7 +420,9 @@ public class OperationReportServiceImpl implements IOperationReportService { ...@@ -414,7 +420,9 @@ public class OperationReportServiceImpl implements IOperationReportService {
414 put("departId", tmpDepartId); 420 put("departId", tmpDepartId);
415 put("departName", tmpDepartName); 421 put("departName", tmpDepartName);
416 put("sjyh", item.get("sjyh")); 422 put("sjyh", item.get("sjyh"));
423 // 序时 = 目标
417 put("mbyh", item.get("mbyh")); 424 put("mbyh", item.get("mbyh"));
425 put("xsyh", item.get("mbyh"));
418 put("reason", ""); 426 put("reason", "");
419 }}); 427 }});
420 } 428 }
...@@ -442,22 +450,20 @@ public class OperationReportServiceImpl implements IOperationReportService { ...@@ -442,22 +450,20 @@ public class OperationReportServiceImpl implements IOperationReportService {
442 // 封装结果集 450 // 封装结果集
443 Map<String, Object> resMap = new LinkedHashMap<>(); 451 Map<String, Object> resMap = new LinkedHashMap<>();
444 // 合并 电费信息 452 // 合并 电费信息
445 Map<String, Object> queryMap0_2 = new LinkedHashMap<String, Object>() {{ 453 Map<String, Object> tmpQueryMap0 = new LinkedHashMap<String, Object>() {{
446 putAll(queryMap0); 454 putAll(queryMap0);
447 putAll(queryMap0_1); 455 putAll(queryMap0_1);
448 }}; 456 }};
449 for (String key: queryMap0_2.keySet()) { 457 for (String key: tmpQueryMap0.keySet()) {
450 resMap.put(key, queryMap0_2.get(key)); 458 resMap.put(key, tmpQueryMap0.get(key));
459 // 计算同比百分比
451 if (key.startsWith("tb_")) { 460 if (key.startsWith("tb_")) {
452 // 补充平均值信息
453 resMap.put(key + "_avg", ConvertUtils.getDouble(queryMap0_2.get(key), 0) / tbTimeList.size());
454 // 计算同比百分比
455 String srcKey = key.replaceAll("tb_", ""); 461 String srcKey = key.replaceAll("tb_", "");
456 Double tbPercentage = (ConvertUtils.getDouble(queryMap0_2.get(srcKey), 0D) - ConvertUtils.getDouble(queryMap0_2.get(key), 0D)) / ConvertUtils.getDouble(queryMap0_2.get(key), 0D) * 100; 462 Double tbPercentage = (ConvertUtils.getDouble(tmpQueryMap0.get(srcKey), 0D) - ConvertUtils.getDouble(tmpQueryMap0.get(key), 0D)) / ConvertUtils.getDouble(tmpQueryMap0.get(key), 0D) * 100;
457 resMap.put(srcKey + "_tbPercentage", (Double.isInfinite(tbPercentage) || Double.isNaN(tbPercentage)) ? null : tbPercentage); 463 resMap.put(srcKey + "_tbPercentage", (Double.isInfinite(tbPercentage) || Double.isNaN(tbPercentage)) ? null : tbPercentage);
458 } else {
459 resMap.put(key + "_avg", ConvertUtils.getDouble(queryMap0_2.get(key), 0) / timeList.size());
460 } 464 }
465 // 补充平均值信息
466 resMap.put(key + "_avg", ConvertUtils.getDouble(tmpQueryMap0.get(key), 0) / timeList.size());
461 } 467 }
462 resMap.putAll(queryMap1); 468 resMap.putAll(queryMap1);
463 resMap.putAll(queryMap1_1); 469 resMap.putAll(queryMap1_1);
...@@ -470,12 +476,6 @@ public class OperationReportServiceImpl implements IOperationReportService { ...@@ -470,12 +476,6 @@ public class OperationReportServiceImpl implements IOperationReportService {
470 Double xsPercentage = ConvertUtils.getDouble(resMap.get(valueArray[1]), 0D) / ConvertUtils.getDouble(resMap.get(valueArray[0]), 0D) * 100; 476 Double xsPercentage = ConvertUtils.getDouble(resMap.get(valueArray[1]), 0D) / ConvertUtils.getDouble(resMap.get(valueArray[0]), 0D) * 100;
471 resMap.put(valueArray[1] + "_xsPercentage", (Double.isInfinite(xsPercentage) || Double.isNaN(xsPercentage)) ? null : xsPercentage); 477 resMap.put(valueArray[1] + "_xsPercentage", (Double.isInfinite(xsPercentage) || Double.isNaN(xsPercentage)) ? null : xsPercentage);
472 } 478 }
473 // 统一保留2位小数
474 for (String key: resMap.keySet()) {
475 if (DigitalUtils.isNumeric(ConvertUtils.getString(resMap.get(key)))) {
476 resMap.put(key, DigitalUtils.nPoint(resMap.get(key), 2));
477 }
478 }
479 resMap.put("sfsrwwcList", sfsrwwcList); 479 resMap.put("sfsrwwcList", sfsrwwcList);
480 resMap.put("sjsfywcList", sjsfywcList); 480 resMap.put("sjsfywcList", sjsfywcList);
481 resMap.put("sjslxjList", sjslxjList); 481 resMap.put("sjslxjList", sjslxjList);
...@@ -483,6 +483,8 @@ public class OperationReportServiceImpl implements IOperationReportService { ...@@ -483,6 +483,8 @@ public class OperationReportServiceImpl implements IOperationReportService {
483 resMap.put("yfcbList", yfcbList); 483 resMap.put("yfcbList", yfcbList);
484 resMap.put("dhcbList", dhcbList); 484 resMap.put("dhcbList", dhcbList);
485 resMap.put("yhcbList", yhcbList); 485 resMap.put("yhcbList", yhcbList);
486 // 统一保留2位小数
487 ParamUtils.retainDecimalFunc(resMap, 2);
486 resMap.put("priorityWorkItemList", priorityWorkItemList); 488 resMap.put("priorityWorkItemList", priorityWorkItemList);
487 resMap.put("hiddenDangerInspectionList", hiddenDangerInspectionList); 489 resMap.put("hiddenDangerInspectionList", hiddenDangerInspectionList);
488 return resMap; 490 return resMap;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!