<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.cftech.sys.dao.CityMapper" >

    <!-- 插入一条城市记录 -->
    <insert id="insertCity" parameterType="com.cftech.sys.model.City">
    	insert into city_code_cn (city_code, city_jb, province_code, city_name, city, province)
        values ( #{cityCode,jdbcType=CHAR}, #{cityJb,jdbcType=INTEGER}, #{provinceCode,jdbcType=CHAR},
        #{cityName,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, #{province,jdbcType=VARCHAR} )
    </insert>

    <!-- 根据省份名称返回该省份下的所有城市列表 -->
    <select id="provinceCities" resultType="com.cftech.sys.model.City" parameterType="java.lang.String">
		select c.id,c.city_code, c.city_name ,c.city_jb,c.province_code,c.city,c.province 
        from city_code_cn c where  c.province = #{province} order by c.city_code	
    </select>
    
    <!-- 根据 city_code 查找城市信息 -->
    <select id="searchCity" resultType="com.cftech.sys.model.City" parameterType="java.lang.String">
        select c.city,c.city_code,c.province_code,c.city_jb,c.city_name,c.id,c.province 
        from  city_code_cn c where c.city_code = #{city_code}
    </select>
    
    <!-- 重命名城市 -->  
    <update id="renameCity" parameterType="com.cftech.sys.model.City">
        update city_code_cn set city_name = #{cityName} where city_code = #{cityCode}
    </update>  
    
    <!-- 删除一个城市记录 -->  
    <delete id="deleteCity" parameterType="java.lang.String">  
        delete from city_code_cn where city_code = #{cityCode}  
    </delete>  
</mapper>