package com.energy.manage.service.controller.analysiserr;

import com.energy.manage.common.base.Page;
import com.energy.manage.common.reponse.ResultResp;
import com.energy.manage.service.config.annotations.UserLoginToken;
import com.energy.manage.service.controller.base.BaseServiceController;
import com.energy.manage.service.domain.dto.windexceptioncount.WindExceptionCountDto;
import com.energy.manage.service.domain.vo.windexceptioncount.WindExceptionCountVo;
import com.energy.manage.service.service.analysiserr.AnalysisErrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 分析结果异常数统计
 * @author chy
 * @date 2024/5/23 17:22
 * @desc
 */
@Api(value = "AnalysisErrController",tags = "分析结果异常数统计")
@RestController
@RequestMapping("/analysisErr")
public class AnalysisErrController extends BaseServiceController {

    @Autowired
    private AnalysisErrService analysisErrService;

    @UserLoginToken
    @ApiOperation(value = "异常查询")
    @GetMapping("/analysisErrQuery")
    public ResultResp<Page<WindExceptionCountVo>> analysisErrQuery(WindExceptionCountDto windExceptionCountDto)
    {
        return pageResult(analysisErrService.analysisErrQuery(windExceptionCountDto),windExceptionCountDto);
    }

    @UserLoginToken
    @ApiOperation(value = "异常添加")
    @PostMapping("/analysisErrAdd")
    public ResultResp analysisErrAdd(@RequestBody WindExceptionCountDto windExceptionCountDto)
    {
        Integer loginUserId = getUserId();
        windExceptionCountDto.setCreateBy(loginUserId);
        windExceptionCountDto.setUpdateBy(loginUserId);
        return analysisErrService.analysisErrAdd(windExceptionCountDto);
    }

    @UserLoginToken
    @ApiOperation(value = "异常编辑")
    @PostMapping("/analysisErrEdit")
    public ResultResp analysisErrEdit(@RequestBody WindExceptionCountDto windExceptionCountDto)
    {
        windExceptionCountDto.setUpdateBy(getUserId());
        return success(analysisErrService.analysisErrEdit(windExceptionCountDto));
    }

    @UserLoginToken
    @ApiOperation(value = "异常删除")
    @PostMapping("/analysisErrDel")
    public ResultResp analysisErrDel(@RequestBody WindExceptionCountDto windExceptionCountDto)
    {
        windExceptionCountDto.setUpdateBy(getUserId());
        return success(analysisErrService.analysisErrDel(windExceptionCountDto));
    }

    @UserLoginToken
    @ApiOperation(value = "查询风机异常信息")
    @GetMapping("/queryErrDescByEngine")
    public ResultResp queryErrDescByEngine(@RequestParam(name = "batchCode") String batchCode,
                                           @RequestParam(name = "engineCode") String engineCode)
    {
        return success(analysisErrService.queryErrDescByEngine(batchCode,engineCode));
    }
}
