package com.rwk.system.mapper;

import java.util.List;
import java.util.Map;
import com.rwk.system.domain.RwkStaffInformation;
import com.rwk.system.domain.RwkFamilyMember;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 人员信息Mapper接口
 *
 * @author rick
 * @date 2024-11-25
 */
@Mapper
public interface RwkStaffInformationMapper
{
    /**
     * 查询人员信息
     *
     * @param id 人员信息主键
     * @return 人员信息
     */
    public RwkStaffInformation selectRwkStaffInformationById(Long id);

    /**
     * 查询人员信息列表
     *
     * @param rwkStaffInformation 人员信息
     * @return 人员信息集合
     */
    public List<RwkStaffInformation> selectRwkStaffInformationList(RwkStaffInformation rwkStaffInformation);

    /**
     * 新增人员信息
     *
     * @param rwkStaffInformation 人员信息
     * @return 结果
     */
    public int insertRwkStaffInformation(RwkStaffInformation rwkStaffInformation);

    /**
     * 修改人员信息
     *
     * @param rwkStaffInformation 人员信息
     * @return 结果
     */
    public int updateRwkStaffInformation(RwkStaffInformation rwkStaffInformation);

    /**
     * 删除人员信息
     *
     * @param id 人员信息主键
     * @return 结果
     */
    public int deleteRwkStaffInformationById(Long id);

    /**
     * 批量删除人员信息
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteRwkStaffInformationByIds(String[] ids);

    /**
     * 批量删除家庭成员
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteRwkFamilyMemberByFamilyMemberCodes(String[] ids);

    /**
     * 批量新增家庭成员
     *
     * @param rwkFamilyMemberList 家庭成员列表
     * @return 结果
     */
    public int batchRwkFamilyMember(List<RwkFamilyMember> rwkFamilyMemberList);


    /**
     * 通过人员信息主键删除家庭成员信息
     *
     * @param id 人员信息ID
     * @return 结果
     */
    public int deleteRwkFamilyMemberByFamilyMemberCode(Long id);

    /**
     * 按照职务层级统计人数
     */
    @Select("select job_level name, count(*) \"value\" from rwk_staff_information\n" +
            "group by job_level;")
    public List<Map<String, Object>> selectTotalByJob();

    /**
     * 按照党派统计人数
     */
    @Select("select party name, count(*) \"value\" from rwk_staff_information\n" +
            "group by party;")
    public List<Map<String, Object>> selectTotalByParty();

    /**
     * 按照性别、年龄统计人数
     */
    @Select("select gender,\n" +
            "    SUM(CASE WHEN age < 40 THEN 1 ELSE 0 END) AS \"40岁以下\",\n" +
            "    SUM(CASE WHEN age >= 40 AND age < 50 THEN 1 ELSE 0 END) AS \"40~50岁\",\n" +
            "    SUM(CASE WHEN age >= 50 AND age < 55 THEN 1 ELSE 0 END) AS \"50~55岁\",\n" +
            "    SUM(CASE WHEN age >= 55 THEN 1 ELSE 0 END) AS \"55岁以上\"\n" +
            "from (SELECT '男' AS gender UNION SELECT '女' AS gender) genders\n" +
            "LEFT JOIN (SELECT sex,YEAR(CURDATE()) - SUBSTRING(id_card, 7, 4) age FROM rwk_staff_information) AS age_data\n" +
            "ON age_data.sex = genders.gender\n" +
            "GROUP BY gender;")
    public List<Map<String, Object>> selectTotalByAge();

    /**
     * 按照单位类别统计人数
     */
    @Select("select unit_attribute name, count(*) \"value\" from rwk_staff_information\n" +
            "group by unit_attribute;")
    public List<Map<String, Object>> selectTotalByUnitAttribute();

    /**
     * 按照全日制学历统计人数
     */
    @Select("select qrz_qualification name, count(*) \"value\" from rwk_staff_information\n" +
            "group by qrz_qualification;")
    public List<Map<String, Object>> selectTotalByQrzQualification();

    /**
     * 按照全日制学位统计人数
     */
    @Select("select qrz_degree name, count(*) \"value\" from rwk_staff_information\n" +
            "group by qrz_degree;")
    public List<Map<String, Object>> selectTotalByQrzDegree();

    /**
     * 按照在职学历统计人数
     */
    @Select("select zz_qualification name, count(*) \"value\" from rwk_staff_information\n" +
            "group by zz_qualification;")
    public List<Map<String, Object>> selectTotalByZzQualification();

    /**
     * 按照在职学位统计人数
     */
    @Select("select zz_degree name, count(*) \"value\" from rwk_staff_information\n" +
            "group by zz_degree;")
    public List<Map<String, Object>> selectTotalByZzDegree();
}
