IMCampaignCategoryMapper.xml 16.3 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.sibu.orderHelper.integral.web.dao.IMWebCampaignCategoryDao">
    
    <select id="get" resultMap="IMCampaignCategoryMap" parameterType="java.util.Map">
        SELECT
            *
        FROM
            im_campaign_category 
        WHERE
            im_campaign_category_id=#{campaignCategoryId}
    </select>
    
    <select id="list" parameterType="map"  resultMap="IMCampaignCategoryMap">
        SELECT cam.* FROM im_campaign_category cam
        LEFT JOIN campaign_product cap ON cam.`im_campaign_category_id` = cap.campaign_id
        LEFT JOIN im_product imp ON cap.product_id = imp.im_product_id
        where cam.delete_flag = 1
        <if test="campaignKeyword != null and campaignKeyword !=''">
            and cam.name like concat('%',#{campaignKeyword},'%')
        </if>
        <if test="isShow != null and isShow !=''">
            and cam.is_show = ${isShow}
        </if>
        <if test="campaginType != null and campaginType !=''">
            and cam.campagin_type = ${campaginType}
        </if>
        <if test="productKeyword != null and productKeyword !=''">
            and imp.name like concat('%',#{productKeyword},'%')
        </if>
        GROUP BY cam.`name`
        order by cam.sort_index
        LIMIT ${pageNow}, ${pageSize}
    </select>
    <select id="totalCountCampagin" resultType="int" parameterType="map">
        SELECT COUNT(*) FROM (
        SELECT  cam.* FROM  im_campaign_category    cam
        LEFT JOIN campaign_product cap ON cam.`im_campaign_category_id` = cap.campaign_id
        LEFT JOIN im_product imp ON cap.product_id = imp.im_product_id
        where cam.delete_flag = 1
        <if test="campaignKeyword != null and campaignKeyword !=''">
            and cam.name like concat('%',#{campaignKeyword},'%')
        </if>
        <if test="isShow != null and isShow !=''">
            and cam.is_show = ${isShow}
        </if>
        <if test="campaginType != null and campaginType !=''">
            and cam.campagin_type = ${campaginType}
        </if>
        <if test="productKeyword != null and productKeyword !=''">
            and imp.name like concat('%',#{productKeyword},'%')
        </if>
        GROUP BY cam.`name`) a
    </select>
    
    <select id="listToIndex" resultMap="IMCampaignCategoryMap">
    	SELECT
            *
        FROM
            im_campaign_category where delete_flag = 1 and is_show = 1 and campagin_type = 0
        order by sort_index
    </select>

    <select id="listCampaignCategoryToAdvert" resultMap="IMCampaignCategoryMap">
        SELECT  *  FROM
        im_campaign_category where delete_flag = 1 and is_show = 1
        order by sort_index
    </select>

    <insert id="add" parameterType="IMCampaignCategoryBean" useGeneratedKeys="true" keyProperty="im_campaign_category_id">
        insert into im_campaign_category(name,image_url,is_show,sort_index,create_dt,delete_flag, campagin_type)
        values(
	        #{name},
	        #{imageUrl},
	        #{isShow},
	        #{sortIndex},
	        now(),
	        1,
	        #{campaginType}
        )
    </insert>

    <!--添加专场商品-->
    <insert id="addCampaginProduct" parameterType="com.sibu.orderHelper.integral.request.CampaginProductAddRequest">
        insert into campaign_product (campaign_id, product_id, product_type, is_show)
        VALUES (#{campaginId}, #{productId}, #{productType}, #{isShow})
    </insert>

    <insert id="addCampaginProducts" parameterType="java.util.List">
        INSERT INTO campaign_product (
        campaign_id, product_id, product_type, is_show
        ) VALUES
        <foreach collection="list" item="campaginProduct" separator=",">
            (#{campaginProduct.campaginId}, #{campaginProduct.productId}, #{campaginProduct.productType}, #{campaginProduct.isShow})
        </foreach>
    </insert>

    <!--更新专场-->
    <update id="updateCampaginProduct" parameterType="java.util.Map">
        update campaign_product set campaign_id = #{campaginId} where product_id = #{productId}
    </update>

    <!--更新专场商品的上下架状态-->
    <update id="updateCampaginProductStatus" parameterType="java.util.Map">
        update campaign_product set is_show = #{isShow} where product_id = #{productId}
    </update>

    <!--删除专场中的商品-->
    <delete id="deleteCampaginProduct" parameterType="java.lang.String">
        delete from campaign_product where product_id = #{productId}
    </delete>

    <!--删除专场中的一个商品-->
    <delete id="deleteOneProductById" parameterType="com.sibu.orderHelper.integral.request.CampaginDeleteProductRequest">
        delete from campaign_product where campaign_id = #{campaginId} AND product_id = #{productId}
    </delete>

    <!--删除专场级联删除商品-->
    <delete id="deleteCampaginProductByCampaginId" parameterType="java.lang.Integer">
        DELETE from campaign_product where campaign_id = #{campaginId}
    </delete>

    <select id="totalCampaginProduct" parameterType="java.util.Map" resultType="int">
        select count(*) from campaign_product where campaign_id = #{campaginId} AND product_id = #{productId}
    </select>

    <select id="checkCampaginProductExist" parameterType="com.sibu.orderHelper.integral.request.CampaginProductAddRequest" resultType="int">
        select count(*) from campaign_product where campaign_id = #{campaginId} and product_id = #{productId}
    </select>

    <select id="pagerProduct" parameterType="map" resultMap="listIMProduct">
        SELECT
        imp.im_product_id,
        imp.name,
        imp.short_name,
        imp.stock_num,
        imp.exchange_integral,
        imp.xws_exchange_integral,
        imp.sibukg_exchange_integral,
        imp.onther1_exchange_integral,
        imp.onther2_exchange_integral,
        imp.onther3_exchange_integral,
        imp.thumb_img,
        imp.is_new,
        imp.is_hot,
        imp.is_reco,
        imp.create_date,
        imp.limit_exchange_number,
        imp.product_type,
        imp.member_price,
        imp.retail_price,
        imp.market_price,
        imp.is_show,
        imp.is_open_spec,
        imp.spec,
        imp.mini_purchase_number,
        imp.erp_code,
        imp.product_campagin,
        imp.is_group,
        s.id AS supplierId,
        s.name AS supplierName
        FROM
        im_product imp
        LEFT JOIN im_product_supplier ps ON imp.im_product_id = ps.product_id
        LEFT JOIN im_supplier s ON ps.supplier_id = s.id
        WHERE
        imp.delete_flag = 1 and imp.is_show = 1
        <if test="categoryId !=null and categoryId != ''">
            and (imp.im_category_id =#{categoryId} or
            imp.im_category_id in (select ic.im_category_id from im_category ic where ic.child_category_id = #{categoryId})
            or imp.im_category_id in (select ic3.im_category_id from im_category ic3 where ic3.child_category_id in (select ic.im_category_id from im_category ic where ic.child_category_id = #{categoryId})))
        </if>
        <if test="keyword != null and keyword !=''">
            and imp.name like concat('%',#{keyword},'%')
        </if>
        and imp.product_type = 1 and imp.im_product_id not IN
        (select cp.product_id from campaign_product cp
        LEFT join im_campaign_category cc on cp.campaign_id=cc.im_campaign_category_id
        where cp.campaign_id = #{campaignId} and cp.product_type = 1 and cc.delete_flag=1)
        ORDER BY
        imp.create_date desc
        LIMIT
        ${pageNow}, ${pageSize}
    </select>

    <select id="totalPagerProduct" parameterType="java.util.Map" resultType="int">
        select count(*) from im_product imp where imp.delete_flag = 1 and imp.is_show = 1
        <if test="categoryId !=null and categoryId != ''">
            and (imp.im_category_id =#{categoryId} or
            imp.im_category_id in (select ic.im_category_id from im_category ic where ic.child_category_id = #{categoryId})
            or imp.im_category_id in (select ic3.im_category_id from im_category ic3 where ic3.child_category_id in (select ic.im_category_id from im_category ic where ic.child_category_id = #{categoryId})))
        </if>
        <if test="keyword != null and keyword !=''">
            and imp.name like concat('%',#{keyword},'%')
        </if>
        and imp.product_type = 1
        and imp.im_product_id not IN
        (select cp.product_id from campaign_product cp
        LEFT join im_campaign_category cc on cp.campaign_id=cc.im_campaign_category_id
        where cp.campaign_id = #{campaignId} and cp.product_type = 1 and cc.delete_flag=1)
    </select>

    <select id="pagerCampaginProduct" parameterType="map" resultMap="listIMProduct">
        SELECT
        imp.im_product_id,
        imp.name,
        imp.short_name,
        imp.stock_num,
        imp.exchange_integral,
        imp.xws_exchange_integral,
        imp.sibukg_exchange_integral,
        imp.onther1_exchange_integral,
        imp.onther2_exchange_integral,
        imp.onther3_exchange_integral,
        imp.thumb_img,
        imp.is_new,
        imp.is_hot,
        imp.is_reco,
        imp.create_date,
        imp.limit_exchange_number,
        imp.product_type,
        imp.member_price,
        imp.retail_price,
        imp.market_price,
        imp.cost,
        imp.is_show,
        imp.is_open_spec,
        imp.spec,
        imp.mini_purchase_number,
        imp.erp_code,
        imp.product_campagin,
        imp.is_group,
        cp.campaign_sort_index,
        cp.id AS campaignProductId,
        s.id AS supplierId,
        s.name AS supplierName
        FROM campaign_product cp
        LEFT JOIN im_campaign_category cc on cc.im_campaign_category_id=cp.campaign_id
        LEFT JOIN im_product imp ON cp.product_id=imp.im_product_id
        LEFT JOIN im_product_inventory imi on imp.im_product_id=imi.im_product_id
        LEFT JOIN im_product_supplier ps ON imp.im_product_id = ps.product_id
        LEFT JOIN im_supplier s ON ps.supplier_id = s.id
        WHERE  imp.delete_flag=1  AND  cp.campaign_id = #{campaignId} and cc.campagin_type=#{campaginType}
               and imp.audit_flag = 100 and imp.is_show=1
        <if test="keyword != null and keyword !=''">
            and imp.name like concat('%',#{keyword},'%')
        </if>
        ORDER BY cp.campaign_sort_index,imp.member_price,imi.cost DESC
        LIMIT  ${pageNow}, ${pageSize}
    </select>

    <select id="totalPagerCampaginProduct" parameterType="java.util.Map" resultType="int">
        select count(*)  FROM campaign_product cp
        LEFT JOIN im_campaign_category cc on cc.im_campaign_category_id=cp.campaign_id
        LEFT JOIN im_product imp ON cp.product_id=imp.im_product_id
        LEFT JOIN im_product_inventory imi on imp.im_product_id=imi.im_product_id
        LEFT JOIN im_product_supplier ps ON imp.im_product_id = ps.product_id
        LEFT JOIN im_supplier s ON ps.supplier_id = s.id
        WHERE  imp.delete_flag=1  AND  cp.campaign_id = #{campaignId} and cc.campagin_type=#{campaginType}
        and imp.audit_flag = 100 and imp.is_show=1
        <if test="keyword != null and keyword !=''">
            and imp.name like concat('%',#{keyword},'%')
        </if>
    </select>

    <resultMap type="IMProductBean" id="listIMProduct">
        <result column="im_product_id" property="imProductId" />
        <result column="im_category_id" property="imCategoryId" />
        <result column="name" property="name" />
        <result column="short_name" property="shortName" />
        <result column="stock_num" property="stockNum" />
        <result column="details" property="details" />
        <result column="exchange_integral" property="exchangeIntegral" />
        <result column="xws_exchange_integral" property="xwsExchangeIntegral" />
        <result column="sibukg_exchange_integral" property="sibukgExchangeIntegral" />
        <result column="onther1_exchange_integral" property="onther1ExchangeIntegral" />
        <result column="onther2_exchange_integral" property="onther2ExchangeIntegral" />
        <result column="onther3_exchange_integral" property="onther3ExchangeIntegral" />
        <result column="thumb_img" property="thumbImg" />
        <result column="bannel_img1" property="bannelImg1" />
        <result column="bannel_img2" property="bannelImg2" />
        <result column="bannel_img3" property="bannelImg3" />
        <result column="bannel_img4" property="bannelImg4" />
        <result column="bannel_img5" property="bannelImg5" />
        <result column="limit_exchange_number" property="limitExchangeNumber"/>
        <result column="is_new" property="isNew" />
        <result column="is_hot" property="isHot" />
        <result column="is_reco" property="isReco" />
        <result column="cost" property="cost" />
        <result column="attention" property="attention" />
        <result column="total_comment_score" property="totalCommentScore" />
        <result column="total_comment_number" property="totalCommentNumber" />
        <result column="create_date" property="createDate"/>
        <result column="product_type" property="productType"/>
        <result column="member_price" property="memberPrice"/>
        <result column="retail_price" property="retailPrice"/>
        <result column="market_price" property="marketPrice"/>
        <result column="delete_flag" property="deleteFlag"/>
        <result column="is_show" property="isShow"/>
        <result column="sort_index" property="sortIndex"/>
        <result column="is_open_spec" property="isOpenSpec"/>
        <result column="spec" property="spec"/>
        <result column="mini_purchase_number" property="miniPurchaseNumber"/>
        <result column="erp_code" property="erpCode"/>
        <result column="format_str" property="formatStr"/>
        <result column="bar_code" property="barCode"/>
        <result column="is_copy" property="isCopy"/>
        <result column="product_campagin" property="productCampagin"/>
        <result column="is_group" property="isGroup"/>
        <result column="campaign_sort_index" property="campaignSortIndex"/>
        <result column="id" property="campaignProductId"/>
        <result column="supplierId" property="supplierId"/>
        <result column="supplierName" property="supplierName"/>
    </resultMap>

    <update id="update" parameterType="IMCampaignCategoryBean">
        UPDATE im_campaign_category SET
            name=#{name},
            image_url=#{imageUrl},
            sort_index=#{sortIndex},
            is_show=#{isShow},
            campagin_type=#{campaginType}
        WHERE im_campaign_category_id=#{imCampaignCategoryId}
    </update>

    <update id="delete" parameterType="String" >
        UPDATE im_campaign_category SET delete_flag=0
        WHERE im_campaign_category_id=#{campaignCategoryId}
    </update>

    <resultMap type="IMCampaignCategoryBean" id="IMCampaignCategoryMap">
    	<id column="im_campaign_category_id" property="imCampaignCategoryId"/>
        <result column="name" property="name" />
        <result column="image_url" property="imageUrl" />
        <result column="sort_index" property="sortIndex" />
        <result column="create_dt" property="createDt" />
        <result column="delete_flag" property="deleteFlag" />
        <result column="is_show" property="isShow" />
        <result column="campagin_type" property="campaginType" />
        <result column="create_dt" property="createDt" />
    </resultMap>

    <select id="totalCampaingnProductByProductId" parameterType="java.lang.String" resultType="java.lang.Integer">
       SELECT  count(cp.id)  FROM  campaign_product cp
       left join im_campaign_category cc on cp.campaign_id=cc.im_campaign_category_id
        WHERE  cp.product_id=#{productId} and cc.delete_flag=1
    </select>

    <update id="updateCampaignProduct" parameterType="map">
        update campaign_product set campaign_sort_index=#{campaignSortIndex}
        where id=#{campaignProductId} limit 1
    </update>

    <select id="listByValid" parameterType="map"  resultMap="IMCampaignCategoryMap">
        SELECT cam.* FROM im_campaign_category cam
        where cam.delete_flag = 1 and is_show = 1
        order by cam.sort_index
        LIMIT ${pageNow}, ${pageSize}
    </select>

    <select id="totalCountCampaginByValid" resultType="int" parameterType="map">
        SELECT  count(*) FROM im_campaign_category cam
        where cam.delete_flag = 1 and is_show = 1
    </select>

</mapper>