首页接口
This commit is contained in:
parent
526b9d6d02
commit
3366e42154
|
|
@ -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<Integer, String> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<Integer, String> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<IndexMapCountVO> 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<IndexMapCountVO> 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<IndexMapCountVO> employeeViolation = kitchenHomePageMapper.getEmployeeViolationCount(1);
|
||||
for(IndexMapCountVO bean : employeeViolation ){
|
||||
if (StringUtils.isNotEmpty(bean.getName())) {
|
||||
bean.setName(StaffWarningMap.get(Integer.valueOf(bean.getName())));
|
||||
}
|
||||
}
|
||||
Map<Integer,String> ViolationMap = ViolationEnum.toMap();
|
||||
List<IndexMapCountVO> 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<IndexMapCountVO> environmentWarning = new ArrayList<>();
|
||||
|
|
@ -234,15 +286,18 @@ public class KitchenHomePageerviceImpl implements IKitchenHomePageService {
|
|||
|
||||
//报警数据分析-环境告警
|
||||
List<IndexMapCountVO> 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<Integer,String> alarmMap = AlarmEnum.toMap();
|
||||
List<IndexMapCountVO> 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<IndexMapCountVO> mergeViolationDataWithStream(
|
||||
Map<Integer, String> violationMap,
|
||||
List<IndexMapCountVO> employeeViolation) {
|
||||
|
||||
List<IndexMapCountVO> result = new ArrayList<>();
|
||||
|
||||
violationMap.forEach((mapKey, mapValue) -> {
|
||||
Optional<IndexMapCountVO> 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+$"); // 匹配正负整数
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
|
||||
<select id="getEmployeeViolationCount" resultType="com.bonus.canteen.core.kitchen.vo.IndexMapCountVO">
|
||||
select alarm_type as `name`,count(illegal_warning_id) as `count` from kitchen_staff_illegal_warning
|
||||
where illegal_warning_type =#{warningType} and DATE(create_time) = CURRENT_DATE()
|
||||
where alarm_type =#{warningType} and DATE(create_time) = CURRENT_DATE()
|
||||
GROUP BY alarm_type
|
||||
|
||||
</select>
|
||||
|
|
|
|||
Loading…
Reference in New Issue