模板数据、设备信息初始化至内存

This commit is contained in:
xy
2024-10-16 18:53:19 +08:00
parent 5169669b2b
commit 78b9a98ab8
11 changed files with 312 additions and 13 deletions

View File

@@ -0,0 +1,28 @@
package com.njcn.csdevice.init;
import com.njcn.csdevice.service.CsDevModelService;
import com.njcn.csdevice.service.CsEquipmentDeliveryService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
/**
* 项目初始化缓存设备池,后续从缓存中获取设备数据
* @author xy
*/
@Slf4j
@Component
@AllArgsConstructor
public class InitData implements CommandLineRunner {
private final CsEquipmentDeliveryService csEquipmentDeliveryService;
private final CsDevModelService csDevModelService;
@Override
public void run(String... args) {
csEquipmentDeliveryService.refreshDeviceDataCache();
csDevModelService.refreshDevModelCache();
}
}

View File

@@ -20,6 +20,12 @@ import com.njcn.csdevice.pojo.vo.CsDevModelPageVO;
*/
public interface CsDevModelService extends IService<CsDevModelPO>{
/**
* 初始化缓存模板信息
* 想缓存模板,发现数据量太大,先按照之前的逻辑处理
*/
void refreshDevModelCache();
/**
* @Description: addDevModel
* @Param: [csDevModelAddParm]

View File

@@ -27,6 +27,11 @@ import java.util.List;
*/
public interface CsEquipmentDeliveryService extends IService<CsEquipmentDeliveryPO>{
/**
* 初始化缓存设备池
*/
void refreshDeviceDataCache();
/**
* @Description: save
* @Param: [csEquipmentDeliveryAddParm]

View File

@@ -50,4 +50,9 @@ public interface ICsDataArrayService extends IService<CsDataArray> {
* @return
*/
List<CsDataArray> findListByParam(DataArrayParam param);
/**
* 根据数据集id获取指标数据
*/
List<CsDataArray> getDataArrayByDataSetIds(List<String> dataSetIds);
}

View File

@@ -64,4 +64,9 @@ public interface ICsDataSetService extends IService<CsDataSet> {
* @return
*/
CsDataSet getDataSetByIdx(String modelId, Integer idx);
/**
* 根据模板id获取所有数据集
*/
List<CsDataSet> getDataSetByModelId(List<String> modelList);
}

View File

@@ -6,6 +6,7 @@ import com.njcn.csdevice.mapper.CsDataArrayMapper;
import com.njcn.csdevice.pojo.dto.DataArrayDTO;
import com.njcn.csdevice.pojo.param.DataArrayParam;
import com.njcn.csdevice.pojo.po.CsDataArray;
import com.njcn.csdevice.pojo.po.CsDataSet;
import com.njcn.csdevice.pojo.vo.DataArrayTreeVO;
import com.njcn.csdevice.pojo.vo.DeviceManagerDetailVO;
import com.njcn.csdevice.service.ICsDataArrayService;
@@ -174,4 +175,11 @@ public class CsDataArrayServiceImpl extends ServiceImpl<CsDataArrayMapper, CsDat
public List<CsDataArray> findListByParam(DataArrayParam param) {
return this.baseMapper.findListByParam(param);
}
@Override
public List<CsDataArray> getDataArrayByDataSetIds(List<String> dataSetIds) {
return this.lambdaQuery()
.in(CsDataArray::getPid,dataSetIds)
.list();
}
}

View File

@@ -9,6 +9,7 @@ import com.njcn.csdevice.service.ICsDataSetService;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -93,4 +94,11 @@ public class CsDataSetServiceImpl extends ServiceImpl<CsDataSetMapper, CsDataSet
.one();
}
@Override
public List<CsDataSet> getDataSetByModelId(List<String> modelList) {
return this.lambdaQuery()
.in(CsDataSet::getPid,modelList)
.list();
}
}

View File

@@ -1,22 +1,37 @@
package com.njcn.csdevice.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.csdevice.mapper.CsDevModelMapper;
import com.njcn.csdevice.pojo.dto.CsDevModelDto;
import com.njcn.csdevice.pojo.param.CsDevModelAddParm;
import com.njcn.csdevice.pojo.param.CsDevModelAuditParm;
import com.njcn.csdevice.pojo.param.CsDevModelQueryListParm;
import com.njcn.csdevice.pojo.param.CsDevModelQueryParm;
import com.njcn.csdevice.pojo.po.CsDataArray;
import com.njcn.csdevice.pojo.po.CsDataSet;
import com.njcn.csdevice.pojo.po.CsDevModelPO;
import com.njcn.csdevice.pojo.vo.CsDevModelPageVO;
import com.njcn.csdevice.service.CsDevModelService;
import com.njcn.csdevice.service.ICsDataArrayService;
import com.njcn.csdevice.service.ICsDataSetService;
import com.njcn.redis.pojo.enums.AppRedisKey;
import com.njcn.redis.utils.RedisUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
*
@@ -27,16 +42,77 @@ import java.sql.Date;
* @author clam
* @version V1.0.0
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class CsDevModelServiceImpl extends ServiceImpl<CsDevModelMapper, CsDevModelPO> implements CsDevModelService{
private final ICsDataSetService csDataSetService;
private final ICsDataArrayService csDataArrayService;
private final RedisUtil redisUtil;
@Override
public void refreshDevModelCache() {
// List<CsDevModelDto> csDevModelDtoList = new ArrayList<>();
// List<CsDevModelDto.CsDataSet> csDataSetList = new ArrayList<>();
// List<CsDevModelDto.CsDataArray> csDataArrayList = new ArrayList<>();
// //获取系统所有模板
// LambdaQueryWrapper<CsDevModelPO> queryWrapper = new LambdaQueryWrapper<>();
// queryWrapper.eq(CsDevModelPO::getStatus,1);
// List<CsDevModelPO> list = this.list(queryWrapper);
// //根据模板ids获取数据集
// if (CollUtil.isNotEmpty(list)) {
// List<String> modelIds = list.stream().map(CsDevModelPO::getId).collect(Collectors.toList());
// List<CsDataSet> csDataSets = csDataSetService.getDataSetByModelId(modelIds);
// //根据数据集获取具体指标
// List<String> dataSetList = csDataSets.stream().map(CsDataSet::getId).collect(Collectors.toList());
// List<CsDataArray> csDataArrays = csDataArrayService.getDataArrayByDataSetIds(dataSetList);
//
// list.forEach(item->{
// CsDevModelDto dto = new CsDevModelDto();
// BeanUtils.copyProperties(item,dto);
// csDevModelDtoList.add(dto);
// });
// csDataSets.forEach(item->{
// CsDevModelDto.CsDataSet dto = new CsDevModelDto.CsDataSet();
// BeanUtils.copyProperties(item,dto);
// csDataSetList.add(dto);
// });
// csDataArrays.forEach(item->{
// CsDevModelDto.CsDataArray dto = new CsDevModelDto.CsDataArray();
// BeanUtils.copyProperties(item,dto);
// csDataArrayList.add(dto);
// });
//
// for (CsDevModelDto.CsDataSet item1 : csDataSetList) {
// List<CsDevModelDto.CsDataArray> list1 = new ArrayList<>();
// for (CsDevModelDto.CsDataArray item2 : csDataArrayList) {
// if (Objects.equals(item1.getId(),item2.getPid())) {
// list1.add(item2);
// }
// }
// item1.setDataArrays(list1);
// }
//
// for (CsDevModelDto item1 : csDevModelDtoList) {
// List<CsDevModelDto.CsDataSet> list1 = new ArrayList<>();
// for (CsDevModelDto.CsDataSet item2 : csDataSetList) {
// if (Objects.equals(item1.getId(),item2.getPid())) {
// list1.add(item2);
// }
// }
// item1.setDataSets(list1);
// redisUtil.saveByKey(AppRedisKey.DEV_MODEL.concat(item1.getId()),item1);
// }
// }
}
@Override
@Transactional(rollbackFor = Exception.class)
public CsDevModelPO addDevModel(CsDevModelAddParm csDevModelAddParm) {
CsDevModelPO csDevModelPO = new CsDevModelPO ();
BeanUtils.copyProperties (csDevModelAddParm, csDevModelPO);
csDevModelPO.setStatus ("1");
csDevModelPO.setVersionDate(Date.valueOf(csDevModelAddParm.getTime()));
this.save (csDevModelPO);
return csDevModelPO;
}
@@ -46,8 +122,7 @@ public class CsDevModelServiceImpl extends ServiceImpl<CsDevModelMapper, CsDevMo
public Boolean AuditDevModel(CsDevModelAuditParm csDevModelAuditParm) {
CsDevModelPO csDevModelPO = new CsDevModelPO ();
BeanUtils.copyProperties (csDevModelAuditParm, csDevModelPO);
boolean b = this.updateById (csDevModelPO);
return b;
return this.updateById (csDevModelPO);
}
@Override
@@ -61,8 +136,7 @@ public class CsDevModelServiceImpl extends ServiceImpl<CsDevModelMapper, CsDevMo
@Override
public CsDevModelPageVO queryDevModelOne(CsDevModelQueryListParm csDevModelQueryListParm) {
CsDevModelPageVO result = this.getBaseMapper ().queryOne(csDevModelQueryListParm);
return result;
return this.getBaseMapper ().queryOne(csDevModelQueryListParm);
}
@Override

View File

@@ -90,9 +90,18 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
private final RedisUtil redisUtil;
private final CsSoftInfoMapper csSoftInfoMapper;
@Override
public void refreshDeviceDataCache() {
LambdaQueryWrapper<CsEquipmentDeliveryPO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.ne(CsEquipmentDeliveryPO::getRunStatus,0);
List<CsEquipmentDeliveryPO> deliveryPOS = this.list(queryWrapper);
redisUtil.saveByKey(AppRedisKey.DEVICE_LIST,deliveryPOS);
}
@Override
@Transactional(rollbackFor = {Exception.class})
public Boolean save(CsEquipmentDeliveryAddParm csEquipmentDeliveryAddParm) {
boolean result;
CsEquipmentDeliveryPO po = this.queryEquipmentPOByndid (csEquipmentDeliveryAddParm.getNdid());
if(!Objects.isNull (po)){
throw new BusinessException (AlgorithmResponseEnum.NDID_ERROR);
@@ -121,7 +130,11 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
csEquipmentProcess.setStatus (1);
csEquipmentProcessPOService.save(csEquipmentProcess);
return this.save (csEquipmentDeliveryPo);
result = this.save (csEquipmentDeliveryPo);
if (result) {
refreshDeviceDataCache();
}
return result;
}
@Override
@@ -161,6 +174,9 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
csDevModelRelationService.lambdaUpdate().eq(CsDevModelRelationPO::getDevId,id).set(CsDevModelRelationPO::getStatus,0).update();
if (update) {
refreshDeviceDataCache();
}
return update;
}
@@ -199,6 +215,7 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
@Override
public Boolean updateEquipmentDelivery(CsEquipmentDeliveryAuditParm csEquipmentDeliveryAuditParm) {
boolean result;
LambdaQueryWrapper<CsEquipmentDeliveryPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(CsEquipmentDeliveryPO::getNdid,csEquipmentDeliveryAuditParm.getNdid())
.in(CsEquipmentDeliveryPO::getStatus,Arrays.asList(1,2,3))
@@ -210,14 +227,22 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
}
CsEquipmentDeliveryPO csEquipmentDeliveryPo = new CsEquipmentDeliveryPO();
BeanUtils.copyProperties (csEquipmentDeliveryAuditParm, csEquipmentDeliveryPo);
return this.updateById (csEquipmentDeliveryPo);
result = this.updateById(csEquipmentDeliveryPo);
if (result) {
refreshDeviceDataCache();
}
return result;
}
@Override
public void updateStatusBynDid(String nDId,Integer status) {
boolean result;
LambdaUpdateWrapper<CsEquipmentDeliveryPO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.set(CsEquipmentDeliveryPO::getStatus,status).eq(CsEquipmentDeliveryPO::getNdid,nDId);
this.update(lambdaUpdateWrapper);
result = this.update(lambdaUpdateWrapper);
if (result) {
refreshDeviceDataCache();
}
}
@Override
@@ -391,9 +416,13 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
@Override
public void updateSoftInfoBynDid(String nDid, String id, Integer module) {
boolean result;
LambdaUpdateWrapper<CsEquipmentDeliveryPO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.set(CsEquipmentDeliveryPO::getSoftinfoId,id).set(CsEquipmentDeliveryPO::getModuleNumber,module).eq(CsEquipmentDeliveryPO::getNdid,nDid);
this.update(lambdaUpdateWrapper);
result = this.update(lambdaUpdateWrapper);
if (result) {
refreshDeviceDataCache();
}
}
@Override
@@ -541,6 +570,7 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
appLineTopologyDiagramPOQueryWrapper.in("line_id",collect);
appLineTopologyDiagramService.remove(appLineTopologyDiagramPOQueryWrapper);
}
refreshDeviceDataCache();
}
@Override
@@ -585,20 +615,28 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
@Override
public void updateSoftInfo(String nDid, String id) {
boolean result;
LambdaUpdateWrapper<CsEquipmentDeliveryPO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.eq(CsEquipmentDeliveryPO::getNdid,nDid)
.ne(CsEquipmentDeliveryPO::getRunStatus,0)
.set(CsEquipmentDeliveryPO::getSoftinfoId,id);
this.update(lambdaUpdateWrapper);
result = this.update(lambdaUpdateWrapper);
if (result) {
refreshDeviceDataCache();
}
}
@Override
public void updateModuleNumber(String nDid, Integer number) {
boolean result;
LambdaUpdateWrapper<CsEquipmentDeliveryPO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.eq(CsEquipmentDeliveryPO::getNdid,nDid)
.ne(CsEquipmentDeliveryPO::getRunStatus,0)
.set(CsEquipmentDeliveryPO::getModuleNumber,number);
this.update(lambdaUpdateWrapper);
result = this.update(lambdaUpdateWrapper);
if (result) {
refreshDeviceDataCache();
}
}
@Override