设备信息
This commit is contained in:
parent
afccb0e06b
commit
faabc4151b
@ -0,0 +1,6 @@
|
|||||||
|
package cn.iocoder.yudao.module.system.constant.device;
|
||||||
|
|
||||||
|
public class DeviceChcheConstant {
|
||||||
|
//设备最后通讯时间
|
||||||
|
public static String DEVICE_LAST_TIME = "device:last:time";
|
||||||
|
}
|
@ -100,4 +100,11 @@ public class DeviceInformationController {
|
|||||||
BeanUtils.toBean(list, DeviceInformationRespVO.class));
|
BeanUtils.toBean(list, DeviceInformationRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/classification")
|
||||||
|
@Operation(summary = "获得设备信息分类列表")
|
||||||
|
public CommonResult<Map<Integer,List<DeviceInformationDO>>> classification() {
|
||||||
|
Map<Integer,List<DeviceInformationDO>> map = informationService.classification();
|
||||||
|
return success(map);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,9 @@ public class DeviceInformationPageReqVO extends PageParam {
|
|||||||
@Schema(description = "设备编号")
|
@Schema(description = "设备编号")
|
||||||
private String deviceNo;
|
private String deviceNo;
|
||||||
|
|
||||||
|
@Schema(description = "设备位置")
|
||||||
|
private String deviceLocation;
|
||||||
|
|
||||||
@Schema(description = "mac地址")
|
@Schema(description = "mac地址")
|
||||||
private String macAddress;
|
private String macAddress;
|
||||||
|
|
||||||
|
@ -50,6 +50,10 @@ public class DeviceInformationRespVO {
|
|||||||
@ExcelProperty("设备编号")
|
@ExcelProperty("设备编号")
|
||||||
private String deviceNo;
|
private String deviceNo;
|
||||||
|
|
||||||
|
@Schema(description = "设备位置")
|
||||||
|
@ExcelProperty("设备位置")
|
||||||
|
private String deviceLocation;
|
||||||
|
|
||||||
@Schema(description = "mac地址")
|
@Schema(description = "mac地址")
|
||||||
@ExcelProperty("mac地址")
|
@ExcelProperty("mac地址")
|
||||||
private String macAddress;
|
private String macAddress;
|
||||||
|
@ -41,6 +41,9 @@ public class DeviceInformationSaveReqVO {
|
|||||||
@Schema(description = "设备编号")
|
@Schema(description = "设备编号")
|
||||||
private String deviceNo;
|
private String deviceNo;
|
||||||
|
|
||||||
|
@Schema(description = "设备位置")
|
||||||
|
private String deviceLocation;
|
||||||
|
|
||||||
@Schema(description = "mac地址")
|
@Schema(description = "mac地址")
|
||||||
private String macAddress;
|
private String macAddress;
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
|||||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
@ -62,6 +63,10 @@ public class DeviceInformationDO extends BaseDO {
|
|||||||
* 设备编号
|
* 设备编号
|
||||||
*/
|
*/
|
||||||
private String deviceNo;
|
private String deviceNo;
|
||||||
|
/**
|
||||||
|
* 设备位置
|
||||||
|
*/
|
||||||
|
private String deviceLocation;
|
||||||
/**
|
/**
|
||||||
* mac地址
|
* mac地址
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
package cn.iocoder.yudao.module.system.enums.device;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* device_information的device_status
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum DeviceStatusEnum {
|
||||||
|
ON_LINE(1, "在线"),
|
||||||
|
OFF_LINE(2, "离线"),
|
||||||
|
EXECPTION(3, "异常");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型
|
||||||
|
*/
|
||||||
|
private final Integer type;
|
||||||
|
/**
|
||||||
|
* 说明
|
||||||
|
*/
|
||||||
|
private final String msg;
|
||||||
|
}
|
@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.information.DeviceInformati
|
|||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备信息 Service 接口
|
* 设备信息 Service 接口
|
||||||
@ -76,4 +77,10 @@ public interface DeviceInformationService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<DeviceInformationDO> getList(@Valid DeviceInformationPageReqVO pageReqVO);
|
List<DeviceInformationDO> getList(@Valid DeviceInformationPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得设备信息分类列表
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Map<Integer, List<DeviceInformationDO>> classification();
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
import cn.iocoder.yudao.module.grpc.api.GrpcServiceApi;
|
import cn.iocoder.yudao.module.grpc.api.GrpcServiceApi;
|
||||||
|
import cn.iocoder.yudao.module.system.constant.device.DeviceChcheConstant;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.information.vo.DeviceInformationPageReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.information.vo.DeviceInformationPageReqVO;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.information.vo.DeviceInformationSaveReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.information.vo.DeviceInformationSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.system.dal.dataobject.information.DeviceInformationDO;
|
import cn.iocoder.yudao.module.system.dal.dataobject.information.DeviceInformationDO;
|
||||||
import cn.iocoder.yudao.module.system.dal.mysql.information.DeviceInformationMapper;
|
import cn.iocoder.yudao.module.system.dal.mysql.information.DeviceInformationMapper;
|
||||||
|
import cn.iocoder.yudao.module.system.enums.device.DeviceStatusEnum;
|
||||||
|
import cn.iocoder.yudao.module.system.util.redis.RedisUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -17,7 +20,9 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static cn.hutool.core.collection.CollUtil.isNotEmpty;
|
import static cn.hutool.core.collection.CollUtil.isNotEmpty;
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
@ -41,6 +46,9 @@ public class DeviceInformationServiceImpl implements DeviceInformationService {
|
|||||||
@Resource
|
@Resource
|
||||||
private GrpcServiceApi grpcServiceApi;
|
private GrpcServiceApi grpcServiceApi;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long createInformation(DeviceInformationSaveReqVO createReqVO) {
|
public Long createInformation(DeviceInformationSaveReqVO createReqVO) {
|
||||||
DeviceInformationPageReqVO pageReqVO = new DeviceInformationPageReqVO();
|
DeviceInformationPageReqVO pageReqVO = new DeviceInformationPageReqVO();
|
||||||
@ -52,7 +60,6 @@ public class DeviceInformationServiceImpl implements DeviceInformationService {
|
|||||||
// 插入
|
// 插入
|
||||||
DeviceInformationDO information = BeanUtils.toBean(createReqVO, DeviceInformationDO.class);
|
DeviceInformationDO information = BeanUtils.toBean(createReqVO, DeviceInformationDO.class);
|
||||||
information.setDeviceStatus(1);
|
information.setDeviceStatus(1);
|
||||||
information.setDeviceLastTime(LocalDateTime.now());
|
|
||||||
informationMapper.insert(information);
|
informationMapper.insert(information);
|
||||||
// 返回
|
// 返回
|
||||||
return information.getId();
|
return information.getId();
|
||||||
@ -83,7 +90,24 @@ public class DeviceInformationServiceImpl implements DeviceInformationService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DeviceInformationDO getInformation(Long id) {
|
public DeviceInformationDO getInformation(Long id) {
|
||||||
return informationMapper.selectById(id);
|
// 校验存在
|
||||||
|
validateInformationExists(id);
|
||||||
|
DeviceInformationDO deviceInformationDO = informationMapper.selectById(id);
|
||||||
|
String deviceKey = DeviceChcheConstant.DEVICE_LAST_TIME +deviceInformationDO.getMacAddress();
|
||||||
|
Object object = redisUtil.get(deviceKey);
|
||||||
|
if (ObjectUtil.isEmpty(object)) {
|
||||||
|
deviceInformationDO.setDeviceStatus(DeviceStatusEnum.OFF_LINE.getType());
|
||||||
|
return deviceInformationDO;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
LocalDateTime curTimeLDT = LocalDateTime.parse((String)object, df);
|
||||||
|
deviceInformationDO.setDeviceLastTime(curTimeLDT);
|
||||||
|
deviceInformationDO.setDeviceStatus(DeviceStatusEnum.ON_LINE.getType());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("查询设备最后通讯时间异常 :{}",e.getMessage());
|
||||||
|
}
|
||||||
|
return deviceInformationDO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -118,4 +142,46 @@ public class DeviceInformationServiceImpl implements DeviceInformationService {
|
|||||||
.eq(pageReqVO.getDeviceType() != null, DeviceInformationDO::getDeviceType, pageReqVO.getDeviceType()));
|
.eq(pageReqVO.getDeviceType() != null, DeviceInformationDO::getDeviceType, pageReqVO.getDeviceType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得设备信息分类列表
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Map<Integer, List<DeviceInformationDO>> classification() {
|
||||||
|
List<DeviceInformationDO> deviceInformationDOS = informationMapper.selectList(new LambdaQueryWrapper<DeviceInformationDO>());
|
||||||
|
if (ObjectUtil.isEmpty(deviceInformationDOS)) {
|
||||||
|
return new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo 需要设置设备通讯的时间
|
||||||
|
for (DeviceInformationDO deviceInformationDO : deviceInformationDOS) {
|
||||||
|
String deviceKey = DeviceChcheConstant.DEVICE_LAST_TIME +deviceInformationDO.getMacAddress();
|
||||||
|
Object object = redisUtil.get(deviceKey);
|
||||||
|
if (ObjectUtil.isEmpty(object)) {
|
||||||
|
deviceInformationDO.setDeviceStatus(DeviceStatusEnum.OFF_LINE.getType());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
LocalDateTime curTimeLDT = LocalDateTime.parse((String)object, df);
|
||||||
|
deviceInformationDO.setDeviceLastTime(curTimeLDT);
|
||||||
|
deviceInformationDO.setDeviceStatus(DeviceStatusEnum.ON_LINE.getType());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("查询设备最后通讯时间异常 :{}",e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Integer, List<DeviceInformationDO>> collect =
|
||||||
|
deviceInformationDOS.stream()
|
||||||
|
.collect(Collectors.groupingBy(DeviceInformationDO::getDeviceType));
|
||||||
|
|
||||||
|
ArrayList<Map.Entry<Integer, List<DeviceInformationDO>>> list = new ArrayList<Map.Entry<Integer, List<DeviceInformationDO>>>(collect.entrySet());
|
||||||
|
Collections.sort(list, new Comparator<Map.Entry<Integer, List<DeviceInformationDO>>>() {
|
||||||
|
public int compare(Map.Entry<Integer, List<DeviceInformationDO>> o1, Map.Entry<Integer, List<DeviceInformationDO>> o2) {
|
||||||
|
return o1.getKey().compareTo(o2.getKey()); // 按照值排序
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return collect;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user