package com.njcn.process.controller;


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.MonitorParam;
import com.njcn.process.pojo.param.StrategyParam;
import com.njcn.process.pojo.po.ThsWarnStrategy;
import com.njcn.process.service.ThsWarnStrategyService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wr
 * @since 2023-03-10
 */
@RestController
@RequestMapping("/process/thsWarnStrategy")
@Api(tags = "预警单策略|告警单策略")
@RequiredArgsConstructor
public class ThsWarnStrategyController extends BaseController {

    private final ThsWarnStrategyService thsWarnStrategyService;

    @PostMapping("/getStrategyPage")
    @ApiOperation("分页查询")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    public HttpResult<Page<ThsWarnStrategy>> getStrategyPage(@RequestBody @Validated StrategyParam.StrategyPageParam param) {
        String methodDescribe = getMethodDescribe("getStrategyPage");
        Page<ThsWarnStrategy> page = thsWarnStrategyService.strategyPage(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }

    @PostMapping("/getStrategyList")
    @ApiOperation("数据查询")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    public HttpResult<List<ThsWarnStrategy>> strategyList(@RequestBody @Validated StrategyParam.StrategyPageParam param) {
        String methodDescribe = getMethodDescribe("getStrategyPage");
        List<ThsWarnStrategy> list = thsWarnStrategyService.strategyList(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @PostMapping("/insertStrategy")
    @ApiOperation(value = "数据添加")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    public HttpResult<Boolean> insertStrategy(@RequestBody @Validated StrategyParam.StrategyInsertParam param) {
        String methodDescribe = getMethodDescribe("insertStrategy");
        Boolean flag = thsWarnStrategyService.insertStrategy(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @PostMapping("/bindStrategy")
    @ApiOperation(value = "信息绑定")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    public HttpResult<Boolean> bindStrategy(@RequestBody @Validated StrategyParam.BindParam param) {
        String methodDescribe = getMethodDescribe("bindStrategy");
        Boolean flag = thsWarnStrategyService.bindStrategy(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @PostMapping("/getUpdateStrategy")
    @ApiOperation(value = "详细查询")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    public HttpResult<StrategyParam.StrategyUpdateParam> getUpdateStrategy(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getUpdateStrategy");
        StrategyParam.StrategyUpdateParam updateStrategy = thsWarnStrategyService.getUpdateStrategy(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, updateStrategy, methodDescribe);
    }

    @PostMapping("/updateStrategy")
    @ApiOperation(value = "信息修改")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    public HttpResult<Boolean> updateStrategy(@RequestBody @Validated StrategyParam.StrategyUpParam param) {
        String methodDescribe = getMethodDescribe("updateStrategy");
        Boolean flag = thsWarnStrategyService.updateStrategy(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @PostMapping("/updateStrategyState")
    @ApiOperation(value = "修改状态")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    public HttpResult<Boolean> updateStrategyState(@RequestBody @Validated StrategyParam.StrategyStateParam param) {
        String methodDescribe = getMethodDescribe("updateStrategyState");
        Boolean flag = thsWarnStrategyService.updateStrategyState(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @GetMapping("/getMonitor")
    @ApiOperation(value = "监测点查询接口")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    public HttpResult<List<StrategyParam.MonitorTree>> getMonitor(@Param("orgId") String orgId) {
        String methodDescribe = getMethodDescribe("getMonitor");
        List<StrategyParam.MonitorTree> monitor = thsWarnStrategyService.getMonitor( orgId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, monitor, methodDescribe);
    }

    @PostMapping("/bindMonitor")
    @ApiOperation(value = "监测点绑定")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    public HttpResult<Boolean> bindMonitor(@RequestBody @Validated MonitorParam param) {
        String methodDescribe = getMethodDescribe("bindMonitor");
        Boolean flag = thsWarnStrategyService.bindMonitor(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @GetMapping("/echoMonitor")
    @ApiOperation(value = "监测点回显")
    public HttpResult<StrategyParam.MonitorTree> echoMonitor(@Param("deptId") String deptId,
                                                             @Param("type") Integer type,
                                                             @Param("grade") Integer grade) {
        String methodDescribe = getMethodDescribe("echoMonitor");
        StrategyParam.MonitorTree info = thsWarnStrategyService.echoMonitor(deptId, type,grade);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, info, methodDescribe);
    }

    @PostMapping("/delStrategy")
    @ApiOperation(value = "信息删除")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    public HttpResult<Boolean> delStrategy(String ids) {
        String methodDescribe = getMethodDescribe("delStrategy");
        Boolean flag = thsWarnStrategyService.delStrategy(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

}

