云
2 天以前 657698fd2fb32794932474648dbaee9e284e38c8
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
package cn.iocoder.yudao.module.mes.controller.admin.energy;
 
import cn.iocoder.yudao.framework.common.pojo.*;
import cn.iocoder.yudao.module.mes.controller.admin.energy.vo.EnergyAlertRuleSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.energy.*;
import cn.iocoder.yudao.module.mes.service.energy.EnergyAlertService;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
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.*;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
@RestController @RequestMapping("/energy/alert") @Validated
public class EnergyAlertController {
    @Resource private EnergyAlertService energyAlertService;
    @Resource private AdminUserService adminUserService;
    @GetMapping("/page") @PreAuthorize("@ss.hasPermission('energy:alert:query')")
    public CommonResult<PageResult<EnergyAlertRuleDO>> page(@Valid PageParam page) { return success(energyAlertService.page(page)); }
    @GetMapping("/logs") @PreAuthorize("@ss.hasPermission('energy:alert:query')")
    public CommonResult<PageResult<EnergyAlertLogDO>> logs(@Valid PageParam page,
            @RequestParam(required=false) @DateTimeFormat(iso=DateTimeFormat.ISO.DATE) LocalDate date,
            @RequestParam(required=false) @Pattern(regexp="SENT|FAILED") String status) {
        return success(energyAlertService.logs(page, date, status));
    }
    @GetMapping("/recipients") @PreAuthorize("@ss.hasPermission('energy:alert:query')")
    public CommonResult<List<Map<String, Object>>> recipients() {
        return success(adminUserService.getUserListByStatus(0).stream()
                .map(user -> Map.<String,Object>of("id", user.getId(), "nickname", user.getNickname())).toList());
    }
    @PostMapping("/create") @PreAuthorize("@ss.hasPermission('energy:alert:create')")
    public CommonResult<Long> create(@Valid @RequestBody EnergyAlertRuleSaveReqVO req) { req.setId(null); return success(energyAlertService.save(req)); }
    @PutMapping("/update") @PreAuthorize("@ss.hasPermission('energy:alert:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody EnergyAlertRuleSaveReqVO req) {
        if (req.getId() == null) throw cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception(
                new cn.iocoder.yudao.framework.common.exception.ErrorCode(1_040_951_001, "修改预警规则必须提供编号"));
        energyAlertService.save(req); return success(true);
    }
    @DeleteMapping("/delete") @PreAuthorize("@ss.hasPermission('energy:alert:delete')")
    public CommonResult<Boolean> delete(@RequestParam Long id) { energyAlertService.delete(id); return success(true); }
    @PostMapping("/check") @PreAuthorize("@ss.hasPermission('energy:alert:check')")
    public CommonResult<Map<String,Integer>> check(@RequestParam @NotNull @PastOrPresent
            @DateTimeFormat(iso=DateTimeFormat.ISO.DATE) LocalDate date) { return success(energyAlertService.check(date)); }
}