|
@@ -1,24 +1,18 @@
|
|
|
package com.hfln.portal.infrastructure.gateway.impl;
|
|
|
|
|
|
import cn.hfln.framework.extension.BizException;
|
|
|
-import com.hfln.portal.common.dto.data.event.AlarmPlanDTO;
|
|
|
-import com.hfln.portal.common.dto.data.event.AlarmTimePlanDTO;
|
|
|
-import com.hfln.portal.common.dto.data.event.EventTypeDTO;
|
|
|
-import com.hfln.portal.common.request.event.AlarmPlanDelReq;
|
|
|
-import com.hfln.portal.common.request.event.AlarmPlanEnableReq;
|
|
|
-import com.hfln.portal.common.request.event.AlarmPlanQueryReq;
|
|
|
-import com.hfln.portal.common.request.event.AlarmPlanSaveReq;
|
|
|
+import com.hfln.portal.common.dto.data.event.*;
|
|
|
+import com.hfln.portal.common.request.event.*;
|
|
|
import com.hfln.portal.domain.customer.OprLogType;
|
|
|
import com.hfln.portal.domain.customer.util.CopyUtils;
|
|
|
import com.hfln.portal.domain.exception.ErrorEnum;
|
|
|
import com.hfln.portal.domain.gateway.AlarmGateway;
|
|
|
import com.hfln.portal.infrastructure.mqtt.MqttSend;
|
|
|
import com.hfln.portal.infrastructure.po.AlarmPlan;
|
|
|
+import com.hfln.portal.infrastructure.po.AlarmPlanTpl;
|
|
|
import com.hfln.portal.infrastructure.po.AlarmTimePlan;
|
|
|
-import com.hfln.portal.infrastructure.service.AlarmPlanService;
|
|
|
-import com.hfln.portal.infrastructure.service.AlarmTimePlanService;
|
|
|
-import com.hfln.portal.infrastructure.service.EventTypeService;
|
|
|
-import com.hfln.portal.infrastructure.service.TblOprLogService;
|
|
|
+import com.hfln.portal.infrastructure.po.AlarmTimePlanTpl;
|
|
|
+import com.hfln.portal.infrastructure.service.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -26,6 +20,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
@@ -41,6 +36,12 @@ public class AlarmGatewayImpl implements AlarmGateway {
|
|
|
private AlarmTimePlanService alarmTimePlanService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private AlarmPlanTplService alarmPlanTplService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AlarmTimePlanTplService alarmTimePlanTplService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private TblOprLogService logService;
|
|
|
|
|
|
@Autowired
|
|
@@ -81,6 +82,8 @@ public class AlarmGatewayImpl implements AlarmGateway {
|
|
|
}
|
|
|
}
|
|
|
BeanUtils.copyProperties(req, alarmPlan);
|
|
|
+ alarmPlan.setUpdateTime(LocalDateTime.now());
|
|
|
+ alarmPlan.setCreateTime(LocalDateTime.now());
|
|
|
alarmPlanService.saveOrUpdate(alarmPlan);
|
|
|
|
|
|
AlarmTimePlan alarmTimePlan = new AlarmTimePlan();
|
|
@@ -131,6 +134,7 @@ public class AlarmGatewayImpl implements AlarmGateway {
|
|
|
throw new BizException(ErrorEnum.ALARM_PLAN_NOT_EXIST.getErrorCode(), ErrorEnum.ALARM_PLAN_NOT_EXIST.getErrorMessage());
|
|
|
}
|
|
|
alarmPlan.setEnable(req.getEnable());
|
|
|
+ alarmPlan.setUpdateTime(LocalDateTime.now());
|
|
|
alarmPlanService.updateById(alarmPlan);
|
|
|
|
|
|
mqttSend.sendAlarmPlanToLas(alarmPlan.getUuid(), "update");
|
|
@@ -142,4 +146,88 @@ public class AlarmGatewayImpl implements AlarmGateway {
|
|
|
|
|
|
return CopyUtils.copyList(eventTypeService.list(), EventTypeDTO.class);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AlarmPlanTplDTO> queryPlanTpl(AlarmPlanTplQueryReq req) {
|
|
|
+
|
|
|
+ List<AlarmPlanTpl> list = alarmPlanTplService.queryPlan(req);
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<AlarmPlanTplDTO> resList = new ArrayList<>();
|
|
|
+ for (AlarmPlanTpl alarmPlanTpl : list) {
|
|
|
+ AlarmPlanTplDTO copy = CopyUtils.copy(alarmPlanTpl, AlarmPlanTplDTO.class);
|
|
|
+ if (alarmPlanTpl.getAlarmTimePlanTplId() != null) {
|
|
|
+ AlarmTimePlanTpl byId = alarmTimePlanTplService.getById(copy.getAlarmTimePlanTplId());
|
|
|
+ copy.setAlarmTimePlanTpl(CopyUtils.copy(byId, AlarmTimePlanTplDTO.class));
|
|
|
+ resList.add(copy);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public AlarmPlanTplDTO savePlanTpl(AlarmPlanTplSaveReq req) {
|
|
|
+
|
|
|
+ AlarmPlanTpl alarmPlanTpl = new AlarmPlanTpl();
|
|
|
+ if (req.getId() != null) {
|
|
|
+ alarmPlanTpl = alarmPlanTplService.getById(req.getId());
|
|
|
+ if (alarmPlanTpl == null) {
|
|
|
+ throw new BizException(ErrorEnum.ALARM_PLAN_TPL_NOT_EXIST.getErrorCode(), ErrorEnum.ALARM_PLAN_TPL_NOT_EXIST.getErrorMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(req, alarmPlanTpl);
|
|
|
+ alarmPlanTpl.setCreateTime(LocalDateTime.now());
|
|
|
+ alarmPlanTpl.setUpdateTime(LocalDateTime.now());
|
|
|
+ alarmPlanTplService.saveOrUpdate(alarmPlanTpl);
|
|
|
+
|
|
|
+ AlarmTimePlanTpl alarmTimePlanTpl = new AlarmTimePlanTpl();
|
|
|
+ if (req.getAlarmTimePlanTplId() != null) {
|
|
|
+ alarmTimePlanTpl = alarmTimePlanTplService.getById(req.getAlarmTimePlanTplId());
|
|
|
+ if (alarmTimePlanTpl == null) {
|
|
|
+ throw new BizException(ErrorEnum.ALARM_TIME_NOT_EXIST.getErrorCode(), ErrorEnum.ALARM_TIME_NOT_EXIST.getErrorMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(req.getAlarmTimePlanTpl(), alarmTimePlanTpl);
|
|
|
+ alarmTimePlanTplService.saveOrUpdate(alarmTimePlanTpl);
|
|
|
+
|
|
|
+ alarmPlanTpl.setAlarmTimePlanTplId(alarmTimePlanTpl.getId());
|
|
|
+ alarmPlanTplService.updateById(alarmPlanTpl);
|
|
|
+
|
|
|
+ AlarmPlanTplDTO copy = CopyUtils.copy(alarmPlanTpl, AlarmPlanTplDTO.class);
|
|
|
+ copy.setAlarmTimePlanTpl(CopyUtils.copy(alarmTimePlanTpl, AlarmTimePlanTplDTO.class));
|
|
|
+ return copy;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void delPlanTpl(AlarmPlanTplDelReq req) {
|
|
|
+
|
|
|
+ AlarmPlanTpl alarmPlanTpl = alarmPlanTplService.getById(req.getId());
|
|
|
+ if (alarmPlanTpl == null) {
|
|
|
+ throw new BizException(ErrorEnum.ALARM_PLAN_TPL_NOT_EXIST.getErrorCode(), ErrorEnum.ALARM_PLAN_TPL_NOT_EXIST.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ AlarmTimePlanTpl alarmTimePlanTpl = alarmTimePlanTplService.getById(alarmPlanTpl.getAlarmTimePlanTplId());
|
|
|
+
|
|
|
+ alarmPlanTplService.delById(req.getId());
|
|
|
+ alarmTimePlanTplService.delById(alarmTimePlanTpl.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void enablePlanTpl(AlarmPlanTplEnableReq req) {
|
|
|
+
|
|
|
+ AlarmPlanTpl alarmPlanTpl = alarmPlanTplService.getById(req.getId());
|
|
|
+ if (alarmPlanTpl == null) {
|
|
|
+ throw new BizException(ErrorEnum.ALARM_PLAN_TPL_NOT_EXIST.getErrorCode(), ErrorEnum.ALARM_PLAN_TPL_NOT_EXIST.getErrorMessage());
|
|
|
+ }
|
|
|
+ alarmPlanTpl.setEnable(req.getEnable());
|
|
|
+ alarmPlanTpl.setUpdateTime(LocalDateTime.now());
|
|
|
+ alarmPlanTplService.updateById(alarmPlanTpl);
|
|
|
+
|
|
|
+ log.info("告警计划alarmPlanId:{}, set enable = {}", req.getId(), req.getEnable());
|
|
|
+ }
|
|
|
}
|