package com.njcn.process.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.process.pojo.param.SupvAlarmParam;
import com.njcn.process.pojo.po.SupvAlarm;
import com.njcn.process.service.ISupvAlarmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.njcn.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wr
 * @since 2023-09-01
 */
@RestController
@Api(tags ="预告警单")
@RequestMapping("/supvAlarm")
@RequiredArgsConstructor
public class SupvAlarmController extends BaseController {

    private final ISupvAlarmService supvAlarmService;

    @PostMapping("addAlarm")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @ApiOperation("新增预告警单")
    public HttpResult<Boolean> addAlarm(@RequestBody @Validated SupvAlarmParam.AlarmInsert insert){
        String methodDescribe = getMethodDescribe("addAlarm");
        Boolean b = supvAlarmService.addAlarm(insert);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, b, methodDescribe);
    }

    @PostMapping("updateAlarm")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @ApiOperation("修改预告警单")
    public HttpResult<Boolean> updateAlarm(@RequestBody @Validated SupvAlarmParam.AlarmUpdate update){
        String methodDescribe = getMethodDescribe("updateAlarm");
        Boolean b = supvAlarmService.updateAlarm(update);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, b, methodDescribe);
    }

    @PostMapping("delAlarm")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @ApiOperation("删除预告警单")
    @ApiImplicitParam(name = "planIds",value = "监督计划索引集合",required = true)
    public HttpResult<Boolean> delAlarm(@RequestBody List<String> planIds){
        String methodDescribe = getMethodDescribe("delAlarm");
        Boolean b = supvAlarmService.delAlarm(planIds);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, b, methodDescribe);
    }

    @PostMapping("/downAlarm")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("导出预告警单信息")
    public void downAlarm(){
        supvAlarmService.downAlarm();
    }

    @PostMapping("pageAlarm")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("分页查询预告警单")
    @ApiImplicitParam(name = "param",value = "请求体",required = true)
    public HttpResult<Page<SupvAlarm>> pageAlarm(@RequestBody SupvAlarmParam param){
        String methodDescribe = getMethodDescribe("pageAlarm");
        Page<SupvAlarm> supvPlanHisPage = supvAlarmService.pageAlarm(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, supvPlanHisPage, methodDescribe);
    }

    @GetMapping("/selectAlarmList")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("预告警单下拉")
    public HttpResult<List<SupvAlarm>> selectAlarmList(){
        String methodDescribe = getMethodDescribe("selectAlarmList");
        LambdaQueryWrapper<SupvAlarm> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.select(SupvAlarm::getAlarmId,SupvAlarm::getBillNo,SupvAlarm::getBillName).orderByDesc(SupvAlarm::getCreaterTime);
        List<SupvAlarm> result = supvAlarmService.list(lambdaQueryWrapper);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

}

