|
@@ -0,0 +1,209 @@
|
|
|
+package com.persagy.apm.diagnose.indicatorrecord.service.impl;
|
|
|
+
|
|
|
+import com.persagy.apm.common.context.AppContext;
|
|
|
+import com.persagy.apm.diagnose.indicatorrecord.dao.MonitorIndicatorRecordMapper;
|
|
|
+import com.persagy.apm.diagnose.indicatorrecord.service.IMonitorIndicatorRecordService;
|
|
|
+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.diagnose.indicatorrecord.model.*;
|
|
|
+import com.persagy.apm.diagnose.indicatorrecord.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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 监测指标历史记录(MonitorIndicatorRecord) service层
|
|
|
+ *
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-10 00:13:27
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndicatorRecordMapper, MonitorIndicatorRecord>
|
|
|
+ implements IMonitorIndicatorRecordService {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建监测指标历史记录
|
|
|
+ * @return 监测指标历史记录主键
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-10 00:13:27
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String createMonitorIndicatorRecord(AddMonitorIndicatorRecordDTO addMonitorIndicatorRecordDTO) {
|
|
|
+ MonitorIndicatorRecord monitorIndicatorRecord = ConvertMonitorIndicatorRecordTool.INSTANCE.convertAddDto2Entity(addMonitorIndicatorRecordDTO);
|
|
|
+ // 设置默认值
|
|
|
+ setDefaultValue(monitorIndicatorRecord);
|
|
|
+ save(monitorIndicatorRecord);
|
|
|
+ return monitorIndicatorRecord.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 如果某些字段没有赋值,使用默认的值
|
|
|
+ *
|
|
|
+ * @param monitorIndicatorRecord 监测指标历史记录实体
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/3/12 12:29 下午
|
|
|
+ */
|
|
|
+ private void setDefaultValue(MonitorIndicatorRecord monitorIndicatorRecord) {
|
|
|
+ monitorIndicatorRecord.setCreator(AppContext.getContext().getAccountId());
|
|
|
+ // todo 其他默认的属性
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 监测指标历史记录详情
|
|
|
+ * @param id 主键
|
|
|
+ * @return 部门do类
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-10 00:13:27
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public MonitorIndicatorRecord queryMonitorIndicatorRecordDetail(String id) {
|
|
|
+ MonitorIndicatorRecord monitorIndicatorRecord = getById(id);
|
|
|
+ if (monitorIndicatorRecord == null) {
|
|
|
+ throw new IllegalArgumentException("查看MonitorIndicatorRecord详情时发生异常,找不到要查看的记录,id=" + id);
|
|
|
+ }
|
|
|
+ return monitorIndicatorRecord;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新监测指标历史记录
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-10 00:13:27
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void updateMonitorIndicatorRecord(UpdateMonitorIndicatorRecordDTO updateMonitorIndicatorRecordDTO) {
|
|
|
+ MonitorIndicatorRecord monitorIndicatorRecord = getById(updateMonitorIndicatorRecordDTO.getId());
|
|
|
+ monitorIndicatorRecord = ConvertMonitorIndicatorRecordTool.INSTANCE.convertUpdateDto2Entity(monitorIndicatorRecord, updateMonitorIndicatorRecordDTO);
|
|
|
+ monitorIndicatorRecord.setModifier(AppContext.getContext().getAccountId());
|
|
|
+ updateById(monitorIndicatorRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验监测指标历史记录是否可删除
|
|
|
+ *
|
|
|
+ * @param id 监测指标历史记录主键
|
|
|
+ * @return 监测指标历史记录do类
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-10 00:13:27
|
|
|
+ */
|
|
|
+ public MonitorIndicatorRecord checkDeletable(String id) {
|
|
|
+ if (id == null) {
|
|
|
+ throw new IllegalArgumentException("删除MonitorIndicatorRecord时发生异常,主键为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ MonitorIndicatorRecord monitorIndicatorRecord = getById(id);
|
|
|
+
|
|
|
+ if (monitorIndicatorRecord == null) {
|
|
|
+ throw new IllegalArgumentException("删除MonitorIndicatorRecord时发生异常,找不到要删除的数据,id:" + id);
|
|
|
+ }
|
|
|
+
|
|
|
+ return monitorIndicatorRecord;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除监测指标历史记录
|
|
|
+ * @param id 主键
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-10 00:13:27
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void deleteMonitorIndicatorRecord(String id) {
|
|
|
+ // 校验是否可删除
|
|
|
+ MonitorIndicatorRecord monitorIndicatorRecord = checkDeletable(id);
|
|
|
+
|
|
|
+ monitorIndicatorRecord.setValid(ValidEnum.FALSE.getType());
|
|
|
+ updateById(monitorIndicatorRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询监测指标历史记录
|
|
|
+ * @return List<MonitorIndicatorRecord>
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-10 00:13:27
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<MonitorIndicatorRecord> queryMonitorIndicatorRecordList(QueryMonitorIndicatorRecordDTO queryMonitorIndicatorRecordDTO) {
|
|
|
+ QueryWrapper<MonitorIndicatorRecord> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(MonitorIndicatorRecord.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
+ // 默认按创建时间倒序排序
|
|
|
+ queryWrapper.orderBy(true, false, MonitorIndicatorRecord.PROP_CREATIONTIME);
|
|
|
+
|
|
|
+ if (queryMonitorIndicatorRecordDTO != null) {
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(queryMonitorIndicatorRecordDTO.getObjId())) {
|
|
|
+ queryWrapper.like(MonitorIndicatorRecord.PROP_OBJ_ID, queryMonitorIndicatorRecordDTO.getObjId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(queryMonitorIndicatorRecordDTO.getMonitorIndicatorId())) {
|
|
|
+ queryWrapper.like(MonitorIndicatorRecord.PROP_MONITOR_INDICATOR_ID, queryMonitorIndicatorRecordDTO.getMonitorIndicatorId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (queryMonitorIndicatorRecordDTO.getDate() != null) {
|
|
|
+ queryWrapper.eq(MonitorIndicatorRecord.PROP_DATE, queryMonitorIndicatorRecordDTO.getDate());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(queryMonitorIndicatorRecordDTO.getValue())) {
|
|
|
+ queryWrapper.like(MonitorIndicatorRecord.PROP_VALUE, queryMonitorIndicatorRecordDTO.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return list(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询监测指标历史记录
|
|
|
+ * @return IPage<MonitorIndicatorRecord>
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-10 00:13:27
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<MonitorIndicatorRecord> pageQueryMonitorIndicatorRecord(PageQueryMonitorIndicatorRecordDTO pageQueryMonitorIndicatorRecordDTO) {
|
|
|
+ QueryWrapper<MonitorIndicatorRecord> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(MonitorIndicatorRecord.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
+ // 这里认为pageQueryDTO是经过校验的,肯定包含分页信息
|
|
|
+ IPage<MonitorIndicatorRecord> pageParam = new Page<>(pageQueryMonitorIndicatorRecordDTO.getPage(), pageQueryMonitorIndicatorRecordDTO.getSize(),true);
|
|
|
+ // 排序信息
|
|
|
+ if(CollectionUtils.isEmpty(pageQueryMonitorIndicatorRecordDTO.getOrders())){
|
|
|
+ // 默认按创建时间倒序排序
|
|
|
+ queryWrapper.orderBy(true, false, MonitorIndicatorRecord.PROP_CREATIONTIME);
|
|
|
+ }else {
|
|
|
+ List<Sort> orders = pageQueryMonitorIndicatorRecordDTO.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(pageQueryMonitorIndicatorRecordDTO.getObjId())) {
|
|
|
+ queryWrapper.like(MonitorIndicatorRecord.PROP_OBJ_ID, pageQueryMonitorIndicatorRecordDTO.getObjId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryMonitorIndicatorRecordDTO.getMonitorIndicatorId())) {
|
|
|
+ queryWrapper.like(MonitorIndicatorRecord.PROP_MONITOR_INDICATOR_ID, pageQueryMonitorIndicatorRecordDTO.getMonitorIndicatorId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pageQueryMonitorIndicatorRecordDTO.getDate() != null) {
|
|
|
+ queryWrapper.eq(MonitorIndicatorRecord.PROP_DATE, pageQueryMonitorIndicatorRecordDTO.getDate());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryMonitorIndicatorRecordDTO.getValue())) {
|
|
|
+ queryWrapper.like(MonitorIndicatorRecord.PROP_VALUE, pageQueryMonitorIndicatorRecordDTO.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ return getBaseMapper().selectPage(pageParam, queryWrapper);
|
|
|
+ }
|
|
|
+}
|