package com.njcn.csdevice.controller.equipment;


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.CsDevModelRelationAddParm;
import com.njcn.csdevice.pojo.param.CsDevModelRelationAuidtParm;
import com.njcn.csdevice.pojo.param.CsDevModelRelationQueryParm;
import com.njcn.csdevice.pojo.po.CsDevModelRelationPO;
import com.njcn.csdevice.pojo.vo.CsDevModelRelationVO;
import com.njcn.csdevice.service.CsDevModelRelationService;
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 springfox.documentation.annotations.ApiIgnore;

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("/devmodelRelation")
@Api(tags = "设备模板关联")
@AllArgsConstructor
public class DevModelRelationController extends BaseController {

    private final CsDevModelRelationService csDevModelRelationService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/addDevModelRelation")
    @ApiOperation("绑定设备与模板")
    @ApiImplicitParam(name = "addParm", value = "新增参数", required = true)
    public HttpResult<CsDevModelRelationPO> addDevModelRelation(@RequestBody @Validated CsDevModelRelationAddParm addParm){
        String methodDescribe = getMethodDescribe("addDevModelRelation");
        CsDevModelRelationPO flag = csDevModelRelationService.addDevModelRelation (addParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/AuditDevModelRelation")
    @ApiOperation("更新/删除出厂设备")
    @ApiImplicitParam(name = "auditParm", value = "更新/删除参数", required = true)
    public HttpResult<Boolean> AuditDevModelRelation(@RequestBody @Validated CsDevModelRelationAuidtParm auditParm ){
        String methodDescribe = getMethodDescribe("AuditDevModelRelation");

        Boolean flag = csDevModelRelationService.AuditDevModelRelation(auditParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }





    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryDevModelRelationList")
    @ApiOperation("设备模板查询")
    @ApiImplicitParam(name = "queryParm", value = "查询参数", required = true)
    public HttpResult<List<CsDevModelRelationVO>> queryDevModelRelationList(@RequestBody CsDevModelRelationQueryParm queryParm){
        String methodDescribe = getMethodDescribe("queryDevModelRelationList");

        List<CsDevModelRelationVO> list  = csDevModelRelationService.queryDevModelRelation(queryParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getModelByDevId")
    @ApiOperation("根据装置Id查询模板")
    @ApiImplicitParam(name = "devId", value = "装置id", required = true)
    public HttpResult<List<CsDevModelRelationPO>> getModelByDevId(@RequestParam("devId") String devId){
        String methodDescribe = getMethodDescribe("getModelByDevId");
        List<CsDevModelRelationPO> list  = csDevModelRelationService.findModelByDevId(devId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getModelByType")
    @ApiOperation("根据装置类型查询模板")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "devId", value = "装置id", required = true),
            @ApiImplicitParam(name = "type", value = "模板类型", required = true)
    })
    @ApiIgnore
    public HttpResult<String> getModelByType(@RequestParam("devId") String devId, @RequestParam("type") Integer type){
        String methodDescribe = getMethodDescribe("getModelByType");
        String modelId  = csDevModelRelationService.getModelByType(devId,type);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, modelId, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/updateDataByList")
    @ApiOperation("根据装置集合修改模板信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "装置id集合", required = true),
            @ApiImplicitParam(name = "id", value = "模板id", required = true)
    })
    @ApiIgnore
    public HttpResult<String> updateDataByList(@RequestParam("list") List<String> list, @RequestParam("id") String id){
        String methodDescribe = getMethodDescribe("updateDataByList");
        csDevModelRelationService.updateDataByList(list,id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

}
