package thyyxxk.webserver.dao.his.settings;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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 org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.dictionary.CodeName;
import thyyxxk.webserver.entity.schedulingClass.data.SchedulingClass;

import java.util.Date;
import java.util.List;

@Mapper
public interface SchedulingClassDao extends BaseMapper<SchedulingClass> {

    @Select("select code, rtrim(name) as name\n" +
            "from a_employee_mi\n" +
            "where dept_code = '3100000'\n" +
            "  and del_flag = 0")
    List<CodeName> getXinXiKeCode();

    @Select("select dict_value\n" +
            "from t_dict_data\n" +
            "where dict_name = 'scheduling_class_sort'\n" +
            "  and dict_type = '1.0'")
    String getSort();


    @Update("update  t_dict_data set  dict_value = #{value} " +
            "where dict_name = 'scheduling_class_sort' and dict_type = '1.0'")
    void updateDictData(String value);


    @Select("select code," +
            " name = (select rtrim(name) from a_employee_mi where scheduling_class.code = a_employee_mi.code)\n" +
            "from scheduling_class where scheduling_date = #{date} ")
    CodeName selectByDate(Date date);

    @Select("select name = (select rtrim(name) from a_employee_mi where a_employee_mi.code = scheduling_class.code)," +
            "change_class_name= (select rtrim(name)\n" +
            "                           from a_employee_mi\n" +
            "                           where scheduling_class.change_class = a_employee_mi.code),\n" +
            "       *\n" +
            "from scheduling_class ${ew.customSqlSegment} ")
    List<SchedulingClass.SchedulingClassVo> selectByDateVo(@Param("ew") LambdaQueryWrapper<SchedulingClass> queryWrapper);


    @Select("select rtrim(phone_no) from a_employee_mi where code = '${code}' ")
    String getCellPhoneNumber(String code);
}
