package thyyxxk.webserver.dao.his.dictionary;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.controller.dictionary.JcPartMaintainController;
import thyyxxk.webserver.entity.zhuyuanyisheng.jianyanjiancha.JcZdClass;

import java.util.List;

@Mapper
public interface JcPartMaintainDao {

    @Select("select a.code,a.name,a.py_code,a.del_flag,a.parent_code,b.name as parentName " +
            "from ysh_zd_part_code a left join jc_zd_class b on b.code=a.parent_code")
    List<JcPartMaintainController.JcPart> getAllJcPart();

    @Select("select * from jc_zd_class")
    List<JcZdClass> getAllJcZdClass();

    @Select("select count(1) from ysh_zd_part_code where name=#{name} ")
    int getSameName(JcPartMaintainController.JcPart jcPart);

    @Select("select count(1) from ysh_zd_part_code where name=#{name} and parent_code=#{parentCode}")
    int getSameNameAndParent(JcPartMaintainController.JcPart jcPart);

    @Insert("insert into ysh_zd_part_code (code,name,py_code,del_flag,parent_code) " +
            "values (#{code},#{name},#{pyCode},#{delFlag},#{parentCode})")
    void insertNewPart(JcPartMaintainController.JcPart jcPart);

    @Update("update ysh_zd_part_code set name=#{name},py_code=#{pyCode}, " +
            "del_flag=#{delFlag},parent_code=#{parentCode} where code=#{code}")
    void updatePart(JcPartMaintainController.JcPart jcPart);

    @Select("select max(cast(code as int)) from " +
            "(SELECT ISNUMERIC(code) as f,code FROM ysh_zd_part_code) t " +
            "where t.f = 1")
    String getMaxNumericCode();

    @Select("select max(code) from ysh_zd_part_code where code like #{prefix} + '%'")
    String getMaxLetterCode(String prefix);
}
