package thyyxxk.webserver.dao.his.technologyArchives;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.dictionary.CodeName;
import thyyxxk.webserver.entity.technologyArchives.TechnologyArchivesHLMain;
import thyyxxk.webserver.entity.technologyArchives.TechnologyArchivesHLType;
import thyyxxk.webserver.entity.technologyArchives.TechnologyArchivesMain;
import thyyxxk.webserver.entity.technologyArchives.TechnologyArchivesType;

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

/**
 * @ClassName TechnologyArchivesDao
 * @Author hsh
 * @Date 2024/7/4 15:37
 * @Version 1.0
 * @Description 技术档案管理
 **/
@Mapper
public interface TechnologyArchivesDao extends BaseMapper<TechnologyArchivesType> {

    @Select(" select top 1 rtrim(mi.name) as name, rtrim(mi.sex_code) as sex, rtrim(mi.social_no) as socialNo, " +
            "   rtrim(mi.phone_no) as phone, convert(varchar(7), mi.birth_date, 23) as birthday, rtrim(mi.code) as account " +
            " from a_employee_mi as mi   " +
            " where mi.code = #{text} or mi.code_rs = #{text} or mi.social_no = #{text} or mi.name = #{text} ")
    TechnologyArchivesMain selectEmployeeInfo(@Param("text") String text);
    @Select("select rtrim(code) as code, rtrim(name) as name from zd_sex_code with(nolock)")
    List<CodeName> getSexCode();

    @Select("select rtrim(code) as code, rtrim(name) as name from zd_nation_code with(nolock)")
    List<CodeName> getNation();

    @Select("select rtrim(code) as code, rtrim(name) as name from zd_emp_political_status with(nolock)")
    List<CodeName> getPolitical();

    @Select("select rtrim(code) as code, rtrim(name) as name from t_region with(nolock) where level = '2'")
    List<CodeName> getCity();

    @Select("select rtrim(code) as code, rtrim(name) as name from zd_emp_title with(nolock)")
    List<CodeName> getTitle();

    @Select("select rtrim(code) as code, rtrim(name) as name from zd_education_code with(nolock)")
    List<CodeName> getEducation();

    @Select("select rtrim(code) as code, rtrim(name) as name from technology_archives_type where type = #{type} order by sort ")
    List<Map<String, Object>> selectTechnologyArchivesType(@Param("type") String type);

    @Select("select rtrim(code) as code, rtrim(name) as name from technology_archives_type order by sort ")
    List<Map<String, Object>> selectTechnologyArchivesTypeAll();

    @Select("select count(1) from sys_parameters where code = 'technologyArchivesCode' and name like '%${code}%' ")
    int selectTechnologyArchivesTypeQx(@Param("code") String code);
    @Select("select * from technology_archives_type where code = #{code} ")
    TechnologyArchivesType selectTechnologyArchivesTypeInfo(@Param("code") String code);

//    @Select("select b.name as xm, a.* from ${tableName} as a, technology_archives_main as b" +
//            "where  a.social_no = b.social_no and a.account = #{code} and a.social_no = #{socialNo}")
//    List<Map<String, Object>> selectTechnologyArchivesInfo(@Param("tableName") String tableName, @Param("socialNo") String socialNo);
//
//    @Select("select * from ${tableName} where social_no = #{socialNo} ")
//    List<Map<String, Object>> selectTechnologyArchivesMainInfo(@Param("tableName") String tableName, @Param("socialNo") String socialNo);
//
//    @Select("${sql} where m.social_no = #{socialNo} ")
//    List<Map<String, Object>> selectTechnologyArchivesInfoBySql(@Param("sql") String sql, @Param("socialNo") String socialNo);
@Select(" select b.name as xm, a.* from ${tableName} as a " +
        " join technology_archives_main as b on a.social_no = b.social_no " +
        " where ( #{code} is null or a.account = #{code} )" +
        " and ( #{socialNo} is null or a.social_no = #{socialNo} ) "  )
List<Map<String, Object>> selectTechnologyArchivesInfo(@Param("tableName") String tableName, @Param("code") String code, @Param("socialNo") String socialNo);

    @Select(" select * from ${tableName} " +
            " where ( #{code} is null or a.account = #{code} )" +
            " and ( #{socialNo} is null or a.social_no = #{socialNo} ) " )
    List<Map<String, Object>> selectTechnologyArchivesMainInfo(@Param("tableName") String tableName, @Param("code") String code, @Param("socialNo") String socialNo);

    @Select("${sql}" +
            " where ( #{code} is null or m.account = #{code} )" +
            " and ( #{socialNo} is null or m.social_no = #{socialNo} ) " )
    List<Map<String, Object>> selectTechnologyArchivesInfoBySql(@Param("sql") String sql, @Param("code") String code, @Param("socialNo") String socialNo);


    @Select("select top 1 rtrim(mi.name) as name, rtrim(mi.sex_code) as sex, rtrim(mi.social_no) as socialNo, " +
            "   rtrim(mi.phone_no) as phone, convert(varchar(7), mi.birth_date, 23) as birthday, rtrim(mi.code_rs) as account " +
            " from a_employee_mi as mi   " +
            " where mi.code = #{text} or mi.code_rs = #{text} or mi.social_no = #{text} or mi.name = #{text} ")
    TechnologyArchivesHLMain selectHLEmployeeInfo(@Param("text") String text);

    @Select("select rtrim(code) as code, rtrim(name) as name from technology_archives_hl_type where type = #{type} order by sort ")
    List<Map<String, Object>> selectTechnologyArchivesHLType(@Param("type") String type);

    @Select("select rtrim(code) as code, rtrim(name) as name from technology_archives_hl_type order by sort ")
    List<Map<String, Object>> selectTechnologyArchivesHLTypeAll();

    @Select("select count(1) from sys_parameters where code = 'hltechnologyArchivesCode' and name like '%${code}%' ")
    int selectHLTechnologyArchivesTypeQx(@Param("code") String code);

    @Select(" select b.name as xm, a.* from ${tableName} as a " +
            " join technology_archives_hl_main as b on a.social_no = b.social_no " +
            " where ( #{code} is null or a.account = #{code} )" +
            " and ( #{socialNo} is null or a.social_no = #{socialNo} ) "  )
    List<Map<String, Object>> selectTechnologyArchivesHLInfo(@Param("tableName") String tableName, @Param("code") String code, @Param("socialNo") String socialNo);

    @Select(" select * from ${tableName} " +
            " where ( #{code} is null or a.account = #{code} )" +
            " and ( #{socialNo} is null or a.social_no = #{socialNo} ) " )
    List<Map<String, Object>> selectTechnologyArchivesHLMainInfo(@Param("tableName") String tableName, @Param("code") String code, @Param("socialNo") String socialNo);

//    @Select("select b.name as xm, a.* from ${tableName} as a, technology_archives_hl_main as b " +
//            "where a.social_no = b.social_no and a.account = #{socialNo} and a.social_no = #{socialNo} ")
//    List<Map<String, Object>> selectTechnologyArchivesHLInfo(@Param("tableName") String tableName, @Param("socialNo") String socialNo);
//
//    @Select("select * from ${tableName} where social_no = #{socialNo} ")
//    List<Map<String, Object>> selectTechnologyArchivesHLMainInfo(@Param("tableName") String tableName, @Param("socialNo") String socialNo);

    @Select("select * from technology_archives_hl_type where code = #{code} ")
    TechnologyArchivesHLType selectTechnologyArchivesHLTypeInfo(@Param("code") String code);
}
