|
|
@@ -2,7 +2,6 @@ package com.xunmei.mediator.api.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
@@ -11,6 +10,7 @@ import com.xunmei.common.core.domain.iot.domain.IotUps;
|
|
|
import com.xunmei.common.core.domain.iot.domain.IotUpsAttr;
|
|
|
import com.xunmei.common.core.enums.iot.UpsStatus;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
+import com.xunmei.common.core.utils.JacksonUtils;
|
|
|
import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
import com.xunmei.mediator.api.mapper.IotUpsAttrMapper;
|
|
|
import com.xunmei.mediator.api.mapper.IotUpsMapper;
|
|
|
@@ -36,6 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
@@ -73,7 +74,7 @@ public class IotUpsServiceImpl extends ServiceImpl<IotUpsMapper, IotUps> impleme
|
|
|
|
|
|
@Override
|
|
|
public ReceiveErrorDto saveUpsDeviceData(UpsDeviceDataDto request, String msgId) throws IllegalAccessException {
|
|
|
- String value = DigestUtils.md5Hex(request.getInfos());
|
|
|
+ String value = DigestUtils.md5Hex(JacksonUtils.toJSONString(request.getInfos()));
|
|
|
String key = request.getOrgCode() + request.getDeviceCode() + "upsdata";
|
|
|
//验证是否在段时间内收到重复的数据
|
|
|
if (!RedisCheckRepeatDataUtil.checkData(key, value)) {
|
|
|
@@ -103,6 +104,7 @@ public class IotUpsServiceImpl extends ServiceImpl<IotUpsMapper, IotUps> impleme
|
|
|
}
|
|
|
|
|
|
private Map<String, Object> buildUpsAndData(UpsDeviceDataDto request) {
|
|
|
+ String info = JSON.toJSONString(request.getInfos());
|
|
|
IotUps upsDevice = baseMapper.selectByUniqueCode(IotUps.getUniqueCode(request.getOrgCode(), request.getHostCode(), request.getDeviceCode()));
|
|
|
ReceiveErrorDto errorDto = ReceiveErrorDto.success();
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
@@ -113,9 +115,9 @@ public class IotUpsServiceImpl extends ServiceImpl<IotUpsMapper, IotUps> impleme
|
|
|
return map;
|
|
|
}
|
|
|
upsDevice.setUpdateTime(DateUtils.toLocalDateTime(request.getUpdateTime()));
|
|
|
- //List<UpsDataVo> infos = buildInfos(request.getInfos());
|
|
|
+ List<UpsDataVo> infos = buildInfos(info);
|
|
|
if (request.getInfos() != null) {
|
|
|
- List<UpsDataVo> list = JSON.parseArray(request.getInfos(), UpsDataVo.class);
|
|
|
+ List<UpsDataVo> list = JSON.parseArray(info, UpsDataVo.class);
|
|
|
for (UpsDataVo vo : list) {
|
|
|
if (StringUtils.isNotEmpty(vo.getName()) && vo.getName().contains("UPS市电状态")) {
|
|
|
upsDevice.setMainsElectricityStatus(Double.valueOf(vo.getVal()).intValue());
|
|
|
@@ -125,6 +127,7 @@ public class IotUpsServiceImpl extends ServiceImpl<IotUpsMapper, IotUps> impleme
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ upsDevice.setInfo(JacksonUtils.toJSONString(infos));
|
|
|
map.put("errorDto", errorDto);
|
|
|
map.put("upsDevice", upsDevice);
|
|
|
return map;
|
|
|
@@ -227,6 +230,7 @@ public class IotUpsServiceImpl extends ServiceImpl<IotUpsMapper, IotUps> impleme
|
|
|
LambdaUpdateWrapper<IotUps> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
updateWrapper.eq(IotUps::getDeleted, 0);
|
|
|
updateWrapper.in(IotUps::getOrgId, orgIdList);
|
|
|
+ updateWrapper.set(IotUps::getDeleted, 1);
|
|
|
baseMapper.update(null, updateWrapper);
|
|
|
}
|
|
|
|
|
|
@@ -236,7 +240,7 @@ public class IotUpsServiceImpl extends ServiceImpl<IotUpsMapper, IotUps> impleme
|
|
|
List<NorthError> errors = new ArrayList<>();
|
|
|
List<IotUps> upsDevices = new ArrayList<>();
|
|
|
List<IotUps> upsDeviceOlds = new ArrayList<>();
|
|
|
- List<IotUps> upsDeviceAllOlds = baseMapper.selectList(new QueryWrapper<>());
|
|
|
+ List<IotUps> upsDeviceAllOlds = this.list();
|
|
|
NorthError error = null;
|
|
|
//获取机构列表
|
|
|
List<Long> list = new ArrayList<>();
|
|
|
@@ -262,10 +266,13 @@ public class IotUpsServiceImpl extends ServiceImpl<IotUpsMapper, IotUps> impleme
|
|
|
Optional<IotUps> upsOptional = upsDeviceAllOlds.stream().filter(r -> r.getUpsUniqueCode().equals(upsDevice.getUpsUniqueCode())).findAny();
|
|
|
if (upsOptional.isPresent()) {
|
|
|
IotUps upsDeviceOld = upsOptional.get();
|
|
|
- BeanUtils.copyProperties(upsDeviceOld, upsDevice);
|
|
|
+ BeanUtils.copyProperties(upsDevice, upsDeviceOld, "id");
|
|
|
+ upsDeviceOld.setUpdateTime(LocalDateTime.now());
|
|
|
upsDeviceOlds.add(upsDeviceOld);
|
|
|
} else {
|
|
|
upsDevice.setId(IdWorker.getId());
|
|
|
+ upsDevice.setCreateTime(LocalDateTime.now());
|
|
|
+ upsDevice.setUpdateTime(LocalDateTime.now());
|
|
|
upsDevices.add(upsDevice);
|
|
|
}
|
|
|
|
|
|
@@ -286,13 +293,12 @@ public class IotUpsServiceImpl extends ServiceImpl<IotUpsMapper, IotUps> impleme
|
|
|
.deviceType(ups.getDeviceType())
|
|
|
.hostCode(ups.getHostCode())
|
|
|
.orgId(org.getId())
|
|
|
- .orgName(org.getName())
|
|
|
+ .orgName(org.getShortName())
|
|
|
.orgPath(org.getPath())
|
|
|
.upsUniqueCode(IotUps.getUniqueCode(org.getCode(), ups.getHostCode(), ups.getDeviceCode()))
|
|
|
.deleted(0)
|
|
|
+ .source(1)
|
|
|
.status(UpsStatus.UN_KNOW.getStatus())
|
|
|
.build();
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|