| | |
| | | package com.ruoyi.project.system.user.controller; |
| | | |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.text.DecimalFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.security.ShiroUtils; |
| | | import com.ruoyi.project.system.company.domain.Company; |
| | | import com.ruoyi.project.system.company.service.ICompanyService; |
| | | import com.ruoyi.project.system.role.domain.Role; |
| | | import com.ruoyi.project.system.role.service.IRoleService; |
| | | import com.ruoyi.project.tr.report.domain.Danger; |
| | | import com.ruoyi.project.tr.report.domain.DangerByTime; |
| | | import com.ruoyi.project.tr.report.domain.RiskDomain; |
| | | import com.ruoyi.project.tr.report.mapper.ReportMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.ui.ModelMap; |
| | |
| | | import com.ruoyi.project.system.menu.domain.Menu; |
| | | import com.ruoyi.project.system.menu.service.IMenuService; |
| | | import com.ruoyi.project.system.user.domain.User; |
| | | |
| | | /** |
| | | * 首页 业务处理 |
| | | * |
| | |
| | | |
| | | @Autowired |
| | | private IRoleService roleService; |
| | | |
| | | @Autowired |
| | | private ReportMapper reportMapper; |
| | | // 系统首页 |
| | | @GetMapping("/index") |
| | | public String index(ModelMap mmap) |
| | | { |
| | | |
| | | |
| | | // 取身份信息 |
| | | User user = getSysUser(); |
| | | // 根据用户id取出菜单 |
| | |
| | | mmap.put("copyrightYear", ruoYiConfig.getCopyrightYear()); |
| | | mmap.put("demoEnabled", ruoYiConfig.isDemoEnabled()); |
| | | |
| | | |
| | | // List fourColorPic = getFourColorPic(companyId); |
| | | // //四色图 |
| | | // mmap.put("fourColorMapUrl", fourColorPic); |
| | | Set<String> stringSet = roleService.selectRoleKeys(user.getUserId()); |
| | | if (stringSet.contains("regionUser")||stringSet.contains("straightRegionUser")){ |
| | | return "indexByRegionUser"; |
| | | }else{ |
| | | return "index"; |
| | | } |
| | | } |
| | | |
| | | } |
| | | // 切换主题 |
| | | @GetMapping("/system/switchSkin") |
| | | public String switchSkin(ModelMap mmap) |
| | |
| | | // 系统介绍 |
| | | @GetMapping("/system/main") |
| | | public String main(ModelMap mmap){ |
| | | //返回该公司的四色图 |
| | | User user = getSysUser(); |
| | | long companyId = user.getCompanyId(); |
| | | List fourColorPic = getFourColorPic(companyId); |
| | | //四色图 |
| | | mmap.put("fourColorMapUrl", fourColorPic); |
| | | List<RiskDomain> riskDomains = reportMapper.selectPublicityRisk(companyId); |
| | | //风险总量 |
| | | mmap.put("allRiskCount", riskDomains.size()); |
| | | AtomicReference<Integer> lowRiskCount = new AtomicReference<>(0); |
| | | AtomicReference<Integer> normalRiskCount = new AtomicReference<>(0); |
| | | AtomicReference<Integer> middleRiskCount = new AtomicReference<>(0); |
| | | AtomicReference<Integer> seriesRiskCount = new AtomicReference<>(0); |
| | | ArrayList<RiskDomain> seriesRisks = new ArrayList<>(); |
| | | riskDomains.forEach(riskDomain -> { |
| | | if (StringUtils.isNotEmpty(riskDomain.getRiskColor())) { |
| | | switch (riskDomain.getRiskColor()) { |
| | | case "蓝色": |
| | | lowRiskCount.getAndSet(lowRiskCount.get() + 1); |
| | | break; |
| | | case "黄色": |
| | | normalRiskCount.getAndSet(normalRiskCount.get() + 1); |
| | | break; |
| | | case "橙色": |
| | | middleRiskCount.getAndSet(middleRiskCount.get() + 1); |
| | | break; |
| | | case "红色": |
| | | seriesRiskCount.getAndSet(seriesRiskCount.get() + 1); |
| | | seriesRisks.add(riskDomain); |
| | | break; |
| | | } |
| | | } |
| | | }); |
| | | //低风险数量 |
| | | mmap.put("lowRiskCount", lowRiskCount); |
| | | //一般风险数量 |
| | | mmap.put("normalRiskCount", normalRiskCount); |
| | | //较大风险数量 |
| | | mmap.put("middleRiskCount", middleRiskCount); |
| | | //重大风险数量 |
| | | mmap.put("seriesRiskCount", seriesRiskCount); |
| | | //重大风险公示信息 |
| | | mmap.put("seriesRisks", seriesRisks); |
| | | List<Danger> dangers = reportMapper.selectPublicityDanger(companyId); |
| | | ArrayList<Danger> seriesDangers = new ArrayList<>(); |
| | | AtomicReference<Integer> unRectifyDangerCount = new AtomicReference<>(0); |
| | | dangers.forEach(danger -> { |
| | | if (danger != null) { |
| | | if (StringUtils.isNotEmpty(danger.getDangerLevel()) && "1".equals(danger.getDangerLevel())) { |
| | | seriesDangers.add(danger); |
| | | } |
| | | if (StringUtils.isNotEmpty(danger.getRectifyStatus()) && "0".equals(danger.getRectifyStatus())) { |
| | | unRectifyDangerCount.getAndSet(unRectifyDangerCount.get() + 1); |
| | | } |
| | | } |
| | | }); |
| | | //重大隐患公示信息 |
| | | mmap.put("seriesDangers", seriesDangers); |
| | | //未整改隐患数量 |
| | | mmap.put("unRectifyDangerCount", unRectifyDangerCount); |
| | | Map monthlyDangerMap = selectMonthlyDangers(companyId); |
| | | ArrayList normalDanger = (ArrayList) monthlyDangerMap.get("normalDanger"); |
| | | long thisMonthNormalDangerCount = (long) normalDanger.get(normalDanger.size() - 1); |
| | | ArrayList highDanger = (ArrayList) monthlyDangerMap.get("highDanger"); |
| | | long thisMonthHighDangerCount = (long) highDanger.get(highDanger.size() - 1); |
| | | //当月一般隐患数量 |
| | | mmap.put("thisMonthNormalDangerCount", thisMonthNormalDangerCount); |
| | | //当月重大隐患数量 |
| | | mmap.put("thisMonthHighDangerCount", thisMonthHighDangerCount); |
| | | //月度隐患总量 |
| | | mmap.put("thisMonthDangerCount", thisMonthHighDangerCount + thisMonthNormalDangerCount); |
| | | Map yearlyDangersMap = selectYearlyDangers(companyId); |
| | | ArrayList normalDanger1 = (ArrayList) yearlyDangersMap.get("normalDanger"); |
| | | ArrayList highDanger1 = (ArrayList) yearlyDangersMap.get("highDanger"); |
| | | long yearlyDangerCount = (long) normalDanger1.get(normalDanger1.size() - 1) + (long) highDanger1.get(highDanger1.size() - 1); |
| | | //年度隐患总量 |
| | | mmap.put("yearlyDangerCount", yearlyDangerCount); |
| | | Long allDangers = (Long) yearlyDangersMap.get("allDangers"); |
| | | double tempPercent = 1.00; |
| | | if (allDangers != 0) { |
| | | tempPercent = (double) (allDangers - unRectifyDangerCount.get()) / allDangers; |
| | | } |
| | | String dangerRectifyPercent = new DecimalFormat("0.00%").format(tempPercent); |
| | | //隐患整改率 |
| | | mmap.put("dangerRectifyPercent", dangerRectifyPercent); |
| | | |
| | | |
| | | |
| | | mmap.put("companyImages",companyService.getCompanyImagesById(ShiroUtils.getSysUser().getCompanyId())); |
| | | mmap.put("version", ruoYiConfig.getVersion()); |
| | | return "main"; |
| | | } |
| | | |
| | | public Map selectYearlyDangers(long companyId) { |
| | | List<DangerByTime> dangerByTimes = reportMapper.selectDangersByYear(companyId); |
| | | return handleYearlyDangers(dangerByTimes); |
| | | } |
| | | |
| | | private Map handleYearlyDangers(List<DangerByTime> list) { |
| | | String nowYear = DateUtils.parseDateToStr("YYYY", DateUtils.getNowDate()); |
| | | Long allDangers = 0l; |
| | | String startYear = nowYear; |
| | | if (list.size() != 0) { |
| | | startYear = list.get(0).getDateTime(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | allDangers += list.get(i).getCount(); |
| | | } |
| | | } |
| | | ArrayList<Integer> reportNames = new ArrayList<>(); |
| | | ArrayList<Long> normalDanger = new ArrayList<>(); |
| | | ArrayList<Long> highDanger = new ArrayList<>(); |
| | | for (int i = 0; i <= Integer.parseInt(nowYear) - Integer.parseInt(startYear); i++) { |
| | | Integer temp = Integer.parseInt(startYear) + i; |
| | | reportNames.add(temp); |
| | | normalDanger.add(0l); |
| | | highDanger.add(0l); |
| | | int finalI = i; |
| | | list.forEach(dt -> { |
| | | if (dt != null) { |
| | | if (temp.toString().equals(dt.getDateTime()) && dt.getDangerLevel() != null) { |
| | | switch (dt.getDangerLevel()) { |
| | | case "0": |
| | | normalDanger.set(finalI, dt.getCount()); |
| | | break; |
| | | case "1": |
| | | highDanger.set(finalI, dt.getCount()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | HashMap<String, Object> reportMap = new HashMap<>(); |
| | | reportMap.put("reportNames", reportNames); |
| | | reportMap.put("normalDanger", normalDanger); |
| | | reportMap.put("highDanger", highDanger); |
| | | reportMap.put("allDangers", allDangers); |
| | | return reportMap; |
| | | } |
| | | |
| | | public Map selectMonthlyDangers(long companyId) { |
| | | Date date = DateUtils.addMonths(DateUtils.getNowDate(), -12); |
| | | List<DangerByTime> dangerByTimes = reportMapper.selectDangersByMonths(date, companyId); |
| | | return handleMonthlyDangers(date, dangerByTimes); |
| | | } |
| | | private Map handleMonthlyDangers(Date date, List<DangerByTime> list) { |
| | | ArrayList<String> reportNames = new ArrayList<>(); |
| | | ArrayList<Long> normalDanger = new ArrayList<>(); |
| | | ArrayList<Long> highDanger = new ArrayList<>(); |
| | | for (int i = 0; i < 12; i++) { |
| | | date = DateUtils.addMonths(date, 1); |
| | | String str = DateUtils.parseDateToStr("YYYY-MM", date); |
| | | reportNames.add(str); |
| | | normalDanger.add(0l); |
| | | highDanger.add(0l); |
| | | int finalI = i; |
| | | list.forEach(dt -> { |
| | | if (dt != null) { |
| | | if (str.equals(dt.getDateTime()) && dt.getDangerLevel() != null) { |
| | | switch (dt.getDangerLevel()) { |
| | | case "0": |
| | | normalDanger.set(finalI, dt.getCount()); |
| | | break; |
| | | case "1": |
| | | highDanger.set(finalI, dt.getCount()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | HashMap<String, List> reportMap = new HashMap<>(); |
| | | reportMap.put("reportNames", reportNames); |
| | | reportMap.put("normalDanger", normalDanger); |
| | | reportMap.put("highDanger", highDanger); |
| | | return reportMap; |
| | | } |
| | | |
| | | public List getFourColorPic(long companyId) { |
| | | Company company = companyService.selectCompanyById(companyId); |
| | | String companyFourColorMapUrl = company.getCompanyFourColorMapUrl(); |
| | | Map colorPicMap = JSON.parseObject(companyFourColorMapUrl); |
| | | Collection<String> values = colorPicMap.values(); |
| | | ArrayList<String> colorPic = new ArrayList<>(); |
| | | values.forEach(v -> { |
| | | v = v.replaceAll("^http:\\/\\/[^/]+", ""); |
| | | colorPic.add(v); |
| | | }); |
| | | return colorPic; |
| | | } |
| | | |
| | | // 数据统计 |
| | |
| | | return "main_two"; |
| | | } |
| | | } |
| | | |
| | | |