|
|
@@ -1,9 +1,11 @@
|
|
|
package com.xunmei.host.video.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.xunmei.common.core.constant.CacheConstants;
|
|
|
@@ -70,72 +72,103 @@ public class IotDvrDiskServiceImpl extends ServiceImpl<IotDvrDiskMapper, IotDvrD
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void updateStatusByDiskDetection(IotDvrHardDiskDetection req,String token) {
|
|
|
+ public void updateStatusByDiskDetection(IotDvrHardDiskDetection req, String token) {
|
|
|
final String equipmentCode = req.getEquipmentCode();
|
|
|
final List<IotDvrDisk> list = lambdaQuery().eq(IotDvrDisk::getHostCode, equipmentCode).eq(IotDvrDisk::getIotToken, token).eq(IotDvrDisk::getDeleted, 0).list();
|
|
|
+ final List<Long> ids = list.stream().map(IotDvrDisk::getId).collect(Collectors.toList());
|
|
|
+ //全部逻辑删除
|
|
|
+ updateDeleteByIds(ids);
|
|
|
final String detailInfo = req.getDetailInfo();
|
|
|
final List<Map> mapList = JSON.parseArray(detailInfo, Map.class);
|
|
|
List<IotDvrDisk> diskArrayList = new ArrayList<>();
|
|
|
for (Map map : mapList) {
|
|
|
- final String index = (String) map.get("diskSerialNum");
|
|
|
+ final String index = (String) map.get("index");
|
|
|
if (ObjectUtil.isNull(index)) {
|
|
|
continue;
|
|
|
}
|
|
|
- final Optional<IotDvrDisk> first = list.stream().filter(disk -> ObjectUtil.equal(disk.getDiskIndex(), String.valueOf(index))).findFirst();
|
|
|
- if (!first.isPresent()) {
|
|
|
- LogUtils.STATUS_INFO_DISKS.info("硬盘检测上报消息处理磁盘状态时未找到对应磁盘,主机code:{},磁盘号:{}", equipmentCode, index);
|
|
|
- continue;
|
|
|
+ IotDvrDisk iotDvrDisk;
|
|
|
+ final Optional<IotDvrDisk> first = list.stream().filter(disk -> ObjectUtil.equal(disk.getDiskIndex(), index)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ iotDvrDisk = first.get();
|
|
|
+ } else {
|
|
|
+ iotDvrDisk = new IotDvrDisk();
|
|
|
+ iotDvrDisk.setCreateTime(LocalDateTime.now());
|
|
|
+ iotDvrDisk.setUpdateTime(LocalDateTime.now());
|
|
|
+ iotDvrDisk.setOrgId(req.getOrgId());
|
|
|
+ iotDvrDisk.setOrgName(req.getOrgName());
|
|
|
+ iotDvrDisk.setOrgPath(req.getOrgPath());
|
|
|
+ iotDvrDisk.setHostCode(req.getEquipmentCode());
|
|
|
+ iotDvrDisk.setIotToken(token);
|
|
|
+ iotDvrDisk.setDiskIndex(index);
|
|
|
+ iotDvrDisk.setSource(1);
|
|
|
}
|
|
|
- final IotDvrDisk iotDvrDisk = first.get();
|
|
|
- iotDvrDisk.setState((Integer) map.get("state"));
|
|
|
- iotDvrDisk.setDiskName((String) map.get("name"));
|
|
|
String totalBytes = String.valueOf(map.get("totalBytes"));
|
|
|
- String availableBytes = String.valueOf(map.get("availableBytes")) ;
|
|
|
+ String availableBytes = String.valueOf(map.get("availableBytes"));
|
|
|
String originState = String.valueOf(map.get("originState"));
|
|
|
- //Integer freeBytes = (Integer) map.get("freeBytes");
|
|
|
-
|
|
|
+ iotDvrDisk.setState((Integer) map.get("state"));
|
|
|
+ iotDvrDisk.setDiskName((String) map.get("name"));
|
|
|
iotDvrDisk.setOriginState(DvrDiskOriginState.getByCodeField(originState));
|
|
|
iotDvrDisk.setAvailable(new BigDecimal(availableBytes).divide(BigDecimal.valueOf(1024 * 1024), 2, RoundingMode.HALF_UP).intValue());
|
|
|
iotDvrDisk.setTotal(new BigDecimal(totalBytes).divide(BigDecimal.valueOf(1024 * 1024), 2, RoundingMode.HALF_UP).intValue());
|
|
|
iotDvrDisk.setStateUpdateTime(req.getCheckTime());
|
|
|
iotDvrDisk.setUpdateTime(LocalDateTime.now());
|
|
|
+ iotDvrDisk.setDeleted(0);
|
|
|
diskArrayList.add(iotDvrDisk);
|
|
|
}
|
|
|
- updateBatchById(diskArrayList);
|
|
|
+ if (CollectionUtil.isNotEmpty(diskArrayList)) {
|
|
|
+ saveOrUpdateBatch(diskArrayList);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 逻辑删除磁盘信息
|
|
|
+ *
|
|
|
* @param token
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public void deleteByToken(String token) {
|
|
|
+ public void deleteByTokenAndHostCode(String token,String hostCode) {
|
|
|
UpdateWrapper<IotDvrDisk> uw = new UpdateWrapper<>();
|
|
|
- uw.lambda().eq(IotDvrDisk::getIotToken,token);
|
|
|
- uw.lambda().set(IotDvrDisk::getDeleted,1);
|
|
|
+ uw.lambda().eq(IotDvrDisk::getIotToken, token);
|
|
|
+ uw.lambda().eq(IotDvrDisk::getHostCode, hostCode);
|
|
|
+ uw.lambda().set(IotDvrDisk::getDeleted, 1);
|
|
|
update(uw);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void updateDeleteByIds(List<Long> ids) {
|
|
|
+ if (ObjectUtil.isEmpty(ids)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ final LambdaUpdateWrapper<IotDvrDisk> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.in(IotDvrDisk::getId, ids);
|
|
|
+ wrapper.set(IotDvrDisk::getDeleted, 1);
|
|
|
+ update(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取磁盘信息
|
|
|
+ *
|
|
|
* @param token
|
|
|
* @param hostCode
|
|
|
* @param diskIndex
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public IotDvrDisk selectByTokenAndDiskIndex(String token, String hostCode,String diskIndex) {
|
|
|
- String key = DVR_DISK_KEY + token + "_"+hostCode + "_" + diskIndex;
|
|
|
- IotDvrDisk info = RedisUtils.getCacheObject(key);
|
|
|
- if(info == null){
|
|
|
+ public IotDvrDisk selectByTokenAndDiskIndex(String token, String hostCode, String diskIndex) {
|
|
|
+ String key = DVR_DISK_KEY + token + "_" + hostCode + "_" + diskIndex;
|
|
|
+ IotDvrDisk info = RedisUtils.getCacheObject(key);
|
|
|
+ if (info == null) {
|
|
|
QueryWrapper<IotDvrDisk> qw = new QueryWrapper<>();
|
|
|
- qw.lambda().eq(IotDvrDisk::getIotToken,token)
|
|
|
- .eq(IotDvrDisk::getHostCode,hostCode)
|
|
|
- .eq(IotDvrDisk::getDiskIndex,diskIndex);
|
|
|
+ qw.lambda().eq(IotDvrDisk::getIotToken, token)
|
|
|
+ .eq(IotDvrDisk::getHostCode, hostCode)
|
|
|
+ .eq(IotDvrDisk::getDeleted, 0)
|
|
|
+ .eq(IotDvrDisk::getDiskIndex, diskIndex);
|
|
|
IotDvrDisk one = getOne(qw);
|
|
|
- if(one != null){
|
|
|
- RedisUtils.setCacheObject(key,one, Duration.ofMillis(1000 * 60 * 60));
|
|
|
+ if (one != null) {
|
|
|
+ RedisUtils.setCacheObject(key, one, Duration.ofMillis(1000 * 60 * 60));
|
|
|
}
|
|
|
return one;
|
|
|
}
|
|
|
@@ -145,11 +178,11 @@ public class IotDvrDiskServiceImpl extends ServiceImpl<IotDvrDiskMapper, IotDvrD
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void updateBatchDisks(List<IotDvrDisk> iotDvrDisks) {
|
|
|
- if(ObjectUtil.isNotEmpty(iotDvrDisks)){
|
|
|
+ if (ObjectUtil.isNotEmpty(iotDvrDisks)) {
|
|
|
updateBatchById(iotDvrDisks);
|
|
|
for (IotDvrDisk iotDvrDisk : iotDvrDisks) {
|
|
|
String key = DVR_DISK_KEY + iotDvrDisk.getIotToken() + "_" + iotDvrDisk.getHostCode() + "_" + iotDvrDisk.getDiskIndex();
|
|
|
- RedisUtils.setCacheObject(key,iotDvrDisk, Duration.ofMillis(1000 * 60 * 60));
|
|
|
+ RedisUtils.setCacheObject(key, iotDvrDisk, Duration.ofMillis(1000 * 60 * 60));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -157,11 +190,11 @@ public class IotDvrDiskServiceImpl extends ServiceImpl<IotDvrDiskMapper, IotDvrD
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void saveBatchDisks(List<IotDvrDisk> iotDvrDisks) {
|
|
|
- if(ObjectUtil.isNotEmpty(iotDvrDisks)){
|
|
|
+ if (ObjectUtil.isNotEmpty(iotDvrDisks)) {
|
|
|
saveBatch(iotDvrDisks);
|
|
|
for (IotDvrDisk iotDvrDisk : iotDvrDisks) {
|
|
|
String key = DVR_DISK_KEY + iotDvrDisk.getIotToken() + "_" + iotDvrDisk.getHostCode() + "_" + iotDvrDisk.getDiskIndex();
|
|
|
- RedisUtils.setCacheObject(key,iotDvrDisk, Duration.ofMillis(1000 * 60 * 60));
|
|
|
+ RedisUtils.setCacheObject(key, iotDvrDisk, Duration.ofMillis(1000 * 60 * 60));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -256,7 +289,7 @@ public class IotDvrDiskServiceImpl extends ServiceImpl<IotDvrDiskMapper, IotDvrD
|
|
|
List<IotDvrDisk> diskList = listMap.get(hostDeviceOptional.get().getEquipmentCode());
|
|
|
List<DvrdiskDto> diskSpaces = pageDto.getDiskSpace();
|
|
|
if (ObjectUtil.isNull(diskList)) {
|
|
|
- diskList=new ArrayList<>();
|
|
|
+ diskList = new ArrayList<>();
|
|
|
}
|
|
|
for (DvrdiskDto dto : diskSpaces) {
|
|
|
List<String> fields = new ArrayList<>();
|