package cn.com.tenlion.projectconfig.controller.api.projectconfig;

import com.sun.org.apache.xpath.internal.operations.Bool;
import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.pojo.result.SuccessResultData;
import ink.wgink.pojo.result.SuccessResultList;
import cn.com.tenlion.projectconfig.pojo.dtos.projectconfig.ProjectConfigDTO;
import cn.com.tenlion.projectconfig.pojo.vos.projectconfig.ProjectConfigVO;
import cn.com.tenlion.projectconfig.service.projectconfig.IProjectConfigService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: ProjectConfigController
 * @Description: CBC项目配置管理表
 * @Author: CodeFactory
 * @Date: 2021-08-12 13:54:56
 * @Version: 3.0
 **/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "CBC项目配置管理表接口")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/projectconfig")
public class ProjectConfigController extends DefaultBaseController {

    @Autowired
    private IProjectConfigService projectConfigService;

    @ApiOperation(value = "修改CBC项目配置管理表", notes = "修改CBC项目配置管理表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectConfigId", value = "CBC项目配置管理表ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updateswitch/{projectConfigId}/{projectConfigSwitch}")
    @CheckRequestBodyAnnotation
    public SuccessResult updateSwitch(@PathVariable("projectConfigId") String projectConfigId, @PathVariable("projectConfigSwitch") Boolean projectConfigSwitch) {
        projectConfigService.updateSwitch(projectConfigId, projectConfigSwitch);
        return new SuccessResult();
    }

    @ApiOperation(value = "新增CBC项目配置管理表", notes = "新增CBC项目配置管理表接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("save")
    @CheckRequestBodyAnnotation
    public SuccessResult save(@RequestBody ProjectConfigVO projectConfigVO) {
        projectConfigService.save(projectConfigVO);
        return new SuccessResult();
    }

    @ApiOperation(value = "删除CBC项目配置管理表", notes = "删除CBC项目配置管理表接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "ids", value = "ID列表，用下划线分隔", paramType = "path", example = "1_2_3")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @DeleteMapping("remove/{ids}")
    public SuccessResult remove(@PathVariable("ids") String ids) {
        projectConfigService.remove(Arrays.asList(ids.split("\\_")));
        return new SuccessResult();
    }

    @ApiOperation(value = "修改CBC项目配置管理表", notes = "修改CBC项目配置管理表接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "projectConfigId", value = "CBC项目配置管理表ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("update/{projectConfigId}")
    @CheckRequestBodyAnnotation
    public SuccessResult update(@PathVariable("projectConfigId") String projectConfigId, @RequestBody ProjectConfigVO projectConfigVO) {
        projectConfigService.update(projectConfigId, projectConfigVO);
        return new SuccessResult();
    }

    @ApiOperation(value = "CBC项目配置管理表详情", notes = "CBC项目配置管理表详情接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "projectConfigId", value = "CBC项目配置管理表ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("get/{projectConfigId}")
        public ProjectConfigDTO get(@PathVariable("projectConfigId") String projectConfigId) {
        return projectConfigService.get(projectConfigId);
    }

    @ApiOperation(value = "CBC项目配置管理表列表", notes = "CBC项目配置管理表列表接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list")
    public List<ProjectConfigDTO> list() {
        Map<String, Object> params = requestParams();
        return projectConfigService.list(params);
    }

    @ApiOperation(value = "CBC项目配置管理表分页列表", notes = "CBC项目配置管理表分页列表接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
        @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
        @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpage")
    public SuccessResultList<List<ProjectConfigDTO>> listPage(ListPage page) {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return projectConfigService.listPage(page);
    }

    @ApiOperation(value = "CBC项目配置管理表统计", notes = "CBC项目配置管理表统计接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("count")
    SuccessResultData<Integer> count() {
        Map<String, Object> params = requestParams();
        return new SuccessResultData<>(projectConfigService.count(params));
    }

}