package thyyxxk.webserver.dao.his.redislike;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
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.login.UserInfo;

import java.util.List;

@Mapper
public interface RedisLikeDao {

    @Select("select rtrim(name) from a_employee_mi with(nolock) where code=#{code}")
    String selectEmployeeName(@Param("code") String code);

    @Select("select rtrim(name) from zd_unit_code with(nolock) where code=#{code}")
    String selectDeptName(@Param("code") String code);

    @Select("select (select rtrim(t.name) from zd_unit_code t where t.code=dept_code ) + '-' + " +
            "rtrim(name) from a_employee_mi with(nolock) where code=#{code}")
    String selectDeptAndUser(@Param("code") String code);

    @Select("select code=(select b.name from t_region b where b.code=a.parent_code),a.name from t_region a where code=#{code}")
    CodeName selectAdmdvsNameAndParentName(@Param("code") String code);

    @Select("select name,code='' from t_si_admdvs where code=#{code}")
    CodeName selectAdmdvsName(@Param("code") String code);

    @Select("select wjw_code from zd_anaesthesia where code=#{code}")
    String selectWjwAnaesthesia(@Param("code") String code);

    @Select("select wjw_code from zd_unit_code where code=#{code}")
    String selectWjwDepartment(@Param("code") String code);

    @Select("select wjw_code from zd_nation_code where code=#{code}")
    String selectWjwNation(@Param("code") String code);

    @Select("select rtrim(name) from zd_country_code where code=#{code}")
    String selectCountryName(@Param("code") String code);

    @Select("select a.code," +
            " a.name," +
            " password," +
            " a.code_rs,rtrim(b.yb_code) as ybCode," +
            " emp_tit_code," +
            " rtrim(b.dept_code) as deptCode," +
            " cast(isnull(NULLIF(doctor_xz_yp, ''), 0) as int) doctor_xz_yp " +
            "from dj_user_base a, a_employee_mi b where a.code=#{code} and isnull(b.del_flag,0)!=1 and a.code=b.code")
    UserInfo selectUserInfo(@Param("code") String code);

    @Select("select rtrim(code) as code,rtrim(code_rs) as codeRs,rtrim(name) as name,yb_code ybCode,emp_tit_code,dept_code,cast(isnull(NULLIF(doctor_xz_yp, ''), 0) as int) doctor_xz_yp from a_employee_mi where code=#{code}")
    UserInfo selectUserInfoFromHis(@Param("code") String code);

    @Insert("insert into dj_user_base (code, code_rs, name, password, del_flag) " +
            "values (#{code}, #{codeRs}, #{name}, '123456', 0)")
    void insertNewUserToDjUserBase(UserInfo user);

    @Select("select role_id from dj_user_role where user_code=#{code}")
    List<Integer> selectUserRoles(@Param("code") String code);

    @Select("select dept_code from zy_part_time_dept where code=#{code}")
    List<String> selectUserPartTimeDept(@Param("code") String code);

    @Select(" select rtrim(yb_code) " +
            "                          from zy_zd_relative_code  " +
            "                          where code = #{code}")
    String selectYbCodeContactRelation(String code);

    @Select("select rtrim(si_caty) " +
            "                          from zd_unit_code " +
            "                          where code = #{code}")
    String selecYbDept(String code);
    @Delete(" delete   from dj_user_base  where code =#{code} ")
    void delNewUserToDjUserBase(String code);
}
