AI预警统计修改
This commit is contained in:
parent
347c887b5b
commit
2762806c3c
@ -4,9 +4,11 @@ import cn.xuyanwu.spring.file.storage.EnableFileStorage;
|
|||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
@MapperScan({"com.xmgl.*.*.*.mapper"})
|
@MapperScan({"com.xmgl.*.*.*.mapper"})
|
||||||
@EnableFileStorage
|
@EnableFileStorage
|
||||||
|
@EnableScheduling
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class AirecognitionApplication {
|
public class AirecognitionApplication {
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,8 @@ import com.xmgl.recognition.modules.admin.entity.Algorithm;
|
|||||||
import com.xmgl.recognition.modules.admin.entity.SystemDictData;
|
import com.xmgl.recognition.modules.admin.entity.SystemDictData;
|
||||||
import com.xmgl.recognition.modules.admin.service.IAlgorithmService;
|
import com.xmgl.recognition.modules.admin.service.IAlgorithmService;
|
||||||
import com.xmgl.recognition.modules.admin.service.ISystemDictDataService;
|
import com.xmgl.recognition.modules.admin.service.ISystemDictDataService;
|
||||||
|
import com.xmgl.recognition.redis.Constant.CacheConstants;
|
||||||
|
import com.xmgl.recognition.redis.lock.RedisRepository;
|
||||||
import com.xmgl.recognition.util.CommonUtil;
|
import com.xmgl.recognition.util.CommonUtil;
|
||||||
import com.xmgl.recognition.util.ParamEnum;
|
import com.xmgl.recognition.util.ParamEnum;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@ -71,6 +73,9 @@ public class DeviceAlarmController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IAlgorithmService algorithmService;
|
private IAlgorithmService algorithmService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisRepository redisRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页列表查询
|
* 分页列表查询
|
||||||
*
|
*
|
||||||
@ -114,6 +119,27 @@ public class DeviceAlarmController {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理预警信息
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@OperLog(operModul = "设备报警管理", operType = "修改", operDesc = "处理预警信息")
|
||||||
|
@ApiOperation(value = "处理预警信息", notes = "处理预警信息", httpMethod = "POST")
|
||||||
|
@ApiImplicitParam(name = "id", value = "设备报警ID", paramType = "query", required = true, dataType = "Integer")
|
||||||
|
@PostMapping(value = "/updateState")
|
||||||
|
public Result<DeviceAlarm> updateState(@ApiIgnore @RequestBody Map<String, Object> map) {
|
||||||
|
Result<DeviceAlarm> result = new Result<DeviceAlarm>();
|
||||||
|
DeviceAlarm deviceAlarm = deviceAlarmService.getById(MapUtils.getString(map, "id"));
|
||||||
|
if (deviceAlarm == null) {
|
||||||
|
result.error500("未找到对应实体");
|
||||||
|
} else {
|
||||||
|
deviceAlarm.setState(1);
|
||||||
|
deviceAlarmService.updateById(deviceAlarm);
|
||||||
|
result.setSuccess(true);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备报警统计
|
* 设备报警统计
|
||||||
* @return
|
* @return
|
||||||
@ -125,10 +151,11 @@ public class DeviceAlarmController {
|
|||||||
Result<Map<String, Object>> result = new Result<Map<String, Object>>();
|
Result<Map<String, Object>> result = new Result<Map<String, Object>>();
|
||||||
Map<String, Object> resultMap = new HashMap<>();
|
Map<String, Object> resultMap = new HashMap<>();
|
||||||
List<DeviceAlarm> deviceAlarmList = deviceAlarmService.getList(Wrappers.<DeviceAlarm>lambdaQuery()
|
List<DeviceAlarm> deviceAlarmList = deviceAlarmService.getList(Wrappers.<DeviceAlarm>lambdaQuery()
|
||||||
.between(DeviceAlarm::getReportTime, DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date())));
|
.between(DeviceAlarm::getReportTime, DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()))
|
||||||
|
.orderByDesc(DeviceAlarm::getReportTime));
|
||||||
List<Algorithm> algorithms = algorithmService.list();
|
List<Algorithm> algorithms = algorithmService.list();
|
||||||
deviceAlarmList.stream().forEach(d -> {
|
deviceAlarmList.stream().forEach(d -> {
|
||||||
List<Algorithm> algorithmList = algorithms.stream().filter(a -> a.getRemark().equals(d.getType())).collect(Collectors.toList());
|
List<Algorithm> algorithmList = algorithms.stream().filter(a -> a.getRemark().equals(d.getType().toString())).collect(Collectors.toList());
|
||||||
d.setTypeName(algorithmList.size() > 0 ? algorithmList.get(0).getTitle() : "");
|
d.setTypeName(algorithmList.size() > 0 ? algorithmList.get(0).getTitle() : "");
|
||||||
});
|
});
|
||||||
resultMap.put("deviceAlarmList", deviceAlarmList);
|
resultMap.put("deviceAlarmList", deviceAlarmList);
|
||||||
@ -154,7 +181,7 @@ public class DeviceAlarmController {
|
|||||||
public Result<List<Map<String, Object>>> queryByType(@ApiIgnore @RequestBody Map<String, Object> map) {
|
public Result<List<Map<String, Object>>> queryByType(@ApiIgnore @RequestBody Map<String, Object> map) {
|
||||||
Result<List<Map<String, Object>>> result = new Result<List<Map<String, Object>>>();
|
Result<List<Map<String, Object>>> result = new Result<List<Map<String, Object>>>();
|
||||||
Integer day = MapUtils.getInteger(map, "day");
|
Integer day = MapUtils.getInteger(map, "day");
|
||||||
List<DeviceAlarm> list = deviceAlarmService.list(Wrappers.<DeviceAlarm>lambdaQuery()
|
List<DeviceAlarm> list = deviceAlarmService.queryListForType(Wrappers.<DeviceAlarm>lambdaQuery()
|
||||||
.between(DeviceAlarm::getReportTime, DateUtil.offsetDay(new Date(), -day), DateUtil.endOfDay(new Date())));
|
.between(DeviceAlarm::getReportTime, DateUtil.offsetDay(new Date(), -day), DateUtil.endOfDay(new Date())));
|
||||||
Map<Integer, List<DeviceAlarm>> collect = list.stream().collect(Collectors.groupingBy(l -> l.getType()));
|
Map<Integer, List<DeviceAlarm>> collect = list.stream().collect(Collectors.groupingBy(l -> l.getType()));
|
||||||
Map<Integer, Integer> resultMap = collect.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().size()));
|
Map<Integer, Integer> resultMap = collect.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().size()));
|
||||||
@ -163,15 +190,16 @@ public class DeviceAlarmController {
|
|||||||
algorithms.stream().forEach(s -> {
|
algorithms.stream().forEach(s -> {
|
||||||
Map<String, Object> map1 = new HashMap<>();
|
Map<String, Object> map1 = new HashMap<>();
|
||||||
map1.put("type", s.getTitle());
|
map1.put("type", s.getTitle());
|
||||||
map1.put("num", resultMap.get(s.getRemark()));
|
Integer num = resultMap.get(Integer.parseInt(s.getRemark()));
|
||||||
|
map1.put("num", num == null ? 0 : num);
|
||||||
resultList.add(map1);
|
resultList.add(map1);
|
||||||
});
|
});
|
||||||
/*resultMap.entrySet().stream().forEach(r -> {
|
resultList.sort(new Comparator<Map<String, Object>>() {
|
||||||
Map<String, Object> map1 = new HashMap<>();
|
@Override
|
||||||
map1.put("type", CommonUtil.getDictValue(systemDictData, r.getKey()));
|
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
|
||||||
map1.put("num", r.getValue());
|
return Integer.parseInt(o1.get("num").toString()) - (Integer.parseInt(o2.get("num").toString()));
|
||||||
resultList.add(map1);
|
}
|
||||||
});*/
|
}.reversed());
|
||||||
result.setSuccess(true);
|
result.setSuccess(true);
|
||||||
result.setResult(resultList);
|
result.setResult(resultList);
|
||||||
return result;
|
return result;
|
||||||
@ -193,7 +221,7 @@ public class DeviceAlarmController {
|
|||||||
Date beginTime = new Date();
|
Date beginTime = new Date();
|
||||||
if (type == 1) {
|
if (type == 1) {
|
||||||
beginTime = DateUtil.beginOfDay(new Date());
|
beginTime = DateUtil.beginOfDay(new Date());
|
||||||
list = deviceAlarmService.list(Wrappers.<DeviceAlarm>lambdaQuery()
|
list = deviceAlarmService.getList(Wrappers.<DeviceAlarm>lambdaQuery()
|
||||||
.between(DeviceAlarm::getReportTime, beginTime, new Date()));
|
.between(DeviceAlarm::getReportTime, beginTime, new Date()));
|
||||||
} else {
|
} else {
|
||||||
if (type == 2) {
|
if (type == 2) {
|
||||||
@ -204,9 +232,11 @@ public class DeviceAlarmController {
|
|||||||
day = 30;
|
day = 30;
|
||||||
}
|
}
|
||||||
beginTime = DateUtil.offsetDay(new Date(), -day);
|
beginTime = DateUtil.offsetDay(new Date(), -day);
|
||||||
list = deviceAlarmService.list(Wrappers.<DeviceAlarm>lambdaQuery()
|
if (type == 2) {
|
||||||
|
list = deviceAlarmService.getList(Wrappers.<DeviceAlarm>lambdaQuery()
|
||||||
.between(DeviceAlarm::getReportTime, beginTime, new Date()));
|
.between(DeviceAlarm::getReportTime, beginTime, new Date()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||||
if (type <= 2) {
|
if (type <= 2) {
|
||||||
for (int i = 0; i < 30; i++) {
|
for (int i = 0; i < 30; i++) {
|
||||||
@ -224,14 +254,23 @@ public class DeviceAlarmController {
|
|||||||
resultList.add(resultMap);
|
resultList.add(resultMap);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
List<Object> objList = redisRepository.getList(CacheConstants.DEVICE_ALARM);
|
||||||
for (int i = 0; i < 31; i++) {
|
for (int i = 0; i < 31; i++) {
|
||||||
Map<String, Object> resultMap = new HashMap<>();
|
|
||||||
DateTime dateTime = DateUtil.offsetDay(beginTime, i);
|
DateTime dateTime = DateUtil.offsetDay(beginTime, i);
|
||||||
if (DateUtil.compare(dateTime, new Date()) >= 0) {
|
if (DateUtil.compare(dateTime, DateUtil.offsetDay(beginTime, day)) >= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
resultMap.put("time", dateTime.toDateStr());
|
Map<String, Object> resultMap = new HashMap<>();
|
||||||
resultMap.put("num", list.stream().filter(l -> new SimpleDateFormat("yyyy-MM-dd").format(l.getReportTime()).equals(dateTime.toDateStr())).count());
|
Map<String, Object> cacheMap = new HashMap<>();
|
||||||
|
String dateStr = dateTime.toDateStr();
|
||||||
|
resultMap.put("num", 0);
|
||||||
|
for (Object s : objList) {
|
||||||
|
cacheMap = (Map<String, Object>) s;
|
||||||
|
if (cacheMap.get("time").equals(dateStr)) {
|
||||||
|
resultMap.put("num", cacheMap.get("num"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resultMap.put("time", dateStr);
|
||||||
resultList.add(resultMap);
|
resultList.add(resultMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,6 +95,13 @@ public class DeviceAlarm implements Serializable {
|
|||||||
@ApiModelProperty(value = "位置")
|
@ApiModelProperty(value = "位置")
|
||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态(1:已阅; 0:未阅)
|
||||||
|
*/
|
||||||
|
@Excel(name = "状态(1:已阅; 0:未阅)", width = 15)
|
||||||
|
@ApiModelProperty(value = "状态(1:已阅; 0:未阅)")
|
||||||
|
private Integer state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备名称
|
* 设备名称
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -25,5 +25,7 @@ public interface DeviceAlarmMapper extends BaseMapper<DeviceAlarm> {
|
|||||||
|
|
||||||
Page<DeviceAlarm> pageList(Page page, @Param(Constants.WRAPPER) Wrapper<DeviceAlarm> wrapper);
|
Page<DeviceAlarm> pageList(Page page, @Param(Constants.WRAPPER) Wrapper<DeviceAlarm> wrapper);
|
||||||
|
|
||||||
List<DeviceAlarm> pageList(@Param(Constants.WRAPPER) Wrapper<DeviceAlarm> wrapper);
|
List<DeviceAlarm> getList(@Param(Constants.WRAPPER) Wrapper<DeviceAlarm> wrapper);
|
||||||
|
|
||||||
|
List<DeviceAlarm> queryListForType(@Param(Constants.WRAPPER) Wrapper<DeviceAlarm> wrapper);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,4 +6,14 @@
|
|||||||
SELECT a.*, d.code as deviceName FROM device_alarm a LEFT JOIN device d ON a.device_code = d.`code`
|
SELECT a.*, d.code as deviceName FROM device_alarm a LEFT JOIN device d ON a.device_code = d.`code`
|
||||||
${ew.customSqlSegment}
|
${ew.customSqlSegment}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getList" resultType="com.xmgl.recognition.modules.enterprise.entity.DeviceAlarm">
|
||||||
|
SELECT a.*, d.code as deviceName FROM device_alarm a LEFT JOIN device d ON a.device_code = d.`code`
|
||||||
|
${ew.customSqlSegment}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="queryListForType" resultType="com.xmgl.recognition.modules.enterprise.entity.DeviceAlarm">
|
||||||
|
SELECT id, type FROM device_alarm
|
||||||
|
${ew.customSqlSegment}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
@ -21,4 +21,6 @@ public interface IDeviceAlarmService extends IService<DeviceAlarm> {
|
|||||||
Page<DeviceAlarm> pageList(Map<String, Object> map);
|
Page<DeviceAlarm> pageList(Map<String, Object> map);
|
||||||
|
|
||||||
List<DeviceAlarm> getList(Wrapper<DeviceAlarm> wrapper);
|
List<DeviceAlarm> getList(Wrapper<DeviceAlarm> wrapper);
|
||||||
|
|
||||||
|
List<DeviceAlarm> queryListForType(Wrapper<DeviceAlarm> wrapper);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,6 +55,11 @@ public class DeviceAlarmServiceImpl extends ServiceImpl<DeviceAlarmMapper, Devic
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DeviceAlarm> getList(Wrapper<DeviceAlarm> wrapper) {
|
public List<DeviceAlarm> getList(Wrapper<DeviceAlarm> wrapper) {
|
||||||
return baseMapper.pageList(wrapper);
|
return baseMapper.getList(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceAlarm> queryListForType(Wrapper<DeviceAlarm> wrapper) {
|
||||||
|
return baseMapper.queryListForType(wrapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,11 @@ public interface CacheConstants {
|
|||||||
*/
|
*/
|
||||||
String USER_DETAILS = "user_details:";
|
String USER_DETAILS = "user_details:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备预警信息
|
||||||
|
*/
|
||||||
|
String DEVICE_ALARM = "device_alarm";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色信息缓存
|
* 角色信息缓存
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.xmgl.recognition.task;
|
package com.xmgl.recognition.task;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUnit;
|
import cn.hutool.core.date.DateUnit;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
@ -10,14 +11,17 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|||||||
import com.xmgl.recognition.modules.admin.entity.Device;
|
import com.xmgl.recognition.modules.admin.entity.Device;
|
||||||
import com.xmgl.recognition.modules.admin.service.IDeviceService;
|
import com.xmgl.recognition.modules.admin.service.IDeviceService;
|
||||||
|
|
||||||
|
import com.xmgl.recognition.modules.enterprise.entity.DeviceAlarm;
|
||||||
|
import com.xmgl.recognition.modules.enterprise.service.IDeviceAlarmService;
|
||||||
|
import com.xmgl.recognition.redis.Constant.CacheConstants;
|
||||||
|
import com.xmgl.recognition.redis.lock.RedisRepository;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 预警信息统计定时任务
|
* @description: 预警信息统计定时任务
|
||||||
@ -29,6 +33,12 @@ public class AlarmTask {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IDeviceService deviceService;
|
private IDeviceService deviceService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisRepository redisRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IDeviceAlarmService deviceAlarmService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ,每分钟检查设备在线状态
|
* ,每分钟检查设备在线状态
|
||||||
*/
|
*/
|
||||||
@ -48,4 +58,21 @@ public class AlarmTask {
|
|||||||
}
|
}
|
||||||
log.info("=========定时检查设备在线任务执行成功========");
|
log.info("=========定时检查设备在线任务执行成功========");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ,统计报警信息
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 1 * * ?")
|
||||||
|
private void deviceAlarmStat() {
|
||||||
|
DateTime dateTime = DateUtil.offsetDay(new Date(), -1);
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("time", dateTime.toDateStr());
|
||||||
|
map.put("num", deviceAlarmService.count(Wrappers.<DeviceAlarm>lambdaQuery()
|
||||||
|
.between(DeviceAlarm::getReportTime, DateUtil.beginOfDay(dateTime), DateUtil.endOfDay(dateTime))));
|
||||||
|
long num = redisRepository.leftPush(CacheConstants.DEVICE_ALARM, map);
|
||||||
|
if (num > 31) {
|
||||||
|
redisRepository.rightPop(CacheConstants.DEVICE_ALARM);
|
||||||
|
}
|
||||||
|
log.info("=========定时检查设备在线任务执行成功========");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,6 +51,7 @@ public class FileUtil {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static MultipartFile base64toMultipart(String data, String fileName) {
|
public static MultipartFile base64toMultipart(String data, String fileName) {
|
||||||
|
data = "data:image/jpeg;base64," + data;
|
||||||
String[] baseStrs = data.split(",");
|
String[] baseStrs = data.split(",");
|
||||||
//BASE64Decoder decoder = new BASE64Decoder();
|
//BASE64Decoder decoder = new BASE64Decoder();
|
||||||
//byte[] b = decoder.decodeBuffer(baseStrs[1]);
|
//byte[] b = decoder.decodeBuffer(baseStrs[1]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user