<?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.panzhihua.service_community.dao.McsCouponDAO">
|
|
<resultMap type="com.panzhihua.service_community.entity.McsCoupon" id="McsCouponMap">
|
<result property="id" column="id" jdbcType="INTEGER"/>
|
<result property="gameId" column="game_id" jdbcType="INTEGER"/>
|
<result property="userId" column="user_id" jdbcType="INTEGER"/>
|
<result property="qrCode" column="qr_code" jdbcType="VARCHAR"/>
|
<result property="coin" column="coin" jdbcType="INTEGER"/>
|
<result property="award" column="award" jdbcType="VARCHAR"/>
|
<result property="isVerified" column="is_verified" jdbcType="VARCHAR"/>
|
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
|
</resultMap>
|
|
<!-- 批量插入 -->
|
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
|
insert into smart_life.mcs_coupon(game_id, user_id, qr_code, is_verified, created_at, updated_at)
|
values
|
<foreach collection="entities" item="entity" separator=",">
|
(#{entity.gameId}, #{entity.userId}, #{entity.qrCode}, #{entity.isVerified}, #{entity.createdAt},
|
#{entity.updatedAt})
|
</foreach>
|
</insert>
|
<!-- 批量插入或按主键更新 -->
|
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
|
insert into smart_life.mcs_coupon(game_id, user_id, qr_code, is_verified, created_at, updated_at)
|
values
|
<foreach collection="entities" item="entity" separator=",">
|
(#{entity.gameId}, #{entity.userId}, #{entity.qrCode}, #{entity.isVerified}, #{entity.createdAt},
|
#{entity.updatedAt})
|
</foreach>
|
on duplicate key update
|
game_id = values(game_id) , user_id = values(user_id) , qr_code = values(qr_code) , is_verified =
|
values(is_verified) , created_at = values(created_at) , updated_at = values(updated_at)
|
</insert>
|
<select id="getMyCouponData"
|
resultType="com.panzhihua.common.model.vos.community.microCommercialStreet.MyCouponVO">
|
SELECT
|
(SELECT IF(SUM(coin) IS NULL,0,SUM(coin)) FROM mcs_coupon WHERE user_id = #{userId}) AS obtainedTotal,
|
(SELECT COUNT(t1.id) FROM mcs_coupon t1 LEFT JOIN mcs_game t2 ON t1.game_id = t2.id WHERE t1.user_id = #{userId} AND t1.is_verified = 1 AND t2.type = 2) AS trialTotal,
|
(SELECT COUNT(t1.id) FROM mcs_coupon t1 LEFT JOIN mcs_game t2 ON t1.game_id = t2.id WHERE t1.user_id = #{userId} AND t1.is_verified = 1 AND t2.type = 1) AS joinGameTotal,
|
(SELECT COUNT(id) FROM mcs_coupon WHERE user_id = #{userId} AND is_verified = 0) AS unVerifiedTotal
|
</select>
|
<select id="getCouponList"
|
resultType="com.panzhihua.common.model.vos.community.microCommercialStreet.McsCouponVO">
|
SELECT t1.*, t2.type, t2.award_type, t2.`name`, t2.expire_at
|
FROM mcs_coupon t1
|
LEFT JOIN mcs_game t2 ON t1.game_id = t2.id
|
WHERE t1.user_id = #{userId}
|
<if test="type != null">
|
AND t2.type = #{type}
|
</if>
|
ORDER BY t1.created_at DESC
|
</select>
|
<select id="pageJoinGameList"
|
resultType="com.panzhihua.common.model.vos.community.microCommercialStreet.McsCouponVO">
|
SELECT t1.*, t2.type, t2.`name`, t2.expire_at, t2.cover, t2.id AS gameId, t2.award_type, t2.allocation,
|
IF(t3.id IS NULL,2,1) AS isEvaluate, t3.id AS evaluateId
|
FROM mcs_coupon t1
|
LEFT JOIN mcs_game t2 ON t1.game_id = t2.id
|
LEFT JOIN mcs_evaluate t3 ON t1.id = t3.coupon_id
|
WHERE t1.user_id = #{pageJoinGameListDTO.userId} AND t1.is_verified = 1
|
<if test="pageJoinGameListDTO.keyword != null and pageJoinGameListDTO.keyword != """>
|
AND t2.`name` LIKE CONCAT(#{pageJoinGameListDTO.keyword}, '%')
|
</if>
|
ORDER BY t1.created_at DESC
|
</select>
|
<select id="getMcsGameStatistics"
|
resultType="com.panzhihua.common.model.vos.community.microCommercialStreet.GameStatisticsVO">
|
SELECT gameTotal, sendCouponTotal,
|
IF(ROUND((sendCouponTotal - unAppliedTotal)/sendCouponTotal * 100,2) IS NULL,0,ROUND((sendCouponTotal - unAppliedTotal)/sendCouponTotal * 100,2))AS appliedPercent,
|
IF(ROUND(unAppliedTotal/sendCouponTotal * 100,2) IS NULL,0,ROUND(unAppliedTotal/sendCouponTotal * 100,2)) AS unAppliedPercent,
|
IF(ROUND(verifiedTotal/(sendCouponTotal - unAppliedTotal) * 100,2) IS NULL,0,ROUND(verifiedTotal/(sendCouponTotal - unAppliedTotal) * 100,2)) AS verifiedPercent,
|
IF(ROUND((sendCouponTotal - unAppliedTotal - verifiedTotal)/(sendCouponTotal - unAppliedTotal) * 100,2) IS NULL,0,ROUND((sendCouponTotal - unAppliedTotal - verifiedTotal)/(sendCouponTotal - unAppliedTotal) * 100,2)) AS unVerifiedPercent
|
FROM(
|
SELECT
|
(SELECT COUNT(t1.id) FROM mcs_game t1 LEFT JOIN mcs_merchant t2 ON t1.merchant_id = t2.id WHERE t1.`status` != 1 AND t1.is_del = 0 AND t1.`type` = 1 AND t2.user_id = #{userId}) AS gameTotal,
|
(SELECT IF(SUM(coupons) IS NULL,0,SUM(coupons)) FROM mcs_game t1 LEFT JOIN mcs_merchant t2 ON t1.merchant_id = t2.id WHERE t1.`status` != 1 AND t1.is_del = 0 AND t1.`type` = 1 AND t2.user_id = #{userId}) AS sendCouponTotal,
|
(SELECT IF(SUM(surplus_coupons) IS NULL,0,SUM(surplus_coupons)) FROM mcs_game t1 LEFT JOIN mcs_merchant t2 ON t1.merchant_id = t2.id WHERE t1.`status` != 1 AND t1.is_del = 0 AND t1.`type` = 1 AND t2.user_id = #{userId}) AS unAppliedTotal,
|
(SELECT COUNT(t1.id) FROM mcs_verified_record t1 LEFT JOIN mcs_merchant t2 ON t1.merchant_id = t2.id LEFT JOIN mcs_game t3 ON t1.game_id = t3.id WHERE t3.is_del = 0 AND t3.`type` = 1 AND t2.user_id = #{userId}) AS verifiedTotal
|
) temp
|
</select>
|
|
</mapper>
|