123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?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.caimei.modules.product.dao.RepeatPurchasePriceDao">
- <sql id="repeatPurchasePriceColumns">
- a.id AS "id",
- a.userId AS "userId",
- a.productId AS "productId",
- a.shopId AS "shopId",
- a.shopName AS "shopName",
- a.taxRate AS "taxRate",
- a.currentPrice AS "currentPrice",
- a.createTime AS "createTime"
- </sql>
- <sql id="repeatPurchasePriceJoins">
- left join product as b on a.productId = b.productID
- left join user as c on a.userId = c.userId
- </sql>
- <sql id="repeatPurchasePriceHistoryJoins">
- INNER JOIN repeat_purchase_price AS b ON a.`userId` = b.`userId` AND a.`productId` = b.`productId`
- </sql>
- <select id="get" resultType="RepeatPurchasePrice">
- SELECT
- <include refid="repeatPurchasePriceColumns"/>
- FROM repeat_purchase_price a
- <include refid="repeatPurchasePriceJoins"/>
- where a.id = #{id}
- AND a.delFlag = 0
- </select>
- <select id="getRepeatPurchasePrice" resultType="RepeatPurchasePrice">
- SELECT
- <include refid="repeatPurchasePriceColumns"/>,
- c.userName AS "userName",
- c.mobile As "mobile",
- c.registerUserTypeID As "type",
- b.name AS "productName"
- FROM repeat_purchase_price a
- <include refid="repeatPurchasePriceJoins"/>
- <where>
- <if test="repeatPurchasePriceId != null and repeatPurchasePriceId != ''" >
- AND a.id = #{repeatPurchasePriceId}
- </if>
- AND a.delFlag = 0
- and b.productCategory = 1
- </where>
- </select>
- <select id="findList" resultType="RepeatPurchasePrice">
- SELECT
- <include refid="repeatPurchasePriceColumns"/>,
- c.name AS "userName",
- c.mobile As "mobile",
- c.bindMobile AS "bindMobile",
- c.registerUserTypeID As "type",
- b.name AS "productName",
- CASE b.costCheckFlag
- WHEN 1 THEN b.`costPrice`
- WHEN 2 THEN b.`costProportional` * b.`price1` / 100
- END AS "costPrice"
- FROM repeat_purchase_price a
- <include refid="repeatPurchasePriceJoins"/>
- <where>
- <if test="productId != null and productId != ''" >
- AND a.productId = #{productId}
- </if>
- <if test="productName != null and productName != ''" >
- AND b.name LIKE
- <if test="dbName == 'oracle'">'%'||#{productName}||'%'</if>
- <if test="dbName == 'mssql'">'%'+#{productName}+'%'</if>
- <if test="dbName == 'mysql'">concat('%',#{productName},'%')</if>
- </if>
- <if test="userName != null and userName != ''" >
- AND c.name LIKE
- <if test="dbName == 'oracle'">'%'||#{userName}||'%'</if>
- <if test="dbName == 'mssql'">'%'+#{userName}+'%'</if>
- <if test="dbName == 'mysql'">concat('%',#{userName},'%')</if>
- </if>
- <if test="mobile != null and mobile != ''" >
- AND (c.mobile = #{mobile} or c.bindMobile = #{mobile})
- </if>
- <if test="shopName != null and shopName != ''" >
- AND a.shopName LIKE
- <if test="dbName == 'oracle'">'%'||#{shopName}||'%'</if>
- <if test="dbName == 'mssql'">'%'+#{shopName}+'%'</if>
- <if test="dbName == 'mysql'">concat('%',#{shopName},'%')</if>
- </if>
- AND a.delFlag = 0
- and b.productCategory = 1
- </where>
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy} desc
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </select>
- <select id="findHistoryPriceList" resultType="RepeatPurchasePriceHistory">
- SELECT
- a.*
- FROM repeat_purchase_price_history a
- <include refid="repeatPurchasePriceHistoryJoins"/>
- <where>
- <if test="repeatPurchasePriceId != null and repeatPurchasePriceId != ''" >
- AND b.id = #{repeatPurchasePriceId}
- </if>
- AND a.cmCartId is null
- AND a.delFlag = 0
- </where>
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy} desc
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </select>
- <select id="findPriceProductList" resultType="String">
- select GROUP_CONCAT(productId) From repeat_purchase_price WHERE userId = #{userId} and delFlag = 0;
- </select>
- <select id="findAllList" resultType="RepeatPurchasePrice">
- SELECT
- <include refid="repeatPurchasePriceColumns"/>
- FROM repeat_purchase_price a
- <include refid="repeatPurchasePriceJoins"/>
- <where>
- a.delFlag = 0
- and b.productCategory = 1
- </where>
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </select>
- <insert id="insert" parameterType="RepeatPurchasePrice" keyProperty="id" useGeneratedKeys="true">
- INSERT INTO repeat_purchase_price(
- id,
- userId,
- productId,
- shopId,
- shopName,
- taxRate,
- currentPrice,
- createTime,
- orderId,
- clubId
- ) VALUES (
- #{id},
- #{userId},
- #{productId},
- #{shopId},
- #{shopName},
- #{taxRate},
- #{currentPrice},
- #{createTime},
- #{orderId},
- #{clubId}
- )
- </insert>
- <update id="update">
- UPDATE repeat_purchase_price SET
- userId = #{userId},
- productId = #{productId},
- shopId = #{shopId},
- shopName = #{shopName},
- taxRate = #{taxRate},
- currentPrice = #{currentPrice},
- createTime = #{createTime}
- WHERE id = #{id}
- </update>
- <update id="delete">
- UPDATE repeat_purchase_price SET
- delFlag = #{delFlag}
- WHERE id = #{id}
- </update>
- <select id="getLastBuyPrice" resultType="RepeatPurchasePrice">
- select <include refid="repeatPurchasePriceColumns"/>
- from repeat_purchase_price a
- <where>
- <if test="userId != null and userId != ''">
- and a.userId = #{userId}
- </if>
- <if test="clubId != null and clubId != ''">
- and a.clubId = #{clubId}
- </if>
- <if test="productId != null and productId != ''">
- and a.productId = #{productId}
- </if>
- AND a.delFlag = 0
- </where>
- limit 0, 1
- </select>
- </mapper>
|