package com.cm.central.control.controller.apis.projectleader;

import com.cm.common.annotation.CheckRequestBodyAnnotation;
import com.cm.common.base.AbstractController;
import com.cm.common.component.SecurityComponent;
import com.cm.common.constants.ISystemConstant;
import com.cm.common.exception.RemoveException;
import com.cm.common.exception.SearchException;
import com.cm.common.pojo.ListPage;
import com.cm.common.pojo.dtos.CurrentUserIdInfoDTO;
import com.cm.common.result.ErrorResult;
import com.cm.common.result.SuccessResult;
import com.cm.common.result.SuccessResultData;
import com.cm.common.result.SuccessResultList;
import com.cm.central.control.pojo.dtos.projectleader.ProjectLeaderDTO;
import com.cm.central.control.pojo.vos.projectleader.ProjectLeaderVO;
import com.cm.central.control.service.projectleader.IProjectLeaderService;
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: ProjectLeaderController
 * @Description: 项目负责人
 * @Author: WenG
 * @Date: 2020-07-30 19:04
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "项目负责人接口")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/projectleader")
public class ProjectLeaderController extends AbstractController {

    @Autowired
    private IProjectLeaderService projectLeaderService;
    @Autowired
    private SecurityComponent securityComponent;

    @ApiOperation(value = "新增项目负责人", notes = "新增项目负责人接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("saveprojectleader")
    @CheckRequestBodyAnnotation
    public SuccessResult saveProjectLeader(@RequestBody ProjectLeaderVO projectLeaderVO) throws Exception {
        return projectLeaderService.saveProjectLeader(projectLeaderVO);
    }

    @ApiOperation(value = "删除项目负责人(id列表)", notes = "删除项目负责人(id列表)接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "ID列表，用下划线分隔", paramType = "path", example = "1_2_3")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @DeleteMapping("removeprojectleader/{ids}")
    public SuccessResult removeProjectLeader(@PathVariable("ids") String ids) throws RemoveException {
        return projectLeaderService.removeProjectLeader(ids);
    }

    @ApiOperation(value = "修改项目负责人", notes = "修改项目负责人接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectLeaderId", value = "项目负责人ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updateprojectleader/{projectLeaderId}")
    @CheckRequestBodyAnnotation
    public SuccessResult updateProjectLeader(@PathVariable("projectLeaderId") String projectLeaderId, @RequestBody ProjectLeaderVO projectLeaderVO) throws Exception {
        return projectLeaderService.updateProjectLeader(projectLeaderId, projectLeaderVO);
    }

    @ApiOperation(value = "项目负责人详情(通过ID)", notes = "项目负责人详情(通过ID)接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectLeaderId", value = "项目负责人ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("getprojectleaderbyid/{projectLeaderId}")
    public ProjectLeaderDTO getProjectLeaderById(@PathVariable("projectLeaderId") String projectLeaderId) throws SearchException {
        return projectLeaderService.getProjectLeaderById(projectLeaderId);
    }

    @ApiOperation(value = "项目负责人列表", notes = "项目负责人列表接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listprojectleader")
    public List<ProjectLeaderDTO> listProjectLeader() throws SearchException {
        Map<String, Object> params = requestParams();
        return projectLeaderService.listProjectLeader(params);
    }

    @ApiOperation(value = "项目负责人分页列表", notes = "项目负责人分页列表接口")
    @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("listpageprojectleader")
    public SuccessResultList<List<ProjectLeaderDTO>> listPageProjectLeader(ListPage page) throws SearchException {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return projectLeaderService.listPageProjectLeader(page);
    }

    @ApiOperation(value = "项目负责人统计", notes = "项目负责人统计接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("countprojectleader")
    SuccessResultData<Integer> countProjectLeader() throws SearchException {
        Map<String, Object> params = requestParams();
        return projectLeaderService.countProjectLeader(params);
    }

    @ApiOperation(value = "当前用户id信息", notes = "当前用户id信息接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("getcurrentuseridinfo")
    public CurrentUserIdInfoDTO getCurrentUserIdInfo() {
        return securityComponent.getCurrentUserIdInfo();
    }

}