You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

266 lines
11 KiB

<?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.example.demo.mapper.coin.GoldDetailMapper">
<insert id="insertExportRecord" useGeneratedKeys="true" keyProperty="recordId.id">
insert into export (account,type,state,url,file_name,data_num)
values(#{account},#{type},#{state},#{url},#{fileName},#{dataNum})
</insert>
<update id="updateConsumeNum">
UPDATE user AS u
JOIN (
SELECT
jwcode,
SUM(CASE WHEN type = 1 THEN 1 ELSE 0 END) AS consume_cnt
FROM user_gold_record
WHERE type IN (0,1)
AND audit_status IN (1,3)
AND flag = 1
GROUP BY jwcode
) AS t ON u.jwcode = t.jwcode
SET
u.consume_num = t.consume_cnt;
</update>
<select id="getGoldDetail" resultType="com.example.demo.domain.vo.coin.GoldDetail">
SELECT
`user`.name,
`user`.jwcode,
m.name AS market,
`ugr`.pay_platform,
`ugr`.type,
Round((`ugr`.free_june + `ugr`.free_december) / 100.0, 2) AS freeGold,
ROUND(`ugr`.sum_gold / 100.0, 2) AS SumGold,
ROUND(`ugr`.permanent_gold / 100.0, 2) AS PermanentGold,
ROUND(`ugr`.free_june / 100.0, 2) AS freeJune,
ROUND(`ugr`.free_december / 100.0, 2) AS freeDecember,
ROUND(`ugr`.task_gold / 100.0, 2) AS taskGold,
`admin`.admin_name,
`ugr`.audit_time,
ROUND((`ugr`.free_june + `ugr`.free_december) / 100.0, 2) AS freeGold
from user_gold_record ugr
left join `user` on `user`.jwcode = `ugr`.jwcode
left join `admin` on `admin`.id = `ugr`.admin_id
left join market m on m.id=`user`.market
<where>
ugr.flag = 1 and
ugr.audit_status IN (1,3)
<if test="flag != 0">
AND `user`.flag = 1
</if>
<if test="jwcode != null">
and ugr.jwcode = #{jwcode}
</if>
<if test="payPlatform != null and payPlatform.length > 0">
and ugr.pay_platform = #{payPlatform}
</if>
<if test="type != null">
and `ugr`.type = #{type}
</if>
<if test="markets!= null and markets.size > 0">
AND user.market IN
<foreach collection="markets" item="markets" open="(" separator="," close=")">
#{markets}
</foreach>
</if>
<if test="startTime != null and endTime != null">
and ugr.`audit_time` BETWEEN #{startTime} AND #{endTime}
</if>
</where>
<choose>
<when test="sortField != null and sortField.length > 0 or sortOrder != null and sortOrder.length > 0">
ORDER BY ${sortField} ${sortOrder}
</when>
<otherwise>
ORDER BY audit_time DESC
</otherwise>
</choose>
</select>
<select id="getTotal" resultType="com.example.demo.domain.vo.coin.Total">
SELECT
ROUND(SUM(sum_gold) / 100.0, 2) AS Goldtotal,
ROUND(SUM(permanent_gold) / 100.0, 2) AS permanentGold,
ROUND((SUM(free_june) + SUM(free_december)) / 100.0, 2) AS freeGold,
ROUND(SUM(task_gold) / 100.0, 2) AS taskGold
from user_gold_record ugr
left join `user` u on u.jwcode = ugr.jwcode
<where>
ugr.flag = 1 and
ugr.audit_status IN (1,3)
<if test="flag != 0">
AND u.flag = 1
</if>
<if test="jwcode != null">
and `ugr`.jwcode = #{jwcode}
</if>
<if test="payPlatform != null and payPlatform.length > 0">
and `ugr`.pay_platform = #{payPlatform}
</if>
<if test="type != null">
and `ugr`.type = #{type}
</if>
<if test="markets!= null and markets.size > 0">
AND user.market IN
<foreach collection="markets" item="market" open="(" separator="," close=")">
#{market}
</foreach>
</if>
<if test="startTime != null and endTime != null">
and ugr.`audit_time` BETWEEN #{startTime} AND #{endTime}
</if>
</where>
</select>
<select id="getGold" resultType="com.example.demo.domain.entity.User">
SELECT
u.id,
u.jwcode,
u.name,
m.name AS market,
ROUND(IFNULL(u.current_permanent_gold+u.current_free_june+u.current_free_december+u.current_task_gold, 0) / 100.0, 2) AS sumGold,
ROUND(IFNULL(u.sum_permanent_gold, 0) / 100.0, 2) AS sumPermanentGold,
ROUND(IFNULL(u.sum_free_june, 0) / 100.0, 2) AS sumFreeJune,
ROUND(IFNULL(u.sum_free_december, 0) / 100.0, 2) AS sumFreeDecember,
ROUND(IFNULL(u.sum_task_gold, 0) / 100.0, 2) AS sumTaskGold,
ROUND(IFNULL(u.current_permanent_gold, 0) / 100.0, 2) AS currentPermanentGold,
ROUND(IFNULL(u.current_free_june, 0) / 100.0, 2) AS currentFreeJune,
ROUND(IFNULL(u.current_free_december, 0) / 100.0, 2) AS currentFreeDecember,
ROUND(IFNULL(u.current_task_gold, 0) / 100.0, 2) AS currentTaskGold,
ROUND(IFNULL(u.sum_consume_permanent, 0) / 100.0, 2) AS sumConsumePermanent,
ROUND(IFNULL(u.sum_consume_task, 0) / 100.0, 2) AS sumConsumeTask,
ROUND(IFNULL(u.sum_consume_free, 0) / 100.0, 2) AS sumConsumeFree,
u.recharge_num,
u.consume_num,
u.first_recharge,
u.create_time,
u.update_time
from user u
left join market m on u.market = m.id
<where>
<if test="flag != 0">
AND u.flag = 1
</if>
<if test="jwcode != null">
and jwcode = #{jwcode}
</if>
<if test="markets != null and markets.size > 0">
AND m.id IN
<foreach collection="markets" item="market" open="(" separator="," close=")">
#{market}
</foreach>
</if>
</where>
<choose>
<when test="sortField != null and sortField.length > 0 or sortOrder != null and sortOrder.length > 0">
ORDER BY ${sortField} ${sortOrder}
</when>
<otherwise>
ORDER BY create_time DESC
</otherwise>
</choose>
</select>
<select id="GoldTotal" resultType="com.example.demo.domain.vo.coin.Total">
SELECT
CAST(SUM(COALESCE(current_permanent_gold, 0)) / 100.0 AS DECIMAL(18,2)) AS permanentGold,
CAST(SUM(COALESCE(current_free_june, 0) + COALESCE(current_free_december, 0)) / 100.0 AS DECIMAL(18,2)) AS freeGold,
CAST(SUM(COALESCE(current_task_gold, 0)) / 100.0 AS DECIMAL(18,2)) AS taskGold,
CAST(
SUM(
COALESCE(current_permanent_gold, 0) +
COALESCE(current_free_june, 0) +
COALESCE(current_free_december, 0) +
COALESCE(current_task_gold, 0)
) / 100.0 AS DECIMAL(18,2)
) AS Goldtotal
from `user`
<where>
<if test="flag != 0">
AND `user`.flag = 1
</if>
<if test="jwcode != null ">
and jwcode = #{jwcode}
</if>
<if test="markets!= null and markets.size > 0">
AND user.market IN
<foreach collection="markets" item="markets" open="(" separator="," close=")">
#{markets}
</foreach>
</if>
</where>
</select>
<select id="getGoldDetail1" resultType="com.example.demo.domain.vo.coin.GoldDetail">
select `user`.name, `user`.jwcode, `user`.market, `ugr`.pay_platform, `ugr`.type, `ugr`.sum_gold, `ugr`.permanent_gold, `ugr`.free_june, `ugr`.free_december, `ugr`.task_gold, `admin`.admin_name, `ugr`.audit_time
from user_gold_record ugr
left join `user` on `user`.jwcode = `ugr`.jwcode
left join `admin` on `admin`.id = `ugr`.admin_id
<where>
ugr.flag = 1
<if test="jwcode != null">
and `ugr`.jwcode = #{jwcode}
</if>
<if test="payPlatform != null and payPlatform.length > 0">
and `ugr`.pay_platform = #{payPlatform}
</if>
<if test="type != null">
and `ugr`.type = #{type}
</if>
<if test="markets != null">
AND user.market IN
<foreach collection="markets" item="markets" open="(" separator="," close=")">
#{markets}
</foreach>
</if>
<if test="startTime != null and endTime != null">
and ugr.`audit_time` BETWEEN #{startTime} AND #{endTime}
</if>
</where>
<choose>
<when test="sortField != null and sortField.length > 0 or sortOrder != null and sortOrder.length > 0">
ORDER BY ${sortField} ${sortOrder}
</when>
<otherwise>
ORDER BY audit_time DESC
</otherwise>
</choose>
</select>
<select id="sumGold" resultType="com.example.demo.domain.vo.coin.Gold">
SELECT
ROUND(SUM(ugr.sum_gold) / 100.0, 2) AS sumGolds,
ROUND(SUM(ugr.permanent_gold) / 100.0, 2) AS permanentGolds,
ROUND(SUM(ugr.task_gold) / 100.0, 2) AS taskGolds,
ROUND(SUM(ugr.free_june + ugr.free_december) / 100.0, 2) AS freeGolds,
COUNT(*) AS totalNum
from user_gold_record ugr
left join `user` on `user`.jwcode = `ugr`.jwcode
left join `admin` on `admin`.id = `ugr`.admin_id
left join market m on m.id=`user`.market
<where>
ugr.flag = 1 and
ugr.audit_status IN (1,3)
<if test="goldDetail.flag != 0">
AND `user`.flag = 1
</if>
<if test="goldDetail.jwcode != null">
and ugr.jwcode = #{goldDetail.jwcode}
</if>
<if test="goldDetail.payPlatform != null and goldDetail.payPlatform.length > 0">
and ugr.pay_platform = #{goldDetail.payPlatform}
</if>
<if test="goldDetail.type != null">
and ugr.type = #{goldDetail.type}
</if>
<if test="goldDetail.markets!= null and goldDetail.markets.size > 0">
AND user.market IN
<foreach collection="goldDetail.markets" item="goldDetail.markets" open="(" separator="," close=")">
#{goldDetail.markets}
</foreach>
</if>
<if test="goldDetail.startTime != null and goldDetail.endTime != null">
and ugr.`audit_time` BETWEEN #{goldDetail.startTime} AND #{goldDetail.endTime}
</if>
</where>
</select>
</mapper>