双重预防项目-国泰新华二开定制版
heheng
2025-06-24 e98eeaaa5766511fdb8e6d5e412eb1c59d1f07ce
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
package com.ruoyi.project.tr.dataStatistics.controller;
 
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.PageDomain;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.page.TableSupport;
import com.ruoyi.project.mobile.domain.ApiResult;
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.role.service.IRoleService;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.tr.dataStatistics.domain.DataStatistics;
import com.ruoyi.project.tr.dataStatistics.service.DataStatisticsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
 
@Controller
@RequestMapping("/tr/dataStatistics")
public class DataStatisticsController extends BaseController {
    @Autowired
    private DataStatisticsService dataStatisticsService;
 
    @Autowired
    private IRoleService roleService;
 
    @Autowired
    private ICompanyService companyService;
 
    private String prefix = "tr/dataStatistics";
 
    /**
     * 获取数据统计页面
     *
     * @param
     * @return
     */
    @RequiresPermissions("tr:dataStatistics:view")
    @GetMapping
    public String dataStatistics(ModelMap mmap) {
        DataStatistics query = new DataStatistics();
        User user = getSysUser();
        String roleName = "";
        if (user.isAdmin()) {
            mmap.put("roleName", "admin");
        } else {
            Set<String> stringSet = roleService.selectRoleKeys(user.getUserId());
            if (stringSet.contains("straightRegionUser")) {
                mmap.put("roleName", "straightRegionUser");
                query.setSelectAllCompanyHasRegion("selectAllCompanyHasRegion");//市直账号,查询所有有区域的公司
                roleName = "straightRegionUser";
            } else if (stringSet.contains("regionUser")) {
                if (!StringUtils.isEmpty(user.getUserName())) {
                    mmap.put("roleName", "regionUser");
                    query.setCompanyRegion(user.getUserName());
                    roleName = "regionUser";
                } else {
                    return prefix + "/dataStatistics";
                }
            } else {
                //判断是否有子公司
                Company sonQuery = new Company();
                sonQuery.setParentId(user.getCompanyId());
                List<Company> sonList = companyService.selectCompanyList(sonQuery);
                if (sonList.size() == 0) {
                    return prefix + "/dataStatistics";
                } else {
                    List<String> companyIdList = new ArrayList<>();
                    for (Company company : sonList) {
                        companyIdList.add(company.getCompanyId().toString());
                    }
                    companyIdList.add(user.getCompanyId().toString());
                    query.setCompanyIdList(companyIdList);
                    mmap.put("roleName", "companyAdminUser");
                    roleName = "companyAdminUser";
                }
            }
 
            if (StringUtils.isEmpty(roleName)) {
                return prefix + "/dataStatistics";
            }
        }
        List<DataStatistics> list = 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 : list) {
            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);
        mmap.put("sumDataStatistics", sumDataStatistics);
 
 
        return prefix + "/dataStatistics";
    }
 
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DataStatistics dataStatistics) {
 
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
 
        User user = getSysUser();
        if (user.isAdmin()) {
 
        } else {
            Set<String> stringSet = roleService.selectRoleKeys(user.getUserId());
            if (stringSet.contains("straightRegionUser")) {
                dataStatistics.setSelectAllCompanyHasRegion("selectAllCompanyHasRegion");//市直账号,查询所有有区域的公司
            } else if (stringSet.contains("regionUser")) {
                dataStatistics.setCompanyRegion(user.getUserName());
            } else {
                //判断是否有子公司
                Company sonQuery = new Company();
                sonQuery.setParentId(user.getCompanyId());
                List<Company> sonList = companyService.selectCompanyList(sonQuery);
                if (sonList.size() == 0) {
                    dataStatistics.setCompanyId(user.getCompanyId());
                } else {
                    List<String> companyIdList = new ArrayList<>();
                    for (Company company : sonList) {
                        companyIdList.add(company.getCompanyId().toString());
                    }
                    companyIdList.add(user.getCompanyId().toString());
                    dataStatistics.setCompanyIdList(companyIdList);
                }
            }
        }
 
        List<DataStatistics> list = dataStatisticsService.selectCompanyDataStatistics(dataStatistics);
        Integer total = list.size();
        Integer startIndex = (pageNum - 1) * pageSize;
        Integer endIndex = (pageNum - 1) * pageSize + pageSize;
        if (total >= endIndex) {
            list = list.subList(startIndex, endIndex);
        } else if (total > startIndex) {
            list = list.subList(startIndex, total);
        }
        TableDataInfo rspData = new TableDataInfo(list, total);
        rspData.setCode(0);
        return rspData;
    }
 
    /**
     * 导出数据统计列表
     */
    @RequiresPermissions("tr:dataStatistics:export")
    @Log(title = "导出数据统计信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DataStatistics dataStatistics) {
        User user = getSysUser();
        if (user.isAdmin()) {
 
        } else {
            Set<String> stringSet = roleService.selectRoleKeys(user.getUserId());
            if (stringSet.contains("straightRegionUser")) {
                dataStatistics.setSelectAllCompanyHasRegion("selectAllCompanyHasRegion");//市直账号,查询所有有区域的公司
            } else if (stringSet.contains("regionUser")) {
                dataStatistics.setCompanyRegion(user.getUserName());
            } else {
                //判断是否有子公司
                Company sonQuery = new Company();
                sonQuery.setParentId(user.getCompanyId());
                List<Company> sonList = companyService.selectCompanyList(sonQuery);
                if (sonList.size() == 0) {
                    dataStatistics.setCompanyId(user.getCompanyId());
                } else {
                    List<String> companyIdList = new ArrayList<>();
                    for (Company company : sonList) {
                        companyIdList.add(company.getCompanyId().toString());
                    }
                    companyIdList.add(user.getCompanyId().toString());
                    dataStatistics.setCompanyIdList(companyIdList);
                }
            }
        }
        List<DataStatistics> list = dataStatisticsService.selectCompanyDataStatistics(dataStatistics);
        ExcelUtil<DataStatistics> util = new ExcelUtil<DataStatistics>(DataStatistics.class);
        return util.exportExcel(list, "数据统计信息");
    }
 
 
    /**
     * 跳转到按部门 进行隐患统计的页面
     *
     * @param mmap
     * @return
     */
    @GetMapping("/hiddenDangerStatisticsByDept")
    public String selectHiddenDangerStatisticsByDept(ModelMap mmap) {
 
        return prefix + "/hiddenDangerStatisticsByDept";
    }
 
    /**
     * 按部门进行隐患统计的返回数据
     * @param dataStatistics
     * @return
     */
    @PostMapping("/hiddenDangerStatisticsListByDept")
    @ResponseBody
    public TableDataInfo hiddenDangerStatisticsListByDept(DataStatistics dataStatistics) {
        return null;
    }
 
 
}