|
@@ -31,6 +31,8 @@ import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmconfig.Delete
|
|
|
import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmconfig.QueryAlarmConfigDTO;
|
|
|
import com.persagy.apm.energyalarmstarter.alarmdata.model.vo.AlarmConfigItem;
|
|
|
import com.persagy.apm.energyalarmstarter.alarmdata.service.AlarmConfigServiceImpl;
|
|
|
+import com.persagy.apm.mybatis.handler.DynamicDataSourceHandler;
|
|
|
+
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.DataFormatter;
|
|
@@ -54,6 +56,8 @@ import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
/**
|
|
|
* 集团报警规则(GroupAlarmRule) service层
|
|
|
*
|
|
@@ -63,55 +67,55 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class GroupAlarmRuleServiceImpl extends ServiceImpl<GroupAlarmRuleMapper, GroupAlarmRule>
|
|
|
- implements IGroupAlarmRuleService {
|
|
|
- @Autowired
|
|
|
- private IAlarmConditionService alarmConditionService;
|
|
|
- @Autowired
|
|
|
- private IProjectAlarmRuleService projectAlarmRuleService;
|
|
|
- @Autowired
|
|
|
- private AlarmConfigServiceImpl alarmConfigService;
|
|
|
- @Autowired
|
|
|
- private GroupManagementServiceImpl groupManagementService;
|
|
|
- @Autowired
|
|
|
- private IProjectAlarmRuleObjRelService projectAlarmRuleObjRelService;
|
|
|
-
|
|
|
- ExecutorService executor = ExecutorBuilder.create()
|
|
|
- .setCorePoolSize(5)
|
|
|
- .setMaxPoolSize(10)
|
|
|
- .setHandler(new ThreadPoolExecutor.CallerRunsPolicy())
|
|
|
- .build();
|
|
|
-
|
|
|
- /**
|
|
|
- * 创建集团报警规则
|
|
|
- *
|
|
|
- * @return 集团报警规则主键
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-09-08 22:35:45
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public String createGroupAlarmRule(AddGroupAlarmRuleDTO addGroupAlarmRuleDTO) throws Exception {
|
|
|
- //1、给某个设备分组创建集团报警
|
|
|
- GroupAlarmRule groupAlarmRule = ConvertGroupAlarmRuleTool.INSTANCE.convertAddDto2Entity(addGroupAlarmRuleDTO);
|
|
|
- AddAlarmConditionDTO alarmCondition = addGroupAlarmRuleDTO.getAlarmCondition();
|
|
|
- Map<String, Object> conditionMap = alarmConditionService.createAlarmCondition(alarmCondition);
|
|
|
- //创建集团报警
|
|
|
- groupAlarmRule.setAlarmConditionId((String) conditionMap.get("id"));
|
|
|
- setDefaultValue(groupAlarmRule);
|
|
|
- save(groupAlarmRule);
|
|
|
- //2、异步创建项目报警
|
|
|
- String userId = PoemsContext.getContext().getUserId();
|
|
|
- String groupCode = PoemsContext.getContext().getGroupCode();
|
|
|
- String projectId = PoemsContext.getContext().getProjectId();
|
|
|
- String pd = PoemsContext.getContext().getPd();
|
|
|
- String loginDevice = PoemsContext.getContext().getLoginDevice();
|
|
|
- executor.execute(() -> {
|
|
|
- // 切换线程需要重新设置线程中的通用变量
|
|
|
- PoemsContext.setContext(userId, loginDevice, pd, groupCode, projectId);
|
|
|
- projectAlarmRuleService.addProjectAlarmRules(addGroupAlarmRuleDTO);
|
|
|
- });
|
|
|
-
|
|
|
- // 勿删,后续有可能恢复 lixing
|
|
|
+ implements IGroupAlarmRuleService {
|
|
|
+ @Autowired
|
|
|
+ private IAlarmConditionService alarmConditionService;
|
|
|
+ @Autowired
|
|
|
+ private IProjectAlarmRuleService projectAlarmRuleService;
|
|
|
+ @Autowired
|
|
|
+ private AlarmConfigServiceImpl alarmConfigService;
|
|
|
+ @Autowired
|
|
|
+ private GroupManagementServiceImpl groupManagementService;
|
|
|
+ @Autowired
|
|
|
+ private IProjectAlarmRuleObjRelService projectAlarmRuleObjRelService;
|
|
|
+ @Autowired
|
|
|
+ private DynamicDataSourceHandler dataSourceHandler;
|
|
|
+
|
|
|
+ ExecutorService executor = ExecutorBuilder.create().setCorePoolSize(5).setMaxPoolSize(10)
|
|
|
+ .setHandler(new ThreadPoolExecutor.CallerRunsPolicy()).build();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建集团报警规则
|
|
|
+ *
|
|
|
+ * @return 集团报警规则主键
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:35:45
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String createGroupAlarmRule(AddGroupAlarmRuleDTO addGroupAlarmRuleDTO, String requestUri) throws Exception {
|
|
|
+ // 1、给某个设备分组创建集团报警
|
|
|
+ GroupAlarmRule groupAlarmRule = ConvertGroupAlarmRuleTool.INSTANCE.convertAddDto2Entity(addGroupAlarmRuleDTO);
|
|
|
+ AddAlarmConditionDTO alarmCondition = addGroupAlarmRuleDTO.getAlarmCondition();
|
|
|
+ Map<String, Object> conditionMap = alarmConditionService.createAlarmCondition(alarmCondition);
|
|
|
+ // 创建集团报警
|
|
|
+ groupAlarmRule.setAlarmConditionId((String) conditionMap.get("id"));
|
|
|
+ setDefaultValue(groupAlarmRule);
|
|
|
+ save(groupAlarmRule);
|
|
|
+ // 2、异步创建项目报警
|
|
|
+ String userId = PoemsContext.getContext().getUserId();
|
|
|
+ String groupCode = PoemsContext.getContext().getGroupCode();
|
|
|
+ String projectId = PoemsContext.getContext().getProjectId();
|
|
|
+ String pd = PoemsContext.getContext().getPd();
|
|
|
+ String loginDevice = PoemsContext.getContext().getLoginDevice();
|
|
|
+ executor.execute(() -> {
|
|
|
+ // 切换线程需要重新设置线程中的通用变量
|
|
|
+ PoemsContext.setContext(userId, loginDevice, pd, groupCode, projectId);
|
|
|
+ dataSourceHandler.resetDataSource(requestUri);
|
|
|
+ projectAlarmRuleService.addProjectAlarmRules(addGroupAlarmRuleDTO);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 勿删,后续有可能恢复 lixing
|
|
|
// List<ProjectVO> projects = projectAlarmRuleService.getProject();
|
|
|
// if (projects.size() == 0) {
|
|
|
// throw new Exception("获取项目为空");
|
|
@@ -163,60 +167,61 @@ public class GroupAlarmRuleServiceImpl extends ServiceImpl<GroupAlarmRuleMapper,
|
|
|
// }
|
|
|
// projectAlarmRuleService.sendBatchCreateAlarmConfigMsg(alarmConfigs, projectId);
|
|
|
// }
|
|
|
- return groupAlarmRule.getId();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 如果某些字段没有赋值,使用默认的值
|
|
|
- *
|
|
|
- * @param groupAlarmRule 集团报警规则实体
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021/3/12 12:29 下午
|
|
|
- */
|
|
|
- private void setDefaultValue(GroupAlarmRule groupAlarmRule) {
|
|
|
- groupAlarmRule.setCreator(PoemsContext.getContext().getUserId());
|
|
|
- groupAlarmRule.setTs(new Timestamp(System.currentTimeMillis()));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 集团报警规则详情
|
|
|
- *
|
|
|
- * @param id 主键
|
|
|
- * @return 部门do类
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-09-08 22:35:45
|
|
|
- */
|
|
|
- @Override
|
|
|
- public GroupAlarmRule queryGroupAlarmRuleDetail(String id) {
|
|
|
- GroupAlarmRule groupAlarmRule = getById(id);
|
|
|
- if (groupAlarmRule == null) {
|
|
|
- throw new IllegalArgumentException("查看GroupAlarmRule详情时发生异常,找不到要查看的记录,id=" + id);
|
|
|
- }
|
|
|
- return groupAlarmRule;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 更新集团报警规则
|
|
|
- *
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-09-08 22:35:45
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void updateGroupAlarmRule(UpdateGroupAlarmRuleDTO updateGroupAlarmRuleDTO) throws Exception {
|
|
|
- GroupAlarmRule groupAlarmRule = getById(updateGroupAlarmRuleDTO.getId());
|
|
|
- if (groupAlarmRule == null) {
|
|
|
- throw new IllegalArgumentException("找不到要更新的数据");
|
|
|
- }
|
|
|
- groupAlarmRule = ConvertGroupAlarmRuleTool.INSTANCE.convertUpdateDto2Entity(groupAlarmRule, updateGroupAlarmRuleDTO);
|
|
|
- groupAlarmRule.setModifier(AppContext.getContext().getAccountId());
|
|
|
- updateById(groupAlarmRule);
|
|
|
- //获得报警规则
|
|
|
- UpdateAlarmConditionDTO alarmCondition = updateGroupAlarmRuleDTO.getAlarmCondition();
|
|
|
- alarmConditionService.updateAlarmCondition(alarmCondition);
|
|
|
+ return groupAlarmRule.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 如果某些字段没有赋值,使用默认的值
|
|
|
+ *
|
|
|
+ * @param groupAlarmRule 集团报警规则实体
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/3/12 12:29 下午
|
|
|
+ */
|
|
|
+ private void setDefaultValue(GroupAlarmRule groupAlarmRule) {
|
|
|
+ groupAlarmRule.setCreator(PoemsContext.getContext().getUserId());
|
|
|
+ groupAlarmRule.setTs(new Timestamp(System.currentTimeMillis()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 集团报警规则详情
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 部门do类
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:35:45
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public GroupAlarmRule queryGroupAlarmRuleDetail(String id) {
|
|
|
+ GroupAlarmRule groupAlarmRule = getById(id);
|
|
|
+ if (groupAlarmRule == null) {
|
|
|
+ throw new IllegalArgumentException("查看GroupAlarmRule详情时发生异常,找不到要查看的记录,id=" + id);
|
|
|
+ }
|
|
|
+ return groupAlarmRule;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新集团报警规则
|
|
|
+ *
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:35:45
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void updateGroupAlarmRule(UpdateGroupAlarmRuleDTO updateGroupAlarmRuleDTO) throws Exception {
|
|
|
+ GroupAlarmRule groupAlarmRule = getById(updateGroupAlarmRuleDTO.getId());
|
|
|
+ if (groupAlarmRule == null) {
|
|
|
+ throw new IllegalArgumentException("找不到要更新的数据");
|
|
|
+ }
|
|
|
+ groupAlarmRule = ConvertGroupAlarmRuleTool.INSTANCE.convertUpdateDto2Entity(groupAlarmRule,
|
|
|
+ updateGroupAlarmRuleDTO);
|
|
|
+ groupAlarmRule.setModifier(AppContext.getContext().getAccountId());
|
|
|
+ updateById(groupAlarmRule);
|
|
|
+ // 获得报警规则
|
|
|
+ UpdateAlarmConditionDTO alarmCondition = updateGroupAlarmRuleDTO.getAlarmCondition();
|
|
|
+ alarmConditionService.updateAlarmCondition(alarmCondition);
|
|
|
// Map<String, Object> conditionMap = alarmConditionService.frontend2Backend(alarmCondition.getFrontend());
|
|
|
// alarmConditionService.updateAlarmCondition(conditionMap, alarmCondition);
|
|
|
- // 勿删,后续可能启用 lixing
|
|
|
+ // 勿删,后续可能启用 lixing
|
|
|
// //删除中台设备的报警条件
|
|
|
// String condition = updateGroupAlarmRuleDTO.getCondition();
|
|
|
// String classCode = updateGroupAlarmRuleDTO.getClassCode();
|
|
@@ -271,252 +276,254 @@ public class GroupAlarmRuleServiceImpl extends ServiceImpl<GroupAlarmRuleMapper,
|
|
|
//
|
|
|
// projectAlarmRuleService.sendBatchCreateAlarmConfigMsg(alarmConfigs, projectId);
|
|
|
// }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 校验集团报警规则是否可删除
|
|
|
- *
|
|
|
- * @param id 集团报警规则主键
|
|
|
- * @return 集团报警规则do类
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-09-08 22:35:45
|
|
|
- */
|
|
|
- public GroupAlarmRule checkDeletable(String id) {
|
|
|
- if (id == null) {
|
|
|
- throw new IllegalArgumentException("删除GroupAlarmRule时发生异常,主键为空");
|
|
|
- }
|
|
|
-
|
|
|
- GroupAlarmRule groupAlarmRule = getById(id);
|
|
|
-
|
|
|
- if (groupAlarmRule == null) {
|
|
|
- throw new IllegalArgumentException("删除GroupAlarmRule时发生异常,找不到要删除的数据,id:" + id);
|
|
|
- }
|
|
|
-
|
|
|
- return groupAlarmRule;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除集团报警规则
|
|
|
- *
|
|
|
- * @param id 主键
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-09-08 22:35:45
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void deleteGroupAlarmRule(String id) {
|
|
|
- // 校验是否可删除
|
|
|
- GroupAlarmRule groupAlarmRule = checkDeletable(id);
|
|
|
- groupAlarmRule.setValid(ValidEnum.FALSE.getType());
|
|
|
- updateById(groupAlarmRule);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询集团报警规则
|
|
|
- *
|
|
|
- * @return List<GroupAlarmRule>
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-09-08 22:35:45
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<GroupAlarmRule> queryGroupAlarmRuleList(QueryGroupAlarmRuleDTO queryGroupAlarmRuleDTO) {
|
|
|
- QueryWrapper<GroupAlarmRule> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq(GroupAlarmRule.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
- // 默认按创建时间倒序排序
|
|
|
- queryWrapper.orderBy(true, false, GroupAlarmRule.PROP_CREATIONTIME);
|
|
|
-
|
|
|
- if (queryGroupAlarmRuleDTO != null) {
|
|
|
-
|
|
|
- // todo 需判断使用like还是eq
|
|
|
- if (StringUtils.isNotEmpty(queryGroupAlarmRuleDTO.getGroupId())) {
|
|
|
- queryWrapper.like(GroupAlarmRule.PROP_GROUP_ID, queryGroupAlarmRuleDTO.getGroupId());
|
|
|
- }
|
|
|
-
|
|
|
- // todo 需判断使用like还是eq
|
|
|
- if (StringUtils.isNotEmpty(queryGroupAlarmRuleDTO.getAlarmItemName())) {
|
|
|
- queryWrapper.like(GroupAlarmRule.PROP_ALARM_ITEM_NAME, queryGroupAlarmRuleDTO.getAlarmItemName());
|
|
|
- }
|
|
|
- }
|
|
|
- return list(queryWrapper);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 分页查询集团报警规则
|
|
|
- *
|
|
|
- * @return IPage<GroupAlarmRule>
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-09-08 22:35:45
|
|
|
- */
|
|
|
- @Override
|
|
|
- public IPage<GroupAlarmRule> pageQueryGroupAlarmRule(PageQueryGroupAlarmRuleDTO pageQueryGroupAlarmRuleDTO) {
|
|
|
- QueryWrapper<GroupAlarmRule> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq(GroupAlarmRule.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
- // 这里认为pageQueryDTO是经过校验的,肯定包含分页信息
|
|
|
- IPage<GroupAlarmRule> pageParam = new Page<>(pageQueryGroupAlarmRuleDTO.getPage(), pageQueryGroupAlarmRuleDTO.getSize(), true);
|
|
|
- // 排序信息
|
|
|
- if (CollectionUtils.isEmpty(pageQueryGroupAlarmRuleDTO.getOrders())) {
|
|
|
- // 默认按创建时间倒序排序
|
|
|
- queryWrapper.orderBy(true, false, GroupAlarmRule.PROP_CREATIONTIME);
|
|
|
- } else {
|
|
|
- List<Sort> orders = pageQueryGroupAlarmRuleDTO.getOrders();
|
|
|
- for (Sort sort : orders) {
|
|
|
- // 将驼峰转换为下划线格式
|
|
|
- sort.setColumn(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, sort.getColumn()));
|
|
|
- queryWrapper.orderBy(true, sort.isAsc(), sort.getColumn());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // todo 需判断使用like还是eq
|
|
|
- if (StringUtils.isNotEmpty(pageQueryGroupAlarmRuleDTO.getGroupId())) {
|
|
|
- queryWrapper.eq(GroupAlarmRule.PROP_GROUP_ID, pageQueryGroupAlarmRuleDTO.getGroupId());
|
|
|
- }
|
|
|
-
|
|
|
- // todo 需判断使用like还是eq
|
|
|
- if (StringUtils.isNotEmpty(pageQueryGroupAlarmRuleDTO.getAlarmItemName())) {
|
|
|
- queryWrapper.like(GroupAlarmRule.PROP_ALARM_ITEM_NAME, pageQueryGroupAlarmRuleDTO.getAlarmItemName());
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验集团报警规则是否可删除
|
|
|
+ *
|
|
|
+ * @param id 集团报警规则主键
|
|
|
+ * @return 集团报警规则do类
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:35:45
|
|
|
+ */
|
|
|
+ public GroupAlarmRule checkDeletable(String id) {
|
|
|
+ if (id == null) {
|
|
|
+ throw new IllegalArgumentException("删除GroupAlarmRule时发生异常,主键为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ GroupAlarmRule groupAlarmRule = getById(id);
|
|
|
+
|
|
|
+ if (groupAlarmRule == null) {
|
|
|
+ throw new IllegalArgumentException("删除GroupAlarmRule时发生异常,找不到要删除的数据,id:" + id);
|
|
|
+ }
|
|
|
+
|
|
|
+ return groupAlarmRule;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除集团报警规则
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:35:45
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void deleteGroupAlarmRule(String id) {
|
|
|
+ // 校验是否可删除
|
|
|
+ GroupAlarmRule groupAlarmRule = checkDeletable(id);
|
|
|
+ groupAlarmRule.setValid(ValidEnum.FALSE.getType());
|
|
|
+ updateById(groupAlarmRule);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询集团报警规则
|
|
|
+ *
|
|
|
+ * @return List<GroupAlarmRule>
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:35:45
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<GroupAlarmRule> queryGroupAlarmRuleList(QueryGroupAlarmRuleDTO queryGroupAlarmRuleDTO) {
|
|
|
+ QueryWrapper<GroupAlarmRule> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(GroupAlarmRule.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
+ // 默认按创建时间倒序排序
|
|
|
+ queryWrapper.orderBy(true, false, GroupAlarmRule.PROP_CREATIONTIME);
|
|
|
+
|
|
|
+ if (queryGroupAlarmRuleDTO != null) {
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(queryGroupAlarmRuleDTO.getGroupId())) {
|
|
|
+ queryWrapper.like(GroupAlarmRule.PROP_GROUP_ID, queryGroupAlarmRuleDTO.getGroupId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(queryGroupAlarmRuleDTO.getAlarmItemName())) {
|
|
|
+ queryWrapper.like(GroupAlarmRule.PROP_ALARM_ITEM_NAME, queryGroupAlarmRuleDTO.getAlarmItemName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询集团报警规则
|
|
|
+ *
|
|
|
+ * @return IPage<GroupAlarmRule>
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:35:45
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<GroupAlarmRule> pageQueryGroupAlarmRule(PageQueryGroupAlarmRuleDTO pageQueryGroupAlarmRuleDTO) {
|
|
|
+ QueryWrapper<GroupAlarmRule> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(GroupAlarmRule.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
+ // 这里认为pageQueryDTO是经过校验的,肯定包含分页信息
|
|
|
+ IPage<GroupAlarmRule> pageParam = new Page<>(pageQueryGroupAlarmRuleDTO.getPage(),
|
|
|
+ pageQueryGroupAlarmRuleDTO.getSize(), true);
|
|
|
+ // 排序信息
|
|
|
+ if (CollectionUtils.isEmpty(pageQueryGroupAlarmRuleDTO.getOrders())) {
|
|
|
+ // 默认按创建时间倒序排序
|
|
|
+ queryWrapper.orderBy(true, false, GroupAlarmRule.PROP_CREATIONTIME);
|
|
|
+ } else {
|
|
|
+ List<Sort> orders = pageQueryGroupAlarmRuleDTO.getOrders();
|
|
|
+ for (Sort sort : orders) {
|
|
|
+ // 将驼峰转换为下划线格式
|
|
|
+ sort.setColumn(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, sort.getColumn()));
|
|
|
+ queryWrapper.orderBy(true, sort.isAsc(), sort.getColumn());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryGroupAlarmRuleDTO.getGroupId())) {
|
|
|
+ queryWrapper.eq(GroupAlarmRule.PROP_GROUP_ID, pageQueryGroupAlarmRuleDTO.getGroupId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryGroupAlarmRuleDTO.getAlarmItemName())) {
|
|
|
+ queryWrapper.like(GroupAlarmRule.PROP_ALARM_ITEM_NAME, pageQueryGroupAlarmRuleDTO.getAlarmItemName());
|
|
|
+ }
|
|
|
|
|
|
// // todo 需判断使用like还是eq
|
|
|
// if (StringUtils.isNotEmpty(pageQueryGroupAlarmRuleDTO.getAlarmConditionId())) {
|
|
|
// queryWrapper.like(GroupAlarmRule.PROP_ALARM_CONDITION_ID, pageQueryGroupAlarmRuleDTO.getAlarmConditionId());
|
|
|
// }
|
|
|
|
|
|
- return getBaseMapper().selectPage(pageParam, queryWrapper);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void delete(DeleteGroupAlarmRuleDTO deleteGroupAlarmRuleDTO) throws Exception {
|
|
|
- String groupRuleId = deleteGroupAlarmRuleDTO.getId();
|
|
|
- GroupAlarmRule groupAlarmRule = getById(groupRuleId);
|
|
|
- this.deleteGroupAlarmRule(groupRuleId);
|
|
|
- alarmConditionService.deleteAlarmCondition(deleteGroupAlarmRuleDTO.getAlarmConditionId());
|
|
|
- // 异步删除项目上的报警规则
|
|
|
- PoemsContextContent context = PoemsContext.getContext();
|
|
|
- executor.execute(() -> {
|
|
|
- PoemsContext.setContext(context);
|
|
|
- try {
|
|
|
- projectAlarmRuleService.deleteBatchByGroupRule(groupAlarmRule);
|
|
|
- String condition = deleteGroupAlarmRuleDTO.getCondition();
|
|
|
- String classCode = deleteGroupAlarmRuleDTO.getClassCode();
|
|
|
- deleteEquipCondition(condition, classCode, groupAlarmRule.getAlarmItemCode());
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("删除项目报警规则失败", e);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void deleteEquipCondition(String condition,String classCode, String alarmItemCode) throws Exception {
|
|
|
- //删除设备报警条件 begin
|
|
|
- BatchDeleteAlarmConfigDTO batchDeleteAlarmConfigDTO = new BatchDeleteAlarmConfigDTO();
|
|
|
- List<DeleteAlarmConfigDTO> alarmConfigs = new ArrayList<>();
|
|
|
- //查询所有设备
|
|
|
- List<EquipItem> equips = this.getAllEquip(classCode, condition);
|
|
|
- List<String> objIds = equips.stream().map(EquipItem::getId).collect(Collectors.toList());
|
|
|
- QueryAlarmConfigDTO queryAlarmConfigDTO = new QueryAlarmConfigDTO();
|
|
|
- queryAlarmConfigDTO.setObjId(objIds);
|
|
|
- queryAlarmConfigDTO.setItemCode(Lists.newArrayList(alarmItemCode));
|
|
|
- DmpResult<List<AlarmConfigItem>> query = alarmConfigService.query(queryAlarmConfigDTO);
|
|
|
- //所有设备条件
|
|
|
- List<AlarmConfigItem> data = query.getData();
|
|
|
- //组织删除参数
|
|
|
- if (data.size() > 0) {
|
|
|
- data.forEach(alarmConfigItem -> {
|
|
|
- DeleteAlarmConfigDTO deleteAlarmConfigDTO = new DeleteAlarmConfigDTO();
|
|
|
- deleteAlarmConfigDTO.setId(alarmConfigItem.getId());
|
|
|
- alarmConfigs.add(deleteAlarmConfigDTO);
|
|
|
- });
|
|
|
- batchDeleteAlarmConfigDTO.setAlarmConfigs(alarmConfigs);
|
|
|
- alarmConfigService.batchDelete(batchDeleteAlarmConfigDTO);
|
|
|
- }
|
|
|
- //删除设备报警条件 end
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void readExcel() throws IOException {
|
|
|
- InputStream in = GroupAlarmRuleServiceImpl.class.getResourceAsStream(File.separator + "json" + File.separator + "Project.xlsx");
|
|
|
- XSSFWorkbook sheets = new XSSFWorkbook(in);
|
|
|
- Sheet sheet = sheets.getSheet("慧云3.0及3.1版本清单");
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- for (int i = 1; i < sheet.getPhysicalNumberOfRows() - 1; i++) {
|
|
|
- Row row = sheet.getRow(i);
|
|
|
- DataFormatter dataFormatter = new DataFormatter();
|
|
|
- String s = dataFormatter.formatCellValue(row.getCell(1));
|
|
|
- String id = dataFormatter.formatCellValue(row.getCell(0));
|
|
|
- sb.append("(");
|
|
|
- sb.append("'"+id+"',");
|
|
|
- sb.append("'"+s+"',");
|
|
|
- sb.append("'"+row.getCell(3)+"',");
|
|
|
- sb.append("'WD'");
|
|
|
- sb.append("),");
|
|
|
- }
|
|
|
- String substring = sb.substring(0, sb.length() - 1);
|
|
|
- projectAlarmRuleService.insertProject(substring);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public GroupAlarmRule getGroupAlarmRule(GetGroupAlarmRuleDTO getGroupAlarmRuleDTO) {
|
|
|
- QueryWrapper<GroupAlarmRule> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq(GroupAlarmRule.PROP_GROUP_ID, getGroupAlarmRuleDTO.getGroupId());
|
|
|
- queryWrapper.eq(GroupAlarmRule.PROP_ALARM_ITEM_CODE, getGroupAlarmRuleDTO.getAlarmItemCode());
|
|
|
- queryWrapper.eq(GroupAlarmRule.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
- return getOne(queryWrapper);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<EquipItem> getAllEquip(String classCode, String condition){
|
|
|
- //查询所有项目
|
|
|
- List<ProjectVO> projects = projectAlarmRuleService.getProject();
|
|
|
- List<EquipItem> records = new ArrayList<>();
|
|
|
- for (ProjectVO project : projects) {
|
|
|
- QueryEquipDTO queryEquipDTO = new QueryEquipDTO();
|
|
|
- queryEquipDTO.setClassCode(classCode);
|
|
|
- queryEquipDTO.setCondition(condition);
|
|
|
- List<EquipItem> record = groupManagementService.getEquipList(queryEquipDTO);
|
|
|
- records.addAll(record);
|
|
|
- }
|
|
|
- return records;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<GroupAlarmRule> getExistAlarmItem(String groupId) {
|
|
|
- QueryWrapper<GroupAlarmRule> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq(GroupAlarmRule.PROP_GROUP_ID, groupId);
|
|
|
- queryWrapper.eq(GroupAlarmRule.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
- return list(queryWrapper);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 创建集团报警规则
|
|
|
- *
|
|
|
- * @return 集团报警规则主键
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-09-08 22:35:45
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public String createGroupAlarmRulePM(AddGroupAlarmRuleDTO addGroupAlarmRuleDTO) throws Exception {
|
|
|
- //1、给某个设备分组创建集团报警
|
|
|
- GroupAlarmRule groupAlarmRule = ConvertGroupAlarmRuleTool.INSTANCE.convertAddDto2Entity(addGroupAlarmRuleDTO);
|
|
|
- AddAlarmConditionDTO alarmCondition = addGroupAlarmRuleDTO.getAlarmCondition();
|
|
|
- Map<String, Object> conditionMap = alarmConditionService.createAlarmCondition(alarmCondition);
|
|
|
- //创建集团报警
|
|
|
- groupAlarmRule.setAlarmConditionId((String) conditionMap.get("id"));
|
|
|
- setDefaultValue(groupAlarmRule);
|
|
|
- save(groupAlarmRule);
|
|
|
- //2、异步创建项目报警
|
|
|
- String userId = PoemsContext.getContext().getUserId();
|
|
|
- String groupCode = PoemsContext.getContext().getGroupCode();
|
|
|
- String projectId = PoemsContext.getContext().getProjectId();
|
|
|
- String pd = PoemsContext.getContext().getPd();
|
|
|
- String loginDevice = PoemsContext.getContext().getLoginDevice();
|
|
|
- executor.execute(() -> {
|
|
|
- // 切换线程需要重新设置线程中的通用变量
|
|
|
- PoemsContext.setContext(userId, loginDevice, pd, groupCode, projectId);
|
|
|
- projectAlarmRuleService.addProjectAlarmRulesPM(addGroupAlarmRuleDTO);
|
|
|
- });
|
|
|
-
|
|
|
- // 勿删,后续有可能恢复 lixing
|
|
|
+ return getBaseMapper().selectPage(pageParam, queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void delete(DeleteGroupAlarmRuleDTO deleteGroupAlarmRuleDTO) throws Exception {
|
|
|
+ String groupRuleId = deleteGroupAlarmRuleDTO.getId();
|
|
|
+ GroupAlarmRule groupAlarmRule = getById(groupRuleId);
|
|
|
+ this.deleteGroupAlarmRule(groupRuleId);
|
|
|
+ alarmConditionService.deleteAlarmCondition(deleteGroupAlarmRuleDTO.getAlarmConditionId());
|
|
|
+ // 异步删除项目上的报警规则
|
|
|
+ PoemsContextContent context = PoemsContext.getContext();
|
|
|
+ executor.execute(() -> {
|
|
|
+ PoemsContext.setContext(context);
|
|
|
+ try {
|
|
|
+ projectAlarmRuleService.deleteBatchByGroupRule(groupAlarmRule);
|
|
|
+ String condition = deleteGroupAlarmRuleDTO.getCondition();
|
|
|
+ String classCode = deleteGroupAlarmRuleDTO.getClassCode();
|
|
|
+ deleteEquipCondition(condition, classCode, groupAlarmRule.getAlarmItemCode());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("删除项目报警规则失败", e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteEquipCondition(String condition, String classCode, String alarmItemCode) throws Exception {
|
|
|
+ // 删除设备报警条件 begin
|
|
|
+ BatchDeleteAlarmConfigDTO batchDeleteAlarmConfigDTO = new BatchDeleteAlarmConfigDTO();
|
|
|
+ List<DeleteAlarmConfigDTO> alarmConfigs = new ArrayList<>();
|
|
|
+ // 查询所有设备
|
|
|
+ List<EquipItem> equips = this.getAllEquip(classCode, condition);
|
|
|
+ List<String> objIds = equips.stream().map(EquipItem::getId).collect(Collectors.toList());
|
|
|
+ QueryAlarmConfigDTO queryAlarmConfigDTO = new QueryAlarmConfigDTO();
|
|
|
+ queryAlarmConfigDTO.setObjId(objIds);
|
|
|
+ queryAlarmConfigDTO.setItemCode(Lists.newArrayList(alarmItemCode));
|
|
|
+ DmpResult<List<AlarmConfigItem>> query = alarmConfigService.query(queryAlarmConfigDTO);
|
|
|
+ // 所有设备条件
|
|
|
+ List<AlarmConfigItem> data = query.getData();
|
|
|
+ // 组织删除参数
|
|
|
+ if (data.size() > 0) {
|
|
|
+ data.forEach(alarmConfigItem -> {
|
|
|
+ DeleteAlarmConfigDTO deleteAlarmConfigDTO = new DeleteAlarmConfigDTO();
|
|
|
+ deleteAlarmConfigDTO.setId(alarmConfigItem.getId());
|
|
|
+ alarmConfigs.add(deleteAlarmConfigDTO);
|
|
|
+ });
|
|
|
+ batchDeleteAlarmConfigDTO.setAlarmConfigs(alarmConfigs);
|
|
|
+ alarmConfigService.batchDelete(batchDeleteAlarmConfigDTO);
|
|
|
+ }
|
|
|
+ // 删除设备报警条件 end
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void readExcel() throws IOException {
|
|
|
+ InputStream in = GroupAlarmRuleServiceImpl.class
|
|
|
+ .getResourceAsStream(File.separator + "json" + File.separator + "Project.xlsx");
|
|
|
+ XSSFWorkbook sheets = new XSSFWorkbook(in);
|
|
|
+ Sheet sheet = sheets.getSheet("慧云3.0及3.1版本清单");
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ for (int i = 1; i < sheet.getPhysicalNumberOfRows() - 1; i++) {
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ DataFormatter dataFormatter = new DataFormatter();
|
|
|
+ String s = dataFormatter.formatCellValue(row.getCell(1));
|
|
|
+ String id = dataFormatter.formatCellValue(row.getCell(0));
|
|
|
+ sb.append("(");
|
|
|
+ sb.append("'" + id + "',");
|
|
|
+ sb.append("'" + s + "',");
|
|
|
+ sb.append("'" + row.getCell(3) + "',");
|
|
|
+ sb.append("'WD'");
|
|
|
+ sb.append("),");
|
|
|
+ }
|
|
|
+ String substring = sb.substring(0, sb.length() - 1);
|
|
|
+ projectAlarmRuleService.insertProject(substring);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GroupAlarmRule getGroupAlarmRule(GetGroupAlarmRuleDTO getGroupAlarmRuleDTO) {
|
|
|
+ QueryWrapper<GroupAlarmRule> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(GroupAlarmRule.PROP_GROUP_ID, getGroupAlarmRuleDTO.getGroupId());
|
|
|
+ queryWrapper.eq(GroupAlarmRule.PROP_ALARM_ITEM_CODE, getGroupAlarmRuleDTO.getAlarmItemCode());
|
|
|
+ queryWrapper.eq(GroupAlarmRule.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
+ return getOne(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<EquipItem> getAllEquip(String classCode, String condition) {
|
|
|
+ // 查询所有项目
|
|
|
+ List<ProjectVO> projects = projectAlarmRuleService.getProject();
|
|
|
+ List<EquipItem> records = new ArrayList<>();
|
|
|
+ for (ProjectVO project : projects) {
|
|
|
+ QueryEquipDTO queryEquipDTO = new QueryEquipDTO();
|
|
|
+ queryEquipDTO.setClassCode(classCode);
|
|
|
+ queryEquipDTO.setCondition(condition);
|
|
|
+ List<EquipItem> record = groupManagementService.getEquipList(queryEquipDTO);
|
|
|
+ records.addAll(record);
|
|
|
+ }
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<GroupAlarmRule> getExistAlarmItem(String groupId) {
|
|
|
+ QueryWrapper<GroupAlarmRule> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(GroupAlarmRule.PROP_GROUP_ID, groupId);
|
|
|
+ queryWrapper.eq(GroupAlarmRule.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
+ return list(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建集团报警规则
|
|
|
+ *
|
|
|
+ * @return 集团报警规则主键
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:35:45
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String createGroupAlarmRulePM(AddGroupAlarmRuleDTO addGroupAlarmRuleDTO) throws Exception {
|
|
|
+ // 1、给某个设备分组创建集团报警
|
|
|
+ GroupAlarmRule groupAlarmRule = ConvertGroupAlarmRuleTool.INSTANCE.convertAddDto2Entity(addGroupAlarmRuleDTO);
|
|
|
+ AddAlarmConditionDTO alarmCondition = addGroupAlarmRuleDTO.getAlarmCondition();
|
|
|
+ Map<String, Object> conditionMap = alarmConditionService.createAlarmCondition(alarmCondition);
|
|
|
+ // 创建集团报警
|
|
|
+ groupAlarmRule.setAlarmConditionId((String) conditionMap.get("id"));
|
|
|
+ setDefaultValue(groupAlarmRule);
|
|
|
+ save(groupAlarmRule);
|
|
|
+ // 2、异步创建项目报警
|
|
|
+ String userId = PoemsContext.getContext().getUserId();
|
|
|
+ String groupCode = PoemsContext.getContext().getGroupCode();
|
|
|
+ String projectId = PoemsContext.getContext().getProjectId();
|
|
|
+ String pd = PoemsContext.getContext().getPd();
|
|
|
+ String loginDevice = PoemsContext.getContext().getLoginDevice();
|
|
|
+ executor.execute(() -> {
|
|
|
+ // 切换线程需要重新设置线程中的通用变量
|
|
|
+ PoemsContext.setContext(userId, loginDevice, pd, groupCode, projectId);
|
|
|
+ projectAlarmRuleService.addProjectAlarmRulesPM(addGroupAlarmRuleDTO);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 勿删,后续有可能恢复 lixing
|
|
|
// List<ProjectVO> projects = projectAlarmRuleService.getProject();
|
|
|
// if (projects.size() == 0) {
|
|
|
// throw new Exception("获取项目为空");
|
|
@@ -568,7 +575,7 @@ public class GroupAlarmRuleServiceImpl extends ServiceImpl<GroupAlarmRuleMapper,
|
|
|
// }
|
|
|
// projectAlarmRuleService.sendBatchCreateAlarmConfigMsg(alarmConfigs, projectId);
|
|
|
// }
|
|
|
- return groupAlarmRule.getId();
|
|
|
- }
|
|
|
+ return groupAlarmRule.getId();
|
|
|
+ }
|
|
|
|
|
|
}
|