ScreenDataController.java 63.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253
package com.skua.modules.threedimensional.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.google.common.collect.MapDifference;
import com.google.common.collect.Maps;
import com.skua.modules.alarmtmp.entity.SysFactoryDevice;
import com.skua.modules.alarmtmp.service.ISysFactoryDeviceService;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.context.BaseContextHandler;
import com.skua.core.context.SpringContextUtils;
import com.skua.core.service.IFactoryInfoService;
import com.skua.core.util.ConvertUtils;
import com.skua.core.util.DateUtils;
import com.skua.modules.algorithm.service.ISysAlgorithmLibraryService;
import com.skua.modules.algorithm.service.ISysAlgorithmStatisticsLibraryService;
import com.skua.modules.algorithm.vo.SysAlgorithmStatisticsLibraryVO;
import com.skua.modules.algorithm.vo.SysAlgorithmStatisticsResultChartsVO;
import com.skua.modules.algorithm.vo.SysAlgorithmStatisticsResultNumberVO;
import com.skua.modules.algorithm.vo.SysAlgorithmStatisticsResultVO;
import com.skua.modules.flow.utils.ObjectUtil;
import com.skua.modules.flow.utils.StringUtil;
import com.skua.modules.system.datestandard.service.ISysMonitorMetricInfoService;
import com.skua.modules.system.entity.SysDepart;
import com.skua.modules.system.entity.SysFactoryInfo;
import com.skua.modules.system.service.ISysDepartService;
import com.skua.modules.system.service.ISysFactoryInfoService;
import com.skua.modules.system.vo.SysFactoryInfo.SysFactoryInfoVO;
import com.skua.modules.threedimensional.service.IDataCountDayService;
import com.skua.modules.threedimensional.service.IScreenDataService;
import com.skua.modules.threedimensional.vo.DataParams;
import com.skua.modules.threedimensional.vo.StatisticsParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author sunjy
 * @date 2021/10/20 9:34
 * 大屏借口
 */
@Slf4j
@Api(tags = "大屏接口")
@RestController
@RequestMapping("/screendata")
public class ScreenDataController {

    @Autowired
    private IScreenDataService screenDataService;
    @Autowired
    private ISysAlgorithmStatisticsLibraryService sysAlgorithmStatisticsLibraryService;
    @Autowired
    private ISysDepartService sysDepartService;
    @Autowired
    private ISysFactoryInfoService sysFactoryInfoService;
    @Autowired
    public ISysAlgorithmLibraryService sysAlgorithmLibraryService;
    @Autowired
    private IDataCountDayService dataCountDayService;
    @Autowired
    private ISysFactoryDeviceService sysFactoryDeviceService;

    /**
     * 获取累计流量
     *
     * @param departId
     * @param req
     * @return
     */
    @AutoLog(value = "污水处理情况")
    @ApiOperation(value = "污水处理情况", notes = "污水处理情况")
    @GetMapping(value = "/getWsclqk")
    public Result<Map<String, Object>> getWsclqk(String departId,
                                                 HttpServletRequest req) {

        Result<Map<String, Object>> result = new Result<Map<String, Object>>();
        Map<String, Object> resultMap = new HashMap<String, Object>();
        JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
        if (!StringUtils.hasText(departId)) {//如果厂站为空,查询曹县厂
            departId = "f2df9193c8bc4e7a9cef0e4b98dd9e95";
        }
        String startDate = DateUtils.getTodayOrMonthDate("day") + " 00:00:00";
        Map<String, Object> map = screenDataService.getDifferData(startDate, "JSLL,CSLL", departId, "differ", masterDB);
        Calendar calendar = Calendar.getInstance();
        int hours = calendar.get(calendar.HOUR_OF_DAY);
        //获取设计处理规模
        List<Map<String, Object>> factoryList = new ArrayList<Map<String, Object>>();
        factoryList.addAll(masterDB.queryForList("select pro_scale from sys_factory_info f where f.depart_id = '" + departId + "'"));
        if (factoryList.size() > 0) {
            String sjgm = factoryList.get(0).get("pro_scale").toString();
            Double sjgmDouble = Double.parseDouble(sjgm) * 10000;
            resultMap.put("设计规模", sjgmDouble.toString());
            NumberFormat numberFormat = NumberFormat.getInstance();
            // 设置精确到小数点后1位
            numberFormat.setMaximumFractionDigits(2);
            numberFormat.setGroupingUsed(false);
            if (!ObjectUtil.isEmpty(map.get("CSLL"))) {
                Double csljll = Double.parseDouble(map.get("CSLL").toString());
                String fhl = numberFormat.format(((csljll / hours) * 24) / sjgmDouble);
                resultMap.put("负荷率", fhl);
            }
        }

        resultMap.put("今日累计进水量", map.get("JSLL"));
        resultMap.put("今日累计出水量", map.get("CSLL"));

        result.setSuccess(true);
        result.setResult(resultMap);
        return result;
    }

    /**
     * app水量情况
     *
     * @param departId
     * @param req
     * @return
     */
    @AutoLog(value = "app水量情况")
    @ApiOperation(value = "app水量情况", notes = "app水量情况")
    @GetMapping(value = "/getAppSlqk")
    public Result<Map<String, Object>> getAppSlqk(String departId,
                                                  HttpServletRequest req) {

        Result<Map<String, Object>> result = new Result<Map<String, Object>>();
        Map<String, Object> resultMap = new HashMap<String, Object>();
        NumberFormat numberFormat = NumberFormat.getInstance();
        // 设置精确到小数点后1位
        numberFormat.setMaximumFractionDigits(2);
        numberFormat.setGroupingUsed(false);
        JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
        if (!StringUtils.hasText(departId)) {//如果厂站为空,查询曹县厂
            departId = "f2df9193c8bc4e7a9cef0e4b98dd9e95";
        }
        String startDate = DateUtils.getTodayOrMonthDate("day") + " 00:00:00";
        //获取今日累计水量
        Map<String, Object> map = screenDataService.getDifferData(startDate, "JSLJLL", departId, "differ", masterDB);
        //获取昨日累计水量
        String yestDate = DateUtils.getYesterday();
        Map<String, Object> yestMap = screenDataService.getHistoryData(yestDate, yestDate, "JSLL", departId, masterDB);
        if (StringUtils.hasText(yestMap.get("JSLL").toString())) {
            //昨日水量
            Double yestSl = Double.parseDouble(yestMap.get("JSLL").toString());
            resultMap.put("昨日累计水量", numberFormat.format(yestSl / 10000));
            //今日水量
            if (StringUtils.hasText(map.get("JSLL").toString())) {
                Double todaySl = Double.parseDouble(map.get("JSLL").toString());
                //环比昨日
                //String hb = numberFormat.format(((todaySl - yestSl) / yestSl) / 10000);
                String hb = numberFormat.format((todaySl - yestSl) / 10000);
                resultMap.put("环比昨日", hb);
            }

        }
        //今日水量
        if (StringUtils.hasText(map.get("JSLL").toString())) {
            Double todaySl = Double.parseDouble(map.get("JSLL").toString());
            resultMap.put("今日累计水量", numberFormat.format(todaySl / 10000));
        }

        //本月累计水量
        String monthStartDate = DateUtils.getMonthFirstOrLastDay(startDate, "start");
        Map<String, Object> monthMap = screenDataService.getDifferData(monthStartDate, "JSLL", departId, "differ", masterDB);
        if (StringUtils.hasText(monthMap.get("JSLL").toString())) {
            Double monthSl = Double.parseDouble(monthMap.get("JSLL").toString());
            resultMap.put("本月累计水量", numberFormat.format(monthSl / 10000));
        }

        //上月累计水量
        String lastMonthStartDate = DateUtils.getLastMonthOfMonth(DateUtils.getTodayOrMonthDate("month")) + "-01";
        String lastMonthEndDate = DateUtils.getLastDayOfMonth(DateUtils.getLastMonthOfMonth(DateUtils.getTodayOrMonthDate("month")));
        Map<String, Object> lastMonthMap = screenDataService.getHistoryData(lastMonthStartDate, lastMonthEndDate, "JSLJLL", departId, masterDB);
        if (StringUtils.hasText(lastMonthMap.get("JSLL").toString())) {
            //上月水量
            Double lastMonthSl = Double.parseDouble(lastMonthMap.get("JSLL").toString());
            resultMap.put("上月累计水量", numberFormat.format(lastMonthSl / 10000));
            //本月水量
            if (StringUtils.hasText(monthMap.get("JSLL").toString())) {
                Double monthSl = Double.parseDouble(monthMap.get("JSLL").toString());
                //环比上月
                String hb = numberFormat.format((monthSl - lastMonthSl) / 10000);
                resultMap.put("环比上月", hb);
            }

        }
        result.setSuccess(true);
        result.setResult(resultMap);
        return result;
    }

    /**
     * 今日水量情况
     *
     * @param departId
     * @param req
     * @return
     */
    @AutoLog(value = "今日水量情况")
    @ApiOperation(value = "今日水量情况", notes = "今日水量情况")
    @GetMapping(value = "/getTodaySl")
    public Result<Map<String, Object>> getTodaySl(String departId,
                                                  HttpServletRequest req) {

        Result<Map<String, Object>> result = new Result<Map<String, Object>>();
        Map<String, Object> resultMap = new HashMap<String, Object>();
        JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
        if (!StringUtils.hasText(departId)) {//如果厂站为空,查询曹县厂
            departId = "f2df9193c8bc4e7a9cef0e4b98dd9e95";
        }
        String startDate = DateUtils.getTodayOrMonthDate("day") + " 00:00:00";
        //累计进水、累计出水
        Map<String, Object> map = screenDataService.getDifferData(startDate, "JSLL,CSLL", departId, "differ", masterDB);
        //瞬时进水、瞬时出水
        Map<String, Object> mapss = screenDataService.getDifferData(startDate, "JSLL,CSLL", departId, "avg", masterDB);

        resultMap.put("今日累计进水量", map.get("JSLL"));
        resultMap.put("今日累计出水量", map.get("CSLL"));
        resultMap.put("今日瞬时进水量", mapss.get("JSLL"));
        resultMap.put("今日瞬时出水量", mapss.get("CSLL"));

        result.setSuccess(true);
        result.setResult(resultMap);
        return result;
    }


    /**
     * 今日水量情况
     *
     * @param req GZGSDH
     * @return
     */

    @AutoLog(value = "各子公司电耗")
    @ApiOperation(value = "各子公司电耗", notes = "各子公司电耗")
    @PostMapping(value = "/getFactoryDH")
    public Result<Map<String, Object>> getFactoryDH(@RequestBody JSONObject jsonObject,
                                                    HttpServletRequest req) {

        Result<Map<String, Object>> result = new Result<Map<String, Object>>();
        Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
        //将jsonObject转sysAlgorithmStatisticsLibraryVO对象
        SysAlgorithmStatisticsLibraryVO sysAlgorithmStatisticsLibraryVO = JSONObject.toJavaObject(jsonObject, SysAlgorithmStatisticsLibraryVO.class);
        QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
        sysDepartQueryWrapper.eq("del_flag", 1).eq("depart_type", 1)
                .select("id,depart_name");
        List<Map<String, Object>> departMapList = sysDepartService.listMaps(sysDepartQueryWrapper);
        String departIds = departMapList.stream().map(map ->
                String.valueOf(map.get("id"))
        ).collect(Collectors.joining(","));
        Map departs = departMapList.stream().collect(Collectors.toMap(s -> s.get("id"), s -> s.get("depart_name")));
        if (StringUtils.isEmpty(sysAlgorithmStatisticsLibraryVO.getDepartIds())) {
            sysAlgorithmStatisticsLibraryVO.setDepartIds(departIds);
        }
        //将jsonObject转Map对象
        Map<String, Object> paramMap = JSONObject.toJavaObject(jsonObject, Map.class);
        //将paramMap集合去掉SysAlgorithmStatisticsLibraryVO对象内容
        Map<String, Object> sysAlgorithmStatisticsLibraryVOMap = JSON.parseObject(JSON.toJSONString(sysAlgorithmStatisticsLibraryVO), new TypeReference<Map<String, Object>>() {
        });
        //Maps.difference(Map, Map)用来比较两个Map以获取所有不同点
        MapDifference<String, Object> difference = Maps.difference(paramMap, sysAlgorithmStatisticsLibraryVOMap);
        // 键只存在于左边Map的映射项
        paramMap = difference.entriesOnlyOnLeft();
        SysAlgorithmStatisticsResultVO sysAlgorithmStatisticsResultVO = null;
        try {
            sysAlgorithmStatisticsResultVO = sysAlgorithmStatisticsLibraryService.statistics(sysAlgorithmStatisticsLibraryVO, new HashMap<>());
            SysAlgorithmStatisticsResultChartsVO charts = sysAlgorithmStatisticsResultVO.getCharts();
            List<String> xLine = charts.getXLine();
            Map<String, List<Double>> dataMap = null;//charts.getDataMap();


            List<Double> DSDHList = dataMap.get("DSDH");
            List<Double> HDLList = dataMap.get("HDL");
            List<Double> inWaterList = dataMap.get("进水");
            if (DSDHList.size() > 0) {

                List dList = new ArrayList();
                List zList = new ArrayList();
                List gList = new ArrayList();
                List pgList = new ArrayList();
                for (int i = 0; i < DSDHList.size(); i++) {
                    Double dsdh = DSDHList.get(i);
                    Double HDL = HDLList.get(i);
                    Double inWater = inWaterList.get(i);
                    String departName = String.valueOf(departs.get(xLine.get(i)));

                    HashMap<String, Object> dataResultMap = new HashMap<>();
                    dataResultMap.put("HDL", HDL);
                    dataResultMap.put("DSDH", dsdh);
                    dataResultMap.put("进水", inWater);
                    dataResultMap.put("departName", departName);
                    dataResultMap.put("departId", xLine.get(i));

                    if (dsdh < 0.4) {
                        dataResultMap.put("status", "低电耗");
                        dList.add(dataResultMap);
                    } else if (0.4 <= dsdh && dsdh <= 0.5) {
                        dataResultMap.put("status", "正常电耗");
                        zList.add(dataResultMap);
                    } else if (0.5 < dsdh && dsdh <= 0.7) {
                        dataResultMap.put("status", "偏高电耗");
                        pgList.add(dataResultMap);
                    } else if (0.7 < dsdh) {
                        dataResultMap.put("status", "高电耗");
                        gList.add(dataResultMap);
                    }

                }

                resultMap.put("d", dList.size());
                resultMap.put("z", zList.size());
                resultMap.put("g", gList.size());
                resultMap.put("pg", pgList.size());
                resultMap.put("total", pgList.size() + gList.size() + zList.size() + dList.size());
                resultMap.put("dList", dList);
                resultMap.put("zList", zList);
                resultMap.put("gList", gList);
                resultMap.put("pgList", pgList);
                result.setSuccess(true);
                result.setResult(resultMap);
            }


        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }


    /**
     * 今日水量情况
     *
     * @param req GZGSYH
     * @param req GLDSYH
     * @return
     */

    @AutoLog(value = "各子公司吨水药耗")
    @ApiOperation(value = "各子公司吨水药耗", notes = "各子公司吨水药耗")
    @PostMapping(value = "/getFactoryYH")
    public Result getFactoryYH(@RequestBody JSONObject jsonObject,
                               HttpServletRequest req) {

        Result result = new Result();

        //将jsonObject转sysAlgorithmStatisticsLibraryVO对象
        SysAlgorithmStatisticsLibraryVO sysAlgorithmStatisticsLibraryVO = JSONObject.toJavaObject(jsonObject, SysAlgorithmStatisticsLibraryVO.class);
        QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
        sysDepartQueryWrapper.eq("del_flag", 1).eq("depart_type", 1)
                .select("id,depart_name");
        List<SysDepart> departMapList = sysDepartService.list(sysDepartQueryWrapper);
        String departIds = departMapList.stream().map(map ->
                String.valueOf(map.getId())
        ).collect(Collectors.joining(","));

        Map<String, String> departMaps = departMapList.stream().collect(Collectors.toMap(SysDepart::getId, SysDepart::getDepartName));
        if (StringUtils.isEmpty(sysAlgorithmStatisticsLibraryVO.getDepartIds())) {
            sysAlgorithmStatisticsLibraryVO.setDepartIds(departIds);
        }


        //将jsonObject转Map对象
        Map<String, Object> paramMap = JSONObject.toJavaObject(jsonObject, Map.class);
        //将paramMap集合去掉SysAlgorithmStatisticsLibraryVO对象内容
        Map<String, Object> sysAlgorithmStatisticsLibraryVOMap = JSON.parseObject(JSON.toJSONString(sysAlgorithmStatisticsLibraryVO), new TypeReference<Map<String, Object>>() {
        });
        //Maps.difference(Map, Map)用来比较两个Map以获取所有不同点
        MapDifference<String, Object> difference = Maps.difference(paramMap, sysAlgorithmStatisticsLibraryVOMap);
        // 键只存在于左边Map的映射项
        paramMap = difference.entriesOnlyOnLeft();
        SysAlgorithmStatisticsResultVO sysAlgorithmStatisticsResultVO = null;

        try {

            List<Map<String, Object>> resultList = new ArrayList();
            for (Map.Entry<String, String> entry : departMaps.entrySet()) {
                Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
                String departId = entry.getKey();
                //todo 多厂循环调配置接口速度问题,后期优化
                if (!"f2df9193c8bc4e7a9cef0e4b98dd9e95".equals(departId)) {
                    continue;
                }
                sysAlgorithmStatisticsLibraryVO.setDepartIds(departId);
                sysAlgorithmStatisticsResultVO = sysAlgorithmStatisticsLibraryService.statistics(sysAlgorithmStatisticsLibraryVO, new HashMap<>());
                Map<String, SysAlgorithmStatisticsResultNumberVO> number = sysAlgorithmStatisticsResultVO.getNumber();
                resultMap.put("departId", departId);
                resultMap.put("departName", entry.getValue());
                SysAlgorithmStatisticsResultNumberVO jsVo = number.get("进水");
                Double jsVovalue = getDouble(jsVo.getValue() + "");
                Double jsVovalueHb = getDouble(jsVo.getValueHb() + "");
                Double jsVovalueTb = getDouble(jsVo.getValueTb() + "");
                for (Map.Entry<String, SysAlgorithmStatisticsResultNumberVO> resultNumberVOEntry : number.entrySet()) {
                    String key = resultNumberVOEntry.getKey();
                    if (key.contains("YYLB")) {
                        SysAlgorithmStatisticsResultNumberVO vo = resultNumberVOEntry.getValue();
                        Double value = getDouble(vo.getValue() + "");
                        Double valueHb = getDouble(vo.getValueHb() + "");
                        Double valueTb = getDouble(vo.getValueTb() + "");
                        String unit = vo.getUnit();
                        double dsYh = ConvertUtils.getDouble(value / jsVovalue, 0.0, 2);
                        double dsYhHb = ConvertUtils.getDouble(valueHb / jsVovalueHb, 0.0, 2);
                        double dsYhTb = ConvertUtils.getDouble(valueTb / jsVovalueTb, 0.0, 2);
                        String replace = key.replace("YYLB", "DSYH");
                        SysAlgorithmStatisticsResultNumberVO newVo = new SysAlgorithmStatisticsResultNumberVO();
                        newVo.setValue(dsYh);
                        newVo.setValueHb(dsYhHb);
                        newVo.setValueTb(dsYhTb);
                        newVo.setUnit(unit);
                        number.put(replace, newVo);
                    }

                }
                resultMap.put("number", number);
                resultList.add(resultMap);
            }


            result.setResult(resultList);


        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }


    /**
     * @param departId
     * @param req
     * @return
     */
    @AutoLog(value = "数字指挥中心-运行负荷率分析")
    @ApiOperation(value = "数字指挥中心-运行负荷率分析", notes = "数字指挥中心-运行负荷率分析")
    @GetMapping(value = "/factoryFhl")
    public Result<Map<String, Object>> factoryFhl(String departId, String month,
                                                  HttpServletRequest req) {

        Result<Map<String, Object>> result = new Result<Map<String, Object>>();
        Map<String, Object> resultMap = new HashMap<String, Object>();
        JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
        if (org.apache.commons.lang3.StringUtils.isEmpty(departId)) {
            departId = BaseContextHandler.getDeparts();
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            sysDepartQueryWrapper.eq("del_flag", 1).eq("depart_type", 1).in("id", Lists.newArrayList(departId.split(",")))
                    .select("id,depart_name");
            List<Map<String, Object>> departMapList = sysDepartService.listMaps(sysDepartQueryWrapper);
            departId = departMapList.stream().map(map ->
                    String.valueOf(map.get("id"))
            ).collect(Collectors.joining(","));
        }
        String thisMonth = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
        String startDate = DateUtils.getTodayOrMonthDate("day") + " 00:00:00";
        List<Map<String, Object>> fhlMaps = screenDataService.beforeTodayAvgFhl(departId, month, masterDB);
        //如果是当月,处理水量加上当天小时数据和实时数据
        if (!CollectionUtil.isEmpty(fhlMaps)) {
            int zcfhNum = 0;
            int dfhNum = 0;
            int cfhNum = 0;
            for (Map<String, Object> fhlMap : fhlMaps) {
                double fhl = Double.parseDouble(String.valueOf(fhlMap.getOrDefault("fhl", "0")));
                if (0.6 <= fhl && fhl <= 1.2) {
                    zcfhNum++;
                    fhlMap.put("status", "zcfh");
                } else if (0.6 > fhl) {
                    dfhNum++;
                    fhlMap.put("status", "dfh");
                } else if (1.2 < fhl) {
                    cfhNum++;
                    fhlMap.put("status", "cfh");
                }
            }
            resultMap.put("fhlMaps", fhlMaps);
            resultMap.put("zcfhNum", zcfhNum);
            resultMap.put("dfhNum", dfhNum);
            resultMap.put("cfhNum", cfhNum);
        }
        result.setSuccess(true);
        result.setResult(resultMap);
        return result;
    }


    /**
     * 今日水量情况
     *
     * @param departId
     * @param req
     * @return
     */
    @AutoLog(value = "厂区数字指挥中心-处理水量趋势")
    @ApiOperation(value = "厂区数字指挥中心-处理水量趋势", notes = "厂区数字指挥中心-处理水量趋势")
    @GetMapping(value = "/factorySLQS")
    public Result<Map<String, Object>> factorySLQS(String departId, String startTime, String endTime, String timeType,
                                                   HttpServletRequest req) {

        Result<Map<String, Object>> result = new Result<Map<String, Object>>();
        Map<String, Object> resultMap = new HashMap<String, Object>();
        JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
        if (!StringUtils.hasText(departId)) {//如果厂站为空,查询曹县厂
            departId = "f2df9193c8bc4e7a9cef0e4b98dd9e95";
        }
        String thisYear = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy"));
        String lastYear = LocalDate.now().minusYears(1).format(DateTimeFormatter.ofPattern("yyyy"));
        try {
            String formatStartTime = DateUtils.formatAddTime(startTime, "yyyy-MM-dd", Calendar.YEAR, -1);
            String formatEndTime = DateUtils.formatAddTime(endTime, "yyyy-MM-dd", Calendar.YEAR, -1);
            List<Map<String, Object>> fhlMaps = screenDataService.factorySLQS(departId, startTime, endTime, formatStartTime, formatEndTime, timeType);
            List<Object> dataList = new ArrayList<>();

            if (!CollectionUtil.isEmpty(fhlMaps)) {
                LinkedHashMap<String, Map<String, Object>> linkedHashMap = new LinkedHashMap<>();
                for (Map<String, Object> fhlMap : fhlMaps) {
                    String ts = String.valueOf(fhlMap.get("time"));
                    linkedHashMap.put(ts, fhlMap);
                }
                for (Map.Entry<String, Map<String, Object>> stringMapEntry : linkedHashMap.entrySet()) {
                    String time = stringMapEntry.getKey();
                    if (thisYear.equals(time.substring(0, 4))) {
                        Map<String, Object> lastYearmap = null;
                        if ("day".equals(timeType)) {
                            lastYearmap = linkedHashMap.getOrDefault(DateUtils.formatAddTime(time, "yyyy-MM-dd", Calendar.YEAR, -1), new HashMap<>());
                        } else if ("month".equals(timeType)) {
                            lastYearmap = linkedHashMap.getOrDefault(DateUtils.formatAddTime(time, "yyyy-MM", Calendar.YEAR, -1), new HashMap<>());

                        }
                        HashMap<String, Object> resultdata = new HashMap<>();
                        resultdata.put("time", time);
                        resultdata.put("CLSL", stringMapEntry.getValue().getOrDefault("clsl", "0"));
                        resultdata.put("TBCLSL", lastYearmap.getOrDefault("clsl", "0"));
                        resultdata.put("FHL", stringMapEntry.getValue().getOrDefault("fhl", "0"));
                        resultdata.put("TBFHL", lastYearmap.getOrDefault("fhl", "0"));
                        dataList.add(resultdata);
                    }

                }
            }
            resultMap.put("fhlMaps", dataList);
        } catch (Exception e) {
            e.printStackTrace();
        }

        result.setSuccess(true);
        result.setResult(resultMap);
        return result;
    }


    /**
     * 今日水量情况
     *
     * @param req GZGSYH
     * @return
     */

    @AutoLog(value = "数字指挥中心削减量、削减率")
    @ApiOperation(value = "数字指挥中心削减量、削减率", notes = "数字指挥中心削减量、削减率")
    @PostMapping(value = "/getXJL")
    public Result getXJL(@RequestBody JSONObject jsonObject,
                         HttpServletRequest req) {

        Result result = new Result();

        //将jsonObject转sysAlgorithmStatisticsLibraryVO对象
        SysAlgorithmStatisticsLibraryVO sysAlgorithmStatisticsLibraryVO = JSONObject.toJavaObject(jsonObject, SysAlgorithmStatisticsLibraryVO.class);
        QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
        sysDepartQueryWrapper.eq("del_flag", 1).eq("depart_type", 1)
                .select("id,depart_name");
        List<SysDepart> departMapList = sysDepartService.list(sysDepartQueryWrapper);
        String departIds = departMapList.stream().map(map ->
                String.valueOf(map.getId())
        ).collect(Collectors.joining(","));
        Map<String, String> departMaps = departMapList.stream().collect(Collectors.toMap(SysDepart::getId, SysDepart::getDepartName));
        if (StringUtils.isEmpty(sysAlgorithmStatisticsLibraryVO.getDepartIds())) {
            sysAlgorithmStatisticsLibraryVO.setDepartIds(departIds);
        }
        //将jsonObject转Map对象
        Map<String, Object> paramMap = JSONObject.toJavaObject(jsonObject, Map.class);
        //将paramMap集合去掉SysAlgorithmStatisticsLibraryVO对象内容
        Map<String, Object> sysAlgorithmStatisticsLibraryVOMap = JSON.parseObject(JSON.toJSONString(sysAlgorithmStatisticsLibraryVO), new TypeReference<Map<String, Object>>() {
        });
        //Maps.difference(Map, Map)用来比较两个Map以获取所有不同点
        MapDifference<String, Object> difference = Maps.difference(paramMap, sysAlgorithmStatisticsLibraryVOMap);
        // 键只存在于左边Map的映射项
        paramMap = difference.entriesOnlyOnLeft();
        SysAlgorithmStatisticsResultVO sysAlgorithmStatisticsResultVO = null;
        SysAlgorithmStatisticsResultVO sysAlgorithmStatisticsResultVOTB = null;
        SysAlgorithmStatisticsResultVO sysAlgorithmStatisticsResultVOHB = null;

        try {
            //本期
            JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
            //获取统计配置
            String statisticsCode = sysAlgorithmStatisticsLibraryVO.getStatisticsCode();
            Map<String, Object> statisticsMap = masterDB.queryForMap("select * from sys_algorithm_statistics_library where statistics_code='" + statisticsCode + "'");
            if (StringUtil.isNotBlank(sysAlgorithmStatisticsLibraryVO.getStatisticsGranularity())) {
                statisticsMap.put("statistics_granularity", sysAlgorithmStatisticsLibraryVO.getStatisticsGranularity());
            }
            // statistics_type` '统计类型0数字、1统计图 趋势',
            String statisticsType = sysAlgorithmStatisticsLibraryVO.getStatisticsType();
            if (StringUtil.isNotBlank(statisticsType)) {
                statisticsMap.put("statistics_type", statisticsType);

            }
            sysAlgorithmStatisticsResultVO = null;
            //同比
            if ("1".equals(statisticsType)) {
                String startDate = sysAlgorithmStatisticsLibraryVO.getStartDate();
                String endDate = sysAlgorithmStatisticsLibraryVO.getEndDate();
                sysAlgorithmStatisticsLibraryVO.setStartDate(DateUtils.formatAddTime(startDate, "yyyy-MM-dd", Calendar.YEAR, -1));
                sysAlgorithmStatisticsLibraryVO.setEndDate(DateUtils.formatAddTime(endDate, "yyyy-MM-dd", Calendar.YEAR, -1));
                sysAlgorithmStatisticsResultVOTB = sysAlgorithmStatisticsLibraryService.statistics(sysAlgorithmStatisticsLibraryVO, new HashMap<>());
            }
            result.setResult(sysAlgorithmStatisticsResultVO);


        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    /**
     * 厂区信息自定义查询
     *
     * @return
     */
    @AutoLog(value = "厂区详细信息-厂区信息自定义查询")
    @ApiOperation(value = "厂区详细信息-厂区信息自定义查询", notes = "厂区详细信息-厂区信息自定义查询")
    @RequestMapping(value = "/getFactoryListByWrapper", method = RequestMethod.GET)
    public Result<List<SysFactoryInfoVO>> getFactoryListByWrapper(SysFactoryInfoVO
                                                                          sysFactoryInfoVO, HttpServletRequest request) {
        Result<List<SysFactoryInfoVO>> result = new Result<>();
        QueryWrapper<SysFactoryInfoVO> queryWrapper = new QueryWrapper<>();

        String departType = sysFactoryInfoVO.getDepartType();
        if (org.apache.commons.lang3.StringUtils.isNotBlank(departType)) {
            queryWrapper.in("d.depart_type", departType.split(","));
        }

        String dataDepartId = sysFactoryInfoVO.getDepartId();
        if (org.apache.commons.lang3.StringUtils.isNotBlank(dataDepartId)) {
            queryWrapper.in("d.id", dataDepartId.split(","));
        }
        queryWrapper.orderByAsc("d.depart_order");
        List<SysFactoryInfoVO> factoryInfoVOS = sysFactoryInfoService.getFactoryListByWrapper(queryWrapper);
        //查询厂站设备通道名
        List<SysFactoryDevice> sysFactoryDevices = sysFactoryDeviceService.list();
        Map<String, SysFactoryDevice> sysFactoryDeviceMap = Maps.newHashMap();
        ArrayList<String> iotIds = new ArrayList<>();
        for (SysFactoryDevice sysFactoryDevice : sysFactoryDevices) {
            String factoryId = sysFactoryDevice.getDepartId();
            sysFactoryDeviceMap.put(factoryId, sysFactoryDevice);
            iotIds.add(sysFactoryDevice.getDeviceId());
        }
        try {
            JdbcTemplate master = (JdbcTemplate) SpringContextUtils.getBean("master");
            String sql = "SELECT\n" +
                    "c.video_root_name AS area_name,\n" +
                    "d.depart_name AS depart_name,\n" +
                    "a.*\n" +
                    "FROM\n" +
                    "t_video a\n" +
                    "left JOIN t_video_relate_root b ON a.id = b.video_id\n" +
                    "left JOIN t_video_root c ON b.video_root_id = c.id\n" +
                    "left JOIN sys_depart d ON c.depart_id = d.id";
            List<Map<String, Object>> videos = master.queryForList(sql);
            Map<String, Map<String, Object>> videoData = Maps.newHashMap();
            for (Map<String, Object> video : videos) {
                String depart_id = ConvertUtils.getString(video.get("struct_dic_id"));
                videoData.put(depart_id, video);
            }
            Map<String, String> statusMap = new HashMap<>();
            Map<String, String> aiStatusMap = new HashMap<>();
            for (SysFactoryInfoVO factoryInfoVO : factoryInfoVOS) {
                String departId = factoryInfoVO.getDepartId();
                Map<String, Object> videoDataOrDefault = videoData.getOrDefault(departId, new HashMap<>());
                String ip = ConvertUtils.getString(videoDataOrDefault.get("video_ip"));
                SysFactoryDevice devices = sysFactoryDeviceMap.getOrDefault(departId, new SysFactoryDevice());
                String iotDeviceId = devices.getDeviceId();
                String ioStatus = "1";
                //流量站/水质站/雨量站的在线状态
                if ("1000".equals(factoryInfoVO.getDepartType()) || "2000".equals(factoryInfoVO.getDepartType()) || "3000".equals(factoryInfoVO.getDepartType())|| "9000".equals(factoryInfoVO.getDepartType())) {
                    {
                        ioStatus = statusMap.getOrDefault(iotDeviceId, "OFFLINE");
                        if (!"OFFLINE".equals(ioStatus)) {
                            ioStatus = "1";
                        } else {
                            ioStatus = "0";
                        }
                    }
                    //摄像头的在线状态
                } else if ("4000".equals(factoryInfoVO.getDepartType())) {
                    if (org.apache.commons.lang3.StringUtils.isNotBlank(ip)) {
                        ioStatus = aiStatusMap.getOrDefault(ip, "0");
                    }

                } else {
                    ioStatus = "1";
                }
                factoryInfoVO.setState(ioStatus);
            }
        } catch (
                Exception e) {
            e.printStackTrace();
        }
        result.success("200");
        result.setResult(factoryInfoVOS);
        return result;

    }

    /**
     * 今日水量情况
     * @param jsonObject
     * @return
     */
    @AutoLog(value = "厂区数字指挥中心费用统计")
    @ApiOperation(value = "厂区数字指挥中心费用统计", notes = "厂区数字指挥中心费用统计")
    @PostMapping(value = "/getFYTJ")
    public Result getFYTJ(@RequestBody JSONObject jsonObject) {
        Result result = new Result();
        //将jsonObject转sysAlgorithmStatisticsLibraryVO对象
        SysAlgorithmStatisticsLibraryVO sysAlgorithmStatisticsLibraryVO = JSONObject.toJavaObject(jsonObject, SysAlgorithmStatisticsLibraryVO.class);
        QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
        sysDepartQueryWrapper.eq("del_flag", 1).eq("depart_type", 1)
                .select("id,depart_name");
        List<SysDepart> departMapList = sysDepartService.list(sysDepartQueryWrapper);
        String departIds = departMapList.stream().map(map ->
                String.valueOf(map.getId())
        ).collect(Collectors.joining(","));
        Map<String, String> departMaps = departMapList.stream().collect(Collectors.toMap(SysDepart::getId, SysDepart::getDepartName));
        if (StringUtils.isEmpty(sysAlgorithmStatisticsLibraryVO.getDepartIds())) {
            sysAlgorithmStatisticsLibraryVO.setDepartIds(departIds);
        }
        //将jsonObject转Map对象
        Map<String, Object> paramMap = JSONObject.toJavaObject(jsonObject, Map.class);
        //将paramMap集合去掉SysAlgorithmStatisticsLibraryVO对象内容
        Map<String, Object> sysAlgorithmStatisticsLibraryVOMap = JSON.parseObject(JSON.toJSONString(sysAlgorithmStatisticsLibraryVO), new TypeReference<Map<String, Object>>() {
        });
        //Maps.difference(Map, Map)用来比较两个Map以获取所有不同点
        MapDifference<String, Object> difference = Maps.difference(paramMap, sysAlgorithmStatisticsLibraryVOMap);
        // 键只存在于左边Map的映射项
        paramMap = difference.entriesOnlyOnLeft();
        SysAlgorithmStatisticsResultVO sysAlgorithmStatisticsResultVO = null;
        SysAlgorithmStatisticsResultVO sysAlgorithmStatisticsResultVOTB = null;
        SysAlgorithmStatisticsResultVO sysAlgorithmStatisticsResultVOHB = null;

        try {
            //本期
            JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
            //获取统计配置
            String statisticsCode = sysAlgorithmStatisticsLibraryVO.getStatisticsCode();
            Map<String, Object> statisticsMap = masterDB.queryForMap("select * from sys_algorithm_statistics_library where statistics_code='" + statisticsCode + "'");
            //"统计粒度day、month、year
            if (StringUtil.isNotBlank(sysAlgorithmStatisticsLibraryVO.getStatisticsGranularity())) {
                statisticsMap.put("statistics_granularity", sysAlgorithmStatisticsLibraryVO.getStatisticsGranularity());
            }
            // statistics_type` '统计类型0数字、1统计图 趋势',
            String statisticsType = sysAlgorithmStatisticsLibraryVO.getStatisticsType();
            if (StringUtil.isNotBlank(statisticsType)) {
                statisticsMap.put("statistics_type", statisticsType);
            }
            String startDate = sysAlgorithmStatisticsLibraryVO.getStartDate();
            String endDate = sysAlgorithmStatisticsLibraryVO.getEndDate();
            String startDateormat = DateUtils.dateformat(startDate, "yyyy-MM");
            String endDateformat = DateUtils.dateformat(endDate, "yyyy-MM");
            sysAlgorithmStatisticsResultVO = null;//sysAlgorithmStatisticsLibraryService.statisticsDayAndFill(sysAlgorithmStatisticsLibraryVO, paramMap, statisticsMap, masterDB);
            String appendSql = "";
            if (StringUtil.isNotBlank(departIds)) {
                String[] factory = departIds.split(",");
                StringBuilder sb = new StringBuilder();
                for (String departId : factory) {
                    sb.append(",'").append(departId).append("'");
                }
                if (StringUtil.isNotBlank(sb.toString())) {
                    appendSql = "and b.depart_id in (" + sb.substring(1) + ")";
                }

            }
            String queryDFsql = "select b.depart_id,a.id itemId , a.item_code,a.item_alias,b.data_time,sum(b.item_value)item_value  from f_report_item a left join f_report_itemv b on a.id= b.reit_id where item_code = 'bydfdaca' and report_id = '0019c63fbf21dae37870d72037c01bf9' \n" +
                    "and data_time>='" + startDateormat + "' and data_time<='" + endDateformat + "'\n" + appendSql +
                    "GROUP BY b.data_time order by data_time ";
            //电费
            List<Map<String, Object>> dF = masterDB.queryForList(queryDFsql);
            LinkedHashMap<String, Object> dFMap = new LinkedHashMap<>();
            for (Map<String, Object> map : dF) {
                dFMap.put("" + map.get("data_time"), map.getOrDefault("item_value", 0));
            }
            SysAlgorithmStatisticsResultChartsVO charts = sysAlgorithmStatisticsResultVO.getCharts();
            Map<String, List<Double>> dataMap = null;//charts.getDataMap();
            List<String> xLine = charts.getXLine();
            List<Double> inWaterList = dataMap.get("进水");
            List<Double> dSDFList = new ArrayList<>();
            List<Double> dFList = new ArrayList<>();
            for (int i = 0; i < xLine.size(); i++) {
                double dfValue = ConvertUtils.getDouble(dFMap.getOrDefault(xLine.get(i), "0") + "", 0.0, 2);
                dFList.add(dfValue);
                //吨水电费
                double dSDF = ConvertUtils.getDouble(dfValue / inWaterList.get(i), 0.0, 2);
                dSDFList.add(dSDF);
            }
            dataMap.put("DF", dFList);
            dataMap.put("DSDF", dSDFList);
            result.setResult(sysAlgorithmStatisticsResultVO);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    @AutoLog(value = "能耗统计详情")
    @ApiOperation(value = "能耗统计详情", notes = "能耗统计详情")
    @PostMapping(value = "/getNHTJXQ")
    public Result<List<Map<String, Object>>> getNHTJXQ(@RequestBody JSONObject jsonObject,
                                                       HttpServletRequest req) throws Exception {
        Result<List<Map<String, Object>>> result = new Result<>();
        jsonObject.put("statisticsCode", "YJFYPZ");
        SysAlgorithmStatisticsLibraryVO sysAlgorithmStatisticsLibraryVO = JSONObject.toJavaObject(jsonObject, SysAlgorithmStatisticsLibraryVO.class);
        //将jsonObject转Map对象
        Map<String, Object> paramMap = JSONObject.toJavaObject(jsonObject, Map.class);
        //将paramMap集合去掉SysAlgorithmStatisticsLibraryVO对象内容
        Map<String, Object> sysAlgorithmStatisticsLibraryVOMap = JSON.parseObject(JSON.toJSONString(sysAlgorithmStatisticsLibraryVO), new TypeReference<Map<String, Object>>() {
        });
        //Maps.difference(Map, Map)用来比较两个Map以获取所有不同点
        MapDifference<String, Object> difference = Maps.difference(paramMap, sysAlgorithmStatisticsLibraryVOMap);
        // 键只存在于左边Map的映射项
        paramMap = difference.entriesOnlyOnLeft();
        SysAlgorithmStatisticsResultVO yjVO = sysAlgorithmStatisticsLibraryService.statistics(sysAlgorithmStatisticsLibraryVO, paramMap);
        jsonObject.put("statisticsCode", "DFPZ");
        sysAlgorithmStatisticsLibraryVO = JSONObject.toJavaObject(jsonObject, SysAlgorithmStatisticsLibraryVO.class);
        //将jsonObject转Map对象
        paramMap = JSONObject.toJavaObject(jsonObject, Map.class);
        //将paramMap集合去掉SysAlgorithmStatisticsLibraryVO对象内容
        sysAlgorithmStatisticsLibraryVOMap = JSON.parseObject(JSON.toJSONString(sysAlgorithmStatisticsLibraryVO), new TypeReference<Map<String, Object>>() {
        });
        //Maps.difference(Map, Map)用来比较两个Map以获取所有不同点
        difference = Maps.difference(paramMap, sysAlgorithmStatisticsLibraryVOMap);
        // 键只存在于左边Map的映射项
        paramMap = difference.entriesOnlyOnLeft();
        SysAlgorithmStatisticsResultVO dfVO = sysAlgorithmStatisticsLibraryService.statistics(sysAlgorithmStatisticsLibraryVO, paramMap);

        List<Map<String, Object>> yjVONumberList = yjVO.getNumberList();
        List<Map<String, Object>> dfVONumberList = dfVO.getNumberList();
        for (Map<String, Object> yjVONumberMap : yjVONumberList) {
            for (Map<String, Object> dfVONumberMap : dfVONumberList) {
                if (yjVONumberMap.get("groupField").equals(dfVONumberMap.get("groupField"))) {
                    yjVONumberMap.putAll(dfVONumberMap);
                }
            }
        }
        yjVONumberList = yjVONumberList.stream().sorted((j, i) -> {
            Double k1 = 0.0;
            Double k2 = 0.0;
            try {
                k1 = Double.parseDouble(ConvertUtils.getString(((SysAlgorithmStatisticsResultNumberVO) j.get("YJDSFY")).getValue()).replace("-", "0"));
            } catch (Exception e) {

            }
            try {
                k2 = Double.parseDouble(ConvertUtils.getString(((SysAlgorithmStatisticsResultNumberVO) i.get("YJDSFY")).getValue()).replace("-", "0"));
            } catch (Exception e) {

            }
            return k2.compareTo(k1);
        }).collect(Collectors.toList());
        int count = 1;
        for (Map<String, Object> map : yjVONumberList) {
            map.put("YJDSFYPM", count);
            count++;
        }
        yjVONumberList = yjVONumberList.stream().sorted((j, i) -> {
            Double k1 = 0.0;
            Double k2 = 0.0;
            try {
                k1 = Double.parseDouble(ConvertUtils.getString(((SysAlgorithmStatisticsResultNumberVO) j.get("DSDF")).getValue()).replace("-", "0"));
            } catch (Exception e) {

            }
            try {
                k2 = Double.parseDouble(ConvertUtils.getString(((SysAlgorithmStatisticsResultNumberVO) i.get("DSDF")).getValue()).replace("-", "0"));
            } catch (Exception e) {

            }
            return k2.compareTo(k1);
        }).collect(Collectors.toList());
        count = 1;
        for (Map<String, Object> map : yjVONumberList) {
            map.put("DSDFPM", count);
            count++;
        }
        result.setSuccess(true);
        result.setResult(yjVONumberList);
        return result;
    }

    @AutoLog(value = "各子公司吨水药耗")
    @ApiOperation(value = "各子公司吨水药耗", notes = "各子公司吨水药耗")
    @PostMapping(value = "/getFactoryYHB")
    public Result getFactoryYHB(@RequestBody JSONObject jsonObject,
                                HttpServletRequest req) throws Exception {

        Result result = new Result();
        List<SysDepart> sysDeparts = sysDepartService.list();
        Map<String, String> factoryMap = Maps.newHashMap();
        for (SysDepart sysDepart : sysDeparts) {
            factoryMap.put(sysDepart.getId(), sysDepart.getDepartName());
        }
        // Result<List<Map<String, Object>>> result = new Result<>();
        jsonObject.put("statisticsCode", "GLYHB");

        SysAlgorithmStatisticsLibraryVO sysAlgorithmStatisticsLibraryVO = JSONObject.toJavaObject(jsonObject, SysAlgorithmStatisticsLibraryVO.class);
        //将jsonObject转Map对象
        Map<String, Object> paramMap = JSONObject.toJavaObject(jsonObject, Map.class);
        //将paramMap集合去掉SysAlgorithmStatisticsLibraryVO对象内容
        Map<String, Object> sysAlgorithmStatisticsLibraryVOMap = JSON.parseObject(JSON.toJSONString(sysAlgorithmStatisticsLibraryVO), new TypeReference<Map<String, Object>>() {
        });
        //Maps.difference(Map, Map)用来比较两个Map以获取所有不同点
        MapDifference<String, Object> difference = Maps.difference(paramMap, sysAlgorithmStatisticsLibraryVOMap);
        // 键只存在于左边Map的映射项
        paramMap = difference.entriesOnlyOnLeft();
        SysAlgorithmStatisticsResultVO yjVO = sysAlgorithmStatisticsLibraryService.statistics(sysAlgorithmStatisticsLibraryVO, paramMap);
        List<Map<String, Object>> numberList = yjVO.getNumberList();
        List<Map<String, Object>> newNumberList = Lists.newArrayList();
        try {
            for (Map<String, Object> map : numberList) {
                SysAlgorithmStatisticsResultNumberVO jsVo = (SysAlgorithmStatisticsResultNumberVO) map.get("JSLJLLZ");
                Double jsVovalue = getDouble(jsVo.getValue() + "");
                Double jsVovalueHb = getDouble(jsVo.getValueHb() + "");
                Double jsVovalueTb = getDouble(jsVo.getValueTb() + "");
                Iterator<Map.Entry<String, Object>> iterator = map.entrySet().iterator();
                Map<String, Object> newMap = Maps.newTreeMap();
                newMap.putAll(map);
                newMap.put("departName", factoryMap.get(map.get("groupField")));
                while (iterator.hasNext()) {
                    Map.Entry<String, Object> resultNumberVOEntry = iterator.next();
                    String key = resultNumberVOEntry.getKey();
                    if (key.contains("YYLB")) {
                        SysAlgorithmStatisticsResultNumberVO vo = (SysAlgorithmStatisticsResultNumberVO) resultNumberVOEntry.getValue();
                        Double value = getDouble(vo.getValue() + "");
                        Double valueHb = getDouble(vo.getValueHb() + "");
                        Double valueTb = getDouble(vo.getValueTb() + "");
                        double dsYh = ConvertUtils.getDouble(value / jsVovalue, 0.0, 2);
                        double dsYhHb = ConvertUtils.getDouble(valueHb / jsVovalueHb, 0.0, 2);
                        double dsYhTb = ConvertUtils.getDouble(valueTb / jsVovalueTb, 0.0, 2);
                        String replace = key.replace("YYLB", "DSYH");
                        SysAlgorithmStatisticsResultNumberVO newVo = new SysAlgorithmStatisticsResultNumberVO();

                        //同比
                        String valueHbProportion = ("0.0".equals(dsYhHb) || isNumeric(String.valueOf((dsYh - dsYhHb) / dsYhHb))) ? "-" : String.valueOf((dsYh - dsYhHb) * 100 / dsYhHb);
                        //环比
                        String valueTbProportion = ("0.0".equals(dsYhTb) || isNumeric(String.valueOf((dsYh - dsYhTb) / dsYhTb))) ? "-" : String.valueOf((dsYh - dsYhTb) * 100 / dsYhTb);
                        valueHbProportion = valueHbProportion.replace("NaN", "-").replace("Infinity", "-");
                        valueTbProportion = valueTbProportion.replace("NaN", "-").replace("Infinity", "-");
                        newVo.setValue(dsYh);
                        newVo.setValueHb(dsYhHb);
                        newVo.setValueTb(dsYhTb);
                        newVo.setUnit("kg/吨水");
                        newVo.setValueHbProportion(valueTbProportion);
                        newVo.setValueTbProportion(valueHbProportion);
                        newMap.put(replace, newVo);
                    }
                }
                newNumberList.add(newMap);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        result.setResult(newNumberList);
        return result;
    }

    @AutoLog(value = "处理水量详情")
    @ApiOperation(value = "处理水量详情", notes = "处理水量详情")
    @PostMapping(value = "/getCLSLXQ")
    public Result<List<Map<String, Object>>> getCLSLXQ(@RequestBody JSONObject jsonObject,
                                                       HttpServletRequest req) throws Exception {
        Result<List<Map<String, Object>>> result = new Result<>();
        QueryWrapper<SysFactoryInfo> sysFactoryInfoQueryWrapper = new QueryWrapper<>();
        String departIds = ConvertUtils.getString(jsonObject.get("departIds"));
        if (!org.apache.commons.lang3.StringUtils.isBlank(departIds)) {
            sysFactoryInfoQueryWrapper.in("depart_id", Arrays.asList(departIds.split(",")));
        }
        sysFactoryInfoQueryWrapper.eq("factory_type", "1");
        sysFactoryInfoQueryWrapper.select("pro_scale*10000 as proScale", "depart_id as departId");
        List<Map<String, Object>> maps = sysFactoryInfoService.listMaps(sysFactoryInfoQueryWrapper);
        StringBuilder departIdStringBuilder = new StringBuilder();
        StringBuilder proScaleStringBuilder = new StringBuilder();
        for (Map<String, Object> map : maps) {
            departIdStringBuilder.append(",");
            departIdStringBuilder.append(map.get("departId"));
            proScaleStringBuilder.append(",");
            proScaleStringBuilder.append(map.get("proScale"));
        }
        jsonObject.put("departIds", ConvertUtils.getString(departIdStringBuilder).replaceFirst(",", ""));
        jsonObject.put("SJGM", ConvertUtils.getString(proScaleStringBuilder).replaceFirst(",", ""));
        jsonObject.put("statisticsCode", "CLSLXQ");
        SysAlgorithmStatisticsLibraryVO sysAlgorithmStatisticsLibraryVO = JSONObject.toJavaObject(jsonObject, SysAlgorithmStatisticsLibraryVO.class);
        //将jsonObject转Map对象
        Map<String, Object> paramMap = JSONObject.toJavaObject(jsonObject, Map.class);
        //将paramMap集合去掉SysAlgorithmStatisticsLibraryVO对象内容
        Map<String, Object> sysAlgorithmStatisticsLibraryVOMap = JSON.parseObject(JSON.toJSONString(sysAlgorithmStatisticsLibraryVO), new TypeReference<Map<String, Object>>() {
        });
        //Maps.difference(Map, Map)用来比较两个Map以获取所有不同点
        MapDifference<String, Object> difference = Maps.difference(paramMap, sysAlgorithmStatisticsLibraryVOMap);
        // 键只存在于左边Map的映射项
        paramMap = difference.entriesOnlyOnLeft();
        SysAlgorithmStatisticsResultVO vo = sysAlgorithmStatisticsLibraryService.statistics(sysAlgorithmStatisticsLibraryVO, paramMap);
        List<Map<String, Object>> numberList = vo.getNumberList();
        numberList = numberList.stream().sorted((j, i) -> {
            Double k1 = 0.0;
            Double k2 = 0.0;
            try {
                k1 = Double.parseDouble(ConvertUtils.getString(((SysAlgorithmStatisticsResultNumberVO) j.get("FHL")).getValue()).replace("-", "0"));
            } catch (Exception e) {

            }
            try {
                k2 = Double.parseDouble(ConvertUtils.getString(((SysAlgorithmStatisticsResultNumberVO) i.get("FHL")).getValue()).replace("-", "0"));
            } catch (Exception e) {

            }
            return k2.compareTo(k1);
        }).collect(Collectors.toList());
        int count = 1;
        for (Map<String, Object> map : numberList) {
            map.put("FHLPM", count);
            count++;
        }
        result.setSuccess(true);
        result.setResult(numberList);
        return result;
    }

    @AutoLog(value = "产泥详情")
    @ApiOperation(value = "产泥详情", notes = "产泥详情")
    @PostMapping(value = "/getCNXQ")
    public Result<List<Map<String, Object>>> getCNXQ(@RequestBody JSONObject jsonObject,
                                                     HttpServletRequest req) throws Exception {
        Result<List<Map<String, Object>>> result = new Result<>();
        jsonObject.put("statisticsCode", "CNXQ");
        SysAlgorithmStatisticsLibraryVO sysAlgorithmStatisticsLibraryVO = JSONObject.toJavaObject(jsonObject, SysAlgorithmStatisticsLibraryVO.class);
        //将jsonObject转Map对象
        Map<String, Object> paramMap = JSONObject.toJavaObject(jsonObject, Map.class);
        //将paramMap集合去掉SysAlgorithmStatisticsLibraryVO对象内容
        Map<String, Object> sysAlgorithmStatisticsLibraryVOMap = JSON.parseObject(JSON.toJSONString(sysAlgorithmStatisticsLibraryVO), new TypeReference<Map<String, Object>>() {
        });
        //Maps.difference(Map, Map)用来比较两个Map以获取所有不同点
        MapDifference<String, Object> difference = Maps.difference(paramMap, sysAlgorithmStatisticsLibraryVOMap);
        // 键只存在于左边Map的映射项
        paramMap = difference.entriesOnlyOnLeft();
        SysAlgorithmStatisticsResultVO vo = sysAlgorithmStatisticsLibraryService.statistics(sysAlgorithmStatisticsLibraryVO, paramMap);
        List<Map<String, Object>> numberList = vo.getNumberList();
        result.setSuccess(true);
        result.setResult(numberList);
        return result;
    }

    @AutoLog(value = "电耗详情")
    @ApiOperation(value = "电耗详情", notes = "电耗详情")
    @PostMapping(value = "/getDHXQ")
    public Result<List<Map<String, Object>>> getDHXQ(@RequestBody JSONObject jsonObject,
                                                     HttpServletRequest req) throws Exception {
        Result<List<Map<String, Object>>> result = new Result<>();
        jsonObject.put("statisticsCode", "DHXQ");
        SysAlgorithmStatisticsLibraryVO sysAlgorithmStatisticsLibraryVO = JSONObject.toJavaObject(jsonObject, SysAlgorithmStatisticsLibraryVO.class);
        //将jsonObject转Map对象
        Map<String, Object> paramMap = JSONObject.toJavaObject(jsonObject, Map.class);
        //将paramMap集合去掉SysAlgorithmStatisticsLibraryVO对象内容
        Map<String, Object> sysAlgorithmStatisticsLibraryVOMap = JSON.parseObject(JSON.toJSONString(sysAlgorithmStatisticsLibraryVO), new TypeReference<Map<String, Object>>() {
        });
        //Maps.difference(Map, Map)用来比较两个Map以获取所有不同点
        MapDifference<String, Object> difference = Maps.difference(paramMap, sysAlgorithmStatisticsLibraryVOMap);
        // 键只存在于左边Map的映射项
        paramMap = difference.entriesOnlyOnLeft();
        SysAlgorithmStatisticsResultVO vo = sysAlgorithmStatisticsLibraryService.statistics(sysAlgorithmStatisticsLibraryVO, paramMap);
        List<Map<String, Object>> numberList = vo.getNumberList();
        numberList = numberList.stream().sorted((j, i) -> {
            Double k1 = 0.0;
            Double k2 = 0.0;
            try {
                k1 = Double.parseDouble(ConvertUtils.getString(((SysAlgorithmStatisticsResultNumberVO) j.get("DSDHTB")).getValue()).replace("-", "0"));
            } catch (Exception e) {

            }
            try {
                k2 = Double.parseDouble(ConvertUtils.getString(((SysAlgorithmStatisticsResultNumberVO) i.get("DSDHTB")).getValue()).replace("-", "0"));
            } catch (Exception e) {

            }
            return k2.compareTo(k1);
        }).collect(Collectors.toList());
        int count = 1;
        for (Map<String, Object> map : numberList) {
            map.put("DSDHTBPM", count);
            count++;
        }
        result.setSuccess(true);
        result.setResult(numberList);
        return result;
    }

/**
 * 功能描述: <br>运营日报进出水初始化
 * @Param:
        * @Return:
        * @Author: [Gao Ran]
        * @Date: 2022/1/19 17:57
 */
    @AutoLog(value = "//运营日报进出水初始化")
    @ApiOperation(value = "//运营日报进出水初始化", notes = "//运营日报进出水初始化")
    @GetMapping(value = "/test")
    public Result test(String startTime, String endTime,
                       HttpServletRequest req) throws Exception {
        log.info(String.format("定时日报表服务开始:" + DateUtils.getTimestamp()));
        List<String> dateList = DateUtils.sliceUpDateRange(startTime, endTime, "month");
        // String startTime = DateUtils.getMonthFirstOrLastDay(DateUtils.formatDateTime(),"start");
        //10 * * * * ?
        // 0 0 2 * * ?
        Map<String, String> code2ItemCodeMap = Maps.newHashMap();
        code2ItemCodeMap.put("JSLJLL", "jsl12e8");
        code2ItemCodeMap.put("CSLJLL", "clsle111");
        code2ItemCodeMap.put("HSSL", "hssl1081");
        String codes = "JSLJLL,CSLJLL";
        String codeIds = "";
        for (String code : codes.split(",")) {
            codeIds += ",'" + code + "'";
        }
        JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
        for (String date : dateList) {
            List<Map<String, Object>> dataList = masterDB.queryForList("select * from sys_data_calculation where index_tag in (" + codeIds.replaceFirst(",", "") + ") and ts >='" + date + "'and ts<='" + date + "'");
            if (CollectionUtil.isEmpty(dataList)) {
                continue;
            }
            List<SysFactoryDevice> factoryDevices = sysFactoryDeviceService.list();
            Map<String, Map<String, String>> factoryDataMap = Maps.newHashMap();
            for (SysFactoryDevice factoryDevice : factoryDevices) {
                Map<String, String> dataMap = Maps.newHashMap();
                String departId = factoryDevice.getDepartId();
                for (Map<String, Object> data : dataList) {
                    String code = data.get("index_tag") + "";
                    String ts = data.get("ts") + "";
                    String itemCode = code2ItemCodeMap.get(code);
                    String value = data.getOrDefault("index_value", "0.0") + "";
                    String depart_id = data.get("depart_id") + "";
                    if (departId.equals(depart_id)) {
                        dataMap.put(itemCode, value);
                    }
                }
                factoryDataMap.put(departId, dataMap);
            }

            for (Map.Entry<String, Map<String, String>> entry : factoryDataMap.entrySet()) {
                dataCountDayService.insertOrUpdateReportData(entry.getKey(), date, entry.getValue(), "7675958885b94b8df41b7cade8b12e23");
            }
        }
        log.info(String.format("定时日报表服务结束:" + DateUtils.getTimestamp()));
        return Result.ok("初始化完成");
    }


    private static Double getDouble(String value) {
        if (StringUtil.isNotBlank(value) && !"null".equals(value) && !"-".equals(value)) {
            return ConvertUtils.getDouble(value, 0.0, 2);
        }
        return 0.0;
    }

    public static boolean isNumeric(String str) {
        String bigStr;
        try {
            bigStr = new BigDecimal(str).toString();
        } catch (Exception e) {
            return false;//异常 说明包含非数字。
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(getBetweenDate("2020-02-02", "2020-03-03"));
    }

    public static List<String> getBetweenDate(String start, String end) {
        List<String> list = new ArrayList<>();
        // LocalDate默认的时间格式为2020-02-02
        LocalDate startDate = LocalDate.parse(start);
        LocalDate endDate = LocalDate.parse(end);
        long distance = ChronoUnit.DAYS.between(startDate, endDate);
        if (distance < 1) {
            return list;
        }
        Stream.iterate(startDate, d -> d.plusDays(1)).limit(distance + 1).forEach(f -> list.add(f.toString()));
        return list;
    }

    @AutoLog(value = "获取实时数据")
    @ApiOperation(value = "获取实时数据", notes = "获取实时数据")
    @PostMapping(value = "/getRealTimeSz")
    public Result<Map<String, Object>> getRealTimeSz(@RequestBody DataParams dataParams) {
        Result<Map<String, Object>> result = new Result<>();
        Map<String, Object> map = new HashMap<>();
        result.setResult(map);
        return result;
    }

    @AutoLog(value = "获取污水用电情况")
    @ApiOperation(value = "获取污水用电情况", notes = "获取污水用电情况")
    @PostMapping(value = "/getYhdlqs")
    public Result<List<Map<String, Object>>> getYhdlqs(@RequestBody StatisticsParams statisticsParams) {
        Result<List<Map<String, Object>>> result = new Result<>();
        List<Map<String, Object>> list = new ArrayList<>();
        list = screenDataService.getYhdlqs(statisticsParams);
        result.setResult(list);
        return result;
    }

    @AutoLog(value = "污水用药情况")
    @ApiOperation(value = "污水用药情况", notes = "污水用药情况")
    @PostMapping(value = "/getYhylqs")
    public Result<List<Map<String, Object>>> getYhylqs(@RequestBody StatisticsParams statisticsParams) {
        Result<List<Map<String, Object>>> result = new Result<>();
        List<Map<String, Object>> list = new ArrayList<>();
        list = screenDataService.getYhylqs(statisticsParams);
        result.setResult(list);
        return result;
    }

}