package thyyxxk.webserver.dao.his.crbmanagement;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.crbmanagement.BaseDept;
import thyyxxk.webserver.entity.crbmanagement.BaseUser;

import java.util.List;

@Mapper
public interface CrbBaseDao {

    @Select(" select name from sys_parameters where code = #{code} ")
    String selectOrgCodeByCode(@Param("code") String code);

    @Select(" select rtrim(mi.code) as id, #{orgCode} as orgCode, rtrim(mi.name) as userName, rtrim(mi.dept_code) as deptCode, " +
            " mi.code_rs as loginName, isnull(gw.id_card, rtrim(mi.social_no)) as idCard, '01' as idCardTypeCode, " +
            " isnull(gw.tel, rtrim(mi.phone_no)) as tel, rtrim(mi.yb_code) as physicianNo, " +
            " case when gw.name is null then '2' else '1' end as userTypeCode, " +
            " convert(varchar(100), sysdatetime(), 20) as createTime  " +
            " from a_employee_mi as mi " +
            " left join gw_info as gw on mi.code = gw.code  " +
            " where isnull(mi.del_flag, '0') = '0' and ${ew.sqlSegment} " +
            " order by mi.code ")
    List<BaseUser> selectBaseUser(@Param("orgCode") String orgCode, @Param(Constants.WRAPPER) QueryWrapper<?> qw);

    @Select(" select rtrim(code) as deptCode, rtrim(name) as deptName, " +
            " si_caty as targetDeptCode, si_caty_name as targetDeptName, " +
            " convert(varchar(100), sysdatetime(), 20) as createTime " +
            " from zd_unit_code where ${ew.sqlSegment} " +
            " order by code ")
    List<BaseDept> selectBaseDept(@Param(Constants.WRAPPER) QueryWrapper<?> qw);

}
