package com.njcn.device.pq.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.device.pq.pojo.dto.CvtHarmonicCorrectionFactorsDTO;
import com.njcn.device.pq.pojo.param.CvtHarmonicCorrectionFactorsParam;
import com.njcn.device.pq.pojo.param.NodeParam;
import com.njcn.device.pq.pojo.po.CvtHarmonicCorrectionFactors;
import com.njcn.device.pq.pojo.vo.CvtHarmonicCorrectionFactorsVO;
import com.njcn.device.pq.service.CvtHarmonicCorrectionFactorsService;
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.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description:
 * Date: 2025/02/10  下午 1:53【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Validated
@Slf4j
@Api(tags = "cvt系数配置")
@RestController
@RequestMapping("/cvt")
@RequiredArgsConstructor
public class CvtHarmonicCorrectionFactorsController extends BaseController {

    private final CvtHarmonicCorrectionFactorsService cvtHarmonicCorrectionFactorsService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @ApiOperation("新增cvt系数")
    @ApiImplicitParam(value = "cvt系数信息",name = "cvtHarmonicCorrectionFactorsParam",required = true)
    @PostMapping("add")
    public HttpResult<Boolean> add(@Validated @RequestBody CvtHarmonicCorrectionFactorsParam cvtHarmonicCorrectionFactorsParam){
        String methodDescribe = getMethodDescribe("add");
        boolean result = cvtHarmonicCorrectionFactorsService.add(cvtHarmonicCorrectionFactorsParam);
        if (result){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
        }
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @ApiOperation("修改cvt系数")
    @ApiImplicitParam(value = "cvt系数信息",name = "updateParam",required = true)
    @PostMapping("updateCvt")
    public HttpResult<Boolean> updateCvt(@Validated @RequestBody CvtHarmonicCorrectionFactorsParam.CvtHarmonicCorrectionFactorsParamUpdateParam updateParam){
        String methodDescribe = getMethodDescribe("updateCvt");
        boolean result = cvtHarmonicCorrectionFactorsService.updateCvt(updateParam);
        if (result){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
        }
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @ApiOperation("分页查询")
    @ApiImplicitParam(value = "cvt系数信息",name = "queryParam",required = true)
    @PostMapping("queryPage")
    public HttpResult<Page<CvtHarmonicCorrectionFactorsVO>> queryPage(@Validated @RequestBody CvtHarmonicCorrectionFactorsParam.CvtHarmonicCorrectionFactorsParamQueryParam queryParam){
        String methodDescribe = getMethodDescribe("queryPage");
        Page<CvtHarmonicCorrectionFactorsVO> result = cvtHarmonicCorrectionFactorsService.queryPage(queryParam);

        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);

    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @ApiOperation("列表查询")
    @PostMapping("queryList")
    public HttpResult<List<CvtHarmonicCorrectionFactorsDTO>> queryList( @Validated @RequestBody CvtHarmonicCorrectionFactorsParam.CvtHarmonicCorrectionFactorsParamQueryParam queryParam){
        String methodDescribe = getMethodDescribe("queryList");
        List<CvtHarmonicCorrectionFactorsDTO> result = cvtHarmonicCorrectionFactorsService.queryList(queryParam);

        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);

    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @ApiOperation("根据id查询")
    @PostMapping("queryById")
    public HttpResult<CvtHarmonicCorrectionFactorsDTO> queryById( @RequestParam String id){
        String methodDescribe = getMethodDescribe("queryById");
        CvtHarmonicCorrectionFactorsDTO result = new CvtHarmonicCorrectionFactorsDTO();
        CvtHarmonicCorrectionFactors cvt = cvtHarmonicCorrectionFactorsService.getById(id);
        BeanUtils.copyProperties(result,cvt);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);

    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @ApiOperation("根据id删除")
    @PostMapping("deleteById")
    public HttpResult<Boolean> deleteById( @RequestParam String id){
        String methodDescribe = getMethodDescribe("deleteById");
        boolean result = cvtHarmonicCorrectionFactorsService.removeById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);

    }
}
