From 3366e42154ba26c2992b8210d6c15decc9dedb7c Mon Sep 17 00:00:00 2001 From: liux <963924687@qq.com> Date: Wed, 25 Jun 2025 16:09:16 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kitchen/domain/constants/AlarmEnum.java | 44 ++++++++ .../domain/constants/ViolationEnum.java | 47 ++++++++ .../impl/KitchenHomePageerviceImpl.java | 105 ++++++++++++++++-- .../mapper/kitchen/KitchenHomePageMapper.xml | 2 +- 4 files changed, 185 insertions(+), 13 deletions(-) create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/constants/AlarmEnum.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/constants/ViolationEnum.java diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/constants/AlarmEnum.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/constants/AlarmEnum.java new file mode 100644 index 0000000..68451e3 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/constants/AlarmEnum.java @@ -0,0 +1,44 @@ +package com.bonus.canteen.core.kitchen.domain.constants; + +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * @author xliu 告警枚举 + * @date 2025/6/19 15:44 + */ +public enum AlarmEnum { + + UNCOVER_TRASH(2, "垃圾桶未盖报警"), + FOUND_MOUSE(3, "发现老鼠"), + UNAUTHORIZED_PERSON_ENTER(11, "未授权人员进入"), + FIRE_ALARM(13, "动火离人"); + + + private Integer key; + + private String desc; + + AlarmEnum(Integer key, String desc) { + this.key = key; + this.desc = desc; + } + + public static Map toMap() { + return Stream.of(AlarmEnum.values()) + .collect(Collectors.toMap( + AlarmEnum::getKey, + AlarmEnum::getDesc + )); + } + + public Integer getKey() { + return this.key; + } + + public String getDesc() { + return this.desc; + } + +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/constants/ViolationEnum.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/constants/ViolationEnum.java new file mode 100644 index 0000000..0e30ba8 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/constants/ViolationEnum.java @@ -0,0 +1,47 @@ +package com.bonus.canteen.core.kitchen.domain.constants; + +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * @author xliu 违规类型枚举 + * @date 2025/6/19 15:44 + */ +public enum ViolationEnum { + + UNWEAR_MASK(1, "未戴口罩"), + NOT_WEAR_COOK_CLOTHES(4, "未穿厨师服"), + NOT_WEAR_COOK_HAT(5, "未戴厨师帽"), + NOT_WEAR_GLOVES(6, "未戴手套"), + SMOKE(7, "抽烟"), + CALL_PHONE(8, "打电话"), + DEVICE_RETURN(10, "设备归位"); + + + private Integer key; + + private String desc; + + ViolationEnum(Integer key, String desc) { + this.key = key; + this.desc = desc; + } + + public static Map toMap() { + return Stream.of(ViolationEnum.values()) + .collect(Collectors.toMap( + ViolationEnum::getKey, + ViolationEnum::getDesc + )); + } + + public Integer getKey() { + return this.key; + } + + public String getDesc() { + return this.desc; + } + +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenHomePageerviceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenHomePageerviceImpl.java index bf167f9..c097509 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenHomePageerviceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenHomePageerviceImpl.java @@ -6,7 +6,9 @@ import com.bonus.canteen.core.basic.mapper.BasicSettingMapper; import com.bonus.canteen.core.kitchen.domain.KitchenDeviceInfo; import com.bonus.canteen.core.kitchen.domain.KitchenDeviceSensorMetric; import com.bonus.canteen.core.kitchen.domain.KitchenStaffInfo; +import com.bonus.canteen.core.kitchen.domain.constants.AlarmEnum; import com.bonus.canteen.core.kitchen.domain.constants.StaffWarningEnum; +import com.bonus.canteen.core.kitchen.domain.constants.ViolationEnum; import com.bonus.canteen.core.kitchen.dto.IndexHomePageDTO; import com.bonus.canteen.core.kitchen.mapper.KitchenDeviceInfoMapper; import com.bonus.canteen.core.kitchen.mapper.KitchenDeviceSensorMetricMapper; @@ -175,7 +177,31 @@ public class KitchenHomePageerviceImpl implements IKitchenHomePageService { deviceEndTime = LocalDate.now(); } List deviceStatus = kitchenHomePageMapper.getDeviceStatusCount(deviceStartDate.toString(), deviceEndTime.toString()); + if(deviceStatus!=null && deviceStatus.size() == 0){ + IndexMapCountVO indexMapCountVO = new IndexMapCountVO(); + indexMapCountVO.setName("在线"); + indexMapCountVO.setCount(0); + IndexMapCountVO indexMapCountVO1 = new IndexMapCountVO(); + indexMapCountVO1.setName("离线"); + indexMapCountVO1.setCount(0); + deviceStatus.add(indexMapCountVO); + deviceStatus.add(indexMapCountVO1); + + }else if(deviceStatus!=null && deviceStatus.size() == 1){ + IndexMapCountVO indexMapCountVO = deviceStatus.get(0); + if("在线".equals(indexMapCountVO.getName())) { + IndexMapCountVO indexMapCountVO1 = new IndexMapCountVO(); + indexMapCountVO1.setName("离线"); + indexMapCountVO1.setCount(0); + deviceStatus.add(indexMapCountVO1); + }else{ + IndexMapCountVO indexMapCountVO1 = new IndexMapCountVO(); + indexMapCountVO1.setName("在线"); + indexMapCountVO1.setCount(0); + deviceStatus.add(indexMapCountVO1); + } + } //留样数据分析 LocalDate sampleStartDate = indexHomePageDTO.getSampleStartTime(); @@ -190,16 +216,42 @@ public class KitchenHomePageerviceImpl implements IKitchenHomePageService { } List sampleRetention = kitchenHomePageMapper.getSampleRetentionCount(sampleStartDate.toString(), sampleEndTime.toString()); + if(sampleRetention!=null && sampleRetention.size() == 0){ + IndexMapCountVO indexMapCountVO = new IndexMapCountVO(); + indexMapCountVO.setName("合格"); + indexMapCountVO.setCount(0); + IndexMapCountVO indexMapCountVO1 = new IndexMapCountVO(); + indexMapCountVO1.setName("不合格"); + indexMapCountVO1.setCount(0); + sampleRetention.add(indexMapCountVO); + sampleRetention.add(indexMapCountVO1); + + }else if(sampleRetention!=null && sampleRetention.size() == 1){ + IndexMapCountVO indexMapCountVO = sampleRetention.get(0); + if("合格".equals(indexMapCountVO.getName())) { + IndexMapCountVO indexMapCountVO1 = new IndexMapCountVO(); + indexMapCountVO1.setName("不合格"); + indexMapCountVO1.setCount(0); + deviceStatus.add(indexMapCountVO1); + }else{ + IndexMapCountVO indexMapCountVO1 = new IndexMapCountVO(); + indexMapCountVO1.setName("合格"); + indexMapCountVO1.setCount(0); + sampleRetention.add(indexMapCountVO1); + } + } //报警数据分析-员工违规 List employeeViolation = kitchenHomePageMapper.getEmployeeViolationCount(1); - for(IndexMapCountVO bean : employeeViolation ){ - if (StringUtils.isNotEmpty(bean.getName())) { - bean.setName(StaffWarningMap.get(Integer.valueOf(bean.getName()))); - } - } + Map ViolationMap = ViolationEnum.toMap(); + List employeeViolation_result = mergeViolationDataWithStream(ViolationMap, employeeViolation); +// for(IndexMapCountVO bean : employeeViolation ){ +// if (StringUtils.isNotEmpty(bean.getName())) { +// bean.setName(StaffWarningMap.get(Integer.valueOf(bean.getName()))); +// } +// } if(kitchenDeviceSensorMetrics != null || kitchenDeviceSensorMetrics.size()>0){ List environmentWarning = new ArrayList<>(); @@ -234,15 +286,18 @@ public class KitchenHomePageerviceImpl implements IKitchenHomePageService { //报警数据分析-环境告警 List environmentaAlarm = kitchenHomePageMapper.getEmployeeViolationCount(2); - for(IndexMapCountVO bean : environmentaAlarm ){ - if (StringUtils.isNotEmpty(bean.getName())) { - bean.setName(StaffWarningMap.get(Integer.valueOf(bean.getName()))); - } - } +// for(IndexMapCountVO bean : environmentaAlarm ){ +// if (StringUtils.isNotEmpty(bean.getName())) { +// bean.setName(StaffWarningMap.get(Integer.valueOf(bean.getName()))); +// } +// } + + Map alarmMap = AlarmEnum.toMap(); + List environmentaAlarm_result = mergeViolationDataWithStream(alarmMap, environmentaAlarm); indexHomePageInformationVO.setDeviceCount(Integer.valueOf(deviceInfoCount.toString())); - indexHomePageInformationVO.setEmployeeViolation(employeeViolation); - indexHomePageInformationVO.setEnvironmentalAlarm(environmentaAlarm); + indexHomePageInformationVO.setEmployeeViolation(employeeViolation_result); + indexHomePageInformationVO.setEnvironmentalAlarm(environmentaAlarm_result); indexHomePageInformationVO.setHistoricalWarningCount(historicalWarningCount); indexHomePageInformationVO.setTodayWarningCount(todayWarningCount); indexHomePageInformationVO.setDeviceStatus(deviceStatus); @@ -254,6 +309,32 @@ public class KitchenHomePageerviceImpl implements IKitchenHomePageService { return indexHomePageInformationVO; } + public List mergeViolationDataWithStream( + Map violationMap, + List employeeViolation) { + + List result = new ArrayList<>(); + + violationMap.forEach((mapKey, mapValue) -> { + Optional matchedVo = employeeViolation.stream() + .filter(vo -> { + try { + return mapKey.equals(Integer.parseInt(vo.getName())); + } catch (NumberFormatException e) { + return false; + } + }) + .findFirst(); + + IndexMapCountVO newVo = new IndexMapCountVO(); + newVo.setName(mapValue); // 使用 ViolationMap 的 value 作为 name + newVo.setCount(matchedVo.map(IndexMapCountVO::getCount).orElse(0)); + result.add(newVo); + }); + + return result; + } + public static boolean isInteger(String str) { return str.matches("^-?\\d+$"); // 匹配正负整数 } diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/kitchen/KitchenHomePageMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/kitchen/KitchenHomePageMapper.xml index dbc50ed..d44e2a0 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/kitchen/KitchenHomePageMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/kitchen/KitchenHomePageMapper.xml @@ -10,7 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"