|
@@ -0,0 +1,91 @@
|
|
|
+package com.persagy.apm.alarmservice.group.alarmrecord.controller;
|
|
|
+
|
|
|
+import com.persagy.apm.alarmservice.dependency.saasweb.service.SaasWebClientWrapper;
|
|
|
+import com.persagy.apm.alarmservice.group.alarmrecord.model.ConvertAlarmCommentTool;
|
|
|
+import com.persagy.apm.alarmservice.group.alarmrecord.model.dto.CreateAlarmCommentDTO;
|
|
|
+import com.persagy.apm.alarmservice.group.alarmrecord.model.dto.PageQueryAlarmCommentDTO;
|
|
|
+import com.persagy.apm.alarmservice.group.alarmrecord.model.vo.AlarmCommentListItem;
|
|
|
+import com.persagy.apm.common.model.vo.SimpleObjVO;
|
|
|
+import com.persagy.apm.common.response.ApmResponseUpsertVO;
|
|
|
+import com.persagy.apm.common.response.CommonResult;
|
|
|
+import com.persagy.apm.common.response.PageList;
|
|
|
+import com.persagy.apm.common.utils.ResultHelper;
|
|
|
+import com.persagy.apm.energyalarmstarter.alarmdata.feign.DmpResult;
|
|
|
+import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmcomment.QueryAlarmCommentDTO;
|
|
|
+import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmconfig.AddAlarmCommentDTO;
|
|
|
+import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.common.QueryDTO;
|
|
|
+import com.persagy.apm.energyalarmstarter.alarmdata.model.vo.AlarmCommentItem;
|
|
|
+import com.persagy.apm.energyalarmstarter.alarmdata.model.vo.DmpUpsertVO;
|
|
|
+import com.persagy.apm.energyalarmstarter.alarmdata.service.AlarmCommentServiceImpl;
|
|
|
+import com.persagy.common.exception.BusinessException;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 报警批注控制层
|
|
|
+ *
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:30:38
|
|
|
+ */
|
|
|
+@Api(tags = "报警批注")
|
|
|
+@Validated
|
|
|
+@RestController
|
|
|
+@RequestMapping("alarm_comments")
|
|
|
+public class AlarmCommnetController {
|
|
|
+ @Autowired
|
|
|
+ AlarmCommentServiceImpl alarmCommentService;
|
|
|
+ @Autowired
|
|
|
+ SaasWebClientWrapper saasWebClientWrapper;
|
|
|
+
|
|
|
+ @ApiOperation(value = "报警批注列表")
|
|
|
+ @PostMapping("/query")
|
|
|
+ public CommonResult<PageList<AlarmCommentListItem>> queryCurrentAlarmRecord(
|
|
|
+ @Valid @RequestBody PageQueryAlarmCommentDTO pageQueryAlarmCommentDTO) throws Exception {
|
|
|
+ QueryDTO<QueryAlarmCommentDTO> queryDTO = new QueryDTO<>();
|
|
|
+ queryDTO.setPage(pageQueryAlarmCommentDTO.getPage());
|
|
|
+ queryDTO.setSize(pageQueryAlarmCommentDTO.getSize());
|
|
|
+ QueryAlarmCommentDTO queryAlarmCommentDTO = new QueryAlarmCommentDTO();
|
|
|
+ queryAlarmCommentDTO.setRecordId(pageQueryAlarmCommentDTO.getAlarmRecordId());
|
|
|
+ queryDTO.setCriteria(queryAlarmCommentDTO);
|
|
|
+ DmpResult<List<AlarmCommentItem>> dmpResult = alarmCommentService.pageQuery(queryDTO);
|
|
|
+ if (dmpResult == null || dmpResult.getData() == null) {
|
|
|
+ throw new BusinessException("查询报警批注列表发生异常");
|
|
|
+ }
|
|
|
+ List<AlarmCommentListItem> resultList = dmpResult.getData().stream().map(
|
|
|
+ alarmCommentItem -> {
|
|
|
+ AlarmCommentListItem alarmCommentListItem = ConvertAlarmCommentTool.INSTANCE.
|
|
|
+ convert2AlarmCommentListItem(alarmCommentItem);
|
|
|
+ SimpleObjVO creator = saasWebClientWrapper.getUserInfo(alarmCommentItem.getCreateUser());
|
|
|
+ alarmCommentListItem.setCreator(creator);
|
|
|
+ return alarmCommentListItem;
|
|
|
+ }
|
|
|
+ ).collect(Collectors.toList());
|
|
|
+ return ResultHelper.multi(resultList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "创建报警批注")
|
|
|
+ @PostMapping("/create")
|
|
|
+ public CommonResult<ApmResponseUpsertVO> createAlarmComment(
|
|
|
+ @Valid @RequestBody CreateAlarmCommentDTO createAlarmCommentDTO) throws Exception {
|
|
|
+ AddAlarmCommentDTO addAlarmCommentDTO = new AddAlarmCommentDTO();
|
|
|
+ addAlarmCommentDTO.setRecordId(createAlarmCommentDTO.getAlarmRecordId());
|
|
|
+ addAlarmCommentDTO.setContent(createAlarmCommentDTO.getContent());
|
|
|
+ DmpResult<DmpUpsertVO> dmpResult = alarmCommentService.create(addAlarmCommentDTO);
|
|
|
+ if (dmpResult == null || dmpResult.getData() == null) {
|
|
|
+ throw new BusinessException("创建报警批注失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResultHelper.single(new ApmResponseUpsertVO(dmpResult.getData().getId()));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|