ProductPop.xml 9.29 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.dili.titan.dao.ProductPopDao">

	<resultMap type="productPop" id="productPop">
		<result property="pid" javaType="Long" column="pid"/>
		<result property="name" javaType="String" column="name"/>
        <result property="quotationType" javaType="Integer" column="quotation_type"/>
		<result property="cateId" javaType="Integer" column="cate_id"/>
		<result property="userDefined" javaType="Integer" column="user_defined"/>
		<result property="cate" javaType="String" column="cate"/>
		<result property="status" javaType="Integer" column="status"/>
		<result property="publishSettime" javaType="Date" column="publish_settime"/>
		<result property="publishTime" javaType="Date" column="publish_time"/>
		<result property="publishMode" javaType="Integer" column="publish_mode"/>
		<result property="prepareTime" javaType="Long" column="prepare_time"/>
		<result property="dropsTime" javaType="Date" column="drops_time"/>
		<result property="ctime" javaType="Date" column="ctime"/>
		<result property="utime" javaType="Date" column="utime"/>
		<result property="desc" javaType="String" column="desc"/>
		<result property="minPrice" javaType="Integer" column="minPrice"/>
		<result property="maxPrice" javaType="Integer" column="maxPrice"/>
		<result property="producingArea" javaType="Long" column="producing_area"/>
		<result property="localityArea" javaType="Long" column="locality_area"/>
		<result property="sellerName" javaType="String" column="seller_name"/>
		<result property="seller" javaType="Long" column="seller"/>
		<result property="shop" javaType="Long" column="shop"/>
		<result property="shopName" javaType="String" column="shop_name"/>
		<result property="indate" javaType="Integer" column="indate"/>
		<result property="defaultPic" javaType="String" column="img_url"/>
		<result property="storeUnit" javaType="Integer" column="store_unit"/>
<!-- 		<collection property="deliveryArea" javaType="ArrayList" ofType="delivery">
			<result property="deliId" column="deli_id" javaType="Integer"/>
			<result property="deliName" column="deli_name" javaType="String"/>
			<result property="deliType" column="deli_type" javaType="Integer"/>
		</collection> -->
		<collection property="subCateList" javaType="ArrayList" ofType="category">
			<result property="id" column="id" javaType="Integer"/>
		</collection>
<!-- 		<collection property="skus" javaType="ArrayList" ofType="sku"> -->
<!-- 		    <result property="sku" column="sku" javaType="String" /> -->
<!-- 		    <result property="remark" column="title" javaType="String" /> -->
<!-- 		    <result property="stockNum" column="store" javaType="Integer" /> -->
<!-- 		    <result property="minNum" column="mini_purchase" javaType="Integer"/> -->
<!-- 		    <result property="price" column="price" javaType="Integer"/> -->
<!-- 		</collection> -->
	</resultMap>
	
	<!-- 全部条件(更多功能可以通过queryData扩展实现) 为防止column名重复,查询时将product_pop表取别名为a-->
	<sql id="QUERY_WHERE_CLAUSE">
		<where>
			<if test="pid != null and pid != ''"><![CDATA[AND pid = #{pid}]]></if>
			<if test="name != null and name != ''"><![CDATA[AND a.name = #{name}]]></if>
			<if test="cateId != null and cateId != ''"><![CDATA[AND cate_id = #{cateId}]]></if>
		    <if test="userDefined != null and userDefined != ''"><![CDATA[AND user_defined = #{userDefined}]]></if>
			<if test="producingArea != null and producingArea != ''"><![CDATA[AND producing_area = #{producingArea}]]></if>
			<if test="seller != null and seller != ''"><![CDATA[AND seller = #{seller}]]></if>
			<if test="sellerName != null and sellerName != ''"><![CDATA[AND seller_name = #{sellerName}]]></if>
			<if test="shop != null and shop != ''"><![CDATA[AND shop = #{shop}]]></if>
			<if test="publishMode != null and publishMode != ''"><![CDATA[AND publish_mode = #{publishMode}]]></if>
			<if test="publishTime != null and publishTime != ''"><![CDATA[AND publish_time = #{publishTime}]]></if>
			<if test="status != null and status != '' and status &lt; 4"><![CDATA[AND a.status = #{status}]]></if>
			<if test="userDefined !=null and userDefined !='' "><![CDATA[AND user_defined = #{userDefined}]]></if>
			<if test="status != null and status != '' and status>=4"><![CDATA[AND a.status >3]]></if>
			<if test="startTime != null and endTime == null "><![CDATA[AND ctime > #{startTime}]]></if>
			<if test="startTime == null and endTime != null "><![CDATA[AND ctime < DATE_ADD(#{endTime},INTERVAL 1 DAY)]]></if>
			<if test="startTime != null and endTime != null  and startTime != '' and endTime!= '' "><![CDATA[AND ctime between #{startTime} and DATE_ADD(#{endTime},INTERVAL 1 DAY)]]></if>
			<if test="utime != null and utime != ''"><![CDATA[AND utime = #{utime}]]></if>
			<![CDATA[AND a.status > 0]]>
		</where>
	</sql>

	<!-- 智能排序与分页 -->
	<sql id="QUERY_ORDER_LIMIT_CONDTION">
		<if test="orderField != null and orderField != '' and orderFieldType != null and orderFieldType != ''"><![CDATA[ORDER BY ${orderField} ${orderFieldType}]]></if>
		<if test="startIndex != null and startIndex &gt;= 0 and pageSize != null and pageSize &gt; 0"><![CDATA[LIMIT #{startIndex},#{pageSize}]]></if>
	</sql>
	
	<sql id="UPDATE_COLUMN_SET">
		<set>
			<if test="name != null and name != ''"><![CDATA[ name = #{name},]]></if>
			<if test="cateId != null and cateId != ''"><![CDATA[cate_id = #{cateId},]]></if>
			<if test="producingArea != null and producingArea != ''"><![CDATA[ producing_area = #{producingArea},]]></if>
			<if test="seller != null and seller != ''"><![CDATA[ seller = #{seller},]]></if>
			<if test="shop != null and shop != ''"><![CDATA[ shop = #{shop},]]></if>
			<if test="publishMode != null and publishMode != '' and publishMode > 0 "><![CDATA[ publish_mode = #{publishMode},]]></if>
			<if test="publishTime != null and publishTime != ''"><![CDATA[ publish_time = #{publishTime},]]></if>
			<if test="publishSettime != null and publishSettime != ''"><![CDATA[ publish_settime = #{publishSettime},]]></if>
			<if test="prepareTime != null and prepareTime != ''"><![CDATA[ prepare_time = #{prepareTime},]]></if>
			<if test="dropsTime != null and dropsTime != ''"><![CDATA[ drops_time = #{dropsTime},]]></if>
			<if test="status != null and status != ''"><![CDATA[`status` = #{status},]]></if>
			<if test="foreignPid != null and foreignPid != ''"><![CDATA[ foreign_pid = #{foreignPid},]]></if>
			<if test="ctime != null and ctime != ''"><![CDATA[ ctime = #{ctime},]]></if>
			<![CDATA[ utime = now()]]>
		</set>
	</sql>



	<!-- 插入product_pop记录 -->
	<insert id="insertEntry" parameterType="productPop">
		<![CDATA[
			INSERT INTO product_pop (pid,name,quotation_type,cate_id,producing_area,seller,seller_name,shop,shop_name,indate,publish_mode,publish_settime,status,ctime,prepare_time,foreign_pid,store_unit)
			VALUES (#{pid},#{quotationType},#{name},#{cateId},#{producingArea},#{seller},#{sellerName},#{shop},#{shopName},#{indate},#{publishMode},#{publishSettime},#{status},now(),#{prepareTime},#{foreignPid},#{storeUnit})
		]]>
	</insert>

	<!-- 删除,通过条件 -->
	<update id="deleteByCondtion" parameterType="productPop">
		<![CDATA[DELETE FROM product_pop a]]>
		<include refid="QUERY_WHERE_CLAUSE" />
	</update>

	<!-- 修改记录通过主键 -->
	<update id="updateByKey" parameterType="productPop">
		<![CDATA[UPDATE product_pop]]>
		<include refid="UPDATE_COLUMN_SET"/>
		<![CDATA[WHERE pid = #{pid}]]>
	</update>

	<update id="setProductLocalityArea" parameterType="java.util.Map">
	    <![CDATA[UPDATE product_pop SET locality_area = #{cityId}]]>
		<![CDATA[ WHERE  shop = #{shopId}]]>
	</update>
    <update id="setShopCityId" parameterType="java.util.Map">
        <![CDATA[UPDATE product_pop SET shop_city_id = #{cityId}]]>
        <![CDATA[ WHERE  shop = #{shopId}]]>
    </update>
	<select id="selectProductIdByShopId" parameterType="java.lang.Long" resultType="long">
		<![CDATA[ select pid from  product_pop where shop = #{shopId}]]>
	</select>

	<update id="setShopName" parameterType="java.util.Map">
		<![CDATA[UPDATE product_pop SET shop_name = #{shopName}]]>
		<![CDATA[ WHERE  shop = #{shopId}]]>
	</update>

	<update id="setUserName" parameterType="java.util.Map">
		<![CDATA[UPDATE product_pop SET seller_name = #{userName}]]>
		<![CDATA[ WHERE  seller = #{userId}]]>
	</update>

	<update id="setMarket" parameterType="java.util.Map">
		<![CDATA[UPDATE product_pop SET market_id = #{marketId},market_name = #{marketName} ]]>
		<![CDATA[ WHERE   shop = #{shopId} ]]>
	</update>

	<select id="selectDropsProduct" parameterType="java.lang.Long" resultType="long">
		<![CDATA[ select pid from  product_pop where shop = #{shopId} and (status = 3 or publish_mode = 3)]]>
	</select>

	<update id="dropsProduct" parameterType="java.lang.Long">
		<![CDATA[
             UPDATE product_pop SET status=4,drops_time =now(),publish_mode=1,publish_settime=null
            WHERE shop=#{shopId} and (status = 3 or publish_mode = 3)
            ]]>
	</update>

	<select id="selectDelProduct" parameterType="java.lang.Long" resultType="long">
		<![CDATA[ select pid from  product_pop where shop = #{shopId} and status>0 ]]>
	</select>

	<update id="delProduct" parameterType="java.lang.Long">
		<![CDATA[
             UPDATE product_pop SET status=-1
            WHERE shop=#{shopId} and status>0
            ]]>
	</update>

</mapper>