package com.platform.dao; import java.util.List; import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Update; import org.springframework.stereotype.Repository; import com.platform.entities.EncodedInfoEntity; /** * 数据库操作: 实现增、删、改、查 * * @author wuming * */ @Repository(value = "encodeInfoDao") public interface EncodeInfoDao { /** * 获取查询表下的所有实体(行政区划/系统)信息 * * @param tableName * 查询的表名 * @return 所有实体信息:名称和编码 */ @Select("SELECT code, name FROM ${tableName}") public List getAllEntityInfo( @Param("tableName") String tableName); /** * 根据实体(行政区划/系统)的名称查询编码 * * @param code * 实体编码 * @param tableName * 查询的表名 * @return 编码是主键,查询结果最多只有一条记录 */ @Select("SELECT name FROM ${tableName} WHERE code = #{code}") public String getEncodeNameByCode(@Param("code") String code, @Param("tableName") String tableName); /** * 根据实体(行政区划/系统)的编码查询名称 * * @param name * 实体名称 * @param tableName * 查询的表名 * @return 名称不是主键,查询结果可能会有多个 */ @Select("SELECT code FROM ${tableName} WHERE name = #{name}") public List getEncodeCodeByName(@Param("name") String name, @Param("tableName") String tableName); /** * 根据实体(行政区划/系统)的编码,更新实体的名称 * * @param code * 系统编码 * @param tableName * 查询的表名 * @return */ @Update("UPDATE ${tableName} SET name = #{name} WHERE code = #{code}") public int updateEncodeNameByCode(@Param("code") String code, @Param("name") String name, @Param("tableName") String tableName); /** * 向表中插入实体(行政区划/系统)信息 * * @param efe * 插入的实体信息 * @param tableName * 表名 * @return */ @Insert("INSERT INTO ${tableName} (code, name) VALUES (#{efe.code}, #{efe.name})") public int insertEncodeEntity(@Param("efe") EncodedInfoEntity efe, @Param("tableName") String tableName); /** * 删除表中的实体(行政区划/系统) * * @param code * 实体的编码 * @param tableName * 表名 * @return */ @Delete("DELETE FROM ${tableName} WHERE code = #{code}") public int deleteEncodeByCode(@Param("code") String code, @Param("tableName") String tableName); }