<?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.McsMerchantDAO">
|
|
<resultMap type="com.panzhihua.service_community.entity.McsMerchant" id="McsMerchantMap">
|
<result property="id" column="id" jdbcType="INTEGER"/>
|
<result property="name" column="name" jdbcType="VARCHAR"/>
|
<result property="phone" column="phone" jdbcType="VARCHAR"/>
|
<result property="account" column="account" jdbcType="VARCHAR"/>
|
<result property="logo" column="logo" jdbcType="VARCHAR"/>
|
<result property="userId" column="user_id" jdbcType="INTEGER"/>
|
<result property="level" column="level" jdbcType="INTEGER"/>
|
<result property="publishLimit" column="publish_limit" jdbcType="INTEGER"/>
|
<result property="expireAt" column="expire_at" jdbcType="TIMESTAMP"/>
|
<result property="isPause" column="is_pause" jdbcType="VARCHAR"/>
|
<result property="firstLitAt" column="first_lit_at" jdbcType="TIMESTAMP"/>
|
<result property="address" column="address" jdbcType="VARCHAR"/>
|
<result property="lat" column="lat" jdbcType="VARCHAR"/>
|
<result property="lon" column="lon" jdbcType="VARCHAR"/>
|
<result property="introduction" column="introduction" jdbcType="VARCHAR"/>
|
<result property="isDel" column="is_del" jdbcType="VARCHAR"/>
|
<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_merchant(name, phone, account, logo, user_id, level, publish_limit, expire_at,
|
address, lat, lon, introduction, is_del, created_at, created_by, updated_at, updated_by)
|
values
|
<foreach collection="entities" item="entity" separator=",">
|
(#{entity.name}, #{entity.phone}, #{entity.account}, #{entity.logo}, #{entity.userId}, #{entity.level},
|
#{entity.publishLimit}, #{entity.expireAt}, #{entity.address}, #{entity.lat}, #{entity.lon},
|
#{entity.introduction}, #{entity.isDel}, #{entity.createdAt}, #{entity.createdBy}, #{entity.updatedAt},
|
#{entity.updatedBy})
|
</foreach>
|
</insert>
|
<!-- 批量插入或按主键更新 -->
|
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
|
insert into smart_life.mcs_merchant(name, phone, account, logo, user_id, level, publish_limit, expire_at,
|
address, lat, lon, introduction, is_del, created_at, created_by, updated_at, updated_by)
|
values
|
<foreach collection="entities" item="entity" separator=",">
|
(#{entity.name}, #{entity.phone}, #{entity.account}, #{entity.logo}, #{entity.userId}, #{entity.level},
|
#{entity.publishLimit}, #{entity.expireAt}, #{entity.address}, #{entity.lat}, #{entity.lon},
|
#{entity.introduction}, #{entity.isDel}, #{entity.createdAt}, #{entity.createdBy}, #{entity.updatedAt},
|
#{entity.updatedBy})
|
</foreach>
|
on duplicate key update
|
name = values(name) , phone = values(phone) , account = values(account) , logo = values(logo) , user_id =
|
values(user_id) , level = values(level) , publish_limit = values(publish_limit) , expire_at = values(expire_at)
|
, address = values(address) , lat = values(lat) , lon = values(lon) , introduction = values(introduction) ,
|
is_del = values(is_del) , created_at = values(created_at) , created_by = values(created_by) , updated_at =
|
values(updated_at) , updated_by = values(updated_by)
|
</insert>
|
<update id="updateIsPauseStatus">
|
UPDATE mcs_merchant SET is_pause = 1 WHERE id IN
|
<foreach collection="needDealIds" index="index" item="item" open="(" separator="," close=")">
|
#{item}
|
</foreach>
|
</update>
|
<update id="enableUserStatus">
|
UPDATE sys_user SET `status` = 1 WHERE user_id = #{userId}
|
</update>
|
<select id="getMcsMerchantById"
|
resultType="com.panzhihua.common.model.vos.community.microCommercialStreet.McsMerchantVO">
|
SELECT t1.id, t1.`name`, t1.phone, t1.account, t1.`level`, t1.expire_at, t1.first_lit_at, t1.publish_limit,
|
t1.logo, t1.address, t1.lat, t1.lon, t1.introduction, t2.`status` AS accountStatus
|
FROM mcs_merchant t1
|
LEFT JOIN sys_user t2 ON t1.user_id = t2.user_id
|
WHERE t1.id = #{merchantId} AND t1.is_del = 0
|
</select>
|
<select id="pageMcsMerchant"
|
resultType="com.panzhihua.common.model.vos.community.microCommercialStreet.McsMerchantVO">
|
SELECT t1.id, t1.`name`, t1.phone, t1.account, t1.`level`, t1.expire_at, t1.first_lit_at, t1.publish_limit, t2.`status` AS accountStatus
|
FROM mcs_merchant t1
|
LEFT JOIN sys_user t2 ON t1.user_id = t2.user_id
|
WHERE t1.is_del = 0
|
<if test="pageMcsMerchantDTO.accountStatus != null">
|
AND t2.`status` = #{pageMcsMerchantDTO.accountStatus}
|
</if>
|
<if test="pageMcsMerchantDTO.level != null">
|
AND t1.`level` = #{pageMcsMerchantDTO.level}
|
</if>
|
<if test="pageMcsMerchantDTO.keyword != null and pageMcsMerchantDTO.keyword != """>
|
AND (
|
t1.`name` LIKE CONCAT(#{pageMcsMerchantDTO.keyword}, '%')
|
OR t1.phone LIKE CONCAT(#{pageMcsMerchantDTO.keyword}, '%')
|
)
|
</if>
|
ORDER BY t1.created_at DESC
|
</select>
|
<select id="getMcsMerchantByAccount"
|
resultType="com.panzhihua.common.model.vos.community.microCommercialStreet.McsMerchantVO">
|
SELECT t1.id, t1.`name`, t1.phone, t1.account, t1.`level`, t1.expire_at, t1.first_lit_at, t1.publish_limit,
|
t1.logo, t1.address, t1.lat, t1.lon, t1.introduction, t2.`status` AS accountStatus
|
FROM mcs_merchant t1
|
LEFT JOIN sys_user t2 ON t1.user_id = t2.user_id
|
WHERE t1.account = #{account} AND t1.is_del = 0
|
</select>
|
<select id="getMcsIndexTopData"
|
resultType="com.panzhihua.common.model.vos.community.microCommercialStreet.IndexTopStatisticsVO">
|
SELECT randomCoinTotal + averageCoinTotal AS coinTotal,appliedTotal,gameTotal,infoTotal FROM(
|
SELECT
|
(SELECT IF(SUM(coins) IS NULL,0,SUM(coins)) 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 t1.allocation = 1 AND t2.is_del = 0 AND t3.`status` = 1) AS randomCoinTotal,
|
|
(SELECT IF(SUM(t1.coins * t1.coupons) IS NULL,0,SUM(t1.coins * t1.coupons)) 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 t1.allocation = 2 AND t2.is_del = 0 AND t3.`status` = 1) AS averageCoinTotal,
|
|
(SELECT IF(SUM(coin) IS NULL,0,SUM(coin)) FROM mcs_coupon WHERE to_days(created_at) = to_days(now())) AS appliedTotal,
|
|
(SELECT COUNT(t1.id) 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.`type` = 1 AND t1.expire_at > NOW() AND t2.is_del = 0 AND t3.`status` = 1) AS gameTotal,
|
|
(SELECT COUNT(t1.id) 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.`type` = 2 AND t1.expire_at > NOW() AND t2.is_del = 0 AND t3.`status` = 1) AS infoTotal
|
) temp
|
</select>
|
<select id="pageH5McsMerchant"
|
resultType="com.panzhihua.common.model.vos.community.microCommercialStreet.McsMerchantVO">
|
SELECT * FROM (
|
SELECT t1.id, t1.`name`, t1.phone, t1.account, t1.`level`, t1.expire_at, t1.first_lit_at, t1.publish_limit,
|
t1.introduction, t1.logo,
|
ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN((t1.lat * PI() / 180 - #{pageMcsMerchantDTO.lat} * PI() / 180) / 2),2) +
|
COS(t1.lat * PI() / 180) * COS(#{pageMcsMerchantDTO.lat} * PI() / 180) * POW(SIN((t1.lon * PI() / 180 -
|
#{pageMcsMerchantDTO.lon} * PI() / 180) / 2),2))), 2) AS distance
|
FROM mcs_merchant t1
|
LEFT JOIN sys_user t2 ON t1.user_id = t2.user_id
|
<if test="pageMcsMerchantDTO.type != null">
|
LEFT JOIN (SELECT * FROM mcs_game
|
WHERE `status` = 2 AND `type` = #{pageMcsMerchantDTO.type} AND expire_at > NOW() GROUP BY merchant_id) t3 ON t1.id = t3.merchant_id
|
</if>
|
WHERE t1.is_del = 0 AND t1.expire_at > NOW() AND t2.`status` = 1
|
<if test="pageMcsMerchantDTO.type != null">
|
AND t3.id IS NOT NULL
|
</if>
|
<if test="pageMcsMerchantDTO.keyword != null and pageMcsMerchantDTO.keyword != """>
|
AND t1.`name` LIKE CONCAT(#{pageMcsMerchantDTO.keyword}, '%')
|
</if>
|
) temp WHERE 1=1
|
<if test="pageMcsMerchantDTO.distance != null">
|
<if test="pageMcsMerchantDTO.isMore != null and pageMcsMerchantDTO.isMore ==1">
|
AND distance > #{pageMcsMerchantDTO.distance}
|
</if>
|
<if test="pageMcsMerchantDTO.isMore == null">
|
AND distance <= #{pageMcsMerchantDTO.distance}
|
</if>
|
</if>
|
ORDER BY distance ASC
|
</select>
|
<select id="selectNeedDealExpiredMerchant" resultType="java.lang.Long">
|
SELECT id FROM mcs_merchant WHERE expire_at <= NOW() AND is_pause = 0
|
</select>
|
|
</mapper>
|