双重预防项目-国泰新华二开定制版
heheng
2 天以前 ac8870aae3ec2b5ec5315cc668b482858195cfa4
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
package com.ruoyi.project.mobile.service;
 
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.util.StringUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.project.mobile.controller.ApiController;
import com.ruoyi.project.mobile.domain.ApiRequestHeader;
import com.ruoyi.project.mobile.domain.ApiResult;
import com.ruoyi.project.system.company.domain.Company;
import com.ruoyi.project.system.company.service.ICompanyService;
import com.ruoyi.project.system.dict.domain.DictData;
import com.ruoyi.project.system.dict.domain.DictDataSonByCompanyIndustryType;
import com.ruoyi.project.system.dict.service.IDictTypeService;
import com.ruoyi.project.system.role.service.IRoleService;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.service.IUserService;
import com.ruoyi.project.tr.dataStatistics.domain.DataStatistics;
import com.ruoyi.project.tr.dataStatistics.service.DataStatisticsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;
 
@Service
public class ApiAllDataStatisticsService extends BaseApiService {
    private static Logger logger = LoggerFactory.getLogger(ApiAllDataStatisticsService.class);
    @Autowired
    private DataStatisticsService dataStatisticsService;
    @Autowired
    private IRoleService roleService;
    @Autowired
    IUserService userService;//用户Service
    @Autowired
    private IDictTypeService dictTypeService;
    @Autowired
    private ICompanyService companyService;
 
 
    /**
     * 获取所有区域
     */
    public ApiResult getAllRegion(String str, ApiRequestHeader header) {
        //验证userId,loginName,token,deviceType,deviceId,appType 是否一致
        ApiRequestHeader requestHeader = getHeader(header);
        if (!(header.equals(requestHeader))) {
            return ApiResult.errorToken("验证userId,loginName,token,deviceType,deviceId,appType 不一致");
        }
        List<DictData> dictDataList = dictTypeService.selectDictDataByType("tr_region_list");//获取区域列表
        return ApiResult.success("请求数据成功", dictDataList);
    }
 
 
    /**
     * 根据区域账号用户名,获取区域下公司数据统计
     */
    public ApiResult getAllDataStatisticsByUserName(String str, ApiRequestHeader header) {
        //验证userId,loginName,token,deviceType,deviceId,appType 是否一致
        ApiRequestHeader requestHeader = getHeader(header);
        if (!(header.equals(requestHeader))) {
            return ApiResult.errorToken("验证userId,loginName,token,deviceType,deviceId,appType 不一致");
        }
        DataStatistics dataStatisticsByCompany = new DataStatistics();
        String userName = "";
        try {
            Map<String, String> map = new ObjectMapper().readValue(str, HashMap.class);
            String companyName = map.get("companyName");
            if (!StringUtils.isEmpty(companyName)) {
                dataStatisticsByCompany.setCompanyName(companyName);
            }
            userName = map.get("userName");
        } catch (Exception e) {
            return ApiResult.error("异常");
        }
        Set<String> stringSet = roleService.selectRoleKeys(Long.valueOf(header.userId));
        if (stringSet.contains("regionUser")
                || stringSet.contains("straightRegionUser")) {
            if (!StringUtils.isEmpty(userName)) {
                DataStatistics dataStatisticsByRegion = new DataStatistics();
//                if (stringSet.contains("straightRegionUser")) {
//                    dataStatisticsByRegion.setSelectAllCompanyHasRegion("selectAllCompanyHasRegion");//市直账号,查询所有有区域的公司
//                    dataStatisticsByCompany.setSelectAllCompanyHasRegion("selectAllCompanyHasRegion");//市直账号,查询所有有区域的公司
//                }else if (stringSet.contains("regionUser")) {
//                    dataStatisticsByRegion.setCompanyRegion(userName);
//                    dataStatisticsByRegion.setCompanyRegion(userName);
//                }
 
                if (("漯河市应急管理局").equals(userName)) {
                    dataStatisticsByRegion.setSelectAllCompanyHasRegion("selectAllCompanyHasRegion");//市直账号,查询所有有区域的公司
                    dataStatisticsByCompany.setSelectAllCompanyHasRegion("selectAllCompanyHasRegion");//市直账号,查询所有有区域的公司
                } else {
                    dataStatisticsByRegion.setCompanyRegion(userName);
                    dataStatisticsByCompany.setCompanyRegion(userName);
                }
 
                List<DataStatistics> listByRegion = dataStatisticsService.selectCompanyDataStatistics(dataStatisticsByRegion);
 
                BigDecimal seriesRiskCount = new BigDecimal(0);
                BigDecimal middleRiskCount = new BigDecimal(0);
                BigDecimal normalRiskCount = new BigDecimal(0);
                BigDecimal lowRiskCount = new BigDecimal(0);
                BigDecimal thisMonthHighDangerCount = new BigDecimal(0);
                BigDecimal thisMonthNormalDangerCount = new BigDecimal(0);
                BigDecimal unRectifyDangerCount = new BigDecimal(0);
                BigDecimal allDangers = new BigDecimal(0);
                String dangerRectifyPercent = "100%";
 
                for (DataStatistics temp : listByRegion) {
                    seriesRiskCount = seriesRiskCount.add(new BigDecimal(temp.getSeriesRiskCount()));
                    middleRiskCount = middleRiskCount.add(new BigDecimal(temp.getMiddleRiskCount()));
                    normalRiskCount = normalRiskCount.add(new BigDecimal(temp.getNormalRiskCount()));
                    lowRiskCount = lowRiskCount.add(new BigDecimal(temp.getLowRiskCount()));
                    thisMonthHighDangerCount = thisMonthHighDangerCount.add(new BigDecimal(temp.getThisMonthHighDangerCount()));
                    thisMonthNormalDangerCount = thisMonthNormalDangerCount.add(new BigDecimal(temp.getThisMonthNormalDangerCount()));
                    unRectifyDangerCount = unRectifyDangerCount.add(new BigDecimal(temp.getUnRectifyDangerCount()));
                    allDangers = allDangers.add(new BigDecimal(temp.getAllDangers()));
                }
                DataStatistics sumDataStatistics = new DataStatistics();
                sumDataStatistics.setSeriesRiskCount(seriesRiskCount.longValue());
                sumDataStatistics.setMiddleRiskCount(middleRiskCount.longValue());
                sumDataStatistics.setNormalRiskCount(normalRiskCount.longValue());
                sumDataStatistics.setLowRiskCount(lowRiskCount.longValue());
                sumDataStatistics.setThisMonthHighDangerCount(thisMonthHighDangerCount.longValue());
                sumDataStatistics.setThisMonthNormalDangerCount(thisMonthNormalDangerCount.longValue());
                sumDataStatistics.setUnRectifyDangerCount(unRectifyDangerCount.longValue());
 
                if (allDangers.longValue() != 0) {
                    BigDecimal tempBigDecimal = ApiHiddenDangerCheckService.divide((allDangers.intValue() - unRectifyDangerCount.intValue()), allDangers.intValue(), 4);
                    //下面将结果转化成百分比
                    NumberFormat percent5 = NumberFormat.getPercentInstance();
                    percent5.setMaximumFractionDigits(2);
                    dangerRectifyPercent = percent5.format(tempBigDecimal.doubleValue());
                }
                sumDataStatistics.setDangerRectifyPercent(dangerRectifyPercent);
 
                List<DataStatistics> listByCompany = new ArrayList<>();
                if (StringUtils.isEmpty(dataStatisticsByCompany.getCompanyName())) {
                    dataStatisticsByCompany.setCompanyName("");
                }
                for (DataStatistics temp : listByRegion) {
                    if (temp.getCompanyName().contains(dataStatisticsByCompany.getCompanyName())) {
                        temp.setLedgerByCompanyIdAndRiskLevelMajorUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/major");
                        temp.setLedgerByCompanyIdAndRiskLevelLargerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/larger");
                        temp.setLedgerByCompanyIdAndRiskLevelGeneralUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/general");
                        temp.setLedgerByCompanyIdAndRiskLevelLowUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/low");
 
                        temp.setDangerLedgerListByCompanyIdByThisMonthHighDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/thisMonthHighDanger");
                        temp.setDangerLedgerListByCompanyIdByThisMonthNormalDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/thisMonthNormalDanger");
                        temp.setDangerLedgerListByCompanyIdByUnRectifyDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/unRectifyDanger");
 
                        temp.setDangerPlanExecuteByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerPlanExecuteByCompanyId/" + temp.getCompanyId());
                        temp.setDangerScheduleByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerScheduleByCompanyId/" + temp.getCompanyId());
                        temp.setDangerLedgerListByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId());
                        temp.setLedgerByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId());
                        temp.setArticleByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/articleByCompanyId/" + temp.getCompanyId());
                        temp.setArticleRegulationByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/articleRegulationByCompanyId/" + temp.getCompanyId());
                        listByCompany.add(temp);
                    }
                }
 
                Map<String, Object> resultMap = new HashMap<>();
                resultMap.put("dataStatisticsList", listByCompany);
                resultMap.put("sumDataStatistics", sumDataStatistics);
                return ApiResult.success("请求数据成功", resultMap);
            } else {
                return ApiResult.error("未传输用户名userName!");
            }
        } else {
            return ApiResult.error("用户所在角色不能调用!");
        }
    }
 
 
    //获取总的数据统计
    public DataStatistics getDataStatistics(List<DataStatistics> listTotal) {
        BigDecimal seriesRiskCount = new BigDecimal(0);
        BigDecimal middleRiskCount = new BigDecimal(0);
        BigDecimal normalRiskCount = new BigDecimal(0);
        BigDecimal lowRiskCount = new BigDecimal(0);
        BigDecimal thisMonthHighDangerCount = new BigDecimal(0);
        BigDecimal thisMonthNormalDangerCount = new BigDecimal(0);
        BigDecimal unRectifyDangerCount = new BigDecimal(0);
        BigDecimal allDangers = new BigDecimal(0);
        String dangerRectifyPercent = "100%";
 
        for (DataStatistics temp : listTotal) {
            seriesRiskCount = seriesRiskCount.add(new BigDecimal(temp.getSeriesRiskCount()));
            middleRiskCount = middleRiskCount.add(new BigDecimal(temp.getMiddleRiskCount()));
            normalRiskCount = normalRiskCount.add(new BigDecimal(temp.getNormalRiskCount()));
            lowRiskCount = lowRiskCount.add(new BigDecimal(temp.getLowRiskCount()));
            thisMonthHighDangerCount = thisMonthHighDangerCount.add(new BigDecimal(temp.getThisMonthHighDangerCount()));
            thisMonthNormalDangerCount = thisMonthNormalDangerCount.add(new BigDecimal(temp.getThisMonthNormalDangerCount()));
            unRectifyDangerCount = unRectifyDangerCount.add(new BigDecimal(temp.getUnRectifyDangerCount()));
            allDangers = allDangers.add(new BigDecimal(temp.getAllDangers()));
        }
        DataStatistics sumDataStatistics = new DataStatistics();
        sumDataStatistics.setSeriesRiskCount(seriesRiskCount.longValue());
        sumDataStatistics.setMiddleRiskCount(middleRiskCount.longValue());
        sumDataStatistics.setNormalRiskCount(normalRiskCount.longValue());
        sumDataStatistics.setLowRiskCount(lowRiskCount.longValue());
        sumDataStatistics.setThisMonthHighDangerCount(thisMonthHighDangerCount.longValue());
        sumDataStatistics.setThisMonthNormalDangerCount(thisMonthNormalDangerCount.longValue());
        sumDataStatistics.setUnRectifyDangerCount(unRectifyDangerCount.longValue());
 
        if (allDangers.longValue() != 0) {
            BigDecimal tempBigDecimal = ApiHiddenDangerCheckService.divide((allDangers.intValue() - unRectifyDangerCount.intValue()), allDangers.intValue(), 4);
            //下面将结果转化成百分比
            NumberFormat percent5 = NumberFormat.getPercentInstance();
            percent5.setMaximumFractionDigits(2);
            dangerRectifyPercent = percent5.format(tempBigDecimal.doubleValue());
        }
        sumDataStatistics.setDangerRectifyPercent(dangerRectifyPercent);
        return sumDataStatistics;
    }
 
 
    /**
     * 查询总的数据统计,获取区域列表
     */
    public ApiResult getAllDataStatisticsByStraightRegion(String str, ApiRequestHeader header) {
        //验证userId,loginName,token,deviceType,deviceId,appType 是否一致
        ApiRequestHeader requestHeader = getHeader(header);
        if (!(header.equals(requestHeader))) {
            return ApiResult.errorToken("验证userId,loginName,token,deviceType,deviceId,appType 不一致");
        }
        DataStatistics query = new DataStatistics();
        query.setSelectAllCompanyHasRegion("selectAllCompanyHasRegion");//市直账号,查询所有有区域的公司
        //查询
        List<DataStatistics> listTotal = dataStatisticsService.selectCompanyDataStatistics(query);
        DataStatistics sumDataStatistics = getDataStatistics(listTotal);
 
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("sumDataStatistics", sumDataStatistics);
        List<DictData> regionList = dictTypeService.selectDictDataByType("tr_region_list");//获取区域列表
        resultMap.put("regionList", regionList);
 
//        /tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/major  //重大风险列表
//        /tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/larger  //较大风险列表
//        /tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/general  //一般风险列表
//        /tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/low  //低风险列表
//        /tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthHighDanger  //当月重大隐患
//        /tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthNormalDanger //当月一般隐患
//        /tr/dataStatisticsTotalByApp/dangerLedgerListTotal/unRectifyDanger //未整改隐患
//        /tr/dataStatisticsTotalByApp/dangerLedgerListTotal  //隐患台账
 
 
        String suffix = "?pageLevel=firstPage";
        resultMap.put("ledgerTotalAndRiskLevelMajorUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/major" + suffix);
        resultMap.put("ledgerTotalAndRiskLevelLargerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/larger" + suffix);
        resultMap.put("ledgerTotalAndRiskLevelGeneralUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/general" + suffix);
        resultMap.put("ledgerTotalAndRiskLevelLowUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/low" + suffix);
        resultMap.put("dangerLedgerListTotalByThisMonthHighDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthHighDanger" + suffix);
        resultMap.put("dangerLedgerListToatalByThisMonthNormalDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthNormalDanger" + suffix);
        resultMap.put("dangerLedgerListTotalByUnRectifyDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/unRectifyDanger" + suffix);
        resultMap.put("dangerLedgerListTotalUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal" + suffix);
 
 
        return ApiResult.success("请求数据成功", resultMap);
    }
 
 
    /**
     * 查询某个区域数据统计,获取行业类型列表
     */
    public ApiResult getAllDataStatisticsByRegion(String str, ApiRequestHeader header) {
        //验证userId,loginName,token,deviceType,deviceId,appType 是否一致
        ApiRequestHeader requestHeader = getHeader(header);
        if (!(header.equals(requestHeader))) {
            return ApiResult.errorToken("验证userId,loginName,token,deviceType,deviceId,appType 不一致");
        }
        String companyRegion = "";
        try {
            Map<String, String> map = new ObjectMapper().readValue(str, HashMap.class);
            companyRegion = map.get("companyRegion");
        } catch (Exception e) {
            return ApiResult.error("异常");
        }
        if (StringUtil.isEmpty(companyRegion)) {
            return ApiResult.error("companyRegion参数必填,不能为空!");
        }
 
        DataStatistics query = new DataStatistics();
        query.setCompanyRegion(companyRegion);
        //查询
        List<DataStatistics> listTotal = dataStatisticsService.selectCompanyDataStatistics(query);
        DataStatistics sumDataStatistics = getDataStatistics(listTotal);
 
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("sumDataStatistics", sumDataStatistics);
        List<DictData> companyIndustryTypeListTemp = dictTypeService.selectDictDataByType("company_industry_type");//获取公司行业类型列表
        List<DictData> companySubIndustryTypeByWeihua = dictTypeService.selectDictDataByType("company_sub_industry_type_by_weihua");//危化行业子分类
 
        List<DictDataSonByCompanyIndustryType> companyIndustryTypeList = new ArrayList<>();
        for (DictData temp : companyIndustryTypeListTemp) {
            DictDataSonByCompanyIndustryType dictDataSonByCompanyIndustryType = new DictDataSonByCompanyIndustryType();
            BeanUtils.copyProperties(temp, dictDataSonByCompanyIndustryType);
            if ("危化".equals(temp.getDictValue())) {
                dictDataSonByCompanyIndustryType.setCompanySubIndustryTypeList(companySubIndustryTypeByWeihua);
            }
            companyIndustryTypeList.add(dictDataSonByCompanyIndustryType);
        }
        resultMap.put("companyIndustryTypeList", companyIndustryTypeList);
 
        String suffix = "";
//      String pageLevel,第几个层级
//      String companyRegion,公司区域
//      String companyIndustryType,行业分类
//      String companySubIndustryType,行业子分类
        suffix = "?pageLevel=secondPage&companyRegion=" + companyRegion;
 
        resultMap.put("ledgerTotalAndRiskLevelMajorUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/major" + suffix);
        resultMap.put("ledgerTotalAndRiskLevelLargerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/larger" + suffix);
        resultMap.put("ledgerTotalAndRiskLevelGeneralUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/general" + suffix);
        resultMap.put("ledgerTotalAndRiskLevelLowUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/low" + suffix);
        resultMap.put("dangerLedgerListTotalByThisMonthHighDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthHighDanger" + suffix);
        resultMap.put("dangerLedgerListToatalByThisMonthNormalDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthNormalDanger" + suffix);
        resultMap.put("dangerLedgerListTotalByUnRectifyDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/unRectifyDanger" + suffix);
        resultMap.put("dangerLedgerListTotalUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal" + suffix);
 
        return ApiResult.success("请求数据成功", resultMap);
    }
 
 
    /**
     * 查询某个区域数据和某个行业数据统计
     */
    public ApiResult getAllDataStatisticsByRegionAndIndustryType(String str, ApiRequestHeader header) {
        //验证userId,loginName,token,deviceType,deviceId,appType 是否一致
        ApiRequestHeader requestHeader = getHeader(header);
        if (!(header.equals(requestHeader))) {
            return ApiResult.errorToken("验证userId,loginName,token,deviceType,deviceId,appType 不一致");
        }
        String companyRegion = "";
        String companyIndustryType = "";
        String companySubIndustryType = "";
        String companyName = "";
        try {
            Map<String, String> map = new ObjectMapper().readValue(str, HashMap.class);
            companyRegion = map.get("companyRegion");
            companyIndustryType = map.get("companyIndustryType");
            companySubIndustryType = map.get("companySubIndustryType");
            companyName = map.get("companyName");
        } catch (Exception e) {
            return ApiResult.error("异常");
        }
        if (StringUtil.isEmpty(companyRegion)) {
            return ApiResult.error("companyRegion参数必填,不能为空!");
        }
        if (StringUtil.isEmpty(companyIndustryType)) {
            return ApiResult.error("companyIndustryType参数必填,不能为空!");
        }
        DataStatistics query = new DataStatistics();
        query.setCompanyIndustry(companyIndustryType);
        query.setCompanySubIndustry(companySubIndustryType);
        query.setCompanyRegion(companyRegion);
        //查询
        List<DataStatistics> listTotal = dataStatisticsService.selectCompanyDataStatistics(query);
        DataStatistics sumDataStatistics = getDataStatistics(listTotal);
 
 
        List<DataStatistics> listQueryResultByCompanyName = new ArrayList<>();
        if (StringUtils.isEmpty(companyName)) {
            companyName = "";
        }
        for (DataStatistics temp : listTotal) {
            if (temp.getCompanyName().contains(companyName)) {
                temp.setLedgerByCompanyIdAndRiskLevelMajorUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/major");
                temp.setLedgerByCompanyIdAndRiskLevelLargerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/larger");
                temp.setLedgerByCompanyIdAndRiskLevelGeneralUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/general");
                temp.setLedgerByCompanyIdAndRiskLevelLowUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/low");
 
                temp.setDangerLedgerListByCompanyIdByThisMonthHighDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/thisMonthHighDanger");
                temp.setDangerLedgerListByCompanyIdByThisMonthNormalDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/thisMonthNormalDanger");
                temp.setDangerLedgerListByCompanyIdByUnRectifyDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/unRectifyDanger");
 
                temp.setDangerPlanExecuteByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerPlanExecuteByCompanyId/" + temp.getCompanyId());
                temp.setDangerScheduleByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerScheduleByCompanyId/" + temp.getCompanyId());
                temp.setDangerLedgerListByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId());
                temp.setLedgerByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId());
                temp.setArticleByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/articleByCompanyId/" + temp.getCompanyId());
                temp.setArticleRegulationByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/articleRegulationByCompanyId/" + temp.getCompanyId());
                listQueryResultByCompanyName.add(temp);
            }
        }
 
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("sumDataStatistics", sumDataStatistics);
        resultMap.put("dataStatisticsList", listQueryResultByCompanyName);
 
        String suffix = "";
//      String pageLevel,第几个层级
//      String companyRegion,公司区域
//      String companyIndustryType,行业分类
//      String companySubIndustryType,行业子分类
        if (StringUtil.isEmpty(companySubIndustryType)) {
            suffix = "?pageLevel=thirdPage&companyRegion=" + companyRegion + "&companyIndustryType=" + companyIndustryType;
        } else {
            suffix = "?pageLevel=thirdPage&companyRegion=" + companyRegion + "&companyIndustryType=" + companyIndustryType + "&companySubIndustryType=" + companySubIndustryType;
        }
 
        if (!StringUtil.isEmpty(suffix)) {
            resultMap.put("ledgerTotalAndRiskLevelMajorUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/major" + suffix);
            resultMap.put("ledgerTotalAndRiskLevelLargerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/larger" + suffix);
            resultMap.put("ledgerTotalAndRiskLevelGeneralUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/general" + suffix);
            resultMap.put("ledgerTotalAndRiskLevelLowUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/low" + suffix);
            resultMap.put("dangerLedgerListTotalByThisMonthHighDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthHighDanger" + suffix);
            resultMap.put("dangerLedgerListToatalByThisMonthNormalDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthNormalDanger" + suffix);
            resultMap.put("dangerLedgerListTotalByUnRectifyDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/unRectifyDanger" + suffix);
            resultMap.put("dangerLedgerListTotalUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal" + suffix);
        }
 
        return ApiResult.success("请求数据成功", resultMap);
    }
 
 
    /**
     * 根据角色名称查询数据统计(用于总公司账号数据统计,区域账号不再涉及)
     */
    public ApiResult getAllDataStatisticsByRoleName(String str, ApiRequestHeader header) {
        //验证userId,loginName,token,deviceType,deviceId,appType 是否一致
        ApiRequestHeader requestHeader = getHeader(header);
        if (!(header.equals(requestHeader))) {
            return ApiResult.errorToken("验证userId,loginName,token,deviceType,deviceId,appType 不一致");
        }
        String companyName = "";
        String userId = "";
        try {
            Map<String, String> map = new ObjectMapper().readValue(str, HashMap.class);
            companyName = map.get("companyName");
            userId = map.get("userId");
        } catch (Exception e) {
            return ApiResult.error("异常");
        }
        if (StringUtil.isEmpty(userId)) {
            return ApiResult.error("userId参数必填,不能为空!");
        }
        Set<String> stringSet = roleService.selectRoleKeys(Long.valueOf(userId));
        User user = userService.selectUserById(Long.valueOf(userId));
        DataStatistics query = new DataStatistics();
        if (stringSet.contains("regionUser")
                || stringSet.contains("straightRegionUser")) {
            if (!StringUtils.isEmpty(user.getUserName())) {
                if (("漯河市应急管理局").equals(user.getUserName())) {
                    query.setSelectAllCompanyHasRegion("selectAllCompanyHasRegion");//市直账号,查询所有有区域的公司
                } else {
                    query.setCompanyRegion(user.getUserName());
                }
            } else {
                return ApiResult.error("用户未找到!");
            }
        } else if (stringSet.contains("common")) {
            //判断是否有子公司
            Company sonQuery = new Company();
            sonQuery.setParentId(user.getCompanyId());
            List<Company> sonList = companyService.selectCompanyList(sonQuery);
            if (sonList.size() == 0) {
                return ApiResult.error("用户不能调用!");
            } else {
                List<String> companyIdList = new ArrayList<>();
                for (Company company : sonList) {
                    companyIdList.add(company.getCompanyId().toString());
                }
                companyIdList.add(user.getCompanyId().toString());
                query.setCompanyIdList(companyIdList);
            }
        } else {
            return ApiResult.error("用户所在角色不能调用!");
        }
        //查询
        List<DataStatistics> listTotal = dataStatisticsService.selectCompanyDataStatistics(query);
 
        BigDecimal seriesRiskCount = new BigDecimal(0);
        BigDecimal middleRiskCount = new BigDecimal(0);
        BigDecimal normalRiskCount = new BigDecimal(0);
        BigDecimal lowRiskCount = new BigDecimal(0);
        BigDecimal thisMonthHighDangerCount = new BigDecimal(0);
        BigDecimal thisMonthNormalDangerCount = new BigDecimal(0);
        BigDecimal unRectifyDangerCount = new BigDecimal(0);
        BigDecimal allDangers = new BigDecimal(0);
        String dangerRectifyPercent = "100%";
 
        for (DataStatistics temp : listTotal) {
            seriesRiskCount = seriesRiskCount.add(new BigDecimal(temp.getSeriesRiskCount()));
            middleRiskCount = middleRiskCount.add(new BigDecimal(temp.getMiddleRiskCount()));
            normalRiskCount = normalRiskCount.add(new BigDecimal(temp.getNormalRiskCount()));
            lowRiskCount = lowRiskCount.add(new BigDecimal(temp.getLowRiskCount()));
            thisMonthHighDangerCount = thisMonthHighDangerCount.add(new BigDecimal(temp.getThisMonthHighDangerCount()));
            thisMonthNormalDangerCount = thisMonthNormalDangerCount.add(new BigDecimal(temp.getThisMonthNormalDangerCount()));
            unRectifyDangerCount = unRectifyDangerCount.add(new BigDecimal(temp.getUnRectifyDangerCount()));
            allDangers = allDangers.add(new BigDecimal(temp.getAllDangers()));
        }
        DataStatistics sumDataStatistics = new DataStatistics();
        sumDataStatistics.setSeriesRiskCount(seriesRiskCount.longValue());
        sumDataStatistics.setMiddleRiskCount(middleRiskCount.longValue());
        sumDataStatistics.setNormalRiskCount(normalRiskCount.longValue());
        sumDataStatistics.setLowRiskCount(lowRiskCount.longValue());
        sumDataStatistics.setThisMonthHighDangerCount(thisMonthHighDangerCount.longValue());
        sumDataStatistics.setThisMonthNormalDangerCount(thisMonthNormalDangerCount.longValue());
        sumDataStatistics.setUnRectifyDangerCount(unRectifyDangerCount.longValue());
 
        if (allDangers.longValue() != 0) {
            BigDecimal tempBigDecimal = ApiHiddenDangerCheckService.divide((allDangers.intValue() - unRectifyDangerCount.intValue()), allDangers.intValue(), 4);
            //下面将结果转化成百分比
            NumberFormat percent5 = NumberFormat.getPercentInstance();
            percent5.setMaximumFractionDigits(2);
            dangerRectifyPercent = percent5.format(tempBigDecimal.doubleValue());
        }
        sumDataStatistics.setDangerRectifyPercent(dangerRectifyPercent);
 
        List<DataStatistics> listQueryResultByCompanyName = new ArrayList<>();
        if (StringUtils.isEmpty(companyName)) {
            companyName = "";
        }
        for (DataStatistics temp : listTotal) {
            if (temp.getCompanyName().contains(companyName)) {
                temp.setLedgerByCompanyIdAndRiskLevelMajorUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/major");
                temp.setLedgerByCompanyIdAndRiskLevelLargerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/larger");
                temp.setLedgerByCompanyIdAndRiskLevelGeneralUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/general");
                temp.setLedgerByCompanyIdAndRiskLevelLowUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/low");
 
                temp.setDangerLedgerListByCompanyIdByThisMonthHighDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/thisMonthHighDanger");
                temp.setDangerLedgerListByCompanyIdByThisMonthNormalDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/thisMonthNormalDanger");
                temp.setDangerLedgerListByCompanyIdByUnRectifyDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/unRectifyDanger");
 
                temp.setDangerPlanExecuteByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerPlanExecuteByCompanyId/" + temp.getCompanyId());
                temp.setDangerScheduleByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerScheduleByCompanyId/" + temp.getCompanyId());
                temp.setDangerLedgerListByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId());
                temp.setLedgerByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId());
                temp.setArticleByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/articleByCompanyId/" + temp.getCompanyId());
                temp.setArticleRegulationByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/articleRegulationByCompanyId/" + temp.getCompanyId());
                listQueryResultByCompanyName.add(temp);
            }
        }
 
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("dataStatisticsList", listQueryResultByCompanyName);
        resultMap.put("sumDataStatistics", sumDataStatistics);
        return ApiResult.success("请求数据成功", resultMap);
 
    }
 
 
}