diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java index 316188e..71d587d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java @@ -22,4 +22,11 @@ boolean insertCaseInfoBatch(List caseInfos); List caseInfoList(CaseInfoRequest caseInfoRequest); + + List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest); + + Object caseInfoLastByDrawNo(String drawNo); + + int updateAllStatus(); + } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java index 316188e..71d587d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java @@ -22,4 +22,11 @@ boolean insertCaseInfoBatch(List caseInfos); List caseInfoList(CaseInfoRequest caseInfoRequest); + + List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest); + + Object caseInfoLastByDrawNo(String drawNo); + + int updateAllStatus(); + } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java index b3d1968..7a7fe8a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java @@ -2,6 +2,10 @@ import com.alibaba.fastjson.JSONArray; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import java.util.HashMap; import java.util.List; @@ -13,4 +17,32 @@ */ public interface CockpitService { HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap); + + Object buildingNumberPerHour(); + + Object visitorTodayNumber(); + + Object deviceNumber(); + + Object securityNumber(); + + Object visitorApplyDetail(); + + Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO); + + Object eventCategoryStatistics(); + + Object fireEquipStatistics(); + + Object beOnDutyRatio(); + + Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO); + + Object securityScore(SecurityScoreDTO securityScoreDTO); + + Object securityFrequency(); + + Object areaScore(SecurityScoreDTO securityScoreDTO); + + Object heatMap(HeatMapDTO heatMapDTO); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java index 316188e..71d587d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java @@ -22,4 +22,11 @@ boolean insertCaseInfoBatch(List caseInfos); List caseInfoList(CaseInfoRequest caseInfoRequest); + + List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest); + + Object caseInfoLastByDrawNo(String drawNo); + + int updateAllStatus(); + } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java index b3d1968..7a7fe8a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java @@ -2,6 +2,10 @@ import com.alibaba.fastjson.JSONArray; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import java.util.HashMap; import java.util.List; @@ -13,4 +17,32 @@ */ public interface CockpitService { HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap); + + Object buildingNumberPerHour(); + + Object visitorTodayNumber(); + + Object deviceNumber(); + + Object securityNumber(); + + Object visitorApplyDetail(); + + Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO); + + Object eventCategoryStatistics(); + + Object fireEquipStatistics(); + + Object beOnDutyRatio(); + + Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO); + + Object securityScore(SecurityScoreDTO securityScoreDTO); + + Object securityFrequency(); + + Object areaScore(SecurityScoreDTO securityScoreDTO); + + Object heatMap(HeatMapDTO heatMapDTO); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java new file mode 100644 index 0000000..178b909 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.service; + +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; + +/** + * @Description: + * @Author: wangpeng + * @Date: 2022/10/11 9:10 + */ +public interface PropertyManageService { + Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO); + + Object keyAreaData(String dimension); + + Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO); + + Object attendanceNumber(String dimension); + + Object securityAssessment(String dimension); + + Object keyAreaStatistic(); + + Object responseAssess(); + + Object hazardLevelStatistics(String dimension); + + Object securityRank(); + + Object securityLevelAssess(); + + Object commute(); + + Object keyArea(); + + Object visitor(); + + Object security(); + + Object patrol(); + + Object other(); +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java index 316188e..71d587d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java @@ -22,4 +22,11 @@ boolean insertCaseInfoBatch(List caseInfos); List caseInfoList(CaseInfoRequest caseInfoRequest); + + List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest); + + Object caseInfoLastByDrawNo(String drawNo); + + int updateAllStatus(); + } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java index b3d1968..7a7fe8a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java @@ -2,6 +2,10 @@ import com.alibaba.fastjson.JSONArray; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import java.util.HashMap; import java.util.List; @@ -13,4 +17,32 @@ */ public interface CockpitService { HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap); + + Object buildingNumberPerHour(); + + Object visitorTodayNumber(); + + Object deviceNumber(); + + Object securityNumber(); + + Object visitorApplyDetail(); + + Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO); + + Object eventCategoryStatistics(); + + Object fireEquipStatistics(); + + Object beOnDutyRatio(); + + Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO); + + Object securityScore(SecurityScoreDTO securityScoreDTO); + + Object securityFrequency(); + + Object areaScore(SecurityScoreDTO securityScoreDTO); + + Object heatMap(HeatMapDTO heatMapDTO); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java new file mode 100644 index 0000000..178b909 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.service; + +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; + +/** + * @Description: + * @Author: wangpeng + * @Date: 2022/10/11 9:10 + */ +public interface PropertyManageService { + Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO); + + Object keyAreaData(String dimension); + + Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO); + + Object attendanceNumber(String dimension); + + Object securityAssessment(String dimension); + + Object keyAreaStatistic(); + + Object responseAssess(); + + Object hazardLevelStatistics(String dimension); + + Object securityRank(); + + Object securityLevelAssess(); + + Object commute(); + + Object keyArea(); + + Object visitor(); + + Object security(); + + Object patrol(); + + Object other(); +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java index ea6b8c0..2580187 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java @@ -17,6 +17,7 @@ import com.casic.missiles.modular.service.BlackInfoService; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -70,11 +71,17 @@ faceInfo.setCertificateNum(blackInfo.getIdCardNo()); faceSingleAddOrUpdateRequest.setFaceInfo(faceInfo); FacePic facePic = new FacePic(); - facePic.setFaceBinaryData(blackInfo.getPicture()); - faceSingleAddOrUpdateRequest.setFacePic(facePic); + String picture = blackInfo.getPicture(); + if(StringUtils.isNotEmpty(picture)){ + String substringPicture = picture.substring(picture.indexOf(",") + 1); + facePic.setFaceBinaryData(substringPicture); + } faceSingleAddOrUpdateRequest.setFacePic(facePic); String body = JSONObject.toJSONString(faceSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.FACE_SINGLE_ADDITION, body); + log.info("-----------------------"); + log.info("增加黑名单人脸请求body,{}", body); + log.info("增加黑名单人脸resultStr:{}", JSONObject.toJSONString(resultStr)); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人脸失败,海康response:{}", resultStr); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java index 316188e..71d587d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java @@ -22,4 +22,11 @@ boolean insertCaseInfoBatch(List caseInfos); List caseInfoList(CaseInfoRequest caseInfoRequest); + + List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest); + + Object caseInfoLastByDrawNo(String drawNo); + + int updateAllStatus(); + } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java index b3d1968..7a7fe8a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java @@ -2,6 +2,10 @@ import com.alibaba.fastjson.JSONArray; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import java.util.HashMap; import java.util.List; @@ -13,4 +17,32 @@ */ public interface CockpitService { HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap); + + Object buildingNumberPerHour(); + + Object visitorTodayNumber(); + + Object deviceNumber(); + + Object securityNumber(); + + Object visitorApplyDetail(); + + Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO); + + Object eventCategoryStatistics(); + + Object fireEquipStatistics(); + + Object beOnDutyRatio(); + + Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO); + + Object securityScore(SecurityScoreDTO securityScoreDTO); + + Object securityFrequency(); + + Object areaScore(SecurityScoreDTO securityScoreDTO); + + Object heatMap(HeatMapDTO heatMapDTO); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java new file mode 100644 index 0000000..178b909 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.service; + +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; + +/** + * @Description: + * @Author: wangpeng + * @Date: 2022/10/11 9:10 + */ +public interface PropertyManageService { + Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO); + + Object keyAreaData(String dimension); + + Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO); + + Object attendanceNumber(String dimension); + + Object securityAssessment(String dimension); + + Object keyAreaStatistic(); + + Object responseAssess(); + + Object hazardLevelStatistics(String dimension); + + Object securityRank(); + + Object securityLevelAssess(); + + Object commute(); + + Object keyArea(); + + Object visitor(); + + Object security(); + + Object patrol(); + + Object other(); +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java index ea6b8c0..2580187 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java @@ -17,6 +17,7 @@ import com.casic.missiles.modular.service.BlackInfoService; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -70,11 +71,17 @@ faceInfo.setCertificateNum(blackInfo.getIdCardNo()); faceSingleAddOrUpdateRequest.setFaceInfo(faceInfo); FacePic facePic = new FacePic(); - facePic.setFaceBinaryData(blackInfo.getPicture()); - faceSingleAddOrUpdateRequest.setFacePic(facePic); + String picture = blackInfo.getPicture(); + if(StringUtils.isNotEmpty(picture)){ + String substringPicture = picture.substring(picture.indexOf(",") + 1); + facePic.setFaceBinaryData(substringPicture); + } faceSingleAddOrUpdateRequest.setFacePic(facePic); String body = JSONObject.toJSONString(faceSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.FACE_SINGLE_ADDITION, body); + log.info("-----------------------"); + log.info("增加黑名单人脸请求body,{}", body); + log.info("增加黑名单人脸resultStr:{}", JSONObject.toJSONString(resultStr)); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人脸失败,海康response:{}", resultStr); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java index 6b03d8b..1c34f68 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java @@ -2,17 +2,22 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.dao.CaseInfoMapper; import com.casic.missiles.modular.dao.CategoryLevelMapper; +import com.casic.missiles.modular.dao.DeviceInfoMapper; import com.casic.missiles.modular.dao.HazardLevelMapper; import com.casic.missiles.modular.dto.CaseInfoRequest; import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.model.CaseInfo; +import com.casic.missiles.modular.model.DeviceInfo; import com.casic.missiles.modular.service.CaseInfoService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,6 +31,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; /** * @Description: 安防事件service @@ -50,6 +56,9 @@ @Resource private AbstractDictService dictService; + @Resource + private DeviceInfoMapper deviceInfoMapper; + @Override public List caseInfoListPage(Page page, CaseInfoRequest caseInfoRequest) { try { @@ -136,17 +145,69 @@ @Override public List caseInfoList(CaseInfoRequest caseInfoRequest) { try { - List pageList = caseInfoMapper.getCaseInfoList(caseInfoRequest); - pageList.forEach(caseInfo ->{ + List list = caseInfoMapper.getCaseInfoList(caseInfoRequest); + list.forEach(caseInfo ->{ caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); }); - return pageList; + return list; } catch (DataAccessException ex) { log.error("安防事件: 查询不分页出现异常, 异常:{}", ex); } return null; } + + @Override + public List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest) { + try { + List list = caseInfoMapper.getCaseInfoListUnResolved(caseInfoRequest); + list.forEach(caseInfo ->{ + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + }); + return list; + } catch (DataAccessException ex) { + log.error("未解决/解决中安防事件: 查询不分页出现异常, 异常:{}", ex); + } + return null; + } + + @Override + public Object caseInfoLastByDrawNo(String drawNo) { + //图纸编号和设备编号一一对应 + QueryWrapper dWrapper = new QueryWrapper<>(); + dWrapper.eq("draw_no", drawNo); + DeviceInfo deviceInfo = deviceInfoMapper.selectOne(dWrapper); + if(Objects.isNull(deviceInfo)){ + return ResponseData.error("该图纸编号下不存在关联的设备"); + } + if(StringUtils.isEmpty(deviceInfo.getDevCode())){ + return ResponseData.error("该图纸编号下不存在对应的设备编号"); + }else{ + String devCode = deviceInfo.getDevCode(); + QueryWrapper cWrapper = new QueryWrapper<>(); + cWrapper.eq("device_code", devCode); + List caseInfos = caseInfoMapper.selectList(cWrapper); + if(CollectionUtil.isEmpty(caseInfos)){ + return ResponseData.error("该图纸编号下不存在最近发生的事件"); + } + CaseInfo caseInfo = caseInfos.get(caseInfos.size() - 1); + caseInfo.setDrawNo(deviceInfo.getDrawNo()); + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + return ResponseData.success(caseInfo); + } + } + + @Override + public int updateAllStatus() { + int upflag = caseInfoMapper.updateAllStatus(); + return upflag; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java index 316188e..71d587d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java @@ -22,4 +22,11 @@ boolean insertCaseInfoBatch(List caseInfos); List caseInfoList(CaseInfoRequest caseInfoRequest); + + List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest); + + Object caseInfoLastByDrawNo(String drawNo); + + int updateAllStatus(); + } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java index b3d1968..7a7fe8a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java @@ -2,6 +2,10 @@ import com.alibaba.fastjson.JSONArray; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import java.util.HashMap; import java.util.List; @@ -13,4 +17,32 @@ */ public interface CockpitService { HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap); + + Object buildingNumberPerHour(); + + Object visitorTodayNumber(); + + Object deviceNumber(); + + Object securityNumber(); + + Object visitorApplyDetail(); + + Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO); + + Object eventCategoryStatistics(); + + Object fireEquipStatistics(); + + Object beOnDutyRatio(); + + Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO); + + Object securityScore(SecurityScoreDTO securityScoreDTO); + + Object securityFrequency(); + + Object areaScore(SecurityScoreDTO securityScoreDTO); + + Object heatMap(HeatMapDTO heatMapDTO); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java new file mode 100644 index 0000000..178b909 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.service; + +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; + +/** + * @Description: + * @Author: wangpeng + * @Date: 2022/10/11 9:10 + */ +public interface PropertyManageService { + Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO); + + Object keyAreaData(String dimension); + + Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO); + + Object attendanceNumber(String dimension); + + Object securityAssessment(String dimension); + + Object keyAreaStatistic(); + + Object responseAssess(); + + Object hazardLevelStatistics(String dimension); + + Object securityRank(); + + Object securityLevelAssess(); + + Object commute(); + + Object keyArea(); + + Object visitor(); + + Object security(); + + Object patrol(); + + Object other(); +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java index ea6b8c0..2580187 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java @@ -17,6 +17,7 @@ import com.casic.missiles.modular.service.BlackInfoService; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -70,11 +71,17 @@ faceInfo.setCertificateNum(blackInfo.getIdCardNo()); faceSingleAddOrUpdateRequest.setFaceInfo(faceInfo); FacePic facePic = new FacePic(); - facePic.setFaceBinaryData(blackInfo.getPicture()); - faceSingleAddOrUpdateRequest.setFacePic(facePic); + String picture = blackInfo.getPicture(); + if(StringUtils.isNotEmpty(picture)){ + String substringPicture = picture.substring(picture.indexOf(",") + 1); + facePic.setFaceBinaryData(substringPicture); + } faceSingleAddOrUpdateRequest.setFacePic(facePic); String body = JSONObject.toJSONString(faceSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.FACE_SINGLE_ADDITION, body); + log.info("-----------------------"); + log.info("增加黑名单人脸请求body,{}", body); + log.info("增加黑名单人脸resultStr:{}", JSONObject.toJSONString(resultStr)); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人脸失败,海康response:{}", resultStr); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java index 6b03d8b..1c34f68 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java @@ -2,17 +2,22 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.dao.CaseInfoMapper; import com.casic.missiles.modular.dao.CategoryLevelMapper; +import com.casic.missiles.modular.dao.DeviceInfoMapper; import com.casic.missiles.modular.dao.HazardLevelMapper; import com.casic.missiles.modular.dto.CaseInfoRequest; import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.model.CaseInfo; +import com.casic.missiles.modular.model.DeviceInfo; import com.casic.missiles.modular.service.CaseInfoService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,6 +31,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; /** * @Description: 安防事件service @@ -50,6 +56,9 @@ @Resource private AbstractDictService dictService; + @Resource + private DeviceInfoMapper deviceInfoMapper; + @Override public List caseInfoListPage(Page page, CaseInfoRequest caseInfoRequest) { try { @@ -136,17 +145,69 @@ @Override public List caseInfoList(CaseInfoRequest caseInfoRequest) { try { - List pageList = caseInfoMapper.getCaseInfoList(caseInfoRequest); - pageList.forEach(caseInfo ->{ + List list = caseInfoMapper.getCaseInfoList(caseInfoRequest); + list.forEach(caseInfo ->{ caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); }); - return pageList; + return list; } catch (DataAccessException ex) { log.error("安防事件: 查询不分页出现异常, 异常:{}", ex); } return null; } + + @Override + public List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest) { + try { + List list = caseInfoMapper.getCaseInfoListUnResolved(caseInfoRequest); + list.forEach(caseInfo ->{ + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + }); + return list; + } catch (DataAccessException ex) { + log.error("未解决/解决中安防事件: 查询不分页出现异常, 异常:{}", ex); + } + return null; + } + + @Override + public Object caseInfoLastByDrawNo(String drawNo) { + //图纸编号和设备编号一一对应 + QueryWrapper dWrapper = new QueryWrapper<>(); + dWrapper.eq("draw_no", drawNo); + DeviceInfo deviceInfo = deviceInfoMapper.selectOne(dWrapper); + if(Objects.isNull(deviceInfo)){ + return ResponseData.error("该图纸编号下不存在关联的设备"); + } + if(StringUtils.isEmpty(deviceInfo.getDevCode())){ + return ResponseData.error("该图纸编号下不存在对应的设备编号"); + }else{ + String devCode = deviceInfo.getDevCode(); + QueryWrapper cWrapper = new QueryWrapper<>(); + cWrapper.eq("device_code", devCode); + List caseInfos = caseInfoMapper.selectList(cWrapper); + if(CollectionUtil.isEmpty(caseInfos)){ + return ResponseData.error("该图纸编号下不存在最近发生的事件"); + } + CaseInfo caseInfo = caseInfos.get(caseInfos.size() - 1); + caseInfo.setDrawNo(deviceInfo.getDrawNo()); + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + return ResponseData.success(caseInfo); + } + } + + @Override + public int updateAllStatus() { + int upflag = caseInfoMapper.updateAllStatus(); + return upflag; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java index 7402991..7fb5a6e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java @@ -4,15 +4,34 @@ import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.*; import com.casic.missiles.modular.enums.HikUri; +import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.redis.RedisUtil; +import com.casic.missiles.modular.redis.key.CacheKeys; import com.casic.missiles.modular.service.CockpitService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import java.text.MessageFormat; +import java.text.NumberFormat; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.*; +import java.util.stream.Collectors; /** * @Description: @@ -22,6 +41,28 @@ @Slf4j @Service public class CockpitServiceImpl implements CockpitService { + @Autowired + private StatisticNumberMapper numberMapper; + @Autowired + private AbstractDictService dictService; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private DeviceInfoMapper deviceInfoMapper; + @Autowired + private FireEquipInfoMapper fireEquipInfoMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private VisitorApplyMapper applyMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private RedisUtil redisUtil; @Override public HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap) { @@ -106,4 +147,512 @@ }); return resultMap; } + + @Override + public Object buildingNumberPerHour() { + //当天按小时分组的人数 + List list = numberMapper.selectListByTime(); + Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); + //定时任务中已将每小时三栋楼人数存到数据库 + //将一期主楼和录制楼人数合并,二期单算 + List> resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List buildingNumberDTOS = collect.get(key); + BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); + BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); + BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); + HashMap resultMap = new HashMap<>(); + Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); + Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); + resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); + resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); + resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); + resultList.add(resultMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object visitorTodayNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); + List visitInfos = visitInfoMapper.selectList(wrapper); + HashMap resultMap = new HashMap<>(); + resultMap.put("今日访客量", visitInfos.size()); + return ResponseData.success(resultMap); + } + + @Override + public Object deviceNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + Integer total = deviceInfoMapper.selectCount(wrapper); + QueryWrapper wrapper1 = new QueryWrapper<>(); + wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 + Integer online = deviceInfoMapper.selectCount(wrapper1); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) online / (float) total * 100); + HashMap resultMap = new HashMap<>(); + resultMap.put("设备总数", total); + resultMap.put("设备在线率", result + "%"); + return ResponseData.success(resultMap); + } + + @Override + public Object securityNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) leave / (float) total * 100); + HashMap resultMap = new HashMap<>(); + if (0 == total) { + resultMap.put("安保人员总数", 0); + resultMap.put("安保人员离岗率", "0"); + } else { + resultMap.put("安保人员总数", total); + resultMap.put("安保人员离岗率", result + ""); + } + return ResponseData.success(resultMap); + } + + @Override + public Object visitorApplyDetail() { + List reasonGroup = applyMapper.selectByVisitReason(); + List resultList = new ArrayList<>(); + //空数据处理 + List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); + if (CollectionUtils.isEmpty(reasonGroup)) { + for (Dict dict : visitReason) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(dict.getName()); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); + if (0 == sum) { + return ResponseData.success(); + } + reasonGroup.forEach(group -> { + String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(group.getQuantity()); + applyReasonGroupDTO.setVisitReason(reasonName); + applyReasonGroupDTO.setRatio(result + "%"); + resultList.add(applyReasonGroupDTO); + }); + //返回数据补全处理 + if (resultList.size() < visitReason.size()) { + List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); + for (Dict dict : visitReason) { + String name = dict.getName(); + if (!collect.contains(name)) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(name); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO) { + //查询各危险级别权重name,用于构造返回结构 + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); + + Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); + List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(list)) { + Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + //查询数据,放入redis + List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); + Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //设置过期时间为每月1号0点 + LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) + .withMinute(0).withSecond(0).withNano(0); + long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); + redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + + @Override + public Object eventCategoryStatistics() { + List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); + return ResponseData.success(categoryLevelGroup); + } + + @Override + public Object fireEquipStatistics() { + List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); + //空数据处理 + List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); + if (CollectionUtils.isEmpty(equipTypeGroup)) { + for (Dict dict : equipType) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + return ResponseData.success(equipTypeGroup); + } + equipTypeGroup.forEach(group -> { + String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); + group.setEquipTypeName(equipTypeName); + }); + //返回数据补全处理 + if (equipTypeGroup.size() < equipType.size()) { + List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); + for (Dict dict : equipType) { + String code = dict.getCode(); + if (!collect.contains(code)) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + } + } + return ResponseData.success(equipTypeGroup); + } + + @Override + public Object beOnDutyRatio() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + if (0 == total) { + return ResponseData.success(null); + } + List currentDateHourList = DateUtils.getCurrentDateWorkHourList(); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + //补全空数据 + if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { + for (String date : currentDateHourList) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + return ResponseData.success(onDutyRatioDTOS); + } + onDutyRatioDTOS.forEach(dto -> { + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); + dto.setRatio(result + "%"); + }); + //补全空数据 + List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); + for (String date : currentDateHourList) { + if (!collect.contains(date)) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + } + return ResponseData.success(onDutyRatioDTOS); + } + + @Override + public Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO) { + List gateStatusGroup = null; + //2代表所有摄像头(对应字典2-7) + if ("2".equals(gateStatusGroupDTO.getDevType())) { + gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); + } else { + gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); + } + HashMap resultMap = new HashMap<>(); + //空数据处理 + List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); + if (CollectionUtils.isEmpty(gateStatusGroup)) { + List resultList = new ArrayList<>(); + for (Dict dict : deviceStatus) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + resultMap.put("total", 0); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("无该类设备信息"); + } + List resultList = new ArrayList<>(); + gateStatusGroup.forEach(group -> { + if ("2".equals(gateStatusGroupDTO.getDevType())) { + group.setDevType("2"); + } + String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(devStatus); + gateStatusGroupResponse.setRatio(result + "%"); + gateStatusGroupResponse.setQuantity(group.getQuantity()); + resultList.add(gateStatusGroupResponse); + }); + //返回数据补全处理 + if (resultList.size() < deviceStatus.size()) { + List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); + for (Dict dict : deviceStatus) { + String name = dict.getName(); + if (!collect.contains(name)) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + } + } + resultMap.put("total", sum); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + + @Override + public Object securityScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的position划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + List caseInfos = caseInfoMapper.selectByPosition(position); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //楼栋-评分实体map + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + Map resultMap = new HashMap<>(); + //空数据处理 + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + resultMap.put(dict.getName(), 100.0); + } + return ResponseData.success(resultMap); + } + + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + + collect.keySet().forEach(key -> { + List list = collect.get(key); + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); + resultMap.put(dictValue, 100 - collect1.getSum()); + }); + //返回数据补全处理 + if (collect.size() < devicePosition.size()) { + Set strings = resultMap.keySet(); + for (Dict dict : devicePosition) { + String name = dict.getName(); + if (!strings.contains(name)) { + resultMap.put(dict.getName(), 100.0); + } + } + } + //按楼层分组计算评分 +// collect.keySet().forEach(key -> { +// Map map = new HashMap<>(); +// List securityScoreDTOS = collect.get(key); +// //楼层-评分map +// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); +// collect1.keySet().forEach(key1 -> { +// map.put(key1, 100 - collect1.get(key1)); +// }); +// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); +// resultMap.put(dictValue, map); +// }); + return ResponseData.success(resultMap); + } + + @Override + public Object securityFrequency() { + String year = String.valueOf(DateUtil.thisYear()); + String month = String.valueOf(DateUtil.thisMonth()); + Integer quantity = caseInfoMapper.selectCountByMonth(year, month); + SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); + securityFrequencyDTO.setQuantity(quantity); + securityFrequencyDTO.setYear(year); + securityFrequencyDTO.setMonth(month); + return ResponseData.success(securityFrequencyDTO); + } + + @Override + public Object areaScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的area划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + String area = securityScoreDTO.getArea(); + if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { + return null; + } + Map resultMap = new HashMap<>(); + List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); + if (Objects.isNull(caseInfos)) { + resultMap.put("安防评分", 100.0); + return ResponseData.success(resultMap); + } + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + resultMap.put("安防评分", 100 - collect.getSum()); + return ResponseData.success(resultMap); + } + + @Override + public Object heatMap(HeatMapDTO heatMapDTO) { + if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { + heatMapDTO.setMinute(3); + } + List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); + Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); + HashMap resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect)) { + return ResponseData.success(); + } + collect.keySet().forEach(key -> { + resultMap.put(key, collect.get(key).size()); + }); + return ResponseData.success(resultMap); + } + + private List> getResultMap(List nameList, List> resultList, Map> resultMap) { + resultMap.keySet().forEach(key -> { + List monthAndLevelGroupDTOS = resultMap.get(key); + HashMap hashMap = new HashMap<>(); + for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { +// hashMap.put("年份", andLevelGroupDTO.getYear()); + hashMap.put("月份", /*andLevelGroupDTO.getYear() + "-" + */Integer.valueOf(andLevelGroupDTO.getMonth())); + hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); + } + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + }); + //12个月份,用于构造返回结构 + List list1 = new ArrayList<>(); + for (Map map : resultList) { + list1.add(String.valueOf(map.get("月份"))); + } + for (int i = 1; i < 13; i++) { + if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { + continue; + } + HashMap hashMap = new HashMap<>(); + hashMap.put("月份", i); + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + } + List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); + return results; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java index 316188e..71d587d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java @@ -22,4 +22,11 @@ boolean insertCaseInfoBatch(List caseInfos); List caseInfoList(CaseInfoRequest caseInfoRequest); + + List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest); + + Object caseInfoLastByDrawNo(String drawNo); + + int updateAllStatus(); + } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java index b3d1968..7a7fe8a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java @@ -2,6 +2,10 @@ import com.alibaba.fastjson.JSONArray; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import java.util.HashMap; import java.util.List; @@ -13,4 +17,32 @@ */ public interface CockpitService { HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap); + + Object buildingNumberPerHour(); + + Object visitorTodayNumber(); + + Object deviceNumber(); + + Object securityNumber(); + + Object visitorApplyDetail(); + + Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO); + + Object eventCategoryStatistics(); + + Object fireEquipStatistics(); + + Object beOnDutyRatio(); + + Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO); + + Object securityScore(SecurityScoreDTO securityScoreDTO); + + Object securityFrequency(); + + Object areaScore(SecurityScoreDTO securityScoreDTO); + + Object heatMap(HeatMapDTO heatMapDTO); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java new file mode 100644 index 0000000..178b909 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.service; + +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; + +/** + * @Description: + * @Author: wangpeng + * @Date: 2022/10/11 9:10 + */ +public interface PropertyManageService { + Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO); + + Object keyAreaData(String dimension); + + Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO); + + Object attendanceNumber(String dimension); + + Object securityAssessment(String dimension); + + Object keyAreaStatistic(); + + Object responseAssess(); + + Object hazardLevelStatistics(String dimension); + + Object securityRank(); + + Object securityLevelAssess(); + + Object commute(); + + Object keyArea(); + + Object visitor(); + + Object security(); + + Object patrol(); + + Object other(); +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java index ea6b8c0..2580187 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java @@ -17,6 +17,7 @@ import com.casic.missiles.modular.service.BlackInfoService; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -70,11 +71,17 @@ faceInfo.setCertificateNum(blackInfo.getIdCardNo()); faceSingleAddOrUpdateRequest.setFaceInfo(faceInfo); FacePic facePic = new FacePic(); - facePic.setFaceBinaryData(blackInfo.getPicture()); - faceSingleAddOrUpdateRequest.setFacePic(facePic); + String picture = blackInfo.getPicture(); + if(StringUtils.isNotEmpty(picture)){ + String substringPicture = picture.substring(picture.indexOf(",") + 1); + facePic.setFaceBinaryData(substringPicture); + } faceSingleAddOrUpdateRequest.setFacePic(facePic); String body = JSONObject.toJSONString(faceSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.FACE_SINGLE_ADDITION, body); + log.info("-----------------------"); + log.info("增加黑名单人脸请求body,{}", body); + log.info("增加黑名单人脸resultStr:{}", JSONObject.toJSONString(resultStr)); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人脸失败,海康response:{}", resultStr); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java index 6b03d8b..1c34f68 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java @@ -2,17 +2,22 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.dao.CaseInfoMapper; import com.casic.missiles.modular.dao.CategoryLevelMapper; +import com.casic.missiles.modular.dao.DeviceInfoMapper; import com.casic.missiles.modular.dao.HazardLevelMapper; import com.casic.missiles.modular.dto.CaseInfoRequest; import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.model.CaseInfo; +import com.casic.missiles.modular.model.DeviceInfo; import com.casic.missiles.modular.service.CaseInfoService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,6 +31,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; /** * @Description: 安防事件service @@ -50,6 +56,9 @@ @Resource private AbstractDictService dictService; + @Resource + private DeviceInfoMapper deviceInfoMapper; + @Override public List caseInfoListPage(Page page, CaseInfoRequest caseInfoRequest) { try { @@ -136,17 +145,69 @@ @Override public List caseInfoList(CaseInfoRequest caseInfoRequest) { try { - List pageList = caseInfoMapper.getCaseInfoList(caseInfoRequest); - pageList.forEach(caseInfo ->{ + List list = caseInfoMapper.getCaseInfoList(caseInfoRequest); + list.forEach(caseInfo ->{ caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); }); - return pageList; + return list; } catch (DataAccessException ex) { log.error("安防事件: 查询不分页出现异常, 异常:{}", ex); } return null; } + + @Override + public List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest) { + try { + List list = caseInfoMapper.getCaseInfoListUnResolved(caseInfoRequest); + list.forEach(caseInfo ->{ + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + }); + return list; + } catch (DataAccessException ex) { + log.error("未解决/解决中安防事件: 查询不分页出现异常, 异常:{}", ex); + } + return null; + } + + @Override + public Object caseInfoLastByDrawNo(String drawNo) { + //图纸编号和设备编号一一对应 + QueryWrapper dWrapper = new QueryWrapper<>(); + dWrapper.eq("draw_no", drawNo); + DeviceInfo deviceInfo = deviceInfoMapper.selectOne(dWrapper); + if(Objects.isNull(deviceInfo)){ + return ResponseData.error("该图纸编号下不存在关联的设备"); + } + if(StringUtils.isEmpty(deviceInfo.getDevCode())){ + return ResponseData.error("该图纸编号下不存在对应的设备编号"); + }else{ + String devCode = deviceInfo.getDevCode(); + QueryWrapper cWrapper = new QueryWrapper<>(); + cWrapper.eq("device_code", devCode); + List caseInfos = caseInfoMapper.selectList(cWrapper); + if(CollectionUtil.isEmpty(caseInfos)){ + return ResponseData.error("该图纸编号下不存在最近发生的事件"); + } + CaseInfo caseInfo = caseInfos.get(caseInfos.size() - 1); + caseInfo.setDrawNo(deviceInfo.getDrawNo()); + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + return ResponseData.success(caseInfo); + } + } + + @Override + public int updateAllStatus() { + int upflag = caseInfoMapper.updateAllStatus(); + return upflag; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java index 7402991..7fb5a6e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java @@ -4,15 +4,34 @@ import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.*; import com.casic.missiles.modular.enums.HikUri; +import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.redis.RedisUtil; +import com.casic.missiles.modular.redis.key.CacheKeys; import com.casic.missiles.modular.service.CockpitService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import java.text.MessageFormat; +import java.text.NumberFormat; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.*; +import java.util.stream.Collectors; /** * @Description: @@ -22,6 +41,28 @@ @Slf4j @Service public class CockpitServiceImpl implements CockpitService { + @Autowired + private StatisticNumberMapper numberMapper; + @Autowired + private AbstractDictService dictService; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private DeviceInfoMapper deviceInfoMapper; + @Autowired + private FireEquipInfoMapper fireEquipInfoMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private VisitorApplyMapper applyMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private RedisUtil redisUtil; @Override public HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap) { @@ -106,4 +147,512 @@ }); return resultMap; } + + @Override + public Object buildingNumberPerHour() { + //当天按小时分组的人数 + List list = numberMapper.selectListByTime(); + Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); + //定时任务中已将每小时三栋楼人数存到数据库 + //将一期主楼和录制楼人数合并,二期单算 + List> resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List buildingNumberDTOS = collect.get(key); + BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); + BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); + BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); + HashMap resultMap = new HashMap<>(); + Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); + Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); + resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); + resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); + resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); + resultList.add(resultMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object visitorTodayNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); + List visitInfos = visitInfoMapper.selectList(wrapper); + HashMap resultMap = new HashMap<>(); + resultMap.put("今日访客量", visitInfos.size()); + return ResponseData.success(resultMap); + } + + @Override + public Object deviceNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + Integer total = deviceInfoMapper.selectCount(wrapper); + QueryWrapper wrapper1 = new QueryWrapper<>(); + wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 + Integer online = deviceInfoMapper.selectCount(wrapper1); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) online / (float) total * 100); + HashMap resultMap = new HashMap<>(); + resultMap.put("设备总数", total); + resultMap.put("设备在线率", result + "%"); + return ResponseData.success(resultMap); + } + + @Override + public Object securityNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) leave / (float) total * 100); + HashMap resultMap = new HashMap<>(); + if (0 == total) { + resultMap.put("安保人员总数", 0); + resultMap.put("安保人员离岗率", "0"); + } else { + resultMap.put("安保人员总数", total); + resultMap.put("安保人员离岗率", result + ""); + } + return ResponseData.success(resultMap); + } + + @Override + public Object visitorApplyDetail() { + List reasonGroup = applyMapper.selectByVisitReason(); + List resultList = new ArrayList<>(); + //空数据处理 + List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); + if (CollectionUtils.isEmpty(reasonGroup)) { + for (Dict dict : visitReason) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(dict.getName()); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); + if (0 == sum) { + return ResponseData.success(); + } + reasonGroup.forEach(group -> { + String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(group.getQuantity()); + applyReasonGroupDTO.setVisitReason(reasonName); + applyReasonGroupDTO.setRatio(result + "%"); + resultList.add(applyReasonGroupDTO); + }); + //返回数据补全处理 + if (resultList.size() < visitReason.size()) { + List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); + for (Dict dict : visitReason) { + String name = dict.getName(); + if (!collect.contains(name)) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(name); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO) { + //查询各危险级别权重name,用于构造返回结构 + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); + + Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); + List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(list)) { + Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + //查询数据,放入redis + List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); + Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //设置过期时间为每月1号0点 + LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) + .withMinute(0).withSecond(0).withNano(0); + long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); + redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + + @Override + public Object eventCategoryStatistics() { + List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); + return ResponseData.success(categoryLevelGroup); + } + + @Override + public Object fireEquipStatistics() { + List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); + //空数据处理 + List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); + if (CollectionUtils.isEmpty(equipTypeGroup)) { + for (Dict dict : equipType) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + return ResponseData.success(equipTypeGroup); + } + equipTypeGroup.forEach(group -> { + String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); + group.setEquipTypeName(equipTypeName); + }); + //返回数据补全处理 + if (equipTypeGroup.size() < equipType.size()) { + List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); + for (Dict dict : equipType) { + String code = dict.getCode(); + if (!collect.contains(code)) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + } + } + return ResponseData.success(equipTypeGroup); + } + + @Override + public Object beOnDutyRatio() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + if (0 == total) { + return ResponseData.success(null); + } + List currentDateHourList = DateUtils.getCurrentDateWorkHourList(); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + //补全空数据 + if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { + for (String date : currentDateHourList) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + return ResponseData.success(onDutyRatioDTOS); + } + onDutyRatioDTOS.forEach(dto -> { + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); + dto.setRatio(result + "%"); + }); + //补全空数据 + List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); + for (String date : currentDateHourList) { + if (!collect.contains(date)) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + } + return ResponseData.success(onDutyRatioDTOS); + } + + @Override + public Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO) { + List gateStatusGroup = null; + //2代表所有摄像头(对应字典2-7) + if ("2".equals(gateStatusGroupDTO.getDevType())) { + gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); + } else { + gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); + } + HashMap resultMap = new HashMap<>(); + //空数据处理 + List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); + if (CollectionUtils.isEmpty(gateStatusGroup)) { + List resultList = new ArrayList<>(); + for (Dict dict : deviceStatus) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + resultMap.put("total", 0); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("无该类设备信息"); + } + List resultList = new ArrayList<>(); + gateStatusGroup.forEach(group -> { + if ("2".equals(gateStatusGroupDTO.getDevType())) { + group.setDevType("2"); + } + String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(devStatus); + gateStatusGroupResponse.setRatio(result + "%"); + gateStatusGroupResponse.setQuantity(group.getQuantity()); + resultList.add(gateStatusGroupResponse); + }); + //返回数据补全处理 + if (resultList.size() < deviceStatus.size()) { + List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); + for (Dict dict : deviceStatus) { + String name = dict.getName(); + if (!collect.contains(name)) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + } + } + resultMap.put("total", sum); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + + @Override + public Object securityScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的position划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + List caseInfos = caseInfoMapper.selectByPosition(position); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //楼栋-评分实体map + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + Map resultMap = new HashMap<>(); + //空数据处理 + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + resultMap.put(dict.getName(), 100.0); + } + return ResponseData.success(resultMap); + } + + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + + collect.keySet().forEach(key -> { + List list = collect.get(key); + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); + resultMap.put(dictValue, 100 - collect1.getSum()); + }); + //返回数据补全处理 + if (collect.size() < devicePosition.size()) { + Set strings = resultMap.keySet(); + for (Dict dict : devicePosition) { + String name = dict.getName(); + if (!strings.contains(name)) { + resultMap.put(dict.getName(), 100.0); + } + } + } + //按楼层分组计算评分 +// collect.keySet().forEach(key -> { +// Map map = new HashMap<>(); +// List securityScoreDTOS = collect.get(key); +// //楼层-评分map +// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); +// collect1.keySet().forEach(key1 -> { +// map.put(key1, 100 - collect1.get(key1)); +// }); +// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); +// resultMap.put(dictValue, map); +// }); + return ResponseData.success(resultMap); + } + + @Override + public Object securityFrequency() { + String year = String.valueOf(DateUtil.thisYear()); + String month = String.valueOf(DateUtil.thisMonth()); + Integer quantity = caseInfoMapper.selectCountByMonth(year, month); + SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); + securityFrequencyDTO.setQuantity(quantity); + securityFrequencyDTO.setYear(year); + securityFrequencyDTO.setMonth(month); + return ResponseData.success(securityFrequencyDTO); + } + + @Override + public Object areaScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的area划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + String area = securityScoreDTO.getArea(); + if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { + return null; + } + Map resultMap = new HashMap<>(); + List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); + if (Objects.isNull(caseInfos)) { + resultMap.put("安防评分", 100.0); + return ResponseData.success(resultMap); + } + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + resultMap.put("安防评分", 100 - collect.getSum()); + return ResponseData.success(resultMap); + } + + @Override + public Object heatMap(HeatMapDTO heatMapDTO) { + if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { + heatMapDTO.setMinute(3); + } + List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); + Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); + HashMap resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect)) { + return ResponseData.success(); + } + collect.keySet().forEach(key -> { + resultMap.put(key, collect.get(key).size()); + }); + return ResponseData.success(resultMap); + } + + private List> getResultMap(List nameList, List> resultList, Map> resultMap) { + resultMap.keySet().forEach(key -> { + List monthAndLevelGroupDTOS = resultMap.get(key); + HashMap hashMap = new HashMap<>(); + for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { +// hashMap.put("年份", andLevelGroupDTO.getYear()); + hashMap.put("月份", /*andLevelGroupDTO.getYear() + "-" + */Integer.valueOf(andLevelGroupDTO.getMonth())); + hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); + } + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + }); + //12个月份,用于构造返回结构 + List list1 = new ArrayList<>(); + for (Map map : resultList) { + list1.add(String.valueOf(map.get("月份"))); + } + for (int i = 1; i < 13; i++) { + if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { + continue; + } + HashMap hashMap = new HashMap<>(); + hashMap.put("月份", i); + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + } + List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); + return results; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java index 94308db..f91d7bd 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java @@ -427,6 +427,13 @@ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("draw_no", drawNo); DeviceInfo deviceInfo = deviceInfoMapper.selectOne(wrapper); + if(!Objects.isNull(deviceInfo)){ + deviceInfo.setDevTypeName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_TYPE, deviceInfo.getDevType())); + deviceInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, deviceInfo.getStatus())); + deviceInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, deviceInfo.getPosition())); + deviceInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, deviceInfo.getArea())); + deviceInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, deviceInfo.getIsKeyArea())); + } return deviceInfo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java index 316188e..71d587d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java @@ -22,4 +22,11 @@ boolean insertCaseInfoBatch(List caseInfos); List caseInfoList(CaseInfoRequest caseInfoRequest); + + List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest); + + Object caseInfoLastByDrawNo(String drawNo); + + int updateAllStatus(); + } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java index b3d1968..7a7fe8a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java @@ -2,6 +2,10 @@ import com.alibaba.fastjson.JSONArray; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import java.util.HashMap; import java.util.List; @@ -13,4 +17,32 @@ */ public interface CockpitService { HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap); + + Object buildingNumberPerHour(); + + Object visitorTodayNumber(); + + Object deviceNumber(); + + Object securityNumber(); + + Object visitorApplyDetail(); + + Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO); + + Object eventCategoryStatistics(); + + Object fireEquipStatistics(); + + Object beOnDutyRatio(); + + Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO); + + Object securityScore(SecurityScoreDTO securityScoreDTO); + + Object securityFrequency(); + + Object areaScore(SecurityScoreDTO securityScoreDTO); + + Object heatMap(HeatMapDTO heatMapDTO); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java new file mode 100644 index 0000000..178b909 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.service; + +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; + +/** + * @Description: + * @Author: wangpeng + * @Date: 2022/10/11 9:10 + */ +public interface PropertyManageService { + Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO); + + Object keyAreaData(String dimension); + + Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO); + + Object attendanceNumber(String dimension); + + Object securityAssessment(String dimension); + + Object keyAreaStatistic(); + + Object responseAssess(); + + Object hazardLevelStatistics(String dimension); + + Object securityRank(); + + Object securityLevelAssess(); + + Object commute(); + + Object keyArea(); + + Object visitor(); + + Object security(); + + Object patrol(); + + Object other(); +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java index ea6b8c0..2580187 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java @@ -17,6 +17,7 @@ import com.casic.missiles.modular.service.BlackInfoService; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -70,11 +71,17 @@ faceInfo.setCertificateNum(blackInfo.getIdCardNo()); faceSingleAddOrUpdateRequest.setFaceInfo(faceInfo); FacePic facePic = new FacePic(); - facePic.setFaceBinaryData(blackInfo.getPicture()); - faceSingleAddOrUpdateRequest.setFacePic(facePic); + String picture = blackInfo.getPicture(); + if(StringUtils.isNotEmpty(picture)){ + String substringPicture = picture.substring(picture.indexOf(",") + 1); + facePic.setFaceBinaryData(substringPicture); + } faceSingleAddOrUpdateRequest.setFacePic(facePic); String body = JSONObject.toJSONString(faceSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.FACE_SINGLE_ADDITION, body); + log.info("-----------------------"); + log.info("增加黑名单人脸请求body,{}", body); + log.info("增加黑名单人脸resultStr:{}", JSONObject.toJSONString(resultStr)); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人脸失败,海康response:{}", resultStr); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java index 6b03d8b..1c34f68 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java @@ -2,17 +2,22 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.dao.CaseInfoMapper; import com.casic.missiles.modular.dao.CategoryLevelMapper; +import com.casic.missiles.modular.dao.DeviceInfoMapper; import com.casic.missiles.modular.dao.HazardLevelMapper; import com.casic.missiles.modular.dto.CaseInfoRequest; import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.model.CaseInfo; +import com.casic.missiles.modular.model.DeviceInfo; import com.casic.missiles.modular.service.CaseInfoService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,6 +31,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; /** * @Description: 安防事件service @@ -50,6 +56,9 @@ @Resource private AbstractDictService dictService; + @Resource + private DeviceInfoMapper deviceInfoMapper; + @Override public List caseInfoListPage(Page page, CaseInfoRequest caseInfoRequest) { try { @@ -136,17 +145,69 @@ @Override public List caseInfoList(CaseInfoRequest caseInfoRequest) { try { - List pageList = caseInfoMapper.getCaseInfoList(caseInfoRequest); - pageList.forEach(caseInfo ->{ + List list = caseInfoMapper.getCaseInfoList(caseInfoRequest); + list.forEach(caseInfo ->{ caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); }); - return pageList; + return list; } catch (DataAccessException ex) { log.error("安防事件: 查询不分页出现异常, 异常:{}", ex); } return null; } + + @Override + public List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest) { + try { + List list = caseInfoMapper.getCaseInfoListUnResolved(caseInfoRequest); + list.forEach(caseInfo ->{ + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + }); + return list; + } catch (DataAccessException ex) { + log.error("未解决/解决中安防事件: 查询不分页出现异常, 异常:{}", ex); + } + return null; + } + + @Override + public Object caseInfoLastByDrawNo(String drawNo) { + //图纸编号和设备编号一一对应 + QueryWrapper dWrapper = new QueryWrapper<>(); + dWrapper.eq("draw_no", drawNo); + DeviceInfo deviceInfo = deviceInfoMapper.selectOne(dWrapper); + if(Objects.isNull(deviceInfo)){ + return ResponseData.error("该图纸编号下不存在关联的设备"); + } + if(StringUtils.isEmpty(deviceInfo.getDevCode())){ + return ResponseData.error("该图纸编号下不存在对应的设备编号"); + }else{ + String devCode = deviceInfo.getDevCode(); + QueryWrapper cWrapper = new QueryWrapper<>(); + cWrapper.eq("device_code", devCode); + List caseInfos = caseInfoMapper.selectList(cWrapper); + if(CollectionUtil.isEmpty(caseInfos)){ + return ResponseData.error("该图纸编号下不存在最近发生的事件"); + } + CaseInfo caseInfo = caseInfos.get(caseInfos.size() - 1); + caseInfo.setDrawNo(deviceInfo.getDrawNo()); + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + return ResponseData.success(caseInfo); + } + } + + @Override + public int updateAllStatus() { + int upflag = caseInfoMapper.updateAllStatus(); + return upflag; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java index 7402991..7fb5a6e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java @@ -4,15 +4,34 @@ import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.*; import com.casic.missiles.modular.enums.HikUri; +import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.redis.RedisUtil; +import com.casic.missiles.modular.redis.key.CacheKeys; import com.casic.missiles.modular.service.CockpitService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import java.text.MessageFormat; +import java.text.NumberFormat; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.*; +import java.util.stream.Collectors; /** * @Description: @@ -22,6 +41,28 @@ @Slf4j @Service public class CockpitServiceImpl implements CockpitService { + @Autowired + private StatisticNumberMapper numberMapper; + @Autowired + private AbstractDictService dictService; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private DeviceInfoMapper deviceInfoMapper; + @Autowired + private FireEquipInfoMapper fireEquipInfoMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private VisitorApplyMapper applyMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private RedisUtil redisUtil; @Override public HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap) { @@ -106,4 +147,512 @@ }); return resultMap; } + + @Override + public Object buildingNumberPerHour() { + //当天按小时分组的人数 + List list = numberMapper.selectListByTime(); + Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); + //定时任务中已将每小时三栋楼人数存到数据库 + //将一期主楼和录制楼人数合并,二期单算 + List> resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List buildingNumberDTOS = collect.get(key); + BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); + BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); + BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); + HashMap resultMap = new HashMap<>(); + Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); + Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); + resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); + resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); + resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); + resultList.add(resultMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object visitorTodayNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); + List visitInfos = visitInfoMapper.selectList(wrapper); + HashMap resultMap = new HashMap<>(); + resultMap.put("今日访客量", visitInfos.size()); + return ResponseData.success(resultMap); + } + + @Override + public Object deviceNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + Integer total = deviceInfoMapper.selectCount(wrapper); + QueryWrapper wrapper1 = new QueryWrapper<>(); + wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 + Integer online = deviceInfoMapper.selectCount(wrapper1); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) online / (float) total * 100); + HashMap resultMap = new HashMap<>(); + resultMap.put("设备总数", total); + resultMap.put("设备在线率", result + "%"); + return ResponseData.success(resultMap); + } + + @Override + public Object securityNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) leave / (float) total * 100); + HashMap resultMap = new HashMap<>(); + if (0 == total) { + resultMap.put("安保人员总数", 0); + resultMap.put("安保人员离岗率", "0"); + } else { + resultMap.put("安保人员总数", total); + resultMap.put("安保人员离岗率", result + ""); + } + return ResponseData.success(resultMap); + } + + @Override + public Object visitorApplyDetail() { + List reasonGroup = applyMapper.selectByVisitReason(); + List resultList = new ArrayList<>(); + //空数据处理 + List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); + if (CollectionUtils.isEmpty(reasonGroup)) { + for (Dict dict : visitReason) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(dict.getName()); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); + if (0 == sum) { + return ResponseData.success(); + } + reasonGroup.forEach(group -> { + String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(group.getQuantity()); + applyReasonGroupDTO.setVisitReason(reasonName); + applyReasonGroupDTO.setRatio(result + "%"); + resultList.add(applyReasonGroupDTO); + }); + //返回数据补全处理 + if (resultList.size() < visitReason.size()) { + List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); + for (Dict dict : visitReason) { + String name = dict.getName(); + if (!collect.contains(name)) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(name); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO) { + //查询各危险级别权重name,用于构造返回结构 + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); + + Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); + List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(list)) { + Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + //查询数据,放入redis + List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); + Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //设置过期时间为每月1号0点 + LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) + .withMinute(0).withSecond(0).withNano(0); + long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); + redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + + @Override + public Object eventCategoryStatistics() { + List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); + return ResponseData.success(categoryLevelGroup); + } + + @Override + public Object fireEquipStatistics() { + List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); + //空数据处理 + List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); + if (CollectionUtils.isEmpty(equipTypeGroup)) { + for (Dict dict : equipType) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + return ResponseData.success(equipTypeGroup); + } + equipTypeGroup.forEach(group -> { + String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); + group.setEquipTypeName(equipTypeName); + }); + //返回数据补全处理 + if (equipTypeGroup.size() < equipType.size()) { + List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); + for (Dict dict : equipType) { + String code = dict.getCode(); + if (!collect.contains(code)) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + } + } + return ResponseData.success(equipTypeGroup); + } + + @Override + public Object beOnDutyRatio() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + if (0 == total) { + return ResponseData.success(null); + } + List currentDateHourList = DateUtils.getCurrentDateWorkHourList(); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + //补全空数据 + if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { + for (String date : currentDateHourList) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + return ResponseData.success(onDutyRatioDTOS); + } + onDutyRatioDTOS.forEach(dto -> { + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); + dto.setRatio(result + "%"); + }); + //补全空数据 + List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); + for (String date : currentDateHourList) { + if (!collect.contains(date)) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + } + return ResponseData.success(onDutyRatioDTOS); + } + + @Override + public Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO) { + List gateStatusGroup = null; + //2代表所有摄像头(对应字典2-7) + if ("2".equals(gateStatusGroupDTO.getDevType())) { + gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); + } else { + gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); + } + HashMap resultMap = new HashMap<>(); + //空数据处理 + List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); + if (CollectionUtils.isEmpty(gateStatusGroup)) { + List resultList = new ArrayList<>(); + for (Dict dict : deviceStatus) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + resultMap.put("total", 0); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("无该类设备信息"); + } + List resultList = new ArrayList<>(); + gateStatusGroup.forEach(group -> { + if ("2".equals(gateStatusGroupDTO.getDevType())) { + group.setDevType("2"); + } + String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(devStatus); + gateStatusGroupResponse.setRatio(result + "%"); + gateStatusGroupResponse.setQuantity(group.getQuantity()); + resultList.add(gateStatusGroupResponse); + }); + //返回数据补全处理 + if (resultList.size() < deviceStatus.size()) { + List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); + for (Dict dict : deviceStatus) { + String name = dict.getName(); + if (!collect.contains(name)) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + } + } + resultMap.put("total", sum); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + + @Override + public Object securityScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的position划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + List caseInfos = caseInfoMapper.selectByPosition(position); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //楼栋-评分实体map + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + Map resultMap = new HashMap<>(); + //空数据处理 + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + resultMap.put(dict.getName(), 100.0); + } + return ResponseData.success(resultMap); + } + + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + + collect.keySet().forEach(key -> { + List list = collect.get(key); + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); + resultMap.put(dictValue, 100 - collect1.getSum()); + }); + //返回数据补全处理 + if (collect.size() < devicePosition.size()) { + Set strings = resultMap.keySet(); + for (Dict dict : devicePosition) { + String name = dict.getName(); + if (!strings.contains(name)) { + resultMap.put(dict.getName(), 100.0); + } + } + } + //按楼层分组计算评分 +// collect.keySet().forEach(key -> { +// Map map = new HashMap<>(); +// List securityScoreDTOS = collect.get(key); +// //楼层-评分map +// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); +// collect1.keySet().forEach(key1 -> { +// map.put(key1, 100 - collect1.get(key1)); +// }); +// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); +// resultMap.put(dictValue, map); +// }); + return ResponseData.success(resultMap); + } + + @Override + public Object securityFrequency() { + String year = String.valueOf(DateUtil.thisYear()); + String month = String.valueOf(DateUtil.thisMonth()); + Integer quantity = caseInfoMapper.selectCountByMonth(year, month); + SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); + securityFrequencyDTO.setQuantity(quantity); + securityFrequencyDTO.setYear(year); + securityFrequencyDTO.setMonth(month); + return ResponseData.success(securityFrequencyDTO); + } + + @Override + public Object areaScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的area划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + String area = securityScoreDTO.getArea(); + if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { + return null; + } + Map resultMap = new HashMap<>(); + List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); + if (Objects.isNull(caseInfos)) { + resultMap.put("安防评分", 100.0); + return ResponseData.success(resultMap); + } + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + resultMap.put("安防评分", 100 - collect.getSum()); + return ResponseData.success(resultMap); + } + + @Override + public Object heatMap(HeatMapDTO heatMapDTO) { + if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { + heatMapDTO.setMinute(3); + } + List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); + Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); + HashMap resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect)) { + return ResponseData.success(); + } + collect.keySet().forEach(key -> { + resultMap.put(key, collect.get(key).size()); + }); + return ResponseData.success(resultMap); + } + + private List> getResultMap(List nameList, List> resultList, Map> resultMap) { + resultMap.keySet().forEach(key -> { + List monthAndLevelGroupDTOS = resultMap.get(key); + HashMap hashMap = new HashMap<>(); + for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { +// hashMap.put("年份", andLevelGroupDTO.getYear()); + hashMap.put("月份", /*andLevelGroupDTO.getYear() + "-" + */Integer.valueOf(andLevelGroupDTO.getMonth())); + hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); + } + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + }); + //12个月份,用于构造返回结构 + List list1 = new ArrayList<>(); + for (Map map : resultList) { + list1.add(String.valueOf(map.get("月份"))); + } + for (int i = 1; i < 13; i++) { + if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { + continue; + } + HashMap hashMap = new HashMap<>(); + hashMap.put("月份", i); + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + } + List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); + return results; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java index 94308db..f91d7bd 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java @@ -427,6 +427,13 @@ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("draw_no", drawNo); DeviceInfo deviceInfo = deviceInfoMapper.selectOne(wrapper); + if(!Objects.isNull(deviceInfo)){ + deviceInfo.setDevTypeName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_TYPE, deviceInfo.getDevType())); + deviceInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, deviceInfo.getStatus())); + deviceInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, deviceInfo.getPosition())); + deviceInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, deviceInfo.getArea())); + deviceInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, deviceInfo.getIsKeyArea())); + } return deviceInfo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java index 8ed53d9..c399a7f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java @@ -11,6 +11,7 @@ import com.casic.missiles.modular.service.HikService; import com.casic.missiles.modular.system.model.Dict; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -50,8 +51,11 @@ @Override public CaseInfo blackListHandle(JSONObject event, CaseInfo caseInfo) { - String srcIndex = event.getString("srcIndex"); //海康资源唯一标识 + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 String happenTimeISO = String.valueOf(event.get("happenTime")); + DateTime parse = DateUtil.parse(happenTimeISO); String happenTime = DateUtil.formatDateTime(parse); caseInfo.setHappenTime(happenTime); //发生时间 @@ -89,6 +93,16 @@ log.info("接收到离岗事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //离岗事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray leavePosition = data.getJSONArray("leavePosition"); + if(StringUtils.isNotEmpty(leavePosition.getString(0))){ + JSONObject jsonObject = leavePosition.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -115,6 +129,16 @@ log.info("接收到人员聚集事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //人员聚集事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray group = data.getJSONArray("group"); + if(StringUtils.isNotEmpty(group.getString(0))){ + JSONObject jsonObject = group.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -263,8 +287,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void propertyAttendanceHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); @@ -309,8 +334,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void securityPersonnelHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java index 316188e..71d587d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java @@ -22,4 +22,11 @@ boolean insertCaseInfoBatch(List caseInfos); List caseInfoList(CaseInfoRequest caseInfoRequest); + + List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest); + + Object caseInfoLastByDrawNo(String drawNo); + + int updateAllStatus(); + } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java index b3d1968..7a7fe8a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java @@ -2,6 +2,10 @@ import com.alibaba.fastjson.JSONArray; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import java.util.HashMap; import java.util.List; @@ -13,4 +17,32 @@ */ public interface CockpitService { HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap); + + Object buildingNumberPerHour(); + + Object visitorTodayNumber(); + + Object deviceNumber(); + + Object securityNumber(); + + Object visitorApplyDetail(); + + Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO); + + Object eventCategoryStatistics(); + + Object fireEquipStatistics(); + + Object beOnDutyRatio(); + + Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO); + + Object securityScore(SecurityScoreDTO securityScoreDTO); + + Object securityFrequency(); + + Object areaScore(SecurityScoreDTO securityScoreDTO); + + Object heatMap(HeatMapDTO heatMapDTO); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java new file mode 100644 index 0000000..178b909 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.service; + +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; + +/** + * @Description: + * @Author: wangpeng + * @Date: 2022/10/11 9:10 + */ +public interface PropertyManageService { + Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO); + + Object keyAreaData(String dimension); + + Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO); + + Object attendanceNumber(String dimension); + + Object securityAssessment(String dimension); + + Object keyAreaStatistic(); + + Object responseAssess(); + + Object hazardLevelStatistics(String dimension); + + Object securityRank(); + + Object securityLevelAssess(); + + Object commute(); + + Object keyArea(); + + Object visitor(); + + Object security(); + + Object patrol(); + + Object other(); +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java index ea6b8c0..2580187 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java @@ -17,6 +17,7 @@ import com.casic.missiles.modular.service.BlackInfoService; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -70,11 +71,17 @@ faceInfo.setCertificateNum(blackInfo.getIdCardNo()); faceSingleAddOrUpdateRequest.setFaceInfo(faceInfo); FacePic facePic = new FacePic(); - facePic.setFaceBinaryData(blackInfo.getPicture()); - faceSingleAddOrUpdateRequest.setFacePic(facePic); + String picture = blackInfo.getPicture(); + if(StringUtils.isNotEmpty(picture)){ + String substringPicture = picture.substring(picture.indexOf(",") + 1); + facePic.setFaceBinaryData(substringPicture); + } faceSingleAddOrUpdateRequest.setFacePic(facePic); String body = JSONObject.toJSONString(faceSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.FACE_SINGLE_ADDITION, body); + log.info("-----------------------"); + log.info("增加黑名单人脸请求body,{}", body); + log.info("增加黑名单人脸resultStr:{}", JSONObject.toJSONString(resultStr)); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人脸失败,海康response:{}", resultStr); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java index 6b03d8b..1c34f68 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java @@ -2,17 +2,22 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.dao.CaseInfoMapper; import com.casic.missiles.modular.dao.CategoryLevelMapper; +import com.casic.missiles.modular.dao.DeviceInfoMapper; import com.casic.missiles.modular.dao.HazardLevelMapper; import com.casic.missiles.modular.dto.CaseInfoRequest; import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.model.CaseInfo; +import com.casic.missiles.modular.model.DeviceInfo; import com.casic.missiles.modular.service.CaseInfoService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,6 +31,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; /** * @Description: 安防事件service @@ -50,6 +56,9 @@ @Resource private AbstractDictService dictService; + @Resource + private DeviceInfoMapper deviceInfoMapper; + @Override public List caseInfoListPage(Page page, CaseInfoRequest caseInfoRequest) { try { @@ -136,17 +145,69 @@ @Override public List caseInfoList(CaseInfoRequest caseInfoRequest) { try { - List pageList = caseInfoMapper.getCaseInfoList(caseInfoRequest); - pageList.forEach(caseInfo ->{ + List list = caseInfoMapper.getCaseInfoList(caseInfoRequest); + list.forEach(caseInfo ->{ caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); }); - return pageList; + return list; } catch (DataAccessException ex) { log.error("安防事件: 查询不分页出现异常, 异常:{}", ex); } return null; } + + @Override + public List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest) { + try { + List list = caseInfoMapper.getCaseInfoListUnResolved(caseInfoRequest); + list.forEach(caseInfo ->{ + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + }); + return list; + } catch (DataAccessException ex) { + log.error("未解决/解决中安防事件: 查询不分页出现异常, 异常:{}", ex); + } + return null; + } + + @Override + public Object caseInfoLastByDrawNo(String drawNo) { + //图纸编号和设备编号一一对应 + QueryWrapper dWrapper = new QueryWrapper<>(); + dWrapper.eq("draw_no", drawNo); + DeviceInfo deviceInfo = deviceInfoMapper.selectOne(dWrapper); + if(Objects.isNull(deviceInfo)){ + return ResponseData.error("该图纸编号下不存在关联的设备"); + } + if(StringUtils.isEmpty(deviceInfo.getDevCode())){ + return ResponseData.error("该图纸编号下不存在对应的设备编号"); + }else{ + String devCode = deviceInfo.getDevCode(); + QueryWrapper cWrapper = new QueryWrapper<>(); + cWrapper.eq("device_code", devCode); + List caseInfos = caseInfoMapper.selectList(cWrapper); + if(CollectionUtil.isEmpty(caseInfos)){ + return ResponseData.error("该图纸编号下不存在最近发生的事件"); + } + CaseInfo caseInfo = caseInfos.get(caseInfos.size() - 1); + caseInfo.setDrawNo(deviceInfo.getDrawNo()); + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + return ResponseData.success(caseInfo); + } + } + + @Override + public int updateAllStatus() { + int upflag = caseInfoMapper.updateAllStatus(); + return upflag; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java index 7402991..7fb5a6e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java @@ -4,15 +4,34 @@ import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.*; import com.casic.missiles.modular.enums.HikUri; +import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.redis.RedisUtil; +import com.casic.missiles.modular.redis.key.CacheKeys; import com.casic.missiles.modular.service.CockpitService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import java.text.MessageFormat; +import java.text.NumberFormat; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.*; +import java.util.stream.Collectors; /** * @Description: @@ -22,6 +41,28 @@ @Slf4j @Service public class CockpitServiceImpl implements CockpitService { + @Autowired + private StatisticNumberMapper numberMapper; + @Autowired + private AbstractDictService dictService; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private DeviceInfoMapper deviceInfoMapper; + @Autowired + private FireEquipInfoMapper fireEquipInfoMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private VisitorApplyMapper applyMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private RedisUtil redisUtil; @Override public HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap) { @@ -106,4 +147,512 @@ }); return resultMap; } + + @Override + public Object buildingNumberPerHour() { + //当天按小时分组的人数 + List list = numberMapper.selectListByTime(); + Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); + //定时任务中已将每小时三栋楼人数存到数据库 + //将一期主楼和录制楼人数合并,二期单算 + List> resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List buildingNumberDTOS = collect.get(key); + BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); + BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); + BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); + HashMap resultMap = new HashMap<>(); + Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); + Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); + resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); + resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); + resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); + resultList.add(resultMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object visitorTodayNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); + List visitInfos = visitInfoMapper.selectList(wrapper); + HashMap resultMap = new HashMap<>(); + resultMap.put("今日访客量", visitInfos.size()); + return ResponseData.success(resultMap); + } + + @Override + public Object deviceNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + Integer total = deviceInfoMapper.selectCount(wrapper); + QueryWrapper wrapper1 = new QueryWrapper<>(); + wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 + Integer online = deviceInfoMapper.selectCount(wrapper1); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) online / (float) total * 100); + HashMap resultMap = new HashMap<>(); + resultMap.put("设备总数", total); + resultMap.put("设备在线率", result + "%"); + return ResponseData.success(resultMap); + } + + @Override + public Object securityNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) leave / (float) total * 100); + HashMap resultMap = new HashMap<>(); + if (0 == total) { + resultMap.put("安保人员总数", 0); + resultMap.put("安保人员离岗率", "0"); + } else { + resultMap.put("安保人员总数", total); + resultMap.put("安保人员离岗率", result + ""); + } + return ResponseData.success(resultMap); + } + + @Override + public Object visitorApplyDetail() { + List reasonGroup = applyMapper.selectByVisitReason(); + List resultList = new ArrayList<>(); + //空数据处理 + List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); + if (CollectionUtils.isEmpty(reasonGroup)) { + for (Dict dict : visitReason) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(dict.getName()); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); + if (0 == sum) { + return ResponseData.success(); + } + reasonGroup.forEach(group -> { + String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(group.getQuantity()); + applyReasonGroupDTO.setVisitReason(reasonName); + applyReasonGroupDTO.setRatio(result + "%"); + resultList.add(applyReasonGroupDTO); + }); + //返回数据补全处理 + if (resultList.size() < visitReason.size()) { + List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); + for (Dict dict : visitReason) { + String name = dict.getName(); + if (!collect.contains(name)) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(name); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO) { + //查询各危险级别权重name,用于构造返回结构 + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); + + Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); + List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(list)) { + Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + //查询数据,放入redis + List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); + Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //设置过期时间为每月1号0点 + LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) + .withMinute(0).withSecond(0).withNano(0); + long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); + redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + + @Override + public Object eventCategoryStatistics() { + List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); + return ResponseData.success(categoryLevelGroup); + } + + @Override + public Object fireEquipStatistics() { + List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); + //空数据处理 + List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); + if (CollectionUtils.isEmpty(equipTypeGroup)) { + for (Dict dict : equipType) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + return ResponseData.success(equipTypeGroup); + } + equipTypeGroup.forEach(group -> { + String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); + group.setEquipTypeName(equipTypeName); + }); + //返回数据补全处理 + if (equipTypeGroup.size() < equipType.size()) { + List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); + for (Dict dict : equipType) { + String code = dict.getCode(); + if (!collect.contains(code)) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + } + } + return ResponseData.success(equipTypeGroup); + } + + @Override + public Object beOnDutyRatio() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + if (0 == total) { + return ResponseData.success(null); + } + List currentDateHourList = DateUtils.getCurrentDateWorkHourList(); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + //补全空数据 + if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { + for (String date : currentDateHourList) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + return ResponseData.success(onDutyRatioDTOS); + } + onDutyRatioDTOS.forEach(dto -> { + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); + dto.setRatio(result + "%"); + }); + //补全空数据 + List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); + for (String date : currentDateHourList) { + if (!collect.contains(date)) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + } + return ResponseData.success(onDutyRatioDTOS); + } + + @Override + public Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO) { + List gateStatusGroup = null; + //2代表所有摄像头(对应字典2-7) + if ("2".equals(gateStatusGroupDTO.getDevType())) { + gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); + } else { + gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); + } + HashMap resultMap = new HashMap<>(); + //空数据处理 + List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); + if (CollectionUtils.isEmpty(gateStatusGroup)) { + List resultList = new ArrayList<>(); + for (Dict dict : deviceStatus) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + resultMap.put("total", 0); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("无该类设备信息"); + } + List resultList = new ArrayList<>(); + gateStatusGroup.forEach(group -> { + if ("2".equals(gateStatusGroupDTO.getDevType())) { + group.setDevType("2"); + } + String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(devStatus); + gateStatusGroupResponse.setRatio(result + "%"); + gateStatusGroupResponse.setQuantity(group.getQuantity()); + resultList.add(gateStatusGroupResponse); + }); + //返回数据补全处理 + if (resultList.size() < deviceStatus.size()) { + List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); + for (Dict dict : deviceStatus) { + String name = dict.getName(); + if (!collect.contains(name)) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + } + } + resultMap.put("total", sum); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + + @Override + public Object securityScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的position划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + List caseInfos = caseInfoMapper.selectByPosition(position); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //楼栋-评分实体map + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + Map resultMap = new HashMap<>(); + //空数据处理 + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + resultMap.put(dict.getName(), 100.0); + } + return ResponseData.success(resultMap); + } + + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + + collect.keySet().forEach(key -> { + List list = collect.get(key); + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); + resultMap.put(dictValue, 100 - collect1.getSum()); + }); + //返回数据补全处理 + if (collect.size() < devicePosition.size()) { + Set strings = resultMap.keySet(); + for (Dict dict : devicePosition) { + String name = dict.getName(); + if (!strings.contains(name)) { + resultMap.put(dict.getName(), 100.0); + } + } + } + //按楼层分组计算评分 +// collect.keySet().forEach(key -> { +// Map map = new HashMap<>(); +// List securityScoreDTOS = collect.get(key); +// //楼层-评分map +// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); +// collect1.keySet().forEach(key1 -> { +// map.put(key1, 100 - collect1.get(key1)); +// }); +// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); +// resultMap.put(dictValue, map); +// }); + return ResponseData.success(resultMap); + } + + @Override + public Object securityFrequency() { + String year = String.valueOf(DateUtil.thisYear()); + String month = String.valueOf(DateUtil.thisMonth()); + Integer quantity = caseInfoMapper.selectCountByMonth(year, month); + SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); + securityFrequencyDTO.setQuantity(quantity); + securityFrequencyDTO.setYear(year); + securityFrequencyDTO.setMonth(month); + return ResponseData.success(securityFrequencyDTO); + } + + @Override + public Object areaScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的area划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + String area = securityScoreDTO.getArea(); + if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { + return null; + } + Map resultMap = new HashMap<>(); + List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); + if (Objects.isNull(caseInfos)) { + resultMap.put("安防评分", 100.0); + return ResponseData.success(resultMap); + } + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + resultMap.put("安防评分", 100 - collect.getSum()); + return ResponseData.success(resultMap); + } + + @Override + public Object heatMap(HeatMapDTO heatMapDTO) { + if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { + heatMapDTO.setMinute(3); + } + List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); + Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); + HashMap resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect)) { + return ResponseData.success(); + } + collect.keySet().forEach(key -> { + resultMap.put(key, collect.get(key).size()); + }); + return ResponseData.success(resultMap); + } + + private List> getResultMap(List nameList, List> resultList, Map> resultMap) { + resultMap.keySet().forEach(key -> { + List monthAndLevelGroupDTOS = resultMap.get(key); + HashMap hashMap = new HashMap<>(); + for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { +// hashMap.put("年份", andLevelGroupDTO.getYear()); + hashMap.put("月份", /*andLevelGroupDTO.getYear() + "-" + */Integer.valueOf(andLevelGroupDTO.getMonth())); + hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); + } + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + }); + //12个月份,用于构造返回结构 + List list1 = new ArrayList<>(); + for (Map map : resultList) { + list1.add(String.valueOf(map.get("月份"))); + } + for (int i = 1; i < 13; i++) { + if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { + continue; + } + HashMap hashMap = new HashMap<>(); + hashMap.put("月份", i); + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + } + List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); + return results; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java index 94308db..f91d7bd 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java @@ -427,6 +427,13 @@ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("draw_no", drawNo); DeviceInfo deviceInfo = deviceInfoMapper.selectOne(wrapper); + if(!Objects.isNull(deviceInfo)){ + deviceInfo.setDevTypeName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_TYPE, deviceInfo.getDevType())); + deviceInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, deviceInfo.getStatus())); + deviceInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, deviceInfo.getPosition())); + deviceInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, deviceInfo.getArea())); + deviceInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, deviceInfo.getIsKeyArea())); + } return deviceInfo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java index 8ed53d9..c399a7f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java @@ -11,6 +11,7 @@ import com.casic.missiles.modular.service.HikService; import com.casic.missiles.modular.system.model.Dict; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -50,8 +51,11 @@ @Override public CaseInfo blackListHandle(JSONObject event, CaseInfo caseInfo) { - String srcIndex = event.getString("srcIndex"); //海康资源唯一标识 + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 String happenTimeISO = String.valueOf(event.get("happenTime")); + DateTime parse = DateUtil.parse(happenTimeISO); String happenTime = DateUtil.formatDateTime(parse); caseInfo.setHappenTime(happenTime); //发生时间 @@ -89,6 +93,16 @@ log.info("接收到离岗事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //离岗事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray leavePosition = data.getJSONArray("leavePosition"); + if(StringUtils.isNotEmpty(leavePosition.getString(0))){ + JSONObject jsonObject = leavePosition.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -115,6 +129,16 @@ log.info("接收到人员聚集事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //人员聚集事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray group = data.getJSONArray("group"); + if(StringUtils.isNotEmpty(group.getString(0))){ + JSONObject jsonObject = group.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -263,8 +287,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void propertyAttendanceHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); @@ -309,8 +334,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void securityPersonnelHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java new file mode 100644 index 0000000..4427f19 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java @@ -0,0 +1,1255 @@ +package com.casic.missiles.modular.service.impl; + +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.config.CockpitConfig; +import com.casic.missiles.modular.dao.*; +import com.casic.missiles.modular.dto.statistics.*; +import com.casic.missiles.modular.enums.SecurityEventDict; +import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.service.PropertyManageService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.text.NumberFormat; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @Description: 驾驶舱二级页面-物管信息 + * @Author: wangpeng + * @Date: 2022/10/11 9:11 + */ +@Slf4j +@Service +public class PropertyManageServiceImpl implements PropertyManageService { + @Autowired + private AttendanceInfoMapper attendanceInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private DeviceRepairLogMapper repairLogMapper; + @Autowired + private CockpitConfig cockpitConfig; + @Autowired + private AbstractDictService dictService; + + @Override + public Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO) { + //各类型员工及总数 + List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); + Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); + + String dateDimension = attendanceRatioDTO.getDateDimension(); + List attendanceRatioDTOS = new ArrayList<>(); + List dateList = null; + //考勤的人数,按单次考勤过滤 + if ("week".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); + dateList = DateUtils.getCurrentDateDayList(); + } else if ("month".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); + dateList = DateUtils.getCurrentDateWeekList(); + } else if ("year".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); + dateList = DateUtils.getCurrentDateMonthList(); + } + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { + for (String date : dateList) { + HashMap hashMap = new HashMap<>(); + hashMap.put("date", date); + hashMap.put("property", "0%"); + hashMap.put("security", "0%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + //计算出勤率 + Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); + + dateList.forEach(date -> { + HashMap hashMap = new HashMap<>(); + if (CollectionUtils.isEmpty(dateMap.get(date))) { + hashMap.put("date", date); + hashMap.put("property", "0%"); + hashMap.put("security", "0%"); + resultList.add(hashMap); + } else { + List attendances = dateMap.get(date); + attendances.forEach(attendanceRatio -> { + attendanceRatio.setDateDimension(dateDimension); + attendanceRatio.setStaffType(attendanceRatio.getStaffType()); + List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); + String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); + attendanceRatio.setAttendanceRatio(ratio + "%"); + //构造返回结构 + hashMap.put("date", attendanceRatio.getDate()); +// String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); + if ("1".equals(attendanceRatio.getStaffType())) { + hashMap.put("property", attendanceRatio.getAttendanceRatio()); + } + if ("2".equals(attendanceRatio.getStaffType())) { + hashMap.put("security", attendanceRatio.getAttendanceRatio()); + } + }); + //补全缺少数据 + if (1 == attendances.size()) { + AttendanceRatioDTO attendanceRatioDTO1 = attendances.get(0); + if ("1".equals(attendanceRatioDTO1.getStaffType())) { + hashMap.put("security", "0%"); + } + if ("2".equals(attendanceRatioDTO1.getStaffType())) { + hashMap.put("property", "0%"); + } + } + resultList.add(hashMap); + } + }); + return ResponseData.success(resultList); + + } + + @Override + public Object keyAreaData(String dimension) { + List resultList = null; + List dateList = null; + if ("year".equals(dimension)) { + //近365天数据按月分组统计 + resultList = caseInfoMapper.selectPreMonthCountByNearYear(); + dateList = DateUtils.getCurrentDateMonthList(); + } else if ("month".equals(dimension)) { + //近30天数据按周分组统计 + resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); + dateList = DateUtils.getCurrentDateWeekList(); + } else if ("week".equals(dimension)) { + //近7天数据按天分组统计 + resultList = caseInfoMapper.selectPreDayCountBySevenDay(); + dateList = DateUtils.getCurrentDateDayList(); + } + //补全空数据处理 + if (CollectionUtils.isEmpty(resultList)) { + for (String date : dateList) { + PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); + preMonthOrWeekCaseDTO.setDimension(date); + preMonthOrWeekCaseDTO.setQuantity(0); + resultList.add(preMonthOrWeekCaseDTO); + } + } else { + for (String date : dateList) { + List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); + if (!collect.contains(date)) { + PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); + preMonthOrWeekCaseDTO.setDimension(date); + preMonthOrWeekCaseDTO.setQuantity(0); + resultList.add(preMonthOrWeekCaseDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { + String year = avgMonthAndWeekGroupDTO.getYear(); + List monthList = caseInfoMapper.selectPreMonthCountByYear(year); + Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); + HashMap strAvgMap = new HashMap<>(); + List resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List preMonthOrWeekCaseDTOS = collect.get(key); + int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); + //若年份是本年,则使用各安防级别数量/当前月份数 + //若不是本年,除数为12 + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + if (year.equals(String.valueOf(DateUtil.thisYear()))) { + monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); + strAvgMap.put(key, monthAndWeekDTO); + } else { + monthAndWeekDTO.setMonthQuantity(sum / 12); + strAvgMap.put(key, monthAndWeekDTO); + } + } + + List weekList = caseInfoMapper.selectPreWeekCountByYear(year); + Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); + for (String key : collect1.keySet()) { + List preMonthOrWeekCaseDTOS = collect.get(key); + int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); + if (year.equals(String.valueOf(DateUtil.thisYear()))) { + if (!Objects.isNull(strAvgMap.get(key))) { + MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); + strAvgMap.put(key, monthAndWeekDTO); + } else { + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); + strAvgMap.put(key, monthAndWeekDTO); + } + } else { + if (!Objects.isNull(strAvgMap.get(key))) { + MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / 52); + strAvgMap.put(key, monthAndWeekDTO); + } else { + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / 52); + strAvgMap.put(key, monthAndWeekDTO); + } + } + } + strAvgMap.keySet().forEach(key -> { + resultList.add(strAvgMap.get(key)); + }); + //输出顺序 + Collections.swap(resultList, 1, 2); + return ResponseData.success(resultList); + } + + @Override + public Object attendanceNumber(String dimension) { + List attendanceNumberDTOs = null; + List> resultList = new ArrayList<>(); + List dateList = new ArrayList<>(); + if ("week".equals(dimension)) { + //近7天数据按天分组统计 + attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); + dateList = DateUtils.getCurrentDateDayList(); + } else if ("day".equals(dimension)) { + //今天数据按小时分组统计 + attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); + dateList = DateUtils.getCurrentDateWorkHourList(); + } + if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { + for (String date : dateList) { + HashMap hashMap = new HashMap<>(); + hashMap.put("staticTime", date); + hashMap.put("1", "0"); + hashMap.put("2", "0"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); + if ("day".equals(dimension)) { + collect = collect.entrySet().stream().collect(Collectors.toMap(m -> m.getKey().substring(5) + ":00", Map.Entry::getValue)); + } + + for (String date : dateList) { + Map resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect.get(date))) { + resultMap.put("1", "0"); + resultMap.put("2", "0"); + resultMap.put("staticTime", date); + resultList.add(resultMap); + } else { + List attendanceNumberDTOS = collect.get(date); +// Map resultMap = new HashMap<>(); + AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); + if (attendanceNumberDTOS.size() >= 2) { + AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); + resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); + } + resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); + resultMap.put("staticTime", date); + resultList.add(resultMap); + //补全map缺少数据 + if (!resultMap.containsKey("1")) { + resultMap.put("1", "0"); + } + if (!resultMap.containsKey("2")) { + resultMap.put("2", "0"); + } + } + } + +// +// collect.keySet().forEach(key -> { +// List attendanceNumberDTOS = collect.get(key); +// Map resultMap = new HashMap<>(); +// AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); +// if (attendanceNumberDTOS.size() >= 2) { +// AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); +// resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); +// } +// resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); +// resultMap.put("staticTime", attendanceNumberDTO.getDate().substring(5) + ":00"); +// resultList.add(resultMap); +// }); +// //补全空数据处理 +// if (CollectionUtils.isEmpty(resultList)) { +// for (String date : dateList) { +// Map resultMap = new HashMap<>(); +// resultMap.put("1", "0"); +// resultMap.put("2", "0"); +// resultMap.put("staticTime", date); +// resultList.add(resultMap); +// } +// } else { +// List collectList = new ArrayList<>(); +// for (Map map : resultList) { +// String staticTime = map.get("staticTime"); +// collectList.add(staticTime); +// //补全map缺少数据 +// if (!map.containsKey("1")) { +// map.put("1", "0"); +// } +// if (!map.containsKey("2")) { +// map.put("2", "0"); +// } +// } +// for (String date : dateList) { +// if (!collectList.contains(date)) { +// Map resultMap = new HashMap<>(); +// resultMap.put("1", "0"); +// resultMap.put("2", "0"); +// resultMap.put("staticTime", date); +// resultList.add(resultMap); +// } +// } +// } + return ResponseData.success(resultList); + } + + @Override + public Object securityAssessment(String dimension) { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + if ("week".equals(dimension)) { + //近7天早晚高峰数据 + List caseInfos = caseInfoMapper.selectListBySevenDay(); + //按时间(天)进行分组 + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(" "); + String dayTime = array[0]; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } else if ("day".equals(dimension)) { + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDatePeakHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + + } + return null; + } + + @Override + public Object keyAreaStatistic() { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday2(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + dayTime = dayTime.substring(5) + ":00"; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } + + @Override + public Object responseAssess() { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday3(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + //扣分=事件级别权重*未解决小时数 + Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); + Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); + long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); + Double score = Double.valueOf(hazardWeight) * between; + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + dayTime = dayTime.substring(5) + ":00"; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } + + @Override + public Object hazardLevelStatistics(String dimension) { + List hazardLevelGroup = null; + if ("week".equals(dimension)) { + hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); + } else if ("month".equals(dimension)) { + hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); + } + if (CollectionUtils.isEmpty(hazardLevelGroup)) { + log.info("重点区域威胁事件类型统计,无安防事件"); + return ResponseData.error("无安防事件发生!"); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("安防事件总数为0"); + } + hazardLevelGroup.forEach(group -> { + CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); + group.setLevelName(caseHazardLevel.getName()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + group.setLevelRatio(result + "%"); + }); + HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); + hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); + hazardLevelGroupResponse.setQuantity(sum); + return ResponseData.success(hazardLevelGroupResponse); + } + + @Override + public Object securityRank() { + //考勤表近一个月按人员分组的考勤个数前十名 + List list = attendanceInfoMapper.getCountForRank(); + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(list)) { + //补全空数据处理 + List staffList = staffInfoMapper.selectListLimitTen(); + for (StaffInfo staffInfo : staffList) { + HashMap hashMap = new HashMap<>(); + hashMap.put(staffInfo.getStaffName(), "0%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + //构造返回结构 + for (SecurityRankDTO dto : list) { + // TODO: 2022/9/15 分母使用30,后续看产品定义 + HashMap hashMap = new HashMap<>(); + String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); + hashMap.put("name", dto.getStaffName()); + hashMap.put("ratio", result + "%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object securityLevelAssess() { + //今天数据按小时分组统计 + List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + if (CollectionUtils.isEmpty(resultList)) { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); + levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); + levelAssessDTO.setDate(date); +// levelAssessDTO.setQuantity(); + resultList.add(levelAssessDTO); + } + return ResponseData.success(resultList); + } + resultList.forEach(result -> { + result.setDate(result.getDate().substring(5) + ":00"); + BigDecimal deScore = new BigDecimal(result.getQuantity()); + BigDecimal preScore = new BigDecimal("100.0"); + result.setScore(preScore.subtract(deScore).doubleValue()); + }); + //数据补全处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + for (SecurityLevelAssessDTO levelAssessDTO : resultList) { + String substring = levelAssessDTO.getDate().substring(5) + ":00"; + if (!substring.equals(date)) { + SecurityLevelAssessDTO levelAssess = new SecurityLevelAssessDTO(); + levelAssess.setScore(new BigDecimal("100.0").doubleValue()); + levelAssess.setDate(date); + resultList.add(levelAssess); + break; + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object commute() { + //早晚高峰区域安防评估 + ResponseData assessResultJson = (ResponseData) this.securityAssessment("week"); + if (Objects.isNull(assessResultJson) || 200 != assessResultJson.getCode()) { + return assessResultJson; + } + JSONArray assessData = JSONArray.parseArray(JSON.toJSONString(assessResultJson.getData())); + //所有类型的员工出勤 + List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); + long sum = staffTypeAndSumDTOS.stream().collect(Collectors.summarizingInt(StaffTypeAndSumDTO::getSum)).getSum(); + List countByTypeAndDateForWeek = attendanceInfoMapper.getCountByTypeAndDateForWeek(); + Map> dateMap = countByTypeAndDateForWeek.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); + HashMap attendanceMap = new HashMap<>(); + dateMap.keySet().forEach(key -> { + List attendanceRatioDTOS = dateMap.get(key); + //当天所有类型的员工的出勤人数 + long sum1 = attendanceRatioDTOS.stream().collect(Collectors.summarizingInt(AttendanceRatioDTO::getQuantity)).getSum(); + //出勤占比评分 + Double attendanceRatio = ((float) sum1 / (float) sum) * 100 * cockpitConfig.getCommuteWeight(); + attendanceMap.put(key, attendanceRatio); + }); + //构造结果 + List> resultList = new ArrayList<>(); + Iterator iterator = assessData.stream().iterator(); + while (iterator.hasNext()) { + JSONObject next = (JSONObject) iterator.next(); + String date = next.getString("date"); + HashMap map = new HashMap<>(); + //计算评分 + Double assessRatio = next.getInteger("score") * (1 - cockpitConfig.getCommuteWeight()); + NumberFormat numberFormat = NumberFormat.getInstance(); + numberFormat.setMaximumFractionDigits(2); + if (!Objects.isNull(attendanceMap.get(date))) { + Double attendanceRatio = attendanceMap.get(date); + Double r = assessRatio + attendanceRatio; + map.put("score", numberFormat.format(r)); + } else { + //无员工出勤率(出勤为0),只有安防评估分值 + map.put("score", numberFormat.format(assessRatio)); + } + map.put("date", date); + resultList.add(map); + } + return ResponseData.success(resultList); + } + + @Override + public Object keyArea() { + //1-重点区域安防事件次数/所有安防事件次数 + //获取近7天每天的安防事件个数,所有和重点区域 + List weekCaseDTOS = caseInfoMapper.selectPreDayCountBySevenDay(); + List weekCaseKeyAreaDTOS = caseInfoMapper.selectPreDayCountBySevenDayKeyArea(); + List caseInfos = caseInfoMapper.selectListBySevenDayKeyArea(); + HashMap weekCaseMap = new HashMap<>(); + HashMap caseScoreMap = new HashMap<>(); + HashMap keyAreaScoreMap = new HashMap<>(); + HashMap assessScoreMap = new HashMap<>(); + List dateList = DateUtils.getCurrentDateDayList(); + List> result = getForResult(weekCaseDTOS, weekCaseKeyAreaDTOS, caseInfos, weekCaseMap, caseScoreMap, + keyAreaScoreMap, assessScoreMap, dateList); + + //上个月对应数据 + List beforeMonthKeyAreaCaseDTOS = caseInfoMapper.selectPreDayCountByBeforeMonthKeyArea(); + List beforeMonthCaseDTOS = caseInfoMapper.selectPreDayCountByBeforeMonth(); + List beforeMonthCaseInfos = caseInfoMapper.selectListByBeforeMonthKeyArea(); + HashMap beforeMonthWeekCaseMap = new HashMap<>(); + HashMap beforeMonthCaseScoreMap = new HashMap<>(); + HashMap beforeMonthKeyAreaScoreMap = new HashMap<>(); + HashMap beforeMonthAssessScoreMap = new HashMap<>(); + List beforeMonthDateList = DateUtils.getCurrentDateDayBeforeMonthList(); + List> resultBeforeMonth = getForResult(beforeMonthCaseDTOS, beforeMonthKeyAreaCaseDTOS, beforeMonthCaseInfos, + beforeMonthWeekCaseMap, beforeMonthCaseScoreMap, beforeMonthKeyAreaScoreMap, beforeMonthAssessScoreMap, beforeMonthDateList); + //计算环比 + for (int i = 0; i < result.size(); i++) { + Map resultMap = result.get(i); + Map resultBeforeMonthMap = resultBeforeMonth.get(i); + BigDecimal resultScore = BigDecimal.valueOf(Double.valueOf(String.valueOf(resultMap.get("score")))); + BigDecimal resultBeforeMonthScore = BigDecimal.valueOf(Double.valueOf(String.valueOf(resultBeforeMonthMap.get("score")))); + BigDecimal finalResult = resultScore.subtract(resultBeforeMonthScore).divide(resultBeforeMonthScore, 2, BigDecimal.ROUND_HALF_UP); + resultMap.put("ringRatio", finalResult); + } + return ResponseData.success(result); + } + + @Override + public Object visitor() { + //查询每天的访客对应的离开记录(进入记录存在且在申请范围内) + //近7天主要使用申请离开时间(申请进入时间不会影响扣分) + List list = visitInfoMapper.selectListBySevenDay(); + list.stream().forEach(visit -> { + DateTime dateTime = DateUtil.parseDateTime(visit.getApplyOutTime()); + String formatDate = DatePattern.NORM_DATE_FORMAT.format(dateTime); + visit.setDate(formatDate); + }); + Map> dateVisitMap = list.stream().collect(Collectors.groupingBy(MultiScoreVisitorDTO::getDate)); + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + HashMap deductMap = new HashMap<>(); //扣分使用 + dateList.forEach(date -> { + //1、空数据处理 + if (CollectionUtils.isEmpty(dateVisitMap)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } else if (CollectionUtils.isEmpty(dateVisitMap.get(date))) { + //2、补全数据处理 + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } else { + //3、计算数据处理 + //计算分数(未在申请时间段内离开减分(包括无离开时间和有离开时间两种情况)、未在申请区域内离开减分),配置扣分,配置每个访客最高扣分 + List multiScoreVisitorDTOS = dateVisitMap.get(date); + //遍历访客 + for (MultiScoreVisitorDTO visitorDTO : multiScoreVisitorDTOS) { + //无离开时间 + if (StringUtils.isEmpty(visitorDTO.getOutTime())) { + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + cockpitConfig.getVisitorWeight().get("NoRecordPointDeduct")); + } else { + deductMap.put(date, cockpitConfig.getVisitorWeight().get("NoRecordPointDeduct")); + } + } else { +// DateTime applyInDateTime = DateUtil.parseDateTime(visitorDTO.getApplyInTime()); + DateTime applyOutDateTime = DateUtil.parseDateTime(visitorDTO.getApplyOutTime()); + DateTime outDateTime = DateUtil.parseDateTime(visitorDTO.getOutTime()); + //未在申请时间段离开(在申请离开时间后离开) + if (DateUtil.compare(outDateTime, applyOutDateTime) > 0) { + long betweenHour = DateUtil.between(outDateTime, applyOutDateTime, DateUnit.HOUR); + Double score = betweenHour * cockpitConfig.getVisitorWeight().get("singlePointDeduct"); + //该访客扣分到达最多分 + if (score >= cockpitConfig.getVisitorWeight().get("mostPointDeduct")) { + score = cockpitConfig.getVisitorWeight().get("mostPointDeduct"); + } + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + score); + } else { + deductMap.put(date, score); + } + } + //未在申请区域离开 + if (StringUtils.isNotEmpty(visitorDTO.getApplyVisitPosition()) && !visitorDTO.getApplyVisitPosition().equals(visitorDTO.getVisitPosition())) { + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + cockpitConfig.getVisitorWeight().get("singlePointDeduct")); + } else { + deductMap.put(date, cockpitConfig.getVisitorWeight().get("singlePointDeduct")); + } + } + + } + } + //添加到结果list + HashMap map = new HashMap<>(); + map.put("date", date); + if (!Objects.isNull(deductMap.get(date))) { + //最少0分 + if (deductMap.get(date) >= 100) { + map.put("score", 0); + } else { + map.put("score", 100 - deductMap.get(date)); + } + } else { + map.put("score", 100); + } + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object security() { + //安保人员到岗率*100*权重0.5 + //近7天安保人员到岗率 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + + List dateCountList = caseInfoMapper.selectDemobilizedCountSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap onDutyMap = new HashMap<>(); + dateCountList.forEach(dateCount -> { + //到岗率 + BigDecimal totalCount = new BigDecimal(total); + BigDecimal leaveCount = new BigDecimal(dateCount.getLeaveCount()); + BigDecimal result = totalCount.subtract(leaveCount).divide(totalCount, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + onDutyMap.put(dateCount.getDate(), result.multiply(BigDecimal.valueOf(cockpitConfig.getSecurityWeight().get("onDuty"))).setScale(2, BigDecimal.ROUND_HALF_UP)); + }); + + //安保等级评估均值*权重0.5 + List levelAssessList = caseInfoMapper.selectListByTypeSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap levelAssessMap = new HashMap<>(); + levelAssessList.forEach(levelAssess -> { + //6-23点共17小时,100-该天扣分/17 + BigDecimal deScore = new BigDecimal(levelAssess.getQuantity()); + BigDecimal preScore = new BigDecimal("100.0"); + BigDecimal divide = deScore.divide(BigDecimal.valueOf(17), 2, BigDecimal.ROUND_HALF_UP); + BigDecimal result = preScore.subtract(divide); + levelAssessMap.put(levelAssess.getDate(), result.multiply(BigDecimal.valueOf(cockpitConfig.getSecurityWeight().get("levelAssess"))).setScale(2, BigDecimal.ROUND_HALF_UP)); + }); + + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + Double onDutyWeight = cockpitConfig.getSecurityWeight().get("onDuty"); + Double levelAssessWeight = cockpitConfig.getSecurityWeight().get("levelAssess"); + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + //1、空数据处理 + if (CollectionUtils.isEmpty(onDutyMap) && CollectionUtils.isEmpty(levelAssessMap)) { + //2个map都空 + map.put("score", "100"); + resultList.add(map); + } else if (CollectionUtils.isEmpty(onDutyMap) || CollectionUtils.isEmpty(levelAssessMap)) { + //2个map有一个为空 + if (CollectionUtils.isEmpty(onDutyMap)) { + if (!Objects.isNull(levelAssessMap.get(date))) { + map.put("score", levelAssessMap.get(date).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + } else { + map.put("score", BigDecimal.valueOf(100 * levelAssessWeight).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + } + } + if (CollectionUtils.isEmpty(levelAssessMap)) { + if (!Objects.isNull(onDutyMap.get(date))) { + map.put("score", onDutyMap.get(date).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + } else { + map.put("score", BigDecimal.valueOf(100 * onDutyWeight).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + } + } + } else if (Objects.isNull(onDutyMap.get(date)) && Objects.isNull(levelAssessMap.get(date))) { + //该日期2个都空 + map.put("score", "100"); + resultList.add(map); + } else if (Objects.isNull(onDutyMap.get(date)) && !Objects.isNull(levelAssessMap.get(date))) { + //2、补全到岗率数据处理 + //该日期onDutyMap空,levelAssessMap不空 + map.put("score", levelAssessMap.get(date).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + resultList.add(map); + } else if (Objects.isNull(levelAssessMap.get(date)) && !Objects.isNull(onDutyMap.get(date))) { + //2、补全安保等级评估数据处理 + //该日期levelAssessMap空,onDutyMap不空 + map.put("score", onDutyMap.get(date).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + resultList.add(map); + } else if (!Objects.isNull(levelAssessMap.get(date)) && !Objects.isNull(onDutyMap.get(date))) { + //该日期2个都不空 + BigDecimal onDutyDecimal = onDutyMap.get(date); + BigDecimal levelAssessDecimal = levelAssessMap.get(date); + map.put("score", onDutyDecimal.add(levelAssessDecimal).stripTrailingZeros().toPlainString()); + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object patrol() { + //近7天安保人员到岗率 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + + List dateCountList = caseInfoMapper.selectDemobilizedCountSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap onDutyMap = new HashMap<>(); + dateCountList.forEach(dateCount -> { + //到岗率 + BigDecimal totalCount = new BigDecimal(total); + BigDecimal leaveCount = new BigDecimal(dateCount.getLeaveCount()); + BigDecimal result = totalCount.subtract(leaveCount).divide(totalCount, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + onDutyMap.put(dateCount.getDate(), result.stripTrailingZeros().toPlainString()); + }); + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + //1、空数据处理 + if (CollectionUtils.isEmpty(onDutyMap) || Objects.isNull(onDutyMap.get(date))) { + map.put("date", date); + map.put("score", "100"); + resultList.add(map); + } else { + map.put("date", date); + map.put("score", onDutyMap.get(date)); + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object other() { + //安全防护评分(所有楼的评分的均值) + List caseInfos = caseInfoMapper.selectByPositionSevenDay(null); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap securityScoreMap = new HashMap<>(); + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + securityScoreDTO1.setDate(caseInfo.getHappenTime().substring(0, caseInfo.getHappenTime().indexOf(" "))); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + securityScoreMap.put(dict.getName(), BigDecimal.valueOf(100)); + } + } else { + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getDate)); + collect.keySet().forEach(key -> { + List list = collect.get(key); + //该日期发生时间的楼栋 + Map> collect3 = list.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + //无评分的楼栋数据补全处理 + if (collect3.size() < devicePosition.size()) { + List collect4 = list.stream().map(SecurityScoreDTO::getPosition).collect(Collectors.toList()); + for (Dict dict : devicePosition) { + String code = dict.getCode(); + if (!collect4.contains(code)) { + SecurityScoreDTO securityScoreDTO = new SecurityScoreDTO(); + securityScoreDTO.setDate(key); + securityScoreDTO.setPosition(code); + securityScoreDTO.setScore(100.0); + list.add(securityScoreDTO); + } + } + } + //该日期所有楼栋扣分和 + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + double sum = collect1.getSum(); + //该日期发生时间的楼栋个数 + Map> collect4 = list.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + int size = collect4.keySet().size(); + //(100*发生事件的楼栋个数-扣分和)/楼栋个数 + BigDecimal securityScore = BigDecimal.valueOf(100).multiply(BigDecimal.valueOf(size)).subtract(BigDecimal.valueOf(sum)).divide(BigDecimal.valueOf(size), 2, BigDecimal.ROUND_HALF_UP); + securityScoreMap.put(key, securityScore); + }); + } + + //设备维修次数(满分一百分,发生一次维修减5分) + //当天设备的维修记录 + HashMap repairMap = new HashMap<>(); + List repairLogs = repairLogMapper.selectListBySevenDay(); + repairLogs.forEach(repair -> { + repair.setRepairEndTime(repair.getRepairEndTime().substring(0, repair.getRepairEndTime().indexOf(" "))); + }); + List dateList = DateUtils.getCurrentDateDayList(); + Map> collect = repairLogs.stream().collect(Collectors.groupingBy(DeviceRepairLog::getRepairEndTime)); + collect.keySet().forEach(key -> { + List deviceRepairLogs = collect.get(key); + //开始时间到结束时间的每天都扣分 + for (DeviceRepairLog log : deviceRepairLogs) { + String startTime = log.getRepairStartTime().substring(0, log.getRepairStartTime().indexOf(" ")); + String endTime = log.getRepairEndTime().substring(0, log.getRepairStartTime().indexOf(" ")); + List betweenDays = DateUtils.getBetweenDays(startTime, endTime); + //包含首尾时间 + Collection intersection = org.apache.commons.collections4.CollectionUtils.intersection(dateList, betweenDays); + if (!CollectionUtils.isEmpty(intersection)) { + for (String date : intersection) { + if (Objects.isNull(repairMap.get(date))) { + //发生一次维修减5分 + repairMap.put(date, BigDecimal.valueOf(100 - 5)); + } else { + BigDecimal old = repairMap.get(date); + repairMap.put(date, old.subtract(BigDecimal.valueOf(5))); + } + } + } + } + }); + //构造结果 + List> resultList = new ArrayList<>(); + BigDecimal repairConfigScore = BigDecimal.valueOf(cockpitConfig.getOtherWeight().get("repair")); + BigDecimal securityConfigScore = BigDecimal.valueOf(cockpitConfig.getOtherWeight().get("security")); + if (CollectionUtils.isEmpty(securityScoreMap)) { + for (String date : dateList) { + securityScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if(CollectionUtils.isEmpty(repairMap)){ + for (String date : dateList) { + repairMap.put(date, BigDecimal.valueOf(100)); + } + } + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + //补全数据处理 + if (Objects.isNull(securityScoreMap.get(date)) && Objects.isNull(repairMap.get(date))) { + //该日期2个都空 + map.put("score", "100"); + } else if (Objects.isNull(securityScoreMap.get(date)) && !Objects.isNull(repairMap.get(date))) { + //该日期securityScoreMap空,repairMap不空 + map.put("score", repairConfigScore.multiply(repairMap.get(date)).add(securityConfigScore.multiply(BigDecimal.valueOf(100))) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } else if (Objects.isNull(repairMap.get(date)) && !Objects.isNull(securityScoreMap.get(date))) { + //该日期securityScoreMap不空,repairMap空 + map.put("score", securityConfigScore.multiply(securityScoreMap.get(date)).add(repairConfigScore.multiply(BigDecimal.valueOf(100))) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } else if (!Objects.isNull(securityScoreMap.get(date)) && !Objects.isNull(repairMap.get(date))) { + //该日期2个都不空 + BigDecimal securityScoreDecimal = securityConfigScore.multiply(securityScoreMap.get(date)); + BigDecimal repairDecimal = repairConfigScore.multiply(repairMap.get(date)); + map.put("score", securityScoreDecimal.add(repairDecimal) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } + resultList.add(map); + }); + return ResponseData.success(resultList); + } + + private List> getForResult(List weekCaseDTOS, List weekCaseKeyAreaDTOS, + List caseInfos, HashMap weekCaseMap, HashMap caseScoreMap, + HashMap keyAreaScoreMap, HashMap assessScoreMap, + List dateList){ + Map keyAreaWeight = cockpitConfig.getKeyAreaWeight(); + weekCaseKeyAreaDTOS.forEach(dto -> { + weekCaseMap.put(dto.getDimension(), BigDecimal.valueOf(dto.getQuantity())); + }); + weekCaseDTOS.forEach(dto -> { + String date = dto.getDimension(); + Integer quantity = dto.getQuantity(); + //无重点区域事件数据,1-安防事件次数/所有安防事件次数=1 + if (Objects.isNull(weekCaseMap.get(date)) || weekCaseMap.get(date).equals(BigDecimal.ZERO)) { + caseScoreMap.put(date, BigDecimal.valueOf(1 * 100)); + } else { + BigDecimal multiply = BigDecimal.valueOf(quantity).subtract(weekCaseMap.get(date)).divide(BigDecimal.valueOf(quantity), 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + caseScoreMap.put(date, multiply); + } + }); + + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + caseInfos.forEach(caseInfo -> { + //重点区域安防事态评估分数 + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double keyAreaScore = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String dayTime = caseInfo.getHappenTime().substring(0, caseInfo.getHappenTime().indexOf(" ")); + BigDecimal preScore; + if (keyAreaScoreMap.containsKey(dayTime)) { + preScore = keyAreaScoreMap.get(dayTime); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(keyAreaScore.toString()); + keyAreaScoreMap.put(dayTime, preScore.subtract(nowScore)); + + //安防机动支援力量响应评估分数 + //扣分=事件级别权重*未解决小时数 + Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); + Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); + long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); + Double assessScore = Double.valueOf(hazardWeight) * between; + BigDecimal preAssessScore; + if (assessScoreMap.containsKey(dayTime)) { + preAssessScore = assessScoreMap.get(dayTime); + } else { + preAssessScore = new BigDecimal("100.0"); + } + BigDecimal nowAssessScore = new BigDecimal(assessScore.toString()); + assessScoreMap.put(dayTime, preAssessScore.subtract(nowAssessScore)); + }); + //构造结果 + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(caseScoreMap)) { + for (String date : dateList) { + caseScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if (CollectionUtils.isEmpty(keyAreaScoreMap)) { + for (String date : dateList) { + keyAreaScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if (CollectionUtils.isEmpty(assessScoreMap)) { + for (String date : dateList) { + assessScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + BigDecimal preCaseScore = Objects.isNull(caseScoreMap.get(date)) ? BigDecimal.valueOf(100) : caseScoreMap.get(date); + BigDecimal preKeyAreaScore = Objects.isNull(keyAreaScoreMap.get(date)) ? BigDecimal.valueOf(100) : keyAreaScoreMap.get(date); + BigDecimal preAssessScore = Objects.isNull(assessScoreMap.get(date)) ? BigDecimal.valueOf(100) : assessScoreMap.get(date); + BigDecimal caseScore = preCaseScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("case"))); + BigDecimal keyAreaScore = preKeyAreaScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("keyArea"))); + BigDecimal responseAssessScore = preAssessScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("responseAssess"))); + map.put("score", caseScore.add(keyAreaScore).add(responseAssessScore).stripTrailingZeros().toPlainString()); + resultList.add(map); + }); + return resultList; + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java index 316188e..71d587d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java @@ -22,4 +22,11 @@ boolean insertCaseInfoBatch(List caseInfos); List caseInfoList(CaseInfoRequest caseInfoRequest); + + List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest); + + Object caseInfoLastByDrawNo(String drawNo); + + int updateAllStatus(); + } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java index b3d1968..7a7fe8a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java @@ -2,6 +2,10 @@ import com.alibaba.fastjson.JSONArray; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import java.util.HashMap; import java.util.List; @@ -13,4 +17,32 @@ */ public interface CockpitService { HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap); + + Object buildingNumberPerHour(); + + Object visitorTodayNumber(); + + Object deviceNumber(); + + Object securityNumber(); + + Object visitorApplyDetail(); + + Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO); + + Object eventCategoryStatistics(); + + Object fireEquipStatistics(); + + Object beOnDutyRatio(); + + Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO); + + Object securityScore(SecurityScoreDTO securityScoreDTO); + + Object securityFrequency(); + + Object areaScore(SecurityScoreDTO securityScoreDTO); + + Object heatMap(HeatMapDTO heatMapDTO); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java new file mode 100644 index 0000000..178b909 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.service; + +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; + +/** + * @Description: + * @Author: wangpeng + * @Date: 2022/10/11 9:10 + */ +public interface PropertyManageService { + Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO); + + Object keyAreaData(String dimension); + + Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO); + + Object attendanceNumber(String dimension); + + Object securityAssessment(String dimension); + + Object keyAreaStatistic(); + + Object responseAssess(); + + Object hazardLevelStatistics(String dimension); + + Object securityRank(); + + Object securityLevelAssess(); + + Object commute(); + + Object keyArea(); + + Object visitor(); + + Object security(); + + Object patrol(); + + Object other(); +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java index ea6b8c0..2580187 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java @@ -17,6 +17,7 @@ import com.casic.missiles.modular.service.BlackInfoService; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -70,11 +71,17 @@ faceInfo.setCertificateNum(blackInfo.getIdCardNo()); faceSingleAddOrUpdateRequest.setFaceInfo(faceInfo); FacePic facePic = new FacePic(); - facePic.setFaceBinaryData(blackInfo.getPicture()); - faceSingleAddOrUpdateRequest.setFacePic(facePic); + String picture = blackInfo.getPicture(); + if(StringUtils.isNotEmpty(picture)){ + String substringPicture = picture.substring(picture.indexOf(",") + 1); + facePic.setFaceBinaryData(substringPicture); + } faceSingleAddOrUpdateRequest.setFacePic(facePic); String body = JSONObject.toJSONString(faceSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.FACE_SINGLE_ADDITION, body); + log.info("-----------------------"); + log.info("增加黑名单人脸请求body,{}", body); + log.info("增加黑名单人脸resultStr:{}", JSONObject.toJSONString(resultStr)); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人脸失败,海康response:{}", resultStr); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java index 6b03d8b..1c34f68 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java @@ -2,17 +2,22 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.dao.CaseInfoMapper; import com.casic.missiles.modular.dao.CategoryLevelMapper; +import com.casic.missiles.modular.dao.DeviceInfoMapper; import com.casic.missiles.modular.dao.HazardLevelMapper; import com.casic.missiles.modular.dto.CaseInfoRequest; import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.model.CaseInfo; +import com.casic.missiles.modular.model.DeviceInfo; import com.casic.missiles.modular.service.CaseInfoService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,6 +31,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; /** * @Description: 安防事件service @@ -50,6 +56,9 @@ @Resource private AbstractDictService dictService; + @Resource + private DeviceInfoMapper deviceInfoMapper; + @Override public List caseInfoListPage(Page page, CaseInfoRequest caseInfoRequest) { try { @@ -136,17 +145,69 @@ @Override public List caseInfoList(CaseInfoRequest caseInfoRequest) { try { - List pageList = caseInfoMapper.getCaseInfoList(caseInfoRequest); - pageList.forEach(caseInfo ->{ + List list = caseInfoMapper.getCaseInfoList(caseInfoRequest); + list.forEach(caseInfo ->{ caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); }); - return pageList; + return list; } catch (DataAccessException ex) { log.error("安防事件: 查询不分页出现异常, 异常:{}", ex); } return null; } + + @Override + public List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest) { + try { + List list = caseInfoMapper.getCaseInfoListUnResolved(caseInfoRequest); + list.forEach(caseInfo ->{ + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + }); + return list; + } catch (DataAccessException ex) { + log.error("未解决/解决中安防事件: 查询不分页出现异常, 异常:{}", ex); + } + return null; + } + + @Override + public Object caseInfoLastByDrawNo(String drawNo) { + //图纸编号和设备编号一一对应 + QueryWrapper dWrapper = new QueryWrapper<>(); + dWrapper.eq("draw_no", drawNo); + DeviceInfo deviceInfo = deviceInfoMapper.selectOne(dWrapper); + if(Objects.isNull(deviceInfo)){ + return ResponseData.error("该图纸编号下不存在关联的设备"); + } + if(StringUtils.isEmpty(deviceInfo.getDevCode())){ + return ResponseData.error("该图纸编号下不存在对应的设备编号"); + }else{ + String devCode = deviceInfo.getDevCode(); + QueryWrapper cWrapper = new QueryWrapper<>(); + cWrapper.eq("device_code", devCode); + List caseInfos = caseInfoMapper.selectList(cWrapper); + if(CollectionUtil.isEmpty(caseInfos)){ + return ResponseData.error("该图纸编号下不存在最近发生的事件"); + } + CaseInfo caseInfo = caseInfos.get(caseInfos.size() - 1); + caseInfo.setDrawNo(deviceInfo.getDrawNo()); + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + return ResponseData.success(caseInfo); + } + } + + @Override + public int updateAllStatus() { + int upflag = caseInfoMapper.updateAllStatus(); + return upflag; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java index 7402991..7fb5a6e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java @@ -4,15 +4,34 @@ import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.*; import com.casic.missiles.modular.enums.HikUri; +import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.redis.RedisUtil; +import com.casic.missiles.modular.redis.key.CacheKeys; import com.casic.missiles.modular.service.CockpitService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import java.text.MessageFormat; +import java.text.NumberFormat; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.*; +import java.util.stream.Collectors; /** * @Description: @@ -22,6 +41,28 @@ @Slf4j @Service public class CockpitServiceImpl implements CockpitService { + @Autowired + private StatisticNumberMapper numberMapper; + @Autowired + private AbstractDictService dictService; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private DeviceInfoMapper deviceInfoMapper; + @Autowired + private FireEquipInfoMapper fireEquipInfoMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private VisitorApplyMapper applyMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private RedisUtil redisUtil; @Override public HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap) { @@ -106,4 +147,512 @@ }); return resultMap; } + + @Override + public Object buildingNumberPerHour() { + //当天按小时分组的人数 + List list = numberMapper.selectListByTime(); + Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); + //定时任务中已将每小时三栋楼人数存到数据库 + //将一期主楼和录制楼人数合并,二期单算 + List> resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List buildingNumberDTOS = collect.get(key); + BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); + BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); + BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); + HashMap resultMap = new HashMap<>(); + Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); + Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); + resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); + resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); + resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); + resultList.add(resultMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object visitorTodayNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); + List visitInfos = visitInfoMapper.selectList(wrapper); + HashMap resultMap = new HashMap<>(); + resultMap.put("今日访客量", visitInfos.size()); + return ResponseData.success(resultMap); + } + + @Override + public Object deviceNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + Integer total = deviceInfoMapper.selectCount(wrapper); + QueryWrapper wrapper1 = new QueryWrapper<>(); + wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 + Integer online = deviceInfoMapper.selectCount(wrapper1); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) online / (float) total * 100); + HashMap resultMap = new HashMap<>(); + resultMap.put("设备总数", total); + resultMap.put("设备在线率", result + "%"); + return ResponseData.success(resultMap); + } + + @Override + public Object securityNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) leave / (float) total * 100); + HashMap resultMap = new HashMap<>(); + if (0 == total) { + resultMap.put("安保人员总数", 0); + resultMap.put("安保人员离岗率", "0"); + } else { + resultMap.put("安保人员总数", total); + resultMap.put("安保人员离岗率", result + ""); + } + return ResponseData.success(resultMap); + } + + @Override + public Object visitorApplyDetail() { + List reasonGroup = applyMapper.selectByVisitReason(); + List resultList = new ArrayList<>(); + //空数据处理 + List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); + if (CollectionUtils.isEmpty(reasonGroup)) { + for (Dict dict : visitReason) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(dict.getName()); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); + if (0 == sum) { + return ResponseData.success(); + } + reasonGroup.forEach(group -> { + String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(group.getQuantity()); + applyReasonGroupDTO.setVisitReason(reasonName); + applyReasonGroupDTO.setRatio(result + "%"); + resultList.add(applyReasonGroupDTO); + }); + //返回数据补全处理 + if (resultList.size() < visitReason.size()) { + List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); + for (Dict dict : visitReason) { + String name = dict.getName(); + if (!collect.contains(name)) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(name); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO) { + //查询各危险级别权重name,用于构造返回结构 + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); + + Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); + List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(list)) { + Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + //查询数据,放入redis + List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); + Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //设置过期时间为每月1号0点 + LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) + .withMinute(0).withSecond(0).withNano(0); + long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); + redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + + @Override + public Object eventCategoryStatistics() { + List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); + return ResponseData.success(categoryLevelGroup); + } + + @Override + public Object fireEquipStatistics() { + List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); + //空数据处理 + List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); + if (CollectionUtils.isEmpty(equipTypeGroup)) { + for (Dict dict : equipType) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + return ResponseData.success(equipTypeGroup); + } + equipTypeGroup.forEach(group -> { + String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); + group.setEquipTypeName(equipTypeName); + }); + //返回数据补全处理 + if (equipTypeGroup.size() < equipType.size()) { + List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); + for (Dict dict : equipType) { + String code = dict.getCode(); + if (!collect.contains(code)) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + } + } + return ResponseData.success(equipTypeGroup); + } + + @Override + public Object beOnDutyRatio() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + if (0 == total) { + return ResponseData.success(null); + } + List currentDateHourList = DateUtils.getCurrentDateWorkHourList(); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + //补全空数据 + if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { + for (String date : currentDateHourList) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + return ResponseData.success(onDutyRatioDTOS); + } + onDutyRatioDTOS.forEach(dto -> { + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); + dto.setRatio(result + "%"); + }); + //补全空数据 + List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); + for (String date : currentDateHourList) { + if (!collect.contains(date)) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + } + return ResponseData.success(onDutyRatioDTOS); + } + + @Override + public Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO) { + List gateStatusGroup = null; + //2代表所有摄像头(对应字典2-7) + if ("2".equals(gateStatusGroupDTO.getDevType())) { + gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); + } else { + gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); + } + HashMap resultMap = new HashMap<>(); + //空数据处理 + List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); + if (CollectionUtils.isEmpty(gateStatusGroup)) { + List resultList = new ArrayList<>(); + for (Dict dict : deviceStatus) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + resultMap.put("total", 0); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("无该类设备信息"); + } + List resultList = new ArrayList<>(); + gateStatusGroup.forEach(group -> { + if ("2".equals(gateStatusGroupDTO.getDevType())) { + group.setDevType("2"); + } + String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(devStatus); + gateStatusGroupResponse.setRatio(result + "%"); + gateStatusGroupResponse.setQuantity(group.getQuantity()); + resultList.add(gateStatusGroupResponse); + }); + //返回数据补全处理 + if (resultList.size() < deviceStatus.size()) { + List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); + for (Dict dict : deviceStatus) { + String name = dict.getName(); + if (!collect.contains(name)) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + } + } + resultMap.put("total", sum); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + + @Override + public Object securityScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的position划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + List caseInfos = caseInfoMapper.selectByPosition(position); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //楼栋-评分实体map + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + Map resultMap = new HashMap<>(); + //空数据处理 + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + resultMap.put(dict.getName(), 100.0); + } + return ResponseData.success(resultMap); + } + + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + + collect.keySet().forEach(key -> { + List list = collect.get(key); + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); + resultMap.put(dictValue, 100 - collect1.getSum()); + }); + //返回数据补全处理 + if (collect.size() < devicePosition.size()) { + Set strings = resultMap.keySet(); + for (Dict dict : devicePosition) { + String name = dict.getName(); + if (!strings.contains(name)) { + resultMap.put(dict.getName(), 100.0); + } + } + } + //按楼层分组计算评分 +// collect.keySet().forEach(key -> { +// Map map = new HashMap<>(); +// List securityScoreDTOS = collect.get(key); +// //楼层-评分map +// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); +// collect1.keySet().forEach(key1 -> { +// map.put(key1, 100 - collect1.get(key1)); +// }); +// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); +// resultMap.put(dictValue, map); +// }); + return ResponseData.success(resultMap); + } + + @Override + public Object securityFrequency() { + String year = String.valueOf(DateUtil.thisYear()); + String month = String.valueOf(DateUtil.thisMonth()); + Integer quantity = caseInfoMapper.selectCountByMonth(year, month); + SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); + securityFrequencyDTO.setQuantity(quantity); + securityFrequencyDTO.setYear(year); + securityFrequencyDTO.setMonth(month); + return ResponseData.success(securityFrequencyDTO); + } + + @Override + public Object areaScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的area划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + String area = securityScoreDTO.getArea(); + if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { + return null; + } + Map resultMap = new HashMap<>(); + List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); + if (Objects.isNull(caseInfos)) { + resultMap.put("安防评分", 100.0); + return ResponseData.success(resultMap); + } + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + resultMap.put("安防评分", 100 - collect.getSum()); + return ResponseData.success(resultMap); + } + + @Override + public Object heatMap(HeatMapDTO heatMapDTO) { + if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { + heatMapDTO.setMinute(3); + } + List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); + Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); + HashMap resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect)) { + return ResponseData.success(); + } + collect.keySet().forEach(key -> { + resultMap.put(key, collect.get(key).size()); + }); + return ResponseData.success(resultMap); + } + + private List> getResultMap(List nameList, List> resultList, Map> resultMap) { + resultMap.keySet().forEach(key -> { + List monthAndLevelGroupDTOS = resultMap.get(key); + HashMap hashMap = new HashMap<>(); + for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { +// hashMap.put("年份", andLevelGroupDTO.getYear()); + hashMap.put("月份", /*andLevelGroupDTO.getYear() + "-" + */Integer.valueOf(andLevelGroupDTO.getMonth())); + hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); + } + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + }); + //12个月份,用于构造返回结构 + List list1 = new ArrayList<>(); + for (Map map : resultList) { + list1.add(String.valueOf(map.get("月份"))); + } + for (int i = 1; i < 13; i++) { + if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { + continue; + } + HashMap hashMap = new HashMap<>(); + hashMap.put("月份", i); + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + } + List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); + return results; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java index 94308db..f91d7bd 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java @@ -427,6 +427,13 @@ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("draw_no", drawNo); DeviceInfo deviceInfo = deviceInfoMapper.selectOne(wrapper); + if(!Objects.isNull(deviceInfo)){ + deviceInfo.setDevTypeName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_TYPE, deviceInfo.getDevType())); + deviceInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, deviceInfo.getStatus())); + deviceInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, deviceInfo.getPosition())); + deviceInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, deviceInfo.getArea())); + deviceInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, deviceInfo.getIsKeyArea())); + } return deviceInfo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java index 8ed53d9..c399a7f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java @@ -11,6 +11,7 @@ import com.casic.missiles.modular.service.HikService; import com.casic.missiles.modular.system.model.Dict; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -50,8 +51,11 @@ @Override public CaseInfo blackListHandle(JSONObject event, CaseInfo caseInfo) { - String srcIndex = event.getString("srcIndex"); //海康资源唯一标识 + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 String happenTimeISO = String.valueOf(event.get("happenTime")); + DateTime parse = DateUtil.parse(happenTimeISO); String happenTime = DateUtil.formatDateTime(parse); caseInfo.setHappenTime(happenTime); //发生时间 @@ -89,6 +93,16 @@ log.info("接收到离岗事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //离岗事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray leavePosition = data.getJSONArray("leavePosition"); + if(StringUtils.isNotEmpty(leavePosition.getString(0))){ + JSONObject jsonObject = leavePosition.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -115,6 +129,16 @@ log.info("接收到人员聚集事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //人员聚集事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray group = data.getJSONArray("group"); + if(StringUtils.isNotEmpty(group.getString(0))){ + JSONObject jsonObject = group.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -263,8 +287,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void propertyAttendanceHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); @@ -309,8 +334,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void securityPersonnelHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java new file mode 100644 index 0000000..4427f19 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java @@ -0,0 +1,1255 @@ +package com.casic.missiles.modular.service.impl; + +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.config.CockpitConfig; +import com.casic.missiles.modular.dao.*; +import com.casic.missiles.modular.dto.statistics.*; +import com.casic.missiles.modular.enums.SecurityEventDict; +import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.service.PropertyManageService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.text.NumberFormat; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @Description: 驾驶舱二级页面-物管信息 + * @Author: wangpeng + * @Date: 2022/10/11 9:11 + */ +@Slf4j +@Service +public class PropertyManageServiceImpl implements PropertyManageService { + @Autowired + private AttendanceInfoMapper attendanceInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private DeviceRepairLogMapper repairLogMapper; + @Autowired + private CockpitConfig cockpitConfig; + @Autowired + private AbstractDictService dictService; + + @Override + public Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO) { + //各类型员工及总数 + List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); + Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); + + String dateDimension = attendanceRatioDTO.getDateDimension(); + List attendanceRatioDTOS = new ArrayList<>(); + List dateList = null; + //考勤的人数,按单次考勤过滤 + if ("week".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); + dateList = DateUtils.getCurrentDateDayList(); + } else if ("month".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); + dateList = DateUtils.getCurrentDateWeekList(); + } else if ("year".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); + dateList = DateUtils.getCurrentDateMonthList(); + } + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { + for (String date : dateList) { + HashMap hashMap = new HashMap<>(); + hashMap.put("date", date); + hashMap.put("property", "0%"); + hashMap.put("security", "0%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + //计算出勤率 + Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); + + dateList.forEach(date -> { + HashMap hashMap = new HashMap<>(); + if (CollectionUtils.isEmpty(dateMap.get(date))) { + hashMap.put("date", date); + hashMap.put("property", "0%"); + hashMap.put("security", "0%"); + resultList.add(hashMap); + } else { + List attendances = dateMap.get(date); + attendances.forEach(attendanceRatio -> { + attendanceRatio.setDateDimension(dateDimension); + attendanceRatio.setStaffType(attendanceRatio.getStaffType()); + List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); + String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); + attendanceRatio.setAttendanceRatio(ratio + "%"); + //构造返回结构 + hashMap.put("date", attendanceRatio.getDate()); +// String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); + if ("1".equals(attendanceRatio.getStaffType())) { + hashMap.put("property", attendanceRatio.getAttendanceRatio()); + } + if ("2".equals(attendanceRatio.getStaffType())) { + hashMap.put("security", attendanceRatio.getAttendanceRatio()); + } + }); + //补全缺少数据 + if (1 == attendances.size()) { + AttendanceRatioDTO attendanceRatioDTO1 = attendances.get(0); + if ("1".equals(attendanceRatioDTO1.getStaffType())) { + hashMap.put("security", "0%"); + } + if ("2".equals(attendanceRatioDTO1.getStaffType())) { + hashMap.put("property", "0%"); + } + } + resultList.add(hashMap); + } + }); + return ResponseData.success(resultList); + + } + + @Override + public Object keyAreaData(String dimension) { + List resultList = null; + List dateList = null; + if ("year".equals(dimension)) { + //近365天数据按月分组统计 + resultList = caseInfoMapper.selectPreMonthCountByNearYear(); + dateList = DateUtils.getCurrentDateMonthList(); + } else if ("month".equals(dimension)) { + //近30天数据按周分组统计 + resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); + dateList = DateUtils.getCurrentDateWeekList(); + } else if ("week".equals(dimension)) { + //近7天数据按天分组统计 + resultList = caseInfoMapper.selectPreDayCountBySevenDay(); + dateList = DateUtils.getCurrentDateDayList(); + } + //补全空数据处理 + if (CollectionUtils.isEmpty(resultList)) { + for (String date : dateList) { + PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); + preMonthOrWeekCaseDTO.setDimension(date); + preMonthOrWeekCaseDTO.setQuantity(0); + resultList.add(preMonthOrWeekCaseDTO); + } + } else { + for (String date : dateList) { + List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); + if (!collect.contains(date)) { + PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); + preMonthOrWeekCaseDTO.setDimension(date); + preMonthOrWeekCaseDTO.setQuantity(0); + resultList.add(preMonthOrWeekCaseDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { + String year = avgMonthAndWeekGroupDTO.getYear(); + List monthList = caseInfoMapper.selectPreMonthCountByYear(year); + Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); + HashMap strAvgMap = new HashMap<>(); + List resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List preMonthOrWeekCaseDTOS = collect.get(key); + int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); + //若年份是本年,则使用各安防级别数量/当前月份数 + //若不是本年,除数为12 + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + if (year.equals(String.valueOf(DateUtil.thisYear()))) { + monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); + strAvgMap.put(key, monthAndWeekDTO); + } else { + monthAndWeekDTO.setMonthQuantity(sum / 12); + strAvgMap.put(key, monthAndWeekDTO); + } + } + + List weekList = caseInfoMapper.selectPreWeekCountByYear(year); + Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); + for (String key : collect1.keySet()) { + List preMonthOrWeekCaseDTOS = collect.get(key); + int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); + if (year.equals(String.valueOf(DateUtil.thisYear()))) { + if (!Objects.isNull(strAvgMap.get(key))) { + MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); + strAvgMap.put(key, monthAndWeekDTO); + } else { + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); + strAvgMap.put(key, monthAndWeekDTO); + } + } else { + if (!Objects.isNull(strAvgMap.get(key))) { + MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / 52); + strAvgMap.put(key, monthAndWeekDTO); + } else { + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / 52); + strAvgMap.put(key, monthAndWeekDTO); + } + } + } + strAvgMap.keySet().forEach(key -> { + resultList.add(strAvgMap.get(key)); + }); + //输出顺序 + Collections.swap(resultList, 1, 2); + return ResponseData.success(resultList); + } + + @Override + public Object attendanceNumber(String dimension) { + List attendanceNumberDTOs = null; + List> resultList = new ArrayList<>(); + List dateList = new ArrayList<>(); + if ("week".equals(dimension)) { + //近7天数据按天分组统计 + attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); + dateList = DateUtils.getCurrentDateDayList(); + } else if ("day".equals(dimension)) { + //今天数据按小时分组统计 + attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); + dateList = DateUtils.getCurrentDateWorkHourList(); + } + if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { + for (String date : dateList) { + HashMap hashMap = new HashMap<>(); + hashMap.put("staticTime", date); + hashMap.put("1", "0"); + hashMap.put("2", "0"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); + if ("day".equals(dimension)) { + collect = collect.entrySet().stream().collect(Collectors.toMap(m -> m.getKey().substring(5) + ":00", Map.Entry::getValue)); + } + + for (String date : dateList) { + Map resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect.get(date))) { + resultMap.put("1", "0"); + resultMap.put("2", "0"); + resultMap.put("staticTime", date); + resultList.add(resultMap); + } else { + List attendanceNumberDTOS = collect.get(date); +// Map resultMap = new HashMap<>(); + AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); + if (attendanceNumberDTOS.size() >= 2) { + AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); + resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); + } + resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); + resultMap.put("staticTime", date); + resultList.add(resultMap); + //补全map缺少数据 + if (!resultMap.containsKey("1")) { + resultMap.put("1", "0"); + } + if (!resultMap.containsKey("2")) { + resultMap.put("2", "0"); + } + } + } + +// +// collect.keySet().forEach(key -> { +// List attendanceNumberDTOS = collect.get(key); +// Map resultMap = new HashMap<>(); +// AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); +// if (attendanceNumberDTOS.size() >= 2) { +// AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); +// resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); +// } +// resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); +// resultMap.put("staticTime", attendanceNumberDTO.getDate().substring(5) + ":00"); +// resultList.add(resultMap); +// }); +// //补全空数据处理 +// if (CollectionUtils.isEmpty(resultList)) { +// for (String date : dateList) { +// Map resultMap = new HashMap<>(); +// resultMap.put("1", "0"); +// resultMap.put("2", "0"); +// resultMap.put("staticTime", date); +// resultList.add(resultMap); +// } +// } else { +// List collectList = new ArrayList<>(); +// for (Map map : resultList) { +// String staticTime = map.get("staticTime"); +// collectList.add(staticTime); +// //补全map缺少数据 +// if (!map.containsKey("1")) { +// map.put("1", "0"); +// } +// if (!map.containsKey("2")) { +// map.put("2", "0"); +// } +// } +// for (String date : dateList) { +// if (!collectList.contains(date)) { +// Map resultMap = new HashMap<>(); +// resultMap.put("1", "0"); +// resultMap.put("2", "0"); +// resultMap.put("staticTime", date); +// resultList.add(resultMap); +// } +// } +// } + return ResponseData.success(resultList); + } + + @Override + public Object securityAssessment(String dimension) { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + if ("week".equals(dimension)) { + //近7天早晚高峰数据 + List caseInfos = caseInfoMapper.selectListBySevenDay(); + //按时间(天)进行分组 + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(" "); + String dayTime = array[0]; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } else if ("day".equals(dimension)) { + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDatePeakHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + + } + return null; + } + + @Override + public Object keyAreaStatistic() { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday2(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + dayTime = dayTime.substring(5) + ":00"; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } + + @Override + public Object responseAssess() { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday3(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + //扣分=事件级别权重*未解决小时数 + Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); + Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); + long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); + Double score = Double.valueOf(hazardWeight) * between; + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + dayTime = dayTime.substring(5) + ":00"; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } + + @Override + public Object hazardLevelStatistics(String dimension) { + List hazardLevelGroup = null; + if ("week".equals(dimension)) { + hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); + } else if ("month".equals(dimension)) { + hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); + } + if (CollectionUtils.isEmpty(hazardLevelGroup)) { + log.info("重点区域威胁事件类型统计,无安防事件"); + return ResponseData.error("无安防事件发生!"); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("安防事件总数为0"); + } + hazardLevelGroup.forEach(group -> { + CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); + group.setLevelName(caseHazardLevel.getName()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + group.setLevelRatio(result + "%"); + }); + HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); + hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); + hazardLevelGroupResponse.setQuantity(sum); + return ResponseData.success(hazardLevelGroupResponse); + } + + @Override + public Object securityRank() { + //考勤表近一个月按人员分组的考勤个数前十名 + List list = attendanceInfoMapper.getCountForRank(); + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(list)) { + //补全空数据处理 + List staffList = staffInfoMapper.selectListLimitTen(); + for (StaffInfo staffInfo : staffList) { + HashMap hashMap = new HashMap<>(); + hashMap.put(staffInfo.getStaffName(), "0%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + //构造返回结构 + for (SecurityRankDTO dto : list) { + // TODO: 2022/9/15 分母使用30,后续看产品定义 + HashMap hashMap = new HashMap<>(); + String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); + hashMap.put("name", dto.getStaffName()); + hashMap.put("ratio", result + "%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object securityLevelAssess() { + //今天数据按小时分组统计 + List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + if (CollectionUtils.isEmpty(resultList)) { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); + levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); + levelAssessDTO.setDate(date); +// levelAssessDTO.setQuantity(); + resultList.add(levelAssessDTO); + } + return ResponseData.success(resultList); + } + resultList.forEach(result -> { + result.setDate(result.getDate().substring(5) + ":00"); + BigDecimal deScore = new BigDecimal(result.getQuantity()); + BigDecimal preScore = new BigDecimal("100.0"); + result.setScore(preScore.subtract(deScore).doubleValue()); + }); + //数据补全处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + for (SecurityLevelAssessDTO levelAssessDTO : resultList) { + String substring = levelAssessDTO.getDate().substring(5) + ":00"; + if (!substring.equals(date)) { + SecurityLevelAssessDTO levelAssess = new SecurityLevelAssessDTO(); + levelAssess.setScore(new BigDecimal("100.0").doubleValue()); + levelAssess.setDate(date); + resultList.add(levelAssess); + break; + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object commute() { + //早晚高峰区域安防评估 + ResponseData assessResultJson = (ResponseData) this.securityAssessment("week"); + if (Objects.isNull(assessResultJson) || 200 != assessResultJson.getCode()) { + return assessResultJson; + } + JSONArray assessData = JSONArray.parseArray(JSON.toJSONString(assessResultJson.getData())); + //所有类型的员工出勤 + List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); + long sum = staffTypeAndSumDTOS.stream().collect(Collectors.summarizingInt(StaffTypeAndSumDTO::getSum)).getSum(); + List countByTypeAndDateForWeek = attendanceInfoMapper.getCountByTypeAndDateForWeek(); + Map> dateMap = countByTypeAndDateForWeek.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); + HashMap attendanceMap = new HashMap<>(); + dateMap.keySet().forEach(key -> { + List attendanceRatioDTOS = dateMap.get(key); + //当天所有类型的员工的出勤人数 + long sum1 = attendanceRatioDTOS.stream().collect(Collectors.summarizingInt(AttendanceRatioDTO::getQuantity)).getSum(); + //出勤占比评分 + Double attendanceRatio = ((float) sum1 / (float) sum) * 100 * cockpitConfig.getCommuteWeight(); + attendanceMap.put(key, attendanceRatio); + }); + //构造结果 + List> resultList = new ArrayList<>(); + Iterator iterator = assessData.stream().iterator(); + while (iterator.hasNext()) { + JSONObject next = (JSONObject) iterator.next(); + String date = next.getString("date"); + HashMap map = new HashMap<>(); + //计算评分 + Double assessRatio = next.getInteger("score") * (1 - cockpitConfig.getCommuteWeight()); + NumberFormat numberFormat = NumberFormat.getInstance(); + numberFormat.setMaximumFractionDigits(2); + if (!Objects.isNull(attendanceMap.get(date))) { + Double attendanceRatio = attendanceMap.get(date); + Double r = assessRatio + attendanceRatio; + map.put("score", numberFormat.format(r)); + } else { + //无员工出勤率(出勤为0),只有安防评估分值 + map.put("score", numberFormat.format(assessRatio)); + } + map.put("date", date); + resultList.add(map); + } + return ResponseData.success(resultList); + } + + @Override + public Object keyArea() { + //1-重点区域安防事件次数/所有安防事件次数 + //获取近7天每天的安防事件个数,所有和重点区域 + List weekCaseDTOS = caseInfoMapper.selectPreDayCountBySevenDay(); + List weekCaseKeyAreaDTOS = caseInfoMapper.selectPreDayCountBySevenDayKeyArea(); + List caseInfos = caseInfoMapper.selectListBySevenDayKeyArea(); + HashMap weekCaseMap = new HashMap<>(); + HashMap caseScoreMap = new HashMap<>(); + HashMap keyAreaScoreMap = new HashMap<>(); + HashMap assessScoreMap = new HashMap<>(); + List dateList = DateUtils.getCurrentDateDayList(); + List> result = getForResult(weekCaseDTOS, weekCaseKeyAreaDTOS, caseInfos, weekCaseMap, caseScoreMap, + keyAreaScoreMap, assessScoreMap, dateList); + + //上个月对应数据 + List beforeMonthKeyAreaCaseDTOS = caseInfoMapper.selectPreDayCountByBeforeMonthKeyArea(); + List beforeMonthCaseDTOS = caseInfoMapper.selectPreDayCountByBeforeMonth(); + List beforeMonthCaseInfos = caseInfoMapper.selectListByBeforeMonthKeyArea(); + HashMap beforeMonthWeekCaseMap = new HashMap<>(); + HashMap beforeMonthCaseScoreMap = new HashMap<>(); + HashMap beforeMonthKeyAreaScoreMap = new HashMap<>(); + HashMap beforeMonthAssessScoreMap = new HashMap<>(); + List beforeMonthDateList = DateUtils.getCurrentDateDayBeforeMonthList(); + List> resultBeforeMonth = getForResult(beforeMonthCaseDTOS, beforeMonthKeyAreaCaseDTOS, beforeMonthCaseInfos, + beforeMonthWeekCaseMap, beforeMonthCaseScoreMap, beforeMonthKeyAreaScoreMap, beforeMonthAssessScoreMap, beforeMonthDateList); + //计算环比 + for (int i = 0; i < result.size(); i++) { + Map resultMap = result.get(i); + Map resultBeforeMonthMap = resultBeforeMonth.get(i); + BigDecimal resultScore = BigDecimal.valueOf(Double.valueOf(String.valueOf(resultMap.get("score")))); + BigDecimal resultBeforeMonthScore = BigDecimal.valueOf(Double.valueOf(String.valueOf(resultBeforeMonthMap.get("score")))); + BigDecimal finalResult = resultScore.subtract(resultBeforeMonthScore).divide(resultBeforeMonthScore, 2, BigDecimal.ROUND_HALF_UP); + resultMap.put("ringRatio", finalResult); + } + return ResponseData.success(result); + } + + @Override + public Object visitor() { + //查询每天的访客对应的离开记录(进入记录存在且在申请范围内) + //近7天主要使用申请离开时间(申请进入时间不会影响扣分) + List list = visitInfoMapper.selectListBySevenDay(); + list.stream().forEach(visit -> { + DateTime dateTime = DateUtil.parseDateTime(visit.getApplyOutTime()); + String formatDate = DatePattern.NORM_DATE_FORMAT.format(dateTime); + visit.setDate(formatDate); + }); + Map> dateVisitMap = list.stream().collect(Collectors.groupingBy(MultiScoreVisitorDTO::getDate)); + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + HashMap deductMap = new HashMap<>(); //扣分使用 + dateList.forEach(date -> { + //1、空数据处理 + if (CollectionUtils.isEmpty(dateVisitMap)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } else if (CollectionUtils.isEmpty(dateVisitMap.get(date))) { + //2、补全数据处理 + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } else { + //3、计算数据处理 + //计算分数(未在申请时间段内离开减分(包括无离开时间和有离开时间两种情况)、未在申请区域内离开减分),配置扣分,配置每个访客最高扣分 + List multiScoreVisitorDTOS = dateVisitMap.get(date); + //遍历访客 + for (MultiScoreVisitorDTO visitorDTO : multiScoreVisitorDTOS) { + //无离开时间 + if (StringUtils.isEmpty(visitorDTO.getOutTime())) { + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + cockpitConfig.getVisitorWeight().get("NoRecordPointDeduct")); + } else { + deductMap.put(date, cockpitConfig.getVisitorWeight().get("NoRecordPointDeduct")); + } + } else { +// DateTime applyInDateTime = DateUtil.parseDateTime(visitorDTO.getApplyInTime()); + DateTime applyOutDateTime = DateUtil.parseDateTime(visitorDTO.getApplyOutTime()); + DateTime outDateTime = DateUtil.parseDateTime(visitorDTO.getOutTime()); + //未在申请时间段离开(在申请离开时间后离开) + if (DateUtil.compare(outDateTime, applyOutDateTime) > 0) { + long betweenHour = DateUtil.between(outDateTime, applyOutDateTime, DateUnit.HOUR); + Double score = betweenHour * cockpitConfig.getVisitorWeight().get("singlePointDeduct"); + //该访客扣分到达最多分 + if (score >= cockpitConfig.getVisitorWeight().get("mostPointDeduct")) { + score = cockpitConfig.getVisitorWeight().get("mostPointDeduct"); + } + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + score); + } else { + deductMap.put(date, score); + } + } + //未在申请区域离开 + if (StringUtils.isNotEmpty(visitorDTO.getApplyVisitPosition()) && !visitorDTO.getApplyVisitPosition().equals(visitorDTO.getVisitPosition())) { + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + cockpitConfig.getVisitorWeight().get("singlePointDeduct")); + } else { + deductMap.put(date, cockpitConfig.getVisitorWeight().get("singlePointDeduct")); + } + } + + } + } + //添加到结果list + HashMap map = new HashMap<>(); + map.put("date", date); + if (!Objects.isNull(deductMap.get(date))) { + //最少0分 + if (deductMap.get(date) >= 100) { + map.put("score", 0); + } else { + map.put("score", 100 - deductMap.get(date)); + } + } else { + map.put("score", 100); + } + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object security() { + //安保人员到岗率*100*权重0.5 + //近7天安保人员到岗率 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + + List dateCountList = caseInfoMapper.selectDemobilizedCountSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap onDutyMap = new HashMap<>(); + dateCountList.forEach(dateCount -> { + //到岗率 + BigDecimal totalCount = new BigDecimal(total); + BigDecimal leaveCount = new BigDecimal(dateCount.getLeaveCount()); + BigDecimal result = totalCount.subtract(leaveCount).divide(totalCount, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + onDutyMap.put(dateCount.getDate(), result.multiply(BigDecimal.valueOf(cockpitConfig.getSecurityWeight().get("onDuty"))).setScale(2, BigDecimal.ROUND_HALF_UP)); + }); + + //安保等级评估均值*权重0.5 + List levelAssessList = caseInfoMapper.selectListByTypeSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap levelAssessMap = new HashMap<>(); + levelAssessList.forEach(levelAssess -> { + //6-23点共17小时,100-该天扣分/17 + BigDecimal deScore = new BigDecimal(levelAssess.getQuantity()); + BigDecimal preScore = new BigDecimal("100.0"); + BigDecimal divide = deScore.divide(BigDecimal.valueOf(17), 2, BigDecimal.ROUND_HALF_UP); + BigDecimal result = preScore.subtract(divide); + levelAssessMap.put(levelAssess.getDate(), result.multiply(BigDecimal.valueOf(cockpitConfig.getSecurityWeight().get("levelAssess"))).setScale(2, BigDecimal.ROUND_HALF_UP)); + }); + + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + Double onDutyWeight = cockpitConfig.getSecurityWeight().get("onDuty"); + Double levelAssessWeight = cockpitConfig.getSecurityWeight().get("levelAssess"); + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + //1、空数据处理 + if (CollectionUtils.isEmpty(onDutyMap) && CollectionUtils.isEmpty(levelAssessMap)) { + //2个map都空 + map.put("score", "100"); + resultList.add(map); + } else if (CollectionUtils.isEmpty(onDutyMap) || CollectionUtils.isEmpty(levelAssessMap)) { + //2个map有一个为空 + if (CollectionUtils.isEmpty(onDutyMap)) { + if (!Objects.isNull(levelAssessMap.get(date))) { + map.put("score", levelAssessMap.get(date).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + } else { + map.put("score", BigDecimal.valueOf(100 * levelAssessWeight).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + } + } + if (CollectionUtils.isEmpty(levelAssessMap)) { + if (!Objects.isNull(onDutyMap.get(date))) { + map.put("score", onDutyMap.get(date).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + } else { + map.put("score", BigDecimal.valueOf(100 * onDutyWeight).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + } + } + } else if (Objects.isNull(onDutyMap.get(date)) && Objects.isNull(levelAssessMap.get(date))) { + //该日期2个都空 + map.put("score", "100"); + resultList.add(map); + } else if (Objects.isNull(onDutyMap.get(date)) && !Objects.isNull(levelAssessMap.get(date))) { + //2、补全到岗率数据处理 + //该日期onDutyMap空,levelAssessMap不空 + map.put("score", levelAssessMap.get(date).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + resultList.add(map); + } else if (Objects.isNull(levelAssessMap.get(date)) && !Objects.isNull(onDutyMap.get(date))) { + //2、补全安保等级评估数据处理 + //该日期levelAssessMap空,onDutyMap不空 + map.put("score", onDutyMap.get(date).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + resultList.add(map); + } else if (!Objects.isNull(levelAssessMap.get(date)) && !Objects.isNull(onDutyMap.get(date))) { + //该日期2个都不空 + BigDecimal onDutyDecimal = onDutyMap.get(date); + BigDecimal levelAssessDecimal = levelAssessMap.get(date); + map.put("score", onDutyDecimal.add(levelAssessDecimal).stripTrailingZeros().toPlainString()); + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object patrol() { + //近7天安保人员到岗率 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + + List dateCountList = caseInfoMapper.selectDemobilizedCountSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap onDutyMap = new HashMap<>(); + dateCountList.forEach(dateCount -> { + //到岗率 + BigDecimal totalCount = new BigDecimal(total); + BigDecimal leaveCount = new BigDecimal(dateCount.getLeaveCount()); + BigDecimal result = totalCount.subtract(leaveCount).divide(totalCount, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + onDutyMap.put(dateCount.getDate(), result.stripTrailingZeros().toPlainString()); + }); + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + //1、空数据处理 + if (CollectionUtils.isEmpty(onDutyMap) || Objects.isNull(onDutyMap.get(date))) { + map.put("date", date); + map.put("score", "100"); + resultList.add(map); + } else { + map.put("date", date); + map.put("score", onDutyMap.get(date)); + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object other() { + //安全防护评分(所有楼的评分的均值) + List caseInfos = caseInfoMapper.selectByPositionSevenDay(null); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap securityScoreMap = new HashMap<>(); + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + securityScoreDTO1.setDate(caseInfo.getHappenTime().substring(0, caseInfo.getHappenTime().indexOf(" "))); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + securityScoreMap.put(dict.getName(), BigDecimal.valueOf(100)); + } + } else { + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getDate)); + collect.keySet().forEach(key -> { + List list = collect.get(key); + //该日期发生时间的楼栋 + Map> collect3 = list.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + //无评分的楼栋数据补全处理 + if (collect3.size() < devicePosition.size()) { + List collect4 = list.stream().map(SecurityScoreDTO::getPosition).collect(Collectors.toList()); + for (Dict dict : devicePosition) { + String code = dict.getCode(); + if (!collect4.contains(code)) { + SecurityScoreDTO securityScoreDTO = new SecurityScoreDTO(); + securityScoreDTO.setDate(key); + securityScoreDTO.setPosition(code); + securityScoreDTO.setScore(100.0); + list.add(securityScoreDTO); + } + } + } + //该日期所有楼栋扣分和 + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + double sum = collect1.getSum(); + //该日期发生时间的楼栋个数 + Map> collect4 = list.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + int size = collect4.keySet().size(); + //(100*发生事件的楼栋个数-扣分和)/楼栋个数 + BigDecimal securityScore = BigDecimal.valueOf(100).multiply(BigDecimal.valueOf(size)).subtract(BigDecimal.valueOf(sum)).divide(BigDecimal.valueOf(size), 2, BigDecimal.ROUND_HALF_UP); + securityScoreMap.put(key, securityScore); + }); + } + + //设备维修次数(满分一百分,发生一次维修减5分) + //当天设备的维修记录 + HashMap repairMap = new HashMap<>(); + List repairLogs = repairLogMapper.selectListBySevenDay(); + repairLogs.forEach(repair -> { + repair.setRepairEndTime(repair.getRepairEndTime().substring(0, repair.getRepairEndTime().indexOf(" "))); + }); + List dateList = DateUtils.getCurrentDateDayList(); + Map> collect = repairLogs.stream().collect(Collectors.groupingBy(DeviceRepairLog::getRepairEndTime)); + collect.keySet().forEach(key -> { + List deviceRepairLogs = collect.get(key); + //开始时间到结束时间的每天都扣分 + for (DeviceRepairLog log : deviceRepairLogs) { + String startTime = log.getRepairStartTime().substring(0, log.getRepairStartTime().indexOf(" ")); + String endTime = log.getRepairEndTime().substring(0, log.getRepairStartTime().indexOf(" ")); + List betweenDays = DateUtils.getBetweenDays(startTime, endTime); + //包含首尾时间 + Collection intersection = org.apache.commons.collections4.CollectionUtils.intersection(dateList, betweenDays); + if (!CollectionUtils.isEmpty(intersection)) { + for (String date : intersection) { + if (Objects.isNull(repairMap.get(date))) { + //发生一次维修减5分 + repairMap.put(date, BigDecimal.valueOf(100 - 5)); + } else { + BigDecimal old = repairMap.get(date); + repairMap.put(date, old.subtract(BigDecimal.valueOf(5))); + } + } + } + } + }); + //构造结果 + List> resultList = new ArrayList<>(); + BigDecimal repairConfigScore = BigDecimal.valueOf(cockpitConfig.getOtherWeight().get("repair")); + BigDecimal securityConfigScore = BigDecimal.valueOf(cockpitConfig.getOtherWeight().get("security")); + if (CollectionUtils.isEmpty(securityScoreMap)) { + for (String date : dateList) { + securityScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if(CollectionUtils.isEmpty(repairMap)){ + for (String date : dateList) { + repairMap.put(date, BigDecimal.valueOf(100)); + } + } + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + //补全数据处理 + if (Objects.isNull(securityScoreMap.get(date)) && Objects.isNull(repairMap.get(date))) { + //该日期2个都空 + map.put("score", "100"); + } else if (Objects.isNull(securityScoreMap.get(date)) && !Objects.isNull(repairMap.get(date))) { + //该日期securityScoreMap空,repairMap不空 + map.put("score", repairConfigScore.multiply(repairMap.get(date)).add(securityConfigScore.multiply(BigDecimal.valueOf(100))) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } else if (Objects.isNull(repairMap.get(date)) && !Objects.isNull(securityScoreMap.get(date))) { + //该日期securityScoreMap不空,repairMap空 + map.put("score", securityConfigScore.multiply(securityScoreMap.get(date)).add(repairConfigScore.multiply(BigDecimal.valueOf(100))) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } else if (!Objects.isNull(securityScoreMap.get(date)) && !Objects.isNull(repairMap.get(date))) { + //该日期2个都不空 + BigDecimal securityScoreDecimal = securityConfigScore.multiply(securityScoreMap.get(date)); + BigDecimal repairDecimal = repairConfigScore.multiply(repairMap.get(date)); + map.put("score", securityScoreDecimal.add(repairDecimal) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } + resultList.add(map); + }); + return ResponseData.success(resultList); + } + + private List> getForResult(List weekCaseDTOS, List weekCaseKeyAreaDTOS, + List caseInfos, HashMap weekCaseMap, HashMap caseScoreMap, + HashMap keyAreaScoreMap, HashMap assessScoreMap, + List dateList){ + Map keyAreaWeight = cockpitConfig.getKeyAreaWeight(); + weekCaseKeyAreaDTOS.forEach(dto -> { + weekCaseMap.put(dto.getDimension(), BigDecimal.valueOf(dto.getQuantity())); + }); + weekCaseDTOS.forEach(dto -> { + String date = dto.getDimension(); + Integer quantity = dto.getQuantity(); + //无重点区域事件数据,1-安防事件次数/所有安防事件次数=1 + if (Objects.isNull(weekCaseMap.get(date)) || weekCaseMap.get(date).equals(BigDecimal.ZERO)) { + caseScoreMap.put(date, BigDecimal.valueOf(1 * 100)); + } else { + BigDecimal multiply = BigDecimal.valueOf(quantity).subtract(weekCaseMap.get(date)).divide(BigDecimal.valueOf(quantity), 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + caseScoreMap.put(date, multiply); + } + }); + + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + caseInfos.forEach(caseInfo -> { + //重点区域安防事态评估分数 + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double keyAreaScore = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String dayTime = caseInfo.getHappenTime().substring(0, caseInfo.getHappenTime().indexOf(" ")); + BigDecimal preScore; + if (keyAreaScoreMap.containsKey(dayTime)) { + preScore = keyAreaScoreMap.get(dayTime); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(keyAreaScore.toString()); + keyAreaScoreMap.put(dayTime, preScore.subtract(nowScore)); + + //安防机动支援力量响应评估分数 + //扣分=事件级别权重*未解决小时数 + Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); + Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); + long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); + Double assessScore = Double.valueOf(hazardWeight) * between; + BigDecimal preAssessScore; + if (assessScoreMap.containsKey(dayTime)) { + preAssessScore = assessScoreMap.get(dayTime); + } else { + preAssessScore = new BigDecimal("100.0"); + } + BigDecimal nowAssessScore = new BigDecimal(assessScore.toString()); + assessScoreMap.put(dayTime, preAssessScore.subtract(nowAssessScore)); + }); + //构造结果 + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(caseScoreMap)) { + for (String date : dateList) { + caseScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if (CollectionUtils.isEmpty(keyAreaScoreMap)) { + for (String date : dateList) { + keyAreaScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if (CollectionUtils.isEmpty(assessScoreMap)) { + for (String date : dateList) { + assessScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + BigDecimal preCaseScore = Objects.isNull(caseScoreMap.get(date)) ? BigDecimal.valueOf(100) : caseScoreMap.get(date); + BigDecimal preKeyAreaScore = Objects.isNull(keyAreaScoreMap.get(date)) ? BigDecimal.valueOf(100) : keyAreaScoreMap.get(date); + BigDecimal preAssessScore = Objects.isNull(assessScoreMap.get(date)) ? BigDecimal.valueOf(100) : assessScoreMap.get(date); + BigDecimal caseScore = preCaseScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("case"))); + BigDecimal keyAreaScore = preKeyAreaScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("keyArea"))); + BigDecimal responseAssessScore = preAssessScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("responseAssess"))); + map.put("score", caseScore.add(keyAreaScore).add(responseAssessScore).stripTrailingZeros().toPlainString()); + resultList.add(map); + }); + return resultList; + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java index decc60c..2c66ec1 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java @@ -96,7 +96,10 @@ JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人员失败,海康response:{}", resultStr); - return ResponseData.error("单个添加人员失败"); + if("0x00052301".equals(resultJson.get("code"))){ + return ResponseData.error("添加人员身份证号重复!"); + } + return ResponseData.error("单个添加人员失败!"); } JSONObject data = (JSONObject)resultJson.get("data"); String faceId = data.getString("faceId"); @@ -129,13 +132,11 @@ String body = JSONObject.toJSONString(personSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.PERSON_SINGLE_UPDATE, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); + //海康该接口成功返回data为空 if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个修改人员失败,海康response:{}", resultStr); return ResponseData.error("单个修改人员失败"); } - JSONObject data = (JSONObject)resultJson.get("data"); - String faceId = data.getString("faceId"); - staffInfo.setStaffFaceId(faceId); if(staffInfoMapper.updateById(staffInfo) > 0){ return ResponseData.success(); } @@ -265,6 +266,7 @@ @Override public StaffInfo selectStaffInfoByCode(StaffInfo staffInfo) { StaffInfo info = staffInfoMapper.selectByCode(staffInfo.getStaffCode()); + info.setPicture(getPictureFromHik(staffInfo.getStaffCode())); return info; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java index 316188e..71d587d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java @@ -22,4 +22,11 @@ boolean insertCaseInfoBatch(List caseInfos); List caseInfoList(CaseInfoRequest caseInfoRequest); + + List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest); + + Object caseInfoLastByDrawNo(String drawNo); + + int updateAllStatus(); + } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java index b3d1968..7a7fe8a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java @@ -2,6 +2,10 @@ import com.alibaba.fastjson.JSONArray; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import java.util.HashMap; import java.util.List; @@ -13,4 +17,32 @@ */ public interface CockpitService { HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap); + + Object buildingNumberPerHour(); + + Object visitorTodayNumber(); + + Object deviceNumber(); + + Object securityNumber(); + + Object visitorApplyDetail(); + + Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO); + + Object eventCategoryStatistics(); + + Object fireEquipStatistics(); + + Object beOnDutyRatio(); + + Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO); + + Object securityScore(SecurityScoreDTO securityScoreDTO); + + Object securityFrequency(); + + Object areaScore(SecurityScoreDTO securityScoreDTO); + + Object heatMap(HeatMapDTO heatMapDTO); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java new file mode 100644 index 0000000..178b909 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.service; + +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; + +/** + * @Description: + * @Author: wangpeng + * @Date: 2022/10/11 9:10 + */ +public interface PropertyManageService { + Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO); + + Object keyAreaData(String dimension); + + Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO); + + Object attendanceNumber(String dimension); + + Object securityAssessment(String dimension); + + Object keyAreaStatistic(); + + Object responseAssess(); + + Object hazardLevelStatistics(String dimension); + + Object securityRank(); + + Object securityLevelAssess(); + + Object commute(); + + Object keyArea(); + + Object visitor(); + + Object security(); + + Object patrol(); + + Object other(); +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java index ea6b8c0..2580187 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java @@ -17,6 +17,7 @@ import com.casic.missiles.modular.service.BlackInfoService; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -70,11 +71,17 @@ faceInfo.setCertificateNum(blackInfo.getIdCardNo()); faceSingleAddOrUpdateRequest.setFaceInfo(faceInfo); FacePic facePic = new FacePic(); - facePic.setFaceBinaryData(blackInfo.getPicture()); - faceSingleAddOrUpdateRequest.setFacePic(facePic); + String picture = blackInfo.getPicture(); + if(StringUtils.isNotEmpty(picture)){ + String substringPicture = picture.substring(picture.indexOf(",") + 1); + facePic.setFaceBinaryData(substringPicture); + } faceSingleAddOrUpdateRequest.setFacePic(facePic); String body = JSONObject.toJSONString(faceSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.FACE_SINGLE_ADDITION, body); + log.info("-----------------------"); + log.info("增加黑名单人脸请求body,{}", body); + log.info("增加黑名单人脸resultStr:{}", JSONObject.toJSONString(resultStr)); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人脸失败,海康response:{}", resultStr); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java index 6b03d8b..1c34f68 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java @@ -2,17 +2,22 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.dao.CaseInfoMapper; import com.casic.missiles.modular.dao.CategoryLevelMapper; +import com.casic.missiles.modular.dao.DeviceInfoMapper; import com.casic.missiles.modular.dao.HazardLevelMapper; import com.casic.missiles.modular.dto.CaseInfoRequest; import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.model.CaseInfo; +import com.casic.missiles.modular.model.DeviceInfo; import com.casic.missiles.modular.service.CaseInfoService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,6 +31,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; /** * @Description: 安防事件service @@ -50,6 +56,9 @@ @Resource private AbstractDictService dictService; + @Resource + private DeviceInfoMapper deviceInfoMapper; + @Override public List caseInfoListPage(Page page, CaseInfoRequest caseInfoRequest) { try { @@ -136,17 +145,69 @@ @Override public List caseInfoList(CaseInfoRequest caseInfoRequest) { try { - List pageList = caseInfoMapper.getCaseInfoList(caseInfoRequest); - pageList.forEach(caseInfo ->{ + List list = caseInfoMapper.getCaseInfoList(caseInfoRequest); + list.forEach(caseInfo ->{ caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); }); - return pageList; + return list; } catch (DataAccessException ex) { log.error("安防事件: 查询不分页出现异常, 异常:{}", ex); } return null; } + + @Override + public List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest) { + try { + List list = caseInfoMapper.getCaseInfoListUnResolved(caseInfoRequest); + list.forEach(caseInfo ->{ + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + }); + return list; + } catch (DataAccessException ex) { + log.error("未解决/解决中安防事件: 查询不分页出现异常, 异常:{}", ex); + } + return null; + } + + @Override + public Object caseInfoLastByDrawNo(String drawNo) { + //图纸编号和设备编号一一对应 + QueryWrapper dWrapper = new QueryWrapper<>(); + dWrapper.eq("draw_no", drawNo); + DeviceInfo deviceInfo = deviceInfoMapper.selectOne(dWrapper); + if(Objects.isNull(deviceInfo)){ + return ResponseData.error("该图纸编号下不存在关联的设备"); + } + if(StringUtils.isEmpty(deviceInfo.getDevCode())){ + return ResponseData.error("该图纸编号下不存在对应的设备编号"); + }else{ + String devCode = deviceInfo.getDevCode(); + QueryWrapper cWrapper = new QueryWrapper<>(); + cWrapper.eq("device_code", devCode); + List caseInfos = caseInfoMapper.selectList(cWrapper); + if(CollectionUtil.isEmpty(caseInfos)){ + return ResponseData.error("该图纸编号下不存在最近发生的事件"); + } + CaseInfo caseInfo = caseInfos.get(caseInfos.size() - 1); + caseInfo.setDrawNo(deviceInfo.getDrawNo()); + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + return ResponseData.success(caseInfo); + } + } + + @Override + public int updateAllStatus() { + int upflag = caseInfoMapper.updateAllStatus(); + return upflag; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java index 7402991..7fb5a6e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java @@ -4,15 +4,34 @@ import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.*; import com.casic.missiles.modular.enums.HikUri; +import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.redis.RedisUtil; +import com.casic.missiles.modular.redis.key.CacheKeys; import com.casic.missiles.modular.service.CockpitService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import java.text.MessageFormat; +import java.text.NumberFormat; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.*; +import java.util.stream.Collectors; /** * @Description: @@ -22,6 +41,28 @@ @Slf4j @Service public class CockpitServiceImpl implements CockpitService { + @Autowired + private StatisticNumberMapper numberMapper; + @Autowired + private AbstractDictService dictService; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private DeviceInfoMapper deviceInfoMapper; + @Autowired + private FireEquipInfoMapper fireEquipInfoMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private VisitorApplyMapper applyMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private RedisUtil redisUtil; @Override public HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap) { @@ -106,4 +147,512 @@ }); return resultMap; } + + @Override + public Object buildingNumberPerHour() { + //当天按小时分组的人数 + List list = numberMapper.selectListByTime(); + Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); + //定时任务中已将每小时三栋楼人数存到数据库 + //将一期主楼和录制楼人数合并,二期单算 + List> resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List buildingNumberDTOS = collect.get(key); + BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); + BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); + BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); + HashMap resultMap = new HashMap<>(); + Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); + Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); + resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); + resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); + resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); + resultList.add(resultMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object visitorTodayNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); + List visitInfos = visitInfoMapper.selectList(wrapper); + HashMap resultMap = new HashMap<>(); + resultMap.put("今日访客量", visitInfos.size()); + return ResponseData.success(resultMap); + } + + @Override + public Object deviceNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + Integer total = deviceInfoMapper.selectCount(wrapper); + QueryWrapper wrapper1 = new QueryWrapper<>(); + wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 + Integer online = deviceInfoMapper.selectCount(wrapper1); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) online / (float) total * 100); + HashMap resultMap = new HashMap<>(); + resultMap.put("设备总数", total); + resultMap.put("设备在线率", result + "%"); + return ResponseData.success(resultMap); + } + + @Override + public Object securityNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) leave / (float) total * 100); + HashMap resultMap = new HashMap<>(); + if (0 == total) { + resultMap.put("安保人员总数", 0); + resultMap.put("安保人员离岗率", "0"); + } else { + resultMap.put("安保人员总数", total); + resultMap.put("安保人员离岗率", result + ""); + } + return ResponseData.success(resultMap); + } + + @Override + public Object visitorApplyDetail() { + List reasonGroup = applyMapper.selectByVisitReason(); + List resultList = new ArrayList<>(); + //空数据处理 + List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); + if (CollectionUtils.isEmpty(reasonGroup)) { + for (Dict dict : visitReason) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(dict.getName()); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); + if (0 == sum) { + return ResponseData.success(); + } + reasonGroup.forEach(group -> { + String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(group.getQuantity()); + applyReasonGroupDTO.setVisitReason(reasonName); + applyReasonGroupDTO.setRatio(result + "%"); + resultList.add(applyReasonGroupDTO); + }); + //返回数据补全处理 + if (resultList.size() < visitReason.size()) { + List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); + for (Dict dict : visitReason) { + String name = dict.getName(); + if (!collect.contains(name)) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(name); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO) { + //查询各危险级别权重name,用于构造返回结构 + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); + + Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); + List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(list)) { + Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + //查询数据,放入redis + List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); + Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //设置过期时间为每月1号0点 + LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) + .withMinute(0).withSecond(0).withNano(0); + long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); + redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + + @Override + public Object eventCategoryStatistics() { + List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); + return ResponseData.success(categoryLevelGroup); + } + + @Override + public Object fireEquipStatistics() { + List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); + //空数据处理 + List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); + if (CollectionUtils.isEmpty(equipTypeGroup)) { + for (Dict dict : equipType) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + return ResponseData.success(equipTypeGroup); + } + equipTypeGroup.forEach(group -> { + String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); + group.setEquipTypeName(equipTypeName); + }); + //返回数据补全处理 + if (equipTypeGroup.size() < equipType.size()) { + List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); + for (Dict dict : equipType) { + String code = dict.getCode(); + if (!collect.contains(code)) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + } + } + return ResponseData.success(equipTypeGroup); + } + + @Override + public Object beOnDutyRatio() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + if (0 == total) { + return ResponseData.success(null); + } + List currentDateHourList = DateUtils.getCurrentDateWorkHourList(); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + //补全空数据 + if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { + for (String date : currentDateHourList) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + return ResponseData.success(onDutyRatioDTOS); + } + onDutyRatioDTOS.forEach(dto -> { + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); + dto.setRatio(result + "%"); + }); + //补全空数据 + List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); + for (String date : currentDateHourList) { + if (!collect.contains(date)) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + } + return ResponseData.success(onDutyRatioDTOS); + } + + @Override + public Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO) { + List gateStatusGroup = null; + //2代表所有摄像头(对应字典2-7) + if ("2".equals(gateStatusGroupDTO.getDevType())) { + gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); + } else { + gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); + } + HashMap resultMap = new HashMap<>(); + //空数据处理 + List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); + if (CollectionUtils.isEmpty(gateStatusGroup)) { + List resultList = new ArrayList<>(); + for (Dict dict : deviceStatus) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + resultMap.put("total", 0); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("无该类设备信息"); + } + List resultList = new ArrayList<>(); + gateStatusGroup.forEach(group -> { + if ("2".equals(gateStatusGroupDTO.getDevType())) { + group.setDevType("2"); + } + String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(devStatus); + gateStatusGroupResponse.setRatio(result + "%"); + gateStatusGroupResponse.setQuantity(group.getQuantity()); + resultList.add(gateStatusGroupResponse); + }); + //返回数据补全处理 + if (resultList.size() < deviceStatus.size()) { + List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); + for (Dict dict : deviceStatus) { + String name = dict.getName(); + if (!collect.contains(name)) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + } + } + resultMap.put("total", sum); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + + @Override + public Object securityScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的position划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + List caseInfos = caseInfoMapper.selectByPosition(position); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //楼栋-评分实体map + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + Map resultMap = new HashMap<>(); + //空数据处理 + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + resultMap.put(dict.getName(), 100.0); + } + return ResponseData.success(resultMap); + } + + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + + collect.keySet().forEach(key -> { + List list = collect.get(key); + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); + resultMap.put(dictValue, 100 - collect1.getSum()); + }); + //返回数据补全处理 + if (collect.size() < devicePosition.size()) { + Set strings = resultMap.keySet(); + for (Dict dict : devicePosition) { + String name = dict.getName(); + if (!strings.contains(name)) { + resultMap.put(dict.getName(), 100.0); + } + } + } + //按楼层分组计算评分 +// collect.keySet().forEach(key -> { +// Map map = new HashMap<>(); +// List securityScoreDTOS = collect.get(key); +// //楼层-评分map +// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); +// collect1.keySet().forEach(key1 -> { +// map.put(key1, 100 - collect1.get(key1)); +// }); +// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); +// resultMap.put(dictValue, map); +// }); + return ResponseData.success(resultMap); + } + + @Override + public Object securityFrequency() { + String year = String.valueOf(DateUtil.thisYear()); + String month = String.valueOf(DateUtil.thisMonth()); + Integer quantity = caseInfoMapper.selectCountByMonth(year, month); + SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); + securityFrequencyDTO.setQuantity(quantity); + securityFrequencyDTO.setYear(year); + securityFrequencyDTO.setMonth(month); + return ResponseData.success(securityFrequencyDTO); + } + + @Override + public Object areaScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的area划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + String area = securityScoreDTO.getArea(); + if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { + return null; + } + Map resultMap = new HashMap<>(); + List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); + if (Objects.isNull(caseInfos)) { + resultMap.put("安防评分", 100.0); + return ResponseData.success(resultMap); + } + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + resultMap.put("安防评分", 100 - collect.getSum()); + return ResponseData.success(resultMap); + } + + @Override + public Object heatMap(HeatMapDTO heatMapDTO) { + if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { + heatMapDTO.setMinute(3); + } + List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); + Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); + HashMap resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect)) { + return ResponseData.success(); + } + collect.keySet().forEach(key -> { + resultMap.put(key, collect.get(key).size()); + }); + return ResponseData.success(resultMap); + } + + private List> getResultMap(List nameList, List> resultList, Map> resultMap) { + resultMap.keySet().forEach(key -> { + List monthAndLevelGroupDTOS = resultMap.get(key); + HashMap hashMap = new HashMap<>(); + for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { +// hashMap.put("年份", andLevelGroupDTO.getYear()); + hashMap.put("月份", /*andLevelGroupDTO.getYear() + "-" + */Integer.valueOf(andLevelGroupDTO.getMonth())); + hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); + } + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + }); + //12个月份,用于构造返回结构 + List list1 = new ArrayList<>(); + for (Map map : resultList) { + list1.add(String.valueOf(map.get("月份"))); + } + for (int i = 1; i < 13; i++) { + if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { + continue; + } + HashMap hashMap = new HashMap<>(); + hashMap.put("月份", i); + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + } + List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); + return results; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java index 94308db..f91d7bd 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java @@ -427,6 +427,13 @@ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("draw_no", drawNo); DeviceInfo deviceInfo = deviceInfoMapper.selectOne(wrapper); + if(!Objects.isNull(deviceInfo)){ + deviceInfo.setDevTypeName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_TYPE, deviceInfo.getDevType())); + deviceInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, deviceInfo.getStatus())); + deviceInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, deviceInfo.getPosition())); + deviceInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, deviceInfo.getArea())); + deviceInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, deviceInfo.getIsKeyArea())); + } return deviceInfo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java index 8ed53d9..c399a7f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java @@ -11,6 +11,7 @@ import com.casic.missiles.modular.service.HikService; import com.casic.missiles.modular.system.model.Dict; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -50,8 +51,11 @@ @Override public CaseInfo blackListHandle(JSONObject event, CaseInfo caseInfo) { - String srcIndex = event.getString("srcIndex"); //海康资源唯一标识 + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 String happenTimeISO = String.valueOf(event.get("happenTime")); + DateTime parse = DateUtil.parse(happenTimeISO); String happenTime = DateUtil.formatDateTime(parse); caseInfo.setHappenTime(happenTime); //发生时间 @@ -89,6 +93,16 @@ log.info("接收到离岗事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //离岗事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray leavePosition = data.getJSONArray("leavePosition"); + if(StringUtils.isNotEmpty(leavePosition.getString(0))){ + JSONObject jsonObject = leavePosition.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -115,6 +129,16 @@ log.info("接收到人员聚集事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //人员聚集事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray group = data.getJSONArray("group"); + if(StringUtils.isNotEmpty(group.getString(0))){ + JSONObject jsonObject = group.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -263,8 +287,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void propertyAttendanceHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); @@ -309,8 +334,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void securityPersonnelHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java new file mode 100644 index 0000000..4427f19 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java @@ -0,0 +1,1255 @@ +package com.casic.missiles.modular.service.impl; + +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.config.CockpitConfig; +import com.casic.missiles.modular.dao.*; +import com.casic.missiles.modular.dto.statistics.*; +import com.casic.missiles.modular.enums.SecurityEventDict; +import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.service.PropertyManageService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.text.NumberFormat; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @Description: 驾驶舱二级页面-物管信息 + * @Author: wangpeng + * @Date: 2022/10/11 9:11 + */ +@Slf4j +@Service +public class PropertyManageServiceImpl implements PropertyManageService { + @Autowired + private AttendanceInfoMapper attendanceInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private DeviceRepairLogMapper repairLogMapper; + @Autowired + private CockpitConfig cockpitConfig; + @Autowired + private AbstractDictService dictService; + + @Override + public Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO) { + //各类型员工及总数 + List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); + Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); + + String dateDimension = attendanceRatioDTO.getDateDimension(); + List attendanceRatioDTOS = new ArrayList<>(); + List dateList = null; + //考勤的人数,按单次考勤过滤 + if ("week".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); + dateList = DateUtils.getCurrentDateDayList(); + } else if ("month".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); + dateList = DateUtils.getCurrentDateWeekList(); + } else if ("year".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); + dateList = DateUtils.getCurrentDateMonthList(); + } + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { + for (String date : dateList) { + HashMap hashMap = new HashMap<>(); + hashMap.put("date", date); + hashMap.put("property", "0%"); + hashMap.put("security", "0%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + //计算出勤率 + Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); + + dateList.forEach(date -> { + HashMap hashMap = new HashMap<>(); + if (CollectionUtils.isEmpty(dateMap.get(date))) { + hashMap.put("date", date); + hashMap.put("property", "0%"); + hashMap.put("security", "0%"); + resultList.add(hashMap); + } else { + List attendances = dateMap.get(date); + attendances.forEach(attendanceRatio -> { + attendanceRatio.setDateDimension(dateDimension); + attendanceRatio.setStaffType(attendanceRatio.getStaffType()); + List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); + String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); + attendanceRatio.setAttendanceRatio(ratio + "%"); + //构造返回结构 + hashMap.put("date", attendanceRatio.getDate()); +// String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); + if ("1".equals(attendanceRatio.getStaffType())) { + hashMap.put("property", attendanceRatio.getAttendanceRatio()); + } + if ("2".equals(attendanceRatio.getStaffType())) { + hashMap.put("security", attendanceRatio.getAttendanceRatio()); + } + }); + //补全缺少数据 + if (1 == attendances.size()) { + AttendanceRatioDTO attendanceRatioDTO1 = attendances.get(0); + if ("1".equals(attendanceRatioDTO1.getStaffType())) { + hashMap.put("security", "0%"); + } + if ("2".equals(attendanceRatioDTO1.getStaffType())) { + hashMap.put("property", "0%"); + } + } + resultList.add(hashMap); + } + }); + return ResponseData.success(resultList); + + } + + @Override + public Object keyAreaData(String dimension) { + List resultList = null; + List dateList = null; + if ("year".equals(dimension)) { + //近365天数据按月分组统计 + resultList = caseInfoMapper.selectPreMonthCountByNearYear(); + dateList = DateUtils.getCurrentDateMonthList(); + } else if ("month".equals(dimension)) { + //近30天数据按周分组统计 + resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); + dateList = DateUtils.getCurrentDateWeekList(); + } else if ("week".equals(dimension)) { + //近7天数据按天分组统计 + resultList = caseInfoMapper.selectPreDayCountBySevenDay(); + dateList = DateUtils.getCurrentDateDayList(); + } + //补全空数据处理 + if (CollectionUtils.isEmpty(resultList)) { + for (String date : dateList) { + PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); + preMonthOrWeekCaseDTO.setDimension(date); + preMonthOrWeekCaseDTO.setQuantity(0); + resultList.add(preMonthOrWeekCaseDTO); + } + } else { + for (String date : dateList) { + List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); + if (!collect.contains(date)) { + PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); + preMonthOrWeekCaseDTO.setDimension(date); + preMonthOrWeekCaseDTO.setQuantity(0); + resultList.add(preMonthOrWeekCaseDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { + String year = avgMonthAndWeekGroupDTO.getYear(); + List monthList = caseInfoMapper.selectPreMonthCountByYear(year); + Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); + HashMap strAvgMap = new HashMap<>(); + List resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List preMonthOrWeekCaseDTOS = collect.get(key); + int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); + //若年份是本年,则使用各安防级别数量/当前月份数 + //若不是本年,除数为12 + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + if (year.equals(String.valueOf(DateUtil.thisYear()))) { + monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); + strAvgMap.put(key, monthAndWeekDTO); + } else { + monthAndWeekDTO.setMonthQuantity(sum / 12); + strAvgMap.put(key, monthAndWeekDTO); + } + } + + List weekList = caseInfoMapper.selectPreWeekCountByYear(year); + Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); + for (String key : collect1.keySet()) { + List preMonthOrWeekCaseDTOS = collect.get(key); + int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); + if (year.equals(String.valueOf(DateUtil.thisYear()))) { + if (!Objects.isNull(strAvgMap.get(key))) { + MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); + strAvgMap.put(key, monthAndWeekDTO); + } else { + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); + strAvgMap.put(key, monthAndWeekDTO); + } + } else { + if (!Objects.isNull(strAvgMap.get(key))) { + MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / 52); + strAvgMap.put(key, monthAndWeekDTO); + } else { + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / 52); + strAvgMap.put(key, monthAndWeekDTO); + } + } + } + strAvgMap.keySet().forEach(key -> { + resultList.add(strAvgMap.get(key)); + }); + //输出顺序 + Collections.swap(resultList, 1, 2); + return ResponseData.success(resultList); + } + + @Override + public Object attendanceNumber(String dimension) { + List attendanceNumberDTOs = null; + List> resultList = new ArrayList<>(); + List dateList = new ArrayList<>(); + if ("week".equals(dimension)) { + //近7天数据按天分组统计 + attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); + dateList = DateUtils.getCurrentDateDayList(); + } else if ("day".equals(dimension)) { + //今天数据按小时分组统计 + attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); + dateList = DateUtils.getCurrentDateWorkHourList(); + } + if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { + for (String date : dateList) { + HashMap hashMap = new HashMap<>(); + hashMap.put("staticTime", date); + hashMap.put("1", "0"); + hashMap.put("2", "0"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); + if ("day".equals(dimension)) { + collect = collect.entrySet().stream().collect(Collectors.toMap(m -> m.getKey().substring(5) + ":00", Map.Entry::getValue)); + } + + for (String date : dateList) { + Map resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect.get(date))) { + resultMap.put("1", "0"); + resultMap.put("2", "0"); + resultMap.put("staticTime", date); + resultList.add(resultMap); + } else { + List attendanceNumberDTOS = collect.get(date); +// Map resultMap = new HashMap<>(); + AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); + if (attendanceNumberDTOS.size() >= 2) { + AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); + resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); + } + resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); + resultMap.put("staticTime", date); + resultList.add(resultMap); + //补全map缺少数据 + if (!resultMap.containsKey("1")) { + resultMap.put("1", "0"); + } + if (!resultMap.containsKey("2")) { + resultMap.put("2", "0"); + } + } + } + +// +// collect.keySet().forEach(key -> { +// List attendanceNumberDTOS = collect.get(key); +// Map resultMap = new HashMap<>(); +// AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); +// if (attendanceNumberDTOS.size() >= 2) { +// AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); +// resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); +// } +// resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); +// resultMap.put("staticTime", attendanceNumberDTO.getDate().substring(5) + ":00"); +// resultList.add(resultMap); +// }); +// //补全空数据处理 +// if (CollectionUtils.isEmpty(resultList)) { +// for (String date : dateList) { +// Map resultMap = new HashMap<>(); +// resultMap.put("1", "0"); +// resultMap.put("2", "0"); +// resultMap.put("staticTime", date); +// resultList.add(resultMap); +// } +// } else { +// List collectList = new ArrayList<>(); +// for (Map map : resultList) { +// String staticTime = map.get("staticTime"); +// collectList.add(staticTime); +// //补全map缺少数据 +// if (!map.containsKey("1")) { +// map.put("1", "0"); +// } +// if (!map.containsKey("2")) { +// map.put("2", "0"); +// } +// } +// for (String date : dateList) { +// if (!collectList.contains(date)) { +// Map resultMap = new HashMap<>(); +// resultMap.put("1", "0"); +// resultMap.put("2", "0"); +// resultMap.put("staticTime", date); +// resultList.add(resultMap); +// } +// } +// } + return ResponseData.success(resultList); + } + + @Override + public Object securityAssessment(String dimension) { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + if ("week".equals(dimension)) { + //近7天早晚高峰数据 + List caseInfos = caseInfoMapper.selectListBySevenDay(); + //按时间(天)进行分组 + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(" "); + String dayTime = array[0]; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } else if ("day".equals(dimension)) { + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDatePeakHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + + } + return null; + } + + @Override + public Object keyAreaStatistic() { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday2(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + dayTime = dayTime.substring(5) + ":00"; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } + + @Override + public Object responseAssess() { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday3(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + //扣分=事件级别权重*未解决小时数 + Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); + Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); + long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); + Double score = Double.valueOf(hazardWeight) * between; + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + dayTime = dayTime.substring(5) + ":00"; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } + + @Override + public Object hazardLevelStatistics(String dimension) { + List hazardLevelGroup = null; + if ("week".equals(dimension)) { + hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); + } else if ("month".equals(dimension)) { + hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); + } + if (CollectionUtils.isEmpty(hazardLevelGroup)) { + log.info("重点区域威胁事件类型统计,无安防事件"); + return ResponseData.error("无安防事件发生!"); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("安防事件总数为0"); + } + hazardLevelGroup.forEach(group -> { + CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); + group.setLevelName(caseHazardLevel.getName()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + group.setLevelRatio(result + "%"); + }); + HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); + hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); + hazardLevelGroupResponse.setQuantity(sum); + return ResponseData.success(hazardLevelGroupResponse); + } + + @Override + public Object securityRank() { + //考勤表近一个月按人员分组的考勤个数前十名 + List list = attendanceInfoMapper.getCountForRank(); + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(list)) { + //补全空数据处理 + List staffList = staffInfoMapper.selectListLimitTen(); + for (StaffInfo staffInfo : staffList) { + HashMap hashMap = new HashMap<>(); + hashMap.put(staffInfo.getStaffName(), "0%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + //构造返回结构 + for (SecurityRankDTO dto : list) { + // TODO: 2022/9/15 分母使用30,后续看产品定义 + HashMap hashMap = new HashMap<>(); + String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); + hashMap.put("name", dto.getStaffName()); + hashMap.put("ratio", result + "%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object securityLevelAssess() { + //今天数据按小时分组统计 + List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + if (CollectionUtils.isEmpty(resultList)) { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); + levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); + levelAssessDTO.setDate(date); +// levelAssessDTO.setQuantity(); + resultList.add(levelAssessDTO); + } + return ResponseData.success(resultList); + } + resultList.forEach(result -> { + result.setDate(result.getDate().substring(5) + ":00"); + BigDecimal deScore = new BigDecimal(result.getQuantity()); + BigDecimal preScore = new BigDecimal("100.0"); + result.setScore(preScore.subtract(deScore).doubleValue()); + }); + //数据补全处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + for (SecurityLevelAssessDTO levelAssessDTO : resultList) { + String substring = levelAssessDTO.getDate().substring(5) + ":00"; + if (!substring.equals(date)) { + SecurityLevelAssessDTO levelAssess = new SecurityLevelAssessDTO(); + levelAssess.setScore(new BigDecimal("100.0").doubleValue()); + levelAssess.setDate(date); + resultList.add(levelAssess); + break; + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object commute() { + //早晚高峰区域安防评估 + ResponseData assessResultJson = (ResponseData) this.securityAssessment("week"); + if (Objects.isNull(assessResultJson) || 200 != assessResultJson.getCode()) { + return assessResultJson; + } + JSONArray assessData = JSONArray.parseArray(JSON.toJSONString(assessResultJson.getData())); + //所有类型的员工出勤 + List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); + long sum = staffTypeAndSumDTOS.stream().collect(Collectors.summarizingInt(StaffTypeAndSumDTO::getSum)).getSum(); + List countByTypeAndDateForWeek = attendanceInfoMapper.getCountByTypeAndDateForWeek(); + Map> dateMap = countByTypeAndDateForWeek.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); + HashMap attendanceMap = new HashMap<>(); + dateMap.keySet().forEach(key -> { + List attendanceRatioDTOS = dateMap.get(key); + //当天所有类型的员工的出勤人数 + long sum1 = attendanceRatioDTOS.stream().collect(Collectors.summarizingInt(AttendanceRatioDTO::getQuantity)).getSum(); + //出勤占比评分 + Double attendanceRatio = ((float) sum1 / (float) sum) * 100 * cockpitConfig.getCommuteWeight(); + attendanceMap.put(key, attendanceRatio); + }); + //构造结果 + List> resultList = new ArrayList<>(); + Iterator iterator = assessData.stream().iterator(); + while (iterator.hasNext()) { + JSONObject next = (JSONObject) iterator.next(); + String date = next.getString("date"); + HashMap map = new HashMap<>(); + //计算评分 + Double assessRatio = next.getInteger("score") * (1 - cockpitConfig.getCommuteWeight()); + NumberFormat numberFormat = NumberFormat.getInstance(); + numberFormat.setMaximumFractionDigits(2); + if (!Objects.isNull(attendanceMap.get(date))) { + Double attendanceRatio = attendanceMap.get(date); + Double r = assessRatio + attendanceRatio; + map.put("score", numberFormat.format(r)); + } else { + //无员工出勤率(出勤为0),只有安防评估分值 + map.put("score", numberFormat.format(assessRatio)); + } + map.put("date", date); + resultList.add(map); + } + return ResponseData.success(resultList); + } + + @Override + public Object keyArea() { + //1-重点区域安防事件次数/所有安防事件次数 + //获取近7天每天的安防事件个数,所有和重点区域 + List weekCaseDTOS = caseInfoMapper.selectPreDayCountBySevenDay(); + List weekCaseKeyAreaDTOS = caseInfoMapper.selectPreDayCountBySevenDayKeyArea(); + List caseInfos = caseInfoMapper.selectListBySevenDayKeyArea(); + HashMap weekCaseMap = new HashMap<>(); + HashMap caseScoreMap = new HashMap<>(); + HashMap keyAreaScoreMap = new HashMap<>(); + HashMap assessScoreMap = new HashMap<>(); + List dateList = DateUtils.getCurrentDateDayList(); + List> result = getForResult(weekCaseDTOS, weekCaseKeyAreaDTOS, caseInfos, weekCaseMap, caseScoreMap, + keyAreaScoreMap, assessScoreMap, dateList); + + //上个月对应数据 + List beforeMonthKeyAreaCaseDTOS = caseInfoMapper.selectPreDayCountByBeforeMonthKeyArea(); + List beforeMonthCaseDTOS = caseInfoMapper.selectPreDayCountByBeforeMonth(); + List beforeMonthCaseInfos = caseInfoMapper.selectListByBeforeMonthKeyArea(); + HashMap beforeMonthWeekCaseMap = new HashMap<>(); + HashMap beforeMonthCaseScoreMap = new HashMap<>(); + HashMap beforeMonthKeyAreaScoreMap = new HashMap<>(); + HashMap beforeMonthAssessScoreMap = new HashMap<>(); + List beforeMonthDateList = DateUtils.getCurrentDateDayBeforeMonthList(); + List> resultBeforeMonth = getForResult(beforeMonthCaseDTOS, beforeMonthKeyAreaCaseDTOS, beforeMonthCaseInfos, + beforeMonthWeekCaseMap, beforeMonthCaseScoreMap, beforeMonthKeyAreaScoreMap, beforeMonthAssessScoreMap, beforeMonthDateList); + //计算环比 + for (int i = 0; i < result.size(); i++) { + Map resultMap = result.get(i); + Map resultBeforeMonthMap = resultBeforeMonth.get(i); + BigDecimal resultScore = BigDecimal.valueOf(Double.valueOf(String.valueOf(resultMap.get("score")))); + BigDecimal resultBeforeMonthScore = BigDecimal.valueOf(Double.valueOf(String.valueOf(resultBeforeMonthMap.get("score")))); + BigDecimal finalResult = resultScore.subtract(resultBeforeMonthScore).divide(resultBeforeMonthScore, 2, BigDecimal.ROUND_HALF_UP); + resultMap.put("ringRatio", finalResult); + } + return ResponseData.success(result); + } + + @Override + public Object visitor() { + //查询每天的访客对应的离开记录(进入记录存在且在申请范围内) + //近7天主要使用申请离开时间(申请进入时间不会影响扣分) + List list = visitInfoMapper.selectListBySevenDay(); + list.stream().forEach(visit -> { + DateTime dateTime = DateUtil.parseDateTime(visit.getApplyOutTime()); + String formatDate = DatePattern.NORM_DATE_FORMAT.format(dateTime); + visit.setDate(formatDate); + }); + Map> dateVisitMap = list.stream().collect(Collectors.groupingBy(MultiScoreVisitorDTO::getDate)); + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + HashMap deductMap = new HashMap<>(); //扣分使用 + dateList.forEach(date -> { + //1、空数据处理 + if (CollectionUtils.isEmpty(dateVisitMap)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } else if (CollectionUtils.isEmpty(dateVisitMap.get(date))) { + //2、补全数据处理 + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } else { + //3、计算数据处理 + //计算分数(未在申请时间段内离开减分(包括无离开时间和有离开时间两种情况)、未在申请区域内离开减分),配置扣分,配置每个访客最高扣分 + List multiScoreVisitorDTOS = dateVisitMap.get(date); + //遍历访客 + for (MultiScoreVisitorDTO visitorDTO : multiScoreVisitorDTOS) { + //无离开时间 + if (StringUtils.isEmpty(visitorDTO.getOutTime())) { + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + cockpitConfig.getVisitorWeight().get("NoRecordPointDeduct")); + } else { + deductMap.put(date, cockpitConfig.getVisitorWeight().get("NoRecordPointDeduct")); + } + } else { +// DateTime applyInDateTime = DateUtil.parseDateTime(visitorDTO.getApplyInTime()); + DateTime applyOutDateTime = DateUtil.parseDateTime(visitorDTO.getApplyOutTime()); + DateTime outDateTime = DateUtil.parseDateTime(visitorDTO.getOutTime()); + //未在申请时间段离开(在申请离开时间后离开) + if (DateUtil.compare(outDateTime, applyOutDateTime) > 0) { + long betweenHour = DateUtil.between(outDateTime, applyOutDateTime, DateUnit.HOUR); + Double score = betweenHour * cockpitConfig.getVisitorWeight().get("singlePointDeduct"); + //该访客扣分到达最多分 + if (score >= cockpitConfig.getVisitorWeight().get("mostPointDeduct")) { + score = cockpitConfig.getVisitorWeight().get("mostPointDeduct"); + } + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + score); + } else { + deductMap.put(date, score); + } + } + //未在申请区域离开 + if (StringUtils.isNotEmpty(visitorDTO.getApplyVisitPosition()) && !visitorDTO.getApplyVisitPosition().equals(visitorDTO.getVisitPosition())) { + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + cockpitConfig.getVisitorWeight().get("singlePointDeduct")); + } else { + deductMap.put(date, cockpitConfig.getVisitorWeight().get("singlePointDeduct")); + } + } + + } + } + //添加到结果list + HashMap map = new HashMap<>(); + map.put("date", date); + if (!Objects.isNull(deductMap.get(date))) { + //最少0分 + if (deductMap.get(date) >= 100) { + map.put("score", 0); + } else { + map.put("score", 100 - deductMap.get(date)); + } + } else { + map.put("score", 100); + } + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object security() { + //安保人员到岗率*100*权重0.5 + //近7天安保人员到岗率 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + + List dateCountList = caseInfoMapper.selectDemobilizedCountSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap onDutyMap = new HashMap<>(); + dateCountList.forEach(dateCount -> { + //到岗率 + BigDecimal totalCount = new BigDecimal(total); + BigDecimal leaveCount = new BigDecimal(dateCount.getLeaveCount()); + BigDecimal result = totalCount.subtract(leaveCount).divide(totalCount, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + onDutyMap.put(dateCount.getDate(), result.multiply(BigDecimal.valueOf(cockpitConfig.getSecurityWeight().get("onDuty"))).setScale(2, BigDecimal.ROUND_HALF_UP)); + }); + + //安保等级评估均值*权重0.5 + List levelAssessList = caseInfoMapper.selectListByTypeSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap levelAssessMap = new HashMap<>(); + levelAssessList.forEach(levelAssess -> { + //6-23点共17小时,100-该天扣分/17 + BigDecimal deScore = new BigDecimal(levelAssess.getQuantity()); + BigDecimal preScore = new BigDecimal("100.0"); + BigDecimal divide = deScore.divide(BigDecimal.valueOf(17), 2, BigDecimal.ROUND_HALF_UP); + BigDecimal result = preScore.subtract(divide); + levelAssessMap.put(levelAssess.getDate(), result.multiply(BigDecimal.valueOf(cockpitConfig.getSecurityWeight().get("levelAssess"))).setScale(2, BigDecimal.ROUND_HALF_UP)); + }); + + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + Double onDutyWeight = cockpitConfig.getSecurityWeight().get("onDuty"); + Double levelAssessWeight = cockpitConfig.getSecurityWeight().get("levelAssess"); + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + //1、空数据处理 + if (CollectionUtils.isEmpty(onDutyMap) && CollectionUtils.isEmpty(levelAssessMap)) { + //2个map都空 + map.put("score", "100"); + resultList.add(map); + } else if (CollectionUtils.isEmpty(onDutyMap) || CollectionUtils.isEmpty(levelAssessMap)) { + //2个map有一个为空 + if (CollectionUtils.isEmpty(onDutyMap)) { + if (!Objects.isNull(levelAssessMap.get(date))) { + map.put("score", levelAssessMap.get(date).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + } else { + map.put("score", BigDecimal.valueOf(100 * levelAssessWeight).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + } + } + if (CollectionUtils.isEmpty(levelAssessMap)) { + if (!Objects.isNull(onDutyMap.get(date))) { + map.put("score", onDutyMap.get(date).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + } else { + map.put("score", BigDecimal.valueOf(100 * onDutyWeight).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + } + } + } else if (Objects.isNull(onDutyMap.get(date)) && Objects.isNull(levelAssessMap.get(date))) { + //该日期2个都空 + map.put("score", "100"); + resultList.add(map); + } else if (Objects.isNull(onDutyMap.get(date)) && !Objects.isNull(levelAssessMap.get(date))) { + //2、补全到岗率数据处理 + //该日期onDutyMap空,levelAssessMap不空 + map.put("score", levelAssessMap.get(date).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + resultList.add(map); + } else if (Objects.isNull(levelAssessMap.get(date)) && !Objects.isNull(onDutyMap.get(date))) { + //2、补全安保等级评估数据处理 + //该日期levelAssessMap空,onDutyMap不空 + map.put("score", onDutyMap.get(date).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + resultList.add(map); + } else if (!Objects.isNull(levelAssessMap.get(date)) && !Objects.isNull(onDutyMap.get(date))) { + //该日期2个都不空 + BigDecimal onDutyDecimal = onDutyMap.get(date); + BigDecimal levelAssessDecimal = levelAssessMap.get(date); + map.put("score", onDutyDecimal.add(levelAssessDecimal).stripTrailingZeros().toPlainString()); + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object patrol() { + //近7天安保人员到岗率 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + + List dateCountList = caseInfoMapper.selectDemobilizedCountSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap onDutyMap = new HashMap<>(); + dateCountList.forEach(dateCount -> { + //到岗率 + BigDecimal totalCount = new BigDecimal(total); + BigDecimal leaveCount = new BigDecimal(dateCount.getLeaveCount()); + BigDecimal result = totalCount.subtract(leaveCount).divide(totalCount, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + onDutyMap.put(dateCount.getDate(), result.stripTrailingZeros().toPlainString()); + }); + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + //1、空数据处理 + if (CollectionUtils.isEmpty(onDutyMap) || Objects.isNull(onDutyMap.get(date))) { + map.put("date", date); + map.put("score", "100"); + resultList.add(map); + } else { + map.put("date", date); + map.put("score", onDutyMap.get(date)); + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object other() { + //安全防护评分(所有楼的评分的均值) + List caseInfos = caseInfoMapper.selectByPositionSevenDay(null); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap securityScoreMap = new HashMap<>(); + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + securityScoreDTO1.setDate(caseInfo.getHappenTime().substring(0, caseInfo.getHappenTime().indexOf(" "))); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + securityScoreMap.put(dict.getName(), BigDecimal.valueOf(100)); + } + } else { + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getDate)); + collect.keySet().forEach(key -> { + List list = collect.get(key); + //该日期发生时间的楼栋 + Map> collect3 = list.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + //无评分的楼栋数据补全处理 + if (collect3.size() < devicePosition.size()) { + List collect4 = list.stream().map(SecurityScoreDTO::getPosition).collect(Collectors.toList()); + for (Dict dict : devicePosition) { + String code = dict.getCode(); + if (!collect4.contains(code)) { + SecurityScoreDTO securityScoreDTO = new SecurityScoreDTO(); + securityScoreDTO.setDate(key); + securityScoreDTO.setPosition(code); + securityScoreDTO.setScore(100.0); + list.add(securityScoreDTO); + } + } + } + //该日期所有楼栋扣分和 + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + double sum = collect1.getSum(); + //该日期发生时间的楼栋个数 + Map> collect4 = list.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + int size = collect4.keySet().size(); + //(100*发生事件的楼栋个数-扣分和)/楼栋个数 + BigDecimal securityScore = BigDecimal.valueOf(100).multiply(BigDecimal.valueOf(size)).subtract(BigDecimal.valueOf(sum)).divide(BigDecimal.valueOf(size), 2, BigDecimal.ROUND_HALF_UP); + securityScoreMap.put(key, securityScore); + }); + } + + //设备维修次数(满分一百分,发生一次维修减5分) + //当天设备的维修记录 + HashMap repairMap = new HashMap<>(); + List repairLogs = repairLogMapper.selectListBySevenDay(); + repairLogs.forEach(repair -> { + repair.setRepairEndTime(repair.getRepairEndTime().substring(0, repair.getRepairEndTime().indexOf(" "))); + }); + List dateList = DateUtils.getCurrentDateDayList(); + Map> collect = repairLogs.stream().collect(Collectors.groupingBy(DeviceRepairLog::getRepairEndTime)); + collect.keySet().forEach(key -> { + List deviceRepairLogs = collect.get(key); + //开始时间到结束时间的每天都扣分 + for (DeviceRepairLog log : deviceRepairLogs) { + String startTime = log.getRepairStartTime().substring(0, log.getRepairStartTime().indexOf(" ")); + String endTime = log.getRepairEndTime().substring(0, log.getRepairStartTime().indexOf(" ")); + List betweenDays = DateUtils.getBetweenDays(startTime, endTime); + //包含首尾时间 + Collection intersection = org.apache.commons.collections4.CollectionUtils.intersection(dateList, betweenDays); + if (!CollectionUtils.isEmpty(intersection)) { + for (String date : intersection) { + if (Objects.isNull(repairMap.get(date))) { + //发生一次维修减5分 + repairMap.put(date, BigDecimal.valueOf(100 - 5)); + } else { + BigDecimal old = repairMap.get(date); + repairMap.put(date, old.subtract(BigDecimal.valueOf(5))); + } + } + } + } + }); + //构造结果 + List> resultList = new ArrayList<>(); + BigDecimal repairConfigScore = BigDecimal.valueOf(cockpitConfig.getOtherWeight().get("repair")); + BigDecimal securityConfigScore = BigDecimal.valueOf(cockpitConfig.getOtherWeight().get("security")); + if (CollectionUtils.isEmpty(securityScoreMap)) { + for (String date : dateList) { + securityScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if(CollectionUtils.isEmpty(repairMap)){ + for (String date : dateList) { + repairMap.put(date, BigDecimal.valueOf(100)); + } + } + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + //补全数据处理 + if (Objects.isNull(securityScoreMap.get(date)) && Objects.isNull(repairMap.get(date))) { + //该日期2个都空 + map.put("score", "100"); + } else if (Objects.isNull(securityScoreMap.get(date)) && !Objects.isNull(repairMap.get(date))) { + //该日期securityScoreMap空,repairMap不空 + map.put("score", repairConfigScore.multiply(repairMap.get(date)).add(securityConfigScore.multiply(BigDecimal.valueOf(100))) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } else if (Objects.isNull(repairMap.get(date)) && !Objects.isNull(securityScoreMap.get(date))) { + //该日期securityScoreMap不空,repairMap空 + map.put("score", securityConfigScore.multiply(securityScoreMap.get(date)).add(repairConfigScore.multiply(BigDecimal.valueOf(100))) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } else if (!Objects.isNull(securityScoreMap.get(date)) && !Objects.isNull(repairMap.get(date))) { + //该日期2个都不空 + BigDecimal securityScoreDecimal = securityConfigScore.multiply(securityScoreMap.get(date)); + BigDecimal repairDecimal = repairConfigScore.multiply(repairMap.get(date)); + map.put("score", securityScoreDecimal.add(repairDecimal) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } + resultList.add(map); + }); + return ResponseData.success(resultList); + } + + private List> getForResult(List weekCaseDTOS, List weekCaseKeyAreaDTOS, + List caseInfos, HashMap weekCaseMap, HashMap caseScoreMap, + HashMap keyAreaScoreMap, HashMap assessScoreMap, + List dateList){ + Map keyAreaWeight = cockpitConfig.getKeyAreaWeight(); + weekCaseKeyAreaDTOS.forEach(dto -> { + weekCaseMap.put(dto.getDimension(), BigDecimal.valueOf(dto.getQuantity())); + }); + weekCaseDTOS.forEach(dto -> { + String date = dto.getDimension(); + Integer quantity = dto.getQuantity(); + //无重点区域事件数据,1-安防事件次数/所有安防事件次数=1 + if (Objects.isNull(weekCaseMap.get(date)) || weekCaseMap.get(date).equals(BigDecimal.ZERO)) { + caseScoreMap.put(date, BigDecimal.valueOf(1 * 100)); + } else { + BigDecimal multiply = BigDecimal.valueOf(quantity).subtract(weekCaseMap.get(date)).divide(BigDecimal.valueOf(quantity), 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + caseScoreMap.put(date, multiply); + } + }); + + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + caseInfos.forEach(caseInfo -> { + //重点区域安防事态评估分数 + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double keyAreaScore = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String dayTime = caseInfo.getHappenTime().substring(0, caseInfo.getHappenTime().indexOf(" ")); + BigDecimal preScore; + if (keyAreaScoreMap.containsKey(dayTime)) { + preScore = keyAreaScoreMap.get(dayTime); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(keyAreaScore.toString()); + keyAreaScoreMap.put(dayTime, preScore.subtract(nowScore)); + + //安防机动支援力量响应评估分数 + //扣分=事件级别权重*未解决小时数 + Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); + Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); + long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); + Double assessScore = Double.valueOf(hazardWeight) * between; + BigDecimal preAssessScore; + if (assessScoreMap.containsKey(dayTime)) { + preAssessScore = assessScoreMap.get(dayTime); + } else { + preAssessScore = new BigDecimal("100.0"); + } + BigDecimal nowAssessScore = new BigDecimal(assessScore.toString()); + assessScoreMap.put(dayTime, preAssessScore.subtract(nowAssessScore)); + }); + //构造结果 + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(caseScoreMap)) { + for (String date : dateList) { + caseScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if (CollectionUtils.isEmpty(keyAreaScoreMap)) { + for (String date : dateList) { + keyAreaScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if (CollectionUtils.isEmpty(assessScoreMap)) { + for (String date : dateList) { + assessScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + BigDecimal preCaseScore = Objects.isNull(caseScoreMap.get(date)) ? BigDecimal.valueOf(100) : caseScoreMap.get(date); + BigDecimal preKeyAreaScore = Objects.isNull(keyAreaScoreMap.get(date)) ? BigDecimal.valueOf(100) : keyAreaScoreMap.get(date); + BigDecimal preAssessScore = Objects.isNull(assessScoreMap.get(date)) ? BigDecimal.valueOf(100) : assessScoreMap.get(date); + BigDecimal caseScore = preCaseScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("case"))); + BigDecimal keyAreaScore = preKeyAreaScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("keyArea"))); + BigDecimal responseAssessScore = preAssessScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("responseAssess"))); + map.put("score", caseScore.add(keyAreaScore).add(responseAssessScore).stripTrailingZeros().toPlainString()); + resultList.add(map); + }); + return resultList; + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java index decc60c..2c66ec1 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java @@ -96,7 +96,10 @@ JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人员失败,海康response:{}", resultStr); - return ResponseData.error("单个添加人员失败"); + if("0x00052301".equals(resultJson.get("code"))){ + return ResponseData.error("添加人员身份证号重复!"); + } + return ResponseData.error("单个添加人员失败!"); } JSONObject data = (JSONObject)resultJson.get("data"); String faceId = data.getString("faceId"); @@ -129,13 +132,11 @@ String body = JSONObject.toJSONString(personSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.PERSON_SINGLE_UPDATE, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); + //海康该接口成功返回data为空 if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个修改人员失败,海康response:{}", resultStr); return ResponseData.error("单个修改人员失败"); } - JSONObject data = (JSONObject)resultJson.get("data"); - String faceId = data.getString("faceId"); - staffInfo.setStaffFaceId(faceId); if(staffInfoMapper.updateById(staffInfo) > 0){ return ResponseData.success(); } @@ -265,6 +266,7 @@ @Override public StaffInfo selectStaffInfoByCode(StaffInfo staffInfo) { StaffInfo info = staffInfoMapper.selectByCode(staffInfo.getStaffCode()); + info.setPicture(getPictureFromHik(staffInfo.getStaffCode())); return info; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java index b219984..aa23547 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java @@ -3,7 +3,9 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdcardUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -86,14 +88,21 @@ VisitorInfo visitorInfo = new VisitorInfo(); visitorInfo.setVisitorName(visitorApply.getVisitorName()); - visitorInfo.setGender(Integer.valueOf(visitorApply.getVisitorGender())); + //身份证号确定性别 + int genderByIdCard = IdcardUtil.getGenderByIdCard(visitorApply.getIdCard()); + if(0 == genderByIdCard){ + genderByIdCard = 2; + } + visitorInfo.setGender(genderByIdCard); visitorInfo.setPhoneNo(visitorApply.getVisitorPhone()); visitorInfo.setCertificateNo(visitorApply.getIdCard()); visitorInfo.setCertificateType(111); visitorInfo.setVisitorPhoto(visitorApply.getPicUri()); appointmentFreeRegisterRequest.setVisitorInfo(visitorInfo); - + log.info("--------------------------"); + log.info("请求visitorApply:{}", JSON.toJSONString(visitorApply)); String body = JSONObject.toJSONString(appointmentFreeRegisterRequest); + log.info("请求海康body:{}", body); String resultStr = HikUtil.hikApi(HikUri.APPOINTMENT_FREE_REGISTER, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if(!"0".equals(resultJson.get("code"))){ @@ -129,7 +138,12 @@ appointmentFreeRegisterRequest.setVisitPurpose(visitorApply.getVisitReason()); VisitorInfo visitorInfo = new VisitorInfo(); visitorInfo.setVisitorName(visitorApply.getVisitorName()); - visitorInfo.setGender(Integer.valueOf(visitorApply.getVisitorGender())); + //身份证号确定性别 + int genderByIdCard = IdcardUtil.getGenderByIdCard(visitorApply.getIdCard()); + if(0 == genderByIdCard){ + genderByIdCard = 2; + } + visitorInfo.setGender(genderByIdCard); visitorInfo.setPhoneNo(visitorApply.getVisitorPhone()); visitorInfo.setCertificateNo(visitorApply.getIdCard()); visitorInfo.setCertificateType(111); @@ -165,7 +179,7 @@ VisitorApply visitorApply1 = visitorApplyMapper.selectById(visitorApply.getId()); if(StringUtils.isNotEmpty(visitorApply1.getAppointRecordId())){ List appointRecordIds = new ArrayList<>(); - appointRecordIds.add(visitorApply.getAppointRecordId()); + appointRecordIds.add(visitorApply1.getAppointRecordId()); String body = JSONObject.toJSONString(appointRecordIds); String resultStr = HikUtil.hikApi(HikUri.APPOINTMENT_CANCEL, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); @@ -247,7 +261,12 @@ appointmentFreeRegisterRequest.setVisitPurpose(busConcentrator.getVisitReason()); VisitorInfo visitorInfo = new VisitorInfo(); visitorInfo.setVisitorName(busConcentrator.getVisitorName()); - visitorInfo.setGender(Integer.valueOf(busConcentrator.getVisitorGender())); + //身份证号确定性别 + int genderByIdCard = IdcardUtil.getGenderByIdCard(busConcentrator.getIdCard()); + if(0 == genderByIdCard){ + genderByIdCard = 2; + } + visitorInfo.setGender(genderByIdCard); visitorInfo.setPhoneNo(busConcentrator.getVisitorPhone()); visitorInfo.setCertificateNo(busConcentrator.getIdCard()); visitorInfo.setCertificateType(111); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java index 316188e..71d587d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java @@ -22,4 +22,11 @@ boolean insertCaseInfoBatch(List caseInfos); List caseInfoList(CaseInfoRequest caseInfoRequest); + + List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest); + + Object caseInfoLastByDrawNo(String drawNo); + + int updateAllStatus(); + } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java index b3d1968..7a7fe8a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java @@ -2,6 +2,10 @@ import com.alibaba.fastjson.JSONArray; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import java.util.HashMap; import java.util.List; @@ -13,4 +17,32 @@ */ public interface CockpitService { HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap); + + Object buildingNumberPerHour(); + + Object visitorTodayNumber(); + + Object deviceNumber(); + + Object securityNumber(); + + Object visitorApplyDetail(); + + Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO); + + Object eventCategoryStatistics(); + + Object fireEquipStatistics(); + + Object beOnDutyRatio(); + + Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO); + + Object securityScore(SecurityScoreDTO securityScoreDTO); + + Object securityFrequency(); + + Object areaScore(SecurityScoreDTO securityScoreDTO); + + Object heatMap(HeatMapDTO heatMapDTO); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java new file mode 100644 index 0000000..178b909 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.service; + +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; + +/** + * @Description: + * @Author: wangpeng + * @Date: 2022/10/11 9:10 + */ +public interface PropertyManageService { + Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO); + + Object keyAreaData(String dimension); + + Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO); + + Object attendanceNumber(String dimension); + + Object securityAssessment(String dimension); + + Object keyAreaStatistic(); + + Object responseAssess(); + + Object hazardLevelStatistics(String dimension); + + Object securityRank(); + + Object securityLevelAssess(); + + Object commute(); + + Object keyArea(); + + Object visitor(); + + Object security(); + + Object patrol(); + + Object other(); +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java index ea6b8c0..2580187 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java @@ -17,6 +17,7 @@ import com.casic.missiles.modular.service.BlackInfoService; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -70,11 +71,17 @@ faceInfo.setCertificateNum(blackInfo.getIdCardNo()); faceSingleAddOrUpdateRequest.setFaceInfo(faceInfo); FacePic facePic = new FacePic(); - facePic.setFaceBinaryData(blackInfo.getPicture()); - faceSingleAddOrUpdateRequest.setFacePic(facePic); + String picture = blackInfo.getPicture(); + if(StringUtils.isNotEmpty(picture)){ + String substringPicture = picture.substring(picture.indexOf(",") + 1); + facePic.setFaceBinaryData(substringPicture); + } faceSingleAddOrUpdateRequest.setFacePic(facePic); String body = JSONObject.toJSONString(faceSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.FACE_SINGLE_ADDITION, body); + log.info("-----------------------"); + log.info("增加黑名单人脸请求body,{}", body); + log.info("增加黑名单人脸resultStr:{}", JSONObject.toJSONString(resultStr)); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人脸失败,海康response:{}", resultStr); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java index 6b03d8b..1c34f68 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java @@ -2,17 +2,22 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.dao.CaseInfoMapper; import com.casic.missiles.modular.dao.CategoryLevelMapper; +import com.casic.missiles.modular.dao.DeviceInfoMapper; import com.casic.missiles.modular.dao.HazardLevelMapper; import com.casic.missiles.modular.dto.CaseInfoRequest; import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.model.CaseInfo; +import com.casic.missiles.modular.model.DeviceInfo; import com.casic.missiles.modular.service.CaseInfoService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,6 +31,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; /** * @Description: 安防事件service @@ -50,6 +56,9 @@ @Resource private AbstractDictService dictService; + @Resource + private DeviceInfoMapper deviceInfoMapper; + @Override public List caseInfoListPage(Page page, CaseInfoRequest caseInfoRequest) { try { @@ -136,17 +145,69 @@ @Override public List caseInfoList(CaseInfoRequest caseInfoRequest) { try { - List pageList = caseInfoMapper.getCaseInfoList(caseInfoRequest); - pageList.forEach(caseInfo ->{ + List list = caseInfoMapper.getCaseInfoList(caseInfoRequest); + list.forEach(caseInfo ->{ caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); }); - return pageList; + return list; } catch (DataAccessException ex) { log.error("安防事件: 查询不分页出现异常, 异常:{}", ex); } return null; } + + @Override + public List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest) { + try { + List list = caseInfoMapper.getCaseInfoListUnResolved(caseInfoRequest); + list.forEach(caseInfo ->{ + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + }); + return list; + } catch (DataAccessException ex) { + log.error("未解决/解决中安防事件: 查询不分页出现异常, 异常:{}", ex); + } + return null; + } + + @Override + public Object caseInfoLastByDrawNo(String drawNo) { + //图纸编号和设备编号一一对应 + QueryWrapper dWrapper = new QueryWrapper<>(); + dWrapper.eq("draw_no", drawNo); + DeviceInfo deviceInfo = deviceInfoMapper.selectOne(dWrapper); + if(Objects.isNull(deviceInfo)){ + return ResponseData.error("该图纸编号下不存在关联的设备"); + } + if(StringUtils.isEmpty(deviceInfo.getDevCode())){ + return ResponseData.error("该图纸编号下不存在对应的设备编号"); + }else{ + String devCode = deviceInfo.getDevCode(); + QueryWrapper cWrapper = new QueryWrapper<>(); + cWrapper.eq("device_code", devCode); + List caseInfos = caseInfoMapper.selectList(cWrapper); + if(CollectionUtil.isEmpty(caseInfos)){ + return ResponseData.error("该图纸编号下不存在最近发生的事件"); + } + CaseInfo caseInfo = caseInfos.get(caseInfos.size() - 1); + caseInfo.setDrawNo(deviceInfo.getDrawNo()); + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + return ResponseData.success(caseInfo); + } + } + + @Override + public int updateAllStatus() { + int upflag = caseInfoMapper.updateAllStatus(); + return upflag; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java index 7402991..7fb5a6e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java @@ -4,15 +4,34 @@ import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.*; import com.casic.missiles.modular.enums.HikUri; +import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.redis.RedisUtil; +import com.casic.missiles.modular.redis.key.CacheKeys; import com.casic.missiles.modular.service.CockpitService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import java.text.MessageFormat; +import java.text.NumberFormat; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.*; +import java.util.stream.Collectors; /** * @Description: @@ -22,6 +41,28 @@ @Slf4j @Service public class CockpitServiceImpl implements CockpitService { + @Autowired + private StatisticNumberMapper numberMapper; + @Autowired + private AbstractDictService dictService; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private DeviceInfoMapper deviceInfoMapper; + @Autowired + private FireEquipInfoMapper fireEquipInfoMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private VisitorApplyMapper applyMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private RedisUtil redisUtil; @Override public HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap) { @@ -106,4 +147,512 @@ }); return resultMap; } + + @Override + public Object buildingNumberPerHour() { + //当天按小时分组的人数 + List list = numberMapper.selectListByTime(); + Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); + //定时任务中已将每小时三栋楼人数存到数据库 + //将一期主楼和录制楼人数合并,二期单算 + List> resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List buildingNumberDTOS = collect.get(key); + BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); + BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); + BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); + HashMap resultMap = new HashMap<>(); + Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); + Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); + resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); + resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); + resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); + resultList.add(resultMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object visitorTodayNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); + List visitInfos = visitInfoMapper.selectList(wrapper); + HashMap resultMap = new HashMap<>(); + resultMap.put("今日访客量", visitInfos.size()); + return ResponseData.success(resultMap); + } + + @Override + public Object deviceNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + Integer total = deviceInfoMapper.selectCount(wrapper); + QueryWrapper wrapper1 = new QueryWrapper<>(); + wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 + Integer online = deviceInfoMapper.selectCount(wrapper1); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) online / (float) total * 100); + HashMap resultMap = new HashMap<>(); + resultMap.put("设备总数", total); + resultMap.put("设备在线率", result + "%"); + return ResponseData.success(resultMap); + } + + @Override + public Object securityNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) leave / (float) total * 100); + HashMap resultMap = new HashMap<>(); + if (0 == total) { + resultMap.put("安保人员总数", 0); + resultMap.put("安保人员离岗率", "0"); + } else { + resultMap.put("安保人员总数", total); + resultMap.put("安保人员离岗率", result + ""); + } + return ResponseData.success(resultMap); + } + + @Override + public Object visitorApplyDetail() { + List reasonGroup = applyMapper.selectByVisitReason(); + List resultList = new ArrayList<>(); + //空数据处理 + List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); + if (CollectionUtils.isEmpty(reasonGroup)) { + for (Dict dict : visitReason) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(dict.getName()); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); + if (0 == sum) { + return ResponseData.success(); + } + reasonGroup.forEach(group -> { + String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(group.getQuantity()); + applyReasonGroupDTO.setVisitReason(reasonName); + applyReasonGroupDTO.setRatio(result + "%"); + resultList.add(applyReasonGroupDTO); + }); + //返回数据补全处理 + if (resultList.size() < visitReason.size()) { + List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); + for (Dict dict : visitReason) { + String name = dict.getName(); + if (!collect.contains(name)) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(name); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO) { + //查询各危险级别权重name,用于构造返回结构 + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); + + Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); + List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(list)) { + Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + //查询数据,放入redis + List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); + Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //设置过期时间为每月1号0点 + LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) + .withMinute(0).withSecond(0).withNano(0); + long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); + redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + + @Override + public Object eventCategoryStatistics() { + List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); + return ResponseData.success(categoryLevelGroup); + } + + @Override + public Object fireEquipStatistics() { + List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); + //空数据处理 + List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); + if (CollectionUtils.isEmpty(equipTypeGroup)) { + for (Dict dict : equipType) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + return ResponseData.success(equipTypeGroup); + } + equipTypeGroup.forEach(group -> { + String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); + group.setEquipTypeName(equipTypeName); + }); + //返回数据补全处理 + if (equipTypeGroup.size() < equipType.size()) { + List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); + for (Dict dict : equipType) { + String code = dict.getCode(); + if (!collect.contains(code)) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + } + } + return ResponseData.success(equipTypeGroup); + } + + @Override + public Object beOnDutyRatio() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + if (0 == total) { + return ResponseData.success(null); + } + List currentDateHourList = DateUtils.getCurrentDateWorkHourList(); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + //补全空数据 + if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { + for (String date : currentDateHourList) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + return ResponseData.success(onDutyRatioDTOS); + } + onDutyRatioDTOS.forEach(dto -> { + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); + dto.setRatio(result + "%"); + }); + //补全空数据 + List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); + for (String date : currentDateHourList) { + if (!collect.contains(date)) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + } + return ResponseData.success(onDutyRatioDTOS); + } + + @Override + public Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO) { + List gateStatusGroup = null; + //2代表所有摄像头(对应字典2-7) + if ("2".equals(gateStatusGroupDTO.getDevType())) { + gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); + } else { + gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); + } + HashMap resultMap = new HashMap<>(); + //空数据处理 + List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); + if (CollectionUtils.isEmpty(gateStatusGroup)) { + List resultList = new ArrayList<>(); + for (Dict dict : deviceStatus) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + resultMap.put("total", 0); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("无该类设备信息"); + } + List resultList = new ArrayList<>(); + gateStatusGroup.forEach(group -> { + if ("2".equals(gateStatusGroupDTO.getDevType())) { + group.setDevType("2"); + } + String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(devStatus); + gateStatusGroupResponse.setRatio(result + "%"); + gateStatusGroupResponse.setQuantity(group.getQuantity()); + resultList.add(gateStatusGroupResponse); + }); + //返回数据补全处理 + if (resultList.size() < deviceStatus.size()) { + List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); + for (Dict dict : deviceStatus) { + String name = dict.getName(); + if (!collect.contains(name)) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + } + } + resultMap.put("total", sum); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + + @Override + public Object securityScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的position划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + List caseInfos = caseInfoMapper.selectByPosition(position); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //楼栋-评分实体map + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + Map resultMap = new HashMap<>(); + //空数据处理 + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + resultMap.put(dict.getName(), 100.0); + } + return ResponseData.success(resultMap); + } + + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + + collect.keySet().forEach(key -> { + List list = collect.get(key); + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); + resultMap.put(dictValue, 100 - collect1.getSum()); + }); + //返回数据补全处理 + if (collect.size() < devicePosition.size()) { + Set strings = resultMap.keySet(); + for (Dict dict : devicePosition) { + String name = dict.getName(); + if (!strings.contains(name)) { + resultMap.put(dict.getName(), 100.0); + } + } + } + //按楼层分组计算评分 +// collect.keySet().forEach(key -> { +// Map map = new HashMap<>(); +// List securityScoreDTOS = collect.get(key); +// //楼层-评分map +// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); +// collect1.keySet().forEach(key1 -> { +// map.put(key1, 100 - collect1.get(key1)); +// }); +// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); +// resultMap.put(dictValue, map); +// }); + return ResponseData.success(resultMap); + } + + @Override + public Object securityFrequency() { + String year = String.valueOf(DateUtil.thisYear()); + String month = String.valueOf(DateUtil.thisMonth()); + Integer quantity = caseInfoMapper.selectCountByMonth(year, month); + SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); + securityFrequencyDTO.setQuantity(quantity); + securityFrequencyDTO.setYear(year); + securityFrequencyDTO.setMonth(month); + return ResponseData.success(securityFrequencyDTO); + } + + @Override + public Object areaScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的area划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + String area = securityScoreDTO.getArea(); + if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { + return null; + } + Map resultMap = new HashMap<>(); + List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); + if (Objects.isNull(caseInfos)) { + resultMap.put("安防评分", 100.0); + return ResponseData.success(resultMap); + } + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + resultMap.put("安防评分", 100 - collect.getSum()); + return ResponseData.success(resultMap); + } + + @Override + public Object heatMap(HeatMapDTO heatMapDTO) { + if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { + heatMapDTO.setMinute(3); + } + List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); + Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); + HashMap resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect)) { + return ResponseData.success(); + } + collect.keySet().forEach(key -> { + resultMap.put(key, collect.get(key).size()); + }); + return ResponseData.success(resultMap); + } + + private List> getResultMap(List nameList, List> resultList, Map> resultMap) { + resultMap.keySet().forEach(key -> { + List monthAndLevelGroupDTOS = resultMap.get(key); + HashMap hashMap = new HashMap<>(); + for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { +// hashMap.put("年份", andLevelGroupDTO.getYear()); + hashMap.put("月份", /*andLevelGroupDTO.getYear() + "-" + */Integer.valueOf(andLevelGroupDTO.getMonth())); + hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); + } + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + }); + //12个月份,用于构造返回结构 + List list1 = new ArrayList<>(); + for (Map map : resultList) { + list1.add(String.valueOf(map.get("月份"))); + } + for (int i = 1; i < 13; i++) { + if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { + continue; + } + HashMap hashMap = new HashMap<>(); + hashMap.put("月份", i); + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + } + List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); + return results; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java index 94308db..f91d7bd 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java @@ -427,6 +427,13 @@ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("draw_no", drawNo); DeviceInfo deviceInfo = deviceInfoMapper.selectOne(wrapper); + if(!Objects.isNull(deviceInfo)){ + deviceInfo.setDevTypeName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_TYPE, deviceInfo.getDevType())); + deviceInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, deviceInfo.getStatus())); + deviceInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, deviceInfo.getPosition())); + deviceInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, deviceInfo.getArea())); + deviceInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, deviceInfo.getIsKeyArea())); + } return deviceInfo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java index 8ed53d9..c399a7f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java @@ -11,6 +11,7 @@ import com.casic.missiles.modular.service.HikService; import com.casic.missiles.modular.system.model.Dict; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -50,8 +51,11 @@ @Override public CaseInfo blackListHandle(JSONObject event, CaseInfo caseInfo) { - String srcIndex = event.getString("srcIndex"); //海康资源唯一标识 + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 String happenTimeISO = String.valueOf(event.get("happenTime")); + DateTime parse = DateUtil.parse(happenTimeISO); String happenTime = DateUtil.formatDateTime(parse); caseInfo.setHappenTime(happenTime); //发生时间 @@ -89,6 +93,16 @@ log.info("接收到离岗事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //离岗事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray leavePosition = data.getJSONArray("leavePosition"); + if(StringUtils.isNotEmpty(leavePosition.getString(0))){ + JSONObject jsonObject = leavePosition.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -115,6 +129,16 @@ log.info("接收到人员聚集事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //人员聚集事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray group = data.getJSONArray("group"); + if(StringUtils.isNotEmpty(group.getString(0))){ + JSONObject jsonObject = group.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -263,8 +287,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void propertyAttendanceHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); @@ -309,8 +334,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void securityPersonnelHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java new file mode 100644 index 0000000..4427f19 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java @@ -0,0 +1,1255 @@ +package com.casic.missiles.modular.service.impl; + +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.config.CockpitConfig; +import com.casic.missiles.modular.dao.*; +import com.casic.missiles.modular.dto.statistics.*; +import com.casic.missiles.modular.enums.SecurityEventDict; +import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.service.PropertyManageService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.text.NumberFormat; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @Description: 驾驶舱二级页面-物管信息 + * @Author: wangpeng + * @Date: 2022/10/11 9:11 + */ +@Slf4j +@Service +public class PropertyManageServiceImpl implements PropertyManageService { + @Autowired + private AttendanceInfoMapper attendanceInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private DeviceRepairLogMapper repairLogMapper; + @Autowired + private CockpitConfig cockpitConfig; + @Autowired + private AbstractDictService dictService; + + @Override + public Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO) { + //各类型员工及总数 + List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); + Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); + + String dateDimension = attendanceRatioDTO.getDateDimension(); + List attendanceRatioDTOS = new ArrayList<>(); + List dateList = null; + //考勤的人数,按单次考勤过滤 + if ("week".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); + dateList = DateUtils.getCurrentDateDayList(); + } else if ("month".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); + dateList = DateUtils.getCurrentDateWeekList(); + } else if ("year".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); + dateList = DateUtils.getCurrentDateMonthList(); + } + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { + for (String date : dateList) { + HashMap hashMap = new HashMap<>(); + hashMap.put("date", date); + hashMap.put("property", "0%"); + hashMap.put("security", "0%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + //计算出勤率 + Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); + + dateList.forEach(date -> { + HashMap hashMap = new HashMap<>(); + if (CollectionUtils.isEmpty(dateMap.get(date))) { + hashMap.put("date", date); + hashMap.put("property", "0%"); + hashMap.put("security", "0%"); + resultList.add(hashMap); + } else { + List attendances = dateMap.get(date); + attendances.forEach(attendanceRatio -> { + attendanceRatio.setDateDimension(dateDimension); + attendanceRatio.setStaffType(attendanceRatio.getStaffType()); + List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); + String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); + attendanceRatio.setAttendanceRatio(ratio + "%"); + //构造返回结构 + hashMap.put("date", attendanceRatio.getDate()); +// String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); + if ("1".equals(attendanceRatio.getStaffType())) { + hashMap.put("property", attendanceRatio.getAttendanceRatio()); + } + if ("2".equals(attendanceRatio.getStaffType())) { + hashMap.put("security", attendanceRatio.getAttendanceRatio()); + } + }); + //补全缺少数据 + if (1 == attendances.size()) { + AttendanceRatioDTO attendanceRatioDTO1 = attendances.get(0); + if ("1".equals(attendanceRatioDTO1.getStaffType())) { + hashMap.put("security", "0%"); + } + if ("2".equals(attendanceRatioDTO1.getStaffType())) { + hashMap.put("property", "0%"); + } + } + resultList.add(hashMap); + } + }); + return ResponseData.success(resultList); + + } + + @Override + public Object keyAreaData(String dimension) { + List resultList = null; + List dateList = null; + if ("year".equals(dimension)) { + //近365天数据按月分组统计 + resultList = caseInfoMapper.selectPreMonthCountByNearYear(); + dateList = DateUtils.getCurrentDateMonthList(); + } else if ("month".equals(dimension)) { + //近30天数据按周分组统计 + resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); + dateList = DateUtils.getCurrentDateWeekList(); + } else if ("week".equals(dimension)) { + //近7天数据按天分组统计 + resultList = caseInfoMapper.selectPreDayCountBySevenDay(); + dateList = DateUtils.getCurrentDateDayList(); + } + //补全空数据处理 + if (CollectionUtils.isEmpty(resultList)) { + for (String date : dateList) { + PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); + preMonthOrWeekCaseDTO.setDimension(date); + preMonthOrWeekCaseDTO.setQuantity(0); + resultList.add(preMonthOrWeekCaseDTO); + } + } else { + for (String date : dateList) { + List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); + if (!collect.contains(date)) { + PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); + preMonthOrWeekCaseDTO.setDimension(date); + preMonthOrWeekCaseDTO.setQuantity(0); + resultList.add(preMonthOrWeekCaseDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { + String year = avgMonthAndWeekGroupDTO.getYear(); + List monthList = caseInfoMapper.selectPreMonthCountByYear(year); + Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); + HashMap strAvgMap = new HashMap<>(); + List resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List preMonthOrWeekCaseDTOS = collect.get(key); + int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); + //若年份是本年,则使用各安防级别数量/当前月份数 + //若不是本年,除数为12 + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + if (year.equals(String.valueOf(DateUtil.thisYear()))) { + monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); + strAvgMap.put(key, monthAndWeekDTO); + } else { + monthAndWeekDTO.setMonthQuantity(sum / 12); + strAvgMap.put(key, monthAndWeekDTO); + } + } + + List weekList = caseInfoMapper.selectPreWeekCountByYear(year); + Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); + for (String key : collect1.keySet()) { + List preMonthOrWeekCaseDTOS = collect.get(key); + int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); + if (year.equals(String.valueOf(DateUtil.thisYear()))) { + if (!Objects.isNull(strAvgMap.get(key))) { + MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); + strAvgMap.put(key, monthAndWeekDTO); + } else { + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); + strAvgMap.put(key, monthAndWeekDTO); + } + } else { + if (!Objects.isNull(strAvgMap.get(key))) { + MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / 52); + strAvgMap.put(key, monthAndWeekDTO); + } else { + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / 52); + strAvgMap.put(key, monthAndWeekDTO); + } + } + } + strAvgMap.keySet().forEach(key -> { + resultList.add(strAvgMap.get(key)); + }); + //输出顺序 + Collections.swap(resultList, 1, 2); + return ResponseData.success(resultList); + } + + @Override + public Object attendanceNumber(String dimension) { + List attendanceNumberDTOs = null; + List> resultList = new ArrayList<>(); + List dateList = new ArrayList<>(); + if ("week".equals(dimension)) { + //近7天数据按天分组统计 + attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); + dateList = DateUtils.getCurrentDateDayList(); + } else if ("day".equals(dimension)) { + //今天数据按小时分组统计 + attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); + dateList = DateUtils.getCurrentDateWorkHourList(); + } + if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { + for (String date : dateList) { + HashMap hashMap = new HashMap<>(); + hashMap.put("staticTime", date); + hashMap.put("1", "0"); + hashMap.put("2", "0"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); + if ("day".equals(dimension)) { + collect = collect.entrySet().stream().collect(Collectors.toMap(m -> m.getKey().substring(5) + ":00", Map.Entry::getValue)); + } + + for (String date : dateList) { + Map resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect.get(date))) { + resultMap.put("1", "0"); + resultMap.put("2", "0"); + resultMap.put("staticTime", date); + resultList.add(resultMap); + } else { + List attendanceNumberDTOS = collect.get(date); +// Map resultMap = new HashMap<>(); + AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); + if (attendanceNumberDTOS.size() >= 2) { + AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); + resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); + } + resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); + resultMap.put("staticTime", date); + resultList.add(resultMap); + //补全map缺少数据 + if (!resultMap.containsKey("1")) { + resultMap.put("1", "0"); + } + if (!resultMap.containsKey("2")) { + resultMap.put("2", "0"); + } + } + } + +// +// collect.keySet().forEach(key -> { +// List attendanceNumberDTOS = collect.get(key); +// Map resultMap = new HashMap<>(); +// AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); +// if (attendanceNumberDTOS.size() >= 2) { +// AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); +// resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); +// } +// resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); +// resultMap.put("staticTime", attendanceNumberDTO.getDate().substring(5) + ":00"); +// resultList.add(resultMap); +// }); +// //补全空数据处理 +// if (CollectionUtils.isEmpty(resultList)) { +// for (String date : dateList) { +// Map resultMap = new HashMap<>(); +// resultMap.put("1", "0"); +// resultMap.put("2", "0"); +// resultMap.put("staticTime", date); +// resultList.add(resultMap); +// } +// } else { +// List collectList = new ArrayList<>(); +// for (Map map : resultList) { +// String staticTime = map.get("staticTime"); +// collectList.add(staticTime); +// //补全map缺少数据 +// if (!map.containsKey("1")) { +// map.put("1", "0"); +// } +// if (!map.containsKey("2")) { +// map.put("2", "0"); +// } +// } +// for (String date : dateList) { +// if (!collectList.contains(date)) { +// Map resultMap = new HashMap<>(); +// resultMap.put("1", "0"); +// resultMap.put("2", "0"); +// resultMap.put("staticTime", date); +// resultList.add(resultMap); +// } +// } +// } + return ResponseData.success(resultList); + } + + @Override + public Object securityAssessment(String dimension) { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + if ("week".equals(dimension)) { + //近7天早晚高峰数据 + List caseInfos = caseInfoMapper.selectListBySevenDay(); + //按时间(天)进行分组 + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(" "); + String dayTime = array[0]; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } else if ("day".equals(dimension)) { + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDatePeakHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + + } + return null; + } + + @Override + public Object keyAreaStatistic() { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday2(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + dayTime = dayTime.substring(5) + ":00"; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } + + @Override + public Object responseAssess() { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday3(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + //扣分=事件级别权重*未解决小时数 + Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); + Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); + long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); + Double score = Double.valueOf(hazardWeight) * between; + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + dayTime = dayTime.substring(5) + ":00"; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } + + @Override + public Object hazardLevelStatistics(String dimension) { + List hazardLevelGroup = null; + if ("week".equals(dimension)) { + hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); + } else if ("month".equals(dimension)) { + hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); + } + if (CollectionUtils.isEmpty(hazardLevelGroup)) { + log.info("重点区域威胁事件类型统计,无安防事件"); + return ResponseData.error("无安防事件发生!"); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("安防事件总数为0"); + } + hazardLevelGroup.forEach(group -> { + CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); + group.setLevelName(caseHazardLevel.getName()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + group.setLevelRatio(result + "%"); + }); + HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); + hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); + hazardLevelGroupResponse.setQuantity(sum); + return ResponseData.success(hazardLevelGroupResponse); + } + + @Override + public Object securityRank() { + //考勤表近一个月按人员分组的考勤个数前十名 + List list = attendanceInfoMapper.getCountForRank(); + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(list)) { + //补全空数据处理 + List staffList = staffInfoMapper.selectListLimitTen(); + for (StaffInfo staffInfo : staffList) { + HashMap hashMap = new HashMap<>(); + hashMap.put(staffInfo.getStaffName(), "0%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + //构造返回结构 + for (SecurityRankDTO dto : list) { + // TODO: 2022/9/15 分母使用30,后续看产品定义 + HashMap hashMap = new HashMap<>(); + String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); + hashMap.put("name", dto.getStaffName()); + hashMap.put("ratio", result + "%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object securityLevelAssess() { + //今天数据按小时分组统计 + List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + if (CollectionUtils.isEmpty(resultList)) { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); + levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); + levelAssessDTO.setDate(date); +// levelAssessDTO.setQuantity(); + resultList.add(levelAssessDTO); + } + return ResponseData.success(resultList); + } + resultList.forEach(result -> { + result.setDate(result.getDate().substring(5) + ":00"); + BigDecimal deScore = new BigDecimal(result.getQuantity()); + BigDecimal preScore = new BigDecimal("100.0"); + result.setScore(preScore.subtract(deScore).doubleValue()); + }); + //数据补全处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + for (SecurityLevelAssessDTO levelAssessDTO : resultList) { + String substring = levelAssessDTO.getDate().substring(5) + ":00"; + if (!substring.equals(date)) { + SecurityLevelAssessDTO levelAssess = new SecurityLevelAssessDTO(); + levelAssess.setScore(new BigDecimal("100.0").doubleValue()); + levelAssess.setDate(date); + resultList.add(levelAssess); + break; + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object commute() { + //早晚高峰区域安防评估 + ResponseData assessResultJson = (ResponseData) this.securityAssessment("week"); + if (Objects.isNull(assessResultJson) || 200 != assessResultJson.getCode()) { + return assessResultJson; + } + JSONArray assessData = JSONArray.parseArray(JSON.toJSONString(assessResultJson.getData())); + //所有类型的员工出勤 + List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); + long sum = staffTypeAndSumDTOS.stream().collect(Collectors.summarizingInt(StaffTypeAndSumDTO::getSum)).getSum(); + List countByTypeAndDateForWeek = attendanceInfoMapper.getCountByTypeAndDateForWeek(); + Map> dateMap = countByTypeAndDateForWeek.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); + HashMap attendanceMap = new HashMap<>(); + dateMap.keySet().forEach(key -> { + List attendanceRatioDTOS = dateMap.get(key); + //当天所有类型的员工的出勤人数 + long sum1 = attendanceRatioDTOS.stream().collect(Collectors.summarizingInt(AttendanceRatioDTO::getQuantity)).getSum(); + //出勤占比评分 + Double attendanceRatio = ((float) sum1 / (float) sum) * 100 * cockpitConfig.getCommuteWeight(); + attendanceMap.put(key, attendanceRatio); + }); + //构造结果 + List> resultList = new ArrayList<>(); + Iterator iterator = assessData.stream().iterator(); + while (iterator.hasNext()) { + JSONObject next = (JSONObject) iterator.next(); + String date = next.getString("date"); + HashMap map = new HashMap<>(); + //计算评分 + Double assessRatio = next.getInteger("score") * (1 - cockpitConfig.getCommuteWeight()); + NumberFormat numberFormat = NumberFormat.getInstance(); + numberFormat.setMaximumFractionDigits(2); + if (!Objects.isNull(attendanceMap.get(date))) { + Double attendanceRatio = attendanceMap.get(date); + Double r = assessRatio + attendanceRatio; + map.put("score", numberFormat.format(r)); + } else { + //无员工出勤率(出勤为0),只有安防评估分值 + map.put("score", numberFormat.format(assessRatio)); + } + map.put("date", date); + resultList.add(map); + } + return ResponseData.success(resultList); + } + + @Override + public Object keyArea() { + //1-重点区域安防事件次数/所有安防事件次数 + //获取近7天每天的安防事件个数,所有和重点区域 + List weekCaseDTOS = caseInfoMapper.selectPreDayCountBySevenDay(); + List weekCaseKeyAreaDTOS = caseInfoMapper.selectPreDayCountBySevenDayKeyArea(); + List caseInfos = caseInfoMapper.selectListBySevenDayKeyArea(); + HashMap weekCaseMap = new HashMap<>(); + HashMap caseScoreMap = new HashMap<>(); + HashMap keyAreaScoreMap = new HashMap<>(); + HashMap assessScoreMap = new HashMap<>(); + List dateList = DateUtils.getCurrentDateDayList(); + List> result = getForResult(weekCaseDTOS, weekCaseKeyAreaDTOS, caseInfos, weekCaseMap, caseScoreMap, + keyAreaScoreMap, assessScoreMap, dateList); + + //上个月对应数据 + List beforeMonthKeyAreaCaseDTOS = caseInfoMapper.selectPreDayCountByBeforeMonthKeyArea(); + List beforeMonthCaseDTOS = caseInfoMapper.selectPreDayCountByBeforeMonth(); + List beforeMonthCaseInfos = caseInfoMapper.selectListByBeforeMonthKeyArea(); + HashMap beforeMonthWeekCaseMap = new HashMap<>(); + HashMap beforeMonthCaseScoreMap = new HashMap<>(); + HashMap beforeMonthKeyAreaScoreMap = new HashMap<>(); + HashMap beforeMonthAssessScoreMap = new HashMap<>(); + List beforeMonthDateList = DateUtils.getCurrentDateDayBeforeMonthList(); + List> resultBeforeMonth = getForResult(beforeMonthCaseDTOS, beforeMonthKeyAreaCaseDTOS, beforeMonthCaseInfos, + beforeMonthWeekCaseMap, beforeMonthCaseScoreMap, beforeMonthKeyAreaScoreMap, beforeMonthAssessScoreMap, beforeMonthDateList); + //计算环比 + for (int i = 0; i < result.size(); i++) { + Map resultMap = result.get(i); + Map resultBeforeMonthMap = resultBeforeMonth.get(i); + BigDecimal resultScore = BigDecimal.valueOf(Double.valueOf(String.valueOf(resultMap.get("score")))); + BigDecimal resultBeforeMonthScore = BigDecimal.valueOf(Double.valueOf(String.valueOf(resultBeforeMonthMap.get("score")))); + BigDecimal finalResult = resultScore.subtract(resultBeforeMonthScore).divide(resultBeforeMonthScore, 2, BigDecimal.ROUND_HALF_UP); + resultMap.put("ringRatio", finalResult); + } + return ResponseData.success(result); + } + + @Override + public Object visitor() { + //查询每天的访客对应的离开记录(进入记录存在且在申请范围内) + //近7天主要使用申请离开时间(申请进入时间不会影响扣分) + List list = visitInfoMapper.selectListBySevenDay(); + list.stream().forEach(visit -> { + DateTime dateTime = DateUtil.parseDateTime(visit.getApplyOutTime()); + String formatDate = DatePattern.NORM_DATE_FORMAT.format(dateTime); + visit.setDate(formatDate); + }); + Map> dateVisitMap = list.stream().collect(Collectors.groupingBy(MultiScoreVisitorDTO::getDate)); + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + HashMap deductMap = new HashMap<>(); //扣分使用 + dateList.forEach(date -> { + //1、空数据处理 + if (CollectionUtils.isEmpty(dateVisitMap)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } else if (CollectionUtils.isEmpty(dateVisitMap.get(date))) { + //2、补全数据处理 + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } else { + //3、计算数据处理 + //计算分数(未在申请时间段内离开减分(包括无离开时间和有离开时间两种情况)、未在申请区域内离开减分),配置扣分,配置每个访客最高扣分 + List multiScoreVisitorDTOS = dateVisitMap.get(date); + //遍历访客 + for (MultiScoreVisitorDTO visitorDTO : multiScoreVisitorDTOS) { + //无离开时间 + if (StringUtils.isEmpty(visitorDTO.getOutTime())) { + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + cockpitConfig.getVisitorWeight().get("NoRecordPointDeduct")); + } else { + deductMap.put(date, cockpitConfig.getVisitorWeight().get("NoRecordPointDeduct")); + } + } else { +// DateTime applyInDateTime = DateUtil.parseDateTime(visitorDTO.getApplyInTime()); + DateTime applyOutDateTime = DateUtil.parseDateTime(visitorDTO.getApplyOutTime()); + DateTime outDateTime = DateUtil.parseDateTime(visitorDTO.getOutTime()); + //未在申请时间段离开(在申请离开时间后离开) + if (DateUtil.compare(outDateTime, applyOutDateTime) > 0) { + long betweenHour = DateUtil.between(outDateTime, applyOutDateTime, DateUnit.HOUR); + Double score = betweenHour * cockpitConfig.getVisitorWeight().get("singlePointDeduct"); + //该访客扣分到达最多分 + if (score >= cockpitConfig.getVisitorWeight().get("mostPointDeduct")) { + score = cockpitConfig.getVisitorWeight().get("mostPointDeduct"); + } + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + score); + } else { + deductMap.put(date, score); + } + } + //未在申请区域离开 + if (StringUtils.isNotEmpty(visitorDTO.getApplyVisitPosition()) && !visitorDTO.getApplyVisitPosition().equals(visitorDTO.getVisitPosition())) { + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + cockpitConfig.getVisitorWeight().get("singlePointDeduct")); + } else { + deductMap.put(date, cockpitConfig.getVisitorWeight().get("singlePointDeduct")); + } + } + + } + } + //添加到结果list + HashMap map = new HashMap<>(); + map.put("date", date); + if (!Objects.isNull(deductMap.get(date))) { + //最少0分 + if (deductMap.get(date) >= 100) { + map.put("score", 0); + } else { + map.put("score", 100 - deductMap.get(date)); + } + } else { + map.put("score", 100); + } + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object security() { + //安保人员到岗率*100*权重0.5 + //近7天安保人员到岗率 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + + List dateCountList = caseInfoMapper.selectDemobilizedCountSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap onDutyMap = new HashMap<>(); + dateCountList.forEach(dateCount -> { + //到岗率 + BigDecimal totalCount = new BigDecimal(total); + BigDecimal leaveCount = new BigDecimal(dateCount.getLeaveCount()); + BigDecimal result = totalCount.subtract(leaveCount).divide(totalCount, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + onDutyMap.put(dateCount.getDate(), result.multiply(BigDecimal.valueOf(cockpitConfig.getSecurityWeight().get("onDuty"))).setScale(2, BigDecimal.ROUND_HALF_UP)); + }); + + //安保等级评估均值*权重0.5 + List levelAssessList = caseInfoMapper.selectListByTypeSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap levelAssessMap = new HashMap<>(); + levelAssessList.forEach(levelAssess -> { + //6-23点共17小时,100-该天扣分/17 + BigDecimal deScore = new BigDecimal(levelAssess.getQuantity()); + BigDecimal preScore = new BigDecimal("100.0"); + BigDecimal divide = deScore.divide(BigDecimal.valueOf(17), 2, BigDecimal.ROUND_HALF_UP); + BigDecimal result = preScore.subtract(divide); + levelAssessMap.put(levelAssess.getDate(), result.multiply(BigDecimal.valueOf(cockpitConfig.getSecurityWeight().get("levelAssess"))).setScale(2, BigDecimal.ROUND_HALF_UP)); + }); + + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + Double onDutyWeight = cockpitConfig.getSecurityWeight().get("onDuty"); + Double levelAssessWeight = cockpitConfig.getSecurityWeight().get("levelAssess"); + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + //1、空数据处理 + if (CollectionUtils.isEmpty(onDutyMap) && CollectionUtils.isEmpty(levelAssessMap)) { + //2个map都空 + map.put("score", "100"); + resultList.add(map); + } else if (CollectionUtils.isEmpty(onDutyMap) || CollectionUtils.isEmpty(levelAssessMap)) { + //2个map有一个为空 + if (CollectionUtils.isEmpty(onDutyMap)) { + if (!Objects.isNull(levelAssessMap.get(date))) { + map.put("score", levelAssessMap.get(date).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + } else { + map.put("score", BigDecimal.valueOf(100 * levelAssessWeight).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + } + } + if (CollectionUtils.isEmpty(levelAssessMap)) { + if (!Objects.isNull(onDutyMap.get(date))) { + map.put("score", onDutyMap.get(date).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + } else { + map.put("score", BigDecimal.valueOf(100 * onDutyWeight).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + } + } + } else if (Objects.isNull(onDutyMap.get(date)) && Objects.isNull(levelAssessMap.get(date))) { + //该日期2个都空 + map.put("score", "100"); + resultList.add(map); + } else if (Objects.isNull(onDutyMap.get(date)) && !Objects.isNull(levelAssessMap.get(date))) { + //2、补全到岗率数据处理 + //该日期onDutyMap空,levelAssessMap不空 + map.put("score", levelAssessMap.get(date).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + resultList.add(map); + } else if (Objects.isNull(levelAssessMap.get(date)) && !Objects.isNull(onDutyMap.get(date))) { + //2、补全安保等级评估数据处理 + //该日期levelAssessMap空,onDutyMap不空 + map.put("score", onDutyMap.get(date).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + resultList.add(map); + } else if (!Objects.isNull(levelAssessMap.get(date)) && !Objects.isNull(onDutyMap.get(date))) { + //该日期2个都不空 + BigDecimal onDutyDecimal = onDutyMap.get(date); + BigDecimal levelAssessDecimal = levelAssessMap.get(date); + map.put("score", onDutyDecimal.add(levelAssessDecimal).stripTrailingZeros().toPlainString()); + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object patrol() { + //近7天安保人员到岗率 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + + List dateCountList = caseInfoMapper.selectDemobilizedCountSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap onDutyMap = new HashMap<>(); + dateCountList.forEach(dateCount -> { + //到岗率 + BigDecimal totalCount = new BigDecimal(total); + BigDecimal leaveCount = new BigDecimal(dateCount.getLeaveCount()); + BigDecimal result = totalCount.subtract(leaveCount).divide(totalCount, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + onDutyMap.put(dateCount.getDate(), result.stripTrailingZeros().toPlainString()); + }); + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + //1、空数据处理 + if (CollectionUtils.isEmpty(onDutyMap) || Objects.isNull(onDutyMap.get(date))) { + map.put("date", date); + map.put("score", "100"); + resultList.add(map); + } else { + map.put("date", date); + map.put("score", onDutyMap.get(date)); + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object other() { + //安全防护评分(所有楼的评分的均值) + List caseInfos = caseInfoMapper.selectByPositionSevenDay(null); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap securityScoreMap = new HashMap<>(); + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + securityScoreDTO1.setDate(caseInfo.getHappenTime().substring(0, caseInfo.getHappenTime().indexOf(" "))); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + securityScoreMap.put(dict.getName(), BigDecimal.valueOf(100)); + } + } else { + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getDate)); + collect.keySet().forEach(key -> { + List list = collect.get(key); + //该日期发生时间的楼栋 + Map> collect3 = list.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + //无评分的楼栋数据补全处理 + if (collect3.size() < devicePosition.size()) { + List collect4 = list.stream().map(SecurityScoreDTO::getPosition).collect(Collectors.toList()); + for (Dict dict : devicePosition) { + String code = dict.getCode(); + if (!collect4.contains(code)) { + SecurityScoreDTO securityScoreDTO = new SecurityScoreDTO(); + securityScoreDTO.setDate(key); + securityScoreDTO.setPosition(code); + securityScoreDTO.setScore(100.0); + list.add(securityScoreDTO); + } + } + } + //该日期所有楼栋扣分和 + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + double sum = collect1.getSum(); + //该日期发生时间的楼栋个数 + Map> collect4 = list.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + int size = collect4.keySet().size(); + //(100*发生事件的楼栋个数-扣分和)/楼栋个数 + BigDecimal securityScore = BigDecimal.valueOf(100).multiply(BigDecimal.valueOf(size)).subtract(BigDecimal.valueOf(sum)).divide(BigDecimal.valueOf(size), 2, BigDecimal.ROUND_HALF_UP); + securityScoreMap.put(key, securityScore); + }); + } + + //设备维修次数(满分一百分,发生一次维修减5分) + //当天设备的维修记录 + HashMap repairMap = new HashMap<>(); + List repairLogs = repairLogMapper.selectListBySevenDay(); + repairLogs.forEach(repair -> { + repair.setRepairEndTime(repair.getRepairEndTime().substring(0, repair.getRepairEndTime().indexOf(" "))); + }); + List dateList = DateUtils.getCurrentDateDayList(); + Map> collect = repairLogs.stream().collect(Collectors.groupingBy(DeviceRepairLog::getRepairEndTime)); + collect.keySet().forEach(key -> { + List deviceRepairLogs = collect.get(key); + //开始时间到结束时间的每天都扣分 + for (DeviceRepairLog log : deviceRepairLogs) { + String startTime = log.getRepairStartTime().substring(0, log.getRepairStartTime().indexOf(" ")); + String endTime = log.getRepairEndTime().substring(0, log.getRepairStartTime().indexOf(" ")); + List betweenDays = DateUtils.getBetweenDays(startTime, endTime); + //包含首尾时间 + Collection intersection = org.apache.commons.collections4.CollectionUtils.intersection(dateList, betweenDays); + if (!CollectionUtils.isEmpty(intersection)) { + for (String date : intersection) { + if (Objects.isNull(repairMap.get(date))) { + //发生一次维修减5分 + repairMap.put(date, BigDecimal.valueOf(100 - 5)); + } else { + BigDecimal old = repairMap.get(date); + repairMap.put(date, old.subtract(BigDecimal.valueOf(5))); + } + } + } + } + }); + //构造结果 + List> resultList = new ArrayList<>(); + BigDecimal repairConfigScore = BigDecimal.valueOf(cockpitConfig.getOtherWeight().get("repair")); + BigDecimal securityConfigScore = BigDecimal.valueOf(cockpitConfig.getOtherWeight().get("security")); + if (CollectionUtils.isEmpty(securityScoreMap)) { + for (String date : dateList) { + securityScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if(CollectionUtils.isEmpty(repairMap)){ + for (String date : dateList) { + repairMap.put(date, BigDecimal.valueOf(100)); + } + } + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + //补全数据处理 + if (Objects.isNull(securityScoreMap.get(date)) && Objects.isNull(repairMap.get(date))) { + //该日期2个都空 + map.put("score", "100"); + } else if (Objects.isNull(securityScoreMap.get(date)) && !Objects.isNull(repairMap.get(date))) { + //该日期securityScoreMap空,repairMap不空 + map.put("score", repairConfigScore.multiply(repairMap.get(date)).add(securityConfigScore.multiply(BigDecimal.valueOf(100))) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } else if (Objects.isNull(repairMap.get(date)) && !Objects.isNull(securityScoreMap.get(date))) { + //该日期securityScoreMap不空,repairMap空 + map.put("score", securityConfigScore.multiply(securityScoreMap.get(date)).add(repairConfigScore.multiply(BigDecimal.valueOf(100))) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } else if (!Objects.isNull(securityScoreMap.get(date)) && !Objects.isNull(repairMap.get(date))) { + //该日期2个都不空 + BigDecimal securityScoreDecimal = securityConfigScore.multiply(securityScoreMap.get(date)); + BigDecimal repairDecimal = repairConfigScore.multiply(repairMap.get(date)); + map.put("score", securityScoreDecimal.add(repairDecimal) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } + resultList.add(map); + }); + return ResponseData.success(resultList); + } + + private List> getForResult(List weekCaseDTOS, List weekCaseKeyAreaDTOS, + List caseInfos, HashMap weekCaseMap, HashMap caseScoreMap, + HashMap keyAreaScoreMap, HashMap assessScoreMap, + List dateList){ + Map keyAreaWeight = cockpitConfig.getKeyAreaWeight(); + weekCaseKeyAreaDTOS.forEach(dto -> { + weekCaseMap.put(dto.getDimension(), BigDecimal.valueOf(dto.getQuantity())); + }); + weekCaseDTOS.forEach(dto -> { + String date = dto.getDimension(); + Integer quantity = dto.getQuantity(); + //无重点区域事件数据,1-安防事件次数/所有安防事件次数=1 + if (Objects.isNull(weekCaseMap.get(date)) || weekCaseMap.get(date).equals(BigDecimal.ZERO)) { + caseScoreMap.put(date, BigDecimal.valueOf(1 * 100)); + } else { + BigDecimal multiply = BigDecimal.valueOf(quantity).subtract(weekCaseMap.get(date)).divide(BigDecimal.valueOf(quantity), 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + caseScoreMap.put(date, multiply); + } + }); + + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + caseInfos.forEach(caseInfo -> { + //重点区域安防事态评估分数 + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double keyAreaScore = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String dayTime = caseInfo.getHappenTime().substring(0, caseInfo.getHappenTime().indexOf(" ")); + BigDecimal preScore; + if (keyAreaScoreMap.containsKey(dayTime)) { + preScore = keyAreaScoreMap.get(dayTime); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(keyAreaScore.toString()); + keyAreaScoreMap.put(dayTime, preScore.subtract(nowScore)); + + //安防机动支援力量响应评估分数 + //扣分=事件级别权重*未解决小时数 + Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); + Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); + long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); + Double assessScore = Double.valueOf(hazardWeight) * between; + BigDecimal preAssessScore; + if (assessScoreMap.containsKey(dayTime)) { + preAssessScore = assessScoreMap.get(dayTime); + } else { + preAssessScore = new BigDecimal("100.0"); + } + BigDecimal nowAssessScore = new BigDecimal(assessScore.toString()); + assessScoreMap.put(dayTime, preAssessScore.subtract(nowAssessScore)); + }); + //构造结果 + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(caseScoreMap)) { + for (String date : dateList) { + caseScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if (CollectionUtils.isEmpty(keyAreaScoreMap)) { + for (String date : dateList) { + keyAreaScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if (CollectionUtils.isEmpty(assessScoreMap)) { + for (String date : dateList) { + assessScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + BigDecimal preCaseScore = Objects.isNull(caseScoreMap.get(date)) ? BigDecimal.valueOf(100) : caseScoreMap.get(date); + BigDecimal preKeyAreaScore = Objects.isNull(keyAreaScoreMap.get(date)) ? BigDecimal.valueOf(100) : keyAreaScoreMap.get(date); + BigDecimal preAssessScore = Objects.isNull(assessScoreMap.get(date)) ? BigDecimal.valueOf(100) : assessScoreMap.get(date); + BigDecimal caseScore = preCaseScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("case"))); + BigDecimal keyAreaScore = preKeyAreaScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("keyArea"))); + BigDecimal responseAssessScore = preAssessScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("responseAssess"))); + map.put("score", caseScore.add(keyAreaScore).add(responseAssessScore).stripTrailingZeros().toPlainString()); + resultList.add(map); + }); + return resultList; + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java index decc60c..2c66ec1 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java @@ -96,7 +96,10 @@ JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人员失败,海康response:{}", resultStr); - return ResponseData.error("单个添加人员失败"); + if("0x00052301".equals(resultJson.get("code"))){ + return ResponseData.error("添加人员身份证号重复!"); + } + return ResponseData.error("单个添加人员失败!"); } JSONObject data = (JSONObject)resultJson.get("data"); String faceId = data.getString("faceId"); @@ -129,13 +132,11 @@ String body = JSONObject.toJSONString(personSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.PERSON_SINGLE_UPDATE, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); + //海康该接口成功返回data为空 if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个修改人员失败,海康response:{}", resultStr); return ResponseData.error("单个修改人员失败"); } - JSONObject data = (JSONObject)resultJson.get("data"); - String faceId = data.getString("faceId"); - staffInfo.setStaffFaceId(faceId); if(staffInfoMapper.updateById(staffInfo) > 0){ return ResponseData.success(); } @@ -265,6 +266,7 @@ @Override public StaffInfo selectStaffInfoByCode(StaffInfo staffInfo) { StaffInfo info = staffInfoMapper.selectByCode(staffInfo.getStaffCode()); + info.setPicture(getPictureFromHik(staffInfo.getStaffCode())); return info; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java index b219984..aa23547 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java @@ -3,7 +3,9 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdcardUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -86,14 +88,21 @@ VisitorInfo visitorInfo = new VisitorInfo(); visitorInfo.setVisitorName(visitorApply.getVisitorName()); - visitorInfo.setGender(Integer.valueOf(visitorApply.getVisitorGender())); + //身份证号确定性别 + int genderByIdCard = IdcardUtil.getGenderByIdCard(visitorApply.getIdCard()); + if(0 == genderByIdCard){ + genderByIdCard = 2; + } + visitorInfo.setGender(genderByIdCard); visitorInfo.setPhoneNo(visitorApply.getVisitorPhone()); visitorInfo.setCertificateNo(visitorApply.getIdCard()); visitorInfo.setCertificateType(111); visitorInfo.setVisitorPhoto(visitorApply.getPicUri()); appointmentFreeRegisterRequest.setVisitorInfo(visitorInfo); - + log.info("--------------------------"); + log.info("请求visitorApply:{}", JSON.toJSONString(visitorApply)); String body = JSONObject.toJSONString(appointmentFreeRegisterRequest); + log.info("请求海康body:{}", body); String resultStr = HikUtil.hikApi(HikUri.APPOINTMENT_FREE_REGISTER, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if(!"0".equals(resultJson.get("code"))){ @@ -129,7 +138,12 @@ appointmentFreeRegisterRequest.setVisitPurpose(visitorApply.getVisitReason()); VisitorInfo visitorInfo = new VisitorInfo(); visitorInfo.setVisitorName(visitorApply.getVisitorName()); - visitorInfo.setGender(Integer.valueOf(visitorApply.getVisitorGender())); + //身份证号确定性别 + int genderByIdCard = IdcardUtil.getGenderByIdCard(visitorApply.getIdCard()); + if(0 == genderByIdCard){ + genderByIdCard = 2; + } + visitorInfo.setGender(genderByIdCard); visitorInfo.setPhoneNo(visitorApply.getVisitorPhone()); visitorInfo.setCertificateNo(visitorApply.getIdCard()); visitorInfo.setCertificateType(111); @@ -165,7 +179,7 @@ VisitorApply visitorApply1 = visitorApplyMapper.selectById(visitorApply.getId()); if(StringUtils.isNotEmpty(visitorApply1.getAppointRecordId())){ List appointRecordIds = new ArrayList<>(); - appointRecordIds.add(visitorApply.getAppointRecordId()); + appointRecordIds.add(visitorApply1.getAppointRecordId()); String body = JSONObject.toJSONString(appointRecordIds); String resultStr = HikUtil.hikApi(HikUri.APPOINTMENT_CANCEL, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); @@ -247,7 +261,12 @@ appointmentFreeRegisterRequest.setVisitPurpose(busConcentrator.getVisitReason()); VisitorInfo visitorInfo = new VisitorInfo(); visitorInfo.setVisitorName(busConcentrator.getVisitorName()); - visitorInfo.setGender(Integer.valueOf(busConcentrator.getVisitorGender())); + //身份证号确定性别 + int genderByIdCard = IdcardUtil.getGenderByIdCard(busConcentrator.getIdCard()); + if(0 == genderByIdCard){ + genderByIdCard = 2; + } + visitorInfo.setGender(genderByIdCard); visitorInfo.setPhoneNo(busConcentrator.getVisitorPhone()); visitorInfo.setCertificateNo(busConcentrator.getIdCard()); visitorInfo.setCertificateType(111); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java b/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java index 109eec2..269e3b0 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java @@ -3,13 +3,11 @@ import cn.hutool.core.date.DateUtil; import javafx.util.Pair; +import org.apache.commons.lang3.StringUtils; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; +import java.util.*; /** * Created by Administrator on 2015/2/25. @@ -113,10 +111,46 @@ public static String getYesterday() { Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DATE, -2); + calendar.add(Calendar.DATE, -2); return sdf_day.format(calendar.getTime()); } + /** + * 包括传入的首尾日期 + */ + public static List getBetweenDays(String startTime, String endTime) { + if (StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)) { + return null; + } + //定义转换格式 + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + Date start = null; + Date end = null; + try { + start = df.parse(startTime); + end = df.parse(endTime); + } catch (ParseException e) { + e.printStackTrace(); + } + if (Objects.isNull(start) || Objects.isNull(end)) { + return null; + } + List result = new ArrayList<>(); + Calendar tempStart = Calendar.getInstance(); + tempStart.setTime(start); + tempStart.add(Calendar.DAY_OF_YEAR, 1); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Calendar tempEnd = Calendar.getInstance(); + tempEnd.setTime(end); + result.add(sdf.format(start)); + while (tempStart.before(tempEnd)) { + result.add(sdf.format(tempStart.getTime())); + tempStart.add(Calendar.DAY_OF_YEAR, 1); + } + result.add(endTime); + return result; + } + public static List getCurrentDateWeekList() { List list = new ArrayList<>(); //获取当前日期前30天的日期 @@ -165,7 +199,21 @@ // Date startDate = org.apache.commons.lang3.time.DateUtils.addDays(now, -7); // String s = DateUtil.formatDate(startDate); // list.add(s); - for (int i = 1; i < 8; i++) { + for (int i = 7; i > 0; i--) { + Date date = org.apache.commons.lang3.time.DateUtils.addDays(now, -i); + String s = DateUtil.formatDate(date); + list.add(s); + } + return list; + } + + /** + * 30天前的7天日期 + */ + public static List getCurrentDateDayBeforeMonthList() { + List list = new ArrayList<>(); + Date now = new Date(); + for (int i = 36; i > 29; i--) { Date date = org.apache.commons.lang3.time.DateUtils.addDays(now, -i); String s = DateUtil.formatDate(date); list.add(s); @@ -187,14 +235,22 @@ public static List getCurrentDateWorkHourList() { List list = new ArrayList<>(); + int hour = DateUtil.thisHour(true); String today = DateUtil.today(); - for (int i = 6; i < 24; i++) { + String substring = today.substring(5); + for (int i = 6; i < hour; i++) { if (i < 10) { - list.add(today + " 0" + i); + list.add(substring + " 0" + i + ":00"); } else { - list.add(today + " " + i); + list.add(substring + " " + i + ":00"); } } return list; } + + public static void main(String[] args) { + List betweenDays = getBetweenDays("2022-10-10", "2022-10-17"); + System.out.println(betweenDays); + + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java index 316188e..71d587d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java @@ -22,4 +22,11 @@ boolean insertCaseInfoBatch(List caseInfos); List caseInfoList(CaseInfoRequest caseInfoRequest); + + List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest); + + Object caseInfoLastByDrawNo(String drawNo); + + int updateAllStatus(); + } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java index b3d1968..7a7fe8a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java @@ -2,6 +2,10 @@ import com.alibaba.fastjson.JSONArray; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import java.util.HashMap; import java.util.List; @@ -13,4 +17,32 @@ */ public interface CockpitService { HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap); + + Object buildingNumberPerHour(); + + Object visitorTodayNumber(); + + Object deviceNumber(); + + Object securityNumber(); + + Object visitorApplyDetail(); + + Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO); + + Object eventCategoryStatistics(); + + Object fireEquipStatistics(); + + Object beOnDutyRatio(); + + Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO); + + Object securityScore(SecurityScoreDTO securityScoreDTO); + + Object securityFrequency(); + + Object areaScore(SecurityScoreDTO securityScoreDTO); + + Object heatMap(HeatMapDTO heatMapDTO); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java new file mode 100644 index 0000000..178b909 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.service; + +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; + +/** + * @Description: + * @Author: wangpeng + * @Date: 2022/10/11 9:10 + */ +public interface PropertyManageService { + Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO); + + Object keyAreaData(String dimension); + + Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO); + + Object attendanceNumber(String dimension); + + Object securityAssessment(String dimension); + + Object keyAreaStatistic(); + + Object responseAssess(); + + Object hazardLevelStatistics(String dimension); + + Object securityRank(); + + Object securityLevelAssess(); + + Object commute(); + + Object keyArea(); + + Object visitor(); + + Object security(); + + Object patrol(); + + Object other(); +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java index ea6b8c0..2580187 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java @@ -17,6 +17,7 @@ import com.casic.missiles.modular.service.BlackInfoService; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -70,11 +71,17 @@ faceInfo.setCertificateNum(blackInfo.getIdCardNo()); faceSingleAddOrUpdateRequest.setFaceInfo(faceInfo); FacePic facePic = new FacePic(); - facePic.setFaceBinaryData(blackInfo.getPicture()); - faceSingleAddOrUpdateRequest.setFacePic(facePic); + String picture = blackInfo.getPicture(); + if(StringUtils.isNotEmpty(picture)){ + String substringPicture = picture.substring(picture.indexOf(",") + 1); + facePic.setFaceBinaryData(substringPicture); + } faceSingleAddOrUpdateRequest.setFacePic(facePic); String body = JSONObject.toJSONString(faceSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.FACE_SINGLE_ADDITION, body); + log.info("-----------------------"); + log.info("增加黑名单人脸请求body,{}", body); + log.info("增加黑名单人脸resultStr:{}", JSONObject.toJSONString(resultStr)); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人脸失败,海康response:{}", resultStr); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java index 6b03d8b..1c34f68 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java @@ -2,17 +2,22 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.dao.CaseInfoMapper; import com.casic.missiles.modular.dao.CategoryLevelMapper; +import com.casic.missiles.modular.dao.DeviceInfoMapper; import com.casic.missiles.modular.dao.HazardLevelMapper; import com.casic.missiles.modular.dto.CaseInfoRequest; import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.model.CaseInfo; +import com.casic.missiles.modular.model.DeviceInfo; import com.casic.missiles.modular.service.CaseInfoService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,6 +31,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; /** * @Description: 安防事件service @@ -50,6 +56,9 @@ @Resource private AbstractDictService dictService; + @Resource + private DeviceInfoMapper deviceInfoMapper; + @Override public List caseInfoListPage(Page page, CaseInfoRequest caseInfoRequest) { try { @@ -136,17 +145,69 @@ @Override public List caseInfoList(CaseInfoRequest caseInfoRequest) { try { - List pageList = caseInfoMapper.getCaseInfoList(caseInfoRequest); - pageList.forEach(caseInfo ->{ + List list = caseInfoMapper.getCaseInfoList(caseInfoRequest); + list.forEach(caseInfo ->{ caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); }); - return pageList; + return list; } catch (DataAccessException ex) { log.error("安防事件: 查询不分页出现异常, 异常:{}", ex); } return null; } + + @Override + public List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest) { + try { + List list = caseInfoMapper.getCaseInfoListUnResolved(caseInfoRequest); + list.forEach(caseInfo ->{ + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + }); + return list; + } catch (DataAccessException ex) { + log.error("未解决/解决中安防事件: 查询不分页出现异常, 异常:{}", ex); + } + return null; + } + + @Override + public Object caseInfoLastByDrawNo(String drawNo) { + //图纸编号和设备编号一一对应 + QueryWrapper dWrapper = new QueryWrapper<>(); + dWrapper.eq("draw_no", drawNo); + DeviceInfo deviceInfo = deviceInfoMapper.selectOne(dWrapper); + if(Objects.isNull(deviceInfo)){ + return ResponseData.error("该图纸编号下不存在关联的设备"); + } + if(StringUtils.isEmpty(deviceInfo.getDevCode())){ + return ResponseData.error("该图纸编号下不存在对应的设备编号"); + }else{ + String devCode = deviceInfo.getDevCode(); + QueryWrapper cWrapper = new QueryWrapper<>(); + cWrapper.eq("device_code", devCode); + List caseInfos = caseInfoMapper.selectList(cWrapper); + if(CollectionUtil.isEmpty(caseInfos)){ + return ResponseData.error("该图纸编号下不存在最近发生的事件"); + } + CaseInfo caseInfo = caseInfos.get(caseInfos.size() - 1); + caseInfo.setDrawNo(deviceInfo.getDrawNo()); + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + return ResponseData.success(caseInfo); + } + } + + @Override + public int updateAllStatus() { + int upflag = caseInfoMapper.updateAllStatus(); + return upflag; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java index 7402991..7fb5a6e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java @@ -4,15 +4,34 @@ import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.*; import com.casic.missiles.modular.enums.HikUri; +import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.redis.RedisUtil; +import com.casic.missiles.modular.redis.key.CacheKeys; import com.casic.missiles.modular.service.CockpitService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import java.text.MessageFormat; +import java.text.NumberFormat; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.*; +import java.util.stream.Collectors; /** * @Description: @@ -22,6 +41,28 @@ @Slf4j @Service public class CockpitServiceImpl implements CockpitService { + @Autowired + private StatisticNumberMapper numberMapper; + @Autowired + private AbstractDictService dictService; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private DeviceInfoMapper deviceInfoMapper; + @Autowired + private FireEquipInfoMapper fireEquipInfoMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private VisitorApplyMapper applyMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private RedisUtil redisUtil; @Override public HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap) { @@ -106,4 +147,512 @@ }); return resultMap; } + + @Override + public Object buildingNumberPerHour() { + //当天按小时分组的人数 + List list = numberMapper.selectListByTime(); + Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); + //定时任务中已将每小时三栋楼人数存到数据库 + //将一期主楼和录制楼人数合并,二期单算 + List> resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List buildingNumberDTOS = collect.get(key); + BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); + BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); + BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); + HashMap resultMap = new HashMap<>(); + Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); + Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); + resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); + resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); + resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); + resultList.add(resultMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object visitorTodayNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); + List visitInfos = visitInfoMapper.selectList(wrapper); + HashMap resultMap = new HashMap<>(); + resultMap.put("今日访客量", visitInfos.size()); + return ResponseData.success(resultMap); + } + + @Override + public Object deviceNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + Integer total = deviceInfoMapper.selectCount(wrapper); + QueryWrapper wrapper1 = new QueryWrapper<>(); + wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 + Integer online = deviceInfoMapper.selectCount(wrapper1); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) online / (float) total * 100); + HashMap resultMap = new HashMap<>(); + resultMap.put("设备总数", total); + resultMap.put("设备在线率", result + "%"); + return ResponseData.success(resultMap); + } + + @Override + public Object securityNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) leave / (float) total * 100); + HashMap resultMap = new HashMap<>(); + if (0 == total) { + resultMap.put("安保人员总数", 0); + resultMap.put("安保人员离岗率", "0"); + } else { + resultMap.put("安保人员总数", total); + resultMap.put("安保人员离岗率", result + ""); + } + return ResponseData.success(resultMap); + } + + @Override + public Object visitorApplyDetail() { + List reasonGroup = applyMapper.selectByVisitReason(); + List resultList = new ArrayList<>(); + //空数据处理 + List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); + if (CollectionUtils.isEmpty(reasonGroup)) { + for (Dict dict : visitReason) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(dict.getName()); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); + if (0 == sum) { + return ResponseData.success(); + } + reasonGroup.forEach(group -> { + String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(group.getQuantity()); + applyReasonGroupDTO.setVisitReason(reasonName); + applyReasonGroupDTO.setRatio(result + "%"); + resultList.add(applyReasonGroupDTO); + }); + //返回数据补全处理 + if (resultList.size() < visitReason.size()) { + List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); + for (Dict dict : visitReason) { + String name = dict.getName(); + if (!collect.contains(name)) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(name); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO) { + //查询各危险级别权重name,用于构造返回结构 + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); + + Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); + List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(list)) { + Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + //查询数据,放入redis + List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); + Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //设置过期时间为每月1号0点 + LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) + .withMinute(0).withSecond(0).withNano(0); + long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); + redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + + @Override + public Object eventCategoryStatistics() { + List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); + return ResponseData.success(categoryLevelGroup); + } + + @Override + public Object fireEquipStatistics() { + List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); + //空数据处理 + List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); + if (CollectionUtils.isEmpty(equipTypeGroup)) { + for (Dict dict : equipType) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + return ResponseData.success(equipTypeGroup); + } + equipTypeGroup.forEach(group -> { + String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); + group.setEquipTypeName(equipTypeName); + }); + //返回数据补全处理 + if (equipTypeGroup.size() < equipType.size()) { + List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); + for (Dict dict : equipType) { + String code = dict.getCode(); + if (!collect.contains(code)) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + } + } + return ResponseData.success(equipTypeGroup); + } + + @Override + public Object beOnDutyRatio() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + if (0 == total) { + return ResponseData.success(null); + } + List currentDateHourList = DateUtils.getCurrentDateWorkHourList(); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + //补全空数据 + if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { + for (String date : currentDateHourList) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + return ResponseData.success(onDutyRatioDTOS); + } + onDutyRatioDTOS.forEach(dto -> { + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); + dto.setRatio(result + "%"); + }); + //补全空数据 + List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); + for (String date : currentDateHourList) { + if (!collect.contains(date)) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + } + return ResponseData.success(onDutyRatioDTOS); + } + + @Override + public Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO) { + List gateStatusGroup = null; + //2代表所有摄像头(对应字典2-7) + if ("2".equals(gateStatusGroupDTO.getDevType())) { + gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); + } else { + gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); + } + HashMap resultMap = new HashMap<>(); + //空数据处理 + List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); + if (CollectionUtils.isEmpty(gateStatusGroup)) { + List resultList = new ArrayList<>(); + for (Dict dict : deviceStatus) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + resultMap.put("total", 0); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("无该类设备信息"); + } + List resultList = new ArrayList<>(); + gateStatusGroup.forEach(group -> { + if ("2".equals(gateStatusGroupDTO.getDevType())) { + group.setDevType("2"); + } + String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(devStatus); + gateStatusGroupResponse.setRatio(result + "%"); + gateStatusGroupResponse.setQuantity(group.getQuantity()); + resultList.add(gateStatusGroupResponse); + }); + //返回数据补全处理 + if (resultList.size() < deviceStatus.size()) { + List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); + for (Dict dict : deviceStatus) { + String name = dict.getName(); + if (!collect.contains(name)) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + } + } + resultMap.put("total", sum); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + + @Override + public Object securityScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的position划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + List caseInfos = caseInfoMapper.selectByPosition(position); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //楼栋-评分实体map + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + Map resultMap = new HashMap<>(); + //空数据处理 + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + resultMap.put(dict.getName(), 100.0); + } + return ResponseData.success(resultMap); + } + + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + + collect.keySet().forEach(key -> { + List list = collect.get(key); + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); + resultMap.put(dictValue, 100 - collect1.getSum()); + }); + //返回数据补全处理 + if (collect.size() < devicePosition.size()) { + Set strings = resultMap.keySet(); + for (Dict dict : devicePosition) { + String name = dict.getName(); + if (!strings.contains(name)) { + resultMap.put(dict.getName(), 100.0); + } + } + } + //按楼层分组计算评分 +// collect.keySet().forEach(key -> { +// Map map = new HashMap<>(); +// List securityScoreDTOS = collect.get(key); +// //楼层-评分map +// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); +// collect1.keySet().forEach(key1 -> { +// map.put(key1, 100 - collect1.get(key1)); +// }); +// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); +// resultMap.put(dictValue, map); +// }); + return ResponseData.success(resultMap); + } + + @Override + public Object securityFrequency() { + String year = String.valueOf(DateUtil.thisYear()); + String month = String.valueOf(DateUtil.thisMonth()); + Integer quantity = caseInfoMapper.selectCountByMonth(year, month); + SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); + securityFrequencyDTO.setQuantity(quantity); + securityFrequencyDTO.setYear(year); + securityFrequencyDTO.setMonth(month); + return ResponseData.success(securityFrequencyDTO); + } + + @Override + public Object areaScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的area划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + String area = securityScoreDTO.getArea(); + if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { + return null; + } + Map resultMap = new HashMap<>(); + List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); + if (Objects.isNull(caseInfos)) { + resultMap.put("安防评分", 100.0); + return ResponseData.success(resultMap); + } + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + resultMap.put("安防评分", 100 - collect.getSum()); + return ResponseData.success(resultMap); + } + + @Override + public Object heatMap(HeatMapDTO heatMapDTO) { + if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { + heatMapDTO.setMinute(3); + } + List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); + Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); + HashMap resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect)) { + return ResponseData.success(); + } + collect.keySet().forEach(key -> { + resultMap.put(key, collect.get(key).size()); + }); + return ResponseData.success(resultMap); + } + + private List> getResultMap(List nameList, List> resultList, Map> resultMap) { + resultMap.keySet().forEach(key -> { + List monthAndLevelGroupDTOS = resultMap.get(key); + HashMap hashMap = new HashMap<>(); + for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { +// hashMap.put("年份", andLevelGroupDTO.getYear()); + hashMap.put("月份", /*andLevelGroupDTO.getYear() + "-" + */Integer.valueOf(andLevelGroupDTO.getMonth())); + hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); + } + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + }); + //12个月份,用于构造返回结构 + List list1 = new ArrayList<>(); + for (Map map : resultList) { + list1.add(String.valueOf(map.get("月份"))); + } + for (int i = 1; i < 13; i++) { + if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { + continue; + } + HashMap hashMap = new HashMap<>(); + hashMap.put("月份", i); + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + } + List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); + return results; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java index 94308db..f91d7bd 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java @@ -427,6 +427,13 @@ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("draw_no", drawNo); DeviceInfo deviceInfo = deviceInfoMapper.selectOne(wrapper); + if(!Objects.isNull(deviceInfo)){ + deviceInfo.setDevTypeName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_TYPE, deviceInfo.getDevType())); + deviceInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, deviceInfo.getStatus())); + deviceInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, deviceInfo.getPosition())); + deviceInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, deviceInfo.getArea())); + deviceInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, deviceInfo.getIsKeyArea())); + } return deviceInfo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java index 8ed53d9..c399a7f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java @@ -11,6 +11,7 @@ import com.casic.missiles.modular.service.HikService; import com.casic.missiles.modular.system.model.Dict; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -50,8 +51,11 @@ @Override public CaseInfo blackListHandle(JSONObject event, CaseInfo caseInfo) { - String srcIndex = event.getString("srcIndex"); //海康资源唯一标识 + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 String happenTimeISO = String.valueOf(event.get("happenTime")); + DateTime parse = DateUtil.parse(happenTimeISO); String happenTime = DateUtil.formatDateTime(parse); caseInfo.setHappenTime(happenTime); //发生时间 @@ -89,6 +93,16 @@ log.info("接收到离岗事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //离岗事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray leavePosition = data.getJSONArray("leavePosition"); + if(StringUtils.isNotEmpty(leavePosition.getString(0))){ + JSONObject jsonObject = leavePosition.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -115,6 +129,16 @@ log.info("接收到人员聚集事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //人员聚集事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray group = data.getJSONArray("group"); + if(StringUtils.isNotEmpty(group.getString(0))){ + JSONObject jsonObject = group.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -263,8 +287,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void propertyAttendanceHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); @@ -309,8 +334,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void securityPersonnelHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java new file mode 100644 index 0000000..4427f19 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java @@ -0,0 +1,1255 @@ +package com.casic.missiles.modular.service.impl; + +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.config.CockpitConfig; +import com.casic.missiles.modular.dao.*; +import com.casic.missiles.modular.dto.statistics.*; +import com.casic.missiles.modular.enums.SecurityEventDict; +import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.service.PropertyManageService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.text.NumberFormat; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @Description: 驾驶舱二级页面-物管信息 + * @Author: wangpeng + * @Date: 2022/10/11 9:11 + */ +@Slf4j +@Service +public class PropertyManageServiceImpl implements PropertyManageService { + @Autowired + private AttendanceInfoMapper attendanceInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private DeviceRepairLogMapper repairLogMapper; + @Autowired + private CockpitConfig cockpitConfig; + @Autowired + private AbstractDictService dictService; + + @Override + public Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO) { + //各类型员工及总数 + List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); + Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); + + String dateDimension = attendanceRatioDTO.getDateDimension(); + List attendanceRatioDTOS = new ArrayList<>(); + List dateList = null; + //考勤的人数,按单次考勤过滤 + if ("week".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); + dateList = DateUtils.getCurrentDateDayList(); + } else if ("month".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); + dateList = DateUtils.getCurrentDateWeekList(); + } else if ("year".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); + dateList = DateUtils.getCurrentDateMonthList(); + } + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { + for (String date : dateList) { + HashMap hashMap = new HashMap<>(); + hashMap.put("date", date); + hashMap.put("property", "0%"); + hashMap.put("security", "0%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + //计算出勤率 + Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); + + dateList.forEach(date -> { + HashMap hashMap = new HashMap<>(); + if (CollectionUtils.isEmpty(dateMap.get(date))) { + hashMap.put("date", date); + hashMap.put("property", "0%"); + hashMap.put("security", "0%"); + resultList.add(hashMap); + } else { + List attendances = dateMap.get(date); + attendances.forEach(attendanceRatio -> { + attendanceRatio.setDateDimension(dateDimension); + attendanceRatio.setStaffType(attendanceRatio.getStaffType()); + List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); + String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); + attendanceRatio.setAttendanceRatio(ratio + "%"); + //构造返回结构 + hashMap.put("date", attendanceRatio.getDate()); +// String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); + if ("1".equals(attendanceRatio.getStaffType())) { + hashMap.put("property", attendanceRatio.getAttendanceRatio()); + } + if ("2".equals(attendanceRatio.getStaffType())) { + hashMap.put("security", attendanceRatio.getAttendanceRatio()); + } + }); + //补全缺少数据 + if (1 == attendances.size()) { + AttendanceRatioDTO attendanceRatioDTO1 = attendances.get(0); + if ("1".equals(attendanceRatioDTO1.getStaffType())) { + hashMap.put("security", "0%"); + } + if ("2".equals(attendanceRatioDTO1.getStaffType())) { + hashMap.put("property", "0%"); + } + } + resultList.add(hashMap); + } + }); + return ResponseData.success(resultList); + + } + + @Override + public Object keyAreaData(String dimension) { + List resultList = null; + List dateList = null; + if ("year".equals(dimension)) { + //近365天数据按月分组统计 + resultList = caseInfoMapper.selectPreMonthCountByNearYear(); + dateList = DateUtils.getCurrentDateMonthList(); + } else if ("month".equals(dimension)) { + //近30天数据按周分组统计 + resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); + dateList = DateUtils.getCurrentDateWeekList(); + } else if ("week".equals(dimension)) { + //近7天数据按天分组统计 + resultList = caseInfoMapper.selectPreDayCountBySevenDay(); + dateList = DateUtils.getCurrentDateDayList(); + } + //补全空数据处理 + if (CollectionUtils.isEmpty(resultList)) { + for (String date : dateList) { + PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); + preMonthOrWeekCaseDTO.setDimension(date); + preMonthOrWeekCaseDTO.setQuantity(0); + resultList.add(preMonthOrWeekCaseDTO); + } + } else { + for (String date : dateList) { + List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); + if (!collect.contains(date)) { + PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); + preMonthOrWeekCaseDTO.setDimension(date); + preMonthOrWeekCaseDTO.setQuantity(0); + resultList.add(preMonthOrWeekCaseDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { + String year = avgMonthAndWeekGroupDTO.getYear(); + List monthList = caseInfoMapper.selectPreMonthCountByYear(year); + Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); + HashMap strAvgMap = new HashMap<>(); + List resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List preMonthOrWeekCaseDTOS = collect.get(key); + int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); + //若年份是本年,则使用各安防级别数量/当前月份数 + //若不是本年,除数为12 + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + if (year.equals(String.valueOf(DateUtil.thisYear()))) { + monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); + strAvgMap.put(key, monthAndWeekDTO); + } else { + monthAndWeekDTO.setMonthQuantity(sum / 12); + strAvgMap.put(key, monthAndWeekDTO); + } + } + + List weekList = caseInfoMapper.selectPreWeekCountByYear(year); + Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); + for (String key : collect1.keySet()) { + List preMonthOrWeekCaseDTOS = collect.get(key); + int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); + if (year.equals(String.valueOf(DateUtil.thisYear()))) { + if (!Objects.isNull(strAvgMap.get(key))) { + MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); + strAvgMap.put(key, monthAndWeekDTO); + } else { + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); + strAvgMap.put(key, monthAndWeekDTO); + } + } else { + if (!Objects.isNull(strAvgMap.get(key))) { + MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / 52); + strAvgMap.put(key, monthAndWeekDTO); + } else { + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / 52); + strAvgMap.put(key, monthAndWeekDTO); + } + } + } + strAvgMap.keySet().forEach(key -> { + resultList.add(strAvgMap.get(key)); + }); + //输出顺序 + Collections.swap(resultList, 1, 2); + return ResponseData.success(resultList); + } + + @Override + public Object attendanceNumber(String dimension) { + List attendanceNumberDTOs = null; + List> resultList = new ArrayList<>(); + List dateList = new ArrayList<>(); + if ("week".equals(dimension)) { + //近7天数据按天分组统计 + attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); + dateList = DateUtils.getCurrentDateDayList(); + } else if ("day".equals(dimension)) { + //今天数据按小时分组统计 + attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); + dateList = DateUtils.getCurrentDateWorkHourList(); + } + if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { + for (String date : dateList) { + HashMap hashMap = new HashMap<>(); + hashMap.put("staticTime", date); + hashMap.put("1", "0"); + hashMap.put("2", "0"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); + if ("day".equals(dimension)) { + collect = collect.entrySet().stream().collect(Collectors.toMap(m -> m.getKey().substring(5) + ":00", Map.Entry::getValue)); + } + + for (String date : dateList) { + Map resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect.get(date))) { + resultMap.put("1", "0"); + resultMap.put("2", "0"); + resultMap.put("staticTime", date); + resultList.add(resultMap); + } else { + List attendanceNumberDTOS = collect.get(date); +// Map resultMap = new HashMap<>(); + AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); + if (attendanceNumberDTOS.size() >= 2) { + AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); + resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); + } + resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); + resultMap.put("staticTime", date); + resultList.add(resultMap); + //补全map缺少数据 + if (!resultMap.containsKey("1")) { + resultMap.put("1", "0"); + } + if (!resultMap.containsKey("2")) { + resultMap.put("2", "0"); + } + } + } + +// +// collect.keySet().forEach(key -> { +// List attendanceNumberDTOS = collect.get(key); +// Map resultMap = new HashMap<>(); +// AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); +// if (attendanceNumberDTOS.size() >= 2) { +// AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); +// resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); +// } +// resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); +// resultMap.put("staticTime", attendanceNumberDTO.getDate().substring(5) + ":00"); +// resultList.add(resultMap); +// }); +// //补全空数据处理 +// if (CollectionUtils.isEmpty(resultList)) { +// for (String date : dateList) { +// Map resultMap = new HashMap<>(); +// resultMap.put("1", "0"); +// resultMap.put("2", "0"); +// resultMap.put("staticTime", date); +// resultList.add(resultMap); +// } +// } else { +// List collectList = new ArrayList<>(); +// for (Map map : resultList) { +// String staticTime = map.get("staticTime"); +// collectList.add(staticTime); +// //补全map缺少数据 +// if (!map.containsKey("1")) { +// map.put("1", "0"); +// } +// if (!map.containsKey("2")) { +// map.put("2", "0"); +// } +// } +// for (String date : dateList) { +// if (!collectList.contains(date)) { +// Map resultMap = new HashMap<>(); +// resultMap.put("1", "0"); +// resultMap.put("2", "0"); +// resultMap.put("staticTime", date); +// resultList.add(resultMap); +// } +// } +// } + return ResponseData.success(resultList); + } + + @Override + public Object securityAssessment(String dimension) { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + if ("week".equals(dimension)) { + //近7天早晚高峰数据 + List caseInfos = caseInfoMapper.selectListBySevenDay(); + //按时间(天)进行分组 + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(" "); + String dayTime = array[0]; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } else if ("day".equals(dimension)) { + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDatePeakHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + + } + return null; + } + + @Override + public Object keyAreaStatistic() { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday2(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + dayTime = dayTime.substring(5) + ":00"; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } + + @Override + public Object responseAssess() { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday3(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + //扣分=事件级别权重*未解决小时数 + Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); + Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); + long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); + Double score = Double.valueOf(hazardWeight) * between; + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + dayTime = dayTime.substring(5) + ":00"; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } + + @Override + public Object hazardLevelStatistics(String dimension) { + List hazardLevelGroup = null; + if ("week".equals(dimension)) { + hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); + } else if ("month".equals(dimension)) { + hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); + } + if (CollectionUtils.isEmpty(hazardLevelGroup)) { + log.info("重点区域威胁事件类型统计,无安防事件"); + return ResponseData.error("无安防事件发生!"); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("安防事件总数为0"); + } + hazardLevelGroup.forEach(group -> { + CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); + group.setLevelName(caseHazardLevel.getName()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + group.setLevelRatio(result + "%"); + }); + HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); + hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); + hazardLevelGroupResponse.setQuantity(sum); + return ResponseData.success(hazardLevelGroupResponse); + } + + @Override + public Object securityRank() { + //考勤表近一个月按人员分组的考勤个数前十名 + List list = attendanceInfoMapper.getCountForRank(); + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(list)) { + //补全空数据处理 + List staffList = staffInfoMapper.selectListLimitTen(); + for (StaffInfo staffInfo : staffList) { + HashMap hashMap = new HashMap<>(); + hashMap.put(staffInfo.getStaffName(), "0%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + //构造返回结构 + for (SecurityRankDTO dto : list) { + // TODO: 2022/9/15 分母使用30,后续看产品定义 + HashMap hashMap = new HashMap<>(); + String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); + hashMap.put("name", dto.getStaffName()); + hashMap.put("ratio", result + "%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object securityLevelAssess() { + //今天数据按小时分组统计 + List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + if (CollectionUtils.isEmpty(resultList)) { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); + levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); + levelAssessDTO.setDate(date); +// levelAssessDTO.setQuantity(); + resultList.add(levelAssessDTO); + } + return ResponseData.success(resultList); + } + resultList.forEach(result -> { + result.setDate(result.getDate().substring(5) + ":00"); + BigDecimal deScore = new BigDecimal(result.getQuantity()); + BigDecimal preScore = new BigDecimal("100.0"); + result.setScore(preScore.subtract(deScore).doubleValue()); + }); + //数据补全处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + for (SecurityLevelAssessDTO levelAssessDTO : resultList) { + String substring = levelAssessDTO.getDate().substring(5) + ":00"; + if (!substring.equals(date)) { + SecurityLevelAssessDTO levelAssess = new SecurityLevelAssessDTO(); + levelAssess.setScore(new BigDecimal("100.0").doubleValue()); + levelAssess.setDate(date); + resultList.add(levelAssess); + break; + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object commute() { + //早晚高峰区域安防评估 + ResponseData assessResultJson = (ResponseData) this.securityAssessment("week"); + if (Objects.isNull(assessResultJson) || 200 != assessResultJson.getCode()) { + return assessResultJson; + } + JSONArray assessData = JSONArray.parseArray(JSON.toJSONString(assessResultJson.getData())); + //所有类型的员工出勤 + List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); + long sum = staffTypeAndSumDTOS.stream().collect(Collectors.summarizingInt(StaffTypeAndSumDTO::getSum)).getSum(); + List countByTypeAndDateForWeek = attendanceInfoMapper.getCountByTypeAndDateForWeek(); + Map> dateMap = countByTypeAndDateForWeek.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); + HashMap attendanceMap = new HashMap<>(); + dateMap.keySet().forEach(key -> { + List attendanceRatioDTOS = dateMap.get(key); + //当天所有类型的员工的出勤人数 + long sum1 = attendanceRatioDTOS.stream().collect(Collectors.summarizingInt(AttendanceRatioDTO::getQuantity)).getSum(); + //出勤占比评分 + Double attendanceRatio = ((float) sum1 / (float) sum) * 100 * cockpitConfig.getCommuteWeight(); + attendanceMap.put(key, attendanceRatio); + }); + //构造结果 + List> resultList = new ArrayList<>(); + Iterator iterator = assessData.stream().iterator(); + while (iterator.hasNext()) { + JSONObject next = (JSONObject) iterator.next(); + String date = next.getString("date"); + HashMap map = new HashMap<>(); + //计算评分 + Double assessRatio = next.getInteger("score") * (1 - cockpitConfig.getCommuteWeight()); + NumberFormat numberFormat = NumberFormat.getInstance(); + numberFormat.setMaximumFractionDigits(2); + if (!Objects.isNull(attendanceMap.get(date))) { + Double attendanceRatio = attendanceMap.get(date); + Double r = assessRatio + attendanceRatio; + map.put("score", numberFormat.format(r)); + } else { + //无员工出勤率(出勤为0),只有安防评估分值 + map.put("score", numberFormat.format(assessRatio)); + } + map.put("date", date); + resultList.add(map); + } + return ResponseData.success(resultList); + } + + @Override + public Object keyArea() { + //1-重点区域安防事件次数/所有安防事件次数 + //获取近7天每天的安防事件个数,所有和重点区域 + List weekCaseDTOS = caseInfoMapper.selectPreDayCountBySevenDay(); + List weekCaseKeyAreaDTOS = caseInfoMapper.selectPreDayCountBySevenDayKeyArea(); + List caseInfos = caseInfoMapper.selectListBySevenDayKeyArea(); + HashMap weekCaseMap = new HashMap<>(); + HashMap caseScoreMap = new HashMap<>(); + HashMap keyAreaScoreMap = new HashMap<>(); + HashMap assessScoreMap = new HashMap<>(); + List dateList = DateUtils.getCurrentDateDayList(); + List> result = getForResult(weekCaseDTOS, weekCaseKeyAreaDTOS, caseInfos, weekCaseMap, caseScoreMap, + keyAreaScoreMap, assessScoreMap, dateList); + + //上个月对应数据 + List beforeMonthKeyAreaCaseDTOS = caseInfoMapper.selectPreDayCountByBeforeMonthKeyArea(); + List beforeMonthCaseDTOS = caseInfoMapper.selectPreDayCountByBeforeMonth(); + List beforeMonthCaseInfos = caseInfoMapper.selectListByBeforeMonthKeyArea(); + HashMap beforeMonthWeekCaseMap = new HashMap<>(); + HashMap beforeMonthCaseScoreMap = new HashMap<>(); + HashMap beforeMonthKeyAreaScoreMap = new HashMap<>(); + HashMap beforeMonthAssessScoreMap = new HashMap<>(); + List beforeMonthDateList = DateUtils.getCurrentDateDayBeforeMonthList(); + List> resultBeforeMonth = getForResult(beforeMonthCaseDTOS, beforeMonthKeyAreaCaseDTOS, beforeMonthCaseInfos, + beforeMonthWeekCaseMap, beforeMonthCaseScoreMap, beforeMonthKeyAreaScoreMap, beforeMonthAssessScoreMap, beforeMonthDateList); + //计算环比 + for (int i = 0; i < result.size(); i++) { + Map resultMap = result.get(i); + Map resultBeforeMonthMap = resultBeforeMonth.get(i); + BigDecimal resultScore = BigDecimal.valueOf(Double.valueOf(String.valueOf(resultMap.get("score")))); + BigDecimal resultBeforeMonthScore = BigDecimal.valueOf(Double.valueOf(String.valueOf(resultBeforeMonthMap.get("score")))); + BigDecimal finalResult = resultScore.subtract(resultBeforeMonthScore).divide(resultBeforeMonthScore, 2, BigDecimal.ROUND_HALF_UP); + resultMap.put("ringRatio", finalResult); + } + return ResponseData.success(result); + } + + @Override + public Object visitor() { + //查询每天的访客对应的离开记录(进入记录存在且在申请范围内) + //近7天主要使用申请离开时间(申请进入时间不会影响扣分) + List list = visitInfoMapper.selectListBySevenDay(); + list.stream().forEach(visit -> { + DateTime dateTime = DateUtil.parseDateTime(visit.getApplyOutTime()); + String formatDate = DatePattern.NORM_DATE_FORMAT.format(dateTime); + visit.setDate(formatDate); + }); + Map> dateVisitMap = list.stream().collect(Collectors.groupingBy(MultiScoreVisitorDTO::getDate)); + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + HashMap deductMap = new HashMap<>(); //扣分使用 + dateList.forEach(date -> { + //1、空数据处理 + if (CollectionUtils.isEmpty(dateVisitMap)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } else if (CollectionUtils.isEmpty(dateVisitMap.get(date))) { + //2、补全数据处理 + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } else { + //3、计算数据处理 + //计算分数(未在申请时间段内离开减分(包括无离开时间和有离开时间两种情况)、未在申请区域内离开减分),配置扣分,配置每个访客最高扣分 + List multiScoreVisitorDTOS = dateVisitMap.get(date); + //遍历访客 + for (MultiScoreVisitorDTO visitorDTO : multiScoreVisitorDTOS) { + //无离开时间 + if (StringUtils.isEmpty(visitorDTO.getOutTime())) { + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + cockpitConfig.getVisitorWeight().get("NoRecordPointDeduct")); + } else { + deductMap.put(date, cockpitConfig.getVisitorWeight().get("NoRecordPointDeduct")); + } + } else { +// DateTime applyInDateTime = DateUtil.parseDateTime(visitorDTO.getApplyInTime()); + DateTime applyOutDateTime = DateUtil.parseDateTime(visitorDTO.getApplyOutTime()); + DateTime outDateTime = DateUtil.parseDateTime(visitorDTO.getOutTime()); + //未在申请时间段离开(在申请离开时间后离开) + if (DateUtil.compare(outDateTime, applyOutDateTime) > 0) { + long betweenHour = DateUtil.between(outDateTime, applyOutDateTime, DateUnit.HOUR); + Double score = betweenHour * cockpitConfig.getVisitorWeight().get("singlePointDeduct"); + //该访客扣分到达最多分 + if (score >= cockpitConfig.getVisitorWeight().get("mostPointDeduct")) { + score = cockpitConfig.getVisitorWeight().get("mostPointDeduct"); + } + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + score); + } else { + deductMap.put(date, score); + } + } + //未在申请区域离开 + if (StringUtils.isNotEmpty(visitorDTO.getApplyVisitPosition()) && !visitorDTO.getApplyVisitPosition().equals(visitorDTO.getVisitPosition())) { + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + cockpitConfig.getVisitorWeight().get("singlePointDeduct")); + } else { + deductMap.put(date, cockpitConfig.getVisitorWeight().get("singlePointDeduct")); + } + } + + } + } + //添加到结果list + HashMap map = new HashMap<>(); + map.put("date", date); + if (!Objects.isNull(deductMap.get(date))) { + //最少0分 + if (deductMap.get(date) >= 100) { + map.put("score", 0); + } else { + map.put("score", 100 - deductMap.get(date)); + } + } else { + map.put("score", 100); + } + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object security() { + //安保人员到岗率*100*权重0.5 + //近7天安保人员到岗率 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + + List dateCountList = caseInfoMapper.selectDemobilizedCountSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap onDutyMap = new HashMap<>(); + dateCountList.forEach(dateCount -> { + //到岗率 + BigDecimal totalCount = new BigDecimal(total); + BigDecimal leaveCount = new BigDecimal(dateCount.getLeaveCount()); + BigDecimal result = totalCount.subtract(leaveCount).divide(totalCount, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + onDutyMap.put(dateCount.getDate(), result.multiply(BigDecimal.valueOf(cockpitConfig.getSecurityWeight().get("onDuty"))).setScale(2, BigDecimal.ROUND_HALF_UP)); + }); + + //安保等级评估均值*权重0.5 + List levelAssessList = caseInfoMapper.selectListByTypeSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap levelAssessMap = new HashMap<>(); + levelAssessList.forEach(levelAssess -> { + //6-23点共17小时,100-该天扣分/17 + BigDecimal deScore = new BigDecimal(levelAssess.getQuantity()); + BigDecimal preScore = new BigDecimal("100.0"); + BigDecimal divide = deScore.divide(BigDecimal.valueOf(17), 2, BigDecimal.ROUND_HALF_UP); + BigDecimal result = preScore.subtract(divide); + levelAssessMap.put(levelAssess.getDate(), result.multiply(BigDecimal.valueOf(cockpitConfig.getSecurityWeight().get("levelAssess"))).setScale(2, BigDecimal.ROUND_HALF_UP)); + }); + + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + Double onDutyWeight = cockpitConfig.getSecurityWeight().get("onDuty"); + Double levelAssessWeight = cockpitConfig.getSecurityWeight().get("levelAssess"); + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + //1、空数据处理 + if (CollectionUtils.isEmpty(onDutyMap) && CollectionUtils.isEmpty(levelAssessMap)) { + //2个map都空 + map.put("score", "100"); + resultList.add(map); + } else if (CollectionUtils.isEmpty(onDutyMap) || CollectionUtils.isEmpty(levelAssessMap)) { + //2个map有一个为空 + if (CollectionUtils.isEmpty(onDutyMap)) { + if (!Objects.isNull(levelAssessMap.get(date))) { + map.put("score", levelAssessMap.get(date).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + } else { + map.put("score", BigDecimal.valueOf(100 * levelAssessWeight).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + } + } + if (CollectionUtils.isEmpty(levelAssessMap)) { + if (!Objects.isNull(onDutyMap.get(date))) { + map.put("score", onDutyMap.get(date).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + } else { + map.put("score", BigDecimal.valueOf(100 * onDutyWeight).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + } + } + } else if (Objects.isNull(onDutyMap.get(date)) && Objects.isNull(levelAssessMap.get(date))) { + //该日期2个都空 + map.put("score", "100"); + resultList.add(map); + } else if (Objects.isNull(onDutyMap.get(date)) && !Objects.isNull(levelAssessMap.get(date))) { + //2、补全到岗率数据处理 + //该日期onDutyMap空,levelAssessMap不空 + map.put("score", levelAssessMap.get(date).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + resultList.add(map); + } else if (Objects.isNull(levelAssessMap.get(date)) && !Objects.isNull(onDutyMap.get(date))) { + //2、补全安保等级评估数据处理 + //该日期levelAssessMap空,onDutyMap不空 + map.put("score", onDutyMap.get(date).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + resultList.add(map); + } else if (!Objects.isNull(levelAssessMap.get(date)) && !Objects.isNull(onDutyMap.get(date))) { + //该日期2个都不空 + BigDecimal onDutyDecimal = onDutyMap.get(date); + BigDecimal levelAssessDecimal = levelAssessMap.get(date); + map.put("score", onDutyDecimal.add(levelAssessDecimal).stripTrailingZeros().toPlainString()); + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object patrol() { + //近7天安保人员到岗率 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + + List dateCountList = caseInfoMapper.selectDemobilizedCountSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap onDutyMap = new HashMap<>(); + dateCountList.forEach(dateCount -> { + //到岗率 + BigDecimal totalCount = new BigDecimal(total); + BigDecimal leaveCount = new BigDecimal(dateCount.getLeaveCount()); + BigDecimal result = totalCount.subtract(leaveCount).divide(totalCount, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + onDutyMap.put(dateCount.getDate(), result.stripTrailingZeros().toPlainString()); + }); + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + //1、空数据处理 + if (CollectionUtils.isEmpty(onDutyMap) || Objects.isNull(onDutyMap.get(date))) { + map.put("date", date); + map.put("score", "100"); + resultList.add(map); + } else { + map.put("date", date); + map.put("score", onDutyMap.get(date)); + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object other() { + //安全防护评分(所有楼的评分的均值) + List caseInfos = caseInfoMapper.selectByPositionSevenDay(null); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap securityScoreMap = new HashMap<>(); + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + securityScoreDTO1.setDate(caseInfo.getHappenTime().substring(0, caseInfo.getHappenTime().indexOf(" "))); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + securityScoreMap.put(dict.getName(), BigDecimal.valueOf(100)); + } + } else { + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getDate)); + collect.keySet().forEach(key -> { + List list = collect.get(key); + //该日期发生时间的楼栋 + Map> collect3 = list.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + //无评分的楼栋数据补全处理 + if (collect3.size() < devicePosition.size()) { + List collect4 = list.stream().map(SecurityScoreDTO::getPosition).collect(Collectors.toList()); + for (Dict dict : devicePosition) { + String code = dict.getCode(); + if (!collect4.contains(code)) { + SecurityScoreDTO securityScoreDTO = new SecurityScoreDTO(); + securityScoreDTO.setDate(key); + securityScoreDTO.setPosition(code); + securityScoreDTO.setScore(100.0); + list.add(securityScoreDTO); + } + } + } + //该日期所有楼栋扣分和 + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + double sum = collect1.getSum(); + //该日期发生时间的楼栋个数 + Map> collect4 = list.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + int size = collect4.keySet().size(); + //(100*发生事件的楼栋个数-扣分和)/楼栋个数 + BigDecimal securityScore = BigDecimal.valueOf(100).multiply(BigDecimal.valueOf(size)).subtract(BigDecimal.valueOf(sum)).divide(BigDecimal.valueOf(size), 2, BigDecimal.ROUND_HALF_UP); + securityScoreMap.put(key, securityScore); + }); + } + + //设备维修次数(满分一百分,发生一次维修减5分) + //当天设备的维修记录 + HashMap repairMap = new HashMap<>(); + List repairLogs = repairLogMapper.selectListBySevenDay(); + repairLogs.forEach(repair -> { + repair.setRepairEndTime(repair.getRepairEndTime().substring(0, repair.getRepairEndTime().indexOf(" "))); + }); + List dateList = DateUtils.getCurrentDateDayList(); + Map> collect = repairLogs.stream().collect(Collectors.groupingBy(DeviceRepairLog::getRepairEndTime)); + collect.keySet().forEach(key -> { + List deviceRepairLogs = collect.get(key); + //开始时间到结束时间的每天都扣分 + for (DeviceRepairLog log : deviceRepairLogs) { + String startTime = log.getRepairStartTime().substring(0, log.getRepairStartTime().indexOf(" ")); + String endTime = log.getRepairEndTime().substring(0, log.getRepairStartTime().indexOf(" ")); + List betweenDays = DateUtils.getBetweenDays(startTime, endTime); + //包含首尾时间 + Collection intersection = org.apache.commons.collections4.CollectionUtils.intersection(dateList, betweenDays); + if (!CollectionUtils.isEmpty(intersection)) { + for (String date : intersection) { + if (Objects.isNull(repairMap.get(date))) { + //发生一次维修减5分 + repairMap.put(date, BigDecimal.valueOf(100 - 5)); + } else { + BigDecimal old = repairMap.get(date); + repairMap.put(date, old.subtract(BigDecimal.valueOf(5))); + } + } + } + } + }); + //构造结果 + List> resultList = new ArrayList<>(); + BigDecimal repairConfigScore = BigDecimal.valueOf(cockpitConfig.getOtherWeight().get("repair")); + BigDecimal securityConfigScore = BigDecimal.valueOf(cockpitConfig.getOtherWeight().get("security")); + if (CollectionUtils.isEmpty(securityScoreMap)) { + for (String date : dateList) { + securityScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if(CollectionUtils.isEmpty(repairMap)){ + for (String date : dateList) { + repairMap.put(date, BigDecimal.valueOf(100)); + } + } + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + //补全数据处理 + if (Objects.isNull(securityScoreMap.get(date)) && Objects.isNull(repairMap.get(date))) { + //该日期2个都空 + map.put("score", "100"); + } else if (Objects.isNull(securityScoreMap.get(date)) && !Objects.isNull(repairMap.get(date))) { + //该日期securityScoreMap空,repairMap不空 + map.put("score", repairConfigScore.multiply(repairMap.get(date)).add(securityConfigScore.multiply(BigDecimal.valueOf(100))) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } else if (Objects.isNull(repairMap.get(date)) && !Objects.isNull(securityScoreMap.get(date))) { + //该日期securityScoreMap不空,repairMap空 + map.put("score", securityConfigScore.multiply(securityScoreMap.get(date)).add(repairConfigScore.multiply(BigDecimal.valueOf(100))) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } else if (!Objects.isNull(securityScoreMap.get(date)) && !Objects.isNull(repairMap.get(date))) { + //该日期2个都不空 + BigDecimal securityScoreDecimal = securityConfigScore.multiply(securityScoreMap.get(date)); + BigDecimal repairDecimal = repairConfigScore.multiply(repairMap.get(date)); + map.put("score", securityScoreDecimal.add(repairDecimal) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } + resultList.add(map); + }); + return ResponseData.success(resultList); + } + + private List> getForResult(List weekCaseDTOS, List weekCaseKeyAreaDTOS, + List caseInfos, HashMap weekCaseMap, HashMap caseScoreMap, + HashMap keyAreaScoreMap, HashMap assessScoreMap, + List dateList){ + Map keyAreaWeight = cockpitConfig.getKeyAreaWeight(); + weekCaseKeyAreaDTOS.forEach(dto -> { + weekCaseMap.put(dto.getDimension(), BigDecimal.valueOf(dto.getQuantity())); + }); + weekCaseDTOS.forEach(dto -> { + String date = dto.getDimension(); + Integer quantity = dto.getQuantity(); + //无重点区域事件数据,1-安防事件次数/所有安防事件次数=1 + if (Objects.isNull(weekCaseMap.get(date)) || weekCaseMap.get(date).equals(BigDecimal.ZERO)) { + caseScoreMap.put(date, BigDecimal.valueOf(1 * 100)); + } else { + BigDecimal multiply = BigDecimal.valueOf(quantity).subtract(weekCaseMap.get(date)).divide(BigDecimal.valueOf(quantity), 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + caseScoreMap.put(date, multiply); + } + }); + + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + caseInfos.forEach(caseInfo -> { + //重点区域安防事态评估分数 + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double keyAreaScore = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String dayTime = caseInfo.getHappenTime().substring(0, caseInfo.getHappenTime().indexOf(" ")); + BigDecimal preScore; + if (keyAreaScoreMap.containsKey(dayTime)) { + preScore = keyAreaScoreMap.get(dayTime); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(keyAreaScore.toString()); + keyAreaScoreMap.put(dayTime, preScore.subtract(nowScore)); + + //安防机动支援力量响应评估分数 + //扣分=事件级别权重*未解决小时数 + Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); + Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); + long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); + Double assessScore = Double.valueOf(hazardWeight) * between; + BigDecimal preAssessScore; + if (assessScoreMap.containsKey(dayTime)) { + preAssessScore = assessScoreMap.get(dayTime); + } else { + preAssessScore = new BigDecimal("100.0"); + } + BigDecimal nowAssessScore = new BigDecimal(assessScore.toString()); + assessScoreMap.put(dayTime, preAssessScore.subtract(nowAssessScore)); + }); + //构造结果 + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(caseScoreMap)) { + for (String date : dateList) { + caseScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if (CollectionUtils.isEmpty(keyAreaScoreMap)) { + for (String date : dateList) { + keyAreaScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if (CollectionUtils.isEmpty(assessScoreMap)) { + for (String date : dateList) { + assessScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + BigDecimal preCaseScore = Objects.isNull(caseScoreMap.get(date)) ? BigDecimal.valueOf(100) : caseScoreMap.get(date); + BigDecimal preKeyAreaScore = Objects.isNull(keyAreaScoreMap.get(date)) ? BigDecimal.valueOf(100) : keyAreaScoreMap.get(date); + BigDecimal preAssessScore = Objects.isNull(assessScoreMap.get(date)) ? BigDecimal.valueOf(100) : assessScoreMap.get(date); + BigDecimal caseScore = preCaseScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("case"))); + BigDecimal keyAreaScore = preKeyAreaScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("keyArea"))); + BigDecimal responseAssessScore = preAssessScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("responseAssess"))); + map.put("score", caseScore.add(keyAreaScore).add(responseAssessScore).stripTrailingZeros().toPlainString()); + resultList.add(map); + }); + return resultList; + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java index decc60c..2c66ec1 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java @@ -96,7 +96,10 @@ JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人员失败,海康response:{}", resultStr); - return ResponseData.error("单个添加人员失败"); + if("0x00052301".equals(resultJson.get("code"))){ + return ResponseData.error("添加人员身份证号重复!"); + } + return ResponseData.error("单个添加人员失败!"); } JSONObject data = (JSONObject)resultJson.get("data"); String faceId = data.getString("faceId"); @@ -129,13 +132,11 @@ String body = JSONObject.toJSONString(personSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.PERSON_SINGLE_UPDATE, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); + //海康该接口成功返回data为空 if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个修改人员失败,海康response:{}", resultStr); return ResponseData.error("单个修改人员失败"); } - JSONObject data = (JSONObject)resultJson.get("data"); - String faceId = data.getString("faceId"); - staffInfo.setStaffFaceId(faceId); if(staffInfoMapper.updateById(staffInfo) > 0){ return ResponseData.success(); } @@ -265,6 +266,7 @@ @Override public StaffInfo selectStaffInfoByCode(StaffInfo staffInfo) { StaffInfo info = staffInfoMapper.selectByCode(staffInfo.getStaffCode()); + info.setPicture(getPictureFromHik(staffInfo.getStaffCode())); return info; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java index b219984..aa23547 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java @@ -3,7 +3,9 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdcardUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -86,14 +88,21 @@ VisitorInfo visitorInfo = new VisitorInfo(); visitorInfo.setVisitorName(visitorApply.getVisitorName()); - visitorInfo.setGender(Integer.valueOf(visitorApply.getVisitorGender())); + //身份证号确定性别 + int genderByIdCard = IdcardUtil.getGenderByIdCard(visitorApply.getIdCard()); + if(0 == genderByIdCard){ + genderByIdCard = 2; + } + visitorInfo.setGender(genderByIdCard); visitorInfo.setPhoneNo(visitorApply.getVisitorPhone()); visitorInfo.setCertificateNo(visitorApply.getIdCard()); visitorInfo.setCertificateType(111); visitorInfo.setVisitorPhoto(visitorApply.getPicUri()); appointmentFreeRegisterRequest.setVisitorInfo(visitorInfo); - + log.info("--------------------------"); + log.info("请求visitorApply:{}", JSON.toJSONString(visitorApply)); String body = JSONObject.toJSONString(appointmentFreeRegisterRequest); + log.info("请求海康body:{}", body); String resultStr = HikUtil.hikApi(HikUri.APPOINTMENT_FREE_REGISTER, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if(!"0".equals(resultJson.get("code"))){ @@ -129,7 +138,12 @@ appointmentFreeRegisterRequest.setVisitPurpose(visitorApply.getVisitReason()); VisitorInfo visitorInfo = new VisitorInfo(); visitorInfo.setVisitorName(visitorApply.getVisitorName()); - visitorInfo.setGender(Integer.valueOf(visitorApply.getVisitorGender())); + //身份证号确定性别 + int genderByIdCard = IdcardUtil.getGenderByIdCard(visitorApply.getIdCard()); + if(0 == genderByIdCard){ + genderByIdCard = 2; + } + visitorInfo.setGender(genderByIdCard); visitorInfo.setPhoneNo(visitorApply.getVisitorPhone()); visitorInfo.setCertificateNo(visitorApply.getIdCard()); visitorInfo.setCertificateType(111); @@ -165,7 +179,7 @@ VisitorApply visitorApply1 = visitorApplyMapper.selectById(visitorApply.getId()); if(StringUtils.isNotEmpty(visitorApply1.getAppointRecordId())){ List appointRecordIds = new ArrayList<>(); - appointRecordIds.add(visitorApply.getAppointRecordId()); + appointRecordIds.add(visitorApply1.getAppointRecordId()); String body = JSONObject.toJSONString(appointRecordIds); String resultStr = HikUtil.hikApi(HikUri.APPOINTMENT_CANCEL, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); @@ -247,7 +261,12 @@ appointmentFreeRegisterRequest.setVisitPurpose(busConcentrator.getVisitReason()); VisitorInfo visitorInfo = new VisitorInfo(); visitorInfo.setVisitorName(busConcentrator.getVisitorName()); - visitorInfo.setGender(Integer.valueOf(busConcentrator.getVisitorGender())); + //身份证号确定性别 + int genderByIdCard = IdcardUtil.getGenderByIdCard(busConcentrator.getIdCard()); + if(0 == genderByIdCard){ + genderByIdCard = 2; + } + visitorInfo.setGender(genderByIdCard); visitorInfo.setPhoneNo(busConcentrator.getVisitorPhone()); visitorInfo.setCertificateNo(busConcentrator.getIdCard()); visitorInfo.setCertificateType(111); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java b/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java index 109eec2..269e3b0 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java @@ -3,13 +3,11 @@ import cn.hutool.core.date.DateUtil; import javafx.util.Pair; +import org.apache.commons.lang3.StringUtils; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; +import java.util.*; /** * Created by Administrator on 2015/2/25. @@ -113,10 +111,46 @@ public static String getYesterday() { Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DATE, -2); + calendar.add(Calendar.DATE, -2); return sdf_day.format(calendar.getTime()); } + /** + * 包括传入的首尾日期 + */ + public static List getBetweenDays(String startTime, String endTime) { + if (StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)) { + return null; + } + //定义转换格式 + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + Date start = null; + Date end = null; + try { + start = df.parse(startTime); + end = df.parse(endTime); + } catch (ParseException e) { + e.printStackTrace(); + } + if (Objects.isNull(start) || Objects.isNull(end)) { + return null; + } + List result = new ArrayList<>(); + Calendar tempStart = Calendar.getInstance(); + tempStart.setTime(start); + tempStart.add(Calendar.DAY_OF_YEAR, 1); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Calendar tempEnd = Calendar.getInstance(); + tempEnd.setTime(end); + result.add(sdf.format(start)); + while (tempStart.before(tempEnd)) { + result.add(sdf.format(tempStart.getTime())); + tempStart.add(Calendar.DAY_OF_YEAR, 1); + } + result.add(endTime); + return result; + } + public static List getCurrentDateWeekList() { List list = new ArrayList<>(); //获取当前日期前30天的日期 @@ -165,7 +199,21 @@ // Date startDate = org.apache.commons.lang3.time.DateUtils.addDays(now, -7); // String s = DateUtil.formatDate(startDate); // list.add(s); - for (int i = 1; i < 8; i++) { + for (int i = 7; i > 0; i--) { + Date date = org.apache.commons.lang3.time.DateUtils.addDays(now, -i); + String s = DateUtil.formatDate(date); + list.add(s); + } + return list; + } + + /** + * 30天前的7天日期 + */ + public static List getCurrentDateDayBeforeMonthList() { + List list = new ArrayList<>(); + Date now = new Date(); + for (int i = 36; i > 29; i--) { Date date = org.apache.commons.lang3.time.DateUtils.addDays(now, -i); String s = DateUtil.formatDate(date); list.add(s); @@ -187,14 +235,22 @@ public static List getCurrentDateWorkHourList() { List list = new ArrayList<>(); + int hour = DateUtil.thisHour(true); String today = DateUtil.today(); - for (int i = 6; i < 24; i++) { + String substring = today.substring(5); + for (int i = 6; i < hour; i++) { if (i < 10) { - list.add(today + " 0" + i); + list.add(substring + " 0" + i + ":00"); } else { - list.add(today + " " + i); + list.add(substring + " " + i + ":00"); } } return list; } + + public static void main(String[] args) { + List betweenDays = getBetweenDays("2022-10-10", "2022-10-17"); + System.out.println(betweenDays); + + } } diff --git a/casic-web/src/main/build/package.xml b/casic-web/src/main/build/package.xml index 394dd0f..742d85b 100644 --- a/casic-web/src/main/build/package.xml +++ b/casic-web/src/main/build/package.xml @@ -22,6 +22,7 @@ start.bat start.sh + teststart.sh true 0744 diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java index 316188e..71d587d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java @@ -22,4 +22,11 @@ boolean insertCaseInfoBatch(List caseInfos); List caseInfoList(CaseInfoRequest caseInfoRequest); + + List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest); + + Object caseInfoLastByDrawNo(String drawNo); + + int updateAllStatus(); + } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java index b3d1968..7a7fe8a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java @@ -2,6 +2,10 @@ import com.alibaba.fastjson.JSONArray; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import java.util.HashMap; import java.util.List; @@ -13,4 +17,32 @@ */ public interface CockpitService { HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap); + + Object buildingNumberPerHour(); + + Object visitorTodayNumber(); + + Object deviceNumber(); + + Object securityNumber(); + + Object visitorApplyDetail(); + + Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO); + + Object eventCategoryStatistics(); + + Object fireEquipStatistics(); + + Object beOnDutyRatio(); + + Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO); + + Object securityScore(SecurityScoreDTO securityScoreDTO); + + Object securityFrequency(); + + Object areaScore(SecurityScoreDTO securityScoreDTO); + + Object heatMap(HeatMapDTO heatMapDTO); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java new file mode 100644 index 0000000..178b909 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.service; + +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; + +/** + * @Description: + * @Author: wangpeng + * @Date: 2022/10/11 9:10 + */ +public interface PropertyManageService { + Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO); + + Object keyAreaData(String dimension); + + Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO); + + Object attendanceNumber(String dimension); + + Object securityAssessment(String dimension); + + Object keyAreaStatistic(); + + Object responseAssess(); + + Object hazardLevelStatistics(String dimension); + + Object securityRank(); + + Object securityLevelAssess(); + + Object commute(); + + Object keyArea(); + + Object visitor(); + + Object security(); + + Object patrol(); + + Object other(); +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java index ea6b8c0..2580187 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java @@ -17,6 +17,7 @@ import com.casic.missiles.modular.service.BlackInfoService; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -70,11 +71,17 @@ faceInfo.setCertificateNum(blackInfo.getIdCardNo()); faceSingleAddOrUpdateRequest.setFaceInfo(faceInfo); FacePic facePic = new FacePic(); - facePic.setFaceBinaryData(blackInfo.getPicture()); - faceSingleAddOrUpdateRequest.setFacePic(facePic); + String picture = blackInfo.getPicture(); + if(StringUtils.isNotEmpty(picture)){ + String substringPicture = picture.substring(picture.indexOf(",") + 1); + facePic.setFaceBinaryData(substringPicture); + } faceSingleAddOrUpdateRequest.setFacePic(facePic); String body = JSONObject.toJSONString(faceSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.FACE_SINGLE_ADDITION, body); + log.info("-----------------------"); + log.info("增加黑名单人脸请求body,{}", body); + log.info("增加黑名单人脸resultStr:{}", JSONObject.toJSONString(resultStr)); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人脸失败,海康response:{}", resultStr); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java index 6b03d8b..1c34f68 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java @@ -2,17 +2,22 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.dao.CaseInfoMapper; import com.casic.missiles.modular.dao.CategoryLevelMapper; +import com.casic.missiles.modular.dao.DeviceInfoMapper; import com.casic.missiles.modular.dao.HazardLevelMapper; import com.casic.missiles.modular.dto.CaseInfoRequest; import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.model.CaseInfo; +import com.casic.missiles.modular.model.DeviceInfo; import com.casic.missiles.modular.service.CaseInfoService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,6 +31,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; /** * @Description: 安防事件service @@ -50,6 +56,9 @@ @Resource private AbstractDictService dictService; + @Resource + private DeviceInfoMapper deviceInfoMapper; + @Override public List caseInfoListPage(Page page, CaseInfoRequest caseInfoRequest) { try { @@ -136,17 +145,69 @@ @Override public List caseInfoList(CaseInfoRequest caseInfoRequest) { try { - List pageList = caseInfoMapper.getCaseInfoList(caseInfoRequest); - pageList.forEach(caseInfo ->{ + List list = caseInfoMapper.getCaseInfoList(caseInfoRequest); + list.forEach(caseInfo ->{ caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); }); - return pageList; + return list; } catch (DataAccessException ex) { log.error("安防事件: 查询不分页出现异常, 异常:{}", ex); } return null; } + + @Override + public List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest) { + try { + List list = caseInfoMapper.getCaseInfoListUnResolved(caseInfoRequest); + list.forEach(caseInfo ->{ + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + }); + return list; + } catch (DataAccessException ex) { + log.error("未解决/解决中安防事件: 查询不分页出现异常, 异常:{}", ex); + } + return null; + } + + @Override + public Object caseInfoLastByDrawNo(String drawNo) { + //图纸编号和设备编号一一对应 + QueryWrapper dWrapper = new QueryWrapper<>(); + dWrapper.eq("draw_no", drawNo); + DeviceInfo deviceInfo = deviceInfoMapper.selectOne(dWrapper); + if(Objects.isNull(deviceInfo)){ + return ResponseData.error("该图纸编号下不存在关联的设备"); + } + if(StringUtils.isEmpty(deviceInfo.getDevCode())){ + return ResponseData.error("该图纸编号下不存在对应的设备编号"); + }else{ + String devCode = deviceInfo.getDevCode(); + QueryWrapper cWrapper = new QueryWrapper<>(); + cWrapper.eq("device_code", devCode); + List caseInfos = caseInfoMapper.selectList(cWrapper); + if(CollectionUtil.isEmpty(caseInfos)){ + return ResponseData.error("该图纸编号下不存在最近发生的事件"); + } + CaseInfo caseInfo = caseInfos.get(caseInfos.size() - 1); + caseInfo.setDrawNo(deviceInfo.getDrawNo()); + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + return ResponseData.success(caseInfo); + } + } + + @Override + public int updateAllStatus() { + int upflag = caseInfoMapper.updateAllStatus(); + return upflag; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java index 7402991..7fb5a6e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java @@ -4,15 +4,34 @@ import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.*; import com.casic.missiles.modular.enums.HikUri; +import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.redis.RedisUtil; +import com.casic.missiles.modular.redis.key.CacheKeys; import com.casic.missiles.modular.service.CockpitService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import java.text.MessageFormat; +import java.text.NumberFormat; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.*; +import java.util.stream.Collectors; /** * @Description: @@ -22,6 +41,28 @@ @Slf4j @Service public class CockpitServiceImpl implements CockpitService { + @Autowired + private StatisticNumberMapper numberMapper; + @Autowired + private AbstractDictService dictService; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private DeviceInfoMapper deviceInfoMapper; + @Autowired + private FireEquipInfoMapper fireEquipInfoMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private VisitorApplyMapper applyMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private RedisUtil redisUtil; @Override public HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap) { @@ -106,4 +147,512 @@ }); return resultMap; } + + @Override + public Object buildingNumberPerHour() { + //当天按小时分组的人数 + List list = numberMapper.selectListByTime(); + Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); + //定时任务中已将每小时三栋楼人数存到数据库 + //将一期主楼和录制楼人数合并,二期单算 + List> resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List buildingNumberDTOS = collect.get(key); + BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); + BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); + BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); + HashMap resultMap = new HashMap<>(); + Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); + Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); + resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); + resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); + resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); + resultList.add(resultMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object visitorTodayNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); + List visitInfos = visitInfoMapper.selectList(wrapper); + HashMap resultMap = new HashMap<>(); + resultMap.put("今日访客量", visitInfos.size()); + return ResponseData.success(resultMap); + } + + @Override + public Object deviceNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + Integer total = deviceInfoMapper.selectCount(wrapper); + QueryWrapper wrapper1 = new QueryWrapper<>(); + wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 + Integer online = deviceInfoMapper.selectCount(wrapper1); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) online / (float) total * 100); + HashMap resultMap = new HashMap<>(); + resultMap.put("设备总数", total); + resultMap.put("设备在线率", result + "%"); + return ResponseData.success(resultMap); + } + + @Override + public Object securityNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) leave / (float) total * 100); + HashMap resultMap = new HashMap<>(); + if (0 == total) { + resultMap.put("安保人员总数", 0); + resultMap.put("安保人员离岗率", "0"); + } else { + resultMap.put("安保人员总数", total); + resultMap.put("安保人员离岗率", result + ""); + } + return ResponseData.success(resultMap); + } + + @Override + public Object visitorApplyDetail() { + List reasonGroup = applyMapper.selectByVisitReason(); + List resultList = new ArrayList<>(); + //空数据处理 + List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); + if (CollectionUtils.isEmpty(reasonGroup)) { + for (Dict dict : visitReason) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(dict.getName()); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); + if (0 == sum) { + return ResponseData.success(); + } + reasonGroup.forEach(group -> { + String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(group.getQuantity()); + applyReasonGroupDTO.setVisitReason(reasonName); + applyReasonGroupDTO.setRatio(result + "%"); + resultList.add(applyReasonGroupDTO); + }); + //返回数据补全处理 + if (resultList.size() < visitReason.size()) { + List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); + for (Dict dict : visitReason) { + String name = dict.getName(); + if (!collect.contains(name)) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(name); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO) { + //查询各危险级别权重name,用于构造返回结构 + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); + + Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); + List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(list)) { + Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + //查询数据,放入redis + List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); + Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //设置过期时间为每月1号0点 + LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) + .withMinute(0).withSecond(0).withNano(0); + long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); + redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + + @Override + public Object eventCategoryStatistics() { + List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); + return ResponseData.success(categoryLevelGroup); + } + + @Override + public Object fireEquipStatistics() { + List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); + //空数据处理 + List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); + if (CollectionUtils.isEmpty(equipTypeGroup)) { + for (Dict dict : equipType) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + return ResponseData.success(equipTypeGroup); + } + equipTypeGroup.forEach(group -> { + String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); + group.setEquipTypeName(equipTypeName); + }); + //返回数据补全处理 + if (equipTypeGroup.size() < equipType.size()) { + List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); + for (Dict dict : equipType) { + String code = dict.getCode(); + if (!collect.contains(code)) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + } + } + return ResponseData.success(equipTypeGroup); + } + + @Override + public Object beOnDutyRatio() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + if (0 == total) { + return ResponseData.success(null); + } + List currentDateHourList = DateUtils.getCurrentDateWorkHourList(); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + //补全空数据 + if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { + for (String date : currentDateHourList) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + return ResponseData.success(onDutyRatioDTOS); + } + onDutyRatioDTOS.forEach(dto -> { + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); + dto.setRatio(result + "%"); + }); + //补全空数据 + List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); + for (String date : currentDateHourList) { + if (!collect.contains(date)) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + } + return ResponseData.success(onDutyRatioDTOS); + } + + @Override + public Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO) { + List gateStatusGroup = null; + //2代表所有摄像头(对应字典2-7) + if ("2".equals(gateStatusGroupDTO.getDevType())) { + gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); + } else { + gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); + } + HashMap resultMap = new HashMap<>(); + //空数据处理 + List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); + if (CollectionUtils.isEmpty(gateStatusGroup)) { + List resultList = new ArrayList<>(); + for (Dict dict : deviceStatus) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + resultMap.put("total", 0); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("无该类设备信息"); + } + List resultList = new ArrayList<>(); + gateStatusGroup.forEach(group -> { + if ("2".equals(gateStatusGroupDTO.getDevType())) { + group.setDevType("2"); + } + String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(devStatus); + gateStatusGroupResponse.setRatio(result + "%"); + gateStatusGroupResponse.setQuantity(group.getQuantity()); + resultList.add(gateStatusGroupResponse); + }); + //返回数据补全处理 + if (resultList.size() < deviceStatus.size()) { + List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); + for (Dict dict : deviceStatus) { + String name = dict.getName(); + if (!collect.contains(name)) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + } + } + resultMap.put("total", sum); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + + @Override + public Object securityScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的position划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + List caseInfos = caseInfoMapper.selectByPosition(position); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //楼栋-评分实体map + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + Map resultMap = new HashMap<>(); + //空数据处理 + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + resultMap.put(dict.getName(), 100.0); + } + return ResponseData.success(resultMap); + } + + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + + collect.keySet().forEach(key -> { + List list = collect.get(key); + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); + resultMap.put(dictValue, 100 - collect1.getSum()); + }); + //返回数据补全处理 + if (collect.size() < devicePosition.size()) { + Set strings = resultMap.keySet(); + for (Dict dict : devicePosition) { + String name = dict.getName(); + if (!strings.contains(name)) { + resultMap.put(dict.getName(), 100.0); + } + } + } + //按楼层分组计算评分 +// collect.keySet().forEach(key -> { +// Map map = new HashMap<>(); +// List securityScoreDTOS = collect.get(key); +// //楼层-评分map +// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); +// collect1.keySet().forEach(key1 -> { +// map.put(key1, 100 - collect1.get(key1)); +// }); +// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); +// resultMap.put(dictValue, map); +// }); + return ResponseData.success(resultMap); + } + + @Override + public Object securityFrequency() { + String year = String.valueOf(DateUtil.thisYear()); + String month = String.valueOf(DateUtil.thisMonth()); + Integer quantity = caseInfoMapper.selectCountByMonth(year, month); + SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); + securityFrequencyDTO.setQuantity(quantity); + securityFrequencyDTO.setYear(year); + securityFrequencyDTO.setMonth(month); + return ResponseData.success(securityFrequencyDTO); + } + + @Override + public Object areaScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的area划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + String area = securityScoreDTO.getArea(); + if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { + return null; + } + Map resultMap = new HashMap<>(); + List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); + if (Objects.isNull(caseInfos)) { + resultMap.put("安防评分", 100.0); + return ResponseData.success(resultMap); + } + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + resultMap.put("安防评分", 100 - collect.getSum()); + return ResponseData.success(resultMap); + } + + @Override + public Object heatMap(HeatMapDTO heatMapDTO) { + if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { + heatMapDTO.setMinute(3); + } + List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); + Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); + HashMap resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect)) { + return ResponseData.success(); + } + collect.keySet().forEach(key -> { + resultMap.put(key, collect.get(key).size()); + }); + return ResponseData.success(resultMap); + } + + private List> getResultMap(List nameList, List> resultList, Map> resultMap) { + resultMap.keySet().forEach(key -> { + List monthAndLevelGroupDTOS = resultMap.get(key); + HashMap hashMap = new HashMap<>(); + for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { +// hashMap.put("年份", andLevelGroupDTO.getYear()); + hashMap.put("月份", /*andLevelGroupDTO.getYear() + "-" + */Integer.valueOf(andLevelGroupDTO.getMonth())); + hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); + } + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + }); + //12个月份,用于构造返回结构 + List list1 = new ArrayList<>(); + for (Map map : resultList) { + list1.add(String.valueOf(map.get("月份"))); + } + for (int i = 1; i < 13; i++) { + if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { + continue; + } + HashMap hashMap = new HashMap<>(); + hashMap.put("月份", i); + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + } + List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); + return results; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java index 94308db..f91d7bd 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java @@ -427,6 +427,13 @@ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("draw_no", drawNo); DeviceInfo deviceInfo = deviceInfoMapper.selectOne(wrapper); + if(!Objects.isNull(deviceInfo)){ + deviceInfo.setDevTypeName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_TYPE, deviceInfo.getDevType())); + deviceInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, deviceInfo.getStatus())); + deviceInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, deviceInfo.getPosition())); + deviceInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, deviceInfo.getArea())); + deviceInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, deviceInfo.getIsKeyArea())); + } return deviceInfo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java index 8ed53d9..c399a7f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java @@ -11,6 +11,7 @@ import com.casic.missiles.modular.service.HikService; import com.casic.missiles.modular.system.model.Dict; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -50,8 +51,11 @@ @Override public CaseInfo blackListHandle(JSONObject event, CaseInfo caseInfo) { - String srcIndex = event.getString("srcIndex"); //海康资源唯一标识 + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 String happenTimeISO = String.valueOf(event.get("happenTime")); + DateTime parse = DateUtil.parse(happenTimeISO); String happenTime = DateUtil.formatDateTime(parse); caseInfo.setHappenTime(happenTime); //发生时间 @@ -89,6 +93,16 @@ log.info("接收到离岗事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //离岗事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray leavePosition = data.getJSONArray("leavePosition"); + if(StringUtils.isNotEmpty(leavePosition.getString(0))){ + JSONObject jsonObject = leavePosition.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -115,6 +129,16 @@ log.info("接收到人员聚集事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //人员聚集事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray group = data.getJSONArray("group"); + if(StringUtils.isNotEmpty(group.getString(0))){ + JSONObject jsonObject = group.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -263,8 +287,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void propertyAttendanceHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); @@ -309,8 +334,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void securityPersonnelHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java new file mode 100644 index 0000000..4427f19 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java @@ -0,0 +1,1255 @@ +package com.casic.missiles.modular.service.impl; + +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.config.CockpitConfig; +import com.casic.missiles.modular.dao.*; +import com.casic.missiles.modular.dto.statistics.*; +import com.casic.missiles.modular.enums.SecurityEventDict; +import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.service.PropertyManageService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.text.NumberFormat; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @Description: 驾驶舱二级页面-物管信息 + * @Author: wangpeng + * @Date: 2022/10/11 9:11 + */ +@Slf4j +@Service +public class PropertyManageServiceImpl implements PropertyManageService { + @Autowired + private AttendanceInfoMapper attendanceInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private DeviceRepairLogMapper repairLogMapper; + @Autowired + private CockpitConfig cockpitConfig; + @Autowired + private AbstractDictService dictService; + + @Override + public Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO) { + //各类型员工及总数 + List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); + Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); + + String dateDimension = attendanceRatioDTO.getDateDimension(); + List attendanceRatioDTOS = new ArrayList<>(); + List dateList = null; + //考勤的人数,按单次考勤过滤 + if ("week".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); + dateList = DateUtils.getCurrentDateDayList(); + } else if ("month".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); + dateList = DateUtils.getCurrentDateWeekList(); + } else if ("year".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); + dateList = DateUtils.getCurrentDateMonthList(); + } + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { + for (String date : dateList) { + HashMap hashMap = new HashMap<>(); + hashMap.put("date", date); + hashMap.put("property", "0%"); + hashMap.put("security", "0%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + //计算出勤率 + Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); + + dateList.forEach(date -> { + HashMap hashMap = new HashMap<>(); + if (CollectionUtils.isEmpty(dateMap.get(date))) { + hashMap.put("date", date); + hashMap.put("property", "0%"); + hashMap.put("security", "0%"); + resultList.add(hashMap); + } else { + List attendances = dateMap.get(date); + attendances.forEach(attendanceRatio -> { + attendanceRatio.setDateDimension(dateDimension); + attendanceRatio.setStaffType(attendanceRatio.getStaffType()); + List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); + String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); + attendanceRatio.setAttendanceRatio(ratio + "%"); + //构造返回结构 + hashMap.put("date", attendanceRatio.getDate()); +// String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); + if ("1".equals(attendanceRatio.getStaffType())) { + hashMap.put("property", attendanceRatio.getAttendanceRatio()); + } + if ("2".equals(attendanceRatio.getStaffType())) { + hashMap.put("security", attendanceRatio.getAttendanceRatio()); + } + }); + //补全缺少数据 + if (1 == attendances.size()) { + AttendanceRatioDTO attendanceRatioDTO1 = attendances.get(0); + if ("1".equals(attendanceRatioDTO1.getStaffType())) { + hashMap.put("security", "0%"); + } + if ("2".equals(attendanceRatioDTO1.getStaffType())) { + hashMap.put("property", "0%"); + } + } + resultList.add(hashMap); + } + }); + return ResponseData.success(resultList); + + } + + @Override + public Object keyAreaData(String dimension) { + List resultList = null; + List dateList = null; + if ("year".equals(dimension)) { + //近365天数据按月分组统计 + resultList = caseInfoMapper.selectPreMonthCountByNearYear(); + dateList = DateUtils.getCurrentDateMonthList(); + } else if ("month".equals(dimension)) { + //近30天数据按周分组统计 + resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); + dateList = DateUtils.getCurrentDateWeekList(); + } else if ("week".equals(dimension)) { + //近7天数据按天分组统计 + resultList = caseInfoMapper.selectPreDayCountBySevenDay(); + dateList = DateUtils.getCurrentDateDayList(); + } + //补全空数据处理 + if (CollectionUtils.isEmpty(resultList)) { + for (String date : dateList) { + PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); + preMonthOrWeekCaseDTO.setDimension(date); + preMonthOrWeekCaseDTO.setQuantity(0); + resultList.add(preMonthOrWeekCaseDTO); + } + } else { + for (String date : dateList) { + List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); + if (!collect.contains(date)) { + PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); + preMonthOrWeekCaseDTO.setDimension(date); + preMonthOrWeekCaseDTO.setQuantity(0); + resultList.add(preMonthOrWeekCaseDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { + String year = avgMonthAndWeekGroupDTO.getYear(); + List monthList = caseInfoMapper.selectPreMonthCountByYear(year); + Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); + HashMap strAvgMap = new HashMap<>(); + List resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List preMonthOrWeekCaseDTOS = collect.get(key); + int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); + //若年份是本年,则使用各安防级别数量/当前月份数 + //若不是本年,除数为12 + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + if (year.equals(String.valueOf(DateUtil.thisYear()))) { + monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); + strAvgMap.put(key, monthAndWeekDTO); + } else { + monthAndWeekDTO.setMonthQuantity(sum / 12); + strAvgMap.put(key, monthAndWeekDTO); + } + } + + List weekList = caseInfoMapper.selectPreWeekCountByYear(year); + Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); + for (String key : collect1.keySet()) { + List preMonthOrWeekCaseDTOS = collect.get(key); + int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); + if (year.equals(String.valueOf(DateUtil.thisYear()))) { + if (!Objects.isNull(strAvgMap.get(key))) { + MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); + strAvgMap.put(key, monthAndWeekDTO); + } else { + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); + strAvgMap.put(key, monthAndWeekDTO); + } + } else { + if (!Objects.isNull(strAvgMap.get(key))) { + MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / 52); + strAvgMap.put(key, monthAndWeekDTO); + } else { + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / 52); + strAvgMap.put(key, monthAndWeekDTO); + } + } + } + strAvgMap.keySet().forEach(key -> { + resultList.add(strAvgMap.get(key)); + }); + //输出顺序 + Collections.swap(resultList, 1, 2); + return ResponseData.success(resultList); + } + + @Override + public Object attendanceNumber(String dimension) { + List attendanceNumberDTOs = null; + List> resultList = new ArrayList<>(); + List dateList = new ArrayList<>(); + if ("week".equals(dimension)) { + //近7天数据按天分组统计 + attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); + dateList = DateUtils.getCurrentDateDayList(); + } else if ("day".equals(dimension)) { + //今天数据按小时分组统计 + attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); + dateList = DateUtils.getCurrentDateWorkHourList(); + } + if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { + for (String date : dateList) { + HashMap hashMap = new HashMap<>(); + hashMap.put("staticTime", date); + hashMap.put("1", "0"); + hashMap.put("2", "0"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); + if ("day".equals(dimension)) { + collect = collect.entrySet().stream().collect(Collectors.toMap(m -> m.getKey().substring(5) + ":00", Map.Entry::getValue)); + } + + for (String date : dateList) { + Map resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect.get(date))) { + resultMap.put("1", "0"); + resultMap.put("2", "0"); + resultMap.put("staticTime", date); + resultList.add(resultMap); + } else { + List attendanceNumberDTOS = collect.get(date); +// Map resultMap = new HashMap<>(); + AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); + if (attendanceNumberDTOS.size() >= 2) { + AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); + resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); + } + resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); + resultMap.put("staticTime", date); + resultList.add(resultMap); + //补全map缺少数据 + if (!resultMap.containsKey("1")) { + resultMap.put("1", "0"); + } + if (!resultMap.containsKey("2")) { + resultMap.put("2", "0"); + } + } + } + +// +// collect.keySet().forEach(key -> { +// List attendanceNumberDTOS = collect.get(key); +// Map resultMap = new HashMap<>(); +// AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); +// if (attendanceNumberDTOS.size() >= 2) { +// AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); +// resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); +// } +// resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); +// resultMap.put("staticTime", attendanceNumberDTO.getDate().substring(5) + ":00"); +// resultList.add(resultMap); +// }); +// //补全空数据处理 +// if (CollectionUtils.isEmpty(resultList)) { +// for (String date : dateList) { +// Map resultMap = new HashMap<>(); +// resultMap.put("1", "0"); +// resultMap.put("2", "0"); +// resultMap.put("staticTime", date); +// resultList.add(resultMap); +// } +// } else { +// List collectList = new ArrayList<>(); +// for (Map map : resultList) { +// String staticTime = map.get("staticTime"); +// collectList.add(staticTime); +// //补全map缺少数据 +// if (!map.containsKey("1")) { +// map.put("1", "0"); +// } +// if (!map.containsKey("2")) { +// map.put("2", "0"); +// } +// } +// for (String date : dateList) { +// if (!collectList.contains(date)) { +// Map resultMap = new HashMap<>(); +// resultMap.put("1", "0"); +// resultMap.put("2", "0"); +// resultMap.put("staticTime", date); +// resultList.add(resultMap); +// } +// } +// } + return ResponseData.success(resultList); + } + + @Override + public Object securityAssessment(String dimension) { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + if ("week".equals(dimension)) { + //近7天早晚高峰数据 + List caseInfos = caseInfoMapper.selectListBySevenDay(); + //按时间(天)进行分组 + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(" "); + String dayTime = array[0]; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } else if ("day".equals(dimension)) { + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDatePeakHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + + } + return null; + } + + @Override + public Object keyAreaStatistic() { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday2(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + dayTime = dayTime.substring(5) + ":00"; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } + + @Override + public Object responseAssess() { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday3(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + //扣分=事件级别权重*未解决小时数 + Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); + Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); + long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); + Double score = Double.valueOf(hazardWeight) * between; + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + dayTime = dayTime.substring(5) + ":00"; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } + + @Override + public Object hazardLevelStatistics(String dimension) { + List hazardLevelGroup = null; + if ("week".equals(dimension)) { + hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); + } else if ("month".equals(dimension)) { + hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); + } + if (CollectionUtils.isEmpty(hazardLevelGroup)) { + log.info("重点区域威胁事件类型统计,无安防事件"); + return ResponseData.error("无安防事件发生!"); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("安防事件总数为0"); + } + hazardLevelGroup.forEach(group -> { + CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); + group.setLevelName(caseHazardLevel.getName()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + group.setLevelRatio(result + "%"); + }); + HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); + hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); + hazardLevelGroupResponse.setQuantity(sum); + return ResponseData.success(hazardLevelGroupResponse); + } + + @Override + public Object securityRank() { + //考勤表近一个月按人员分组的考勤个数前十名 + List list = attendanceInfoMapper.getCountForRank(); + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(list)) { + //补全空数据处理 + List staffList = staffInfoMapper.selectListLimitTen(); + for (StaffInfo staffInfo : staffList) { + HashMap hashMap = new HashMap<>(); + hashMap.put(staffInfo.getStaffName(), "0%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + //构造返回结构 + for (SecurityRankDTO dto : list) { + // TODO: 2022/9/15 分母使用30,后续看产品定义 + HashMap hashMap = new HashMap<>(); + String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); + hashMap.put("name", dto.getStaffName()); + hashMap.put("ratio", result + "%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object securityLevelAssess() { + //今天数据按小时分组统计 + List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + if (CollectionUtils.isEmpty(resultList)) { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); + levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); + levelAssessDTO.setDate(date); +// levelAssessDTO.setQuantity(); + resultList.add(levelAssessDTO); + } + return ResponseData.success(resultList); + } + resultList.forEach(result -> { + result.setDate(result.getDate().substring(5) + ":00"); + BigDecimal deScore = new BigDecimal(result.getQuantity()); + BigDecimal preScore = new BigDecimal("100.0"); + result.setScore(preScore.subtract(deScore).doubleValue()); + }); + //数据补全处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + for (SecurityLevelAssessDTO levelAssessDTO : resultList) { + String substring = levelAssessDTO.getDate().substring(5) + ":00"; + if (!substring.equals(date)) { + SecurityLevelAssessDTO levelAssess = new SecurityLevelAssessDTO(); + levelAssess.setScore(new BigDecimal("100.0").doubleValue()); + levelAssess.setDate(date); + resultList.add(levelAssess); + break; + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object commute() { + //早晚高峰区域安防评估 + ResponseData assessResultJson = (ResponseData) this.securityAssessment("week"); + if (Objects.isNull(assessResultJson) || 200 != assessResultJson.getCode()) { + return assessResultJson; + } + JSONArray assessData = JSONArray.parseArray(JSON.toJSONString(assessResultJson.getData())); + //所有类型的员工出勤 + List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); + long sum = staffTypeAndSumDTOS.stream().collect(Collectors.summarizingInt(StaffTypeAndSumDTO::getSum)).getSum(); + List countByTypeAndDateForWeek = attendanceInfoMapper.getCountByTypeAndDateForWeek(); + Map> dateMap = countByTypeAndDateForWeek.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); + HashMap attendanceMap = new HashMap<>(); + dateMap.keySet().forEach(key -> { + List attendanceRatioDTOS = dateMap.get(key); + //当天所有类型的员工的出勤人数 + long sum1 = attendanceRatioDTOS.stream().collect(Collectors.summarizingInt(AttendanceRatioDTO::getQuantity)).getSum(); + //出勤占比评分 + Double attendanceRatio = ((float) sum1 / (float) sum) * 100 * cockpitConfig.getCommuteWeight(); + attendanceMap.put(key, attendanceRatio); + }); + //构造结果 + List> resultList = new ArrayList<>(); + Iterator iterator = assessData.stream().iterator(); + while (iterator.hasNext()) { + JSONObject next = (JSONObject) iterator.next(); + String date = next.getString("date"); + HashMap map = new HashMap<>(); + //计算评分 + Double assessRatio = next.getInteger("score") * (1 - cockpitConfig.getCommuteWeight()); + NumberFormat numberFormat = NumberFormat.getInstance(); + numberFormat.setMaximumFractionDigits(2); + if (!Objects.isNull(attendanceMap.get(date))) { + Double attendanceRatio = attendanceMap.get(date); + Double r = assessRatio + attendanceRatio; + map.put("score", numberFormat.format(r)); + } else { + //无员工出勤率(出勤为0),只有安防评估分值 + map.put("score", numberFormat.format(assessRatio)); + } + map.put("date", date); + resultList.add(map); + } + return ResponseData.success(resultList); + } + + @Override + public Object keyArea() { + //1-重点区域安防事件次数/所有安防事件次数 + //获取近7天每天的安防事件个数,所有和重点区域 + List weekCaseDTOS = caseInfoMapper.selectPreDayCountBySevenDay(); + List weekCaseKeyAreaDTOS = caseInfoMapper.selectPreDayCountBySevenDayKeyArea(); + List caseInfos = caseInfoMapper.selectListBySevenDayKeyArea(); + HashMap weekCaseMap = new HashMap<>(); + HashMap caseScoreMap = new HashMap<>(); + HashMap keyAreaScoreMap = new HashMap<>(); + HashMap assessScoreMap = new HashMap<>(); + List dateList = DateUtils.getCurrentDateDayList(); + List> result = getForResult(weekCaseDTOS, weekCaseKeyAreaDTOS, caseInfos, weekCaseMap, caseScoreMap, + keyAreaScoreMap, assessScoreMap, dateList); + + //上个月对应数据 + List beforeMonthKeyAreaCaseDTOS = caseInfoMapper.selectPreDayCountByBeforeMonthKeyArea(); + List beforeMonthCaseDTOS = caseInfoMapper.selectPreDayCountByBeforeMonth(); + List beforeMonthCaseInfos = caseInfoMapper.selectListByBeforeMonthKeyArea(); + HashMap beforeMonthWeekCaseMap = new HashMap<>(); + HashMap beforeMonthCaseScoreMap = new HashMap<>(); + HashMap beforeMonthKeyAreaScoreMap = new HashMap<>(); + HashMap beforeMonthAssessScoreMap = new HashMap<>(); + List beforeMonthDateList = DateUtils.getCurrentDateDayBeforeMonthList(); + List> resultBeforeMonth = getForResult(beforeMonthCaseDTOS, beforeMonthKeyAreaCaseDTOS, beforeMonthCaseInfos, + beforeMonthWeekCaseMap, beforeMonthCaseScoreMap, beforeMonthKeyAreaScoreMap, beforeMonthAssessScoreMap, beforeMonthDateList); + //计算环比 + for (int i = 0; i < result.size(); i++) { + Map resultMap = result.get(i); + Map resultBeforeMonthMap = resultBeforeMonth.get(i); + BigDecimal resultScore = BigDecimal.valueOf(Double.valueOf(String.valueOf(resultMap.get("score")))); + BigDecimal resultBeforeMonthScore = BigDecimal.valueOf(Double.valueOf(String.valueOf(resultBeforeMonthMap.get("score")))); + BigDecimal finalResult = resultScore.subtract(resultBeforeMonthScore).divide(resultBeforeMonthScore, 2, BigDecimal.ROUND_HALF_UP); + resultMap.put("ringRatio", finalResult); + } + return ResponseData.success(result); + } + + @Override + public Object visitor() { + //查询每天的访客对应的离开记录(进入记录存在且在申请范围内) + //近7天主要使用申请离开时间(申请进入时间不会影响扣分) + List list = visitInfoMapper.selectListBySevenDay(); + list.stream().forEach(visit -> { + DateTime dateTime = DateUtil.parseDateTime(visit.getApplyOutTime()); + String formatDate = DatePattern.NORM_DATE_FORMAT.format(dateTime); + visit.setDate(formatDate); + }); + Map> dateVisitMap = list.stream().collect(Collectors.groupingBy(MultiScoreVisitorDTO::getDate)); + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + HashMap deductMap = new HashMap<>(); //扣分使用 + dateList.forEach(date -> { + //1、空数据处理 + if (CollectionUtils.isEmpty(dateVisitMap)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } else if (CollectionUtils.isEmpty(dateVisitMap.get(date))) { + //2、补全数据处理 + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } else { + //3、计算数据处理 + //计算分数(未在申请时间段内离开减分(包括无离开时间和有离开时间两种情况)、未在申请区域内离开减分),配置扣分,配置每个访客最高扣分 + List multiScoreVisitorDTOS = dateVisitMap.get(date); + //遍历访客 + for (MultiScoreVisitorDTO visitorDTO : multiScoreVisitorDTOS) { + //无离开时间 + if (StringUtils.isEmpty(visitorDTO.getOutTime())) { + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + cockpitConfig.getVisitorWeight().get("NoRecordPointDeduct")); + } else { + deductMap.put(date, cockpitConfig.getVisitorWeight().get("NoRecordPointDeduct")); + } + } else { +// DateTime applyInDateTime = DateUtil.parseDateTime(visitorDTO.getApplyInTime()); + DateTime applyOutDateTime = DateUtil.parseDateTime(visitorDTO.getApplyOutTime()); + DateTime outDateTime = DateUtil.parseDateTime(visitorDTO.getOutTime()); + //未在申请时间段离开(在申请离开时间后离开) + if (DateUtil.compare(outDateTime, applyOutDateTime) > 0) { + long betweenHour = DateUtil.between(outDateTime, applyOutDateTime, DateUnit.HOUR); + Double score = betweenHour * cockpitConfig.getVisitorWeight().get("singlePointDeduct"); + //该访客扣分到达最多分 + if (score >= cockpitConfig.getVisitorWeight().get("mostPointDeduct")) { + score = cockpitConfig.getVisitorWeight().get("mostPointDeduct"); + } + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + score); + } else { + deductMap.put(date, score); + } + } + //未在申请区域离开 + if (StringUtils.isNotEmpty(visitorDTO.getApplyVisitPosition()) && !visitorDTO.getApplyVisitPosition().equals(visitorDTO.getVisitPosition())) { + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + cockpitConfig.getVisitorWeight().get("singlePointDeduct")); + } else { + deductMap.put(date, cockpitConfig.getVisitorWeight().get("singlePointDeduct")); + } + } + + } + } + //添加到结果list + HashMap map = new HashMap<>(); + map.put("date", date); + if (!Objects.isNull(deductMap.get(date))) { + //最少0分 + if (deductMap.get(date) >= 100) { + map.put("score", 0); + } else { + map.put("score", 100 - deductMap.get(date)); + } + } else { + map.put("score", 100); + } + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object security() { + //安保人员到岗率*100*权重0.5 + //近7天安保人员到岗率 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + + List dateCountList = caseInfoMapper.selectDemobilizedCountSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap onDutyMap = new HashMap<>(); + dateCountList.forEach(dateCount -> { + //到岗率 + BigDecimal totalCount = new BigDecimal(total); + BigDecimal leaveCount = new BigDecimal(dateCount.getLeaveCount()); + BigDecimal result = totalCount.subtract(leaveCount).divide(totalCount, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + onDutyMap.put(dateCount.getDate(), result.multiply(BigDecimal.valueOf(cockpitConfig.getSecurityWeight().get("onDuty"))).setScale(2, BigDecimal.ROUND_HALF_UP)); + }); + + //安保等级评估均值*权重0.5 + List levelAssessList = caseInfoMapper.selectListByTypeSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap levelAssessMap = new HashMap<>(); + levelAssessList.forEach(levelAssess -> { + //6-23点共17小时,100-该天扣分/17 + BigDecimal deScore = new BigDecimal(levelAssess.getQuantity()); + BigDecimal preScore = new BigDecimal("100.0"); + BigDecimal divide = deScore.divide(BigDecimal.valueOf(17), 2, BigDecimal.ROUND_HALF_UP); + BigDecimal result = preScore.subtract(divide); + levelAssessMap.put(levelAssess.getDate(), result.multiply(BigDecimal.valueOf(cockpitConfig.getSecurityWeight().get("levelAssess"))).setScale(2, BigDecimal.ROUND_HALF_UP)); + }); + + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + Double onDutyWeight = cockpitConfig.getSecurityWeight().get("onDuty"); + Double levelAssessWeight = cockpitConfig.getSecurityWeight().get("levelAssess"); + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + //1、空数据处理 + if (CollectionUtils.isEmpty(onDutyMap) && CollectionUtils.isEmpty(levelAssessMap)) { + //2个map都空 + map.put("score", "100"); + resultList.add(map); + } else if (CollectionUtils.isEmpty(onDutyMap) || CollectionUtils.isEmpty(levelAssessMap)) { + //2个map有一个为空 + if (CollectionUtils.isEmpty(onDutyMap)) { + if (!Objects.isNull(levelAssessMap.get(date))) { + map.put("score", levelAssessMap.get(date).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + } else { + map.put("score", BigDecimal.valueOf(100 * levelAssessWeight).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + } + } + if (CollectionUtils.isEmpty(levelAssessMap)) { + if (!Objects.isNull(onDutyMap.get(date))) { + map.put("score", onDutyMap.get(date).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + } else { + map.put("score", BigDecimal.valueOf(100 * onDutyWeight).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + } + } + } else if (Objects.isNull(onDutyMap.get(date)) && Objects.isNull(levelAssessMap.get(date))) { + //该日期2个都空 + map.put("score", "100"); + resultList.add(map); + } else if (Objects.isNull(onDutyMap.get(date)) && !Objects.isNull(levelAssessMap.get(date))) { + //2、补全到岗率数据处理 + //该日期onDutyMap空,levelAssessMap不空 + map.put("score", levelAssessMap.get(date).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + resultList.add(map); + } else if (Objects.isNull(levelAssessMap.get(date)) && !Objects.isNull(onDutyMap.get(date))) { + //2、补全安保等级评估数据处理 + //该日期levelAssessMap空,onDutyMap不空 + map.put("score", onDutyMap.get(date).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + resultList.add(map); + } else if (!Objects.isNull(levelAssessMap.get(date)) && !Objects.isNull(onDutyMap.get(date))) { + //该日期2个都不空 + BigDecimal onDutyDecimal = onDutyMap.get(date); + BigDecimal levelAssessDecimal = levelAssessMap.get(date); + map.put("score", onDutyDecimal.add(levelAssessDecimal).stripTrailingZeros().toPlainString()); + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object patrol() { + //近7天安保人员到岗率 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + + List dateCountList = caseInfoMapper.selectDemobilizedCountSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap onDutyMap = new HashMap<>(); + dateCountList.forEach(dateCount -> { + //到岗率 + BigDecimal totalCount = new BigDecimal(total); + BigDecimal leaveCount = new BigDecimal(dateCount.getLeaveCount()); + BigDecimal result = totalCount.subtract(leaveCount).divide(totalCount, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + onDutyMap.put(dateCount.getDate(), result.stripTrailingZeros().toPlainString()); + }); + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + //1、空数据处理 + if (CollectionUtils.isEmpty(onDutyMap) || Objects.isNull(onDutyMap.get(date))) { + map.put("date", date); + map.put("score", "100"); + resultList.add(map); + } else { + map.put("date", date); + map.put("score", onDutyMap.get(date)); + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object other() { + //安全防护评分(所有楼的评分的均值) + List caseInfos = caseInfoMapper.selectByPositionSevenDay(null); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap securityScoreMap = new HashMap<>(); + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + securityScoreDTO1.setDate(caseInfo.getHappenTime().substring(0, caseInfo.getHappenTime().indexOf(" "))); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + securityScoreMap.put(dict.getName(), BigDecimal.valueOf(100)); + } + } else { + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getDate)); + collect.keySet().forEach(key -> { + List list = collect.get(key); + //该日期发生时间的楼栋 + Map> collect3 = list.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + //无评分的楼栋数据补全处理 + if (collect3.size() < devicePosition.size()) { + List collect4 = list.stream().map(SecurityScoreDTO::getPosition).collect(Collectors.toList()); + for (Dict dict : devicePosition) { + String code = dict.getCode(); + if (!collect4.contains(code)) { + SecurityScoreDTO securityScoreDTO = new SecurityScoreDTO(); + securityScoreDTO.setDate(key); + securityScoreDTO.setPosition(code); + securityScoreDTO.setScore(100.0); + list.add(securityScoreDTO); + } + } + } + //该日期所有楼栋扣分和 + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + double sum = collect1.getSum(); + //该日期发生时间的楼栋个数 + Map> collect4 = list.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + int size = collect4.keySet().size(); + //(100*发生事件的楼栋个数-扣分和)/楼栋个数 + BigDecimal securityScore = BigDecimal.valueOf(100).multiply(BigDecimal.valueOf(size)).subtract(BigDecimal.valueOf(sum)).divide(BigDecimal.valueOf(size), 2, BigDecimal.ROUND_HALF_UP); + securityScoreMap.put(key, securityScore); + }); + } + + //设备维修次数(满分一百分,发生一次维修减5分) + //当天设备的维修记录 + HashMap repairMap = new HashMap<>(); + List repairLogs = repairLogMapper.selectListBySevenDay(); + repairLogs.forEach(repair -> { + repair.setRepairEndTime(repair.getRepairEndTime().substring(0, repair.getRepairEndTime().indexOf(" "))); + }); + List dateList = DateUtils.getCurrentDateDayList(); + Map> collect = repairLogs.stream().collect(Collectors.groupingBy(DeviceRepairLog::getRepairEndTime)); + collect.keySet().forEach(key -> { + List deviceRepairLogs = collect.get(key); + //开始时间到结束时间的每天都扣分 + for (DeviceRepairLog log : deviceRepairLogs) { + String startTime = log.getRepairStartTime().substring(0, log.getRepairStartTime().indexOf(" ")); + String endTime = log.getRepairEndTime().substring(0, log.getRepairStartTime().indexOf(" ")); + List betweenDays = DateUtils.getBetweenDays(startTime, endTime); + //包含首尾时间 + Collection intersection = org.apache.commons.collections4.CollectionUtils.intersection(dateList, betweenDays); + if (!CollectionUtils.isEmpty(intersection)) { + for (String date : intersection) { + if (Objects.isNull(repairMap.get(date))) { + //发生一次维修减5分 + repairMap.put(date, BigDecimal.valueOf(100 - 5)); + } else { + BigDecimal old = repairMap.get(date); + repairMap.put(date, old.subtract(BigDecimal.valueOf(5))); + } + } + } + } + }); + //构造结果 + List> resultList = new ArrayList<>(); + BigDecimal repairConfigScore = BigDecimal.valueOf(cockpitConfig.getOtherWeight().get("repair")); + BigDecimal securityConfigScore = BigDecimal.valueOf(cockpitConfig.getOtherWeight().get("security")); + if (CollectionUtils.isEmpty(securityScoreMap)) { + for (String date : dateList) { + securityScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if(CollectionUtils.isEmpty(repairMap)){ + for (String date : dateList) { + repairMap.put(date, BigDecimal.valueOf(100)); + } + } + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + //补全数据处理 + if (Objects.isNull(securityScoreMap.get(date)) && Objects.isNull(repairMap.get(date))) { + //该日期2个都空 + map.put("score", "100"); + } else if (Objects.isNull(securityScoreMap.get(date)) && !Objects.isNull(repairMap.get(date))) { + //该日期securityScoreMap空,repairMap不空 + map.put("score", repairConfigScore.multiply(repairMap.get(date)).add(securityConfigScore.multiply(BigDecimal.valueOf(100))) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } else if (Objects.isNull(repairMap.get(date)) && !Objects.isNull(securityScoreMap.get(date))) { + //该日期securityScoreMap不空,repairMap空 + map.put("score", securityConfigScore.multiply(securityScoreMap.get(date)).add(repairConfigScore.multiply(BigDecimal.valueOf(100))) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } else if (!Objects.isNull(securityScoreMap.get(date)) && !Objects.isNull(repairMap.get(date))) { + //该日期2个都不空 + BigDecimal securityScoreDecimal = securityConfigScore.multiply(securityScoreMap.get(date)); + BigDecimal repairDecimal = repairConfigScore.multiply(repairMap.get(date)); + map.put("score", securityScoreDecimal.add(repairDecimal) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } + resultList.add(map); + }); + return ResponseData.success(resultList); + } + + private List> getForResult(List weekCaseDTOS, List weekCaseKeyAreaDTOS, + List caseInfos, HashMap weekCaseMap, HashMap caseScoreMap, + HashMap keyAreaScoreMap, HashMap assessScoreMap, + List dateList){ + Map keyAreaWeight = cockpitConfig.getKeyAreaWeight(); + weekCaseKeyAreaDTOS.forEach(dto -> { + weekCaseMap.put(dto.getDimension(), BigDecimal.valueOf(dto.getQuantity())); + }); + weekCaseDTOS.forEach(dto -> { + String date = dto.getDimension(); + Integer quantity = dto.getQuantity(); + //无重点区域事件数据,1-安防事件次数/所有安防事件次数=1 + if (Objects.isNull(weekCaseMap.get(date)) || weekCaseMap.get(date).equals(BigDecimal.ZERO)) { + caseScoreMap.put(date, BigDecimal.valueOf(1 * 100)); + } else { + BigDecimal multiply = BigDecimal.valueOf(quantity).subtract(weekCaseMap.get(date)).divide(BigDecimal.valueOf(quantity), 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + caseScoreMap.put(date, multiply); + } + }); + + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + caseInfos.forEach(caseInfo -> { + //重点区域安防事态评估分数 + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double keyAreaScore = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String dayTime = caseInfo.getHappenTime().substring(0, caseInfo.getHappenTime().indexOf(" ")); + BigDecimal preScore; + if (keyAreaScoreMap.containsKey(dayTime)) { + preScore = keyAreaScoreMap.get(dayTime); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(keyAreaScore.toString()); + keyAreaScoreMap.put(dayTime, preScore.subtract(nowScore)); + + //安防机动支援力量响应评估分数 + //扣分=事件级别权重*未解决小时数 + Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); + Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); + long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); + Double assessScore = Double.valueOf(hazardWeight) * between; + BigDecimal preAssessScore; + if (assessScoreMap.containsKey(dayTime)) { + preAssessScore = assessScoreMap.get(dayTime); + } else { + preAssessScore = new BigDecimal("100.0"); + } + BigDecimal nowAssessScore = new BigDecimal(assessScore.toString()); + assessScoreMap.put(dayTime, preAssessScore.subtract(nowAssessScore)); + }); + //构造结果 + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(caseScoreMap)) { + for (String date : dateList) { + caseScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if (CollectionUtils.isEmpty(keyAreaScoreMap)) { + for (String date : dateList) { + keyAreaScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if (CollectionUtils.isEmpty(assessScoreMap)) { + for (String date : dateList) { + assessScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + BigDecimal preCaseScore = Objects.isNull(caseScoreMap.get(date)) ? BigDecimal.valueOf(100) : caseScoreMap.get(date); + BigDecimal preKeyAreaScore = Objects.isNull(keyAreaScoreMap.get(date)) ? BigDecimal.valueOf(100) : keyAreaScoreMap.get(date); + BigDecimal preAssessScore = Objects.isNull(assessScoreMap.get(date)) ? BigDecimal.valueOf(100) : assessScoreMap.get(date); + BigDecimal caseScore = preCaseScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("case"))); + BigDecimal keyAreaScore = preKeyAreaScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("keyArea"))); + BigDecimal responseAssessScore = preAssessScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("responseAssess"))); + map.put("score", caseScore.add(keyAreaScore).add(responseAssessScore).stripTrailingZeros().toPlainString()); + resultList.add(map); + }); + return resultList; + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java index decc60c..2c66ec1 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java @@ -96,7 +96,10 @@ JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人员失败,海康response:{}", resultStr); - return ResponseData.error("单个添加人员失败"); + if("0x00052301".equals(resultJson.get("code"))){ + return ResponseData.error("添加人员身份证号重复!"); + } + return ResponseData.error("单个添加人员失败!"); } JSONObject data = (JSONObject)resultJson.get("data"); String faceId = data.getString("faceId"); @@ -129,13 +132,11 @@ String body = JSONObject.toJSONString(personSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.PERSON_SINGLE_UPDATE, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); + //海康该接口成功返回data为空 if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个修改人员失败,海康response:{}", resultStr); return ResponseData.error("单个修改人员失败"); } - JSONObject data = (JSONObject)resultJson.get("data"); - String faceId = data.getString("faceId"); - staffInfo.setStaffFaceId(faceId); if(staffInfoMapper.updateById(staffInfo) > 0){ return ResponseData.success(); } @@ -265,6 +266,7 @@ @Override public StaffInfo selectStaffInfoByCode(StaffInfo staffInfo) { StaffInfo info = staffInfoMapper.selectByCode(staffInfo.getStaffCode()); + info.setPicture(getPictureFromHik(staffInfo.getStaffCode())); return info; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java index b219984..aa23547 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java @@ -3,7 +3,9 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdcardUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -86,14 +88,21 @@ VisitorInfo visitorInfo = new VisitorInfo(); visitorInfo.setVisitorName(visitorApply.getVisitorName()); - visitorInfo.setGender(Integer.valueOf(visitorApply.getVisitorGender())); + //身份证号确定性别 + int genderByIdCard = IdcardUtil.getGenderByIdCard(visitorApply.getIdCard()); + if(0 == genderByIdCard){ + genderByIdCard = 2; + } + visitorInfo.setGender(genderByIdCard); visitorInfo.setPhoneNo(visitorApply.getVisitorPhone()); visitorInfo.setCertificateNo(visitorApply.getIdCard()); visitorInfo.setCertificateType(111); visitorInfo.setVisitorPhoto(visitorApply.getPicUri()); appointmentFreeRegisterRequest.setVisitorInfo(visitorInfo); - + log.info("--------------------------"); + log.info("请求visitorApply:{}", JSON.toJSONString(visitorApply)); String body = JSONObject.toJSONString(appointmentFreeRegisterRequest); + log.info("请求海康body:{}", body); String resultStr = HikUtil.hikApi(HikUri.APPOINTMENT_FREE_REGISTER, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if(!"0".equals(resultJson.get("code"))){ @@ -129,7 +138,12 @@ appointmentFreeRegisterRequest.setVisitPurpose(visitorApply.getVisitReason()); VisitorInfo visitorInfo = new VisitorInfo(); visitorInfo.setVisitorName(visitorApply.getVisitorName()); - visitorInfo.setGender(Integer.valueOf(visitorApply.getVisitorGender())); + //身份证号确定性别 + int genderByIdCard = IdcardUtil.getGenderByIdCard(visitorApply.getIdCard()); + if(0 == genderByIdCard){ + genderByIdCard = 2; + } + visitorInfo.setGender(genderByIdCard); visitorInfo.setPhoneNo(visitorApply.getVisitorPhone()); visitorInfo.setCertificateNo(visitorApply.getIdCard()); visitorInfo.setCertificateType(111); @@ -165,7 +179,7 @@ VisitorApply visitorApply1 = visitorApplyMapper.selectById(visitorApply.getId()); if(StringUtils.isNotEmpty(visitorApply1.getAppointRecordId())){ List appointRecordIds = new ArrayList<>(); - appointRecordIds.add(visitorApply.getAppointRecordId()); + appointRecordIds.add(visitorApply1.getAppointRecordId()); String body = JSONObject.toJSONString(appointRecordIds); String resultStr = HikUtil.hikApi(HikUri.APPOINTMENT_CANCEL, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); @@ -247,7 +261,12 @@ appointmentFreeRegisterRequest.setVisitPurpose(busConcentrator.getVisitReason()); VisitorInfo visitorInfo = new VisitorInfo(); visitorInfo.setVisitorName(busConcentrator.getVisitorName()); - visitorInfo.setGender(Integer.valueOf(busConcentrator.getVisitorGender())); + //身份证号确定性别 + int genderByIdCard = IdcardUtil.getGenderByIdCard(busConcentrator.getIdCard()); + if(0 == genderByIdCard){ + genderByIdCard = 2; + } + visitorInfo.setGender(genderByIdCard); visitorInfo.setPhoneNo(busConcentrator.getVisitorPhone()); visitorInfo.setCertificateNo(busConcentrator.getIdCard()); visitorInfo.setCertificateType(111); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java b/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java index 109eec2..269e3b0 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java @@ -3,13 +3,11 @@ import cn.hutool.core.date.DateUtil; import javafx.util.Pair; +import org.apache.commons.lang3.StringUtils; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; +import java.util.*; /** * Created by Administrator on 2015/2/25. @@ -113,10 +111,46 @@ public static String getYesterday() { Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DATE, -2); + calendar.add(Calendar.DATE, -2); return sdf_day.format(calendar.getTime()); } + /** + * 包括传入的首尾日期 + */ + public static List getBetweenDays(String startTime, String endTime) { + if (StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)) { + return null; + } + //定义转换格式 + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + Date start = null; + Date end = null; + try { + start = df.parse(startTime); + end = df.parse(endTime); + } catch (ParseException e) { + e.printStackTrace(); + } + if (Objects.isNull(start) || Objects.isNull(end)) { + return null; + } + List result = new ArrayList<>(); + Calendar tempStart = Calendar.getInstance(); + tempStart.setTime(start); + tempStart.add(Calendar.DAY_OF_YEAR, 1); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Calendar tempEnd = Calendar.getInstance(); + tempEnd.setTime(end); + result.add(sdf.format(start)); + while (tempStart.before(tempEnd)) { + result.add(sdf.format(tempStart.getTime())); + tempStart.add(Calendar.DAY_OF_YEAR, 1); + } + result.add(endTime); + return result; + } + public static List getCurrentDateWeekList() { List list = new ArrayList<>(); //获取当前日期前30天的日期 @@ -165,7 +199,21 @@ // Date startDate = org.apache.commons.lang3.time.DateUtils.addDays(now, -7); // String s = DateUtil.formatDate(startDate); // list.add(s); - for (int i = 1; i < 8; i++) { + for (int i = 7; i > 0; i--) { + Date date = org.apache.commons.lang3.time.DateUtils.addDays(now, -i); + String s = DateUtil.formatDate(date); + list.add(s); + } + return list; + } + + /** + * 30天前的7天日期 + */ + public static List getCurrentDateDayBeforeMonthList() { + List list = new ArrayList<>(); + Date now = new Date(); + for (int i = 36; i > 29; i--) { Date date = org.apache.commons.lang3.time.DateUtils.addDays(now, -i); String s = DateUtil.formatDate(date); list.add(s); @@ -187,14 +235,22 @@ public static List getCurrentDateWorkHourList() { List list = new ArrayList<>(); + int hour = DateUtil.thisHour(true); String today = DateUtil.today(); - for (int i = 6; i < 24; i++) { + String substring = today.substring(5); + for (int i = 6; i < hour; i++) { if (i < 10) { - list.add(today + " 0" + i); + list.add(substring + " 0" + i + ":00"); } else { - list.add(today + " " + i); + list.add(substring + " " + i + ":00"); } } return list; } + + public static void main(String[] args) { + List betweenDays = getBetweenDays("2022-10-10", "2022-10-17"); + System.out.println(betweenDays); + + } } diff --git a/casic-web/src/main/build/package.xml b/casic-web/src/main/build/package.xml index 394dd0f..742d85b 100644 --- a/casic-web/src/main/build/package.xml +++ b/casic-web/src/main/build/package.xml @@ -22,6 +22,7 @@ start.bat start.sh + teststart.sh true 0744 diff --git a/casic-web/src/main/resources/config/application-dev.yml b/casic-web/src/main/resources/config/application-dev.yml index f436857..e7e5127 100644 --- a/casic-web/src/main/resources/config/application-dev.yml +++ b/casic-web/src/main/resources/config/application-dev.yml @@ -20,7 +20,7 @@ casic: kaptcha-open: false #是否开启登录时验证码 (true/false) - no-login-urls: /websocket/**,${casic.sysUrl}/user/login,${casic.sysUrl}/user/appLogin,${casic.sysUrl}/kaptcha/base64,${casic.sysUrl}/config/baseConfig,/route/mockToken,/cockpit/**,/propertyManage/**,/eventRcv/**,/hik/**,/staffInfo/**,/**/listPage,/**/list,/**/drawNo,/socket/repost + no-login-urls: /websocket/**,${casic.sysUrl}/user/login,${casic.sysUrl}/user/appLogin,${casic.sysUrl}/kaptcha/base64,${casic.sysUrl}/config/baseConfig,/route/mockToken,/cockpit/**,/propertyManage/**,/eventRcv/**,/hik/**,/staffInfo/**,/**/listPage,/**/list,/**/drawNo,/socket/repost,/caseInfo/update,/**/list/unResolved,/last/drawNo,/multiScore/** #flowable数据源和多数据源配置 db: init: @@ -34,6 +34,27 @@ config: #模板文件本地路径 exportPath: D:\code\casic-security-cockpit\casic-web\src\main\resources\config\export\ + #综合评分组件配置 + #员工通勤安防系数组件-员工出勤率权重 + commuteWeight: 0.6 + #重点区域防控系数组件权重 + keyAreaWeight: + case: 0.5 + keyArea: 0.25 + responseAssess: 0.25 + #访客控制安全系数组件权重 + visitorWeight: + singlePointDeduct: 2 #多停留1小时扣分数 + mostPointDeduct: 10 #每个访客最多扣分 + noRecordPointDeduct: 10 #无离开记录扣分 + #安保人员到岗系数组件 + securityWeight: + onDuty: 0.5 + levelAssess: 0.5 + #其他相关安全系统指标系数组件 + otherWeight: + security: 0.5 + repair: 0.5 logging: level.root: info diff --git a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java index ac68966..a83fa78 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/config/CockpitConfig.java @@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Description: 全局配置文件 * @Author: wangpeng @@ -14,4 +16,9 @@ @ConfigurationProperties("cockpit.config") public class CockpitConfig { private String exportPath; + private Double commuteWeight; + private Map keyAreaWeight; + private Map visitorWeight; + private Map securityWeight; + private Map otherWeight; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java index bb42780..c631b4d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/CaseInfoController.java @@ -56,6 +56,28 @@ } /** + * 安防事件列表(不分页),未解决/解决中事件 + * join设备表查出drawNo + */ + @PostMapping("/list/unResolved") + @ResponseBody + @CrossOrigin + public Object listUnResolved(@RequestBody CaseInfoRequest caseInfoRequest) { + List caseInfos = caseInfoService.caseInfoListUnResolved(caseInfoRequest); + return ResponseData.success(caseInfos); + } + + /** + * 根据图纸编号drawNo查询最近发生的一个事件 + */ + @PostMapping("/last/drawNo") + @ResponseBody + @CrossOrigin + public Object lastDrawNo(String drawNo) { + return caseInfoService.caseInfoLastByDrawNo(drawNo); + } + + /** * 编辑事件状态 */ @PostMapping("/update") @@ -67,6 +89,19 @@ return ResponseData.error("更新异常"); } + /** + * 所有事件一键已解决 + */ + @PostMapping("/oneClickSolved") + @ResponseBody + public Object oneClickSolved() { + int upFlag = caseInfoService.updateAllStatus(); + if (upFlag >= 0) { + return ResponseData.success(); + } + return ResponseData.error("更新异常"); + } + @PostMapping("/batchImport") @ResponseBody public Object batchImport(@RequestParam("file") MultipartFile file) { @@ -81,7 +116,7 @@ return true; }); } catch (IOException ex) { - log.error("安防事件:批量导出文件异常,异常信息:{}", ex.getMessage()); + log.error("安防事件:批量导入文件异常,异常信息:{}", ex.getMessage()); } List list = caseInfoService.addCaseInfoBatch(results); if (CollectionUtil.isNotEmpty(list)) { diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java index 90ce183..833b73f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/SocketController.java @@ -26,6 +26,7 @@ */ @PostMapping("/repost") @ResponseBody + @CrossOrigin public Object listPage(@RequestBody ReSocketRequest reSocketRequest) { webSocket.sendAllMessage(JSONObject.toJSONString(reSocketRequest)); return ResponseData.success(); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java index 9fa00b7..18a8822 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/VisitorController.java @@ -35,9 +35,9 @@ Page page = PageFactory.defaultPage(); List visitorApplies = visitService.visitInfoListPage(page, visitorRequest); visitorApplies.parallelStream().forEach(visitInfo -> { - String orderId = visitInfo.getOrderId(); + String idCard = visitInfo.getIdCard(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("order_id", orderId); + queryWrapper.eq("id_card", idCard); visitInfo.setFrequency(visitService.count(queryWrapper)); //访客照片获取 String pictureUrl = visitService.getVisitorPicture(visitInfo); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java index 131c98a..a63865d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/CockpitController.java @@ -1,35 +1,20 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.config.AccessGroupConfig; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.*; -import com.casic.missiles.modular.redis.RedisUtil; -import com.casic.missiles.modular.redis.key.CacheKeys; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import com.casic.missiles.modular.service.CockpitService; -import com.casic.missiles.modular.system.model.Dict; -import com.casic.missiles.modular.util.DateUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.stream.Collectors; +import java.util.HashMap; +import java.util.List; /** * @Description: 驾驶舱驻留页面-前端主动查询相关 @@ -41,42 +26,9 @@ @RequestMapping("/cockpit") public class CockpitController { @Autowired - private RedisUtil redisUtil; - - @Autowired private CockpitService cockpitService; @Autowired - private AbstractDictService dictService; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; - - @Autowired - private DeviceInfoMapper deviceInfoMapper; - - @Autowired - private FireEquipInfoMapper fireEquipInfoMapper; - - @Autowired - private VisitInfoMapper visitInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private VisitorApplyMapper applyMapper; - - @Autowired - private StatisticNumberMapper numberMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired private AccessGroupConfig accessGroupConfig; /** @@ -110,26 +62,7 @@ @GetMapping("/build/numberPerHour") @ResponseBody public Object buildingNumberPerHour() { - //当天按小时分组的人数 - List list = numberMapper.selectListByTime(); - Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); - //定时任务中已将每小时三栋楼人数存到数据库 - //将一期主楼和录制楼人数合并,二期单算 - List> resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List buildingNumberDTOS = collect.get(key); - BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); - BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); - BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); - HashMap resultMap = new HashMap<>(); - Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); - Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); - resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); - resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); - resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); - resultList.add(resultMap); - } - return ResponseData.success(resultList); + return cockpitService.buildingNumberPerHour(); } /** @@ -138,12 +71,7 @@ @GetMapping("/visitor/todayNumber") @ResponseBody public Object visitorTodayNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); - List visitInfos = visitInfoMapper.selectList(wrapper); - HashMap resultMap = new HashMap<>(); - resultMap.put("今日访客量", visitInfos.size()); - return ResponseData.success(resultMap); + return cockpitService.visitorTodayNumber(); } /** @@ -152,19 +80,7 @@ @GetMapping("/device/number") @ResponseBody public Object deviceNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - Integer total = deviceInfoMapper.selectCount(wrapper); - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 - Integer online = deviceInfoMapper.selectCount(wrapper1); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) online / (float) total * 100); - HashMap resultMap = new HashMap<>(); - resultMap.put("设备总数", total); - resultMap.put("设备在线率", result + "%"); - return ResponseData.success(resultMap); + return cockpitService.deviceNumber(); } /** @@ -173,26 +89,7 @@ @GetMapping("/staff/securityNumber") @ResponseBody public Object securityNumber() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format((float) leave / (float) total * 100); - HashMap resultMap = new HashMap<>(); - if (0 == total) { - resultMap.put("安保人员总数", 0); - resultMap.put("安保人员离岗率", "0"); - } else { - resultMap.put("安保人员总数", total); - resultMap.put("安保人员离岗率", result + ""); - } - return ResponseData.success(resultMap); + return cockpitService.securityNumber(); } /** @@ -201,51 +98,7 @@ @GetMapping("/visitor/applyDetail") @ResponseBody public Object visitorApplyDetail() { - List reasonGroup = applyMapper.selectByVisitReason(); - List resultList = new ArrayList<>(); - //空数据处理 - List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); - if (CollectionUtils.isEmpty(reasonGroup)) { - for (Dict dict : visitReason) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(dict.getName()); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); - if (0 == sum) { - return ResponseData.success(); - } - reasonGroup.forEach(group -> { - String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(group.getQuantity()); - applyReasonGroupDTO.setVisitReason(reasonName); - applyReasonGroupDTO.setRatio(result + "%"); - resultList.add(applyReasonGroupDTO); - }); - //返回数据补全处理 - if (resultList.size() < visitReason.size()) { - List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); - for (Dict dict : visitReason) { - String name = dict.getName(); - if (!collect.contains(name)) { - ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); - applyReasonGroupDTO.setQuantity(0); - applyReasonGroupDTO.setVisitReason(name); - applyReasonGroupDTO.setRatio("0%"); - resultList.add(applyReasonGroupDTO); - } - } - } - return ResponseData.success(resultList); + return cockpitService.visitorApplyDetail(); } /** @@ -254,32 +107,7 @@ @PostMapping("/case/keyAreaStatistic") @ResponseBody public Object keyAreaEventStatistic(@RequestBody MonthAndLevelGroupDTO monthAndLevelGroupDTO) { - //查询各危险级别权重name,用于构造返回结构 - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); - - Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); - List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(list)) { - Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); - } - //查询数据,放入redis - List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); - Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); - //设置过期时间为每月1号0点 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) - .withMinute(0).withSecond(0).withNano(0); - long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); - redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); - //构造返回结构 - List> results = getResultMap(nameList, resultList, resultMap); - results.stream().sorted(); - return ResponseData.success(results); + return cockpitService.keyAreaEventStatistic(monthAndLevelGroupDTO); } /** @@ -288,8 +116,7 @@ @GetMapping("/case/categoryStatistics") @ResponseBody public Object eventCategoryStatistics() { - List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); - return ResponseData.success(categoryLevelGroup); + return cockpitService.eventCategoryStatistics(); } /** @@ -298,38 +125,7 @@ @GetMapping("/device/fireEquipStatistics") @ResponseBody public Object fireEquipStatistics() { - List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); - //空数据处理 - List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); - if (CollectionUtils.isEmpty(equipTypeGroup)) { - for (Dict dict : equipType) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - return ResponseData.success(equipTypeGroup); - } - equipTypeGroup.forEach(group -> { - String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); - group.setEquipTypeName(equipTypeName); - }); - //返回数据补全处理 - if (equipTypeGroup.size() < equipType.size()) { - List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); - for (Dict dict : equipType) { - String code = dict.getCode(); - if (!collect.contains(code)) { - EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); - equipTypeGroupDTO.setQuantity(0); - equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); - equipTypeGroupDTO.setEquipTypeName(dict.getName()); - equipTypeGroup.add(equipTypeGroupDTO); - } - } - } - return ResponseData.success(equipTypeGroup); + return cockpitService.fireEquipStatistics(); } /** @@ -338,47 +134,7 @@ @GetMapping("/staff/beOnDutyRatio") @ResponseBody public Object beOnDutyRatio() { - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_type", 2); - // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 - Integer total = staffInfoMapper.selectCount(wrapper); - if (0 == total) { - return ResponseData.success(null); - } - List currentDateHourList = DateUtils.getCurrentDateHourList(); - //当日离岗事件按设备去重后的个数 - // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 - List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - //补全空数据 - if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { - for (String date : currentDateHourList) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - return ResponseData.success(onDutyRatioDTOS); - } - onDutyRatioDTOS.forEach(dto -> { - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); - dto.setRatio(result + "%"); - }); - //补全空数据 - List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); - for (String date : currentDateHourList) { - if (!collect.contains(date)) { - OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); - onDutyRatioDTO.setDate(date); - onDutyRatioDTO.setRatio("0%"); - onDutyRatioDTO.setQuantity(String.valueOf(0)); - onDutyRatioDTOS.add(onDutyRatioDTO); - } - } - return ResponseData.success(onDutyRatioDTOS); + return cockpitService.beOnDutyRatio(); } /** @@ -387,67 +143,8 @@ */ @PostMapping("/device/statistics") @ResponseBody - public Object GateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { - List gateStatusGroup = null; - //2代表所有摄像头(对应字典2-7) - if ("2".equals(gateStatusGroupDTO.getDevType())) { - gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); - } else { - gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); - } - HashMap resultMap = new HashMap<>(); - //空数据处理 - List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); - if (CollectionUtils.isEmpty(gateStatusGroup)) { - List resultList = new ArrayList<>(); - for (Dict dict : deviceStatus) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - resultMap.put("total", 0); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("无该类设备信息"); - } - List resultList = new ArrayList<>(); - gateStatusGroup.forEach(group -> { - if ("2".equals(gateStatusGroupDTO.getDevType())) { - group.setDevType("2"); - } - String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(devStatus); - gateStatusGroupResponse.setRatio(result + "%"); - gateStatusGroupResponse.setQuantity(group.getQuantity()); - resultList.add(gateStatusGroupResponse); - }); - //返回数据补全处理 - if (resultList.size() < deviceStatus.size()) { - List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); - for (Dict dict : deviceStatus) { - String name = dict.getName(); - if (!collect.contains(name)) { - GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); - gateStatusGroupResponse.setStatus(dict.getName()); - gateStatusGroupResponse.setRatio("0%"); - gateStatusGroupResponse.setQuantity(0); - resultList.add(gateStatusGroupResponse); - } - } - } - resultMap.put("total", sum); - resultMap.put("list", resultList); - return ResponseData.success(resultMap); + public Object gateStatusStatistics(@RequestBody GateStatusGroupDTO gateStatusGroupDTO) { + return cockpitService.gateStatusStatistics(gateStatusGroupDTO); } /** @@ -457,80 +154,9 @@ */ @PostMapping("/device/securityScore") @ResponseBody - public Object SecurityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的position划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - List caseInfos = caseInfoMapper.selectByPosition(position); - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - //楼栋-评分实体map - //过滤空position - List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> - StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) - ).collect(Collectors.toList()); - Map resultMap = new HashMap<>(); - //空数据处理 - List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); - if (CollectionUtils.isEmpty(collect2)) { - for (Dict dict : devicePosition) { - resultMap.put(dict.getName(), 100.0); - } - return ResponseData.success(resultMap); - } - - Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); - - collect.keySet().forEach(key -> { - List list = collect.get(key); - DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); - resultMap.put(dictValue, 100 - collect1.getSum()); - }); - //返回数据补全处理 - if (collect.size() < devicePosition.size()) { - Set strings = resultMap.keySet(); - for (Dict dict : devicePosition) { - String name = dict.getName(); - if (!strings.contains(name)) { - resultMap.put(dict.getName(), 100.0); - } - } - } - //按楼层分组计算评分 -// collect.keySet().forEach(key -> { -// Map map = new HashMap<>(); -// List securityScoreDTOS = collect.get(key); -// //楼层-评分map -// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); -// collect1.keySet().forEach(key1 -> { -// map.put(key1, 100 - collect1.get(key1)); -// }); -// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); -// resultMap.put(dictValue, map); -// }); - return ResponseData.success(resultMap); + @CrossOrigin + public Object securityScore(@RequestBody SecurityScoreDTO securityScoreDTO) { + return cockpitService.securityScore(securityScoreDTO); } /** @@ -538,15 +164,8 @@ */ @GetMapping("/device/securityFrequency") @ResponseBody - public Object SecurityFrequency() { - String year = String.valueOf(DateUtil.thisYear()); - String month = String.valueOf(DateUtil.thisMonth()); - Integer quantity = caseInfoMapper.selectCountByMonth(year, month); - SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); - securityFrequencyDTO.setQuantity(quantity); - securityFrequencyDTO.setYear(year); - securityFrequencyDTO.setMonth(month); - return ResponseData.success(securityFrequencyDTO); + public Object securityFrequency() { + return cockpitService.securityFrequency(); } /** @@ -555,45 +174,7 @@ @PostMapping("/device/areaScore") @ResponseBody public Object areaScore(@RequestBody SecurityScoreDTO securityScoreDTO) { - //按发生事件的设备所在的area划分计算评分,当天发生的事件 - String position = securityScoreDTO.getPosition(); - String area = securityScoreDTO.getArea(); - if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { - return null; - } - Map resultMap = new HashMap<>(); - List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); - if (Objects.isNull(caseInfos)) { - resultMap.put("安防评分", 100.0); - return ResponseData.success(resultMap); - } - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - - List securityScoreDTOs = new ArrayList<>(); - caseInfos.forEach(caseInfo -> { - SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); - securityScoreDTO1.setPosition(caseInfo.getPosition()); - securityScoreDTO1.setArea(caseInfo.getArea()); - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - //每个事件的扣分 - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - securityScoreDTO1.setScore(score); - securityScoreDTOs.add(securityScoreDTO1); - }); - DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); - resultMap.put("安防评分", 100 - collect.getSum()); - return ResponseData.success(resultMap); + return cockpitService.areaScore(securityScoreDTO); } /** @@ -601,58 +182,9 @@ */ @PostMapping("/caseInfo/heatMap") @ResponseBody - public Object HeatMap(@RequestBody HeatMapDTO heatMapDTO) { - if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { - heatMapDTO.setMinute(3); - } - List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); - Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); - HashMap resultMap = new HashMap<>(); - if (CollectionUtils.isEmpty(collect)) { - return ResponseData.success(); - } - collect.keySet().forEach(key -> { - resultMap.put(key, collect.get(key).size()); - }); - return ResponseData.success(resultMap); - } - - private List> getResultMap(List nameList, List> resultList, Map> resultMap) { - resultMap.keySet().forEach(key -> { - List monthAndLevelGroupDTOS = resultMap.get(key); - HashMap hashMap = new HashMap<>(); - for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { -// hashMap.put("年份", andLevelGroupDTO.getYear()); - hashMap.put("月份", Integer.valueOf(andLevelGroupDTO.getMonth())); - hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); - } - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - }); - //12个月份,用于构造返回结构 - List list1 = new ArrayList<>(); - for (Map map : resultList) { - list1.add(String.valueOf(map.get("月份"))); - } - for (int i = 1; i < 13; i++) { - if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { - continue; - } - HashMap hashMap = new HashMap<>(); - hashMap.put("月份", i); - for (String s : nameList) { - if (!hashMap.keySet().contains(s)) { - hashMap.put(s, "0"); - } - } - resultList.add(hashMap); - } - List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); - return results; + @CrossOrigin + public Object heatMap(@RequestBody HeatMapDTO heatMapDTO) { + return cockpitService.heatMap(heatMapDTO); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java new file mode 100644 index 0000000..5647f31 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/MultiScoreController.java @@ -0,0 +1,108 @@ +package com.casic.missiles.modular.controller.cockpit; + +import com.casic.missiles.modular.service.PropertyManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Description: 驾驶舱二级页面-物管信息-综合评分组件 + * @Author: wangpeng + * @Date: 2022/10/10 15:47 + */ +@Slf4j +@RestController +@RequestMapping("/multiScore") +public class MultiScoreController { + @Autowired + private PropertyManageService propertyManageService; + + /** + * 员工通勤安防系数组件 + * 近7天的员工通勤安防评分 + * 横坐标 近7天时间(不算当日) + * 纵坐标 安防评分结果 + * 安防评分结果计算公式(满分100分):员工出勤率(出勤率*100)*权重(0.6)+早晚高峰区域安防评估的均值*权重(0.4) + */ + @GetMapping("/commute") + @ResponseBody + public Object commute() { + return propertyManageService.commute(); + } + + /** + * 重点区域防控系数组件 + * 近7天重点区域防控评分 + * 折柱混合,横坐标为时间,纵坐标为防控评分,折线图表示环比值(以月作为环比趋势) + * 防控评分计算公式: + * (1-重点区域发生安防事件次数/所有安防事件次数)*100*权重0.5+重点区域安防事态评估分数(当天0-23点的平均值作为当天的分数) + * *权重0.25+安防机动支援力量响应评估分数(当天0-23点的平均值作为当天的分数)*权重0.25 + */ + @GetMapping("/keyArea") + @ResponseBody + public Object keyArea() { + return propertyManageService.keyArea(); + } + + /** + * 访客控制安全系数组件 + * 近7天访客安全安防评分(不算当日) + * 柱状图 + * 横坐标表示时间 + * 纵坐标表示访客安全评分 + * 访客安防评分规则: + * 当日所有访客出现一次逾期未离开记录,减分(分数减少要开发出来可调。未在申请时间段内离开减分;未在申请区域内离开减分),满分100分 + */ + @GetMapping("/visitor") + @ResponseBody + public Object visitor() { + return propertyManageService.visitor(); + } + + /** + * 安保人员到岗系数组件 + * 近7天安保人员到岗评分(不算当日) + * 折线图 + * 横坐标 近7日时间 + * 纵坐标安保人员评分 + * 安保人员评分:安保人员到岗率*100*权重0.5+安保等级评估均值*权重0.5 + */ + @GetMapping("/security") + @ResponseBody + public Object security() { + return propertyManageService.security(); + } + + /** + * 巡视人员分布因数组件 + * 巡视人员评分(不算当日) + * 柱状图 + * 横坐标 近7天时间 + * 纵坐标 巡视安防评分 + * 巡视安防评分计算规则:机动力量在岗率*100 + * 岗位时间: + */ + @GetMapping("/patrol") + @ResponseBody + public Object patrol() { + return propertyManageService.patrol(); + } + + /** + * 其他相关安全系统指标系数组件 + * 其他相关安全评分 + * 近7天,折线图 + * 横坐标时间 + * 纵坐标其他相关安全评分 + * 其他相关安全评定规则: + * 设备在线率*100*权重0.4+安全防护评分(4个楼的评分的均值)*权重0.3+设备维修次数(满分一百分,发生一次维修减5分)*权重0.3 + */ + @GetMapping("/other") + @ResponseBody + public Object other() { + return propertyManageService.other(); + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java index 93c1949..9e063a9 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/cockpit/PropertyManageController.java @@ -1,32 +1,18 @@ package com.casic.missiles.modular.controller.cockpit; -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; -import com.casic.missiles.core.application.service.AbstractDictService; import com.casic.missiles.model.response.ResponseData; -import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.DeviceRepairLogDTO; import com.casic.missiles.modular.dto.DeviceRepairRequest; -import com.casic.missiles.modular.dto.statistics.*; -import com.casic.missiles.modular.enums.SecurityEventDict; -import com.casic.missiles.modular.enums.SecurityEventType; -import com.casic.missiles.modular.model.CaseCategoryLevel; -import com.casic.missiles.modular.model.CaseHazardLevel; -import com.casic.missiles.modular.model.CaseInfo; -import com.casic.missiles.modular.model.StaffInfo; +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; +import com.casic.missiles.modular.dto.statistics.DeviceStatusDTO; import com.casic.missiles.modular.service.DeviceInfoService; -import com.casic.missiles.modular.util.DateUtils; +import com.casic.missiles.modular.service.PropertyManageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.math.BigDecimal; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static com.casic.missiles.modular.util.DateUtils.getCurrentDateDayList; +import java.util.List; /** * @Description: 驾驶舱二级页面-物管信息 @@ -38,84 +24,18 @@ @RequestMapping("/propertyManage") public class PropertyManageController { @Autowired - private AttendanceInfoMapper attendanceInfoMapper; - - @Autowired - private StaffInfoMapper staffInfoMapper; - - @Autowired - private CaseInfoMapper caseInfoMapper; - - @Autowired - private HazardLevelMapper hazardLevelMapper; - - @Autowired - private CategoryLevelMapper categoryLevelMapper; + private PropertyManageService propertyManageService; @Autowired private DeviceInfoService deviceInfoService; - @Autowired - private AbstractDictService dictService; - - /** - * 安防事件时域频次统计,每月的每天安防事件个数(原方案) - * 月维度:展示每个月的每天的数据 - */ - @PostMapping("/case/time/keyAreaStatistic") - @ResponseBody - public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { - String year = monthAndDayGroupDTO.getYear(); - String month = monthAndDayGroupDTO.getMonth(); - List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); - resultList.forEach(result -> { - result.setYear(year); - result.setMonth(month); - }); - return ResponseData.success(resultList); - } - /** * 12、安防事件时域频次统计,统计变为近365天/一个月/近7天 */ @PostMapping("/case/time/keyAreaStatistic/{dimension}") @ResponseBody public Object keyAreaData(@PathVariable("dimension") String dimension) { - List resultList = null; - List dateList = null; - if ("year".equals(dimension)) { - //近365天数据按月分组统计 - resultList = caseInfoMapper.selectPreMonthCountByNearYear(); - dateList = DateUtils.getCurrentDateMonthList(); - } else if ("month".equals(dimension)) { - //近30天数据按周分组统计 - resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); - dateList = DateUtils.getCurrentDateWeekList(); - } else if ("week".equals(dimension)) { - //近7天数据按天分组统计 - resultList = caseInfoMapper.selectPreDayCountBySevenDay(); - dateList = getCurrentDateDayList(); - } - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } else { - for (String date : dateList) { - List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); - if (!collect.contains(date)) { - PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); - preMonthOrWeekCaseDTO.setDimension(date); - preMonthOrWeekCaseDTO.setQuantity(0); - resultList.add(preMonthOrWeekCaseDTO); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.keyAreaData(dimension); } @@ -126,67 +46,7 @@ @PostMapping("/case/frequency/keyAreaStatistic") @ResponseBody public Object keyAreaFrequencyStatistic(@RequestBody AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { - String year = avgMonthAndWeekGroupDTO.getYear(); - List monthList = caseInfoMapper.selectPreMonthCountByYear(year); - Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - HashMap strAvgMap = new HashMap<>(); - List resultList = new ArrayList<>(); - for (String key : collect.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - //若年份是本年,则使用各安防级别数量/当前月份数 - //若不是本年,除数为12 - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - monthAndWeekDTO.setMonthQuantity(sum / 12); - strAvgMap.put(key, monthAndWeekDTO); - } - } - - List weekList = caseInfoMapper.selectPreWeekCountByYear(year); - Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); - for (String key : collect1.keySet()) { - List preMonthOrWeekCaseDTOS = collect.get(key); - int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); - if (year.equals(String.valueOf(DateUtil.thisYear()))) { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); - strAvgMap.put(key, monthAndWeekDTO); - } - } else { - if (!Objects.isNull(strAvgMap.get(key))) { - MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } else { - MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); - String hazardName = hazardLevelMapper.selectHazardNameByCode(key); - monthAndWeekDTO.setLevelName(hazardName); - monthAndWeekDTO.setWeekQuantity(sum / 52); - strAvgMap.put(key, monthAndWeekDTO); - } - } - } - strAvgMap.keySet().forEach(key -> { - resultList.add(strAvgMap.get(key)); - }); - return ResponseData.success(resultList); + return propertyManageService.keyAreaFrequencyStatistic(avgMonthAndWeekGroupDTO); } /** @@ -197,48 +57,7 @@ @PostMapping("/staff/attendanceRatio") @ResponseBody public Object attendanceRatio(@RequestBody AttendanceRatioDTO attendanceRatioDTO) { - //各类型员工及总数 - List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); - Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); - - String dateDimension = attendanceRatioDTO.getDateDimension(); - List attendanceRatioDTOS = new ArrayList<>(); - //考勤的人数,按单次考勤过滤 - if ("week".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); - } else if ("month".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); - } else if ("year".equals(dateDimension)) { - attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); - } - if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //计算出勤率 - - List> resultList = new ArrayList<>(); - Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); - dateMap.keySet().forEach(key -> { - HashMap hashMap = new HashMap<>(); - List attendances = dateMap.get(key); - attendances.forEach(attendanceRatio -> { - attendanceRatio.setDateDimension(dateDimension); - attendanceRatio.setStaffType(attendanceRatio.getStaffType()); - List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); - String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); - attendanceRatio.setAttendanceRatio(ratio + "%"); - //构造返回结构 - hashMap.put("时间", attendanceRatio.getDate()); - String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); - hashMap.put(name, attendanceRatio.getAttendanceRatio()); - }); - resultList.add(hashMap); - }); - return ResponseData.success(resultList); + return propertyManageService.attendanceRatio(attendanceRatioDTO); } /** @@ -247,60 +66,7 @@ @PostMapping("/staff/attendanceNumber/{dimension}") @ResponseBody public Object attendanceNumber(@PathVariable("dimension") String dimension) { - List attendanceNumberDTOs = null; - List> resultList = new ArrayList<>(); - List dateList = new ArrayList<>(); - if ("week".equals(dimension)) { - //近7天数据按天分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); - dateList = DateUtils.getCurrentDateDayList(); - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); - dateList = DateUtils.getCurrentDateHourList(); - } - if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { - return ResponseData.error("该查询条件下,无员工出勤数据!"); - } - Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); - collect.keySet().forEach(key -> { - List attendanceNumberDTOS = collect.get(key); - Map resultMap = new HashMap<>(); - AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); - if (attendanceNumberDTOS.size() >= 2) { - AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); - resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); - } - resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); - resultMap.put("staticTime", attendanceNumberDTO.getDate()); - resultList.add(resultMap); - }); - //补全空数据处理 - if (CollectionUtils.isEmpty(resultList)) { - for (String date : dateList) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } else { - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = map.get("staticTime"); - collectList.add(staticTime); - } - for (String date : dateList) { - if (!collectList.contains(date)) { - Map resultMap = new HashMap<>(); - resultMap.put("1", "0"); - resultMap.put("2", "0"); - resultMap.put("staticTime", date); - resultList.add(resultMap); - } - } - } - return ResponseData.success(resultList); + return propertyManageService.attendanceNumber(dimension); } /** @@ -309,131 +75,7 @@ @PostMapping("/security/assessment/{dimension}") @ResponseBody public Object securityAssessment(@PathVariable("dimension") String dimension) { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - if ("week".equals(dimension)) { - //近7天早晚高峰数据 - List caseInfos = caseInfoMapper.selectListBySevenDay(); - //按时间(天)进行分组 - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(" "); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - } else if ("day".equals(dimension)) { - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDatePeakHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } - - } - return null; + return propertyManageService.securityAssessment(dimension); } /** @@ -442,72 +84,7 @@ @GetMapping("/security/keyAreaStatistic") @ResponseBody public Object keyAreaStatistic() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap categoryScoreMap = new HashMap<>(); - List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); - categoryLevelList.forEach(categoryLevel -> { - categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday2(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); - Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(new ArrayList<>()); - } + return propertyManageService.keyAreaStatistic(); } /** @@ -516,70 +93,7 @@ @GetMapping("/security/responseAssess") @ResponseBody public Object responseAssess() { - //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 - HashMap hazardScoreMap = new HashMap<>(); - List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); - caseHazardLevelList.forEach(hazardLevel -> { - hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); - }); - HashMap hashMap = new HashMap<>(); - //今天数据按小时分组统计 - List caseInfos = caseInfoMapper.selectListByToday3(); - caseInfos.forEach(caseInfo -> { - String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); - //扣分=事件级别权重*未解决小时数 - Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); - Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); - long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); - Double score = Double.valueOf(hazardWeight) * between; - String[] array = caseInfo.getHappenTime().split(":"); - String dayTime = array[0]; - BigDecimal preScore; - if (hashMap.containsKey(dayTime)) { - Double aDouble = hashMap.get(dayTime); - preScore = new BigDecimal(aDouble.toString()); - } else { - preScore = new BigDecimal("100.0"); - } - BigDecimal nowScore = new BigDecimal(score.toString()); - hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); - }); - - List> resultList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(hashMap)) { - hashMap.keySet().forEach(key -> { - HashMap map = new HashMap<>(); - map.put("日期", key); - map.put("安防评估", hashMap.get(key)); - resultList.add(map); - }); - //补全空数据处理 - List collectList = new ArrayList<>(); - for (Map map : resultList) { - String staticTime = String.valueOf(map.get("日期")); - collectList.add(staticTime); - } - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - if (!collectList.contains(date)) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - } - return ResponseData.success(resultList); - } else { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateDayList(); - for (String date : dateList) { - HashMap map = new HashMap<>(); - map.put("日期", date); - map.put("安防评估", 100); - resultList.add(map); - } - return ResponseData.success(resultList); - } + return propertyManageService.responseAssess(); } /** @@ -588,34 +102,8 @@ */ @GetMapping("/case/hazardLevelStatistics/{dimension}") @ResponseBody - public Object HazardLevelStatistics(@PathVariable("dimension") String dimension) { - List hazardLevelGroup = null; - if ("week".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); - } else if ("month".equals(dimension)) { - hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); - } - if (CollectionUtils.isEmpty(hazardLevelGroup)) { - log.info("重点区域威胁事件类型统计,无安防事件"); - return ResponseData.error("无安防事件发生!"); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); - if (sum <= 0) { - return ResponseData.error("安防事件总数为0"); - } - hazardLevelGroup.forEach(group -> { - CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); - group.setLevelName(caseHazardLevel.getName()); - String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); - group.setLevelRatio(result + "%"); - }); - HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); - hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); - hazardLevelGroupResponse.setQuantity(sum); - return ResponseData.success(hazardLevelGroupResponse); + public Object hazardLevelStatistics(@PathVariable("dimension") String dimension) { + return propertyManageService.hazardLevelStatistics(dimension); } /** @@ -627,32 +115,7 @@ @GetMapping("/security/rank") @ResponseBody public Object securityRank() { - //考勤表近一个月按人员分组的考勤个数前十名 - List list = attendanceInfoMapper.getCountForRank(); - List> resultList = new ArrayList<>(); - if (CollectionUtils.isEmpty(list)) { - //补全空数据处理 - List staffList = staffInfoMapper.selectListLimitTen(); - for (StaffInfo staffInfo : staffList) { - HashMap hashMap = new HashMap<>(); - hashMap.put(staffInfo.getStaffName(), "0%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); - } - NumberFormat numberFormat = NumberFormat.getInstance(); - // 设置精确到小数点后2位 - numberFormat.setMaximumFractionDigits(2); - //构造返回结构 - for (SecurityRankDTO dto : list) { - // TODO: 2022/9/15 分母使用30,后续看产品定义 - HashMap hashMap = new HashMap<>(); - String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); - hashMap.put("name", dto.getStaffName()); - hashMap.put("ratio", result + "%"); - resultList.add(hashMap); - } - return ResponseData.success(resultList); + return propertyManageService.securityRank(); } /** @@ -661,26 +124,7 @@ @GetMapping("/security/levelAssess") @ResponseBody public Object securityLevelAssess() { - //今天数据按小时分组统计 - List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); - if (CollectionUtils.isEmpty(resultList)) { - //补全空数据处理 - List dateList = DateUtils.getCurrentDateWorkHourList(); - for (String date : dateList) { - SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); - levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); - levelAssessDTO.setDate(date); -// levelAssessDTO.setQuantity(); - resultList.add(levelAssessDTO); - } - return ResponseData.success(resultList); - } - resultList.forEach(result -> { - BigDecimal deScore = new BigDecimal(result.getQuantity()); - BigDecimal preScore = new BigDecimal("100.0"); - result.setScore(preScore.subtract(deScore).doubleValue()); - }); - return ResponseData.success(resultList); + return propertyManageService.securityLevelAssess(); } /** @@ -702,4 +146,21 @@ List deviceStatusDTOS = deviceInfoService.getDeviceStatusGroup(); return ResponseData.success(deviceStatusDTOS); } + + /** + * 安防事件时域频次统计,每月的每天安防事件个数(原方案) + * 月维度:展示每个月的每天的数据 + */ +// @PostMapping("/case/time/keyAreaStatistic") +// @ResponseBody +// public Object keyAreaTimeStatistic(@RequestBody MonthAndDayGroupDTO monthAndDayGroupDTO) { +// String year = monthAndDayGroupDTO.getYear(); +// String month = monthAndDayGroupDTO.getMonth(); +// List resultList = caseInfoMapper.selectCountByMonthAndDay(year, month); +// resultList.forEach(result -> { +// result.setYear(year); +// result.setMonth(month); +// }); +// return ResponseData.success(resultList); +// } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java index 191def1..34011af 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/controller/hik/HikController.java @@ -210,7 +210,8 @@ //高空抛物事件处理 caseInfo1 = hikService.highAltitudeParabolicHandle(event, caseInfo1); } - if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime())) { + //过滤掉无发生时间 + if (!Objects.isNull(caseInfo1) && !StringUtils.isEmpty(caseInfo1.getHappenTime()) && !StringUtils.isEmpty(caseInfo1.getDeviceCode())) { caseInfos.add(caseInfo1); } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java index 02c1f49..af971b6 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/CaseInfoMapper.java @@ -71,4 +71,24 @@ List getCaseInfoList(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); List selectByPositionAndArea(@Param("position") String position, @Param("area") String area); + + List getCaseInfoListUnResolved(@Param("caseInfoRequest") CaseInfoRequest caseInfoRequest); + + int updateAllStatus(); + + List selectPreDayCountBySevenDayKeyArea(); + + List selectDemobilizedCountSevenDay(@Param("eventType") Number eventType); + + List selectListByTypeSevenDay(@Param("eventType") Number eventType); + + List selectListBySevenDayKeyArea(); + + List selectByPositionSevenDay(@Param("position") String position); + + List selectPreDayCountByBeforeMonthKeyArea(); + + List selectPreDayCountByBeforeMonth(); + + List selectListByBeforeMonthKeyArea(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java index 5bfaf63..bd9dc12 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/DeviceRepairLogMapper.java @@ -20,4 +20,6 @@ List getDeviceRepairListPage(@Param("page") Page page, @Param("deviceRepairRequest")DeviceRepairRequest deviceRepairRequest); List getDeviceRepairList(@Param("deviceRepairRequest") DeviceRepairRequest deviceRepairRequest); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java index 6c52542..2476000 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitInfoMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.missiles.modular.dto.VisitorRequest; +import com.casic.missiles.modular.dto.statistics.MultiScoreVisitorDTO; import com.casic.missiles.modular.model.VisitInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,6 @@ List getVisitInfoListPage(@Param("page") Page page, @Param("visitorRequest") VisitorRequest visitorRequest); VisitInfo selectByOrderId(@Param("orderId") String orderId); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java index 6ea55bd..df6985a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/VisitorApplyMapper.java @@ -21,4 +21,6 @@ List getVisitorApplyListPage(@Param("page") Page page, @Param("visitorApplyRequest") VisitorApplyRequest visitorApplyRequest); List selectByVisitReason(); + + List selectListBySevenDay(); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml index a07c992..60bd1ea 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/AttendanceInfoMapper.xml @@ -35,7 +35,7 @@ and DATE_FORMAT(atte_date,"%y%m%d") = CURRENT_DATE - + - + - + - SELECT * - FROM bus_case_info + SELECT bci.*, bdi.draw_no AS drawNo + FROM bus_case_info bci LEFT JOIN bus_device_info bdi ON bci.index_code = bdi.index_code WHERE 1=1 - and hazard_level_code = #{caseInfoRequest.level} + and bci.hazard_level_code = #{caseInfoRequest.level} - and category_level_code = #{caseInfoRequest.type} + and bci.category_level_code = #{caseInfoRequest.type} - and status = #{caseInfoRequest.status} + and bci.status = #{caseInfoRequest.status} - and description = #{caseInfoRequest.description} + and bci.description like concat('%',#{caseInfoRequest.description},'%') + + + and bci.position = #{caseInfoRequest.position} + + + and bci.area = #{caseInfoRequest.area} + + + and bdi.draw_no = #{caseInfoRequest.drawNo} + + + and bci.happen_time >= #{caseInfoRequest.happenStartTime} + + + and bci.happen_time <= #{caseInfoRequest.happenEndTime} ORDER by happen_time DESC @@ -165,7 +180,7 @@ FROM bus_case_info WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null - AND (hour(happen_time) BETWEEN 06 and 23) + AND (hour(happen_time) BETWEEN 06 and DATE_FORMAT(CURRENT_DATE,'%h')) AND is_key_area = 1 @@ -175,7 +190,7 @@ WHERE TO_DAYS(happen_time) = TO_DAYS(now()) AND hazard_level_code is not null AND is_key_area = 1 - AND hour(timediff(update_time, happen_time)) >= 1; + AND hour(timediff(update_time, happen_time)) >= 1 + + + + + update bus_case_info set status = 3 where status != 3 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml index 1d25cbd..7d24f8b 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/CategoryLevelMapper.xml @@ -6,11 +6,11 @@ SELECT * FROM bus_case_category_level WHERE 1=1 - + and code = #{categoryLevelRequest.code} - - and name = #{categoryLevelRequest.name} + + and name like concat('%',#{categoryLevelRequest.name},'%') ORDER by create_time DESC @@ -24,7 +24,10 @@ and code = #{categoryLevelRequest.code} - and name = #{categoryLevelRequest.name} + and name like concat('%',#{categoryLevelRequest.name},'%') + + + and description like concat('%',#{categoryLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml index bc3cbfc..043a3c2 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceInfoMapper.xml @@ -7,10 +7,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} @@ -35,10 +35,10 @@ FROM bus_device_info WHERE 1=1 - and dev_code = #{deviceInfoRequest.devCode} + and dev_code like concat('%',#{deviceInfoRequest.devCode},'%') - and dev_name = #{deviceInfoRequest.devName} + and dev_name like concat('%',#{deviceInfoRequest.devName},'%') and dev_type = #{deviceInfoRequest.devType} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml index cf1a481..4e39921 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/DeviceRepairLogMapper.xml @@ -33,4 +33,11 @@ ORDER by create_time DESC + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml index 458322b..544abdb 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/HazardLevelMapper.xml @@ -6,11 +6,14 @@ SELECT * FROM bus_case_hazard_level WHERE 1=1 - + and code = #{hazardLevelRequest.code} - - and name = #{hazardLevelRequest.name} + + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC @@ -24,7 +27,10 @@ and code = #{hazardLevelRequest.code} - and name = #{hazardLevelRequest.name} + and name like concat('%',#{hazardLevelRequest.name},'%') + + + and description like concat('%',#{hazardLevelRequest.description},'%') ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml index 2e94ec9..9aef589 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/StaffInfoMapper.xml @@ -32,11 +32,11 @@ SELECT * FROM bus_staff_info WHERE 1=1 - - and (staff_code like concat('%',#{keywords},'%') or staff_name like concat('%',#{keywords},'%')) + + and (staff_code like concat('%',#{staffInfoRequest.keywords},'%') or staff_name like concat('%',#{staffInfoRequest.keywords},'%')) - - and staff_type = #{staffType} + + and staff_type = #{staffInfoRequest.staffType} ORDER by create_time DESC diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml index 230529a..9e8d5f7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitInfoMapper.xml @@ -29,4 +29,14 @@ WHERE order_id = #{orderId} and DATE_FORMAT(in_time,'%Y-%m-%d') = CURRENT_DATE limit 1 + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml index 3c388b7..42f0645 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml +++ b/casic-server/src/main/java/com/casic/missiles/modular/dao/mapping/VisitorApplyMapper.xml @@ -28,4 +28,11 @@ FROM bus_visit_info GROUP BY visit_reason + + \ No newline at end of file diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java index c10655e..a7ff759 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/CaseInfoRequest.java @@ -16,4 +16,10 @@ private String description; private String happenStartTime; private String happenEndTime; + //区域 + private String position; + //楼层 + private String area; + //图纸编号 + private String drawNo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java index aa4bb17..1b06e1e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/HazardLevelRequest.java @@ -11,4 +11,5 @@ public class HazardLevelRequest { private String code; private String name; + private String description; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java new file mode 100644 index 0000000..76724ed --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreDemobilizeDTO.java @@ -0,0 +1,14 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 近7天安保人员离岗实体 + * @Author: wangpeng + * @Date: 2022/10/14 14:37 + */ +@Data +public class MultiScoreDemobilizeDTO { + private String date; + private Integer leaveCount; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java new file mode 100644 index 0000000..d109191 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/MultiScoreVisitorDTO.java @@ -0,0 +1,20 @@ +package com.casic.missiles.modular.dto.statistics; + +import lombok.Data; + +/** + * @Description: 综合评分组件-访客控制安全系数组件DTO + * @Author: wangpeng + * @Date: 2022/10/14 9:35 + */ +@Data +public class MultiScoreVisitorDTO { + private String applyInTime; + private String applyOutTime; + private String applyVisitPosition; + private String inTime; + private String outTime; + private String visitPosition; + //日期统计维度,分组使用 + private String date; +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java index f7bd4a2..602b4c7 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/dto/statistics/SecurityScoreDTO.java @@ -15,4 +15,7 @@ private String area; //评分,出参 private Double score; + + //综合评分组件-其他相关安全系统指标系数组件使用 + private String date; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java index 316188e..71d587d 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CaseInfoService.java @@ -22,4 +22,11 @@ boolean insertCaseInfoBatch(List caseInfos); List caseInfoList(CaseInfoRequest caseInfoRequest); + + List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest); + + Object caseInfoLastByDrawNo(String drawNo); + + int updateAllStatus(); + } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java index b3d1968..7a7fe8a 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/CockpitService.java @@ -2,6 +2,10 @@ import com.alibaba.fastjson.JSONArray; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.GateStatusGroupDTO; +import com.casic.missiles.modular.dto.statistics.HeatMapDTO; +import com.casic.missiles.modular.dto.statistics.MonthAndLevelGroupDTO; +import com.casic.missiles.modular.dto.statistics.SecurityScoreDTO; import java.util.HashMap; import java.util.List; @@ -13,4 +17,32 @@ */ public interface CockpitService { HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap); + + Object buildingNumberPerHour(); + + Object visitorTodayNumber(); + + Object deviceNumber(); + + Object securityNumber(); + + Object visitorApplyDetail(); + + Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO); + + Object eventCategoryStatistics(); + + Object fireEquipStatistics(); + + Object beOnDutyRatio(); + + Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO); + + Object securityScore(SecurityScoreDTO securityScoreDTO); + + Object securityFrequency(); + + Object areaScore(SecurityScoreDTO securityScoreDTO); + + Object heatMap(HeatMapDTO heatMapDTO); } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java new file mode 100644 index 0000000..178b909 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/PropertyManageService.java @@ -0,0 +1,43 @@ +package com.casic.missiles.modular.service; + +import com.casic.missiles.modular.dto.statistics.AttendanceRatioDTO; +import com.casic.missiles.modular.dto.statistics.AvgMonthAndWeekGroupDTO; + +/** + * @Description: + * @Author: wangpeng + * @Date: 2022/10/11 9:10 + */ +public interface PropertyManageService { + Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO); + + Object keyAreaData(String dimension); + + Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO); + + Object attendanceNumber(String dimension); + + Object securityAssessment(String dimension); + + Object keyAreaStatistic(); + + Object responseAssess(); + + Object hazardLevelStatistics(String dimension); + + Object securityRank(); + + Object securityLevelAssess(); + + Object commute(); + + Object keyArea(); + + Object visitor(); + + Object security(); + + Object patrol(); + + Object other(); +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java index ea6b8c0..2580187 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/BlackInfoServiceImpl.java @@ -17,6 +17,7 @@ import com.casic.missiles.modular.service.BlackInfoService; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -70,11 +71,17 @@ faceInfo.setCertificateNum(blackInfo.getIdCardNo()); faceSingleAddOrUpdateRequest.setFaceInfo(faceInfo); FacePic facePic = new FacePic(); - facePic.setFaceBinaryData(blackInfo.getPicture()); - faceSingleAddOrUpdateRequest.setFacePic(facePic); + String picture = blackInfo.getPicture(); + if(StringUtils.isNotEmpty(picture)){ + String substringPicture = picture.substring(picture.indexOf(",") + 1); + facePic.setFaceBinaryData(substringPicture); + } faceSingleAddOrUpdateRequest.setFacePic(facePic); String body = JSONObject.toJSONString(faceSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.FACE_SINGLE_ADDITION, body); + log.info("-----------------------"); + log.info("增加黑名单人脸请求body,{}", body); + log.info("增加黑名单人脸resultStr:{}", JSONObject.toJSONString(resultStr)); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人脸失败,海康response:{}", resultStr); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java index 6b03d8b..1c34f68 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CaseInfoServiceImpl.java @@ -2,17 +2,22 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.dao.CaseInfoMapper; import com.casic.missiles.modular.dao.CategoryLevelMapper; +import com.casic.missiles.modular.dao.DeviceInfoMapper; import com.casic.missiles.modular.dao.HazardLevelMapper; import com.casic.missiles.modular.dto.CaseInfoRequest; import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.model.CaseInfo; +import com.casic.missiles.modular.model.DeviceInfo; import com.casic.missiles.modular.service.CaseInfoService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,6 +31,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; /** * @Description: 安防事件service @@ -50,6 +56,9 @@ @Resource private AbstractDictService dictService; + @Resource + private DeviceInfoMapper deviceInfoMapper; + @Override public List caseInfoListPage(Page page, CaseInfoRequest caseInfoRequest) { try { @@ -136,17 +145,69 @@ @Override public List caseInfoList(CaseInfoRequest caseInfoRequest) { try { - List pageList = caseInfoMapper.getCaseInfoList(caseInfoRequest); - pageList.forEach(caseInfo ->{ + List list = caseInfoMapper.getCaseInfoList(caseInfoRequest); + list.forEach(caseInfo ->{ caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); }); - return pageList; + return list; } catch (DataAccessException ex) { log.error("安防事件: 查询不分页出现异常, 异常:{}", ex); } return null; } + + @Override + public List caseInfoListUnResolved(CaseInfoRequest caseInfoRequest) { + try { + List list = caseInfoMapper.getCaseInfoListUnResolved(caseInfoRequest); + list.forEach(caseInfo ->{ + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + }); + return list; + } catch (DataAccessException ex) { + log.error("未解决/解决中安防事件: 查询不分页出现异常, 异常:{}", ex); + } + return null; + } + + @Override + public Object caseInfoLastByDrawNo(String drawNo) { + //图纸编号和设备编号一一对应 + QueryWrapper dWrapper = new QueryWrapper<>(); + dWrapper.eq("draw_no", drawNo); + DeviceInfo deviceInfo = deviceInfoMapper.selectOne(dWrapper); + if(Objects.isNull(deviceInfo)){ + return ResponseData.error("该图纸编号下不存在关联的设备"); + } + if(StringUtils.isEmpty(deviceInfo.getDevCode())){ + return ResponseData.error("该图纸编号下不存在对应的设备编号"); + }else{ + String devCode = deviceInfo.getDevCode(); + QueryWrapper cWrapper = new QueryWrapper<>(); + cWrapper.eq("device_code", devCode); + List caseInfos = caseInfoMapper.selectList(cWrapper); + if(CollectionUtil.isEmpty(caseInfos)){ + return ResponseData.error("该图纸编号下不存在最近发生的事件"); + } + CaseInfo caseInfo = caseInfos.get(caseInfos.size() - 1); + caseInfo.setDrawNo(deviceInfo.getDrawNo()); + caseInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.CASE_STATUS, caseInfo.getStatus())); + caseInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, caseInfo.getPosition())); + caseInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, caseInfo.getArea())); + caseInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, caseInfo.getIsKeyArea())); + return ResponseData.success(caseInfo); + } + } + + @Override + public int updateAllStatus() { + int upflag = caseInfoMapper.updateAllStatus(); + return upflag; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java index 7402991..7fb5a6e 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/CockpitServiceImpl.java @@ -4,15 +4,34 @@ import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.dao.*; import com.casic.missiles.modular.dto.hik.DoorEventsRequest; +import com.casic.missiles.modular.dto.statistics.*; import com.casic.missiles.modular.enums.HikUri; +import com.casic.missiles.modular.enums.SecurityEventDict; import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.redis.RedisUtil; +import com.casic.missiles.modular.redis.key.CacheKeys; import com.casic.missiles.modular.service.CockpitService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; import com.casic.missiles.modular.util.HikUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import java.text.MessageFormat; +import java.text.NumberFormat; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.*; +import java.util.stream.Collectors; /** * @Description: @@ -22,6 +41,28 @@ @Slf4j @Service public class CockpitServiceImpl implements CockpitService { + @Autowired + private StatisticNumberMapper numberMapper; + @Autowired + private AbstractDictService dictService; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private DeviceInfoMapper deviceInfoMapper; + @Autowired + private FireEquipInfoMapper fireEquipInfoMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private VisitorApplyMapper applyMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private RedisUtil redisUtil; @Override public HashMap dataHandle(DoorEventsRequest doorEventsRequest, HashMap> configMap, HashMap jsonMap, HashMap resultMap) { @@ -106,4 +147,512 @@ }); return resultMap; } + + @Override + public Object buildingNumberPerHour() { + //当天按小时分组的人数 + List list = numberMapper.selectListByTime(); + Map> collect = list.stream().collect(Collectors.groupingBy(BuildingNumberDTO::getStatisticTime)); + //定时任务中已将每小时三栋楼人数存到数据库 + //将一期主楼和录制楼人数合并,二期单算 + List> resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List buildingNumberDTOS = collect.get(key); + BuildingNumberDTO mainBuildingOne = buildingNumberDTOS.get(0); + BuildingNumberDTO mainBuildingTwo = buildingNumberDTOS.get(1); + BuildingNumberDTO recordingBuilding = buildingNumberDTOS.get(2); + HashMap resultMap = new HashMap<>(); + Integer oneQuantity = Integer.valueOf(mainBuildingOne.getStatisticQuantity()); + Integer recordingQuantity = Integer.valueOf(recordingBuilding.getStatisticQuantity()); + resultMap.put("staticTime", mainBuildingOne.getStatisticTime()); + resultMap.put(mainBuildingOne.getStatisticPositionName() + "、" + recordingBuilding.getStatisticPositionName(), String.valueOf(oneQuantity + recordingQuantity)); + resultMap.put(mainBuildingTwo.getStatisticPositionName(), mainBuildingTwo.getStatisticQuantity()); + resultList.add(resultMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object visitorTodayNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.apply("date_format(now(),'%Y-%m-%d') = date_format(in_time,'%Y-%m-%d')"); + List visitInfos = visitInfoMapper.selectList(wrapper); + HashMap resultMap = new HashMap<>(); + resultMap.put("今日访客量", visitInfos.size()); + return ResponseData.success(resultMap); + } + + @Override + public Object deviceNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + Integer total = deviceInfoMapper.selectCount(wrapper); + QueryWrapper wrapper1 = new QueryWrapper<>(); + wrapper1.eq("status", 1); //字典值:在线1、离线2、故障3 + Integer online = deviceInfoMapper.selectCount(wrapper1); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) online / (float) total * 100); + HashMap resultMap = new HashMap<>(); + resultMap.put("设备总数", total); + resultMap.put("设备在线率", result + "%"); + return ResponseData.success(resultMap); + } + + @Override + public Object securityNumber() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + Integer leave = caseInfoMapper.selectDemobilizedCount(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) leave / (float) total * 100); + HashMap resultMap = new HashMap<>(); + if (0 == total) { + resultMap.put("安保人员总数", 0); + resultMap.put("安保人员离岗率", "0"); + } else { + resultMap.put("安保人员总数", total); + resultMap.put("安保人员离岗率", result + ""); + } + return ResponseData.success(resultMap); + } + + @Override + public Object visitorApplyDetail() { + List reasonGroup = applyMapper.selectByVisitReason(); + List resultList = new ArrayList<>(); + //空数据处理 + List visitReason = dictService.findInDictByCode(SecurityEventDict.VISIT_REASON); + if (CollectionUtils.isEmpty(reasonGroup)) { + for (Dict dict : visitReason) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(dict.getName()); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = reasonGroup.stream().collect(Collectors.summarizingInt(ApplyReasonGroupDTO::getQuantity)).getSum(); + if (0 == sum) { + return ResponseData.success(); + } + reasonGroup.forEach(group -> { + String reasonName = dictService.getDictNameByCode(SecurityEventDict.VISIT_REASON, group.getVisitReason()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(group.getQuantity()); + applyReasonGroupDTO.setVisitReason(reasonName); + applyReasonGroupDTO.setRatio(result + "%"); + resultList.add(applyReasonGroupDTO); + }); + //返回数据补全处理 + if (resultList.size() < visitReason.size()) { + List collect = resultList.stream().map(ApplyReasonGroupDTO::getVisitReason).collect(Collectors.toList()); + for (Dict dict : visitReason) { + String name = dict.getName(); + if (!collect.contains(name)) { + ApplyReasonGroupDTO applyReasonGroupDTO = new ApplyReasonGroupDTO(); + applyReasonGroupDTO.setQuantity(0); + applyReasonGroupDTO.setVisitReason(name); + applyReasonGroupDTO.setRatio("0%"); + resultList.add(applyReasonGroupDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaEventStatistic(MonthAndLevelGroupDTO monthAndLevelGroupDTO) { + //查询各危险级别权重name,用于构造返回结构 + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + List nameList = caseHazardLevelList.stream().map(CaseHazardLevel::getName).collect(Collectors.toList()); + + Object o = redisUtil.get(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear())); + List list = JSONArray.parseArray(String.valueOf(o), MonthAndLevelGroupDTO.class); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(list)) { + Map> resultMap = list.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + //查询数据,放入redis + List monthAndLevelGroup = caseInfoMapper.selectByLevelAndMonth(monthAndLevelGroupDTO.getYear()); + Map> resultMap = monthAndLevelGroup.stream().collect(Collectors.groupingBy(MonthAndLevelGroupDTO::getMonth)); + //设置过期时间为每月1号0点 + LocalDateTime midnight = LocalDateTime.now().plusMonths(1).withDayOfMonth(1).withHour(0) + .withMinute(0).withSecond(0).withNano(0); + long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight); + redisUtil.set(MessageFormat.format(CacheKeys.MONTH_STATISTIC_KEY, monthAndLevelGroupDTO.getYear()), JSONObject.toJSONString(monthAndLevelGroup), between); + //构造返回结构 + List> results = getResultMap(nameList, resultList, resultMap); + results.stream().sorted(); + results.stream().forEach(result -> { + String monthName = String.valueOf(result.get("月份")); + if(monthName.length() == 1){ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-0" + monthName); + }else{ + result.put("月份", monthAndLevelGroupDTO.getYear() + "-" + monthName); + } + }); + return ResponseData.success(results); + } + + @Override + public Object eventCategoryStatistics() { + List categoryLevelGroup = caseInfoMapper.selectByCategoryLevel(); + return ResponseData.success(categoryLevelGroup); + } + + @Override + public Object fireEquipStatistics() { + List equipTypeGroup = fireEquipInfoMapper.selectByEquipType(); + //空数据处理 + List equipType = dictService.findInDictByCode(SecurityEventDict.EQUIP_TYPE); + if (CollectionUtils.isEmpty(equipTypeGroup)) { + for (Dict dict : equipType) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + return ResponseData.success(equipTypeGroup); + } + equipTypeGroup.forEach(group -> { + String equipTypeName = dictService.getDictNameByCode(SecurityEventDict.EQUIP_TYPE, group.getEquipTypeCode()); + group.setEquipTypeName(equipTypeName); + }); + //返回数据补全处理 + if (equipTypeGroup.size() < equipType.size()) { + List collect = equipTypeGroup.stream().map(EquipTypeGroupDTO::getEquipTypeCode).collect(Collectors.toList()); + for (Dict dict : equipType) { + String code = dict.getCode(); + if (!collect.contains(code)) { + EquipTypeGroupDTO equipTypeGroupDTO = new EquipTypeGroupDTO(); + equipTypeGroupDTO.setQuantity(0); + equipTypeGroupDTO.setEquipTypeCode(dict.getCode()); + equipTypeGroupDTO.setEquipTypeName(dict.getName()); + equipTypeGroup.add(equipTypeGroupDTO); + } + } + } + return ResponseData.success(equipTypeGroup); + } + + @Override + public Object beOnDutyRatio() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + if (0 == total) { + return ResponseData.success(null); + } + List currentDateHourList = DateUtils.getCurrentDateWorkHourList(); + //当日离岗事件按设备去重后的个数 + // TODO: 2022/9/2 目前相当于24小时内的计算,之后看需要可改成自定义小时数计算离岗率,即离岗+6小时内仅一次离岗则恢复为100%,多次则累加离岗次数计算离岗率 + List onDutyRatioDTOS = caseInfoMapper.selectDemobilizedCountByHour(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + //补全空数据 + if (CollectionUtils.isEmpty(onDutyRatioDTOS)) { + for (String date : currentDateHourList) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + return ResponseData.success(onDutyRatioDTOS); + } + onDutyRatioDTOS.forEach(dto -> { + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format(100 - Float.valueOf(dto.getQuantity()) / (float) total * 100); + dto.setRatio(result + "%"); + }); + //补全空数据 + List collect = onDutyRatioDTOS.stream().map(OnDutyRatioDTO::getDate).collect(Collectors.toList()); + for (String date : currentDateHourList) { + if (!collect.contains(date)) { + OnDutyRatioDTO onDutyRatioDTO = new OnDutyRatioDTO(); + onDutyRatioDTO.setDate(date); + onDutyRatioDTO.setRatio("0%"); + onDutyRatioDTO.setQuantity(String.valueOf(0)); + onDutyRatioDTOS.add(onDutyRatioDTO); + } + } + return ResponseData.success(onDutyRatioDTOS); + } + + @Override + public Object gateStatusStatistics(GateStatusGroupDTO gateStatusGroupDTO) { + List gateStatusGroup = null; + //2代表所有摄像头(对应字典2-7) + if ("2".equals(gateStatusGroupDTO.getDevType())) { + gateStatusGroup = deviceInfoMapper.selectByTypeForCamera(); + } else { + gateStatusGroup = deviceInfoMapper.selectByType(gateStatusGroupDTO.getDevType()); + } + HashMap resultMap = new HashMap<>(); + //空数据处理 + List deviceStatus = dictService.findInDictByCode(SecurityEventDict.DEVICE_STATUS); + if (CollectionUtils.isEmpty(gateStatusGroup)) { + List resultList = new ArrayList<>(); + for (Dict dict : deviceStatus) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + resultMap.put("total", 0); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = gateStatusGroup.stream().collect(Collectors.summarizingInt(GateStatusGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("无该类设备信息"); + } + List resultList = new ArrayList<>(); + gateStatusGroup.forEach(group -> { + if ("2".equals(gateStatusGroupDTO.getDevType())) { + group.setDevType("2"); + } + String devStatus = dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, group.getStatus()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(devStatus); + gateStatusGroupResponse.setRatio(result + "%"); + gateStatusGroupResponse.setQuantity(group.getQuantity()); + resultList.add(gateStatusGroupResponse); + }); + //返回数据补全处理 + if (resultList.size() < deviceStatus.size()) { + List collect = resultList.stream().map(GateStatusGroupResponse::getStatus).collect(Collectors.toList()); + for (Dict dict : deviceStatus) { + String name = dict.getName(); + if (!collect.contains(name)) { + GateStatusGroupResponse gateStatusGroupResponse = new GateStatusGroupResponse(); + gateStatusGroupResponse.setStatus(dict.getName()); + gateStatusGroupResponse.setRatio("0%"); + gateStatusGroupResponse.setQuantity(0); + resultList.add(gateStatusGroupResponse); + } + } + } + resultMap.put("total", sum); + resultMap.put("list", resultList); + return ResponseData.success(resultMap); + } + + @Override + public Object securityScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的position划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + List caseInfos = caseInfoMapper.selectByPosition(position); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //楼栋-评分实体map + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + Map resultMap = new HashMap<>(); + //空数据处理 + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + resultMap.put(dict.getName(), 100.0); + } + return ResponseData.success(resultMap); + } + + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + + collect.keySet().forEach(key -> { + List list = collect.get(key); + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); + resultMap.put(dictValue, 100 - collect1.getSum()); + }); + //返回数据补全处理 + if (collect.size() < devicePosition.size()) { + Set strings = resultMap.keySet(); + for (Dict dict : devicePosition) { + String name = dict.getName(); + if (!strings.contains(name)) { + resultMap.put(dict.getName(), 100.0); + } + } + } + //按楼层分组计算评分 +// collect.keySet().forEach(key -> { +// Map map = new HashMap<>(); +// List securityScoreDTOS = collect.get(key); +// //楼层-评分map +// Map collect1 = securityScoreDTOS.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getArea, Collectors.summingDouble(SecurityScoreDTO::getScore))); +// collect1.keySet().forEach(key1 -> { +// map.put(key1, 100 - collect1.get(key1)); +// }); +// String dictValue = dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, key); +// resultMap.put(dictValue, map); +// }); + return ResponseData.success(resultMap); + } + + @Override + public Object securityFrequency() { + String year = String.valueOf(DateUtil.thisYear()); + String month = String.valueOf(DateUtil.thisMonth()); + Integer quantity = caseInfoMapper.selectCountByMonth(year, month); + SecurityFrequencyDTO securityFrequencyDTO = new SecurityFrequencyDTO(); + securityFrequencyDTO.setQuantity(quantity); + securityFrequencyDTO.setYear(year); + securityFrequencyDTO.setMonth(month); + return ResponseData.success(securityFrequencyDTO); + } + + @Override + public Object areaScore(SecurityScoreDTO securityScoreDTO) { + //按发生事件的设备所在的area划分计算评分,当天发生的事件 + String position = securityScoreDTO.getPosition(); + String area = securityScoreDTO.getArea(); + if (StringUtils.isEmpty(position) || StringUtils.isEmpty(area)) { + return null; + } + Map resultMap = new HashMap<>(); + List caseInfos = caseInfoMapper.selectByPositionAndArea(position, area); + if (Objects.isNull(caseInfos)) { + resultMap.put("安防评分", 100.0); + return ResponseData.success(resultMap); + } + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + DoubleSummaryStatistics collect = securityScoreDTOs.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + resultMap.put("安防评分", 100 - collect.getSum()); + return ResponseData.success(resultMap); + } + + @Override + public Object heatMap(HeatMapDTO heatMapDTO) { + if (!Objects.isNull(heatMapDTO) && Objects.isNull(heatMapDTO.getMinute())) { + heatMapDTO.setMinute(3); + } + List caseInfoList = caseInfoMapper.selectPersonnelGatherByTime(heatMapDTO.getMinute(), SecurityEventType.PERSONNEL_GATHER_EVENT); + Map> collect = caseInfoList.stream().collect(Collectors.groupingBy(CaseInfo::getIndexCode)); + HashMap resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect)) { + return ResponseData.success(); + } + collect.keySet().forEach(key -> { + resultMap.put(key, collect.get(key).size()); + }); + return ResponseData.success(resultMap); + } + + private List> getResultMap(List nameList, List> resultList, Map> resultMap) { + resultMap.keySet().forEach(key -> { + List monthAndLevelGroupDTOS = resultMap.get(key); + HashMap hashMap = new HashMap<>(); + for (MonthAndLevelGroupDTO andLevelGroupDTO : monthAndLevelGroupDTOS) { +// hashMap.put("年份", andLevelGroupDTO.getYear()); + hashMap.put("月份", /*andLevelGroupDTO.getYear() + "-" + */Integer.valueOf(andLevelGroupDTO.getMonth())); + hashMap.put(andLevelGroupDTO.getLevelName(), String.valueOf(andLevelGroupDTO.getQuantity())); + } + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + }); + //12个月份,用于构造返回结构 + List list1 = new ArrayList<>(); + for (Map map : resultList) { + list1.add(String.valueOf(map.get("月份"))); + } + for (int i = 1; i < 13; i++) { + if (CollectionUtils.isEmpty(list1) || list1.contains(String.valueOf(i))) { + continue; + } + HashMap hashMap = new HashMap<>(); + hashMap.put("月份", i); + for (String s : nameList) { + if (!hashMap.keySet().contains(s)) { + hashMap.put(s, "0"); + } + } + resultList.add(hashMap); + } + List> results = resultList.stream().sorted(Comparator.comparingInt(e -> (int) e.get("月份"))).collect(Collectors.toList()); + return results; + } } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java index 94308db..f91d7bd 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/DeviceInfoServiceImpl.java @@ -427,6 +427,13 @@ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("draw_no", drawNo); DeviceInfo deviceInfo = deviceInfoMapper.selectOne(wrapper); + if(!Objects.isNull(deviceInfo)){ + deviceInfo.setDevTypeName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_TYPE, deviceInfo.getDevType())); + deviceInfo.setStatusName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_STATUS, deviceInfo.getStatus())); + deviceInfo.setPositionName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_POSITION, deviceInfo.getPosition())); + deviceInfo.setAreaName(dictService.getDictNameByCode(SecurityEventDict.DEVICE_AREA, deviceInfo.getArea())); + deviceInfo.setIsKeyAreaName(dictService.getDictNameByCode(SecurityEventDict.IS_KEY_AREA, deviceInfo.getIsKeyArea())); + } return deviceInfo; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java index 8ed53d9..c399a7f 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/HikServiceImpl.java @@ -11,6 +11,7 @@ import com.casic.missiles.modular.service.HikService; import com.casic.missiles.modular.system.model.Dict; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -50,8 +51,11 @@ @Override public CaseInfo blackListHandle(JSONObject event, CaseInfo caseInfo) { - String srcIndex = event.getString("srcIndex"); //海康资源唯一标识 + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 String happenTimeISO = String.valueOf(event.get("happenTime")); + DateTime parse = DateUtil.parse(happenTimeISO); String happenTime = DateUtil.formatDateTime(parse); caseInfo.setHappenTime(happenTime); //发生时间 @@ -89,6 +93,16 @@ log.info("接收到离岗事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //离岗事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray leavePosition = data.getJSONArray("leavePosition"); + if(StringUtils.isNotEmpty(leavePosition.getString(0))){ + JSONObject jsonObject = leavePosition.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -115,6 +129,16 @@ log.info("接收到人员聚集事件,但数据库中无该事件发生的设备信息, srcIndex:{}", srcIndex); return caseInfo; } + //人员聚集事件背景图imageUrl + JSONObject data = event.getJSONObject("data"); + if(!Objects.isNull(data)){ + JSONArray group = data.getJSONArray("group"); + if(StringUtils.isNotEmpty(group.getString(0))){ + JSONObject jsonObject = group.getJSONObject(0); + String imageUrl = jsonObject.getString("imageUrl"); + caseInfo.setEventPicture(imageUrl); + } + } caseInfo.setIndexCode(srcIndex); caseInfo.setDeviceCode(deviceInfo.getDevCode()); //设备code caseInfo.setDevName(deviceInfo.getDevName()); //设备名 @@ -263,8 +287,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void propertyAttendanceHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); @@ -309,8 +334,9 @@ @Override @Transactional(rollbackFor = Exception.class) public void securityPersonnelHandle(JSONObject event) { - String srcIndex = event.getString("srcIndex"); - JSONObject data = (JSONObject) event.get("data"); + JSONObject data = event.getJSONObject("data"); + JSONObject resInfoResult = data.getJSONArray("resInfo").getJSONObject(0); + String srcIndex = resInfoResult.getString("indexCode"); ////海康资源唯一标识 JSONObject faceRecognitionResult = (JSONObject) data.get("faceRecognitionResult"); JSONArray faceMatchArr = (JSONArray) faceRecognitionResult.get("faceMatch"); JSONObject faceMatch = (JSONObject) faceMatchArr.get(0); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java new file mode 100644 index 0000000..4427f19 --- /dev/null +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/PropertyManageServiceImpl.java @@ -0,0 +1,1255 @@ +package com.casic.missiles.modular.service.impl; + +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.casic.missiles.core.application.service.AbstractDictService; +import com.casic.missiles.model.response.ResponseData; +import com.casic.missiles.modular.config.CockpitConfig; +import com.casic.missiles.modular.dao.*; +import com.casic.missiles.modular.dto.statistics.*; +import com.casic.missiles.modular.enums.SecurityEventDict; +import com.casic.missiles.modular.enums.SecurityEventType; +import com.casic.missiles.modular.model.*; +import com.casic.missiles.modular.service.PropertyManageService; +import com.casic.missiles.modular.system.model.Dict; +import com.casic.missiles.modular.util.DateUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.text.NumberFormat; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @Description: 驾驶舱二级页面-物管信息 + * @Author: wangpeng + * @Date: 2022/10/11 9:11 + */ +@Slf4j +@Service +public class PropertyManageServiceImpl implements PropertyManageService { + @Autowired + private AttendanceInfoMapper attendanceInfoMapper; + @Autowired + private StaffInfoMapper staffInfoMapper; + @Autowired + private CaseInfoMapper caseInfoMapper; + @Autowired + private HazardLevelMapper hazardLevelMapper; + @Autowired + private CategoryLevelMapper categoryLevelMapper; + @Autowired + private VisitInfoMapper visitInfoMapper; + @Autowired + private DeviceRepairLogMapper repairLogMapper; + @Autowired + private CockpitConfig cockpitConfig; + @Autowired + private AbstractDictService dictService; + + @Override + public Object attendanceRatio(AttendanceRatioDTO attendanceRatioDTO) { + //各类型员工及总数 + List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); + Map> typeNumMap = staffTypeAndSumDTOS.stream().collect(Collectors.groupingBy(StaffTypeAndSumDTO::getStaffType)); + + String dateDimension = attendanceRatioDTO.getDateDimension(); + List attendanceRatioDTOS = new ArrayList<>(); + List dateList = null; + //考勤的人数,按单次考勤过滤 + if ("week".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForWeek(); + dateList = DateUtils.getCurrentDateDayList(); + } else if ("month".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForMonth(); + dateList = DateUtils.getCurrentDateWeekList(); + } else if ("year".equals(dateDimension)) { + attendanceRatioDTOS = attendanceInfoMapper.getCountByTypeAndDateForYear(); + dateList = DateUtils.getCurrentDateMonthList(); + } + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(attendanceRatioDTOS)) { + for (String date : dateList) { + HashMap hashMap = new HashMap<>(); + hashMap.put("date", date); + hashMap.put("property", "0%"); + hashMap.put("security", "0%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + //计算出勤率 + Map> dateMap = attendanceRatioDTOS.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); + + dateList.forEach(date -> { + HashMap hashMap = new HashMap<>(); + if (CollectionUtils.isEmpty(dateMap.get(date))) { + hashMap.put("date", date); + hashMap.put("property", "0%"); + hashMap.put("security", "0%"); + resultList.add(hashMap); + } else { + List attendances = dateMap.get(date); + attendances.forEach(attendanceRatio -> { + attendanceRatio.setDateDimension(dateDimension); + attendanceRatio.setStaffType(attendanceRatio.getStaffType()); + List staffSum = typeNumMap.get(attendanceRatio.getStaffType()); + String ratio = numberFormat.format(((float) attendanceRatio.getQuantity() / (float) staffSum.get(0).getSum()) * 100); + attendanceRatio.setAttendanceRatio(ratio + "%"); + //构造返回结构 + hashMap.put("date", attendanceRatio.getDate()); +// String name = dictService.getDictNameByCode(SecurityEventDict.STAFF_TYPE, attendanceRatio.getStaffType()); + if ("1".equals(attendanceRatio.getStaffType())) { + hashMap.put("property", attendanceRatio.getAttendanceRatio()); + } + if ("2".equals(attendanceRatio.getStaffType())) { + hashMap.put("security", attendanceRatio.getAttendanceRatio()); + } + }); + //补全缺少数据 + if (1 == attendances.size()) { + AttendanceRatioDTO attendanceRatioDTO1 = attendances.get(0); + if ("1".equals(attendanceRatioDTO1.getStaffType())) { + hashMap.put("security", "0%"); + } + if ("2".equals(attendanceRatioDTO1.getStaffType())) { + hashMap.put("property", "0%"); + } + } + resultList.add(hashMap); + } + }); + return ResponseData.success(resultList); + + } + + @Override + public Object keyAreaData(String dimension) { + List resultList = null; + List dateList = null; + if ("year".equals(dimension)) { + //近365天数据按月分组统计 + resultList = caseInfoMapper.selectPreMonthCountByNearYear(); + dateList = DateUtils.getCurrentDateMonthList(); + } else if ("month".equals(dimension)) { + //近30天数据按周分组统计 + resultList = caseInfoMapper.selectPreWeekCountByThirtyDay(); + dateList = DateUtils.getCurrentDateWeekList(); + } else if ("week".equals(dimension)) { + //近7天数据按天分组统计 + resultList = caseInfoMapper.selectPreDayCountBySevenDay(); + dateList = DateUtils.getCurrentDateDayList(); + } + //补全空数据处理 + if (CollectionUtils.isEmpty(resultList)) { + for (String date : dateList) { + PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); + preMonthOrWeekCaseDTO.setDimension(date); + preMonthOrWeekCaseDTO.setQuantity(0); + resultList.add(preMonthOrWeekCaseDTO); + } + } else { + for (String date : dateList) { + List collect = resultList.stream().map(PreMonthOrWeekCaseDTO::getDimension).collect(Collectors.toList()); + if (!collect.contains(date)) { + PreMonthOrWeekCaseDTO preMonthOrWeekCaseDTO = new PreMonthOrWeekCaseDTO(); + preMonthOrWeekCaseDTO.setDimension(date); + preMonthOrWeekCaseDTO.setQuantity(0); + resultList.add(preMonthOrWeekCaseDTO); + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object keyAreaFrequencyStatistic(AvgMonthAndWeekGroupDTO avgMonthAndWeekGroupDTO) { + String year = avgMonthAndWeekGroupDTO.getYear(); + List monthList = caseInfoMapper.selectPreMonthCountByYear(year); + Map> collect = monthList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); + HashMap strAvgMap = new HashMap<>(); + List resultList = new ArrayList<>(); + for (String key : collect.keySet()) { + List preMonthOrWeekCaseDTOS = collect.get(key); + int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); + //若年份是本年,则使用各安防级别数量/当前月份数 + //若不是本年,除数为12 + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + if (year.equals(String.valueOf(DateUtil.thisYear()))) { + monthAndWeekDTO.setMonthQuantity(sum / DateUtil.thisMonth()); + strAvgMap.put(key, monthAndWeekDTO); + } else { + monthAndWeekDTO.setMonthQuantity(sum / 12); + strAvgMap.put(key, monthAndWeekDTO); + } + } + + List weekList = caseInfoMapper.selectPreWeekCountByYear(year); + Map> collect1 = weekList.stream().collect(Collectors.groupingBy(PreMonthOrWeekCaseDTO::getHazardLevelCode)); + for (String key : collect1.keySet()) { + List preMonthOrWeekCaseDTOS = collect.get(key); + int sum = preMonthOrWeekCaseDTOS.stream().mapToInt(PreMonthOrWeekCaseDTO::getQuantity).sum(); + if (year.equals(String.valueOf(DateUtil.thisYear()))) { + if (!Objects.isNull(strAvgMap.get(key))) { + MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); + strAvgMap.put(key, monthAndWeekDTO); + } else { + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / DateUtil.thisWeekOfYear()); + strAvgMap.put(key, monthAndWeekDTO); + } + } else { + if (!Objects.isNull(strAvgMap.get(key))) { + MonthAndWeekDTO monthAndWeekDTO = strAvgMap.get(key); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / 52); + strAvgMap.put(key, monthAndWeekDTO); + } else { + MonthAndWeekDTO monthAndWeekDTO = new MonthAndWeekDTO(); + String hazardName = hazardLevelMapper.selectHazardNameByCode(key); + monthAndWeekDTO.setLevelName(hazardName); + monthAndWeekDTO.setWeekQuantity(sum / 52); + strAvgMap.put(key, monthAndWeekDTO); + } + } + } + strAvgMap.keySet().forEach(key -> { + resultList.add(strAvgMap.get(key)); + }); + //输出顺序 + Collections.swap(resultList, 1, 2); + return ResponseData.success(resultList); + } + + @Override + public Object attendanceNumber(String dimension) { + List attendanceNumberDTOs = null; + List> resultList = new ArrayList<>(); + List dateList = new ArrayList<>(); + if ("week".equals(dimension)) { + //近7天数据按天分组统计 + attendanceNumberDTOs = attendanceInfoMapper.getCountForWeek(); + dateList = DateUtils.getCurrentDateDayList(); + } else if ("day".equals(dimension)) { + //今天数据按小时分组统计 + attendanceNumberDTOs = attendanceInfoMapper.getCountForDay(); + dateList = DateUtils.getCurrentDateWorkHourList(); + } + if (CollectionUtils.isEmpty(attendanceNumberDTOs)) { + for (String date : dateList) { + HashMap hashMap = new HashMap<>(); + hashMap.put("staticTime", date); + hashMap.put("1", "0"); + hashMap.put("2", "0"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + Map> collect = attendanceNumberDTOs.stream().collect(Collectors.groupingBy(AttendanceNumberDTO::getDate)); + if ("day".equals(dimension)) { + collect = collect.entrySet().stream().collect(Collectors.toMap(m -> m.getKey().substring(5) + ":00", Map.Entry::getValue)); + } + + for (String date : dateList) { + Map resultMap = new HashMap<>(); + if (CollectionUtils.isEmpty(collect.get(date))) { + resultMap.put("1", "0"); + resultMap.put("2", "0"); + resultMap.put("staticTime", date); + resultList.add(resultMap); + } else { + List attendanceNumberDTOS = collect.get(date); +// Map resultMap = new HashMap<>(); + AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); + if (attendanceNumberDTOS.size() >= 2) { + AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); + resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); + } + resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); + resultMap.put("staticTime", date); + resultList.add(resultMap); + //补全map缺少数据 + if (!resultMap.containsKey("1")) { + resultMap.put("1", "0"); + } + if (!resultMap.containsKey("2")) { + resultMap.put("2", "0"); + } + } + } + +// +// collect.keySet().forEach(key -> { +// List attendanceNumberDTOS = collect.get(key); +// Map resultMap = new HashMap<>(); +// AttendanceNumberDTO attendanceNumberDTO = attendanceNumberDTOS.get(0); +// if (attendanceNumberDTOS.size() >= 2) { +// AttendanceNumberDTO attendanceNumberDTO2 = attendanceNumberDTOS.get(1); +// resultMap.put(attendanceNumberDTO2.getStaffType(), attendanceNumberDTO2.getQuantity()); +// } +// resultMap.put(attendanceNumberDTO.getStaffType(), attendanceNumberDTO.getQuantity()); +// resultMap.put("staticTime", attendanceNumberDTO.getDate().substring(5) + ":00"); +// resultList.add(resultMap); +// }); +// //补全空数据处理 +// if (CollectionUtils.isEmpty(resultList)) { +// for (String date : dateList) { +// Map resultMap = new HashMap<>(); +// resultMap.put("1", "0"); +// resultMap.put("2", "0"); +// resultMap.put("staticTime", date); +// resultList.add(resultMap); +// } +// } else { +// List collectList = new ArrayList<>(); +// for (Map map : resultList) { +// String staticTime = map.get("staticTime"); +// collectList.add(staticTime); +// //补全map缺少数据 +// if (!map.containsKey("1")) { +// map.put("1", "0"); +// } +// if (!map.containsKey("2")) { +// map.put("2", "0"); +// } +// } +// for (String date : dateList) { +// if (!collectList.contains(date)) { +// Map resultMap = new HashMap<>(); +// resultMap.put("1", "0"); +// resultMap.put("2", "0"); +// resultMap.put("staticTime", date); +// resultList.add(resultMap); +// } +// } +// } + return ResponseData.success(resultList); + } + + @Override + public Object securityAssessment(String dimension) { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + if ("week".equals(dimension)) { + //近7天早晚高峰数据 + List caseInfos = caseInfoMapper.selectListBySevenDay(); + //按时间(天)进行分组 + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(" "); + String dayTime = array[0]; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } else if ("day".equals(dimension)) { + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDatePeakHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateDayList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + + } + return null; + } + + @Override + public Object keyAreaStatistic() { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday2(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + dayTime = dayTime.substring(5) + ":00"; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全空数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } + + @Override + public Object responseAssess() { + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap hashMap = new HashMap<>(); + //今天数据按小时分组统计 + List caseInfos = caseInfoMapper.selectListByToday3(); + caseInfos.forEach(caseInfo -> { + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + //扣分=事件级别权重*未解决小时数 + Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); + Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); + long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); + Double score = Double.valueOf(hazardWeight) * between; + String[] array = caseInfo.getHappenTime().split(":"); + String dayTime = array[0]; + dayTime = dayTime.substring(5) + ":00"; + BigDecimal preScore; + if (hashMap.containsKey(dayTime)) { + Double aDouble = hashMap.get(dayTime); + preScore = new BigDecimal(aDouble.toString()); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(score.toString()); + hashMap.put(dayTime, preScore.subtract(nowScore).doubleValue()); + }); + + List> resultList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(hashMap)) { + hashMap.keySet().forEach(key -> { + HashMap map = new HashMap<>(); + map.put("date", key); + map.put("score", hashMap.get(key)); + resultList.add(map); + }); + //补全数据处理 + List collectList = new ArrayList<>(); + for (Map map : resultList) { + String staticTime = String.valueOf(map.get("date")); + collectList.add(staticTime); + } + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + if (!collectList.contains(date)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + } + return ResponseData.success(resultList); + } else { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } + return ResponseData.success(resultList); + } + } + + @Override + public Object hazardLevelStatistics(String dimension) { + List hazardLevelGroup = null; + if ("week".equals(dimension)) { + hazardLevelGroup = caseInfoMapper.selectByHazardLevelWeek(); + } else if ("month".equals(dimension)) { + hazardLevelGroup = caseInfoMapper.selectByHazardLevelMonth(); + } + if (CollectionUtils.isEmpty(hazardLevelGroup)) { + log.info("重点区域威胁事件类型统计,无安防事件"); + return ResponseData.error("无安防事件发生!"); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + long sum = hazardLevelGroup.stream().collect(Collectors.summarizingInt(HazardLevelGroupDTO::getQuantity)).getSum(); + if (sum <= 0) { + return ResponseData.error("安防事件总数为0"); + } + hazardLevelGroup.forEach(group -> { + CaseHazardLevel caseHazardLevel = hazardLevelMapper.getCaseHazardLevel(group.getLevelCode()); + group.setLevelName(caseHazardLevel.getName()); + String result = numberFormat.format((float) group.getQuantity() / (float) sum * 100); + group.setLevelRatio(result + "%"); + }); + HazardLevelGroupResponse hazardLevelGroupResponse = new HazardLevelGroupResponse(); + hazardLevelGroupResponse.setHazardLevelGroup(hazardLevelGroup); + hazardLevelGroupResponse.setQuantity(sum); + return ResponseData.success(hazardLevelGroupResponse); + } + + @Override + public Object securityRank() { + //考勤表近一个月按人员分组的考勤个数前十名 + List list = attendanceInfoMapper.getCountForRank(); + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(list)) { + //补全空数据处理 + List staffList = staffInfoMapper.selectListLimitTen(); + for (StaffInfo staffInfo : staffList) { + HashMap hashMap = new HashMap<>(); + hashMap.put(staffInfo.getStaffName(), "0%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + //构造返回结构 + for (SecurityRankDTO dto : list) { + // TODO: 2022/9/15 分母使用30,后续看产品定义 + HashMap hashMap = new HashMap<>(); + String result = numberFormat.format(Float.valueOf(dto.getQuantity()) / (float) 30 * 100); + hashMap.put("name", dto.getStaffName()); + hashMap.put("ratio", result + "%"); + resultList.add(hashMap); + } + return ResponseData.success(resultList); + } + + @Override + public Object securityLevelAssess() { + //今天数据按小时分组统计 + List resultList = caseInfoMapper.selectListByType(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + if (CollectionUtils.isEmpty(resultList)) { + //补全空数据处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + SecurityLevelAssessDTO levelAssessDTO = new SecurityLevelAssessDTO(); + levelAssessDTO.setScore(new BigDecimal("100.0").doubleValue()); + levelAssessDTO.setDate(date); +// levelAssessDTO.setQuantity(); + resultList.add(levelAssessDTO); + } + return ResponseData.success(resultList); + } + resultList.forEach(result -> { + result.setDate(result.getDate().substring(5) + ":00"); + BigDecimal deScore = new BigDecimal(result.getQuantity()); + BigDecimal preScore = new BigDecimal("100.0"); + result.setScore(preScore.subtract(deScore).doubleValue()); + }); + //数据补全处理 + List dateList = DateUtils.getCurrentDateWorkHourList(); + for (String date : dateList) { + for (SecurityLevelAssessDTO levelAssessDTO : resultList) { + String substring = levelAssessDTO.getDate().substring(5) + ":00"; + if (!substring.equals(date)) { + SecurityLevelAssessDTO levelAssess = new SecurityLevelAssessDTO(); + levelAssess.setScore(new BigDecimal("100.0").doubleValue()); + levelAssess.setDate(date); + resultList.add(levelAssess); + break; + } + } + } + return ResponseData.success(resultList); + } + + @Override + public Object commute() { + //早晚高峰区域安防评估 + ResponseData assessResultJson = (ResponseData) this.securityAssessment("week"); + if (Objects.isNull(assessResultJson) || 200 != assessResultJson.getCode()) { + return assessResultJson; + } + JSONArray assessData = JSONArray.parseArray(JSON.toJSONString(assessResultJson.getData())); + //所有类型的员工出勤 + List staffTypeAndSumDTOS = staffInfoMapper.selectCountByType(); + long sum = staffTypeAndSumDTOS.stream().collect(Collectors.summarizingInt(StaffTypeAndSumDTO::getSum)).getSum(); + List countByTypeAndDateForWeek = attendanceInfoMapper.getCountByTypeAndDateForWeek(); + Map> dateMap = countByTypeAndDateForWeek.stream().collect(Collectors.groupingBy(AttendanceRatioDTO::getDate)); + HashMap attendanceMap = new HashMap<>(); + dateMap.keySet().forEach(key -> { + List attendanceRatioDTOS = dateMap.get(key); + //当天所有类型的员工的出勤人数 + long sum1 = attendanceRatioDTOS.stream().collect(Collectors.summarizingInt(AttendanceRatioDTO::getQuantity)).getSum(); + //出勤占比评分 + Double attendanceRatio = ((float) sum1 / (float) sum) * 100 * cockpitConfig.getCommuteWeight(); + attendanceMap.put(key, attendanceRatio); + }); + //构造结果 + List> resultList = new ArrayList<>(); + Iterator iterator = assessData.stream().iterator(); + while (iterator.hasNext()) { + JSONObject next = (JSONObject) iterator.next(); + String date = next.getString("date"); + HashMap map = new HashMap<>(); + //计算评分 + Double assessRatio = next.getInteger("score") * (1 - cockpitConfig.getCommuteWeight()); + NumberFormat numberFormat = NumberFormat.getInstance(); + numberFormat.setMaximumFractionDigits(2); + if (!Objects.isNull(attendanceMap.get(date))) { + Double attendanceRatio = attendanceMap.get(date); + Double r = assessRatio + attendanceRatio; + map.put("score", numberFormat.format(r)); + } else { + //无员工出勤率(出勤为0),只有安防评估分值 + map.put("score", numberFormat.format(assessRatio)); + } + map.put("date", date); + resultList.add(map); + } + return ResponseData.success(resultList); + } + + @Override + public Object keyArea() { + //1-重点区域安防事件次数/所有安防事件次数 + //获取近7天每天的安防事件个数,所有和重点区域 + List weekCaseDTOS = caseInfoMapper.selectPreDayCountBySevenDay(); + List weekCaseKeyAreaDTOS = caseInfoMapper.selectPreDayCountBySevenDayKeyArea(); + List caseInfos = caseInfoMapper.selectListBySevenDayKeyArea(); + HashMap weekCaseMap = new HashMap<>(); + HashMap caseScoreMap = new HashMap<>(); + HashMap keyAreaScoreMap = new HashMap<>(); + HashMap assessScoreMap = new HashMap<>(); + List dateList = DateUtils.getCurrentDateDayList(); + List> result = getForResult(weekCaseDTOS, weekCaseKeyAreaDTOS, caseInfos, weekCaseMap, caseScoreMap, + keyAreaScoreMap, assessScoreMap, dateList); + + //上个月对应数据 + List beforeMonthKeyAreaCaseDTOS = caseInfoMapper.selectPreDayCountByBeforeMonthKeyArea(); + List beforeMonthCaseDTOS = caseInfoMapper.selectPreDayCountByBeforeMonth(); + List beforeMonthCaseInfos = caseInfoMapper.selectListByBeforeMonthKeyArea(); + HashMap beforeMonthWeekCaseMap = new HashMap<>(); + HashMap beforeMonthCaseScoreMap = new HashMap<>(); + HashMap beforeMonthKeyAreaScoreMap = new HashMap<>(); + HashMap beforeMonthAssessScoreMap = new HashMap<>(); + List beforeMonthDateList = DateUtils.getCurrentDateDayBeforeMonthList(); + List> resultBeforeMonth = getForResult(beforeMonthCaseDTOS, beforeMonthKeyAreaCaseDTOS, beforeMonthCaseInfos, + beforeMonthWeekCaseMap, beforeMonthCaseScoreMap, beforeMonthKeyAreaScoreMap, beforeMonthAssessScoreMap, beforeMonthDateList); + //计算环比 + for (int i = 0; i < result.size(); i++) { + Map resultMap = result.get(i); + Map resultBeforeMonthMap = resultBeforeMonth.get(i); + BigDecimal resultScore = BigDecimal.valueOf(Double.valueOf(String.valueOf(resultMap.get("score")))); + BigDecimal resultBeforeMonthScore = BigDecimal.valueOf(Double.valueOf(String.valueOf(resultBeforeMonthMap.get("score")))); + BigDecimal finalResult = resultScore.subtract(resultBeforeMonthScore).divide(resultBeforeMonthScore, 2, BigDecimal.ROUND_HALF_UP); + resultMap.put("ringRatio", finalResult); + } + return ResponseData.success(result); + } + + @Override + public Object visitor() { + //查询每天的访客对应的离开记录(进入记录存在且在申请范围内) + //近7天主要使用申请离开时间(申请进入时间不会影响扣分) + List list = visitInfoMapper.selectListBySevenDay(); + list.stream().forEach(visit -> { + DateTime dateTime = DateUtil.parseDateTime(visit.getApplyOutTime()); + String formatDate = DatePattern.NORM_DATE_FORMAT.format(dateTime); + visit.setDate(formatDate); + }); + Map> dateVisitMap = list.stream().collect(Collectors.groupingBy(MultiScoreVisitorDTO::getDate)); + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + HashMap deductMap = new HashMap<>(); //扣分使用 + dateList.forEach(date -> { + //1、空数据处理 + if (CollectionUtils.isEmpty(dateVisitMap)) { + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } else if (CollectionUtils.isEmpty(dateVisitMap.get(date))) { + //2、补全数据处理 + HashMap map = new HashMap<>(); + map.put("date", date); + map.put("score", 100); + resultList.add(map); + } else { + //3、计算数据处理 + //计算分数(未在申请时间段内离开减分(包括无离开时间和有离开时间两种情况)、未在申请区域内离开减分),配置扣分,配置每个访客最高扣分 + List multiScoreVisitorDTOS = dateVisitMap.get(date); + //遍历访客 + for (MultiScoreVisitorDTO visitorDTO : multiScoreVisitorDTOS) { + //无离开时间 + if (StringUtils.isEmpty(visitorDTO.getOutTime())) { + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + cockpitConfig.getVisitorWeight().get("NoRecordPointDeduct")); + } else { + deductMap.put(date, cockpitConfig.getVisitorWeight().get("NoRecordPointDeduct")); + } + } else { +// DateTime applyInDateTime = DateUtil.parseDateTime(visitorDTO.getApplyInTime()); + DateTime applyOutDateTime = DateUtil.parseDateTime(visitorDTO.getApplyOutTime()); + DateTime outDateTime = DateUtil.parseDateTime(visitorDTO.getOutTime()); + //未在申请时间段离开(在申请离开时间后离开) + if (DateUtil.compare(outDateTime, applyOutDateTime) > 0) { + long betweenHour = DateUtil.between(outDateTime, applyOutDateTime, DateUnit.HOUR); + Double score = betweenHour * cockpitConfig.getVisitorWeight().get("singlePointDeduct"); + //该访客扣分到达最多分 + if (score >= cockpitConfig.getVisitorWeight().get("mostPointDeduct")) { + score = cockpitConfig.getVisitorWeight().get("mostPointDeduct"); + } + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + score); + } else { + deductMap.put(date, score); + } + } + //未在申请区域离开 + if (StringUtils.isNotEmpty(visitorDTO.getApplyVisitPosition()) && !visitorDTO.getApplyVisitPosition().equals(visitorDTO.getVisitPosition())) { + //有该日期的分数,累加扣分 + if (!Objects.isNull(deductMap.get(date))) { + Double reScore = deductMap.get(date); + deductMap.put(date, reScore + cockpitConfig.getVisitorWeight().get("singlePointDeduct")); + } else { + deductMap.put(date, cockpitConfig.getVisitorWeight().get("singlePointDeduct")); + } + } + + } + } + //添加到结果list + HashMap map = new HashMap<>(); + map.put("date", date); + if (!Objects.isNull(deductMap.get(date))) { + //最少0分 + if (deductMap.get(date) >= 100) { + map.put("score", 0); + } else { + map.put("score", 100 - deductMap.get(date)); + } + } else { + map.put("score", 100); + } + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object security() { + //安保人员到岗率*100*权重0.5 + //近7天安保人员到岗率 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + + List dateCountList = caseInfoMapper.selectDemobilizedCountSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap onDutyMap = new HashMap<>(); + dateCountList.forEach(dateCount -> { + //到岗率 + BigDecimal totalCount = new BigDecimal(total); + BigDecimal leaveCount = new BigDecimal(dateCount.getLeaveCount()); + BigDecimal result = totalCount.subtract(leaveCount).divide(totalCount, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + onDutyMap.put(dateCount.getDate(), result.multiply(BigDecimal.valueOf(cockpitConfig.getSecurityWeight().get("onDuty"))).setScale(2, BigDecimal.ROUND_HALF_UP)); + }); + + //安保等级评估均值*权重0.5 + List levelAssessList = caseInfoMapper.selectListByTypeSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap levelAssessMap = new HashMap<>(); + levelAssessList.forEach(levelAssess -> { + //6-23点共17小时,100-该天扣分/17 + BigDecimal deScore = new BigDecimal(levelAssess.getQuantity()); + BigDecimal preScore = new BigDecimal("100.0"); + BigDecimal divide = deScore.divide(BigDecimal.valueOf(17), 2, BigDecimal.ROUND_HALF_UP); + BigDecimal result = preScore.subtract(divide); + levelAssessMap.put(levelAssess.getDate(), result.multiply(BigDecimal.valueOf(cockpitConfig.getSecurityWeight().get("levelAssess"))).setScale(2, BigDecimal.ROUND_HALF_UP)); + }); + + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + Double onDutyWeight = cockpitConfig.getSecurityWeight().get("onDuty"); + Double levelAssessWeight = cockpitConfig.getSecurityWeight().get("levelAssess"); + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + //1、空数据处理 + if (CollectionUtils.isEmpty(onDutyMap) && CollectionUtils.isEmpty(levelAssessMap)) { + //2个map都空 + map.put("score", "100"); + resultList.add(map); + } else if (CollectionUtils.isEmpty(onDutyMap) || CollectionUtils.isEmpty(levelAssessMap)) { + //2个map有一个为空 + if (CollectionUtils.isEmpty(onDutyMap)) { + if (!Objects.isNull(levelAssessMap.get(date))) { + map.put("score", levelAssessMap.get(date).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + } else { + map.put("score", BigDecimal.valueOf(100 * levelAssessWeight).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + } + } + if (CollectionUtils.isEmpty(levelAssessMap)) { + if (!Objects.isNull(onDutyMap.get(date))) { + map.put("score", onDutyMap.get(date).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + } else { + map.put("score", BigDecimal.valueOf(100 * onDutyWeight).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + } + } + } else if (Objects.isNull(onDutyMap.get(date)) && Objects.isNull(levelAssessMap.get(date))) { + //该日期2个都空 + map.put("score", "100"); + resultList.add(map); + } else if (Objects.isNull(onDutyMap.get(date)) && !Objects.isNull(levelAssessMap.get(date))) { + //2、补全到岗率数据处理 + //该日期onDutyMap空,levelAssessMap不空 + map.put("score", levelAssessMap.get(date).add(BigDecimal.valueOf(100 * onDutyWeight)).stripTrailingZeros().toPlainString()); + resultList.add(map); + } else if (Objects.isNull(levelAssessMap.get(date)) && !Objects.isNull(onDutyMap.get(date))) { + //2、补全安保等级评估数据处理 + //该日期levelAssessMap空,onDutyMap不空 + map.put("score", onDutyMap.get(date).add(BigDecimal.valueOf(100 * levelAssessWeight)).stripTrailingZeros().toPlainString()); + resultList.add(map); + } else if (!Objects.isNull(levelAssessMap.get(date)) && !Objects.isNull(onDutyMap.get(date))) { + //该日期2个都不空 + BigDecimal onDutyDecimal = onDutyMap.get(date); + BigDecimal levelAssessDecimal = levelAssessMap.get(date); + map.put("score", onDutyDecimal.add(levelAssessDecimal).stripTrailingZeros().toPlainString()); + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object patrol() { + //近7天安保人员到岗率 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("staff_type", 2); + // TODO: 2022/9/2 后续使用产品确定的每天出勤的安保人员的数量 + Integer total = staffInfoMapper.selectCount(wrapper); + + List dateCountList = caseInfoMapper.selectDemobilizedCountSevenDay(SecurityEventType.PERSONNEL_DEMOBILIZED_EVENT); + HashMap onDutyMap = new HashMap<>(); + dateCountList.forEach(dateCount -> { + //到岗率 + BigDecimal totalCount = new BigDecimal(total); + BigDecimal leaveCount = new BigDecimal(dateCount.getLeaveCount()); + BigDecimal result = totalCount.subtract(leaveCount).divide(totalCount, 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + onDutyMap.put(dateCount.getDate(), result.stripTrailingZeros().toPlainString()); + }); + //构造结果 + List> resultList = new ArrayList<>(); + List dateList = DateUtils.getCurrentDateDayList(); + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + //1、空数据处理 + if (CollectionUtils.isEmpty(onDutyMap) || Objects.isNull(onDutyMap.get(date))) { + map.put("date", date); + map.put("score", "100"); + resultList.add(map); + } else { + map.put("date", date); + map.put("score", onDutyMap.get(date)); + resultList.add(map); + } + }); + return ResponseData.success(resultList); + } + + @Override + public Object other() { + //安全防护评分(所有楼的评分的均值) + List caseInfos = caseInfoMapper.selectByPositionSevenDay(null); + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + HashMap securityScoreMap = new HashMap<>(); + List securityScoreDTOs = new ArrayList<>(); + caseInfos.forEach(caseInfo -> { + SecurityScoreDTO securityScoreDTO1 = new SecurityScoreDTO(); + securityScoreDTO1.setPosition(caseInfo.getPosition()); + securityScoreDTO1.setArea(caseInfo.getArea()); + securityScoreDTO1.setDate(caseInfo.getHappenTime().substring(0, caseInfo.getHappenTime().indexOf(" "))); + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + //每个事件的扣分 + Double score = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + securityScoreDTO1.setScore(score); + securityScoreDTOs.add(securityScoreDTO1); + }); + //过滤空position + List collect2 = securityScoreDTOs.stream().filter(securityScoreDTO1 -> + StringUtils.isNotEmpty(securityScoreDTO1.getPosition()) + ).collect(Collectors.toList()); + List devicePosition = dictService.findInDictByCode(SecurityEventDict.DEVICE_POSITION); + if (CollectionUtils.isEmpty(collect2)) { + for (Dict dict : devicePosition) { + securityScoreMap.put(dict.getName(), BigDecimal.valueOf(100)); + } + } else { + Map> collect = collect2.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getDate)); + collect.keySet().forEach(key -> { + List list = collect.get(key); + //该日期发生时间的楼栋 + Map> collect3 = list.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + //无评分的楼栋数据补全处理 + if (collect3.size() < devicePosition.size()) { + List collect4 = list.stream().map(SecurityScoreDTO::getPosition).collect(Collectors.toList()); + for (Dict dict : devicePosition) { + String code = dict.getCode(); + if (!collect4.contains(code)) { + SecurityScoreDTO securityScoreDTO = new SecurityScoreDTO(); + securityScoreDTO.setDate(key); + securityScoreDTO.setPosition(code); + securityScoreDTO.setScore(100.0); + list.add(securityScoreDTO); + } + } + } + //该日期所有楼栋扣分和 + DoubleSummaryStatistics collect1 = list.stream().collect(Collectors.summarizingDouble(SecurityScoreDTO::getScore)); + double sum = collect1.getSum(); + //该日期发生时间的楼栋个数 + Map> collect4 = list.stream().collect(Collectors.groupingBy(SecurityScoreDTO::getPosition)); + int size = collect4.keySet().size(); + //(100*发生事件的楼栋个数-扣分和)/楼栋个数 + BigDecimal securityScore = BigDecimal.valueOf(100).multiply(BigDecimal.valueOf(size)).subtract(BigDecimal.valueOf(sum)).divide(BigDecimal.valueOf(size), 2, BigDecimal.ROUND_HALF_UP); + securityScoreMap.put(key, securityScore); + }); + } + + //设备维修次数(满分一百分,发生一次维修减5分) + //当天设备的维修记录 + HashMap repairMap = new HashMap<>(); + List repairLogs = repairLogMapper.selectListBySevenDay(); + repairLogs.forEach(repair -> { + repair.setRepairEndTime(repair.getRepairEndTime().substring(0, repair.getRepairEndTime().indexOf(" "))); + }); + List dateList = DateUtils.getCurrentDateDayList(); + Map> collect = repairLogs.stream().collect(Collectors.groupingBy(DeviceRepairLog::getRepairEndTime)); + collect.keySet().forEach(key -> { + List deviceRepairLogs = collect.get(key); + //开始时间到结束时间的每天都扣分 + for (DeviceRepairLog log : deviceRepairLogs) { + String startTime = log.getRepairStartTime().substring(0, log.getRepairStartTime().indexOf(" ")); + String endTime = log.getRepairEndTime().substring(0, log.getRepairStartTime().indexOf(" ")); + List betweenDays = DateUtils.getBetweenDays(startTime, endTime); + //包含首尾时间 + Collection intersection = org.apache.commons.collections4.CollectionUtils.intersection(dateList, betweenDays); + if (!CollectionUtils.isEmpty(intersection)) { + for (String date : intersection) { + if (Objects.isNull(repairMap.get(date))) { + //发生一次维修减5分 + repairMap.put(date, BigDecimal.valueOf(100 - 5)); + } else { + BigDecimal old = repairMap.get(date); + repairMap.put(date, old.subtract(BigDecimal.valueOf(5))); + } + } + } + } + }); + //构造结果 + List> resultList = new ArrayList<>(); + BigDecimal repairConfigScore = BigDecimal.valueOf(cockpitConfig.getOtherWeight().get("repair")); + BigDecimal securityConfigScore = BigDecimal.valueOf(cockpitConfig.getOtherWeight().get("security")); + if (CollectionUtils.isEmpty(securityScoreMap)) { + for (String date : dateList) { + securityScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if(CollectionUtils.isEmpty(repairMap)){ + for (String date : dateList) { + repairMap.put(date, BigDecimal.valueOf(100)); + } + } + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + //补全数据处理 + if (Objects.isNull(securityScoreMap.get(date)) && Objects.isNull(repairMap.get(date))) { + //该日期2个都空 + map.put("score", "100"); + } else if (Objects.isNull(securityScoreMap.get(date)) && !Objects.isNull(repairMap.get(date))) { + //该日期securityScoreMap空,repairMap不空 + map.put("score", repairConfigScore.multiply(repairMap.get(date)).add(securityConfigScore.multiply(BigDecimal.valueOf(100))) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } else if (Objects.isNull(repairMap.get(date)) && !Objects.isNull(securityScoreMap.get(date))) { + //该日期securityScoreMap不空,repairMap空 + map.put("score", securityConfigScore.multiply(securityScoreMap.get(date)).add(repairConfigScore.multiply(BigDecimal.valueOf(100))) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } else if (!Objects.isNull(securityScoreMap.get(date)) && !Objects.isNull(repairMap.get(date))) { + //该日期2个都不空 + BigDecimal securityScoreDecimal = securityConfigScore.multiply(securityScoreMap.get(date)); + BigDecimal repairDecimal = repairConfigScore.multiply(repairMap.get(date)); + map.put("score", securityScoreDecimal.add(repairDecimal) + .setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); + } + resultList.add(map); + }); + return ResponseData.success(resultList); + } + + private List> getForResult(List weekCaseDTOS, List weekCaseKeyAreaDTOS, + List caseInfos, HashMap weekCaseMap, HashMap caseScoreMap, + HashMap keyAreaScoreMap, HashMap assessScoreMap, + List dateList){ + Map keyAreaWeight = cockpitConfig.getKeyAreaWeight(); + weekCaseKeyAreaDTOS.forEach(dto -> { + weekCaseMap.put(dto.getDimension(), BigDecimal.valueOf(dto.getQuantity())); + }); + weekCaseDTOS.forEach(dto -> { + String date = dto.getDimension(); + Integer quantity = dto.getQuantity(); + //无重点区域事件数据,1-安防事件次数/所有安防事件次数=1 + if (Objects.isNull(weekCaseMap.get(date)) || weekCaseMap.get(date).equals(BigDecimal.ZERO)) { + caseScoreMap.put(date, BigDecimal.valueOf(1 * 100)); + } else { + BigDecimal multiply = BigDecimal.valueOf(quantity).subtract(weekCaseMap.get(date)).divide(BigDecimal.valueOf(quantity), 2, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)); + caseScoreMap.put(date, multiply); + } + }); + + //查询各危险级别权重、各类别权重,放入map,避免循环中多次查数据库 + HashMap hazardScoreMap = new HashMap<>(); + List caseHazardLevelList = hazardLevelMapper.getCaseHazardLevelList(null); + caseHazardLevelList.forEach(hazardLevel -> { + hazardScoreMap.put(hazardLevel.getCode(), hazardLevel.getWeight()); + }); + HashMap categoryScoreMap = new HashMap<>(); + List categoryLevelList = categoryLevelMapper.getCaseCategoryLevelList(null); + categoryLevelList.forEach(categoryLevel -> { + categoryScoreMap.put(categoryLevel.getCode(), categoryLevel.getWeight()); + }); + + caseInfos.forEach(caseInfo -> { + //重点区域安防事态评估分数 + String hazardWeight = hazardScoreMap.get(caseInfo.getHazardLevelCode()); + String categoryWeight = categoryScoreMap.get(caseInfo.getCategoryLevelCode()); + Double keyAreaScore = Double.valueOf(hazardWeight) * Double.valueOf(categoryWeight); + String dayTime = caseInfo.getHappenTime().substring(0, caseInfo.getHappenTime().indexOf(" ")); + BigDecimal preScore; + if (keyAreaScoreMap.containsKey(dayTime)) { + preScore = keyAreaScoreMap.get(dayTime); + } else { + preScore = new BigDecimal("100.0"); + } + BigDecimal nowScore = new BigDecimal(keyAreaScore.toString()); + keyAreaScoreMap.put(dayTime, preScore.subtract(nowScore)); + + //安防机动支援力量响应评估分数 + //扣分=事件级别权重*未解决小时数 + Date updateTime = DateUtil.parse(caseInfo.getUpdateTime()); + Date happenTime = DateUtil.parse(caseInfo.getHappenTime()); + long between = DateUtil.between(updateTime, happenTime, DateUnit.HOUR); + Double assessScore = Double.valueOf(hazardWeight) * between; + BigDecimal preAssessScore; + if (assessScoreMap.containsKey(dayTime)) { + preAssessScore = assessScoreMap.get(dayTime); + } else { + preAssessScore = new BigDecimal("100.0"); + } + BigDecimal nowAssessScore = new BigDecimal(assessScore.toString()); + assessScoreMap.put(dayTime, preAssessScore.subtract(nowAssessScore)); + }); + //构造结果 + List> resultList = new ArrayList<>(); + if (CollectionUtils.isEmpty(caseScoreMap)) { + for (String date : dateList) { + caseScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if (CollectionUtils.isEmpty(keyAreaScoreMap)) { + for (String date : dateList) { + keyAreaScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + if (CollectionUtils.isEmpty(assessScoreMap)) { + for (String date : dateList) { + assessScoreMap.put(date, BigDecimal.valueOf(100)); + } + } + dateList.forEach(date -> { + HashMap map = new HashMap<>(); + map.put("date", date); + BigDecimal preCaseScore = Objects.isNull(caseScoreMap.get(date)) ? BigDecimal.valueOf(100) : caseScoreMap.get(date); + BigDecimal preKeyAreaScore = Objects.isNull(keyAreaScoreMap.get(date)) ? BigDecimal.valueOf(100) : keyAreaScoreMap.get(date); + BigDecimal preAssessScore = Objects.isNull(assessScoreMap.get(date)) ? BigDecimal.valueOf(100) : assessScoreMap.get(date); + BigDecimal caseScore = preCaseScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("case"))); + BigDecimal keyAreaScore = preKeyAreaScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("keyArea"))); + BigDecimal responseAssessScore = preAssessScore.multiply(BigDecimal.valueOf(keyAreaWeight.get("responseAssess"))); + map.put("score", caseScore.add(keyAreaScore).add(responseAssessScore).stripTrailingZeros().toPlainString()); + resultList.add(map); + }); + return resultList; + } +} diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java index decc60c..2c66ec1 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/StaffInfoServiceImpl.java @@ -96,7 +96,10 @@ JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个添加人员失败,海康response:{}", resultStr); - return ResponseData.error("单个添加人员失败"); + if("0x00052301".equals(resultJson.get("code"))){ + return ResponseData.error("添加人员身份证号重复!"); + } + return ResponseData.error("单个添加人员失败!"); } JSONObject data = (JSONObject)resultJson.get("data"); String faceId = data.getString("faceId"); @@ -129,13 +132,11 @@ String body = JSONObject.toJSONString(personSingleAddOrUpdateRequest); String resultStr = HikUtil.hikApi(HikUri.PERSON_SINGLE_UPDATE, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); + //海康该接口成功返回data为空 if (!"0".equals(resultJson.get("code"))) { log.error("请求海康,单个修改人员失败,海康response:{}", resultStr); return ResponseData.error("单个修改人员失败"); } - JSONObject data = (JSONObject)resultJson.get("data"); - String faceId = data.getString("faceId"); - staffInfo.setStaffFaceId(faceId); if(staffInfoMapper.updateById(staffInfo) > 0){ return ResponseData.success(); } @@ -265,6 +266,7 @@ @Override public StaffInfo selectStaffInfoByCode(StaffInfo staffInfo) { StaffInfo info = staffInfoMapper.selectByCode(staffInfo.getStaffCode()); + info.setPicture(getPictureFromHik(staffInfo.getStaffCode())); return info; } diff --git a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java index b219984..aa23547 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/service/impl/VisitorApplyServiceImpl.java @@ -3,7 +3,9 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdcardUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -86,14 +88,21 @@ VisitorInfo visitorInfo = new VisitorInfo(); visitorInfo.setVisitorName(visitorApply.getVisitorName()); - visitorInfo.setGender(Integer.valueOf(visitorApply.getVisitorGender())); + //身份证号确定性别 + int genderByIdCard = IdcardUtil.getGenderByIdCard(visitorApply.getIdCard()); + if(0 == genderByIdCard){ + genderByIdCard = 2; + } + visitorInfo.setGender(genderByIdCard); visitorInfo.setPhoneNo(visitorApply.getVisitorPhone()); visitorInfo.setCertificateNo(visitorApply.getIdCard()); visitorInfo.setCertificateType(111); visitorInfo.setVisitorPhoto(visitorApply.getPicUri()); appointmentFreeRegisterRequest.setVisitorInfo(visitorInfo); - + log.info("--------------------------"); + log.info("请求visitorApply:{}", JSON.toJSONString(visitorApply)); String body = JSONObject.toJSONString(appointmentFreeRegisterRequest); + log.info("请求海康body:{}", body); String resultStr = HikUtil.hikApi(HikUri.APPOINTMENT_FREE_REGISTER, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); if(!"0".equals(resultJson.get("code"))){ @@ -129,7 +138,12 @@ appointmentFreeRegisterRequest.setVisitPurpose(visitorApply.getVisitReason()); VisitorInfo visitorInfo = new VisitorInfo(); visitorInfo.setVisitorName(visitorApply.getVisitorName()); - visitorInfo.setGender(Integer.valueOf(visitorApply.getVisitorGender())); + //身份证号确定性别 + int genderByIdCard = IdcardUtil.getGenderByIdCard(visitorApply.getIdCard()); + if(0 == genderByIdCard){ + genderByIdCard = 2; + } + visitorInfo.setGender(genderByIdCard); visitorInfo.setPhoneNo(visitorApply.getVisitorPhone()); visitorInfo.setCertificateNo(visitorApply.getIdCard()); visitorInfo.setCertificateType(111); @@ -165,7 +179,7 @@ VisitorApply visitorApply1 = visitorApplyMapper.selectById(visitorApply.getId()); if(StringUtils.isNotEmpty(visitorApply1.getAppointRecordId())){ List appointRecordIds = new ArrayList<>(); - appointRecordIds.add(visitorApply.getAppointRecordId()); + appointRecordIds.add(visitorApply1.getAppointRecordId()); String body = JSONObject.toJSONString(appointRecordIds); String resultStr = HikUtil.hikApi(HikUri.APPOINTMENT_CANCEL, body); JSONObject resultJson = (JSONObject)JSONObject.parse(resultStr); @@ -247,7 +261,12 @@ appointmentFreeRegisterRequest.setVisitPurpose(busConcentrator.getVisitReason()); VisitorInfo visitorInfo = new VisitorInfo(); visitorInfo.setVisitorName(busConcentrator.getVisitorName()); - visitorInfo.setGender(Integer.valueOf(busConcentrator.getVisitorGender())); + //身份证号确定性别 + int genderByIdCard = IdcardUtil.getGenderByIdCard(busConcentrator.getIdCard()); + if(0 == genderByIdCard){ + genderByIdCard = 2; + } + visitorInfo.setGender(genderByIdCard); visitorInfo.setPhoneNo(busConcentrator.getVisitorPhone()); visitorInfo.setCertificateNo(busConcentrator.getIdCard()); visitorInfo.setCertificateType(111); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java b/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java index 109eec2..269e3b0 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/util/DateUtils.java @@ -3,13 +3,11 @@ import cn.hutool.core.date.DateUtil; import javafx.util.Pair; +import org.apache.commons.lang3.StringUtils; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; +import java.util.*; /** * Created by Administrator on 2015/2/25. @@ -113,10 +111,46 @@ public static String getYesterday() { Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DATE, -2); + calendar.add(Calendar.DATE, -2); return sdf_day.format(calendar.getTime()); } + /** + * 包括传入的首尾日期 + */ + public static List getBetweenDays(String startTime, String endTime) { + if (StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)) { + return null; + } + //定义转换格式 + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + Date start = null; + Date end = null; + try { + start = df.parse(startTime); + end = df.parse(endTime); + } catch (ParseException e) { + e.printStackTrace(); + } + if (Objects.isNull(start) || Objects.isNull(end)) { + return null; + } + List result = new ArrayList<>(); + Calendar tempStart = Calendar.getInstance(); + tempStart.setTime(start); + tempStart.add(Calendar.DAY_OF_YEAR, 1); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Calendar tempEnd = Calendar.getInstance(); + tempEnd.setTime(end); + result.add(sdf.format(start)); + while (tempStart.before(tempEnd)) { + result.add(sdf.format(tempStart.getTime())); + tempStart.add(Calendar.DAY_OF_YEAR, 1); + } + result.add(endTime); + return result; + } + public static List getCurrentDateWeekList() { List list = new ArrayList<>(); //获取当前日期前30天的日期 @@ -165,7 +199,21 @@ // Date startDate = org.apache.commons.lang3.time.DateUtils.addDays(now, -7); // String s = DateUtil.formatDate(startDate); // list.add(s); - for (int i = 1; i < 8; i++) { + for (int i = 7; i > 0; i--) { + Date date = org.apache.commons.lang3.time.DateUtils.addDays(now, -i); + String s = DateUtil.formatDate(date); + list.add(s); + } + return list; + } + + /** + * 30天前的7天日期 + */ + public static List getCurrentDateDayBeforeMonthList() { + List list = new ArrayList<>(); + Date now = new Date(); + for (int i = 36; i > 29; i--) { Date date = org.apache.commons.lang3.time.DateUtils.addDays(now, -i); String s = DateUtil.formatDate(date); list.add(s); @@ -187,14 +235,22 @@ public static List getCurrentDateWorkHourList() { List list = new ArrayList<>(); + int hour = DateUtil.thisHour(true); String today = DateUtil.today(); - for (int i = 6; i < 24; i++) { + String substring = today.substring(5); + for (int i = 6; i < hour; i++) { if (i < 10) { - list.add(today + " 0" + i); + list.add(substring + " 0" + i + ":00"); } else { - list.add(today + " " + i); + list.add(substring + " " + i + ":00"); } } return list; } + + public static void main(String[] args) { + List betweenDays = getBetweenDays("2022-10-10", "2022-10-17"); + System.out.println(betweenDays); + + } } diff --git a/casic-web/src/main/build/package.xml b/casic-web/src/main/build/package.xml index 394dd0f..742d85b 100644 --- a/casic-web/src/main/build/package.xml +++ b/casic-web/src/main/build/package.xml @@ -22,6 +22,7 @@ start.bat start.sh + teststart.sh true 0744 diff --git a/casic-web/src/main/resources/config/application-dev.yml b/casic-web/src/main/resources/config/application-dev.yml index f436857..e7e5127 100644 --- a/casic-web/src/main/resources/config/application-dev.yml +++ b/casic-web/src/main/resources/config/application-dev.yml @@ -20,7 +20,7 @@ casic: kaptcha-open: false #是否开启登录时验证码 (true/false) - no-login-urls: /websocket/**,${casic.sysUrl}/user/login,${casic.sysUrl}/user/appLogin,${casic.sysUrl}/kaptcha/base64,${casic.sysUrl}/config/baseConfig,/route/mockToken,/cockpit/**,/propertyManage/**,/eventRcv/**,/hik/**,/staffInfo/**,/**/listPage,/**/list,/**/drawNo,/socket/repost + no-login-urls: /websocket/**,${casic.sysUrl}/user/login,${casic.sysUrl}/user/appLogin,${casic.sysUrl}/kaptcha/base64,${casic.sysUrl}/config/baseConfig,/route/mockToken,/cockpit/**,/propertyManage/**,/eventRcv/**,/hik/**,/staffInfo/**,/**/listPage,/**/list,/**/drawNo,/socket/repost,/caseInfo/update,/**/list/unResolved,/last/drawNo,/multiScore/** #flowable数据源和多数据源配置 db: init: @@ -34,6 +34,27 @@ config: #模板文件本地路径 exportPath: D:\code\casic-security-cockpit\casic-web\src\main\resources\config\export\ + #综合评分组件配置 + #员工通勤安防系数组件-员工出勤率权重 + commuteWeight: 0.6 + #重点区域防控系数组件权重 + keyAreaWeight: + case: 0.5 + keyArea: 0.25 + responseAssess: 0.25 + #访客控制安全系数组件权重 + visitorWeight: + singlePointDeduct: 2 #多停留1小时扣分数 + mostPointDeduct: 10 #每个访客最多扣分 + noRecordPointDeduct: 10 #无离开记录扣分 + #安保人员到岗系数组件 + securityWeight: + onDuty: 0.5 + levelAssess: 0.5 + #其他相关安全系统指标系数组件 + otherWeight: + security: 0.5 + repair: 0.5 logging: level.root: info diff --git a/casic-web/src/main/resources/config/application-prod.yml b/casic-web/src/main/resources/config/application-prod.yml index ba83780..939e753 100644 --- a/casic-web/src/main/resources/config/application-prod.yml +++ b/casic-web/src/main/resources/config/application-prod.yml @@ -18,7 +18,7 @@ casic: kaptcha-open: false #是否开启登录时验证码 (true/false) - no-login-urls: /websocket/**,${casic.sysUrl}/user/login,${casic.sysUrl}/user/appLogin,${casic.sysUrl}/kaptcha/base64,${casic.sysUrl}/config/baseConfig,/route/mockToken,/cockpit/**,/propertyManage/**,/eventRcv/**,/hik/**,/staffInfo/**,/**/listPage,/**/list,/**/drawNo,/socket/repost + no-login-urls: /websocket/**,${casic.sysUrl}/user/login,${casic.sysUrl}/user/appLogin,${casic.sysUrl}/kaptcha/base64,${casic.sysUrl}/config/baseConfig,/route/mockToken,/cockpit/**,/propertyManage/**,/eventRcv/**,/hik/**,/staffInfo/**,/**/listPage,/**/list,/**/drawNo,/socket/repost,/caseInfo/update,/**/list/unResolved,/last/drawNo,/multiScore/** #flowable数据源和多数据源配置 db: init: @@ -31,7 +31,28 @@ cockpit: config: #模板文件本地路径 - exportPath: D:\code\casic-security-cockpit\casic-web\src\main\resources\config\export\ + exportPath: /config/export + #综合评分组件配置 + #员工通勤安防系数组件-员工出勤率权重 + commuteWeight: 0.6 + #重点区域防控系数组件权重 + keyAreaWeight: + case: 0.5 + keyArea: 0.25 + responseAssess: 0.25 + #访客控制安全系数组件权重 + visitorWeight: + singlePointDeduct: 2 #多停留1小时扣分数 + mostPointDeduct: 10 #每个访客最多扣分 + noRecordPointDeduct: 10 #无离开记录扣分 + #安保人员到岗系数组件 + securityWeight: + onDuty: 0.5 + levelAssess: 0.5 + #其他相关安全系统指标系数组件 + otherWeight: + security: 0.5 + repair: 0.5 logging: level.root: info