|
|
@@ -1,19 +1,28 @@
|
|
|
package com.xunmei.iot.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.xunmei.common.core.constant.CacheConstants;
|
|
|
+import com.xunmei.common.core.constant.Constants;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseMission;
|
|
|
+import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseMissionCh;
|
|
|
+import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThreshold;
|
|
|
+import com.xunmei.common.core.domain.iot.domain.IotDeviceDiagnoseThresholdCh;
|
|
|
import com.xunmei.common.core.enums.OrgTypeEnum;
|
|
|
+import com.xunmei.common.core.exception.ServiceException;
|
|
|
+import com.xunmei.common.core.utils.IDHelper;
|
|
|
import com.xunmei.common.core.utils.StringUtils;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
import com.xunmei.iot.dto.cameraDiagnose.DiagnoseMissionPageDto;
|
|
|
import com.xunmei.iot.mapper.DiagnoseMissionChMapper;
|
|
|
+import com.xunmei.iot.mapper.DiagnoseThresholdChMapper;
|
|
|
import com.xunmei.iot.service.DiagnoseMissionService;
|
|
|
import com.xunmei.iot.vo.alarmData.AlarmTypeSelectedVO;
|
|
|
+import com.xunmei.iot.vo.sensor.DiagnoseMissionBindVo;
|
|
|
import com.xunmei.iot.vo.sensor.DiagnoseMissionPageVo;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
@@ -32,6 +41,8 @@ public class DiagnoseMissionServiceImpl implements DiagnoseMissionService {
|
|
|
|
|
|
@Autowired
|
|
|
private DiagnoseMissionChMapper diagnoseMissionChMapper;
|
|
|
+ @Autowired
|
|
|
+ private DiagnoseThresholdChMapper diagnoseThresholdChMapper;
|
|
|
|
|
|
@Override
|
|
|
public TableDataInfo<DiagnoseMissionPageVo> selectDiagnoseMissionPage(DiagnoseMissionPageDto request) {
|
|
|
@@ -113,13 +124,66 @@ public class DiagnoseMissionServiceImpl implements DiagnoseMissionService {
|
|
|
request.setOrgId(null);
|
|
|
}
|
|
|
|
|
|
- List<IotDeviceDiagnoseMission> missions = diagnoseMissionChMapper.selectAllDiagnoseMission();
|
|
|
+ Integer camerasCount = diagnoseMissionChMapper.selectCamerasCount(request);
|
|
|
+ if (camerasCount == null || camerasCount == 0) {
|
|
|
+ String errorMsg = "绑定任务查询条件筛选结果为空!";
|
|
|
+ throw new ServiceException(errorMsg);
|
|
|
+ }
|
|
|
|
|
|
- Page<DiagnoseMissionPageVo> page = diagnoseMissionChMapper.selectPageData(request.getPageRequest(), request);
|
|
|
- final List<SysOrgVO> cacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
+ String bindMissionId = request.getBindMissionId();
|
|
|
+ QueryWrapper<IotDeviceDiagnoseThreshold> queryWrapper = new QueryWrapper();
|
|
|
+ queryWrapper.eq("type", 1);
|
|
|
+ queryWrapper.last(Constants.LIMIT1);
|
|
|
+ IotDeviceDiagnoseThreshold system = diagnoseThresholdChMapper.selectOne(queryWrapper);
|
|
|
+ //获取未绑定阈值的通道
|
|
|
+ List<IotDeviceDiagnoseThresholdCh> batchInsertsUnbindThresholdCh = Lists.newArrayList();
|
|
|
+ //获取要绑定的通道
|
|
|
+ List<IotDeviceDiagnoseMissionCh> batchInserts = Lists.newArrayList();
|
|
|
+ List<IotDeviceDiagnoseMissionCh> batchUpdates = Lists.newArrayList();
|
|
|
+
|
|
|
+ List<DiagnoseMissionBindVo> list = diagnoseMissionChMapper.selectCamerasBind(request);
|
|
|
+ for (DiagnoseMissionBindVo info :list) {
|
|
|
+ String beanId = info.getMissionId();
|
|
|
+ IotDeviceDiagnoseMissionCh chn = new IotDeviceDiagnoseMissionCh();
|
|
|
+ chn.setIotToken(info.getIotToken());
|
|
|
+ chn.setDeviceProduct(info.getDeviceProduct());
|
|
|
+ chn.setDvs(info.getDvs());
|
|
|
+ chn.setChannel(info.getChannel());
|
|
|
+ chn.setMissionId(bindMissionId);
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(beanId)) {
|
|
|
+ chn.setId(IDHelper.id());
|
|
|
+ batchInserts.add(chn);
|
|
|
+ } else if (!beanId.equals(bindMissionId)) {
|
|
|
+ batchUpdates.add(chn);
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(info.getThresholdCodes())) {
|
|
|
+ IotDeviceDiagnoseThresholdCh thresholdCh = new IotDeviceDiagnoseThresholdCh();
|
|
|
+ thresholdCh.setThresholdCode(system.getThresholdCode());
|
|
|
+ thresholdCh.setIotToken(info.getIotToken());
|
|
|
+ thresholdCh.setDeviceProduct(info.getDeviceProduct());
|
|
|
+ thresholdCh.setDvs(info.getDvs());
|
|
|
+ thresholdCh.setChannel(info.getChannel());
|
|
|
+ thresholdCh.setId(IDHelper.id());
|
|
|
+ batchInsertsUnbindThresholdCh.add(thresholdCh);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- for (DiagnoseMissionPageVo bean : page.getRecords()) {
|
|
|
+ if (batchInserts != null && !batchInserts.isEmpty()) {
|
|
|
+ diagnoseMissionChMapper.batchInsertMissionCh(batchInserts);
|
|
|
+ }
|
|
|
+ if (batchUpdates != null && !batchUpdates.isEmpty()) {
|
|
|
+ diagnoseMissionChMapper.batchUpdateMissionCh(batchUpdates);
|
|
|
+ }
|
|
|
|
|
|
+ //查询的通道如果未绑定阈值,绑定它们到默认阈值上
|
|
|
+ if (batchInsertsUnbindThresholdCh != null && !batchInsertsUnbindThresholdCh.isEmpty()) {
|
|
|
+ diagnoseMissionChMapper.batchInsertThresholdCh(batchInsertsUnbindThresholdCh);
|
|
|
}
|
|
|
+
|
|
|
+ //更新默认阈值绑定数量
|
|
|
+ Integer cameraBindCount = diagnoseThresholdChMapper.selectBindCount(system.getThresholdCode());
|
|
|
+ system.setDignoseNumber(cameraBindCount);
|
|
|
+ diagnoseThresholdChMapper.updateById(system);
|
|
|
}
|
|
|
}
|