RegionMapper.xml 7.8 KB
Newer Older
苗卫卫 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
<?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.boco.nbd.wios.manage.mapper.def.RegionMapper">

    <resultMap id="BaseResultMap" type="com.boco.nbd.wios.manage.entity.bo.Region">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="code" jdbcType="VARCHAR" property="code"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="parent_id" jdbcType="INTEGER" property="parentId"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="id_tree" jdbcType="VARCHAR" property="idTree"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
    </resultMap>


    <sql id="Base_Column_List">
        id
        , code, name, parent_id, status, remark,id_tree, create_time, update_time
    </sql>


    <delete id="delete" parameterType="java.lang.Integer">
        delete
        from t_region
        where id = #{id,jdbcType=INTEGER}
    </delete>


    <insert id="insert" parameterType="com.boco.nbd.wios.manage.entity.bo.Region"
            useGeneratedKeys="true" keyProperty="id">
        insert into t_region (id, code, name,
                              parent_id, status, remark, id_tree,
                              create_time, update_time)
        values (#{id,jdbcType=INTEGER}, #{code,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
                #{parentId,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{remark,jdbcType=VARCHAR},
                #{idTree,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
    </insert>


    <insert id="insertDynamic" parameterType="com.boco.nbd.wios.manage.entity.bo.Region">
        insert into t_region
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="code != null">
                code,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="parentId != null">
                parent_id,
            </if>
            <if test="status != null">
                status,
            </if>
            <if test="remark != null">
                remark,
            </if>
            <if test="idTree != null">
                id_tree,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="code != null">
                #{code,jdbcType=VARCHAR},
            </if>
            <if test="name != null">
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="parentId != null">
                #{parentId,jdbcType=INTEGER},
            </if>
            <if test="status != null">
                #{status,jdbcType=INTEGER},
            </if>
            <if test="remark != null">
                #{remark,jdbcType=VARCHAR},
            </if>
            <if test="idTree != null">
                #{idTree,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
        </trim>
    </insert>


    <update id="updateDynamic" parameterType="com.boco.nbd.wios.manage.entity.bo.Region">
        update t_region
        <set>
            <if test="code != null">
                code = #{code,jdbcType=VARCHAR},
            </if>
            <if test="name != null">
                name = #{name,jdbcType=VARCHAR},
            </if>
            <if test="parentId != null">
                parent_id = #{parentId,jdbcType=INTEGER},
            </if>
            <if test="status != null">
                status = #{status,jdbcType=INTEGER},
            </if>
            <if test="remark != null">
                remark = #{remark,jdbcType=VARCHAR},
            </if>
            <if test="idTree != null">
                id_tree = #{idTree,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>


    <update id="update" parameterType="com.boco.nbd.wios.manage.entity.bo.Region">
        update t_region
        set code        = #{code,jdbcType=VARCHAR},
            name        = #{name,jdbcType=VARCHAR},
            parent_id   = #{parentId,jdbcType=INTEGER},
            status      = #{status,jdbcType=INTEGER},
            remark      = #{remark,jdbcType=VARCHAR},
            id_tree     = #{idTree,jdbcType=VARCHAR},
            create_time = #{createTime,jdbcType=TIMESTAMP},
            update_time = #{updateTime,jdbcType=TIMESTAMP}
        where id = #{id,jdbcType=INTEGER}
    </update>


    <select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_region
        where id = #{id,jdbcType=INTEGER}
    </select>


    <select id="selectRegionByOrderId" parameterType="String" resultType="Integer">
        SELECT CASE
                   WHEN
                       t.region_level = 1 THEN
                       t.country_id
                   WHEN t.region_level = 2 THEN
                       t.area_id
                   WHEN t.region_level = 3 THEN
                       t.province_id
                   WHEN t.region_level = 5 THEN
                       t.city_id
                   ELSE t.region_id
                   END AS region_id
        FROM t_order AS t
        WHERE t.id = #{orderId}
    </select>


    <select id="selectByParentId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_region
        where parent_id = #{parentId,jdbcType=INTEGER} and status=1
    </select>

    <select id="selectAll" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_region t
        <where>
            1=1
            <if test="status != null">
                and t.status = #{status}
            </if>
            <if test="ids != null">
                and t.id in
                <foreach collection="ids" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            order by t.id_tree
        </where>
    </select>

    <select id="selectByName" parameterType="java.lang.String" resultMap="BaseResultMap">
        select *
        from t_region
        where name = #{name}
          and status = 1
    </select>

    <select id="selectByCode" parameterType="java.lang.String" resultMap="BaseResultMap">
        select *
        from t_region
        where code = #{code}
    </select>

    <select id="selectSelfAndChildren" parameterType="java.lang.String" resultMap="BaseResultMap">
        select *
        from t_region
        where id_tree like concat(#{idTree}, '%')
    </select>

    <update id="updateIdTree">
        update t_region
        set id_tree = concat(#{idTreeNewPrefix}, substring(id_tree, length(#{idTreePrefix}) + 1, length(id_tree)))
        where id_tree like concat(#{idTreePrefix}, '%')
    </update>

</mapper>