package thyyxxk.webserver.dao.his.dictionary;

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.datamodify.GetDropdownBox;

import java.util.List;

/**
 * <p>
 * 描述： 医保科室匹配
 * </p>
 *
 * @author xc
 * @date 2021-07-21 14:29
 */
@Mapper
public interface YibaoKeShiPiPeiDao {

    /**
     * @param flag 判断 是否查询匹配的还是未 匹配的 1 未匹配的 2 匹配的
     * @return 返回除了 病室的科室
     */
    @Select("<script>" +
            "select code,name,si_caty,(select name from t_yb_dept where code = si_caty) si_caty_name  from zd_unit_code where " +
            "<if test=\"flag == 1\">" +
            "si_caty is null" +
            "</if>" +
            "<if test=\"flag == 2\">" +
            "si_caty is not null " +
            "</if>" +
            "and (code like '1%' or code like '2%' or code like '3%' or code like '8%')  " +
            "</script>")
    List<GetDropdownBox> getBenYuanKeShiCode(Integer flag);

    /**
     * @return 返回全部医保的科室编码
     */
    @Select("select code,name from t_yb_dept")
    List<GetDropdownBox> getYiBaoKeShi();

    /**
     * 匹配医保科室
     *
     * @param benYuanCode 本院编码
     * @param yiBaoCode   医保编码
     */
    @Update("update zd_unit_code set si_caty=#{yiBaoCode}, " +
            "si_caty_name=#{yiBaoName} where code = #{benYuanCode}")
    void piPeiKeShi(@Param("benYuanCode") String benYuanCode,
                    @Param("yiBaoCode") String yiBaoCode,
                    @Param("yiBaoName") String yiBaoName);
}
