package thyyxxk.webserver.dao.his.hutoolcache;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
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 thyyxxk.webserver.entity.medicine.YpZdGroupName;
import thyyxxk.webserver.entity.settings.IntergrationMenu;
import thyyxxk.webserver.entity.settings.IntergrationPlatformRoleMenu;
import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.YzZdOrderItemConfirm;
import thyyxxk.webserver.service.hutoolcache.*;

import java.util.List;

@Mapper
public interface HutoolCacheDao {

    @Select("select code,name,py_code,charge_code from zy_bill_item where code=#{code}")
    ZyBillItemCache.ZyBillItem selectZyBillItem(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(String code);

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

    @Select("select code,rtrim(name) as name,rtrim(py_code) as pyCode,wjw_code " +
            "from zd_nation_code where code=#{code}")
    NationCache.Nation selectNation(String code);

    @Select("select code,rtrim(name) as name,rtrim(py_code) as pyCode,si_code " +
            "from zd_country_code where code=#{code}")
    CountryCache.Country selectCountry(String code);

    @Select("select rtrim(code) as code,rtrim(name) as name,rtrim(py_code) as pyCode " +
            "from zy_occupation_code where code=#{code}")
    OccupationCache.Occupation selectOccupation(String code);

    @Select("select b.code," +
            " rtrim(b.name) name," +
            " password," +
            " b.code_rs," +
            " rtrim(b.yb_code) as ybCode," +
            "hzDay = (select hz_day from zd_unit_code where zd_unit_code.code = b.dept_code)," +
            " emp_tit_code," +
            " rtrim(b.dept_code) as deptCode,user_config, " +
            " 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(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(String code);

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

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

    @Select("select hz_day  from zd_unit_code where code = #{deptCode}")
    Integer getDeptHzDayByCode(@Param("deptCode") String deptCode);

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

    @Select("select RTRIM(code) " +
            "from zd_unit_code " +
            "where ${ew.sqlSegment}" +
            "and isnull(del_flag, 0) = 0")
    List<String> selectChildDeptByCodeList(@Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper);

    @Select(" select rtrim(code) as code,rtrim(name) as name,rtrim(py_code) as pyCode," +
            "rtrim(yb_code) as ybCode from zy_zd_relative_code where code = #{code}")
    RelativeCache.Relative selectRelative(String code);

    @Delete(" delete   from dj_user_base  where code =#{code} ")
    void delNewUserToDjUserBase(String code);

    @Select("select code,name,py_code,si_caty,si_caty_name,wjw_code from zd_unit_code where code = #{code}")
    DeptCache.Dept selectZdUnitCode(String code);

    @Select("select code,name,py_code,si_caty,si_caty_name,wjw_code from zd_unit_code where si_caty = #{code}")
    DeptCache.Dept selectZdUnitCodeByYbCode(String code);

    @Select("select * from t_intergration_menu order by type , sort  ")
    List<IntergrationMenu> getAll();

    @Select("select * " +
            "from yz_zd_order_item_confirm")
    List<YzZdOrderItemConfirm> getYzZdOrderItemConfirm();

    @Select("select group_no, group_name,start_time, end_time " +
            "from yp_zd_group_name\n" +
            "where zy_flag = 1\n" +
            "  and del_flag = 0\n" +
            "  and xy_flag = 1")
    List<YpZdGroupName> selectYpZdGroup();


    @Select("select group_no, group_name,start_time, end_time " +
            "from yp_zd_group_name\n" +
            "where zy_flag = 1\n" +
            "  and del_flag = 0\n" +
            "  and zcy_flag = 1")
    List<YpZdGroupName> selectYpCyGroup();
}
