|
- <?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.iformall.mapper.WxCreditHistoryMapper">
- <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCreditHistory">
- <id column="id" jdbcType="BIGINT" property="id" />
- <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
- <result column="c_user_id" jdbcType="BIGINT" property="cUserId" />
- <result column="credit_amount" jdbcType="INTEGER" property="creditAmount" />
- <result column="credit_num" jdbcType="INTEGER" property="creditNum" />
- <result column="credit_type" jdbcType="INTEGER" property="creditType" />
- <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
- <result column="receipt_url" jdbcType="VARCHAR" property="receiptUrl" />
- <result column="operator_type" jdbcType="INTEGER" property="operatorType" />
- <result column="operator_id" jdbcType="BIGINT" property="operatorId" />
- <result column="merchant_id" jdbcType="BIGINT" property="merchantId" />
- <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
- <result column="business_id" jdbcType="BIGINT" property="businessId" />
- <result column="spend" jdbcType="INTEGER" property="spend" />
- <result column="change_purpose" jdbcType="VARCHAR" property="changePurpose" />
- <result column="ticket_number" jdbcType="VARCHAR" property="ticketNumber"/>
- <result column="buser_id" jdbcType="BIGINT" property="buserId"/>
- </resultMap>
-
- <sql id="allColumns">
- `id`,`tenant_id`,`c_user_id`,`credit_amount`,`credit_num`,`credit_type`,`create_date`,`receipt_url`,`operator_type`,`operator_id`,`merchant_id`,`coupon_id`,`business_id`,`spend`,`change_purpose`,`ticket_number`,`buser_id`
- </sql>
-
- <sql id="dynamicWhereConditions">
- <if test=" null != startTime ">
- and credit.create_date >= #{startTime}
- </if>
- <if test=" null != endTime">
- and credit.create_date < #{endTime}
- </if>
- <if test=" null != operatorType ">
- and credit.operator_type = #{operatorType}
- </if>
- <if test=" null != operatorId ">
- and credit.operator_id = #{operatorId}
- </if>
- <if test=" null != creditType ">
- and credit.credit_type = #{creditType}
- </if>
- <if test=" null != cUserId ">
- and credit.c_user_id = #{cUserId}
- </if>
- <if test=" null != merchantId ">
- and credit.merchant_id = #{merchantId}
- </if>
- <if test=" null != ticketNumber and ''!=ticketNumber ">
- and credit.ticket_number like concat('%', #{ticketNumber},'%')
- </if>
- <if test=" null != buserId ">
- and credit.buser_id = #{buserId}
- </if>
-
- <if test=" null != merchantIds ">
- and credit.merchant_id in
- <foreach collection="merchantIds" index="index" item="merchantIdItem" open="(" separator="," close=")">
- #{merchantIdItem}
- </foreach>
- </if>
-
- <if test=" null != cUserIds ">
- and credit.c_user_id in
- <foreach collection="cUserIds" index="index" item="cUserIdItem" open="(" separator="," close=")">
- #{cUserIdItem}
- </foreach>
- </if>
- </sql>
-
- <select id="selectById" parameterType="java.util.HashMap" resultMap="BaseResultMap">
- select <include refid="allColumns" /> from wx_credit_history where id =#{id} and tenant_id = #{tenantId}
- </select>
-
- <select id="findList" parameterType="com.iformall.domain.po.WxCreditHistory" resultMap="BaseResultMap">
- select <include refid="allColumns" />
- from wx_credit_history credit
- where `tenant_id` = #{tenantId}
- <include refid="dynamicWhereConditions" />
- ORDER BY credit.create_date DESC
- </select>
-
- <select id="findListMore" parameterType="com.iformall.domain.po.WxCreditHistory" resultMap="BaseResultMap">
- SELECT
- credit.id ,credit.tenant_id ,credit.c_user_id ,credit.credit_amount ,credit.credit_num,credit.create_date,credit.credit_type,credit.receipt_url ,
- credit.operator_type,credit.operator_id,credit.merchant_id,credit.ticket_number,credit.change_purpose
- FROM wx_credit_history credit
- where credit.`tenant_id` = #{tenantId}
- <include refid="dynamicWhereConditions" />
- ORDER BY credit.create_date DESC
- <if test=" null != begin ">
- limit #{begin}, #{limit}
- </if>
- </select>
-
- <select id="loginCount" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer">
- select COUNT(0) from wx_credit_history
- where 1=1
- <if test=" null != cUserId ">
- and `c_user_id` = #{cUserId}
- </if>
- <if test=" null != creditType ">
- and `credit_type` = #{creditType}
- </if>
- and DATEDIFF(`create_date`,now())=0
- </select>
-
- <select id="monthCount" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer">
- select COUNT(0) from wx_credit_history
- where 1=1
- <if test=" null != cUserId ">
- and `c_user_id` = #{cUserId}
- </if>
- <if test=" null != creditType ">
- and `credit_type` = #{creditType}
- </if>
- and DATE_FORMAT(`create_date`,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m');
- </select>
-
- <select id="countTodayList" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer">
- select count(0)
- from wx_credit_history
- where 1=1
- <if test=" null != tenantId and '' != tenantId">
- and `tenant_id` = #{tenantId}
- </if>
- <if test=" null != cUserId ">
- and `c_user_id` = #{cUserId}
- </if>
- <if test=" null != creditType ">
- and `credit_type` = #{creditType}
- </if>
- and DATEDIFF(`create_date`,now())=0
- </select>
-
- <select id="creditAmount" parameterType="java.lang.Long" resultType="java.lang.Integer">
- SELECT credit_amount FROM wx_credit_history where c_user_id = #{cUserId} ORDER BY create_date desc limit 1
- </select>
-
- <select id="countList" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer">
- select count(0)
- from wx_credit_history
- where 1=1
- <if test=" null != tenantId and '' != tenantId">
- and `tenant_id` = #{tenantId}
- </if>
- <if test=" null != cUserId ">
- and `c_user_id` = #{cUserId}
- </if>
- <if test=" null != creditType ">
- and `credit_type` = #{creditType}
- </if>
- </select>
-
- <select id="getIncrementCreditAmount" parameterType="com.iformall.domain.po.WxCreditHistory"
- resultType="java.lang.Long">
- select ifnull(sum(credit.credit_num),0) amount
- from wx_credit_history credit
- where credit.`tenant_id` = #{tenantId}
- <include refid="dynamicWhereConditions"/>
- and credit.credit_num>0
- </select>
-
- <select id="getDecrementCreditAmount" parameterType="com.iformall.domain.po.WxCreditHistory"
- resultType="java.lang.Long">
- select ABS(ifnull(sum(credit.credit_num),0)) amount
- from wx_credit_history credit
- where credit.`tenant_id` = #{tenantId}
- <include refid="dynamicWhereConditions"/>
- and credit.credit_num < 0
- </select>
-
- <select id="getAddCreditSummary" parameterType="com.iformall.domain.po.WxCreditHistory"
- resultType="java.lang.Integer">
- select ifnull(sum(credit.credit_num),0) amount
- from wx_credit_history credit
- where credit.`tenant_id` = #{tenantId}
- and credit.credit_num > 0 and credit.c_user_id = #{cUserId}
- <if test=" null != startTime ">
- and credit.create_date >= #{startTime}
- </if>
- <if test=" null != endTime">
- and credit.create_date < #{endTime}
- </if>
-
- </select>
-
- <select id="getLesCreditSummary" parameterType="com.iformall.domain.po.WxCreditHistory"
- resultType="java.lang.Integer">
- select ifnull(sum(credit.credit_num),0) amount
- from wx_credit_history credit
- where credit.`tenant_id` = #{tenantId}
- and credit.credit_num < 0
- and credit.c_user_id = #{cUserId}
- <if test=" null != startTime ">
- and credit.create_date >= #{startTime}
- </if>
- <if test=" null != endTime">
- and credit.create_date < #{endTime}
- </if>
- </select>
-
- <select id="getPeopleCount" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Long">
- select count(distinct credit.c_user_id) people
- from wx_credit_history credit
- where credit.`tenant_id` = #{tenantId}
- <include refid="dynamicWhereConditions"/>
- </select>
-
- <delete id="deleteById" parameterType="java.util.HashMap">
- delete from wx_credit_history where id = #{id} and tenant_id = #{tenantId}
- </delete>
-
- <update id="userCreditClear" statementType="CALLABLE" >
- {call user_credit_clear(#{cutOffDate},#{finalTableIndex})}
- </update>
-
- <select id="getIsMemberCarAndClearCredit" parameterType="com.iformall.domain.po.WxCreditHistory" resultMap="BaseResultMap">
- select <include refid="allColumns" />
- from wx_credit_history
- where `tenant_id` = #{tenantId}
- and `credit_type` = #{creditType}
- and create_date >= #{startTime}
- and `c_user_id` in
- (select user_id from wx_member_card where `final_tenant_id` = #{finalTenantId} )
- </select>
-
- <select id="merchantCreditAdd" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="com.iformall.domain.vo.MerchantCreditRankingVo">
- select credit.merchant_id merchantId,sum(credit.credit_num) sumAddCredit
- from wx_credit_history credit
- where credit.merchant_id is not null and credit.merchant_id != -1
- and credit.credit_num > 0
- and `tenant_id` = #{tenantId}
- <if test=" null != startTime ">
- and credit.create_date >= #{startTime}
- </if>
- <if test=" null != endTime">
- and credit.create_date < #{endTime}
- </if>
- GROUP BY credit.merchant_id
- ORDER BY sumAddCredit desc
- </select>
-
- <select id="merchantCreditLes" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="com.iformall.domain.vo.MerchantCreditRankingVo">
- select credit.merchant_id merchantId,sum(credit.credit_num) sumLesCredit
- from wx_credit_history credit
- where credit.credit_num < 0
- and `tenant_id` = #{tenantId}
- <if test=" null != merchantIds ">
- and credit.merchant_id in
- <foreach collection="merchantIds" index="index" item="merchantIdItem" open="(" separator="," close=")">
- #{merchantIdItem}
- </foreach>
- </if>
- <if test=" null != startTime ">
- and credit.create_date >= #{startTime}
- </if>
- <if test=" null != endTime">
- and credit.create_date < #{endTime}
- </if>
- GROUP BY credit.merchant_id
- </select>
-
- <select id="merchantCreditAddUserCount" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="com.iformall.domain.vo.MerchantCreditRankingVo">
- select credit.merchant_id merchantId,count(distinct credit.c_user_id) countAddCreditUser
- from wx_credit_history credit
- where credit.credit_num > 0
- and `tenant_id` = #{tenantId}
- <if test=" null != merchantIds ">
- and credit.merchant_id in
- <foreach collection="merchantIds" index="index" item="merchantIdItem" open="(" separator="," close=")">
- #{merchantIdItem}
- </foreach>
- </if>
- <if test=" null != startTime ">
- and credit.create_date >= #{startTime}
- </if>
- <if test=" null != endTime">
- and credit.create_date < #{endTime}
- </if>
- GROUP BY credit.merchant_id
- </select>
-
- <select id="merchantCreditLesUserCount" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="com.iformall.domain.vo.MerchantCreditRankingVo">
- select credit.merchant_id merchantId,count(distinct credit.c_user_id) countLesCreditUser
- from wx_credit_history credit
- where credit.credit_num < 0
- and `tenant_id` = #{tenantId}
- <if test=" null != merchantIds ">
- and credit.merchant_id in
- <foreach collection="merchantIds" index="index" item="merchantIdItem" open="(" separator="," close=")">
- #{merchantIdItem}
- </foreach>
- </if>
- <if test=" null != startTime ">
- and credit.create_date >= #{startTime}
- </if>
- <if test=" null != endTime">
- and credit.create_date < #{endTime}
- </if>
- GROUP BY credit.merchant_id
- </select>
-
-
- <select id="findAddList" parameterType="com.iformall.domain.po.WxCreditHistory"
- resultType="com.iformall.domain.po.WxCreditHistory">
- select credit.c_user_id cUserId,ifnull(sum(credit.credit_num),0) creditNum
- from wx_credit_history credit
- where credit.`tenant_id` = #{tenantId}
- and credit.credit_num > 0
-
- <if test=" null != userIdList ">
- and credit.`c_user_id` in
- <foreach collection="userIdList" index="index" item="uItem" open="(" separator="," close=")">
- #{uItem}
- </foreach>
- </if>
- <if test=" null != startTime ">
- and credit.create_date >= #{startTime}
- </if>
- <if test=" null != endTime">
- and credit.create_date < #{endTime}
- </if>
-
- GROUP BY credit.`c_user_id`
-
- </select>
-
- <select id="findLesList" parameterType="com.iformall.domain.po.WxCreditHistory"
- resultType="com.iformall.domain.po.WxCreditHistory">
- select credit.c_user_id cUserId,ifnull(sum(credit.credit_num),0) creditNum
- from wx_credit_history credit
- where credit.`tenant_id` = #{tenantId}
- and credit.credit_num < 0
-
- <if test=" null != userIdList ">
- and credit.`c_user_id` in
- <foreach collection="userIdList" index="index" item="uItem" open="(" separator="," close=")">
- #{uItem}
- </foreach>
- </if>
- <if test=" null != startTime ">
- and credit.create_date >= #{startTime}
- </if>
- <if test=" null != endTime">
- and credit.create_date < #{endTime}
- </if>
-
- GROUP BY credit.`c_user_id`
- </select>
-
- </mapper>
|