|
|
@@ -1,12 +1,22 @@
|
|
|
package cn.sciento.farm.automationv2.api.controller;
|
|
|
|
|
|
+import cn.sciento.core.domain.Page;
|
|
|
+import cn.sciento.core.iam.ResourceLevel;
|
|
|
+import cn.sciento.core.util.Results;
|
|
|
import cn.sciento.farm.automationv2.api.dto.PageRequest;
|
|
|
import cn.sciento.farm.automationv2.api.dto.Result;
|
|
|
import cn.sciento.farm.automationv2.app.service.AlarmNotificationService;
|
|
|
import cn.sciento.farm.automationv2.app.service.AlarmRecordService;
|
|
|
import cn.sciento.farm.automationv2.domain.entity.AlarmRecord;
|
|
|
+import cn.sciento.farm.automationv2.domain.entity.IrrigationTask;
|
|
|
+import cn.sciento.farm.automationv2.domain.valueobject.IrrigationTaskVO;
|
|
|
+import cn.sciento.swagger.annotation.Permission;
|
|
|
+import io.choerodon.mybatis.pagehelper.annotation.PageableDefault;
|
|
|
+import io.choerodon.mybatis.pagehelper.domain.Sort;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.List;
|
|
|
@@ -16,75 +26,53 @@ import java.util.List;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@RestController
|
|
|
-@RequestMapping("/api/alarms")
|
|
|
-@RequiredArgsConstructor
|
|
|
+@RequestMapping("/v2/{tenantId}/alarms")
|
|
|
public class AlarmController {
|
|
|
|
|
|
- private final AlarmRecordService alarmRecordService;
|
|
|
- private final AlarmNotificationService alarmNotificationService;
|
|
|
+ private AlarmRecordService alarmRecordService;
|
|
|
+ private AlarmNotificationService alarmNotificationService;
|
|
|
|
|
|
- /**
|
|
|
- * 查询报警详情
|
|
|
- */
|
|
|
- @GetMapping("/{id}")
|
|
|
- public Result<AlarmRecord> getAlarm(@PathVariable Long id) {
|
|
|
- log.info("查询报警详情,alarmId={}", id);
|
|
|
-
|
|
|
- AlarmRecord alarm = alarmRecordService.getAlarmById(id);
|
|
|
- if (alarm == null) {
|
|
|
- return Result.error("报警记录不存在");
|
|
|
- }
|
|
|
-
|
|
|
- return Result.success(alarm);
|
|
|
+ public AlarmController(AlarmRecordService alarmRecordService, AlarmNotificationService alarmNotificationService) {
|
|
|
+ this.alarmRecordService = alarmRecordService;
|
|
|
+ this.alarmNotificationService = alarmNotificationService;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 分页查询报警记录
|
|
|
- */
|
|
|
- @GetMapping
|
|
|
- public Result<List<AlarmRecord>> listAlarms(PageRequest pageRequest) {
|
|
|
- log.info("分页查询报警记录,pageNum={}, pageSize={}, tenantId={}",
|
|
|
- pageRequest.getPageNum(), pageRequest.getPageSize(), pageRequest.getTenantId());
|
|
|
-
|
|
|
- List<AlarmRecord> alarms = alarmRecordService.listAlarms(
|
|
|
- pageRequest.getTenantId(),
|
|
|
- pageRequest.getOffset(),
|
|
|
- pageRequest.getLimit()
|
|
|
- );
|
|
|
|
|
|
- return Result.success(alarms);
|
|
|
+ @ApiOperation("分页查询报警记录")
|
|
|
+ @Permission(level = ResourceLevel.ORGANIZATION)
|
|
|
+ @GetMapping
|
|
|
+ public ResponseEntity<Page<AlarmRecord>> page(@PathVariable Long tenantId,
|
|
|
+ AlarmRecord alarmRecord,
|
|
|
+ @PageableDefault(page = 1,size = 20,sort = {"creation_date"}, direction = Sort.Direction.DESC) io.choerodon.mybatis.pagehelper.domain.PageRequest pageRequest){
|
|
|
+ alarmRecord.setTenantId(tenantId);
|
|
|
+ return Results.success(alarmRecordService.page(alarmRecord,pageRequest));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 查询未处理报警
|
|
|
- */
|
|
|
- @GetMapping("/unhandled")
|
|
|
- public Result<List<AlarmRecord>> listUnhandledAlarms(@RequestParam Long tenantId,
|
|
|
- @RequestParam(defaultValue = "50") Integer limit) {
|
|
|
- log.info("查询未处理报警,tenantId={}, limit={}", tenantId, limit);
|
|
|
-
|
|
|
- List<AlarmRecord> alarms = alarmRecordService.listUnhandledAlarms(tenantId, limit);
|
|
|
|
|
|
- return Result.success(alarms);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 标记报警已处理
|
|
|
*/
|
|
|
- @PostMapping("/{id}/handle")
|
|
|
- public Result<Void> handleAlarm(@PathVariable Long id,
|
|
|
- @RequestParam Long handledBy,
|
|
|
+ @Permission(level = ResourceLevel.ORGANIZATION)
|
|
|
+ @PostMapping("/handle/{alarmId}")
|
|
|
+ public ResponseEntity handleAlarm(@PathVariable Long tenantId,
|
|
|
+ @PathVariable Long alarmId,
|
|
|
@RequestParam(required = false) String remark) {
|
|
|
- log.info("标记报警已处理,alarmId={}, handledBy={}, remark={}", id, handledBy, remark);
|
|
|
+ alarmRecordService.markAsHandled(alarmId, remark);
|
|
|
+ return Results.success();
|
|
|
|
|
|
- try {
|
|
|
- alarmRecordService.markAsHandled(id, handledBy, remark);
|
|
|
- return Result.success();
|
|
|
+ }
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("标记报警失败,alarmId={}", id, e);
|
|
|
- return Result.error("标记失败: " + e.getMessage());
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 全部已读
|
|
|
+ */
|
|
|
+ @Permission(level = ResourceLevel.ORGANIZATION)
|
|
|
+ @PostMapping("/handle-all")
|
|
|
+ public ResponseEntity handleAlarmAll(@PathVariable Long tenantId,
|
|
|
+ @RequestBody AlarmRecord alarmRecord) {
|
|
|
+ alarmRecord.setTenantId(tenantId);
|
|
|
+ alarmRecordService.markAsHandledAll(alarmRecord);
|
|
|
+ return Results.success();
|
|
|
}
|
|
|
|
|
|
/**
|