package com.qy.worksheetsystem.model.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

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

/**
 * description: ProjectMapper <br>
 * date: 2022/3/12 10:24 <br>
 * author: lhbj <br>
 * version: 1.0 <br>
 */
@Repository
public interface ProjectMapper {

    Map<String, String> getProjectListSingle(@Param("number") String number, @Param("id") String id);

    List<Map<String, String>> getProjectList(@Param("number") String number,
                                             @Param("id") String id, @Param("OrgNumber") String OrgNumber);

    List<Map<String, String>> getProjectListV2(@Param("number") String number,
                                               @Param("id") String id, @Param("OrgNumber") String OrgNumber);

    List<Map<String, Object>> getProjectByPNumber(@Param("number") String number);

    List<Map<String, Object>> getProjectByPNumberV2(@Param("number") String number, @Param("OrgNumber") String OrgNumber);

    List<Map<String, Object>> getProjectByPNumberV3(@Param("number") String number, @Param("OrgNumber") String OrgNumber);

    List<Map<String, Object>> getProjectListToChild(@Param("number") String number,
                                                    @Param("id") String id, @Param("OrgNumber") String OrgNumber);

    List<Map<String, Object>> getProjectListToChildV2(@Param("number") String number,
                                                      @Param("id") String id, @Param("OrgNumber") String OrgNumber);

    String getProjectListToChildV3(@Param("number") String number,
                                   @Param("id") String id, @Param("OrgNumber") String OrgNumber);

    /**
     * 获取领导下属员工
     *
     * @param number
     * @param id
     * @param OrgNumber
     * @return
     */
    List<String> getProjectListToChildV2ByPid(@Param("number") String number,
                                              @Param("id") String id, @Param("OrgNumber") String OrgNumber);


    //qingwux项目管理

    /**
     * 项目里员工添加员工
     * personID      人员id
     * projectID     项目id
     * projectRoleID 项目角色id
     *
     * @return
     */
    //@Insert("insert CT_PRO_MemberManagement(CFEmployeeID,CFProjectManagementID,CFProjectRoleID) values (#{personID},#{projectID},#{projectRoleID})")
    int addProjectPerson(Map<String, Object> mapParam);

    /**
     * 通过员工编码获取员工ID
     *
     * @param number
     * @return
     */
    @Select("select  fid as id from t_bd_person where  fnumber = #{number} ")
    String getPersonIdBYNumber(@Param("number") String number);


    /**
     * 获取项目管理名称和编码
     *
     * @param id
     * @return
     */
    @Select("select CFProjectName as \"projectName\" ,FNumber as \"number\"  from CT_PRO_ProjectManagement where fid =#{id}")
    List<Map<String, String>> getProjectManagementInfoBYId(@Param("id") String id);

    /**
     * 获取项目成员表id
     *
     * @return
     */
    //@Select("select newbosid('B49500FE') as \"id\" ")
    @Select("select newbosid('B49500FE') as \"id\"  from dual")
    String getMemberManagementID();

    /**
     * 启动禁用
     *
     * @param state
     * @param personID
     * @param projectID
     * @return
     */
    @Update("update  CT_PRO_MemberManagement set CFState=#{state}  where CFEmployeeID = #{personID}  and CFPROJECTMANAGEMENID= #{projectID}")
    int updateStateByPersonIdAndPerobject(@Param("state") String state, @Param("personID") String personID, @Param("projectID") String projectID);

    /**
     * 获取所有人员信息数据  Id 工号 名称 组织 职位
     *
     * @return
     */
    @Select("select\n" +
            " person.fid as \"personId\",\n" +
            " person.Fname_l2 as \"personName\",\n" +
            " person.fnumber as \"personNumber\",\n" +
            " adminOrg.fid as \"adminOrgId\",\n" +
            " adminOrg.fnumber as \"adminOrgNumber\",\n" +
            "adminOrg.fname_l2 as \"adminOrgName\",\n" +
            "position.fid  as \"positionId\",\n" +
            "position.fnumber as \"positionNumber\",\n" +
            "position.fname_l2 as \"positionName\"\n" +
            " from T_HR_PERSONPOSITION personPosition \n" +
            "left join T_BD_person person on person.fid = personPosition.fpersonId\n" +
            "left join T_org_admin adminOrg on adminOrg.fid = personPosition.FPersonDep\n" +
            "left join T_ORG_Position  position on position.fid = personPosition.FPrimaryPositionID\n")
    List<Map<String, String>> getPersonAll();

    /**
     * 通过项目id获取项目角色名称，角色  id,  人员id  人员名称
     *
     * @param perobjectId
     * @return
     */
    //@Select("select\n" +
    //        "    projectRole.fid as \"projectRoleId\",\n" +
    //        "    projectRole.fname_l2 as \"projectRoleName\",\n" +
    //        "    person.fid as \"personId\",\n" +
    //        "    person.Fname_l2 as \"personName\",\n" +
    //        "    projectManagement.CFProjectName as \"projectName\",\n" +
    //        "    projectManagement.CFExpectedEndTime as \"expectedEndTime\",\n" +
    //        "    projectType.fname_l2 as \"projectTypeName\",\n" +
    //        "    projectType.fid as \"projectTypeId\",\n" +
    //        "    projectType.fnumber  as \"projectTypeNumber\"\n" +
    //        "from CT_PRO_MemberManagement memberManagement\n" +
    //        "    left join CT_PRO_ProjectRole projectRole on projectRole.fid = memberManagement.CFProjectRoleID\n" +
    //        "    left join T_BD_person person on person.fid = memberManagement.CFEmployeeID\n" +
    //        "    left join CT_PRO_ProjectManagement projectManagement on projectManagement.fid = memberManagement.CFPROJECTMANAGEMENID\n" +
    //        "    left join CT_PRO_ProjectType projectType on projectType.fid = projectRole.CFTypeID " +
    //        "where  projectManagement.fid = #{perobjectId}")
    List<Map<String, Object>> getMemberManagementInfoByPerobjectId(@Param("perobjectId") String perobjectId);

    /**
     * 获取员工时间范围内项目列表
     *
     * @param state
     * @return
     */
    List<Map<String, String>> getProjectManagementByState(String state, String dateTime);

    /**
     * 获取员工有效项目列表
     *
     * @param state
     * @param dateTime
     * @return
     */
    List<Map<String, String>> getProjectListByState(String state, String dateTime, String personNumber);

    /**
     * 选择项目角色列表
     *
     * @return
     */
    @Select("select\n" +
            " projectRole.fid as \"id\" ,\n" +
            " projectRole.fname_l2 as \"name\" ,\n" +
            "projectType.fid as \"projectTypeId\" ,\n" +
            "projectType.fname_l2 as \"projectTypeName\" \n" +
            "from CT_PRO_ProjectRole projectRole\n" +
            "left join CT_PRO_ProjectType projectType on projectType.fid = projectRole.CFTypeID\n" +
            "\n")
    List<Map<String, String>> getProjectRoleList();

    @Select("select  * from CT_PRO_MemberManagement  where FNUMBER  =#{number}")
    List<Map<String, String>> getManagementByNumber(String number);


    @Select("select fname_l2 as \"name\" ,fnumber as \"number\" ,fid as \"id\" from T_BD_PERSON where fid = #{personID}")
    Map<String, String> getPerson(String personID);
}
