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.AppProjectAddParm;
import com.njcn.csdevice.pojo.param.AppProjectAuditParm;
import com.njcn.csdevice.pojo.param.AppProjectQueryParm;
import com.njcn.csdevice.pojo.po.AppProjectPO;
import com.njcn.csdevice.pojo.vo.AppProjectVO;
import com.njcn.csdevice.service.AppProjectService;
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("/project")
@Api(tags = " 项目管理")
@AllArgsConstructor
public class AppProjectController  extends BaseController {


    private final AppProjectService appProjectService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryProject")
    @ApiOperation("项目查询")
    @ApiImplicitParam(name = "appProjectQueryParm", value = "项目查询参数", required = true)
    public HttpResult<IPage<AppProjectVO>> queryProject(@Validated @RequestBody AppProjectQueryParm appProjectQueryParm){
        String methodDescribe = getMethodDescribe("queryProject");

        IPage<AppProjectVO> appProjectVOIPage  = appProjectService.queryProject (appProjectQueryParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, appProjectVOIPage, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryProjectById")
    @ApiOperation("项目查询通过id获取")
    @ApiImplicitParam(name = "ids", value = "项目id集合", required = true)
    public HttpResult<List<AppProjectPO>> queryProjectById(@RequestParam List<String> ids){
        String methodDescribe = getMethodDescribe("queryProject");
        List<AppProjectPO> appProjectPOS = appProjectService.listByIds(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, appProjectPOS, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/addAppProject")
    @ApiOperation("新增项目")
    public HttpResult<AppProjectPO> addAppProject(@Validated AppProjectAddParm appProjectAddParm){
        String methodDescribe = getMethodDescribe("addAppProject");
        AppProjectPO po = appProjectService.addAppProject(appProjectAddParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/addPortableProject")
    @ApiOperation("新增便携式项目")
    public HttpResult<AppProjectPO> addPortableProject(@Validated @RequestBody AppProjectAddParm appProjectAddParm){
        String methodDescribe = getMethodDescribe("addPortableProject");
        AppProjectPO po = appProjectService.addAppProject(appProjectAddParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/auditAppProject")
    @ApiOperation("修改/删除项目")
    public HttpResult<Boolean> auditAppProject(@Validated AppProjectAuditParm appProjectAuditParm){
        String methodDescribe = getMethodDescribe("auditAppProject");

        Boolean flag = appProjectService.AuditAppProject(appProjectAuditParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/updateProject")
    @ApiOperation("web修改项目信息")
    public HttpResult<Boolean> updateProject(@RequestBody @Validated AppProjectAuditParm appProjectAuditParm){
        String methodDescribe = getMethodDescribe("updateProject");
        Boolean flag = appProjectService.updateProject(appProjectAuditParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

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

}
