package com.njcn.prepare.harmonic.controller.line;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.prepare.harmonic.pojo.param.LineParam;
import com.njcn.prepare.harmonic.service.mysql.area.IRMpMonitorAlarmCountMService;
import com.njcn.prepare.harmonic.service.mysql.area.RMpTargetWarnDService;
import com.njcn.prepare.harmonic.service.mysql.line.AlarmDetailService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author qijian
 * @date 2022/12/28
 * 监测点指标告警明细
 */
@Validated
@Slf4j
@RestController
@RequestMapping("/alarmDetail")
@Api(tags = "监测点指标告警明细")
@AllArgsConstructor
public class AlarmDetailController extends BaseController {

    private final AlarmDetailService alarmDetailService;

    private final RMpTargetWarnDService rMpTargetWarnDService;

    private final IRMpMonitorAlarmCountMService rMpMonitorAlarmCountMService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @PostMapping("/alarmDetailAlarm")
    @ApiOperation("监测点指标告警日统计")
    @ApiImplicitParam(name = "lineParam", value = "算法通用查询参数", required = true)
    public HttpResult<Boolean> alarmDetailAlarm(@RequestBody @Validated LineParam lineParam) {
        String methodDescribe = getMethodDescribe("alarmDetailAlarm");
        boolean res = alarmDetailService.alarmDetailAlarm(lineParam);
        if(res){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }

    /**
     * @author xuyang
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @PostMapping("/targetDiff")
    @ApiOperation("监测点稳态指标差值日统计")
    @ApiImplicitParam(name = "lineParam", value = "算法通用查询参数", required = true)
    public HttpResult<Boolean> targetDiff(@RequestBody @Validated LineParam lineParam) {
        String methodDescribe = getMethodDescribe("targetDiff");
        alarmDetailService.targetDiff(lineParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @PostMapping("/alarmDay")
    @ApiOperation("监测点指标告警日统计(新)")
    @ApiImplicitParam(name = "lineParam", value = "算法通用查询参数", required = true)
    public HttpResult<Boolean> alarmDay(@RequestBody @Validated LineParam lineParam) {
        String methodDescribe = getMethodDescribe("alarmDay");
        rMpTargetWarnDService.alarmDay(lineParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @PostMapping("/alarmMonth")
    @ApiOperation("监测点指标告警月统计(新)")
    @ApiImplicitParam(name = "lineParam", value = "算法通用查询参数", required = true)
    public HttpResult<Boolean> alarmMonth(@RequestBody @Validated LineParam lineParam) {
        String methodDescribe = getMethodDescribe("alarmMonth");
        rMpMonitorAlarmCountMService.alarmMonth(lineParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }
}
