package com.njcn.csdevice.controller.equipment;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.njcn.common.pojo.annotation.OperateInfo;
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.csdevice.pojo.param.CsDevModelAddParm;
import com.njcn.csdevice.pojo.param.CsDevModelAuditParm;
import com.njcn.csdevice.pojo.param.CsDevModelQueryListParm;
import com.njcn.csdevice.pojo.param.CsDevModelQueryParm;
import com.njcn.csdevice.pojo.po.CsDevModelPO;
import com.njcn.csdevice.pojo.vo.CsDevModelPageVO;
import com.njcn.csdevice.service.CsDevModelService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
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.*;

import java.util.List;

/**
 * Description:
 * 接口文档访问地址：http://serverIP:port/swagger-ui.html
 * Date: 2023/3/27  15:31【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/devmodel")
@Api(tags = "设备模板")
@AllArgsConstructor
public class DevModelController extends BaseController {

    private final CsDevModelService csDevModelService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/addDevModel")
    @ApiOperation("新增设备模板")
    @ApiImplicitParam(name = "csDevModelAddParm", value = "新增设备模板参数", required = true)
    @Deprecated
    public HttpResult<CsDevModelPO> addDevModel(@RequestBody @Validated CsDevModelAddParm csDevModelAddParm) {
        String methodDescribe = getMethodDescribe("addDevModel");
        CsDevModelPO flag = csDevModelService.addDevModel(csDevModelAddParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/AuditDevModel")
    @ApiOperation("更新/删除设备模板参数")
    @ApiImplicitParam(name = "csDevModelAuditParm", value = "更新/删除设备模板参数", required = true)
    public HttpResult<Boolean> AuditDevModel(@RequestBody @Validated CsDevModelAuditParm csDevModelAuditParm) {
        String methodDescribe = getMethodDescribe("AuditDevModel");

        Boolean flag = csDevModelService.AuditDevModel(csDevModelAuditParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryDevModelPage")
    @ApiOperation("设备模板分页查询")
    @ApiImplicitParam(name = "csDevModelQueryParm", value = "设备模板查询参数", required = true)
    public HttpResult<IPage<CsDevModelPageVO>> queryDevModelPage(@RequestBody @Validated CsDevModelQueryParm csDevModelQueryParm) {
        String methodDescribe = getMethodDescribe("queryDevModelPage");

        IPage<CsDevModelPageVO> page = csDevModelService.queryPage(csDevModelQueryParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryDevModelOne")
    @ApiOperation("设备模板查询")
    @ApiImplicitParam(name = "csDevModelQueryListParm", value = "设备模板信息", required = true)
    public HttpResult<CsDevModelPageVO> queryDevModelOne(@RequestBody CsDevModelQueryListParm csDevModelQueryListParm) {
        String methodDescribe = getMethodDescribe("queryDevModelOne");

        CsDevModelPageVO csDevModelPageVO = csDevModelService.queryDevModelOne(csDevModelQueryListParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, csDevModelPageVO, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/findModel")
    @ApiOperation("根据条件查询模板")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "devType", value = "装置类型", required = true),
            @ApiImplicitParam(name = "version", value = "版本", required = true),
            @ApiImplicitParam(name = "time", value = "时间", required = true)
    })
    public HttpResult<CsDevModelPO> findModel(@RequestParam("devType") String devType, @RequestParam("version") String version, @RequestParam("time") String time) {
        String methodDescribe = getMethodDescribe("findModel");
        CsDevModelPO csDevModelPo = csDevModelService.findModel(devType, version, time);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, csDevModelPo, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getModelById")
    @ApiOperation("根据模板Id获取模板数据")
    @ApiImplicitParam(name = "id", value = "模板id", required = true)
    public HttpResult<CsDevModelPO> getModelById(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getModelById");
        CsDevModelPO po = csDevModelService.getModelById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
    }
}
