|
|
@@ -6,7 +6,10 @@ import com.google.common.collect.Lists;
|
|
|
import com.xunmei.common.core.constant.CacheConstants;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
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;
|
|
|
@@ -14,12 +17,14 @@ import com.xunmei.iot.dto.cameraDiagnose.DiagnoseThresholdPageDto;
|
|
|
import com.xunmei.iot.mapper.DiagnoseThresholdChMapper;
|
|
|
import com.xunmei.iot.service.DiagnoseThresholdService;
|
|
|
import com.xunmei.iot.vo.alarmData.AlarmTypeSelectedVO;
|
|
|
+import com.xunmei.iot.vo.sensor.DiagnoseThresholdBindVo;
|
|
|
import com.xunmei.iot.vo.sensor.DiagnoseThresholdPageVo;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
import com.xunmei.system.api.vo.SysOrgVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
@@ -85,6 +90,105 @@ public class DiagnoseThresholdServiceImpl implements DiagnoseThresholdService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void camerasBind(DiagnoseThresholdPageDto req) {
|
|
|
+ final SysOrg sysOrg = orgService.selectOrgById(req.getOrgId(), SecurityConstants.INNER);
|
|
|
+ if (ObjectUtil.equal(Boolean.TRUE, req.getCheckSub())) {
|
|
|
+ req.setOrgPath(sysOrg.getPath());
|
|
|
+ req.setOrgId(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer camerasCount = diagnoseThresholdChMapper.selectCamerasCount(req);
|
|
|
+ if (camerasCount == null || camerasCount == 0) {
|
|
|
+ String errorMsg = "绑定阈值查询条件筛选结果为空!";
|
|
|
+ throw new ServiceException(errorMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<DiagnoseThresholdBindVo> list = diagnoseThresholdChMapper.selectCamerasBind(req);
|
|
|
+ //获取要绑定的通道
|
|
|
+ List<IotDeviceDiagnoseThresholdCh> batchInserts = Lists.newArrayList();
|
|
|
+
|
|
|
+ List<String> bindThresholdCodes = req.getBindThresholdCodes();
|
|
|
+ if (bindThresholdCodes != null && !bindThresholdCodes.isEmpty()) {
|
|
|
+ for (String bindThresholdCode:bindThresholdCodes) {
|
|
|
+ for (DiagnoseThresholdBindVo info : list) {
|
|
|
+ String beanThresholdCodes = info.getThresholdCodes();
|
|
|
+ //避免重复绑定
|
|
|
+ if (StringUtils.isNotEmpty(beanThresholdCodes)
|
|
|
+ &&beanThresholdCodes.contains(bindThresholdCode)) {continue;}
|
|
|
+
|
|
|
+ IotDeviceDiagnoseThresholdCh ch = new IotDeviceDiagnoseThresholdCh();
|
|
|
+ //1.生成绑定数据
|
|
|
+ ch.setIotToken(info.getIotToken());
|
|
|
+ ch.setDeviceProduct(info.getDeviceProduct());
|
|
|
+ ch.setDvs(info.getDvs());
|
|
|
+ ch.setChannel(info.getChannel());
|
|
|
+ ch.setThresholdCode(bindThresholdCode);
|
|
|
+ ch.setId(IDHelper.id());
|
|
|
+ batchInserts.add(ch);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (batchInserts != null && !batchInserts.isEmpty()) {
|
|
|
+ diagnoseThresholdChMapper.batchInsertThresholdCh(batchInserts);
|
|
|
+ }
|
|
|
+ //获取涉及阈值配置,并修改设备数量
|
|
|
+ for (String bindThresholdCode:bindThresholdCodes) {
|
|
|
+ diagnoseThresholdChMapper.updateDignoseNumber(bindThresholdCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void camerasUnbind(DiagnoseThresholdPageDto req){
|
|
|
+ final SysOrg sysOrg = orgService.selectOrgById(req.getOrgId(), SecurityConstants.INNER);
|
|
|
+ if (ObjectUtil.equal(Boolean.TRUE, req.getCheckSub())) {
|
|
|
+ req.setOrgPath(sysOrg.getPath());
|
|
|
+ req.setOrgId(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer camerasCount = diagnoseThresholdChMapper.selectCamerasCount(req);
|
|
|
+ if (camerasCount == null || camerasCount == 0) {
|
|
|
+ String errorMsg = "解绑阈值查询条件筛选结果为空!";
|
|
|
+ throw new ServiceException(errorMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<DiagnoseThresholdBindVo> list = diagnoseThresholdChMapper.selectCamerasBind(req);
|
|
|
+
|
|
|
+ //需要解除绑定的id集合
|
|
|
+ List<Long> unbindIds = Lists.newArrayList();
|
|
|
+
|
|
|
+ List<String> unbindThresholdCodes = req.getBindThresholdCodes();
|
|
|
+ if (unbindThresholdCodes != null && !unbindThresholdCodes.isEmpty()) {
|
|
|
+ for (String unbindThresholdCode:unbindThresholdCodes) {
|
|
|
+ for (DiagnoseThresholdBindVo info : list) {
|
|
|
+ String beanThresholdCodes = info.getThresholdCodes();
|
|
|
+ //通道是否有绑定阈值
|
|
|
+ if(StringUtils.isNotEmpty(beanThresholdCodes)) {
|
|
|
+ String[] beanThresholdCodeArr = beanThresholdCodes.split(",");
|
|
|
+ //通道绑定的阈值是否与将要解绑的一致,一致就解绑
|
|
|
+ for (String beanThresholdCode : beanThresholdCodeArr) {
|
|
|
+ if (beanThresholdCode.contains(unbindThresholdCode)) {
|
|
|
+ String id = beanThresholdCode.split("#")[1];
|
|
|
+ unbindIds.add(Long.parseLong(id));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (unbindIds != null && !unbindIds.isEmpty()) {
|
|
|
+ diagnoseThresholdChMapper.batchDeleteThresholdCh(unbindIds);
|
|
|
+ }
|
|
|
+ //获取涉及阈值配置,并修改设备数量
|
|
|
+ for (String bindThresholdCode:unbindThresholdCodes) {
|
|
|
+ diagnoseThresholdChMapper.updateDignoseNumber(bindThresholdCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
public List<AlarmTypeSelectedVO> thresholdTypeList() {
|
|
|
List<AlarmTypeSelectedVO> list = Lists.newArrayList();
|
|
|
AlarmTypeSelectedVO bean;
|