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 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 sonList = companyService.selectCompanyList(sonQuery); if (sonList.size() == 0) { return prefix + "/dataStatistics"; } else { List 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 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 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 sonList = companyService.selectCompanyList(sonQuery); if (sonList.size() == 0) { dataStatistics.setCompanyId(user.getCompanyId()); } else { List companyIdList = new ArrayList<>(); for (Company company : sonList) { companyIdList.add(company.getCompanyId().toString()); } companyIdList.add(user.getCompanyId().toString()); dataStatistics.setCompanyIdList(companyIdList); } } } List 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 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 sonList = companyService.selectCompanyList(sonQuery); if (sonList.size() == 0) { dataStatistics.setCompanyId(user.getCompanyId()); } else { List companyIdList = new ArrayList<>(); for (Company company : sonList) { companyIdList.add(company.getCompanyId().toString()); } companyIdList.add(user.getCompanyId().toString()); dataStatistics.setCompanyIdList(companyIdList); } } } List list = dataStatisticsService.selectCompanyDataStatistics(dataStatistics); ExcelUtil util = new ExcelUtil(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; } }