ProductPop.xml 15.4 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.diligrp.titan.dao.product.pop.ProductPopDao">

	<!-- product_pop 所有查询列 -->
	<sql id="QUERY_COLUMN_LIST">
		<![CDATA[pid,name,product_type AS productType,product_sample AS productSample,has_special AS hasSpecial,is_allow_delivery AS isAllowDelivery,has_express AS hasExpress,quotation_type AS quotationType,cate_id AS cateId,user_defined AS userDefined,producing_area AS producingArea,localityName,locality_area AS localityArea,country_area AS countryArea,foreign_city_name AS foreignCityName,seller,seller_name AS sellerName,shop,shop_name AS shopName,indate,publish_mode AS publishMode,publish_settime AS publishSettime,publish_time AS publishTime,drops_time AS dropsTime,status,foreign_pid AS foreignPid,store_unit AS storeUnit,prepare_time AS prepareTime,manual_audit_type as manualAuditType,extend,ctime,utime]]>
	</sql>

	<!-- product_pop 查询列来源表-->
	<sql id="QUERY_FROM_TABLE"><![CDATA[FROM product_pop]]></sql>
	
	<!-- 全部条件(更多功能可以通过queryData扩展实现)  -->
	<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 name = #{name}]]></if>
			<if test="productType != null and productType != ''"><![CDATA[AND product_type = #{productType}]]></if>
			<if test="productSample != null and productSample != ''"><![CDATA[AND product_sample = #{productSample}]]></if>
			<if test="quotationType != null and quotationType != ''"><![CDATA[AND quotation_type = #{quotationType}]]></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="localityName != null and localityName != ''"><![CDATA[AND localityName = #{localityName}]]></if>
			<if test="countryArea != null and countryArea != ''"><![CDATA[AND country_area = #{countryArea}]]></if>
			<if test="foreignCityName != null and foreignCityName != ''"><![CDATA[AND foreign_city_name = #{foreignCityName}]]></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="shopName != null and shopName != ''"><![CDATA[AND shop_name = #{shopName}]]></if>
			<if test="indate != null and indate != ''"><![CDATA[AND indate = #{indate}]]></if>
			<if test="publishMode != null and publishMode != ''"><![CDATA[AND publish_mode = #{publishMode}]]></if>
			<if test="publishSettime != null and publishSettime != ''"><![CDATA[AND publish_settime = #{publishSettime}]]></if>
			<if test="publishTime != null and publishTime != ''"><![CDATA[AND publish_time = #{publishTime}]]></if>
			<if test="dropsTime != null and dropsTime != ''"><![CDATA[AND drops_time = #{dropsTime}]]></if>
			<if test="status != null and status != ''"><![CDATA[AND status = #{status}]]></if>
			<if test="foreignPid != null and foreignPid != ''"><![CDATA[AND foreign_pid = #{foreignPid}]]></if>
			<if test="storeUnit != null and storeUnit != ''"><![CDATA[AND store_unit = #{storeUnit}]]></if>
			<if test="manualAuditType != null and manualAuditType != ''"><![CDATA[AND manual_audit_type = #{manualAuditType}]]></if>
			<if test="prepareTime != null and prepareTime != ''"><![CDATA[AND prepare_time = #{prepareTime}]]></if>
			<if test="ctime != null and ctime != ''"><![CDATA[AND ctime = #{ctime}]]></if>
			<if test="utime != null and utime != ''"><![CDATA[AND utime = #{utime}]]></if>
		</where>
	</sql>
	
	<sql id="Query_SearchPopProduct_COLUMN_SET">
				<where>
                    <if test="pstates != null and pstates != ''"><![CDATA[AND status IN ]]>
                        <foreach collection="pstates" item="pstate" open="(" separator="," close=")">
                            <![CDATA[#{pstate}]]>
                        </foreach>
                    </if>
                    <if test="pstate != null and pstate != '' and pstate>=4"><![CDATA[AND status >3]]></if>
                    <if test="pstate != null and pstate != '' and pstate &lt; 4"><![CDATA[AND status = #{pstate}]]></if>
					<if test="storeId != null"><![CDATA[ AND shop = #{storeId}]]></if>
					<if test="title != null and title != ''"><![CDATA[AND name like CONCAT('%',#{title},'%')]]></if>
					<if test="cname != null and cname != ''"><![CDATA[AND cate_id = #{cname}]]></if>
					<if test="productType != null and productType != ''"><![CDATA[AND product_type = #{productType}]]></if>
					<if test="productSample != null and productSample != ''"><![CDATA[AND product_sample = #{productSample}]]></if>
					<if test="begin != null and begin != ''"><![CDATA[AND  drops_time >= #{begin}]]></if>
					<if test="end != null and end != ''"><![CDATA[AND drops_time = #{end}]]></if>
					<if test="begin != null and end == null "><![CDATA[AND drops_time > #{begin}]]></if>
					<if test="begin  == null and end != null "><![CDATA[AND drops_time < DATE_ADD(#{end},INTERVAL 1 DAY)]]></if>
					<if test="begin != null and end != null  and begin != '' and end!= '' "><![CDATA[AND drops_time between #{begin} and DATE_ADD(#{end},INTERVAL 1 DAY)]]></if>
					<if test="createBegin != null and createEnd == null "><![CDATA[AND ctime > #{createBegin}]]></if>
					<if test="createBegin  == null and createEnd != null "><![CDATA[AND ctime < DATE_ADD(#{createEnd},INTERVAL 1 DAY)]]></if>
					<if test="createBegin != null and createEnd != null  and begin != '' and end!= '' "><![CDATA[AND ctime between #{createBegin} and DATE_ADD(#{createEnd},INTERVAL 1 DAY)]]></if>
				</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>

	<!-- 更新列字段,只要不为NULL则更新,除开主键列 -->
    <sql id="UPDATE_COLUMN_SET">
        <set>
            <if test="manualAuditType != null and manualAuditType != ''"><![CDATA[ manual_audit_type = #{manualAuditType},]]></if>
            <if test="name != null and name != ''"><![CDATA[ name = #{name},]]></if>
			<if test="productType != null and productType != ''"><![CDATA[AND product_type = #{productType}]]></if>
			<if test="productSample != null and productSample != ''"><![CDATA[AND product_sample = #{productSample}]]></if>
            <if test="quotationType != null and quotationType != ''"><![CDATA[ quotation_type = #{quotationType},]]></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="localityName != null and localityName != ''"><![CDATA[ localityName = #{localityName},]]></if>
			<if test="localityArea != null and localityArea != ''"><![CDATA[ locality_area = #{localityArea},]]></if>
            <if test="countryArea != null and countryArea != ''"><![CDATA[ country_area = #{countryArea},]]></if>
            <if test="foreignCityName != null and foreignCityName != ''"><![CDATA[ foreign_city_name = #{foreignCityName},]]></if>
            <if test="seller != null and seller != ''"><![CDATA[ seller = #{seller},]]></if>
            <if test="shop != null and shop != ''"><![CDATA[ shop = #{shop},]]></if>
			<if test="hasExpress != null and hasExpress != ''"><![CDATA[ has_express = #{hasExpress},]]></if>
			<if test="isAllowDelivery != null and isAllowDelivery != ''"><![CDATA[ is_allow_delivery = #{isAllowDelivery},]]></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"><![CDATA[foreign_pid = #{foreignPid},]]></if>
            <if test="extend != null and extend != '' "><![CDATA[`extend` = #{extend},]]></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,product_type,product_sample,has_special,is_allow_delivery,has_express,quotation_type,cate_id,producing_area,localityName,locality_area,country_area,foreign_city_name,seller,seller_name,shop,shop_city_id,shop_type,shop_name,market_id,market_name,indate,publish_mode,publish_settime,status,ctime,prepare_time,foreign_pid,store_unit,extend)
			VALUES (#{pid},#{name},#{productType},#{productSample},#{hasSpecial},#{isAllowDelivery},#{hasExpress},#{quotationType},#{cateId},#{producingArea},#{localityName},#{localityArea},#{countryArea},#{foreignCityName},#{seller},#{sellerName},#{shop},#{shopCityId},#{shopType},#{shopName},#{marketId},#{marketName},#{indate},#{publishMode},#{publishSettime},#{status},now(),#{prepareTime},#{foreignPid},#{storeUnit},#{extend})
		]]>
	</insert>
	
	<!-- 返回插入的编号,在事务开启状态下有效 -->
	<select id="lastSequence" resultType="int"><![CDATA[SELECT LAST_INSERT_ID() AS pid]]></select>

	<!-- 删除记录,主键IN(array) -->
	<delete id="deleteByArrayKey" parameterType="java.lang.reflect.Array" >
		<![CDATA[DELETE FROM product_pop WHERE pid IN]]>
		<foreach collection="array" item="pid" open="(" separator="," close=")">
			<![CDATA[#{pid}]]>
		</foreach>
	</delete>

	<!-- 删除,通过条件 -->
	<update id="deleteByCondtion" parameterType="productPop" >
		<![CDATA[DELETE FROM product_pop]]>
		<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>

	<!-- 查询,通过主键IN(array) -->
	<select id="selectEntryArray" parameterType="java.lang.reflect.Array" resultType="productPop">
		<![CDATA[SELECT]]>
		<include refid="QUERY_COLUMN_LIST"/>
		<include refid="QUERY_FROM_TABLE"/>
		<![CDATA[WHERE pid IN]]>
		<foreach collection="array" item="pid" open="(" separator="," close=")">
			<![CDATA[#{pid}]]>
		</foreach>
	</select>

	<!-- 查询,通过条件 -->
	<select id="selectEntryList" parameterType="productPop" resultType="productPop">
		<![CDATA[SELECT]]>
		<include refid="QUERY_COLUMN_LIST"/>
		<include refid="QUERY_FROM_TABLE"/>
		<include refid="QUERY_WHERE_CLAUSE"/>
		<include refid="QUERY_ORDER_LIMIT_CONDTION"/>
	</select>

	<!-- 总数查询,通过条件 -->
	<select id="selectEntryListCount" parameterType="productPop" resultType="int">
		<![CDATA[SELECT COUNT(pid) AS dataCount]]>
		<include refid="QUERY_FROM_TABLE"/>
		<include refid="QUERY_WHERE_CLAUSE"/>
	</select>
	
	<!-- 其它SQL语句 -->
    <!-- 删除第三方产品信息 -->
    <update id="delProduct" parameterType="java.util.Map">
        UPDATE product_pop
        SET status=-1
        WHERE
        pid IN
        <foreach collection="list" item="item" separator="," open="(" close=")">
            <![CDATA[#{item} ]]>
        </foreach>
        <if test="sellerID!=null">
            <![CDATA[  AND seller=#{sellerID} ]]>
        </if>
    </update>

    <!-- 更新第三方产品信息状态 -->
    <update id="updatePopProductStatus" parameterType="java.util.Map">
        UPDATE
        product_pop
        SET
        <![CDATA[ status=#{status}]]>
        <if test="status==3">
            ,publish_time=now(),publish_mode=2,publish_settime=null
        </if>
        <if test="status==7">
            ,drops_time =now(),publish_mode=1,publish_settime=null
        </if>
        WHERE
        <![CDATA[seller=#{sellerId}]]>
        and
        pid IN
        <foreach collection="list" item="item" separator="," open="(" close=")">
            <![CDATA[#{item} ]]>
        </foreach>
    </update>
    <!-- 设置第三商品库分类 -->
    <update id="setProductVirtualCid" parameterType="java.util.Map">
        UPDATE
        product_pop
        SET
        <![CDATA[ user_defined=#{vcid}]]>
        WHERE
        pid IN
        <foreach collection="list" item="item" separator="," open="(" close=")">
            <![CDATA[#{item} ]]>
        </foreach>
    </update>

    <select id="listLatestProductId" parameterType="java.util.Map" resultType="java.lang.Long">
        <![CDATA[SELECT pid ]]>
        <include refid="QUERY_FROM_TABLE"/>
        <![CDATA[
            WHERE shop = #{shopId} AND status = 3
            ORDER BY ctime desc
            LIMIT #{num}
        ]]>
    </select>

    
    <!--查询用户中心三方商品信息  -->
	<select id="selectSearchListPopProductEntryList" parameterType="popProductSearchInput" resultType="long">
<!-- 	    SELECT  t.`pid`,t.`name`,t.`quotation_type`,t.`cate_id`, t.`store_unit`, t.`indate`, t.`status`, t.`publish_mode`, t.`publish_settime`,t.`publish_time`, t.`drops_time`, t.`ctime`, t.`utime`  FROM  product_pop t  -->
		SELECT  t.`pid` FROM  product_pop t 
		<include refid="Query_SearchPopProduct_COLUMN_SET"/>
		<include refid="QUERY_ORDER_LIMIT_CONDTION" />
	</select>
	
   <!-- 查询类目列表 -->
	<select id="selectPopProductCategroyByShopId" parameterType="java.util.Map" resultType="int">
	    SELECT DISTINCT  t.`cate_id` FROM product_pop t WHERE t.`shop`=#{shopId} 
	    <if test="pstatus != null and pstatus != '' and pstatus>=4"><![CDATA[ AND t.`status` >3]]></if>
	    <if test="pstatus != null and pstatus != '' and pstatus &lt; 4"><![CDATA[AND t.`status` = #{pstatus}]]></if>
	</select>

    <select id="selectCountByShopId" parameterType="java.lang.Long" resultType="int">
        <![CDATA[SELECT COUNT(pid) ]]>
        <include refid="QUERY_FROM_TABLE"/>
        <![CDATA[WHERE shop=#{shopId} and status>0 ]]>
    </select>

    <select id="countVirtualCatProducts" parameterType="java.lang.Long" resultType="long">
        <![CDATA[SELECT COUNT(pid) ]]>
        <include refid="QUERY_FROM_TABLE"/>
        <![CDATA[WHERE user_defined=#{vcid} and status>0 ]]>
    </select>

    <select id="getCommonCateIds" parameterType="java.lang.Long" resultType="int">
        <![CDATA[SELECT cate_id ]]>
        <include refid="QUERY_FROM_TABLE"/>
        <![CDATA[WHERE seller=#{userId} and status>0 GROUP BY cate_id ORDER BY count(pid) desc]]>
    </select>
    
    <select id="getCateIdByPids" parameterType="java.util.List" resultType="int">
        <![CDATA[select distinct cate_id AS cateId from product_pop where pid in]]>
        <foreach collection="list" item="item" separator="," open="(" close=")">
            <![CDATA[#{item} ]]>
        </foreach>
    </select>
        
</mapper>