UfoSizeMapper.xml 3.64 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.ufo.dal.UfoSizeMapper">

    <resultMap id="sizeMap" type="com.yoho.ufo.model.commoditybasicrole.size.Size">
        <id property="id" column="id"/>
        <result property="sizeName" column="size_name"/>
        <result property="sortId" column="sort_id"/>
        <result property="orderBy" column="order_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="queryColumns">
        size.id, size.size_name, CONCAT(IFNULL(CONCAT(sort2.sort_name,'/'),''),sort1.sort_name) AS sortName, size.order_by
    </sql>

    <insert id="insertSize" parameterType="com.yoho.ufo.model.commoditybasicrole.size.Size">
        insert into size(id, size_name, sort_id, order_by, create_time, update_time)
        values (#{id}, #{sizeName}, #{sortId}, #{orderBy}, #{createTime}, #{updateTime})
    </insert>




    <update id="updateSize" parameterType="com.yoho.ufo.model.commoditybasicrole.size.Size">
        update size
        <set>
            <if test="size.sizeName != null and size.sizeName !=''">
                size_name = #{size.sizeName},
            </if>
            <if test="size.sortId != null and size.sortId != ''">
                sort_id = #{size.sortId},
            </if>
            <if test="size.orderBy != null and size.orderBy != ''">
                order_by = #{size.orderBy},
            </if>
            <if test="size.createTime != null">
                create_time = #{size.createTime},
            </if>
            <if test="size.updateTime != null">
                update_time = #{size.updateTime}
            </if>
        </set>
        where id = #{size.id}
    </update>

    <select id="selectOneById" resultMap="sizeMap">
        select id, size_name, sort_id, order_by
        from size where id = #{id}
    </select>


    <sql id="queryPage">
        from size
        LEFT JOIN product_sort sort1
        ON size.sort_id = sort1.id
        left join product_sort sort2
        on sort1.parent_id = sort2.id
        <where>
            <if test="size.sortName != null and size.sortName != ''">
                sort1.sort_name like concat('%', #{size.sortName}, '%') or sort2.sort_name like concat('%', #{size.sortName}, '%')
            </if>
            <if test="size.sizeName != null and size.sizeName !=''">
                and size.size_name like concat('%', #{size.sizeName}, '%')
            </if>
        </where>
    </sql>

    <select id="selectSizeCount" resultType="integer">
        select count(*)
        <include refid="queryPage"/>
    </select>

    <select id="getSizePageList" resultMap="sizeMap">
        select <include refid="queryColumns"/>
        <include refid="queryPage"/>
        order by size.update_time desc
        limit #{page.startIndex}, #{page.pageSize}
    </select>


    <select id="selectAllSizeBySortId" resultMap="sizeMap">
        select <include refid="queryColumns"/>
        from size where sort_id = #{sortId}
    </select>
    <select id="selectAllSizeBySortId" resultMap="sizeMap">
        select id,size_name
        from size where sort_id in
        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">  
	  		#{item}  
	 	</foreach>
    </select>

    <select id="selectByIdList" resultMap="sizeMap">
        select id, size_name
        from size where id in
        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
</mapper>