package com.ankaibei.workFlow.webadmin.ankaibei.controller;

import com.ankaibei.workFlow.common.core.object.TokenData;
import com.ankaibei.workFlow.webadmin.ankaibei.api.ProjectTeamApi;
import com.ankaibei.workFlow.webadmin.ankaibei.entity.ProjectTeamInfoEntity;
import com.ankaibei.workFlow.webadmin.ankaibei.enums.CodeEnum;
import com.ankaibei.workFlow.webadmin.ankaibei.utils.JwtUtil;
import com.ankaibei.workFlow.webadmin.ankaibei.vo.ProjectTeamInfoVo;
import com.ankaibei.workFlow.webadmin.ankaibei.vo.ResMsg;
import com.ankaibei.workFlow.webadmin.ankaibei.vo.UserInfoVo;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author lwq
 * @version 1.0
 * @description: 人员管理
 * @date 2022/9/13 10:20
 */
@RestController
@RequestMapping("/projectteam")
public class ProjectTeamController {

    @Resource
    private ProjectTeamApi projectTeamApi;

    /**
     * 查询项目组
     *
     * @param projectTeamInfoVo
     * @return ResMsg
     */
    @RequestMapping("/findProjectTeamAll")
    public ResMsg findProjectTeamAll(@RequestBody ProjectTeamInfoVo projectTeamInfoVo) {

        return projectTeamApi.findProjectTeamAll(projectTeamInfoVo);
    }

    /**
     * 删除项目组
     *
     * @param projectTeamInfoVos
     * @return ResMsg
     */
    @RequestMapping("/deleteProjectTeam")
    public ResMsg deleteProjectTeam(@RequestBody List<ProjectTeamInfoVo> projectTeamInfoVos) {

        if (projectTeamApi.deleteBatch(projectTeamInfoVos)) {
            return new ResMsg(CodeEnum.OK);
        }
        return new ResMsg(CodeEnum.FAIL);
    }

    /**
     * 添加项目组
     *
     * @param projectTeamInfoVo
     * @return ResMsg
     */
    @RequestMapping("/addProjectTeam")
    public ResMsg addProjectTeam(@RequestBody ProjectTeamInfoVo projectTeamInfoVo) {

        return projectTeamApi.addProjectTeam(projectTeamInfoVo);
    }

    /**
     * 添加项目组人员
     *
     * @param projectTeamInfoVo
     * @return ResMsg
     */
    @RequestMapping("/addProjectTeamUser")
    public ResMsg addProjectTeamUser(@RequestBody ProjectTeamInfoVo projectTeamInfoVo) {

        return projectTeamApi.addProjectTeamUser(projectTeamInfoVo);
    }


    /**
     * 编辑项目组
     *
     * @param projectTeamInfoVo
     * @return ResMsg
     */
    @RequestMapping("/updateProjectTeam")
    public ResMsg updateProjectTeam(@RequestBody ProjectTeamInfoVo projectTeamInfoVo) {


        return projectTeamApi.updateProjectTeam(projectTeamInfoVo);
    }


    /**
     * 查询***项目的人员列表
     *
     * @param userInfoVo
     * @return ResMsg
     */
    @RequestMapping("/findProjectTeamUser")
    public ResMsg findProjectTeamUser(@RequestBody UserInfoVo userInfoVo) {

        return projectTeamApi.findProjectTeamUser(userInfoVo);
    }

    /**
     * 查询人员所在的项目列表
     *
     * @return ResMsg
     */
    @RequestMapping("/findUserProject")
    public ResMsg findUserProject() {
        Long userId = TokenData.takeFromRequest().getUserId();
        return projectTeamApi.findUserProject(userId);
    }

    /**
     * 删除人员
     *
     * @param userInfoVos
     * @return ResMsg
     */
    @RequestMapping("/deleteUser")
    public ResMsg deleteUser(@RequestBody List<UserInfoVo> userInfoVos) {

        if (projectTeamApi.deleteBatchUser(userInfoVos)) {
            return new ResMsg(CodeEnum.OK);
        }
        return new ResMsg(CodeEnum.FAIL);
    }

    /**
     * 从项目组移除该人员
     *
     * @param projectTeamInfoVo
     * @return ResMsg
     */
    @RequestMapping("/removeUser")
    public ResMsg removeUser(@RequestBody ProjectTeamInfoVo projectTeamInfoVo) {


        return projectTeamApi.removeUser(projectTeamInfoVo);
    }

    /**
     * 新增人员
     *
     * @param userInfoVo
     * @return ResMsg
     */
    @RequestMapping("/addUser")
    public ResMsg addUser(@RequestBody UserInfoVo userInfoVo) {

        return projectTeamApi.addUser(userInfoVo);
    }

    /**
     * 编辑人员
     *
     * @param userInfoVo
     * @return ResMsg
     */
    @RequestMapping("/updateUser")
    public ResMsg updateUser(@RequestBody UserInfoVo userInfoVo) {

        return projectTeamApi.updateUser(userInfoVo);
    }

    /**
     * 查询用户
     *
     * @param
     * @return ResMsg
     */
    @RequestMapping("/findPrincipal")
    public ResMsg findPrincipal() {

        return projectTeamApi.findPrincipal();
    }

    /**
     * 根据token查询用户信息
     *
     * @param
     * @return ResMsg
     */
    @RequestMapping("/findById")
    public ResMsg findById(HttpServletRequest request) {
        Long userId = TokenData.takeFromRequest().getUserId();
        return projectTeamApi.findById(userId);
    }

    /**
     * 根据项目查询项目组人员
     *
     * @param
     * @return ResMsg
     */
    @RequestMapping("/findTeamUser")
    public ResMsg findTeamUser(@RequestBody ProjectTeamInfoEntity projectTeamInfoEntity) {
        return projectTeamApi.findTeamUser(projectTeamInfoEntity);
    }


}
