UfoSizeMapper.xml 7.55 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="sizeId" column="size_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, size.order_by
    </sql>

    <insert id="insertSize" parameterType="com.yoho.ufo.model.commoditybasicrole.size.Size" useGeneratedKeys="true" keyProperty="id" >
        insert into size(id, size_name, order_by, create_time, update_time)
        values (#{id}, #{sizeName}, #{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.createTime != null">
                create_time = #{size.createTime},
            </if>
            <if test="size.updateTime != null">
                update_time = #{size.updateTime},
            </if>
            <if test="size.orderBy != null and size.orderBy !=''">
                order_by = #{size.orderBy},
            </if>
        </set>
        where id = #{size.id}
    </update>

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


    <sql id="queryPage">
        <where>
            <if test="size.sizeName != null and size.sizeName !=''">
                and size.size_name like concat('%', #{size.sizeName}, '%')
            </if>
            <if test="list != null and list.size() > 0">
                and sort_size.del = 0 and sort_size.sort_id in
		        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
		            #{item}
		        </foreach>
            </if>
        </where>
    </sql>

    <select id="selectSizeCount" resultType="integer">
        select count(*) from size
       	<if test="list != null and list.size() > 0">
            inner join sort_size on size.id = sort_size.size_id
        </if>
        <include refid="queryPage"/>
    </select>

    <select id="getSizePageList" resultMap="sizeMap">
        select <include refid="queryColumns"/> from size
        <if test="list != null and list.size() > 0">
            inner join sort_size on size.id = sort_size.size_id
        </if>
        <include refid="queryPage"/>
        order by size.order_by
        limit #{page.startIndex}, #{page.pageSize}
    </select>

    <select id="selectAllSizeBySortId" resultMap="sizeMap">
        select s.id, s.size_name
        from size s inner join sort_size ss on s.id = ss.size_id where ss.del = 0
        <if test="sortId != null and sortId >0 ">
	        and ss.sort_id = #{sortId}
        </if>
        order by ss.order_by, ss.id
    </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>

    <select id="getOrderBySortLevel2Id" resultMap="sizeMap">
        select s.id, s.size_name,ss.order_by
        from size s inner join sort_size ss on s.id = ss.size_id where ss.del = 0
        <if test="sortId != null and sortId >0 ">
	        and ss.sort_id = #{sortId}
        </if>
        order by ss.order_by, ss.id
    </select>

    <select id="selectAllSize" resultMap="sizeMap">
        select * from size
    </select>


	<insert id="addBind" parameterType="com.yoho.ufo.model.commoditybasicrole.size.Size">
        insert into sort_size(id, sort_id,size_id,order_by, create_time, update_time,del)
        values (#{id}, #{sortId},#{sizeId}, #{orderBy}, #{createTime}, #{updateTime},0)
    </insert>

	<update id="updateBind" parameterType="com.yoho.ufo.model.commoditybasicrole.size.Size">
        update sort_size
        <set>
            <if test="size.sortId != null and size.sortId >0">
                sort_id = #{size.sortId},
            </if>
            <if test="size.sizeId != null and size.sizeId >0">
                size_id = #{size.sizeId},
            </if>
            <if test="size.orderBy != null">
                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>
            <if test="size.del != null">
                del = #{size.del}
            </if>
        </set>
        where id = #{size.id}
    </update>

	<select id="getBySizeIdAndSortId" resultMap="sizeMap">
        select id, size_id,sort_id,order_by
        from sort_size where del = 0 
        <if test="sortId != null and sortId >0 ">
	        and sort_id = #{sortId}
        </if>
        <if test="sizeId != null and sizeId >0 ">
	        and size_id = #{sizeId}
        </if>
    </select>

	<select id="selectAllSizeBySortIdList" resultMap="sizeMap">
        select s.id, s.size_name,ss.order_by
        from size s inner join sort_size ss on s.id = ss.size_id where ss.del = 0
        <if test="sortIdList != null and sortIdList.size() >0 ">
        	and ss.sort_id in
	        <foreach item="item" index="index" collection="sortIdList" open="(" separator="," close=")">
	            #{item}
	        </foreach>
        </if>
        order by ss.order_by, ss.id
    </select>
    
    <select id="getBindPageList" resultMap="sizeMap">
        select * from sort_size ss where del = 0
            <if test="sortIdList != null and sortIdList.size() >0 ">
	        	and ss.sort_id in
		        <foreach item="item" index="index" collection="sortIdList" open="(" separator="," close=")">
		            #{item}
		        </foreach>
	        </if>
            <if test="size.sizeId != null and size.sizeId >0">
                and ss.size_id = #{size.sizeId} 
            </if>
        order by ss.sort_id,ss.order_by
        limit #{page.startIndex}, #{page.pageSize}
    </select>
    <select id="getBindCount" resultType="integer">
        select count(*) from sort_size ss where del = 0
            <if test="sortIdList != null and sortIdList.size() >0 ">
	        	and ss.sort_id in
		        <foreach item="item" index="index" collection="sortIdList" open="(" separator="," close=")">
		            #{item}
		        </foreach>
	        </if>
            <if test="size.sizeId != null and size.sizeId >0">
                and ss.size_id = #{size.sizeId} 
            </if>
    </select>
    <select id="getBindById" resultMap="sizeMap">
        select * from sort_size ss where id = #{id}
    </select>
    
    <select id="selectBySizeName" resultMap="sizeMap">
        select id, size_name from size where size_name = #{sizeName}
    </select>

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