AreaMapper.xml 2.04 KB
<?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.yoho.order.dal.AreaMapper">
    <resultMap id="BaseResultMap" type="com.yoho.order.model.Area">
      <result column="id" property="id" jdbcType="INTEGER" />
      <result column="code" property="code" jdbcType="INTEGER" />
      <result column="caption" property="caption" jdbcType="VARCHAR" />
      <result column="is_support" property="isSupport" jdbcType="VARCHAR" />
      <result column="is_delivery" property="isDelivery" jdbcType="VARCHAR" />
      <result column="is_cash_delivery" property="isCashDelivery" jdbcType="VARCHAR" />
      <result column="status" property="status" jdbcType="INTEGER" />
    </resultMap>

    <sql id="Base_Column_List">
        id, code, caption, is_support, is_delivery, is_cash_delivery, status
    </sql>

    <select id="selectByCodeList" resultMap="BaseResultMap">
        select <include refid="Base_Column_List" />
        from area where 1=1
        <if test="codeList != null and codeList.size()>0">  
         and id in  
            <foreach collection="codeList" item="code" open="(" close=")" separator=",">
             #{code}
            </foreach>
        </if>
    </select>
    
    <select id="selectByParentCode" resultMap="BaseResultMap">
        select <include refid="Base_Column_List" />
        from area where 1=1
        <if test='parentCode=="0"'>  
         and length(id)=2
        </if>
        <if test="parentCode.length()==2">
         and length(id)=4 and left(id,2)=#{parentCode}
        </if>
        <if test="parentCode.length()==4">
         and left(id,4)=#{parentCode} and length(id) &gt;4 and length(id) &lt;9
        </if>
        <if test="parentCode.length()==6">
         and left(id, 6)=#{parentCode} and length(id) &gt;6
        </if>
    </select>

    <insert id="insertArea" parameterType="com.yoho.order.model.Area">
        insert into area(id, code, caption)
        values (#{id}, #{code}, #{caption})
    </insert>
</mapper>