|
- <?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">
- where 1 = 1
- <if test=" null != id ">
- and `id` = #{id}
- </if>
- <if test=" null != tenantId and '' != tenantId">
- and `tenant_id` = #{tenantId}
- </if>
- <if test=" null != cUserId ">
- and `c_user_id` = #{cUserId}
- </if>
- <if test=" null != creditAmount ">
- and `credit_amount` = #{creditAmount}
- </if>
- <if test=" null != creditNum ">
- and `credit_num` = #{creditNum}
- </if>
- <if test=" null != creditType ">
- and `credit_type` = #{creditType}
- </if>
- <if test=" null != receiptUrl ">
- and `receipt_url` like concat('%', #{receiptUrl},'%')
- </if>
- <if test=" null != operatorType ">
- and `operator_type` = #{operatorType}
- </if>
- <if test=" null != operatorId ">
- and `operator_id` = #{operatorId}
- </if>
- <if test=" null != merchantId ">
- and `merchant_id` = #{merchantId}
- </if>
- <if test=" null != couponId ">
- and `coupon_id` = #{couponId}
- </if>
- <if test=" null != businessId ">
- and `business_id` = #{businessId}
- </if>
- <if test=" null != spend ">
- and `spend` = #{spend}
- </if>
- <if test=" null != changePurpose ">
- and `change_purpose` = #{changePurpose}
- </if>
- <if test=" null != ticketNumber and ''!=ticketNumber ">
- and ticket_number like concat('%', #{ticketNumber},'%')
- </if>
-
- <if test=" null != buserId ">
- and `buser_id` = #{buserId}
- </if>
-
- <if test=" null != ids ">
- and id in
- <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
- #{idItem}
- </foreach>
- </if>
- <if test=" null != sortColumns"> order by ${sortColumns} </if>
- </sql>
-
- <sql id="customWhereConditions">
- where 1 = 1
- <if test=" null != name and '' != name">
- and basic.nick_name like concat('%', #{name},'%')
- </if>
- <if test=" null != phone and '' != phone">
- and basic.phone like concat('%', #{phone},'%')
- </if>
- <if test=" null != startTime ">
- and credit.create_date >= #{startTime}
- </if>
- <if test=" null != endTime">
- and credit.create_date < #{endTime}
- </if>
- <if test=" null != tenantId and '' != tenantId">
- and credit.`tenant_id` = #{tenantId}
- </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 != merchantName and ''!=merchantName ">
- and merchant.name like concat('%', #{merchantName},'%')
- </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>
-
- </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
- <include refid="dynamicWhereConditions" />
- </select>
-
- <select id="findListMore" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="com.iformall.domain.vo.WxCreditHistoryVo">
- SELECT
- credit.id creditId,
- case when basic.nick_name is null then basic.name else basic.nick_name end name,
- basic.phone phone,
- basic.sex sex,
- credit.tenant_id tenantId,
- credit.c_user_id cUserId,
- credit.credit_amount creditAmount,
- credit.credit_num creditNum,
- credit.create_date createDate,
- credit.credit_type creditType,
- credit.receipt_url receiptUrl,
- credit.operator_type operatorType,
- credit.operator_id operatorId,
- merchant.NAME merchantName,
- credit.merchant_id merchantId,
- credit.ticket_number ticketNumber,
- case when credit.operator_type=4 then (select name from mall_user_info where id=credit.operator_id)
- when credit.operator_type=3 then (select name from wx_merchant_b_user where id=credit.operator_id)
- when credit.operator_type=2 then (select nick_name from wx_c_user_basic_info where id=credit.operator_id)
- else '' end operator,
- credit.change_purpose changePurpose
- FROM
- wx_c_user_basic_info basic
- INNER JOIN wx_credit_history credit ON basic.id = credit.c_user_id
- LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
- <include refid="customWhereConditions"/>
- ORDER BY
- credit.create_date desc,credit.id DESC
- </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="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 id 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="getTotalCreditAmount" parameterType="com.iformall.domain.po.WxCreditHistory"
- resultType="java.lang.Long">
- select ifnull(sum(credit.amount),0) amount from (
- select basic.credit as amount,credit.c_user_id from wx_credit_history credit
- INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
- LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
- <include refid="customWhereConditions"/>
- group by credit.c_user_id
- ) credit
- </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
- INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
- LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
- <include refid="customWhereConditions"/>
- 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
- INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
- LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
- <include refid="customWhereConditions"/>
- 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(1) people from (
- select count(*) people from wx_credit_history credit
- INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
- LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
- <include refid="customWhereConditions"/>
- group by credit.c_user_id
- ) credit
- </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="merchantCreditRanking" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="com.iformall.domain.vo.MerchantCreditRankingVo">
- select wm.id merchantId,wm.name merchantName,IFNULL(a.sum_credit_num,0) sumAddCredit,
- IFNULL(b.sum_credit_num,0) sumLesCredit,IFNULL(c.count_c_user_id,0) countAddCreditUser,
- IFNULL(d.count_c_user_id,0) countLesCreditUser
- from
- (
- select id,name from wx_merchant
- where is_del = 0
- <if test=" null != tenantId and '' != tenantId">
- and `tenant_id` = #{tenantId}
- </if>
- <if test=" null != parentTenantId and '' != parentTenantId">
- and `parent_tenant_id` = #{parentTenantId}
- </if>
- ) wm
- left join
- (
- select merchant_id,sum(credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix}
- where merchant_id is not null and merchant_id != -1 and credit_num > 0
- <if test=" null != startTime ">
- and create_date >= #{startTime}
- </if>
- <if test=" null != endTime">
- and create_date < #{endTime}
- </if>
- GROUP BY merchant_id
- ) a on a.merchant_id = wm.id
- left join
- (
- select merchant_id,sum(credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix}
- where merchant_id is not null and merchant_id != -1 and credit_num < 0
- <if test=" null != startTime ">
- and create_date >= #{startTime}
- </if>
- <if test=" null != endTime">
- and create_date < #{endTime}
- </if>
- GROUP BY merchant_id
- ) b on b.merchant_id = wm.id
- left join
- (
- select merchant_id,count(distinct c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix}
- where merchant_id is not null and merchant_id != -1 and credit_num > 0
- <if test=" null != startTime ">
- and create_date >= #{startTime}
- </if>
- <if test=" null != endTime">
- and create_date < #{endTime}
- </if>
- GROUP BY merchant_id
- ) c on c.merchant_id = wm.id
- left join
- (
- select merchant_id,count(distinct c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix}
- where merchant_id is not null and merchant_id != -1 and credit_num < 0
- <if test=" null != startTime ">
- and create_date >= #{startTime}
- </if>
- <if test=" null != endTime">
- and create_date < #{endTime}
- </if>
- GROUP BY merchant_id
- ) d on d.merchant_id = wm.id
-
- ORDER BY sumAddCredit desc
-
- </select>
-
- </mapper>
|