package com.njcn.advance.controller.govern.voltage;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.advance.pojo.param.govern.voltage.SgGovernSchemeHistoryParam;
import com.njcn.advance.pojo.vo.govern.voltage.SgGovernSchemeHistoryAllVO;
import com.njcn.advance.pojo.vo.govern.voltage.SgGovernSchemeHistoryVO;
import com.njcn.advance.service.govern.voltage.IGovernSchemeCalcService;
import com.njcn.advance.service.govern.voltage.ISgGovernSchemeHistoryService;
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.common.utils.LogUtil;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
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;

/**
 * @author hongawen
 */
@Slf4j
@Validated
@RestController
@Api(tags = "暂降治理评估控制器")
@RequestMapping("/sagGovernScheme")
@RequiredArgsConstructor
public class SagGovernSchemeController extends BaseController {

    private final IGovernSchemeCalcService governSchemeCalcService;

    private final ISgGovernSchemeHistoryService sgGovernSchemeHistoryService;


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/calc")
    @ApiOperation("根据治理参数，进行暂降治理评估")
    @ApiImplicitParam(name = "sgGovernSchemeHistoryParam", value = "计算参数", required = true)
    public HttpResult<SgGovernSchemeHistoryAllVO> calc(@RequestBody SgGovernSchemeHistoryParam sgGovernSchemeHistoryParam ) {
        String methodDescribe = getMethodDescribe("calc");
        LogUtil.njcnDebug(log, "{}，查询数据为：{}", methodDescribe, sgGovernSchemeHistoryParam);
        SgGovernSchemeHistoryAllVO sgGovernSchemeHistoryAllVO = governSchemeCalcService.calc(sgGovernSchemeHistoryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, sgGovernSchemeHistoryAllVO, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/list")
    @ApiOperation("查询历史治理方案")
    @ApiImplicitParam(name = "SgSchemeHistoryQueryParam", value = "查询参数", required = true)
    public HttpResult<Page<SgGovernSchemeHistoryVO>> list(@RequestBody  SgGovernSchemeHistoryParam.SgSchemeHistoryQueryParam sgSchemeHistoryQueryParam) {
        String methodDescribe = getMethodDescribe("list");
        LogUtil.njcnDebug(log, "{}，查询数据为：{}", methodDescribe, sgSchemeHistoryQueryParam);
        Page<SgGovernSchemeHistoryVO> result = sgGovernSchemeHistoryService.schemeHistoryList(sgSchemeHistoryQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    @PostMapping("/delete")
    @ApiOperation("删除治理方案")
    @ApiImplicitParam(name = "ids", value = "治理方案索引", required = true, dataTypeClass = List.class)
    public HttpResult<Object> delete(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("delete");
        LogUtil.njcnDebug(log, "{}，业务用户ID数据为：{}", methodDescribe, String.join(StrUtil.COMMA, ids));
        boolean result = sgGovernSchemeHistoryService.deleteScheme(ids);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/detail")
    @ApiOperation("根据治理方案索引，查询详细数据回显")
    public HttpResult<SgGovernSchemeHistoryAllVO> detail(String id) {
        String methodDescribe = getMethodDescribe("detail");
        LogUtil.njcnDebug(log, "{}，治理方案索引为：{}", methodDescribe, id);
        SgGovernSchemeHistoryAllVO sgGovernSchemeHistoryAllVO = governSchemeCalcService.detail(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, sgGovernSchemeHistoryAllVO, methodDescribe);
    }


}
