|
@@ -0,0 +1,379 @@
|
|
|
+package com.usky.fire.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.usky.common.core.exception.BusinessException;
|
|
|
+import com.usky.common.core.util.Arith;
|
|
|
+import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
+import com.usky.common.security.utils.SecurityUtils;
|
|
|
+import com.usky.fire.domain.*;
|
|
|
+import com.usky.fire.mapper.BscEnterpriseAutonomyMapper;
|
|
|
+import com.usky.fire.service.*;
|
|
|
+import com.usky.fire.service.util.OnlineMethod;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 企业自主管理大屏统计(全部) 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author JCB
|
|
|
+ * @since 2022-10-09
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class BscEnterpriseAutonomyServiceImpl extends AbstractCrudService<BscEnterpriseAutonomyMapper, BscEnterpriseAutonomy> implements BscEnterpriseAutonomyService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DemBuildScoreService demBuildScoreService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseCompanyService baseCompanyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DemBuildScoreRecordService demBuildScoreRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolInspectionPlanService patrolInspectionPlanService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolInspectionPlanSonService patrolInspectionPlanSonService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolInspectionPlanSiteSonService patrolInspectionPlanSiteSonService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object enterpriseAutonomy(String moduleType, String dataType) {
|
|
|
+ LambdaQueryWrapper<BscEnterpriseAutonomy> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ switch (moduleType) {
|
|
|
+ case "enterpriseAutonomy":
|
|
|
+ queryWrapper.select(BscEnterpriseAutonomy::getEnterpriseAutonomy);
|
|
|
+ break;
|
|
|
+ case "iotDevice":
|
|
|
+ queryWrapper.select(BscEnterpriseAutonomy::getIotDevice);
|
|
|
+ break;
|
|
|
+ case "patrolInspection":
|
|
|
+ queryWrapper.select(BscEnterpriseAutonomy::getPatrolInspection);
|
|
|
+ break;
|
|
|
+ case "streetCompany":
|
|
|
+ queryWrapper.select(BscEnterpriseAutonomy::getStreetCompany);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new BusinessException("参数错误");
|
|
|
+ }
|
|
|
+ queryWrapper.orderByDesc(BscEnterpriseAutonomy::getId)
|
|
|
+ .last(" limit 1");
|
|
|
+ List<BscEnterpriseAutonomy> list = this.list(queryWrapper);
|
|
|
+ Object data = null;
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
+ switch (moduleType) {
|
|
|
+ case "enterpriseAutonomy":
|
|
|
+ data = list.get(0).getEnterpriseAutonomy();
|
|
|
+ break;
|
|
|
+ case "iotDevice":
|
|
|
+ data = list.get(0).getIotDevice();
|
|
|
+ break;
|
|
|
+ case "patrolInspection":
|
|
|
+ data = list.get(0).getPatrolInspection();
|
|
|
+ break;
|
|
|
+ case "streetCompany":
|
|
|
+ data = list.get(0).getStreetCompany();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(data.toString());
|
|
|
+ Object disparateData = jsonObject.get(dataType);
|
|
|
+ return disparateData;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object enterpriseAutonomyData() {
|
|
|
+ String LastMonthDate = OnlineMethod.getLastMonth(new Date());
|
|
|
+ DecimalFormat df = new DecimalFormat("0.00");
|
|
|
+ int deviceDamageCount = 20;
|
|
|
+ int fireCount = 0;
|
|
|
+ int rectificationCount = 40;
|
|
|
+ int buildTypeCount = 10;
|
|
|
+ int highRiskCount = 30;
|
|
|
+ int hiddenDangerCount = 70;
|
|
|
+ List<DemBuildScore> list1 = demBuildScoreService.buildScoreListOne();
|
|
|
+ int companyScoreCount1 = demBuildScoreRecordService.demBuildScoreRecordCount(LastMonthDate, null, 85, null);
|
|
|
+ int companyScoreCount2 = demBuildScoreRecordService.demBuildScoreRecordCount(LastMonthDate, 85, 60, null);
|
|
|
+ int companyScoreCount3 = demBuildScoreRecordService.demBuildScoreRecordCount(LastMonthDate, 60, null, null);
|
|
|
+ int companyScoreRatio = companyScoreCount3 / (companyScoreCount1 + companyScoreCount2 + companyScoreCount3);
|
|
|
+ int companyCount = baseCompanyService.companyCount();
|
|
|
+ Double companyCount1 = Double.valueOf(companyCount);
|
|
|
+ Double deviceDamageRieo = 0.00;
|
|
|
+ Double fireRieo = 0.00;
|
|
|
+ Double rectificationRieo = 0.00;
|
|
|
+ Double buildTypeRieo = 0.00;
|
|
|
+ Double highRiskRieo = 0.00;
|
|
|
+ Double hiddenDangerRieo = 0.00;
|
|
|
+
|
|
|
+ Double deviceDamageScore = 0.00;
|
|
|
+ Double fireScore = 0.00;
|
|
|
+ Double rectificationScore = 0.00;
|
|
|
+ Double buildTypeScore = 0.00;
|
|
|
+ Double highRiskScore = 0.00;
|
|
|
+ Double hiddenDangerScore = 0.00;
|
|
|
+
|
|
|
+ Double deviceDamageScore1 = 0.00;
|
|
|
+ Double fireScore1 = 0.00;
|
|
|
+ Double rectificationScore1 = 0.00;
|
|
|
+ Double buildTypeScore1 = 0.00;
|
|
|
+ Double highRiskScore1 = 0.00;
|
|
|
+ Double hiddenDangerScore1 = 0.00;
|
|
|
+
|
|
|
+ List<Object> data1 = new ArrayList<>();
|
|
|
+ for (int i = 0; i < list1.size(); i++) {
|
|
|
+ Map<String, Object> map1 = new HashMap<>();
|
|
|
+ double sub = 0.0;
|
|
|
+ double div = 0.0;
|
|
|
+ int riskMax = Integer.parseInt(list1.get(i).getRiskMax());
|
|
|
+ int weightProportion = Integer.parseInt(list1.get(i).getWeightProportion());
|
|
|
+ switch (list1.get(i).getRiskId()) {
|
|
|
+ case 1:
|
|
|
+ deviceDamageRieo = Double.valueOf(df.format((float) deviceDamageCount / riskMax * 100));
|
|
|
+ sub = Arith.sub(100, deviceDamageRieo);
|
|
|
+ div = Arith.div(weightProportion, 100);
|
|
|
+ deviceDamageScore = Arith.mul(sub, div);
|
|
|
+ deviceDamageScore1 = Arith.div(deviceDamageScore, companyCount1);
|
|
|
+ map1.put("name", "设备状况指数");
|
|
|
+ map1.put("value", deviceDamageScore1);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ fireRieo = Double.valueOf(df.format((float) fireCount / riskMax * 100));
|
|
|
+ sub = Arith.sub(100, fireRieo);
|
|
|
+ div = Arith.div(weightProportion, 100);
|
|
|
+ fireScore = Arith.mul(sub, div);
|
|
|
+ fireScore1 = Arith.div(fireScore, companyCount1);
|
|
|
+ map1.put("name", "历史火灾指数");
|
|
|
+ map1.put("value", fireScore1);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ rectificationRieo = Double.valueOf(df.format((float) rectificationCount / riskMax * 100));
|
|
|
+ sub = Arith.sub(100, rectificationRieo);
|
|
|
+ div = Arith.div(weightProportion, 100);
|
|
|
+ rectificationScore = Arith.mul(sub, div);
|
|
|
+ rectificationScore1 = Arith.div(rectificationScore, companyCount1);
|
|
|
+ map1.put("name", "执法监管安全指数");
|
|
|
+ map1.put("value", rectificationScore1);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ buildTypeRieo = Double.valueOf(df.format((float) buildTypeCount / riskMax * 100));
|
|
|
+ sub = Arith.sub(100, buildTypeRieo);
|
|
|
+ div = Arith.div(weightProportion, 100);
|
|
|
+ buildTypeScore = Arith.mul(sub, div);
|
|
|
+ buildTypeScore1 = Arith.div(buildTypeScore, companyCount1);
|
|
|
+ map1.put("name", "建筑整体风险指");
|
|
|
+ map1.put("value", buildTypeScore1);
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ highRiskRieo = Double.valueOf(df.format((float) highRiskCount / riskMax * 100));
|
|
|
+ sub = Arith.sub(100, highRiskRieo);
|
|
|
+ div = Arith.div(weightProportion, 100);
|
|
|
+ highRiskScore = Arith.mul(sub, div);
|
|
|
+ highRiskScore1 = Arith.div(highRiskScore, companyCount1);
|
|
|
+ map1.put("name", "场所行业风险指数");
|
|
|
+ map1.put("value", highRiskScore1);
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ hiddenDangerRieo = Double.valueOf(df.format((float) hiddenDangerCount / riskMax * 100));
|
|
|
+ sub = Arith.sub(100, hiddenDangerRieo);
|
|
|
+ div = Arith.div(weightProportion, 100);
|
|
|
+ hiddenDangerScore = Arith.mul(sub, div);
|
|
|
+ hiddenDangerScore1 = Arith.div(hiddenDangerScore, companyCount1);
|
|
|
+ map1.put("name", "隐患状况指数");
|
|
|
+ map1.put("value", hiddenDangerScore1);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ map1.put("mark", "分");
|
|
|
+ data1.add(map1);
|
|
|
+ }
|
|
|
+ List<Object> data2 = new ArrayList<>();
|
|
|
+ for (int i = 0; i < 4; i++) {
|
|
|
+ Map<String, Object> map2 = new HashMap<>();
|
|
|
+ switch (i) {
|
|
|
+ case 0:
|
|
|
+ map2.put("name", "85分以上");
|
|
|
+ map2.put("value", companyScoreCount1);
|
|
|
+ map2.put("mark", "家");
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ map2.put("name", "60~85分");
|
|
|
+ map2.put("value", companyScoreCount2);
|
|
|
+ map2.put("mark", "家");
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ map2.put("name", "60分以下");
|
|
|
+ map2.put("value", companyScoreCount3);
|
|
|
+ map2.put("mark", "家");
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ map2.put("name", "综合风险率");
|
|
|
+ map2.put("value", companyScoreRatio);
|
|
|
+ map2.put("mark", "%");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ data2.add(map2);
|
|
|
+ }
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ List<BscEnterpriseAutonomy> list = this.enterpriseAutonomyList();
|
|
|
+ List<Object> data3 = new ArrayList<>();
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ Map<String, Object> map3 = new HashMap<>();
|
|
|
+ if (!formatter.format(LocalDateTime.now()).equals(formatter.format(list.get(i + list.size() - 1).getCreateTime()))) {
|
|
|
+ map3.put("time", formatter.format(list.get(i + list.size() - 1).getCreateTime()));
|
|
|
+ map3.put("value", list.get(i + list.size() - 1).getRpn());
|
|
|
+ data3.add(map3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, Object> map4 = new HashMap<>();
|
|
|
+ map4.put("time", formatter.format(LocalDateTime.now()));
|
|
|
+ map4.put("value", deviceDamageScore1 + fireScore1 + rectificationScore1 + buildTypeScore1 + highRiskScore1 + hiddenDangerScore1);
|
|
|
+ data3.add(map4);
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("data1", data1);
|
|
|
+ map.put("data2", data2);
|
|
|
+ map.put("data3", data3);
|
|
|
+ map.put("data4", deviceDamageScore1 + fireScore1 + rectificationScore1 + buildTypeScore1 + highRiskScore1 + hiddenDangerScore1);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BscEnterpriseAutonomy> enterpriseAutonomyList() {
|
|
|
+ LambdaQueryWrapper<BscEnterpriseAutonomy> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.select(BscEnterpriseAutonomy::getRpn, BscEnterpriseAutonomy::getCreateTime)
|
|
|
+ .orderByDesc(BscEnterpriseAutonomy::getId)
|
|
|
+ .last(" limit 6");
|
|
|
+ List<BscEnterpriseAutonomy> list = this.list(queryWrapper);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Object iotDevice() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object patrolInspection() {
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String sameDay = format.format(new Date());
|
|
|
+ Integer completedCount = 0;
|
|
|
+ Integer undoneCount = 0;
|
|
|
+ String startTime = null;
|
|
|
+ String endTime = null;
|
|
|
+ List<Object> data1 = new ArrayList<>();
|
|
|
+ List<Object> data2 = new ArrayList<>();
|
|
|
+ List<Object> data3 = new ArrayList<>();
|
|
|
+ for (int i = 0; i < 3; i++) {
|
|
|
+ if (i == 0) {
|
|
|
+ startTime = sameDay;
|
|
|
+ endTime = sameDay;
|
|
|
+ } else if (i == 1) {
|
|
|
+ long timeStamp = OnlineMethod.getLastPeroid(1, new Date());
|
|
|
+ startTime = format.format(timeStamp);
|
|
|
+ endTime = sameDay;
|
|
|
+ } else if (i == 2) {
|
|
|
+ long timeStamp = OnlineMethod.getLastPeroid(2, new Date());
|
|
|
+ startTime = format.format(timeStamp);
|
|
|
+ endTime = sameDay;
|
|
|
+ }
|
|
|
+ List<Integer> planSonIdList1 = this.planSonIdList(startTime,endTime);
|
|
|
+ if (CollectionUtils.isNotEmpty(planSonIdList1)) {
|
|
|
+ undoneCount = patrolInspectionPlanSiteSonService.siteCount(planSonIdList1, 1);
|
|
|
+ completedCount = patrolInspectionPlanSiteSonService.siteCount(planSonIdList1, 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int j = 0; j < 4; j++) {
|
|
|
+ Map<String, Object> map1 = new HashMap<>();
|
|
|
+ switch (i) {
|
|
|
+ case 0:
|
|
|
+ map1.put("name", "今日巡检次数");
|
|
|
+ map1.put("value", undoneCount + completedCount);
|
|
|
+ map1.put("mark", "");
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ map1.put("name", "巡检率");
|
|
|
+ map1.put("value", completedCount / (undoneCount + completedCount) * 100);
|
|
|
+ map1.put("mark", "%");
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ map1.put("name", "合格数");
|
|
|
+ map1.put("value", completedCount);
|
|
|
+ map1.put("mark", "");
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ map1.put("name", "漏检数");
|
|
|
+ map1.put("value", undoneCount);
|
|
|
+ map1.put("mark", "");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (i == 0) {
|
|
|
+ data1.add(map1);
|
|
|
+ } else if (i == 1) {
|
|
|
+ data2.add(map1);
|
|
|
+ } else if (i == 2) {
|
|
|
+ data3.add(map1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("data1",data1);
|
|
|
+ map.put("data2",data2);
|
|
|
+ map.put("data3",data3);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Integer> planSonIdList(String startDate,String endDate) {
|
|
|
+ List<Integer> planSonIdList = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<PatrolInspectionPlan> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.select(PatrolInspectionPlan::getId)
|
|
|
+ .eq(PatrolInspectionPlan::getTenantId, SecurityUtils.getTenantId())
|
|
|
+ .eq(PatrolInspectionPlan::getEnable, 1)
|
|
|
+ .between(PatrolInspectionPlan::getEndDate, startDate, endDate)
|
|
|
+ .between(PatrolInspectionPlan::getStartDate, startDate, endDate);
|
|
|
+ List<PatrolInspectionPlan> planList = patrolInspectionPlanService.list(queryWrapper);
|
|
|
+ if (CollectionUtils.isNotEmpty(planList)) {
|
|
|
+ List<Integer> planIdList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < planList.size(); i++) {
|
|
|
+ planIdList.add(planList.get(i).getId());
|
|
|
+ }
|
|
|
+ List<PatrolInspectionPlanSon> planSonList = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(planIdList)) {
|
|
|
+ LambdaQueryWrapper<PatrolInspectionPlanSon> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper1.select(PatrolInspectionPlanSon::getId)
|
|
|
+ .in(PatrolInspectionPlanSon::getPlanId, planIdList)
|
|
|
+ .between(PatrolInspectionPlanSon::getInspectionDate, startDate, endDate);
|
|
|
+ planSonList = patrolInspectionPlanSonService.list(queryWrapper1);
|
|
|
+ }
|
|
|
+ for (int i = 0; i < planSonList.size(); i++) {
|
|
|
+ planSonIdList.add(planSonList.get(i).getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return planSonIdList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> streetCompany(){
|
|
|
+ QueryWrapper<BaseCompany> query = Wrappers.query();
|
|
|
+ query.select("street_town as streetTown","count(id) as count" )
|
|
|
+ .eq("enable",0)
|
|
|
+ .ne("street_town","")
|
|
|
+ .groupBy("street_town");
|
|
|
+ List<Map<String, Object>> list = baseCompanyService.listMaps(query);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+}
|