<?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.McsGameDAO">
|
|
<resultMap type="com.panzhihua.service_community.entity.McsGame" id="McsGameMap">
|
<result property="id" column="id" jdbcType="INTEGER"/>
|
<result property="name" column="name" jdbcType="VARCHAR"/>
|
<result property="coupons" column="coupons" jdbcType="INTEGER"/>
|
<result property="surplusCoupons" column="surplus_coupons" jdbcType="INTEGER"/>
|
<result property="type" column="type" jdbcType="INTEGER"/>
|
<result property="awardType" column="award_type" jdbcType="INTEGER"/>
|
<result property="allocation" column="allocation" jdbcType="INTEGER"/>
|
<result property="coins" column="coins" jdbcType="INTEGER"/>
|
<result property="surplusCoins" column="surplus_coins" jdbcType="INTEGER"/>
|
<result property="address" column="address" jdbcType="VARCHAR"/>
|
<result property="lat" column="lat" jdbcType="VARCHAR"/>
|
<result property="lon" column="lon" jdbcType="VARCHAR"/>
|
<result property="expireAt" column="expire_at" jdbcType="TIMESTAMP"/>
|
<result property="cover" column="cover" jdbcType="VARCHAR"/>
|
<result property="otherImages" column="other_images" jdbcType="VARCHAR"/>
|
<result property="introduction" column="introduction" jdbcType="VARCHAR"/>
|
<result property="status" column="status" jdbcType="INTEGER"/>
|
<result property="isPopular" column="is_popular" jdbcType="VARCHAR"/>
|
<result property="publishAt" column="publish_at" jdbcType="TIMESTAMP"/>
|
<result property="isDel" column="is_del" jdbcType="VARCHAR"/>
|
<result property="merchantId" column="merchant_id" jdbcType="INTEGER"/>
|
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
<result property="createdBy" column="created_by" jdbcType="INTEGER"/>
|
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
|
<result property="updatedBy" column="updated_by" jdbcType="INTEGER"/>
|
</resultMap>
|
|
<!-- 批量插入 -->
|
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
|
insert into smart_life.mcs_game(name, coupons, surplus_coupons, type, award_type, allocation, coins, address,
|
lat, lon, expire_at, cover, other_images, introduction, status, publish_at, is_del, merchant_id, created_at,
|
created_by, updated_at, updated_by)
|
values
|
<foreach collection="entities" item="entity" separator=",">
|
(#{entity.name}, #{entity.coupons}, #{entity.surplusCoupons}, #{entity.type}, #{entity.awardType},
|
#{entity.allocation}, #{entity.coins}, #{entity.address}, #{entity.lat}, #{entity.lon}, #{entity.expireAt},
|
#{entity.cover}, #{entity.otherImages}, #{entity.introduction}, #{entity.status}, #{entity.publishAt},
|
#{entity.isDel}, #{entity.merchantId}, #{entity.createdAt}, #{entity.createdBy}, #{entity.updatedAt},
|
#{entity.updatedBy})
|
</foreach>
|
</insert>
|
<!-- 批量插入或按主键更新 -->
|
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
|
insert into smart_life.mcs_game(name, coupons, surplus_coupons, type, award_type, allocation, coins, address,
|
lat, lon, expire_at, cover, other_images, introduction, status, publish_at, is_del, merchant_id, created_at,
|
created_by, updated_at, updated_by)
|
values
|
<foreach collection="entities" item="entity" separator=",">
|
(#{entity.name}, #{entity.coupons}, #{entity.surplusCoupons}, #{entity.type}, #{entity.awardType},
|
#{entity.allocation}, #{entity.coins}, #{entity.address}, #{entity.lat}, #{entity.lon}, #{entity.expireAt},
|
#{entity.cover}, #{entity.otherImages}, #{entity.introduction}, #{entity.status}, #{entity.publishAt},
|
#{entity.isDel}, #{entity.merchantId}, #{entity.createdAt}, #{entity.createdBy}, #{entity.updatedAt},
|
#{entity.updatedBy})
|
</foreach>
|
on duplicate key update
|
name = values(name) , coupons = values(coupons) , surplus_coupons = values(surplus_coupons) , type =
|
values(type) , award_type = values(award_type) , allocation = values(allocation) , coins = values(coins) ,
|
address = values(address) , lat = values(lat) , lon = values(lon) , expire_at = values(expire_at) , cover =
|
values(cover) , other_images = values(other_images) , introduction = values(introduction) , status =
|
values(status) , publish_at = values(publish_at) , is_del = values(is_del) , merchant_id = values(merchant_id) ,
|
created_at = values(created_at) , created_by = values(created_by) , updated_at = values(updated_at) , updated_by
|
= values(updated_by)
|
</insert>
|
<update id="setOffByMerchantIds">
|
UPDATE mcs_game SET `status` = 3 WHERE merchant_id IN
|
<foreach collection="needDealIds" index="index" item="item" open="(" separator="," close=")">
|
#{item}
|
</foreach>
|
</update>
|
<select id="pageMcsGame"
|
resultType="com.panzhihua.common.model.vos.community.microCommercialStreet.McsGameVO">
|
(SELECT t1.id, t1.`name`, t1.`type`, t1.coupons, t1.surplus_coupons, t1.award_type,
|
t1.publish_at, t1.expire_at, t1.`status`, t1.merchant_id, t2.`name` AS merchantName, t1.is_popular, t1.cover
|
FROM mcs_game t1
|
LEFT JOIN mcs_merchant t2 ON t1.merchant_id = t2.id
|
WHERE t1.is_del = 0 AND t1.`status` = 2
|
<if test="pageMcsGameDTO.userId != null">
|
AND t2.user_id = #{pageMcsGameDTO.userId}
|
</if>
|
<if test="pageMcsGameDTO.type != null">
|
AND t1.`type` = #{pageMcsGameDTO.type}
|
</if>
|
<if test="pageMcsGameDTO.status != null">
|
AND t1.`status` = #{pageMcsGameDTO.status}
|
</if>
|
<if test="pageMcsGameDTO.keyword != null and pageMcsGameDTO.keyword != """>
|
AND t1.`name` LIKE CONCAT(#{pageMcsGameDTO.keyword}, '%')
|
</if>
|
ORDER BY t1.created_at DESC LIMIT 99999)
|
UNION ALL
|
(SELECT t1.id, t1.`name`, t1.`type`, t1.coupons, t1.surplus_coupons, t1.award_type,
|
t1.publish_at, t1.expire_at, t1.`status`, t1.merchant_id, t2.`name` AS merchantName, t1.is_popular, t1.cover
|
FROM mcs_game t1
|
LEFT JOIN mcs_merchant t2 ON t1.merchant_id = t2.id
|
WHERE t1.is_del = 0 AND t1.`status` != 2
|
<if test="pageMcsGameDTO.userId != null">
|
AND t2.user_id = #{pageMcsGameDTO.userId}
|
</if>
|
<if test="pageMcsGameDTO.type != null">
|
AND t1.`type` = #{pageMcsGameDTO.type}
|
</if>
|
<if test="pageMcsGameDTO.status != null">
|
AND t1.`status` = #{pageMcsGameDTO.status}
|
</if>
|
<if test="pageMcsGameDTO.keyword != null and pageMcsGameDTO.keyword != """>
|
AND t1.`name` LIKE CONCAT(#{pageMcsGameDTO.keyword}, '%')
|
</if>
|
ORDER BY t1.created_at DESC LIMIT 99999)
|
</select>
|
<select id="selectPublishCount" resultType="java.lang.Integer">
|
SELECT SUM(publishCount) AS publishCount FROM
|
(
|
SELECT COUNT(1) AS publishCount FROM mcs_game WHERE merchant_id = #{merchantId} AND `status` = 2 AND is_del = 0
|
UNION ALL
|
SELECT COUNT(1) AS publishCount FROM mcs_information WHERE merchant_id = #{merchantId} AND `status` = 2 AND is_del = 0
|
) temp
|
</select>
|
<select id="selectAppliedCount" resultType="java.lang.Integer">
|
SELECT COUNT(1)
|
FROM mcs_coupon t1
|
LEFT JOIN mcs_game t2 ON t1.game_id = t2.id
|
WHERE t2.merchant_id = #{merchantId} AND t2.`type` = #{type}
|
</select>
|
<select id="selectVerifiedCount" resultType="java.lang.Integer">
|
SELECT COUNT(1)
|
FROM mcs_coupon t1
|
LEFT JOIN mcs_game t2 ON t1.game_id = t2.id
|
WHERE t1.is_verified = 1 AND t2.merchant_id = #{merchantId} AND t2.`type` = #{type}
|
</select>
|
<select id="selectPopularGame"
|
resultType="com.panzhihua.common.model.vos.community.microCommercialStreet.McsGameVO">
|
SELECT t1.id, t1.`name`, t1.coupons, t1.surplus_coupons, t1.`type`, t1.award_type FROM mcs_game t1
|
LEFT JOIN mcs_merchant t2 ON t1.merchant_id = t2.id
|
LEFT JOIN sys_user t3 ON t2.user_id = t3.user_id
|
WHERE t1.is_del = 0 AND t1.`status` = 2 AND t1.is_popular = 1 AND t2.is_del = 0 AND t3.`status` = 1 LIMIT 1
|
</select>
|
<select id="pageH5McsGame"
|
resultType="com.panzhihua.common.model.vos.community.microCommercialStreet.McsGameVO">
|
SELECT * FROM (
|
SELECT t1.id, t1.`name`, t1.`type`, t1.coupons, t1.surplus_coupons, t1.award_type, t1.cover,
|
IF(t1.allocation = 1,t1.coins,t1.coins * t1.coupons) AS coins, t1.allocation, t1.surplus_coins,
|
t1.publish_at, t1.`status`, t1.merchant_id, t1.lat, t1.lon, t2.`name` AS merchantName,
|
ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN((t1.lat * PI() / 180 - #{pageMcsGameDTO.lat} * PI() / 180) / 2),2)
|
+
|
COS(t1.lat * PI() / 180) * COS(#{pageMcsGameDTO.lat} * PI() / 180) * POW(SIN((t1.lon * PI() / 180 -
|
#{pageMcsGameDTO.lon} * PI() / 180) / 2),2))), 2) AS distance
|
FROM mcs_game t1
|
LEFT JOIN mcs_merchant t2 ON t1.merchant_id = t2.id
|
LEFT JOIN sys_user t3 ON t2.user_id = t3.user_id
|
WHERE t1.is_del = 0 AND t1.`status` = 2 AND t1.expire_at > NOW() AND t3.`status` = 1
|
<if test="pageMcsGameDTO.keyword != null and pageMcsGameDTO.keyword != """>
|
AND t1.`name` LIKE CONCAT(#{pageMcsGameDTO.keyword}, '%')
|
</if>
|
<if test="pageMcsGameDTO.type != null">
|
AND t1.`type` = #{pageMcsGameDTO.type}
|
</if>
|
<if test="pageMcsGameDTO.merchantId != null">
|
AND t1.merchant_id = #{pageMcsGameDTO.merchantId}
|
</if>
|
ORDER BY t1.created_at DESC
|
) temp WHERE 1=1
|
<if test="pageMcsGameDTO.distance != null">
|
AND distance <= #{pageMcsGameDTO.distance}
|
</if>
|
</select>
|
<select id="selectDetailById"
|
resultType="com.panzhihua.common.model.vos.community.microCommercialStreet.McsGameVO">
|
SELECT t1.*, t2.`name` AS merchantName, t2.logo
|
FROM mcs_game t1
|
LEFT JOIN mcs_merchant t2 ON t1.merchant_id = t2.id
|
WHERE t1.id = #{gameId}
|
</select>
|
<select id="selectNeedDealExpire" resultType="com.panzhihua.service_community.entity.McsGame">
|
SELECT * FROM mcs_game WHERE expire_at <= NOW() AND `status` != 4
|
</select>
|
|
</mapper>
|