运营月报 优化
正在显示
2 个修改的文件
包含
66 行增加
和
33 行删除
1 | package com.skua.modules.report.controller; | 1 | package com.skua.modules.report.controller; |
2 | 2 | ||
3 | 3 | ||
4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
4 | import com.skua.aop.annotation.CustomExceptionAnno; | 5 | import com.skua.aop.annotation.CustomExceptionAnno; |
5 | import com.skua.core.api.vo.Result; | 6 | import com.skua.core.api.vo.Result; |
6 | import com.skua.core.aspect.annotation.AutoLog; | 7 | import com.skua.core.aspect.annotation.AutoLog; |
... | @@ -11,6 +12,7 @@ import com.skua.modules.custom.service.IFCustomReportDatasetService; | ... | @@ -11,6 +12,7 @@ import com.skua.modules.custom.service.IFCustomReportDatasetService; |
11 | import com.skua.modules.report.service.IOperationReportService; | 12 | import com.skua.modules.report.service.IOperationReportService; |
12 | import com.skua.modules.report.vo.JnhbReportData; | 13 | import com.skua.modules.report.vo.JnhbReportData; |
13 | import com.skua.modules.report.vo.ProductDataVO; | 14 | import com.skua.modules.report.vo.ProductDataVO; |
15 | import com.skua.modules.system.entity.SysDepart; | ||
14 | import com.skua.modules.system.service.ISysDepartService; | 16 | import com.skua.modules.system.service.ISysDepartService; |
15 | import io.swagger.annotations.Api; | 17 | import io.swagger.annotations.Api; |
16 | import io.swagger.annotations.ApiOperation; | 18 | import io.swagger.annotations.ApiOperation; |
... | @@ -65,6 +67,13 @@ public class OperationReportController { | ... | @@ -65,6 +67,13 @@ public class OperationReportController { |
65 | public Result<Object> operationMonthReportCtrl(@RequestParam Map<String,Object> paramsMap) { | 67 | public Result<Object> operationMonthReportCtrl(@RequestParam Map<String,Object> paramsMap) { |
66 | // 请求参数 | 68 | // 请求参数 |
67 | String departId = ConvertUtils.getString(paramsMap.get("departId")); | 69 | String departId = ConvertUtils.getString(paramsMap.get("departId")); |
70 | // 如果是集团,则查询其子集 | ||
71 | if ("af880d6a13404a67825e94bc0f2f3808".equals(departId)) { | ||
72 | List<SysDepart> sysDepartList = departService.list(new QueryWrapper<SysDepart>().eq("parent_id", departId).orderByAsc("depart_order")); | ||
73 | for (SysDepart item: sysDepartList) { | ||
74 | departId += "," + item.getId(); | ||
75 | } | ||
76 | } | ||
68 | String startTime = ConvertUtils.getString(paramsMap.get("startTime")); | 77 | String startTime = ConvertUtils.getString(paramsMap.get("startTime")); |
69 | String endTime = ConvertUtils.getString(paramsMap.get("endTime")); | 78 | String endTime = ConvertUtils.getString(paramsMap.get("endTime")); |
70 | String[] departIdArray = departId.split(","); | 79 | String[] departIdArray = departId.split(","); |
... | @@ -74,6 +83,7 @@ public class OperationReportController { | ... | @@ -74,6 +83,7 @@ public class OperationReportController { |
74 | List<Map<String, Object>> resMapList = new ArrayList<>(); | 83 | List<Map<String, Object>> resMapList = new ArrayList<>(); |
75 | for (String tmpDepartId : departIdArray) { | 84 | for (String tmpDepartId : departIdArray) { |
76 | String childDepartId = departService.getChildDepartId(tmpDepartId); | 85 | String childDepartId = departService.getChildDepartId(tmpDepartId); |
86 | SysDepart tmpSysDepart = departService.getById(departId); | ||
77 | // 获取机构子集 | 87 | // 获取机构子集 |
78 | Map<String, Object> paramMap = new HashMap<>(); | 88 | Map<String, Object> paramMap = new HashMap<>(); |
79 | paramMap.put("startTime", startTime); | 89 | paramMap.put("startTime", startTime); |
... | @@ -82,6 +92,7 @@ public class OperationReportController { | ... | @@ -82,6 +92,7 @@ public class OperationReportController { |
82 | Map<String, Object> resMap = operationReportService.dataAnalysisOfMonth(paramMap); | 92 | Map<String, Object> resMap = operationReportService.dataAnalysisOfMonth(paramMap); |
83 | resMap.put("departId", tmpDepartId); | 93 | resMap.put("departId", tmpDepartId); |
84 | resMap.put("departName", sysDepartDictMap.get(tmpDepartId)); | 94 | resMap.put("departName", sysDepartDictMap.get(tmpDepartId)); |
95 | resMap.put("departType", tmpSysDepart.getDepartType()); | ||
85 | resMapList.add(resMap); | 96 | resMapList.add(resMap); |
86 | } | 97 | } |
87 | return Result.ok(resMapList); | 98 | return Result.ok(resMapList); | ... | ... |
... | @@ -233,65 +233,67 @@ public class OperationReportServiceImpl implements IOperationReportService { | ... | @@ -233,65 +233,67 @@ public class OperationReportServiceImpl implements IOperationReportService { |
233 | List<String> departIdList = Arrays.asList(departId.split(",")); | 233 | List<String> departIdList = Arrays.asList(departId.split(",")); |
234 | // 翻译 | 234 | // 翻译 |
235 | Map<String, String> sysDepartDictMap = businessService.dictMap("sys_depart", departIdList); | 235 | Map<String, String> sysDepartDictMap = businessService.dictMap("sys_depart", departIdList); |
236 | // reitId => 展示字段名称 + dataTime时间长度 + dataValue数据转换 | ||
236 | Map<String, String[]> dictMap0 = new LinkedHashMap<String, String[]>(){{ | 237 | Map<String, String[]> dictMap0 = new LinkedHashMap<String, String[]>(){{ |
237 | // 污水水量 | 238 | // 污水水量(吨 => 万吨) |
238 | put("1816743130490388481", new String[]{"wssl", "10"}); | 239 | put("1816743130490388481", new String[]{"wssl", "10", "/10000"}); |
239 | // 收费水量 | 240 | // 收费水量 |
240 | put("1818936220739293185", new String[]{"sfsl", "7"}); | 241 | put("1818936220739293185", new String[]{"sfsl", "7", ""}); |
241 | // 生产供水量 | 242 | // 生产供水量(吨 => 万吨) |
242 | put("1818218432697643010", new String[]{"scgsl", "10"}); | 243 | put("1818218432697643010", new String[]{"scgsl", "10", "/10000"}); |
243 | // 污泥处置量 | 244 | // 污泥处置量(吨 => 万吨) |
244 | put("1910571063704104961", new String[]{"wnczl", "7"}); | 245 | put("1910571063704104961", new String[]{"wnczl", "7", "/10000"}); |
245 | // 实际水费 | 246 | // 实际水费 |
246 | put("1912415992428384257", new String[]{"sjsf", "7"}); | 247 | put("1912415992428384257", new String[]{"sjsf", "7", ""}); |
247 | // 实际水量 | 248 | // 实际水量 |
248 | put("1818936221372633089", new String[]{"sjsl", "7"}); | 249 | put("1818936221372633089", new String[]{"sjsl", "7", ""}); |
249 | // 实际药费 | 250 | // 实际药费(元=>万元) |
250 | put("1818936218910576642", new String[]{"sjyf", "7"}); | 251 | put("1818936218910576642", new String[]{"sjyf", "7", "/10000"}); |
251 | // 实际电耗 | 252 | // 实际电耗 |
252 | put("1818936219699105793", new String[]{"sjdh", "7"}); | 253 | put("1818936219699105793", new String[]{"sjdh", "7", ""}); |
253 | // 实际药耗 | 254 | // 实际药耗 |
254 | put("1818936218491146241", new String[]{"sjyh", "7"}); | 255 | put("1818936218491146241", new String[]{"sjyh", "7", ""}); |
255 | }}; | 256 | }}; |
256 | CaseWhen caseWhen0 = new CaseWhen(); | 257 | CaseWhen caseWhen0 = new CaseWhen(); |
257 | for (Map.Entry<String, String[]> entry: dictMap0.entrySet()) { | 258 | for (Map.Entry<String, String[]> entry: dictMap0.entrySet()) { |
258 | String reitId = entry.getKey(); | 259 | String reitId = entry.getKey(); |
259 | String alias = entry.getValue()[0]; | 260 | String alias = entry.getValue()[0]; |
260 | int timeLength = Integer.parseInt(entry.getValue()[1]); | 261 | int timeLength = Integer.parseInt(entry.getValue()[1]); |
261 | caseWhen0.selectCaseWhen("reit_id = '" + reitId + "' and data_time >= '" + startTime.substring(0, timeLength) + "' and data_time <= '" + endTime.substring(0, timeLength) + "'", "item_value", "0", alias); | 262 | 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); |
262 | 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); | 263 | 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); |
263 | } | 264 | } |
264 | QueryWrapper<?> queryWrapper0 = new QueryWrapper<>(); | 265 | QueryWrapper<?> queryWrapper0 = new QueryWrapper<>(); |
265 | queryWrapper0.in("reit_id", dictMap0.keySet()) | 266 | queryWrapper0.in("reit_id", dictMap0.keySet()) |
266 | .in("depart_id", departIdList); | 267 | .in("depart_id", departIdList); |
267 | Map<String, Object> queryMap0 = baseService.queryForMap("select " + caseWhen0.print() + " from f_report_itemv", queryWrapper0); | 268 | Map<String, Object> queryMap0 = baseService.queryForMap("select " + caseWhen0.print() + " from f_report_itemv", queryWrapper0); |
268 | // 年度目标 | 269 | // 年度目标 |
269 | Map<String, String> dictMap1 = new LinkedHashMap<String, String>(){{ | 270 | // 数据库字段 => 展示字段名称 + 对比数据展示字段名称 |
271 | Map<String, String[]> dictMap1 = new LinkedHashMap<String, String[]>(){{ | ||
270 | // 目标水量 | 272 | // 目标水量 |
271 | put("target_water", "mbsl"); | 273 | put("target_water", new String[]{"mbsl", "sjsl"}); |
272 | // 目标水费 | 274 | // 目标水费 |
273 | put("target_cost", "mbsf"); | 275 | put("target_cost", new String[]{"mbsf", "sjsf"}); |
274 | // 目标电费 | 276 | // 目标电费 |
275 | put("target_power_cost", "mbdf"); | 277 | put("target_power_cost", new String[]{"mbdf", "sjdf"}); |
276 | // 目标药费 | 278 | // 目标药费(万元) |
277 | put("target_drug * target_water * 10000", "mbyf"); | 279 | put("target_drug * target_water", new String[]{"mbyf", "sjyf"}); |
278 | // 目标电耗 | 280 | // 目标电耗 |
279 | put("target_power", "mbdh"); | 281 | put("target_power", new String[]{"mbdh", "sjdh"}); |
280 | // 目标药耗 | 282 | // 目标药耗 |
281 | put("target_drug", "mbyh"); | 283 | put("target_drug", new String[]{"mbyh", "sjyh"}); |
282 | }}; | 284 | }}; |
283 | QueryWrapper<?> queryWrapper1 = new QueryWrapper<>(); | 285 | QueryWrapper<?> queryWrapper1 = new QueryWrapper<>(); |
284 | queryWrapper1.in("depart_id", departIdList); | 286 | queryWrapper1.in("depart_id", departIdList); |
285 | CaseWhen caseWhen1 = new CaseWhen(); | 287 | CaseWhen caseWhen1 = new CaseWhen(); |
286 | for (Map.Entry<String, String> entry: dictMap1.entrySet()) { | 288 | for (Map.Entry<String, String[]> entry: dictMap1.entrySet()) { |
287 | caseWhen1.selectCaseWhen("target_year = '" + endTime.substring(0, 4) + "'", entry.getKey(), "0", entry.getValue()); | 289 | caseWhen1.selectCaseWhen("target_year = '" + endTime.substring(0, 4) + "'", entry.getKey(), "0", entry.getValue()[0]); |
288 | caseWhen1.selectCaseWhen("target_year = '" + timeArray[1].substring(0, 4) + "'", entry.getKey(), "0", "tb_" + entry.getValue()); | 290 | caseWhen1.selectCaseWhen("target_year = '" + timeArray[1].substring(0, 4) + "'", entry.getKey(), "0", "tb_" + entry.getValue()[0]); |
289 | } | 291 | } |
290 | Map<String, Object> queryMap1 = baseService.queryForMap("select " + caseWhen1.print() + " from report_target_config", queryWrapper1); | 292 | Map<String, Object> queryMap1 = baseService.queryForMap("select " + caseWhen1.print() + " from report_target_config", queryWrapper1); |
291 | // 实际电费信息 | 293 | // 实际电费信息(元=>万元) |
292 | Map<String, String> dictMap2 = new LinkedHashMap<String, String>(){{ | 294 | Map<String, String> dictMap2 = new LinkedHashMap<String, String>(){{ |
293 | // 实际电费 | 295 | // 实际电费 |
294 | put("cost", "sjdf"); | 296 | put("cost/10000", "sjdf"); |
295 | }}; | 297 | }}; |
296 | QueryWrapper<?> queryWrapper2 = new QueryWrapper<>(); | 298 | QueryWrapper<?> queryWrapper2 = new QueryWrapper<>(); |
297 | queryWrapper2.in("depart_id", departIdList); | 299 | queryWrapper2.in("depart_id", departIdList); |
... | @@ -413,16 +415,36 @@ public class OperationReportServiceImpl implements IOperationReportService { | ... | @@ -413,16 +415,36 @@ public class OperationReportServiceImpl implements IOperationReportService { |
413 | }); | 415 | }); |
414 | // 封装结果集 | 416 | // 封装结果集 |
415 | Map<String, Object> resMap = new LinkedHashMap<>(); | 417 | Map<String, Object> resMap = new LinkedHashMap<>(); |
416 | for (String key: queryMap0.keySet()) { | 418 | // 合并 电费信息 |
417 | resMap.put(key, queryMap0.get(key)); | 419 | Map<String, Object> queryMap0_2 = new LinkedHashMap<String, Object>() {{ |
420 | putAll(queryMap0); | ||
421 | putAll(queryMap2); | ||
422 | }}; | ||
423 | for (String key: queryMap0_2.keySet()) { | ||
424 | resMap.put(key, queryMap0_2.get(key)); | ||
418 | if (key.startsWith("tb_")) { | 425 | if (key.startsWith("tb_")) { |
419 | resMap.put(key + "_avg", ConvertUtils.getDouble(queryMap0.get(key), 0) / timeListTb.size()); | 426 | // 补充平均值信息 |
427 | resMap.put(key + "_avg", ConvertUtils.getDouble(queryMap0_2.get(key), 0) / timeListTb.size()); | ||
428 | // 计算同比百分比 | ||
429 | String srcKey = key.replaceAll("tb_", ""); | ||
430 | double tbPercentage = (ConvertUtils.getDouble(queryMap0_2.get(srcKey), 0D) - ConvertUtils.getDouble(queryMap0_2.get(key), 0D)) / ConvertUtils.getDouble(queryMap0_2.get(key), 0D) * 100; | ||
431 | resMap.put(srcKey + "_tbPercentage", tbPercentage); | ||
420 | } else { | 432 | } else { |
421 | resMap.put(key + "_avg", ConvertUtils.getDouble(queryMap0.get(key), 0) / timeList.size()); | 433 | resMap.put(key + "_avg", ConvertUtils.getDouble(queryMap0_2.get(key), 0) / timeList.size()); |
422 | } | 434 | } |
423 | } | 435 | } |
424 | resMap.putAll(queryMap1); | 436 | resMap.putAll(queryMap1); |
425 | resMap.putAll(queryMap2); | 437 | // 计算完成年度目标情况 |
438 | for (String[] valueArray: dictMap1.values()) { | ||
439 | double percentage = ConvertUtils.getDouble(resMap.get(valueArray[1]), 0D) / ConvertUtils.getDouble(resMap.get(valueArray[0]), 0D) * 100; | ||
440 | resMap.put(valueArray[1] + "_targetPercentage", percentage); | ||
441 | } | ||
442 | // 统一保留2位小数 | ||
443 | for (String key: resMap.keySet()) { | ||
444 | if (DigitalUtils.isNumeric(ConvertUtils.getString(resMap.get(key)))) { | ||
445 | resMap.put(key, DigitalUtils.nPoint(resMap.get(key), 2)); | ||
446 | } | ||
447 | } | ||
426 | resMap.put("sfwwcList", sfwwcList); | 448 | resMap.put("sfwwcList", sfwwcList); |
427 | resMap.put("sfywcList", sfywcList); | 449 | resMap.put("sfywcList", sfywcList); |
428 | resMap.put("sjslxjList", sjslxjList); | 450 | resMap.put("sjslxjList", sjslxjList); | ... | ... |
-
请 注册 或 登录 后发表评论