liu
昨天 381e02b9eccbe953b31d09f2af1c2ce77c816140
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package cn.iocoder.yudao.module.mes.controller.admin.em.alert;
 
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo.MesEmAlertHandleReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo.MesEmAlertPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo.MesEmAlertRespVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.em.alert.MesEmAlertDO;
import cn.iocoder.yudao.module.mes.service.em.alert.MesEmAlertService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.time.LocalDate;
import java.util.Collections;
 
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
@Tag(name = "管理后台 - MES 能耗预警")
@RestController
@RequestMapping("/mes/em/alert")
@Validated
public class MesEmAlertController {
 
    @Resource
    private MesEmAlertService alertService;
 
    @GetMapping("/page")
    @Operation(summary = "获得能耗预警分页")
    public CommonResult<PageResult<MesEmAlertRespVO>> getAlertPage(@Valid MesEmAlertPageReqVO pageReqVO) {
        PageResult<MesEmAlertDO> pageResult = alertService.getAlertPage(pageReqVO);
        return success(new PageResult<>(alertService.getAlertRespVOList(pageResult.getList()),
                pageResult.getTotal()));
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得能耗预警")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<MesEmAlertRespVO> getAlert(@RequestParam("id") Long id) {
        MesEmAlertDO alert = alertService.getAlert(id);
        if (alert == null) {
            return success(null);
        }
        return success(alertService.getAlertRespVOList(Collections.singletonList(alert)).get(0));
    }
 
    @PutMapping("/handle")
    @Operation(summary = "处理能耗预警")
    @PreAuthorize("@ss.hasPermission('mes:em-alert:handle')")
    public CommonResult<Boolean> handleAlert(@Valid @RequestBody MesEmAlertHandleReqVO handleReqVO) {
        alertService.handleAlert(handleReqVO);
        return success(true);
    }
 
    @PostMapping("/check")
    @Operation(summary = "重新检测指定日期区间的能耗预警")
    @PreAuthorize("@ss.hasPermission('mes:em-alert:handle')")
    public CommonResult<Integer> checkAlerts(
            @RequestParam("beginDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate beginDate,
            @RequestParam("endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) {
        return success(alertService.checkRange(beginDate, endDate));
    }
 
}