package com.ningdatech.pmapi.sys.controller;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import com.ningdatech.pmapi.sys.model.req.WarningListReq;
import com.ningdatech.pmapi.sys.model.vo.WflowEarlyWarningRecordsVO;
import com.ningdatech.pmapi.sys.service.IEarlyWarningRecordsService;
import com.wflow.bean.dto.WflowEarlyWarningDTO;
import com.wflow.bean.vo.WflowEarlyWarningVO;
import com.wflow.service.IEarlyWarningService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Classname EarlyWarningController
 * @Description
 * @Date 2023/8/01 14:28
 * @Author PoffyZhang
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/v1/sys/early-warning")
@Api(value = "EarlyWarning", tags = "预警管理")
@RequiredArgsConstructor
public class EarlyWarningController {

    private final IEarlyWarningService earlyWarningService;

    private final IEarlyWarningRecordsService earlyWarningRecordsService;

    @ApiOperation(value = "预警规则获取", notes = "预警规则获取")
    @GetMapping("/detail/{areaCode}")
    public List<WflowEarlyWarningVO> detail(@PathVariable String areaCode) {
        return earlyWarningService.detailByRegion(areaCode);
    }

    @ApiOperation(value = "预警规则保存", notes = "预警规则保存")
    @PostMapping("/save")
    @WebLog("预警规则保存")
    public String save(@Validated @RequestBody WflowEarlyWarningDTO dto) {
        return earlyWarningService.saveByDto(dto);
    }

    @ApiOperation(value = "预警记录查询", notes = "预警记录查询")
    @GetMapping("/records/{ruleType}")
    public PageVo<WflowEarlyWarningRecordsVO> records(@PathVariable Integer ruleType, WarningListReq req) {
        return earlyWarningRecordsService.records(ruleType,req);
    }
}
