|
@@ -0,0 +1,217 @@
|
|
|
+package com.persagy.apm.service.impl;
|
|
|
+
|
|
|
+import com.persagy.apm.common.context.AppContext;
|
|
|
+import com.persagy.apm.dao.ProjectAlarmRuleObjRelMapper;
|
|
|
+import com.persagy.apm.service.IProjectAlarmRuleObjRelService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import com.persagy.apm.common.constant.enums.ValidEnum;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.persagy.apm.model.*;
|
|
|
+import com.persagy.apm.model.dto.*;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.google.common.base.CaseFormat;
|
|
|
+import com.persagy.apm.common.model.dto.Sort;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 项目报警规则与监测对象的关联(ProjectAlarmRuleObjRel) service层
|
|
|
+ *
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-07 18:12:08
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ProjectAlarmRuleObjRelServiceImpl extends ServiceImpl<ProjectAlarmRuleObjRelMapper, ProjectAlarmRuleObjRel>
|
|
|
+ implements IProjectAlarmRuleObjRelService {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建项目报警规则与监测对象的关联
|
|
|
+ *
|
|
|
+ * @return 项目报警规则与监测对象的关联主键
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-07 18:12:08
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String createProjectAlarmRuleObjRel(AddProjectAlarmRuleObjRelDTO addProjectAlarmRuleObjRelDTO) {
|
|
|
+ ProjectAlarmRuleObjRel projectAlarmRuleObjRel = ConvertProjectAlarmRuleObjRelTool.INSTANCE.convertAddDto2Entity(addProjectAlarmRuleObjRelDTO);
|
|
|
+ // 设置默认值
|
|
|
+ setDefaultValue(projectAlarmRuleObjRel);
|
|
|
+ save(projectAlarmRuleObjRel);
|
|
|
+ return projectAlarmRuleObjRel.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 如果某些字段没有赋值,使用默认的值
|
|
|
+ *
|
|
|
+ * @param projectAlarmRuleObjRel 项目报警规则与监测对象的关联实体
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/3/12 12:29 下午
|
|
|
+ */
|
|
|
+ private void setDefaultValue(ProjectAlarmRuleObjRel projectAlarmRuleObjRel) {
|
|
|
+ projectAlarmRuleObjRel.setCreator(AppContext.getContext().getAccountId());
|
|
|
+ // todo 其他默认的属性
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 项目报警规则与监测对象的关联详情
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 部门do类
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-07 18:12:08
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ProjectAlarmRuleObjRel queryProjectAlarmRuleObjRelDetail(String id) {
|
|
|
+ ProjectAlarmRuleObjRel projectAlarmRuleObjRel = getById(id);
|
|
|
+ if (projectAlarmRuleObjRel == null) {
|
|
|
+ throw new IllegalArgumentException("查看ProjectAlarmRuleObjRel详情时发生异常,找不到要查看的记录,id=" + id);
|
|
|
+ }
|
|
|
+ return projectAlarmRuleObjRel;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新项目报警规则与监测对象的关联
|
|
|
+ *
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-07 18:12:08
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void updateProjectAlarmRuleObjRel(UpdateProjectAlarmRuleObjRelDTO updateProjectAlarmRuleObjRelDTO) {
|
|
|
+ ProjectAlarmRuleObjRel projectAlarmRuleObjRel = getById(updateProjectAlarmRuleObjRelDTO.getId());
|
|
|
+ projectAlarmRuleObjRel = ConvertProjectAlarmRuleObjRelTool.INSTANCE.convertUpdateDto2Entity(projectAlarmRuleObjRel, updateProjectAlarmRuleObjRelDTO);
|
|
|
+ projectAlarmRuleObjRel.setModifier(AppContext.getContext().getAccountId());
|
|
|
+ updateById(projectAlarmRuleObjRel);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验项目报警规则与监测对象的关联是否可删除
|
|
|
+ *
|
|
|
+ * @param id 项目报警规则与监测对象的关联主键
|
|
|
+ * @return 项目报警规则与监测对象的关联do类
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-07 18:12:08
|
|
|
+ */
|
|
|
+ public ProjectAlarmRuleObjRel checkDeletable(String id) {
|
|
|
+ if (id == null) {
|
|
|
+ throw new IllegalArgumentException("删除ProjectAlarmRuleObjRel时发生异常,主键为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ ProjectAlarmRuleObjRel projectAlarmRuleObjRel = getById(id);
|
|
|
+
|
|
|
+ if (projectAlarmRuleObjRel == null) {
|
|
|
+ throw new IllegalArgumentException("删除ProjectAlarmRuleObjRel时发生异常,找不到要删除的数据,id:" + id);
|
|
|
+ }
|
|
|
+
|
|
|
+ return projectAlarmRuleObjRel;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除项目报警规则与监测对象的关联
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-07 18:12:08
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void deleteProjectAlarmRuleObjRel(String id) {
|
|
|
+ // 校验是否可删除
|
|
|
+ ProjectAlarmRuleObjRel projectAlarmRuleObjRel = checkDeletable(id);
|
|
|
+
|
|
|
+ projectAlarmRuleObjRel.setValid(ValidEnum.FALSE.getType());
|
|
|
+ updateById(projectAlarmRuleObjRel);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询项目报警规则与监测对象的关联
|
|
|
+ *
|
|
|
+ * @return List<ProjectAlarmRuleObjRel>
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-07 18:12:08
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ProjectAlarmRuleObjRel> queryProjectAlarmRuleObjRelList(QueryProjectAlarmRuleObjRelDTO queryProjectAlarmRuleObjRelDTO) {
|
|
|
+ QueryWrapper<ProjectAlarmRuleObjRel> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(ProjectAlarmRuleObjRel.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
+ // 默认按创建时间倒序排序
|
|
|
+ queryWrapper.orderBy(true, false, ProjectAlarmRuleObjRel.PROP_CREATIONTIME);
|
|
|
+
|
|
|
+ if (queryProjectAlarmRuleObjRelDTO != null) {
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(queryProjectAlarmRuleObjRelDTO.getProjectAlarmRuleId())) {
|
|
|
+ queryWrapper.like(ProjectAlarmRuleObjRel.PROP_PROJECT_ALARM_RULE_ID, queryProjectAlarmRuleObjRelDTO.getProjectAlarmRuleId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(queryProjectAlarmRuleObjRelDTO.getEquipId())) {
|
|
|
+ queryWrapper.like(ProjectAlarmRuleObjRel.PROP_EQUIP_ID, queryProjectAlarmRuleObjRelDTO.getEquipId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (queryProjectAlarmRuleObjRelDTO.getOpen() != null) {
|
|
|
+ queryWrapper.eq(ProjectAlarmRuleObjRel.PROP_OPEN, queryProjectAlarmRuleObjRelDTO.getOpen());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(queryProjectAlarmRuleObjRelDTO.getProjectId())) {
|
|
|
+ queryWrapper.like(ProjectAlarmRuleObjRel.PROP_PROJECT_ID, queryProjectAlarmRuleObjRelDTO.getProjectId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return list(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询项目报警规则与监测对象的关联
|
|
|
+ *
|
|
|
+ * @return IPage<ProjectAlarmRuleObjRel>
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-07 18:12:08
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<ProjectAlarmRuleObjRel> pageQueryProjectAlarmRuleObjRel(PageQueryProjectAlarmRuleObjRelDTO pageQueryProjectAlarmRuleObjRelDTO) {
|
|
|
+ QueryWrapper<ProjectAlarmRuleObjRel> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(ProjectAlarmRuleObjRel.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
+ // 这里认为pageQueryDTO是经过校验的,肯定包含分页信息
|
|
|
+ IPage<ProjectAlarmRuleObjRel> pageParam = new Page<>(pageQueryProjectAlarmRuleObjRelDTO.getPage(), pageQueryProjectAlarmRuleObjRelDTO.getSize(), true);
|
|
|
+ // 排序信息
|
|
|
+ if (CollectionUtils.isEmpty(pageQueryProjectAlarmRuleObjRelDTO.getOrders())) {
|
|
|
+ // 默认按创建时间倒序排序
|
|
|
+ queryWrapper.orderBy(true, false, ProjectAlarmRuleObjRel.PROP_CREATIONTIME);
|
|
|
+ } else {
|
|
|
+ List<Sort> orders = pageQueryProjectAlarmRuleObjRelDTO.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(pageQueryProjectAlarmRuleObjRelDTO.getProjectAlarmRuleId())) {
|
|
|
+ queryWrapper.like(ProjectAlarmRuleObjRel.PROP_PROJECT_ALARM_RULE_ID, pageQueryProjectAlarmRuleObjRelDTO.getProjectAlarmRuleId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryProjectAlarmRuleObjRelDTO.getEquipId())) {
|
|
|
+ queryWrapper.like(ProjectAlarmRuleObjRel.PROP_EQUIP_ID, pageQueryProjectAlarmRuleObjRelDTO.getEquipId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pageQueryProjectAlarmRuleObjRelDTO.getOpen() != null) {
|
|
|
+ queryWrapper.eq(ProjectAlarmRuleObjRel.PROP_OPEN, pageQueryProjectAlarmRuleObjRelDTO.getOpen());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryProjectAlarmRuleObjRelDTO.getProjectId())) {
|
|
|
+ queryWrapper.like(ProjectAlarmRuleObjRel.PROP_PROJECT_ID, pageQueryProjectAlarmRuleObjRelDTO.getProjectId());
|
|
|
+ }
|
|
|
+
|
|
|
+ return getBaseMapper().selectPage(pageParam, queryWrapper);
|
|
|
+ }
|
|
|
+}
|