双重预防项目-国泰新华二开定制版
SZH
2022-08-20 f9f0687195e0fe349185437d22c495d74c8d4a20
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
package com.ruoyi.project.tr.dataStatistics.controller;
 
import com.github.pagehelper.util.StringUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.mobile.service.ApiAllDataStatisticsService;
import com.ruoyi.project.mobile.service.ApiHiddenDangerCheckService;
import com.ruoyi.project.system.company.domain.Company;
import com.ruoyi.project.system.company.service.ICompanyService;
import com.ruoyi.project.system.dept.service.IDeptService;
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.service.DataStatisticsService;
import com.ruoyi.project.tr.hiddenDangerCheck.service.IHiddenDangerCheckService;
import com.ruoyi.project.tr.hiddenDangerCheckPoint.domain.HiddenDangerCheckPoint;
import com.ruoyi.project.tr.hiddenDangerCheckPoint.service.IHiddenDangerCheckPointService;
import com.ruoyi.project.tr.region.service.IRegionService;
import com.ruoyi.project.tr.riskCheckPoint.domain.RiskCheckPoint;
import com.ruoyi.project.tr.riskCheckPoint.service.IRiskCheckPointService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
 
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * app端,数据统计功能
 */
@Controller
@RequestMapping("/tr/dataStatisticsTotalByApp")
public class DataStatisticsTotalByAppController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(DataStatisticsTotalByAppController.class);
    @Autowired
    private DataStatisticsService dataStatisticsService;
    @Autowired
    private IRoleService roleService;
    @Autowired
    private IUserService userService;
    @Autowired
    private IDeptService deptService;
 
    @Autowired
    private IHiddenDangerCheckPointService hiddenDangerCheckPointService;
    @Autowired
    private IHiddenDangerCheckService hiddenDangerCheckService;
    @Autowired
    private IRiskCheckPointService riskCheckPointService;
 
 
    @Autowired
    private IRegionService regionService;
 
    @Autowired
    private ICompanyService companyService;
 
    private String prefix = "tr/dataStatisticsTotalByApp";
 
 
    /**
     * 获取隐患台账页面
     */
    @GetMapping("/dangerLedgerListTotal")
    public String dangerLedgerListTotal(ModelMap modelMap,
                                        String pageLevel,
                                        String companyRegion,
                                        String companyIndustryType,
                                        String companySubIndustryType) {
        Company companyQuery = new Company();
        if ("firstPage".equals(pageLevel)) {
 
        } else if ("secondPage".equals(pageLevel)) {
            modelMap.put("companyRegion", companyRegion);
 
            companyQuery.setCompanyRegion(companyRegion);
        } else if ("thirdPage".equals(pageLevel)) {
            modelMap.put("companyRegion", companyRegion);
            modelMap.put("companyIndustryType", companyIndustryType);
            modelMap.put("companySubIndustryType", companySubIndustryType);
 
            companyQuery.setCompanyRegion(companyRegion);
            companyQuery.setCompanyIndustry(companyIndustryType);
            companyQuery.setCompanySubIndustry(companySubIndustryType);
        }
        getDangerDataStatistics(modelMap, companyQuery);
        return prefix + "/dangerLedgerListTotal";
    }
 
 
    //companyId下总的数据统计
    public void getDangerDataStatistics(ModelMap mmap, Company companyQuery) {
 
        int totalDangerNum = 0;//隐患数
        int rectifyNum = 0;//已整改数目
        int notRectifyNum = 0;//未整改数目
        int totalRectifyNum = 0;//整改总条数(已整改数目+未整改数目)
        String rectifyRate = "100%";//整改率
 
        int onTimeRectifyNum = 0;//按期整改数
        String onTimeRectifyRate = "100%";//按期率
        int overdueRectifyNum = 0;//超期整改数
        String overdueRectifyRate = "0%";//超期率
 
        String monthOnMonthRate = "暂无";//环比-------(上个月 - 上上个月)/上上个月
        String yearOnYearRate = "暂无";//同比-------(上个月 - 去年上个月)/去年上个月
 
 
        HiddenDangerCheckPoint hdcpQuery = new HiddenDangerCheckPoint();
        HiddenDangerCheckPoint hdcpQueryAll = new HiddenDangerCheckPoint();
        HiddenDangerCheckPoint queryByTime = new HiddenDangerCheckPoint();
 
        hdcpQuery.setRectifyUserIdIsNotNull("1");//隐患整改人ID  不为空
        hdcpQueryAll.setRectifyUserIdIsNotNull("1");//隐患整改人ID  不为空
        queryByTime.setRectifyUserIdIsNotNull("1");//隐患整改人ID  不为空
 
 
        //有区域的公司列表的过滤
//        Company companyQuery = new Company();
        List<Company> companyListTemp = companyService.selectCompanyList(companyQuery);
        List<Long> companyIdListLast = new ArrayList<>();
        for (Company c : companyListTemp) {
            if (!StringUtil.isEmpty(c.getCompanyRegion())) {
                companyIdListLast.add(c.getCompanyId());
            }
        }
 
        if (companyIdListLast.size() > 0) {
            hdcpQuery.setCompanyIdList(companyIdListLast);
            hdcpQueryAll.setCompanyIdList(companyIdListLast);
            queryByTime.setCompanyIdList(companyIdListLast);
 
 
//        User userQuery = new User();
//        List<User> userList = userService.selectUserList(userQuery);
//        List<Long> userIdList = new ArrayList<>();
//        for (User user : userList) {
//            userIdList.add(user.getUserId());
//        }
 
 
//        if (userIdList.size() > 0) {
//            hdcpQueryAll.setLedgerUserIdList(userIdList);//隐患整改人ID 为登陆账号companyId下的userId的
//            queryByTime.setLedgerUserIdList(userIdList);//隐患整改人ID 为登陆账号companyId下的userId的
 
            //companyId下总的数据统计
            List<HiddenDangerCheckPoint> resultListAll = hiddenDangerCheckPointService.selectHiddenDangerCheckPointList(hdcpQueryAll);//根据companyId 查询出的列表
 
            for (HiddenDangerCheckPoint hdcp : resultListAll) {
                if (!StringUtils.isEmpty(hdcp.getStage())) {
                    if ("3".equals(hdcp.getStage())) {
                        if (!StringUtil.isEmpty(hdcp.getExamineStatus())) {
                            if ("0".equals(hdcp.getExamineStatus())) {
                                notRectifyNum++;
                            }
                        }
                    } else if ("4".equals(hdcp.getStage())) {
                        if (!StringUtil.isEmpty(hdcp.getRectifyStatus())) {
                            if ("0".equals(hdcp.getRectifyStatus())) {
                                notRectifyNum++;
                            }
                        }
                    } else if ("5".equals(hdcp.getStage())) {
                        if (!StringUtil.isEmpty(hdcp.getAcceptStatus())) {
                            rectifyNum++;
                            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
                            try {
                                if (f.parse(f.format(hdcp.getRectifyDeadlineTime())).before(f.parse(f.format(hdcp.getRectifyCompleteTime())))) {
                                    overdueRectifyNum++;
                                } else {
                                    onTimeRectifyNum++;
                                }
                            } catch (ParseException e) {
                            }
                        }
                    }
                }
            }
            totalDangerNum = resultListAll.size();
            totalRectifyNum = rectifyNum + notRectifyNum;
            if (totalDangerNum > 0) {
                //计算整改率
                BigDecimal a = ApiHiddenDangerCheckService.divide(rectifyNum, totalDangerNum, 4);
                //下面将结果转化成百分比
                NumberFormat percent1 = NumberFormat.getPercentInstance();
                percent1.setMaximumFractionDigits(2);
                rectifyRate = percent1.format(a.doubleValue());
 
                //计算按期率
                BigDecimal b = ApiHiddenDangerCheckService.divide(onTimeRectifyNum, totalDangerNum, 4);
                //下面将结果转化成百分比
                NumberFormat percent2 = NumberFormat.getPercentInstance();
                percent2.setMaximumFractionDigits(2);
                onTimeRectifyRate = percent2.format(b.doubleValue());
 
 
                //计算超期率
                BigDecimal c = ApiHiddenDangerCheckService.divide(overdueRectifyNum, totalDangerNum, 4);
                //下面将结果转化成百分比
                NumberFormat percent3 = NumberFormat.getPercentInstance();
                percent3.setMaximumFractionDigits(2);
                overdueRectifyRate = percent3.format(c.doubleValue());
            }
 
 
            Map map1 = ApiHiddenDangerCheckService.getLastMonthTime(0, -1);//上个月
 
            Map map2 = ApiHiddenDangerCheckService.getLastMonthTime(0, -2);//上上个月
 
            Map map3 = ApiHiddenDangerCheckService.getLastMonthTime(-1, -1);//去年上个月
 
 
            queryByTime.setParams(map1);
            List<HiddenDangerCheckPoint> list1 = hiddenDangerCheckPointService.selectHiddenDangerCheckPointList(queryByTime);//上个月
            queryByTime.setParams(map2);
            List<HiddenDangerCheckPoint> list2 = hiddenDangerCheckPointService.selectHiddenDangerCheckPointList(queryByTime);//上上个月
            queryByTime.setParams(map3);
            List<HiddenDangerCheckPoint> list3 = hiddenDangerCheckPointService.selectHiddenDangerCheckPointList(queryByTime);//去年上个月
 
 
            //计算环比
            if (list2.size() > 0) {
                BigDecimal d = ApiHiddenDangerCheckService.divide((list1.size() - list2.size()), list2.size(), 4);
                //下面将结果转化成百分比
                NumberFormat percent4 = NumberFormat.getPercentInstance();
                percent4.setMaximumFractionDigits(2);
                monthOnMonthRate = percent4.format(d.doubleValue());
            } else {
                monthOnMonthRate = "暂无";
            }
 
 
            //计算同比
            if (list3.size() > 0) {
                BigDecimal e = ApiHiddenDangerCheckService.divide((list1.size() - list3.size()), list3.size(), 4);
                //下面将结果转化成百分比
                NumberFormat percent5 = NumberFormat.getPercentInstance();
                percent5.setMaximumFractionDigits(2);
                yearOnYearRate = percent5.format(e.doubleValue());
            } else {
                yearOnYearRate = "暂无";
            }
//        }
        }
 
        mmap.put("totalDangerNum", totalDangerNum);
        mmap.put("rectifyNum", rectifyNum);
        mmap.put("notRectifyNum", notRectifyNum);
        mmap.put("rectifyRate", rectifyRate);
        mmap.put("onTimeRectifyNum", onTimeRectifyNum);
        mmap.put("onTimeRectifyRate", onTimeRectifyRate);
        mmap.put("overdueRectifyNum", overdueRectifyNum);
        mmap.put("overdueRectifyRate", overdueRectifyRate);
 
        mmap.put("monthOnMonthRate", monthOnMonthRate);
        mmap.put("yearOnYearRate", yearOnYearRate);
    }
 
    /**
     * thisMonthHighDanger隐患台账  列表页面
     */
    @GetMapping("/dangerLedgerListTotal/thisMonthHighDanger")
//      String pageLevel,第几个层级
//      String companyRegion,公司区域
//      String companyIndustryType,行业分类
//      String companySubIndustryType,行业子分类
    public String dangerLedgerListTotalByThisMonthHighDanger(ModelMap modelMap,
                                                             String pageLevel,
                                                             String companyRegion,
                                                             String companyIndustryType,
                                                             String companySubIndustryType) {
        if ("firstPage".equals(pageLevel)) {
 
        } else if ("secondPage".equals(pageLevel)) {
            modelMap.put("companyRegion", companyRegion);
        } else if ("thirdPage".equals(pageLevel)) {
            modelMap.put("companyRegion", companyRegion);
            modelMap.put("companyIndustryType", companyIndustryType);
            modelMap.put("companySubIndustryType", companySubIndustryType);
        }
        return prefix + "/dangerLedgerListTotalByThisMonthHighDanger";
    }
 
    /**
     * thisMonthNormalDanger隐患台账  列表页面
     */
    @GetMapping("/dangerLedgerListTotal/thisMonthNormalDanger")
//      String pageLevel,第几个层级
//      String companyRegion,公司区域
//      String companyIndustryType,行业分类
//      String companySubIndustryType,行业子分类
    public String dangerLedgerListTotalByThisMonthNormalDanger(ModelMap modelMap,
                                                               String pageLevel,
                                                               String companyRegion,
                                                               String companyIndustryType,
                                                               String companySubIndustryType) {
        if ("firstPage".equals(pageLevel)) {
 
        } else if ("secondPage".equals(pageLevel)) {
            modelMap.put("companyRegion", companyRegion);
        } else if ("thirdPage".equals(pageLevel)) {
            modelMap.put("companyRegion", companyRegion);
            modelMap.put("companyIndustryType", companyIndustryType);
            modelMap.put("companySubIndustryType", companySubIndustryType);
        }
        return prefix + "/dangerLedgerListTotalByThisMonthNormalDanger";
    }
 
    /**
     * unRectifyDanger隐患台账   列表页面
     */
    @GetMapping("/dangerLedgerListTotal/unRectifyDanger")
//      String pageLevel,第几个层级
//      String companyRegion,公司区域
//      String companyIndustryType,行业分类
//      String companySubIndustryType,行业子分类
    public String dangerLedgerListTotalByUnRectifyDanger(ModelMap modelMap,
                                                         String pageLevel,
                                                         String companyRegion,
                                                         String companyIndustryType,
                                                         String companySubIndustryType) {
        if ("firstPage".equals(pageLevel)) {
 
        } else if ("secondPage".equals(pageLevel)) {
            modelMap.put("companyRegion", companyRegion);
        } else if ("thirdPage".equals(pageLevel)) {
            modelMap.put("companyRegion", companyRegion);
            modelMap.put("companyIndustryType", companyIndustryType);
            modelMap.put("companySubIndustryType", companySubIndustryType);
        }
        return prefix + "/dangerLedgerListTotalByUnRectifyDanger";
    }
 
 
    /**
     * 查询隐患台账列表
     */
    @PostMapping("/dangerLedgerListTotal")
    @ResponseBody
    public TableDataInfo dangerLedgerListTotal(HiddenDangerCheckPoint hiddenDangerCheckPoint, String dateRangeLedger, String rectifyStatusLedger, String rectifyDeptIdLedger,
                                               Company companyQuery) {
//        User userQuery = new User();
//        List<User> userList = userService.selectUserList(userQuery);
//        List<Long> userIdList = new ArrayList<>();
//        for (User user : userList) {
//            userIdList.add(user.getUserId());
//        }
//
//        if (userIdList.size() == 0) {
//            return getDataTable(new ArrayList<HiddenDangerCheckPoint>());
//        }
//
//        hiddenDangerCheckPoint.setLedgerUserIdList(userIdList);//隐患整改人ID 为登陆账号companyId下的userId的
 
        hiddenDangerCheckPoint.setRectifyUserIdIsNotNull("1");//隐患整改人ID  不为空
 
        //有区域的公司列表的过滤
//        Company companyQuery = new Company();
        List<Company> companyListTemp = companyService.selectCompanyList(companyQuery);
        List<Long> companyIdListLast = new ArrayList<>();
        for (Company c : companyListTemp) {
            if (!StringUtil.isEmpty(c.getCompanyRegion())) {
                companyIdListLast.add(c.getCompanyId());
            }
        }
        hiddenDangerCheckPoint.setCompanyIdList(companyIdListLast);
 
        List<HiddenDangerCheckPoint> list = new ArrayList<>();
        if (companyIdListLast.size() > 0) {
            //日期区间
            if (!StringUtils.isEmpty(dateRangeLedger)) {
                if (("近一周").equals(dateRangeLedger)) {
                    hiddenDangerCheckPoint.setParams(ApiHiddenDangerCheckService.getDaySevenRange());
                } else if (("近一月").equals(dateRangeLedger)) {
                    hiddenDangerCheckPoint.setParams(ApiHiddenDangerCheckService.getMonthRange());
                } else if (("近一年").equals(dateRangeLedger)) {
                    hiddenDangerCheckPoint.setParams(ApiHiddenDangerCheckService.getYearRange());
                } else if (("当月").equals(dateRangeLedger)) {
                    hiddenDangerCheckPoint.setParams(ApiHiddenDangerCheckService.getLastMonthTime(0, 0));
                }
            }
            //整改状态
            if (!StringUtils.isEmpty(rectifyStatusLedger)) {
                if (("未整改").equals(rectifyStatusLedger)) {
                    hiddenDangerCheckPoint.setStage("4");
                    hiddenDangerCheckPoint.setRectifyStatus("0");
                } else if (("未验收").equals(rectifyStatusLedger)) {
                    hiddenDangerCheckPoint.setStage("5");
                    hiddenDangerCheckPoint.setAcceptStatus("0");
                } else if (("已验收").equals(rectifyStatusLedger)) {
                    hiddenDangerCheckPoint.setStage("5");
                    hiddenDangerCheckPoint.setAcceptStatus("1");
                } else if (("超期改").equals(rectifyStatusLedger)) {
                    hiddenDangerCheckPoint.setStage("5");
                    hiddenDangerCheckPoint.setOverdueRectify("1");
                }
            }
            //整改部门
            if (!StringUtils.isEmpty(rectifyDeptIdLedger)) {
                hiddenDangerCheckPoint.setRectifyDeptId(Long.valueOf(rectifyDeptIdLedger));
            }
 
            startPage();
            list = hiddenDangerCheckPointService.selectHiddenDangerCheckPointList(hiddenDangerCheckPoint);
        }
        return getDataTable(list);
    }
 
 
    /**
     * 查询检查点及评价列表
     */
    @PostMapping("/riskCheckPoint/ledger")
    @ResponseBody
    public TableDataInfo ledgerList(RiskCheckPoint riskCheckPoint, Company companyQuery) {
        //有区域的公司列表的过滤
//        Company companyQuery = new Company();
        List<Company> companyListTemp = companyService.selectCompanyList(companyQuery);
        List<Long> companyIdListLast = new ArrayList<>();
        for (Company c : companyListTemp) {
            if (!StringUtil.isEmpty(c.getCompanyRegion())) {
                companyIdListLast.add(c.getCompanyId());
            }
        }
        List<RiskCheckPoint> list = new ArrayList<>();
        if (companyIdListLast.size() > 0) {
            riskCheckPoint.setCompanyIdList(companyIdListLast);
            startPage();
            list = riskCheckPointService.selectRiskCheckPointList(riskCheckPoint);
        }
        return getDataTable(list);
    }
 
 
    /**
     * 用于记录风险清单台账
     *
     * @return
     */
//      String pageLevel,第几个层级
//      String companyRegion,公司区域
//      String companyIndustryType,行业分类
//      String companySubIndustryType,行业子分类
    @RequestMapping("/riskCheckPoint/ledger/{level}")
    public String ledgerTotalAndRiskLevel(ModelMap modelMap,
                                          @PathVariable("level") String level,
                                          String pageLevel,
                                          String companyRegion,
                                          String companyIndustryType,
                                          String companySubIndustryType) {
        if ("major".equals(level)) {
            //重大风险
            modelMap.put("level", "重大");
        } else if ("larger".equals(level)) {
            //较大风险
            modelMap.put("level", "较大");
        } else if ("general".equals(level)) {
            //一般风险
            modelMap.put("level", "一般");
        } else if ("low".equals(level)) {
            modelMap.put("level", "低");
        }
 
        if ("firstPage".equals(pageLevel)) {
 
        } else if ("secondPage".equals(pageLevel)) {
            modelMap.put("companyRegion", companyRegion);
        } else if ("thirdPage".equals(pageLevel)) {
            modelMap.put("companyRegion", companyRegion);
            modelMap.put("companyIndustryType", companyIndustryType);
            modelMap.put("companySubIndustryType", companySubIndustryType);
        }
 
        return prefix + "/ledgerTotalAndRiskLevel";
    }
 
 
}