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.CsEngineeringAddParm;
import com.njcn.csdevice.pojo.param.CsEngineeringAuditParm;
import com.njcn.csdevice.pojo.param.CsEngineeringQueryPageParm;
import com.njcn.csdevice.pojo.param.CsEngineeringQueryParm;
import com.njcn.csdevice.pojo.po.CsEngineeringPO;
import com.njcn.csdevice.pojo.vo.CsEngineeringVO;
import com.njcn.csdevice.service.CsEngineeringService;
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.*;

import java.util.List;

/**
 * Description:
 * 接口文档访问地址：http://serverIP:port/swagger-ui.html
 * Date: 2023/3/27  10:54【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/engineering")
@Api(tags = " 工程管理")
@AllArgsConstructor
public class EngineeringController extends BaseController {

    private final CsEngineeringService csEngineeringService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/addEngineering")
    @ApiOperation("新增工程")
    @ApiImplicitParam(name = "csEngineeringAddParm", value = "新增工程参数", required = true)
    public HttpResult<CsEngineeringPO> addEngineering(@Validated @RequestBody CsEngineeringAddParm csEngineeringAddParm){
        String methodDescribe = getMethodDescribe("addEngineering");

        CsEngineeringPO flag = csEngineeringService.addEngineering(csEngineeringAddParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/auditEngineering")
    @ApiOperation("修改/删除工程")
    @ApiImplicitParam(name = "csEngineeringAuditParm", value = "修改项目参数", required = true)
    public HttpResult<Boolean> auditEngineering(@Validated @RequestBody CsEngineeringAuditParm csEngineeringAuditParm){
        String methodDescribe = getMethodDescribe("auditEngineering");

        Boolean flag = csEngineeringService.auditEngineering(csEngineeringAuditParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryEngineering")
    @ApiOperation("查询工程列表")
    @ApiImplicitParam(name = "csEngineeringQueryParm", value = "修改项目参数", required = true)
    public HttpResult<List<CsEngineeringVO>> queryEngineering(@Validated @RequestBody CsEngineeringQueryParm csEngineeringQueryParm){
        String methodDescribe = getMethodDescribe("queryEngineering");

        List<CsEngineeringVO> csEngineeringVOList = csEngineeringService.queryEngineering(csEngineeringQueryParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, csEngineeringVOList, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryEngineeringPage")
    @ApiOperation("分页查询工程列表")
    @ApiImplicitParam(name = "csEngineeringQueryPageParm", value = "修改项目参数", required = true)
    public HttpResult<IPage<CsEngineeringVO>> queryEngineeringPage(@Validated @RequestBody CsEngineeringQueryPageParm csEngineeringQueryPageParm){
        String methodDescribe = getMethodDescribe("queryEngineeringPage");

        IPage<CsEngineeringVO> page = csEngineeringService.queryEngineeringPage(csEngineeringQueryPageParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryEngineeringById")
    @ApiOperation("工程查询通过id获取")
    @ApiImplicitParam(name = "id", value = "工程id", required = true)
    public HttpResult<CsEngineeringPO> queryEngineeringById(@RequestParam String id){
        String methodDescribe = getMethodDescribe("queryEngineeringById");
        CsEngineeringPO po = csEngineeringService.queryEngineeringById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getUnlinkedEngineering")
    @ApiOperation("获取用户未绑定的工程信息")
    @ApiImplicitParam(name = "userId", value = "用户id", required = true)
    public HttpResult<List<CsEngineeringPO>> getUnlinkedEngineering(@RequestParam("userId") String userId){
        String methodDescribe = getMethodDescribe("getUnlinkedEngineering");
        List<CsEngineeringPO> result = csEngineeringService.getUnlinkedEngineering(userId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getEngineeringByName")
    @ApiOperation("根据工程名称获取工程信息")
    @ApiImplicitParam(name = "name", value = "工程名称", required = true)
    public HttpResult<CsEngineeringPO> getEngineeringByName(@RequestParam("name") String name){
        String methodDescribe = getMethodDescribe("getEngineeringByName");
        CsEngineeringPO po = csEngineeringService.getEngineeringByName(name);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
    }

}
