|
@@ -572,6 +572,64 @@ public class ScadaServiceImpl implements ScadaService {
|
|
|
|
|
|
@Override
|
|
|
public List<DeviceArchiveManageVo> getAppData(DeviceQuery deviceQuery) {
|
|
|
+ QueryWrapper<DeviceArchiveManage> queryWrapper = getQueryWrapper(deviceQuery);
|
|
|
+ List<DeviceArchiveManage> deviceArchiveManages = deviceArchiveManageMapper.pageList(queryWrapper);
|
|
|
+ if (CollectionUtils.isEmpty(deviceArchiveManages)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<DeviceArchiveManageVo> manageVos = deviceArchiveManages.stream().map(deviceArchiveManage -> {
|
|
|
+ DeviceArchiveManageVo vo = new DeviceArchiveManageVo();
|
|
|
+ BeanUtils.copyProperties(deviceArchiveManage, vo);
|
|
|
+
|
|
|
+ getAllocation(vo);
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return manageVos;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 获取关联指标
|
|
|
+ * @param vo
|
|
|
+ */
|
|
|
+ private void getAllocation(DeviceArchiveManageVo vo) {
|
|
|
+ QueryWrapper<Allocation> allocationQueryWrapper = new QueryWrapper<>();
|
|
|
+ allocationQueryWrapper.eq("DEVICE_ID", vo.getId());
|
|
|
+ List<Allocation> allocations = allocationMapper.selectList(allocationQueryWrapper);
|
|
|
+ if (!CollectionUtils.isEmpty(allocations)) {
|
|
|
+ List<AllocationVo> allocationVos = allocations.stream().map(allocation -> {
|
|
|
+ AllocationVo allocationVo = new AllocationVo();
|
|
|
+ BeanUtils.copyProperties(allocation, allocationVo);
|
|
|
+
|
|
|
+ List<Scada> dataByCode = scadaMapper.getListDataByCode(allocation.getVariableCode());
|
|
|
+ if (!CollectionUtils.isEmpty(dataByCode)) {
|
|
|
+ allocationVo.setScada(dataByCode.get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Long> reportIdSets = getReportIdSets(Collections.singletonList(allocation));
|
|
|
+ if (!CollectionUtils.isEmpty(reportIdSets)) {
|
|
|
+ logger.info("获取指标报警相关....");
|
|
|
+ QueryWrapper<ScadaReport> scadaReportQueryWrapper = new QueryWrapper<>();
|
|
|
+ scadaReportQueryWrapper.in("ID", reportIdSets);
|
|
|
+ List<ScadaReport> scadaReports = reportMapper.selectList(scadaReportQueryWrapper);
|
|
|
+ if (!CollectionUtils.isEmpty(scadaReports)){
|
|
|
+ allocationVo.setScadaReports(scadaReports);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return allocationVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ vo.setAllocations(allocationVos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 设置查询条件
|
|
|
+ * @param deviceQuery
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private QueryWrapper<DeviceArchiveManage> getQueryWrapper(DeviceQuery deviceQuery) {
|
|
|
QueryWrapper<DeviceArchiveManage> queryWrapper = new QueryWrapper<>();
|
|
|
if (!ObjectUtils.isEmpty(deviceQuery)) {
|
|
|
if (StringUtils.hasText(deviceQuery.getType())) {
|
|
@@ -581,52 +639,53 @@ public class ScadaServiceImpl implements ScadaService {
|
|
|
queryWrapper.eq("manage.STATUS", deviceQuery.getStatus());
|
|
|
}
|
|
|
if (StringUtils.hasText(deviceQuery.getQuery())) {
|
|
|
- queryWrapper.like("manage.ADDRESS", deviceQuery.getQuery());
|
|
|
+ queryWrapper.and(q->{
|
|
|
+ q.like("manage.ADDRESS", deviceQuery.getQuery())
|
|
|
+ .or().like("manage.NAME", deviceQuery.getQuery())
|
|
|
+ .or().like("manage.DESCRIBE", deviceQuery.getQuery());
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
if (StringUtils.hasText(deviceQuery.getCode())){
|
|
|
- queryWrapper.like("allocation.VARIABLE_CODE",deviceQuery.getCode());
|
|
|
+ queryWrapper.like("allocation.VARIABLE_CODE", deviceQuery.getCode());
|
|
|
}
|
|
|
if (deviceQuery.getDeviceId()!=null){
|
|
|
- queryWrapper.eq("manage.ID",deviceQuery.getDeviceId());
|
|
|
+ queryWrapper.eq("manage.ID", deviceQuery.getDeviceId());
|
|
|
}
|
|
|
if (deviceQuery.getLatitude()!=null && deviceQuery.getLongitude()!=null){
|
|
|
queryWrapper.eq("manage.LATITUDE", deviceQuery.getLatitude())
|
|
|
- .eq("manage.LONGITUDE",deviceQuery.getLongitude());
|
|
|
+ .eq("manage.LONGITUDE", deviceQuery.getLongitude());
|
|
|
}
|
|
|
}
|
|
|
- List<DeviceArchiveManage> deviceArchiveManages = deviceArchiveManageMapper.pageList(queryWrapper);
|
|
|
- if (CollectionUtils.isEmpty(deviceArchiveManages)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- List<DeviceArchiveManageVo> manageVos = deviceArchiveManages.stream().map(deviceArchiveManage -> {
|
|
|
- DeviceArchiveManageVo vo = new DeviceArchiveManageVo();
|
|
|
- BeanUtils.copyProperties(deviceArchiveManage, vo);
|
|
|
-
|
|
|
- QueryWrapper<Allocation> allocationQueryWrapper = new QueryWrapper<>();
|
|
|
- allocationQueryWrapper.eq("DEVICE_ID", vo.getId());
|
|
|
- List<Allocation> allocations = allocationMapper.selectList(allocationQueryWrapper);
|
|
|
- if (!CollectionUtils.isEmpty(allocations)) {
|
|
|
- List<AllocationVo> allocationVos = allocations.stream().map(allocation -> {
|
|
|
- AllocationVo allocationVo = new AllocationVo();
|
|
|
- BeanUtils.copyProperties(allocation, allocationVo);
|
|
|
-
|
|
|
- List<Scada> dataByCode = scadaMapper.getListDataByCode(allocation.getVariableCode());
|
|
|
- if (!CollectionUtils.isEmpty(dataByCode)) {
|
|
|
- allocationVo.setScada(dataByCode.get(0));
|
|
|
- }
|
|
|
- return allocationVo;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- vo.setAllocations(allocationVos);
|
|
|
- }
|
|
|
-
|
|
|
- return vo;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- return manageVos;
|
|
|
+ return queryWrapper;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
- public void insertData(Long scadaId) {
|
|
|
- Scada scada = scadaMapper.selectById(scadaId);
|
|
|
+ public void insertData(Scada scada) {
|
|
|
+ syncSave(scada);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Async
|
|
|
+ public void syncSave(Scada data){
|
|
|
+ if (ObjectUtils.isEmpty(data)){
|
|
|
+ throw new RuntimeException("参数为为空");
|
|
|
+ }
|
|
|
+ Scada scada = null;
|
|
|
+ if (data.getId()!=null){
|
|
|
+ scada = scadaMapper.selectById(data.getId());
|
|
|
+ }else if (StringUtils.hasText(data.getCode())){
|
|
|
+ Page<Scada> page = new Page<>(1,1);
|
|
|
+ QueryWrapper<Scada> scadaQueryWrapper = new QueryWrapper<>();
|
|
|
+ scadaQueryWrapper.eq("CODE",data.getCode())
|
|
|
+ .orderByDesc("SCADA_TIME");
|
|
|
+ Page<Scada> scadas = scadaMapper.selectPage(page,scadaQueryWrapper);
|
|
|
+ List<Scada> records = scadas.getRecords();
|
|
|
+ if (!CollectionUtils.isEmpty(records)){
|
|
|
+ scada = records.get(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
log.info("获取到同步scada信息数据:-----{}-----", scada.toString());
|
|
|
if (!ObjectUtils.isEmpty(scada)) {
|
|
|
|
|
@@ -642,10 +701,8 @@ public class ScadaServiceImpl implements ScadaService {
|
|
|
|
|
|
if (CollectionUtils.isEmpty(scadaMapper.selectHistoryById(tableName,scada.getId()))){
|
|
|
log.info("scada数据不存在月份表中,正在执行新增数据");
|
|
|
- List<Scada> scadas = new ArrayList<>();
|
|
|
- scadas.add(scada);
|
|
|
- scadaMapper.insertMouth(scadas, tableName);
|
|
|
- log.info("新增数据成功:-----{}-----", scadas);
|
|
|
+ scadaMapper.insertByOne(scada, tableName);
|
|
|
+ log.info("新增数据成功:-----{}-----", scada);
|
|
|
}
|
|
|
|
|
|
sendNotice(scada);
|
|
@@ -683,6 +740,7 @@ public class ScadaServiceImpl implements ScadaService {
|
|
|
messagepush.setMessage(createMsg(scadaReport.getMsgTemplate(),scadaReport));
|
|
|
messagepush.setType("8");
|
|
|
messagepush.setTableName("SCADA_HISTORY");
|
|
|
+ messagepush.setCreateTime(scada.getScadaTime());
|
|
|
sendTidingsUtil.sendMsg(messagepush, scadaReport.getLiaisonPeople());
|
|
|
logger.info("发送报警消息:{}", messagepush);
|
|
|
}
|