|
@@ -1,35 +1,40 @@
|
|
|
package com.persagy.apm.dmpalarm.service.impl;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.google.common.base.CaseFormat;
|
|
|
-import com.persagy.apm.common.constant.enums.ValidEnum;
|
|
|
-import com.persagy.apm.common.model.dto.Sort;
|
|
|
+import com.persagy.apm.dmpalarm.config.DmpParameterStorage;
|
|
|
import com.persagy.apm.dmpalarm.criteria.CriteriaUtils;
|
|
|
import com.persagy.apm.dmpalarm.criteria.JsonCriteria;
|
|
|
import com.persagy.apm.dmpalarm.dao.AlarmRecordMapper;
|
|
|
import com.persagy.apm.dmpalarm.enumeration.EnumAlarmListType;
|
|
|
+import com.persagy.apm.dmpalarm.enumeration.EnumAlarmLogType;
|
|
|
+import com.persagy.apm.dmpalarm.enumeration.EnumAlarmMessageType;
|
|
|
import com.persagy.apm.dmpalarm.enumeration.EnumAlarmState;
|
|
|
import com.persagy.apm.dmpalarm.enumeration.EnumAlarmTreatState;
|
|
|
+import com.persagy.apm.dmpalarm.json.JacksonMapper;
|
|
|
+import com.persagy.apm.dmpalarm.model.AlarmLog;
|
|
|
import com.persagy.apm.dmpalarm.model.AlarmRecord;
|
|
|
-import com.persagy.apm.dmpalarm.model.ConvertAlarmRecordTool;
|
|
|
-import com.persagy.apm.dmpalarm.model.dto.AddAlarmRecordDTO;
|
|
|
-import com.persagy.apm.dmpalarm.model.dto.PageQueryAlarmRecordDTO;
|
|
|
-import com.persagy.apm.dmpalarm.model.dto.QueryAlarmRecordDTO;
|
|
|
-import com.persagy.apm.dmpalarm.model.dto.UpdateAlarmRecordDTO;
|
|
|
+import com.persagy.apm.dmpalarm.model.DmpMessage;
|
|
|
+import com.persagy.apm.dmpalarm.service.IAlarmLogService;
|
|
|
import com.persagy.apm.dmpalarm.service.IAlarmRecordService;
|
|
|
+import com.persagy.apm.dmpalarm.utils.CheckRequiredParam;
|
|
|
+import com.persagy.apm.dmpalarm.utils.DatePatternStyle;
|
|
|
+import com.persagy.apm.dmpalarm.web.MapResponse;
|
|
|
import com.persagy.apm.dmpalarm.web.PagedResponse;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
@@ -38,439 +43,253 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
* @author lixing
|
|
|
* @version V1.0 2021-12-09 10:44:19
|
|
|
*/
|
|
|
-@Slf4j
|
|
|
@Service
|
|
|
-public class AlarmRecordServiceImpl extends ServiceImpl<AlarmRecordMapper, AlarmRecord> implements IAlarmRecordService {
|
|
|
+@Slf4j
|
|
|
+public class AlarmRecordServiceImpl extends BaseServiceImpl<AlarmRecord> implements IAlarmRecordService {
|
|
|
|
|
|
@Autowired
|
|
|
private CriteriaUtils criteriaUtils;
|
|
|
+ @Autowired
|
|
|
+ private IAlarmLogService alarmLogService;
|
|
|
+ @Autowired
|
|
|
+ private AlarmRecordMapper alarmRecordMapper;
|
|
|
|
|
|
-
|
|
|
- * 创建报警记录
|
|
|
- *
|
|
|
- * @return 报警记录主键
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-12-09 10:44:19
|
|
|
- */
|
|
|
@Override
|
|
|
- public String createAlarmRecord(AddAlarmRecordDTO addAlarmRecordDTO) {
|
|
|
- AlarmRecord alarmRecord = ConvertAlarmRecordTool.INSTANCE.convertAddDto2Entity(addAlarmRecordDTO);
|
|
|
-
|
|
|
- save(alarmRecord);
|
|
|
- return alarmRecord.getId();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 报警记录详情
|
|
|
- *
|
|
|
- * @param id 主键
|
|
|
- * @return 部门do类
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-12-09 10:44:19
|
|
|
- */
|
|
|
- @Override
|
|
|
- public AlarmRecord queryAlarmRecordDetail(String id) {
|
|
|
- AlarmRecord alarmRecord = getById(id);
|
|
|
- if (alarmRecord == null) {
|
|
|
- throw new IllegalArgumentException("查看AlarmRecord详情时发生异常,找不到要查看的记录,id=" + id);
|
|
|
+ public PagedResponse<AlarmRecord> query(JsonCriteria jsonCriteria) {
|
|
|
+ QueryWrapper<AlarmRecord> queryWrapper = criteriaUtils.handleAlarmConditions(jsonCriteria, AlarmRecord.class);
|
|
|
+ this.addAlarmQueryCondition(jsonCriteria.getCriteria(), queryWrapper);
|
|
|
+ PagedResponse<AlarmRecord> pagedResponse = new PagedResponse<>();
|
|
|
+ if (jsonCriteria.isOnlyCount()) {
|
|
|
+ Integer count = baseMapper.selectCount(queryWrapper);
|
|
|
+ pagedResponse.setCount(count.longValue());
|
|
|
+ } else {
|
|
|
+ Page<AlarmRecord> page = baseMapper.selectPage(new Page<>(jsonCriteria.getPage(), jsonCriteria.getSize()),
|
|
|
+ queryWrapper);
|
|
|
+ pagedResponse.setCount(page.getTotal());
|
|
|
+ pagedResponse.setData(page.getRecords());
|
|
|
}
|
|
|
- return alarmRecord;
|
|
|
+ return pagedResponse;
|
|
|
}
|
|
|
|
|
|
|
|
|
- * 更新报警记录
|
|
|
+ * 添加查询报警条件 CURRENT 当前报警 HISTORY 历史报警
|
|
|
*
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-12-09 10:44:19
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void updateAlarmRecord(UpdateAlarmRecordDTO updateAlarmRecordDTO) {
|
|
|
- AlarmRecord alarmRecord = getById(updateAlarmRecordDTO.getId());
|
|
|
- alarmRecord = ConvertAlarmRecordTool.INSTANCE.convertUpdateDto2Entity(alarmRecord, updateAlarmRecordDTO);
|
|
|
- updateById(alarmRecord);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 校验报警记录是否可删除
|
|
|
- *
|
|
|
- * @param id 报警记录主键
|
|
|
- * @return 报警记录do类
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-12-09 10:44:19
|
|
|
+ * @param <T>
|
|
|
+ *
|
|
|
+ * @param jsonObject
|
|
|
+ * @param alarmRecordWrappers
|
|
|
*/
|
|
|
- public AlarmRecord checkDeletable(String id) {
|
|
|
- if (id == null) {
|
|
|
- throw new IllegalArgumentException("删除AlarmRecord时发生异常,主键为空");
|
|
|
+ private <T> void addAlarmQueryCondition(JSONObject criteria, QueryWrapper<T> queryWrappers) {
|
|
|
+ String listType = criteria.getString("listType");
|
|
|
+ if (EnumAlarmListType.CURRENT.name().equals(listType)) {
|
|
|
+ queryWrappers.and(andw -> andw.eq(AlarmRecord.PROP_STATE, EnumAlarmState.UN_HANDLE.getType())
|
|
|
+ .or(orw -> orw.eq(AlarmRecord.PROP_TREAT_STATE, EnumAlarmState.UN_HANDLE.getType())
|
|
|
+ .eq(AlarmRecord.PROP_TREAT_STATE, EnumAlarmTreatState.HANDLING.getType())));
|
|
|
}
|
|
|
|
|
|
- AlarmRecord alarmRecord = getById(id);
|
|
|
+ if (EnumAlarmListType.HISTORY.name().equals(listType)) {
|
|
|
+ queryWrappers.and(andw -> andw.eq(AlarmRecord.PROP_STATE, EnumAlarmState.END.getType())
|
|
|
+ .or(orw -> orw.eq(AlarmRecord.PROP_STATE, EnumAlarmState.EXPIRE.getType())
|
|
|
+ .eq(AlarmRecord.PROP_TREAT_STATE, EnumAlarmTreatState.DONE.getType())));
|
|
|
|
|
|
- if (alarmRecord == null) {
|
|
|
- throw new IllegalArgumentException("删除AlarmRecord时发生异常,找不到要删除的数据,id:" + id);
|
|
|
}
|
|
|
-
|
|
|
- return alarmRecord;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * 删除报警记录
|
|
|
- *
|
|
|
- * @param id 主键
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-12-09 10:44:19
|
|
|
- */
|
|
|
@Override
|
|
|
- public void deleteAlarmRecord(String id) {
|
|
|
-
|
|
|
- AlarmRecord alarmRecord = checkDeletable(id);
|
|
|
-
|
|
|
- alarmRecord.setValid(ValidEnum.FALSE.getType());
|
|
|
- updateById(alarmRecord);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 查询报警记录
|
|
|
- *
|
|
|
- * @return List<AlarmRecord>
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-12-09 10:44:19
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<AlarmRecord> queryAlarmRecordList(QueryAlarmRecordDTO queryAlarmRecordDTO) {
|
|
|
- QueryWrapper<AlarmRecord> queryWrapper = new QueryWrapper<>();
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO != null) {
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(queryAlarmRecordDTO.getItemCode())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_ITEM_CODE, queryAlarmRecordDTO.getItemCode());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(queryAlarmRecordDTO.getProjectId())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_PROJECT_ID, queryAlarmRecordDTO.getProjectId());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(queryAlarmRecordDTO.getObjId())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_OBJ_ID, queryAlarmRecordDTO.getObjId());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(queryAlarmRecordDTO.getClassCode())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_CLASS_CODE, queryAlarmRecordDTO.getClassCode());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(queryAlarmRecordDTO.getLevel())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_LEVEL, queryAlarmRecordDTO.getLevel());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(queryAlarmRecordDTO.getRemark())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_REMARK, queryAlarmRecordDTO.getRemark());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(queryAlarmRecordDTO.getCreateUser())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_CREATE_USER, queryAlarmRecordDTO.getCreateUser());
|
|
|
- }
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO.getCreateTime() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_CREATE_TIME, queryAlarmRecordDTO.getCreateTime());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(queryAlarmRecordDTO.getUpdateUser())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_UPDATE_USER, queryAlarmRecordDTO.getUpdateUser());
|
|
|
- }
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO.getUpdateTime() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_UPDATE_TIME, queryAlarmRecordDTO.getUpdateTime());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(queryAlarmRecordDTO.getName())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_NAME, queryAlarmRecordDTO.getName());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(queryAlarmRecordDTO.getCategory())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_CATEGORY, queryAlarmRecordDTO.getCategory());
|
|
|
- }
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO.getConcern() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_CONCERN, queryAlarmRecordDTO.getConcern());
|
|
|
- }
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO.getState() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_STATE, queryAlarmRecordDTO.getState());
|
|
|
- }
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO.getEffectStartTime() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_EFFECT_START_TIME, queryAlarmRecordDTO.getEffectStartTime());
|
|
|
- }
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO.getEffectEndTime() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_EFFECT_END_TIME, queryAlarmRecordDTO.getEffectEndTime());
|
|
|
- }
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO.getNature() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_NATURE, queryAlarmRecordDTO.getNature());
|
|
|
- }
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO.getTreatMode() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_TREAT_MODE, queryAlarmRecordDTO.getTreatMode());
|
|
|
- }
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO.getTreatState() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_TREAT_STATE, queryAlarmRecordDTO.getTreatState());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(queryAlarmRecordDTO.getGroupCode())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_GROUP_CODE, queryAlarmRecordDTO.getGroupCode());
|
|
|
- }
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO.getCondition() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_CONDITION, queryAlarmRecordDTO.getCondition());
|
|
|
- }
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO.getTriggerInfo() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_TRIGGER_INFO, queryAlarmRecordDTO.getTriggerInfo());
|
|
|
- }
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO.getEndInfo() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_END_INFO, queryAlarmRecordDTO.getEndInfo());
|
|
|
- }
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO.getTriggerTime() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_TRIGGER_TIME, queryAlarmRecordDTO.getTriggerTime());
|
|
|
- }
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO.getEndTime() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_END_TIME, queryAlarmRecordDTO.getEndTime());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(queryAlarmRecordDTO.getOrderId())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_ORDER_ID, queryAlarmRecordDTO.getOrderId());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(queryAlarmRecordDTO.getOrderState())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_ORDER_STATE, queryAlarmRecordDTO.getOrderState());
|
|
|
+ @Transactional
|
|
|
+ public MapResponse create(AlarmRecord param) {
|
|
|
+
|
|
|
+ MapResponse response = new MapResponse();
|
|
|
+ AlarmParam alarmParam = prepareParam(response);
|
|
|
+ if (alarmParam == null) {
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ String checkResult = CheckRequiredParam.check(param, "itemCode", "objId", "level");
|
|
|
+ if (!StringUtils.isEmpty(checkResult)) {
|
|
|
+ response.setFail(checkResult);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ String id = UUID.randomUUID().toString();
|
|
|
+
|
|
|
+ if (!StringUtils.isEmpty(param.getId())) {
|
|
|
+
|
|
|
+ AlarmRecord alarmRecord = getById(param.getId());
|
|
|
+ if (null != alarmRecord) {
|
|
|
+ response.setFail("已存在相同id的报警记录!创建失败!");
|
|
|
+ return response;
|
|
|
+ } else {
|
|
|
+ id = param.getId();
|
|
|
}
|
|
|
-
|
|
|
- if (queryAlarmRecordDTO.getSupplement() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_SUPPLEMENT, queryAlarmRecordDTO.getSupplement());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(queryAlarmRecordDTO.getTargetId())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_TARGET_ID, queryAlarmRecordDTO.getTargetId());
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
+ AlarmRecord entity = param;
|
|
|
+ entity.setId(id);
|
|
|
+ entity.setCreateUser(alarmParam.userId);
|
|
|
+ if (param.getCreateTime() != null) {
|
|
|
+ entity.setCreateTime(param.getCreateTime());
|
|
|
+ } else {
|
|
|
+ entity.setCreateTime(new Date());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (entity.getTreatState() == null) {
|
|
|
+ entity.setTreatState(1);
|
|
|
+ }
|
|
|
+ entity.setValid(1);
|
|
|
+ entity.setProjectId(alarmParam.projectId);
|
|
|
+ entity.setGroupCode(alarmParam.groupCode);
|
|
|
+ save(entity);
|
|
|
+ response.add("id", entity.getId());
|
|
|
+
|
|
|
+ DmpMessage msg = new DmpMessage();
|
|
|
+ msg.setMid(UUID.randomUUID().toString());
|
|
|
+ msg.setType(EnumAlarmMessageType.ALARM_RECORD_CREATE.getValue());
|
|
|
+ msg.setGroupCode(DmpParameterStorage.getGroupCode());
|
|
|
+ msg.setProjectId(DmpParameterStorage.getProjectId());
|
|
|
+ msg.setTargetId(entity.getId());
|
|
|
+ msg.add("obj", JacksonMapper.toSimpleJson(entity));
|
|
|
+ msg.setAppId(DmpParameterStorage.getAppId());
|
|
|
+ msg.setSendTime(DateUtil.format(new Date(), DatePatternStyle.PATTERN_YYYYMMDDHHMMSS));
|
|
|
+ response.add(msg);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
|
|
|
- return list(queryWrapper);
|
|
|
+ private AlarmLog initAlarmLogModel(AlarmRecord param) {
|
|
|
+ AlarmLog alarmLog = new AlarmLog();
|
|
|
+ alarmLog.setRecordId(param.getId());
|
|
|
+ alarmLog.setCreateTime(new Date());
|
|
|
+ alarmLog.setCreateUser(DmpParameterStorage.getUserId());
|
|
|
+ alarmLog.setProjectId(DmpParameterStorage.getProjectId());
|
|
|
+ alarmLog.setGroupCode(DmpParameterStorage.getGroupCode());
|
|
|
+ return alarmLog;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * 分页查询报警记录
|
|
|
- *
|
|
|
- * @return IPage<AlarmRecord>
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021-12-09 10:44:19
|
|
|
- */
|
|
|
@Override
|
|
|
- public IPage<AlarmRecord> pageQueryAlarmRecord(PageQueryAlarmRecordDTO pageQueryAlarmRecordDTO) {
|
|
|
- QueryWrapper<AlarmRecord> queryWrapper = new QueryWrapper<>();
|
|
|
-
|
|
|
- IPage<AlarmRecord> pageParam = new Page<>(pageQueryAlarmRecordDTO.getPage(), pageQueryAlarmRecordDTO.getSize(),
|
|
|
- true);
|
|
|
-
|
|
|
- if (CollectionUtils.isEmpty(pageQueryAlarmRecordDTO.getOrders())) {
|
|
|
-
|
|
|
- } else {
|
|
|
- List<Sort> orders = pageQueryAlarmRecordDTO.getOrders();
|
|
|
- for (Sort sort : orders) {
|
|
|
-
|
|
|
- sort.setColumn(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, sort.getColumn()));
|
|
|
- queryWrapper.orderBy(true, sort.isAsc(), sort.getColumn());
|
|
|
+ @Transactional
|
|
|
+ public MapResponse update(AlarmRecord param) {
|
|
|
+ MapResponse response = new MapResponse();
|
|
|
+ AlarmRecord alarmRecord = getById(param.getId());
|
|
|
+ if (alarmRecord == null) {
|
|
|
+ response.setFail("无法获取到要更新的数据!");
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ AlarmParam alarmParam = prepareParam(response);
|
|
|
+ if (alarmParam == null) {
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ if (param.getName() != null && !param.getName().isEmpty()) {
|
|
|
+ alarmRecord.setName(param.getName());
|
|
|
+ }
|
|
|
+ if (param.getRemark() != null && !param.getRemark().isEmpty()) {
|
|
|
+ alarmRecord.setRemark(param.getRemark());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (param.getState() != null) {
|
|
|
+ if (!param.getState().equals(alarmRecord.getState())) {
|
|
|
+ AlarmLog alarmLog = initAlarmLogModel(param);
|
|
|
+ alarmLog.setType(EnumAlarmLogType.ALARMSTATE);
|
|
|
+ alarmLog.setNature(alarmRecord.getNature());
|
|
|
+ alarmLog.setBefore(alarmRecord.getState());
|
|
|
+ alarmLog.setAfter(param.getState());
|
|
|
+ alarmLogService.create(alarmLog);
|
|
|
}
|
|
|
+ alarmRecord.setState(param.getState());
|
|
|
+ }
|
|
|
+ if (param.getNature() != null) {
|
|
|
+ alarmRecord.setNature(param.getNature());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (param.getTreatMode() != null) {
|
|
|
+ if (!param.getTreatMode().equals(alarmRecord.getTreatMode())) {
|
|
|
+ AlarmLog alarmLogModel = initAlarmLogModel(param);
|
|
|
+ alarmLogModel.setType(EnumAlarmLogType.TREATMODE);
|
|
|
+ alarmLogModel.setNature(alarmRecord.getNature());
|
|
|
+ alarmLogModel.setBefore(alarmRecord.getTreatMode());
|
|
|
+ alarmLogModel.setAfter(param.getTreatMode());
|
|
|
+ alarmLogService.create(alarmLogModel);
|
|
|
+ }
|
|
|
+ alarmRecord.setTreatMode(param.getTreatMode());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (param.getTreatState() != null) {
|
|
|
+ if (!param.getTreatState().equals(alarmRecord.getTreatState())) {
|
|
|
+ AlarmLog alarmLogModel = initAlarmLogModel(param);
|
|
|
+ alarmLogModel.setType(EnumAlarmLogType.TREATSTATE);
|
|
|
+ alarmLogModel.setNature(alarmRecord.getNature());
|
|
|
+ alarmLogModel.setBefore(alarmRecord.getTreatState());
|
|
|
+ alarmLogModel.setAfter(param.getTreatState());
|
|
|
+ alarmLogService.create(alarmLogModel);
|
|
|
+ }
|
|
|
+ alarmRecord.setTreatState(param.getTreatState());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQueryAlarmRecordDTO.getItemCode())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_ITEM_CODE, pageQueryAlarmRecordDTO.getItemCode());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQueryAlarmRecordDTO.getProjectId())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_PROJECT_ID, pageQueryAlarmRecordDTO.getProjectId());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQueryAlarmRecordDTO.getObjId())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_OBJ_ID, pageQueryAlarmRecordDTO.getObjId());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQueryAlarmRecordDTO.getClassCode())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_CLASS_CODE, pageQueryAlarmRecordDTO.getClassCode());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQueryAlarmRecordDTO.getLevel())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_LEVEL, pageQueryAlarmRecordDTO.getLevel());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQueryAlarmRecordDTO.getRemark())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_REMARK, pageQueryAlarmRecordDTO.getRemark());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQueryAlarmRecordDTO.getCreateUser())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_CREATE_USER, pageQueryAlarmRecordDTO.getCreateUser());
|
|
|
- }
|
|
|
-
|
|
|
- if (pageQueryAlarmRecordDTO.getCreateTime() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_CREATE_TIME, pageQueryAlarmRecordDTO.getCreateTime());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQueryAlarmRecordDTO.getUpdateUser())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_UPDATE_USER, pageQueryAlarmRecordDTO.getUpdateUser());
|
|
|
- }
|
|
|
-
|
|
|
- if (pageQueryAlarmRecordDTO.getUpdateTime() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_UPDATE_TIME, pageQueryAlarmRecordDTO.getUpdateTime());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQueryAlarmRecordDTO.getName())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_NAME, pageQueryAlarmRecordDTO.getName());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQueryAlarmRecordDTO.getCategory())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_CATEGORY, pageQueryAlarmRecordDTO.getCategory());
|
|
|
- }
|
|
|
-
|
|
|
- if (pageQueryAlarmRecordDTO.getConcern() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_CONCERN, pageQueryAlarmRecordDTO.getConcern());
|
|
|
- }
|
|
|
-
|
|
|
- if (pageQueryAlarmRecordDTO.getState() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_STATE, pageQueryAlarmRecordDTO.getState());
|
|
|
- }
|
|
|
-
|
|
|
- if (pageQueryAlarmRecordDTO.getEffectStartTime() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_EFFECT_START_TIME, pageQueryAlarmRecordDTO.getEffectStartTime());
|
|
|
- }
|
|
|
-
|
|
|
- if (pageQueryAlarmRecordDTO.getEffectEndTime() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_EFFECT_END_TIME, pageQueryAlarmRecordDTO.getEffectEndTime());
|
|
|
- }
|
|
|
-
|
|
|
- if (pageQueryAlarmRecordDTO.getNature() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_NATURE, pageQueryAlarmRecordDTO.getNature());
|
|
|
- }
|
|
|
-
|
|
|
- if (pageQueryAlarmRecordDTO.getTreatMode() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_TREAT_MODE, pageQueryAlarmRecordDTO.getTreatMode());
|
|
|
- }
|
|
|
-
|
|
|
- if (pageQueryAlarmRecordDTO.getTreatState() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_TREAT_STATE, pageQueryAlarmRecordDTO.getTreatState());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQueryAlarmRecordDTO.getGroupCode())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_GROUP_CODE, pageQueryAlarmRecordDTO.getGroupCode());
|
|
|
- }
|
|
|
-
|
|
|
- if (pageQueryAlarmRecordDTO.getCondition() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_CONDITION, pageQueryAlarmRecordDTO.getCondition());
|
|
|
- }
|
|
|
-
|
|
|
- if (pageQueryAlarmRecordDTO.getTriggerInfo() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_TRIGGER_INFO, pageQueryAlarmRecordDTO.getTriggerInfo());
|
|
|
- }
|
|
|
-
|
|
|
- if (pageQueryAlarmRecordDTO.getEndInfo() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_END_INFO, pageQueryAlarmRecordDTO.getEndInfo());
|
|
|
+
|
|
|
+ if (param.getEndInfo() != null) {
|
|
|
+ alarmRecord.setEndInfo(param.getEndInfo());
|
|
|
}
|
|
|
-
|
|
|
- if (pageQueryAlarmRecordDTO.getTriggerTime() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_TRIGGER_TIME, pageQueryAlarmRecordDTO.getTriggerTime());
|
|
|
+
|
|
|
+ if (param.getEndTime() != null) {
|
|
|
+ alarmRecord.setEndTime(param.getEndTime());
|
|
|
}
|
|
|
-
|
|
|
- if (pageQueryAlarmRecordDTO.getEndTime() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_END_TIME, pageQueryAlarmRecordDTO.getEndTime());
|
|
|
+
|
|
|
+ if (param.getOrderId() != null) {
|
|
|
+ alarmRecord.setOrderId(param.getOrderId());
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQueryAlarmRecordDTO.getOrderId())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_ORDER_ID, pageQueryAlarmRecordDTO.getOrderId());
|
|
|
+
|
|
|
+ if (param.getOrderState() != null) {
|
|
|
+ alarmRecord.setOrderState(param.getOrderState());
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQueryAlarmRecordDTO.getOrderState())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_ORDER_STATE, pageQueryAlarmRecordDTO.getOrderState());
|
|
|
+
|
|
|
+ if (param.getSupplement() != null) {
|
|
|
+ alarmRecord.setSupplement(param.getSupplement());
|
|
|
}
|
|
|
-
|
|
|
- if (pageQueryAlarmRecordDTO.getSupplement() != null) {
|
|
|
- queryWrapper.eq(AlarmRecord.PROP_SUPPLEMENT, pageQueryAlarmRecordDTO.getSupplement());
|
|
|
+
|
|
|
+ if (!StringUtils.isEmpty(param.getLevel())) {
|
|
|
+ alarmRecord.setLevel(param.getLevel());
|
|
|
}
|
|
|
+ alarmRecord.setUpdateUser(alarmParam.userId);
|
|
|
+ alarmRecord.setUpdateTime(new Date());
|
|
|
+ save(alarmRecord);
|
|
|
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(pageQueryAlarmRecordDTO.getTargetId())) {
|
|
|
- queryWrapper.like(AlarmRecord.PROP_TARGET_ID, pageQueryAlarmRecordDTO.getTargetId());
|
|
|
- }
|
|
|
+ response.add("id", alarmRecord.getId());
|
|
|
+
|
|
|
+ DmpMessage msg = new DmpMessage();
|
|
|
+ msg.setMid(UUID.randomUUID().toString());
|
|
|
+ msg.setType(EnumAlarmMessageType.ALARM_RECORD_UPDATE.getValue());
|
|
|
+ msg.setGroupCode(DmpParameterStorage.getGroupCode());
|
|
|
+ msg.setProjectId(DmpParameterStorage.getProjectId());
|
|
|
+ msg.setTargetId(alarmRecord.getId());
|
|
|
+ msg.add("obj", JacksonMapper.toSimpleJson(alarmRecord));
|
|
|
+ msg.setAppId(DmpParameterStorage.getAppId());
|
|
|
+ msg.setSendTime(DateUtil.format(new Date(), DatePatternStyle.PATTERN_YYYYMMDDHHMMSS));
|
|
|
+ response.add(msg);
|
|
|
+ return response;
|
|
|
|
|
|
- return getBaseMapper().selectPage(pageParam, queryWrapper);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public PagedResponse<AlarmRecord> query(JsonCriteria jsonCriteria) {
|
|
|
- QueryWrapper<AlarmRecord> queryWrapper = criteriaUtils.handleAlarmConditions(jsonCriteria, AlarmRecord.class);
|
|
|
- this.addAlarmQueryCondition(jsonCriteria.getCriteria(), queryWrapper);
|
|
|
- PagedResponse<AlarmRecord> pagedResponse = new PagedResponse<>();
|
|
|
- if (jsonCriteria.isOnlyCount()) {
|
|
|
- Integer count = baseMapper.selectCount(queryWrapper);
|
|
|
- pagedResponse.setCount(count.longValue());
|
|
|
- } else {
|
|
|
- Page<AlarmRecord> page = baseMapper.selectPage(new Page<>(jsonCriteria.getPage(), jsonCriteria.getSize()),
|
|
|
- queryWrapper);
|
|
|
- pagedResponse.setCount(page.getTotal());
|
|
|
- pagedResponse.setData(page.getRecords());
|
|
|
- }
|
|
|
- return pagedResponse;
|
|
|
- }
|
|
|
+ @Transactional
|
|
|
+ public MapResponse batchUpdate(AlarmRecord param) {
|
|
|
+ MapResponse response = new MapResponse();
|
|
|
|
|
|
-
|
|
|
- * 添加查询报警条件 CURRENT 当前报警 HISTORY 历史报警
|
|
|
- *
|
|
|
- * @param jsonObject
|
|
|
- * @param alarmRecordWrappers
|
|
|
- */
|
|
|
- private void addAlarmQueryCondition(JSONObject criteria, QueryWrapper<?> queryWrappers) {
|
|
|
- String listType = criteria.getString("listType");
|
|
|
- if (EnumAlarmListType.CURRENT.name().equals(listType)) {
|
|
|
- queryWrappers.eq(AlarmRecord.PROP_STATE, EnumAlarmState.UN_HANDLE.getType());
|
|
|
- queryWrappers.and(andWrapper -> andWrapper
|
|
|
- .eq(AlarmRecord.PROP_TREAT_STATE, EnumAlarmTreatState.UN_HANDLE.getType()).or(orWrapper -> orWrapper
|
|
|
- .eq(AlarmRecord.PROP_TREAT_STATE, EnumAlarmTreatState.HANDLING.getType())));
|
|
|
+ List<AlarmRecord> alarmRecordModelList = param.getAlarmRecordModels();
|
|
|
+ if (CollectionUtils.isEmpty(alarmRecordModelList)) {
|
|
|
+ response.setFail("批量更新报警记录,没有传入需要更新的对象");
|
|
|
+ return response;
|
|
|
}
|
|
|
- if (EnumAlarmListType.HISTORY.name().equals(listType)) {
|
|
|
- queryWrappers.eq(AlarmRecord.PROP_STATE, EnumAlarmState.END.getType()).or(orWrapper -> orWrapper
|
|
|
- .eq(AlarmRecord.PROP_STATE, EnumAlarmState.EXPIRE.getType())
|
|
|
- .or(or2Wrapper -> or2Wrapper.eq(AlarmRecord.PROP_TREAT_STATE, EnumAlarmTreatState.DONE.getType())));
|
|
|
|
|
|
+
|
|
|
+ if (alarmRecordModelList.size() > 200) {
|
|
|
+ response.setFail("一次最多更新200条数据");
|
|
|
+ return response;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+ List<DmpMessage> msgList = new ArrayList<>();
|
|
|
+ alarmRecordModelList.forEach(alarmRecordModel -> {
|
|
|
+ MapResponse updateResponse = update(alarmRecordModel);
|
|
|
+ msgList.addAll(updateResponse.getMessageList());
|
|
|
+ });
|
|
|
+ response.add(msgList);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
}
|