package com.njcn.csdevice.controller.project;

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.CsEdDataAddParm;
import com.njcn.csdevice.pojo.param.CsEdDataAuditParm;
import com.njcn.csdevice.pojo.param.CsEdDataQueryParm;
import com.njcn.csdevice.pojo.po.CsEdDataPO;
import com.njcn.csdevice.pojo.vo.CsEdDataVO;
import com.njcn.csdevice.service.CsEdDataService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
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.*;

/**
 * Description:
 * 接口文档访问地址：http://serverIP:port/swagger-ui.html
 * Date: 2023/4/4  9:02【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/edData")
@Api(tags = "app版本信息")
@AllArgsConstructor
public class CsEdDataController extends BaseController {

    private final CsEdDataService csEdDataService;


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/addEdData")
    @ApiOperation("新增app版本信息")
    public HttpResult<Boolean> addEdData(@Validated CsEdDataAddParm csEdDataAddParm){
        String methodDescribe = getMethodDescribe("addEdData");

        boolean save = csEdDataService.addEdData (csEdDataAddParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, save, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/auditEdData")
    @ApiOperation("修改/删除app版本信息")
    public HttpResult<Boolean> auditEdData(@Validated CsEdDataAuditParm csEdDataAuditParm){
        String methodDescribe = getMethodDescribe("auditEdData");

        Boolean flag = csEdDataService.auditEdData(csEdDataAuditParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryEdDataPage")
    @ApiOperation("版本信息查询")
    @ApiImplicitParam(name = "csEdDataQueryParm", value = "查询参数", required = true)
    public HttpResult<IPage<CsEdDataVO>> queryEdDataPage(@Validated @RequestBody CsEdDataQueryParm csEdDataQueryParm){
        String methodDescribe = getMethodDescribe("queryEdDataPage");

        IPage<CsEdDataVO> page  = csEdDataService.queryEdDataPage (csEdDataQueryParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/findByDevTypeId")
    @ApiOperation("根据装置型号获取装置类型")
    @ApiImplicitParam(name = "devType", value = "装置型号", required = true)
    public HttpResult<CsEdDataVO> findByDevTypeId(@Validated @RequestParam("devType") String devType){
        String methodDescribe = getMethodDescribe("findByDevTypeId");
        CsEdDataVO vo  = csEdDataService.findByDevTypeId(devType);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getById")
    @ApiOperation("根据id查询")
    @ApiImplicitParam(name = "id", value = "id", required = true)
    public HttpResult<CsEdDataPO> getById(@Validated @RequestParam("id") String id){
        String methodDescribe = getMethodDescribe("getById");
        CsEdDataPO dataPO = csEdDataService.getById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, dataPO, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/findByCondition")
    @ApiOperation("根据条件查询是否存在数据")
    @ApiImplicitParam(name = "param", value = "param", required = true)
    public HttpResult<CsEdDataPO> findByCondition(@RequestBody CsEdDataQueryParm param){
        String methodDescribe = getMethodDescribe("findByCondition");
        CsEdDataPO po = csEdDataService.findByCondition(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/addEdDataFirst")
    @ApiOperation("首次录入版本信息")
    @ApiImplicitParam(name = "param", value = "param", required = true)
    public HttpResult<CsEdDataPO> addEdDataFirst(@RequestBody CsEdDataAddParm param){
        String methodDescribe = getMethodDescribe("addEdDataFirst");
        csEdDataService.addEdDataFirst(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/findByPath")
    @ApiOperation("根据文件路径获取版本信息")
    @ApiImplicitParam(name = "filePath", value = "filePath", required = true)
    public HttpResult<CsEdDataPO> findByPath(@RequestParam("filePath") String filePath){
        String methodDescribe = getMethodDescribe("findByPath");
        CsEdDataPO po = csEdDataService.findByPath(filePath);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
    }

}
