Files
FrameTour-BE/src/main/resources/mapper/StatisticsMapper.xml
2025-07-27 19:23:30 +08:00

497 lines
17 KiB
XML

<?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.ycwl.basic.mapper.StatisticsMapper">
<insert id="addStatisticsRecord">
insert into statistics(member_id,type,morph_id,scenic_id)
value (#{memberId},#{type},#{morphId},#{scenicId})
</insert>
<select id="countOrderAmount" resultType="java.math.BigDecimal">
select ifnull(sum(pay_price),0) as payPrice
from `order`
where
(status = 1 or status = 2) and scenic_id = #{scenicId}
<if test="startTime!= null">
and pay_at >= #{startTime}
</if>
<if test="endTime!= null">
and pay_at &lt;= #{endTime}
</if>
</select>
<select id="countPreviewVideoOfMember" resultType="java.lang.Integer">
SELECT
IFNULL(count(1), 0) AS count
FROM (
select count(1) as count
FROM `t_stats_record` r
left join `t_stats` s on r.trace_id=s.trace_id
where r.trace_id in (select trace_id from `t_stats_record` where action = 'ENTER_SCENIC' and `identifier`=#{scenicId})
and action = 'LOAD'
and identifier = 'pages/videoSynthesis/buy'
and JSON_EXTRACT(`params`, '$.share') is null
<if test="startTime!= null">
and r.create_time >= #{startTime}
</if>
<if test="endTime!= null">
and r.create_time &lt;= #{endTime}
</if>
group by s.member_id
)a
</select>
<select id="countScanCodeOfMember" resultType="java.lang.Integer">
SELECT
IFNULL(count(1), 0) AS count
FROM (
select 1
FROM `t_stats_record` r
left join `t_stats` s on r.trace_id=s.trace_id
where r.trace_id in (select trace_id from `t_stats_record` where action = 'ENTER_SCENIC' and `identifier`=#{scenicId})
and action = 'LAUNCH'
and JSON_EXTRACT(`params`, '$.scene') in (1047,1048,1049)
<if test="startTime!= null">
and s.create_time >= #{startTime}
</if>
<if test="endTime!= null">
and s.create_time &lt;= #{endTime}
</if>
group by s.member_id
) AS subquery;
</select>
<select id="countClickPayOfMember" resultType="java.lang.Integer">
SELECT
IFNULL(count(1), 0) AS count
FROM (
select 1
FROM `t_stats_record` r
left join `t_stats` s on r.trace_id=s.trace_id
where r.trace_id in (select trace_id from `t_stats_record` where action = 'ENTER_SCENIC' and `identifier`=#{scenicId})
and action = 'PAYMENT'
and (identifier = 'PAY_REQ' or identifier = 'PAY_BATCH_REQ' or identifier = 'PAY_SOURCE_REQ' or identifier = 'PAY_BATCH_REQ')
<if test="startTime!= null">
and s.create_time >= #{startTime}
</if>
<if test="endTime!= null">
and s.create_time &lt;= #{endTime}
</if>
group by s.member_id
) AS subquery;
</select>
<select id="countPayOfMember" resultType="java.lang.Integer">
SELECT
IFNULL(count(1), 0) AS count
FROM (
select count(1) as count
from `statistics`
where scenic_id = #{scenicId} and type in (3,4)
<if test="startTime!= null">
and create_time >= #{startTime}
</if>
<if test="endTime!= null">
and create_time &lt;= #{endTime}
</if>
group by member_id
)a
</select>
<select id="countSceneOrderNum" resultType="java.lang.Integer">
SELECT
IFNULL(count(count), 0) AS count
FROM (
select count(1) as count
from statistics
where type=4 and scenic_id = #{scenicId}
<if test="startTime!= null">
and create_time >= #{startTime}
</if>
<if test="endTime!= null">
and create_time &lt;= #{endTime}
</if>
group by morph_id
)a
</select>
<select id="countPushOrderNum" resultType="java.lang.Integer">
SELECT
IFNULL(count(count), 0) AS count
FROM (
select count(1) as count
from statistics
where type=3 and scenic_id = #{scenicId}
<if test="startTime!= null">
and create_time >= #{startTime}
</if>
<if test="endTime!= null">
and create_time &lt;= #{endTime}
</if>
group by morph_id
)a
</select>
<select id="countPushOfMember" resultType="java.lang.Integer">
SELECT
IFNULL(count(1), 0) AS count
FROM (
select count(1) as count
FROM `t_stats_record` r
left join `t_stats` s on r.trace_id=s.trace_id
where r.trace_id in (select trace_id from `t_stats_record` where action = 'ENTER_SCENIC' and `identifier`=#{scenicId})
and action = 'PERM_REQ' and identifier = 'NOTIFY'
<if test="startTime!= null">
and r.create_time >= #{startTime}
</if>
<if test="endTime!= null">
and r.create_time &lt;= #{endTime}
</if>
group by s.member_id
)a
</select>
<select id="countCameraShotOfMember" resultType="java.lang.Integer">
select count(1) as count
from face_sample
where scenic_id = #{scenicId}
<if test="startTime!= null">
and create_at >= #{startTime}
</if>
<if test="endTime!= null">
and create_at &lt;= #{endTime}
</if>
</select>
<select id="countUploadFaceOfMember" resultType="java.lang.Integer">
select ifnull(count(1),0) as count
from(
select 1 as count
from t_stats_record r
left join `t_stats` s on r.trace_id=s.trace_id
where r.trace_id in (select trace_id from `t_stats_record` where action = 'ENTER_SCENIC' and `identifier`=#{scenicId})
and r.action = 'FACE_UPLOAD'
<if test="startTime!= null">
and s.create_time >= #{startTime}
</if>
<if test="endTime!= null">
and s.create_time &lt;= #{endTime}
</if>
group by s.member_id
) a
</select>
<select id="countCompleteVideoOfMember" resultType="java.lang.Integer">
select ifnull(count(1),0) as count
from(
select 1 from (
select r.identifier, s.member_id
from t_stats_record r
left join `t_stats` s on r.trace_id=s.trace_id
where r.trace_id in (select trace_id from `t_stats_record` where action = 'ENTER_SCENIC' and `identifier`=#{scenicId})
and r.action = 'FACE_UPLOAD'
<if test="startTime!= null">
and s.create_time >= #{startTime}
</if>
<if test="endTime!= null">
and s.create_time &lt;= #{endTime}
</if>
GROUP BY r.identifier, s.member_id
) stat left join task on task.face_id = stat.identifier and task.`status` = 1
where task.id is not null
group by stat.member_id
) a
</select>
<select id="countTotalVisitorOfMember" resultType="java.lang.Integer">
SELECT
IFNULL(count(1), 0) AS count
FROM (
select 1
FROM `t_stats_record` r
left join `t_stats` s on r.trace_id=s.trace_id
where r.trace_id in (select trace_id from `t_stats_record` where action = 'ENTER_SCENIC' and `identifier`=#{scenicId})
and action = "LAUNCH"
<if test="startTime!= null">
and s.create_time >= #{startTime}
</if>
<if test="endTime!= null">
and s.create_time &lt;= #{endTime}
</if>
group by s.member_id
) AS subquery;
</select>
<select id="countCompleteOfVideo" resultType="java.lang.Integer">
select ifnull(count(1),0) as count
from(
select 1 from (
select r.identifier, s.member_id
from t_stats_record r
left join `t_stats` s on r.trace_id=s.trace_id
where r.trace_id in (select trace_id from `t_stats_record` where action = 'ENTER_SCENIC' and `identifier`=#{scenicId})
and r.action = 'FACE_UPLOAD'
<if test="startTime!= null">
and s.create_time >= #{startTime}
</if>
<if test="endTime!= null">
and s.create_time &lt;= #{endTime}
</if>
GROUP BY r.identifier, s.member_id
) stat left join task on task.face_id = stat.identifier and task.`status` = 1
where task.id is not null
) a
</select>
<select id="countPreviewOfVideo" resultType="java.lang.Integer">
SELECT
IFNULL(SUM(count), 0) AS count
FROM (
select 1 as count
FROM `t_stats_record` r
left join `t_stats` s on r.trace_id=s.trace_id
where r.trace_id in (select trace_id from `t_stats_record` where action = 'ENTER_SCENIC' and `identifier`=#{scenicId})
and action = 'LOAD'
and identifier = 'pages/videoSynthesis/buy'
and JSON_EXTRACT(`params`, '$.id') is not null
and JSON_EXTRACT(`params`, '$.share') is null
<if test="startTime!= null">
and s.create_time >= #{startTime}
</if>
<if test="endTime!= null">
and s.create_time &lt;= #{endTime}
</if>
group by JSON_EXTRACT(`params`, "$.id")
)a
</select>
<select id="countPayOfOrder" resultType="java.lang.Integer">
select count(1) as count
from `order`
where
pay_at is not null and scenic_id = #{scenicId}
<if test="startTime!= null">
and create_at >= #{startTime}
</if>
<if test="endTime!= null">
and create_at &lt;= #{endTime}
</if>
</select>
<select id="countRefundOfOrder" resultType="java.lang.Integer">
select count(1) as count
from `order`
where
refund_status = 1 and scenic_id = #{scenicId}
<if test="startTime!= null">
and create_at >= #{startTime}
</if>
<if test="endTime!= null">
and create_at &lt;= #{endTime}
</if>
</select>
<select id="countRefundAmount" resultType="java.math.BigDecimal">
select ifnull(sum(pay_price),0) as payPrice
from `order`
where
refund_status = 1 and scenic_id = #{scenicId}
<if test="startTime!= null">
and create_at >= #{startTime}
</if>
<if test="endTime!= null">
and create_at &lt;= #{endTime}
</if>
</select>
<select id="getBrokerIdListForUser" resultType="java.lang.Long">
select identifier
from (
select identifier, max(r.create_time) as createTime
FROM `t_stats_record` r
left join `t_stats` s on r.trace_id=s.trace_id
where action = "CODE_SCAN"
and s.member_id = #{memberId}
<if test="startTime!= null">
and r.create_time >= #{startTime}
</if>
<if test="endTime!= null">
and r.create_time &lt;= #{endTime}
</if>
group by identifier
) a
order by createTime desc
</select>
<select id="getUserRecentEnterType" resultType="java.lang.Long">
select JSON_EXTRACT(`params`, '$.scene')
FROM `t_stats_record` r
left join `t_stats` s on r.trace_id=s.trace_id
where action = "LAUNCH" and s.member_id = #{memberId}
<if test="endTime!= null">
and r.create_time &lt;= #{endTime}
</if>
order by r.create_time desc
limit 1
</select>
<select id="listStatByScenic" resultType="com.ycwl.basic.model.mobile.statistic.resp.AppStatisticsFunnelVO">
SELECT cs1 AS cameraShotOfMemberNum, v1 AS totalVisitorOfMemberNum, sv1 AS scanCodeVisitorOfMemberNum, u1 AS uploadFaceOfMemberNum, m1 AS pushOfMemberNum, gv1 AS completeVideoOfMemberNum, gv2 AS completeOfVideoNum, pv1 AS previewVideoOfMemberNum, pv2 AS previewOfVideoNum, cp1 AS clickOnPayOfMemberNum, o1 AS payOfMemberNum, o2 AS payOfOrderNum, o3 AS payOfOrderAmount, ro2 AS refundOfOrderNum, ro3 AS refundOfOrderAmount
FROM scenic_stats
WHERE scenic_id = #{scenicId}
AND date BETWEEN #{startTime} AND #{endTime}
</select>
<select id="orderChartByDate" resultType="java.util.HashMap">
SELECT
DATE(date_series.DATE) as t,
COALESCE ( count( `order`.id ), 0 ) AS count,
COALESCE ( sum( `order`.pay_price ), 0 ) AS price
FROM
(
SELECT
DATE_ADD( #{startTime}, INTERVAL ( units.i + tens.i * 10 + hundreds.i * 100 ) DAY ) AS DATE
FROM
(
SELECT
0 AS i UNION ALL
SELECT
1 UNION ALL
SELECT
2 UNION ALL
SELECT
3 UNION ALL
SELECT
4 UNION ALL
SELECT
5 UNION ALL
SELECT
6 UNION ALL
SELECT
7 UNION ALL
SELECT
8 UNION ALL
SELECT
9
) units
CROSS JOIN (
SELECT
0 AS i UNION ALL
SELECT
1 UNION ALL
SELECT
2 UNION ALL
SELECT
3 UNION ALL
SELECT
4 UNION ALL
SELECT
5 UNION ALL
SELECT
6 UNION ALL
SELECT
7 UNION ALL
SELECT
8 UNION ALL
SELECT
9
) tens
CROSS JOIN (
SELECT
0 AS i UNION ALL
SELECT
1 UNION ALL
SELECT
2 UNION ALL
SELECT
3 UNION ALL
SELECT
4 UNION ALL
SELECT
5 UNION ALL
SELECT
6 UNION ALL
SELECT
7 UNION ALL
SELECT
8 UNION ALL
SELECT
9
) hundreds
WHERE
DATE_ADD( #{startTime}, INTERVAL ( units.i + tens.i * 10 + hundreds.i * 100 ) DAY ) &lt;= #{endTime}
) date_series
LEFT JOIN `order` ON DATE ( `order`.create_at ) = date_series.DATE AND `order`.scenic_id = #{scenicId} AND ( `order`.STATUS = 1 OR `order`.STATUS = 2 )
GROUP BY
date_series.DATE
ORDER BY date_series.DATE
</select>
<select id="orderChartByHour" resultType="java.util.HashMap">
SELECT
date_series.HOUR as t,
COALESCE ( count( `order`.id ), 0 ) AS count,
COALESCE ( sum( `order`.pay_price ), 0 ) AS price
FROM
(
SELECT
DATE_FORMAT( DATE_ADD( #{startTime}, INTERVAL ( units.i + tens.i * 10 + hundreds.i * 100 ) HOUR ), '%m-%d %H') AS HOUR
FROM
(
SELECT
0 AS i UNION ALL
SELECT
1 UNION ALL
SELECT
2 UNION ALL
SELECT
3 UNION ALL
SELECT
4 UNION ALL
SELECT
5 UNION ALL
SELECT
6 UNION ALL
SELECT
7 UNION ALL
SELECT
8 UNION ALL
SELECT
9
) units
CROSS JOIN (
SELECT
0 AS i UNION ALL
SELECT
1 UNION ALL
SELECT
2 UNION ALL
SELECT
3 UNION ALL
SELECT
4 UNION ALL
SELECT
5 UNION ALL
SELECT
6 UNION ALL
SELECT
7 UNION ALL
SELECT
8 UNION ALL
SELECT
9
) tens
CROSS JOIN (
SELECT
0 AS i UNION ALL
SELECT
1 UNION ALL
SELECT
2 UNION ALL
SELECT
3 UNION ALL
SELECT
4 UNION ALL
SELECT
5 UNION ALL
SELECT
6 UNION ALL
SELECT
7 UNION ALL
SELECT
8 UNION ALL
SELECT
9
) hundreds
WHERE
DATE_ADD( #{startTime}, INTERVAL ( units.i + tens.i * 10 + hundreds.i * 100 ) HOUR ) &lt;= #{endTime}
) date_series
LEFT JOIN `order` ON DATE_FORMAT( `order`.create_at, '%m-%d %H' ) = date_series.HOUR AND `order`.scenic_id = #{scenicId} AND ( `order`.STATUS = 1 OR `order`.STATUS = 2 )
GROUP BY
date_series.HOUR
ORDER BY date_series.HOUR
</select>
<insert id="insertStat">
REPLACE INTO scenic_stats (scenic_id, date, cs1, v1, sv1, u1, m1, gv1, gv2, pv1, pv2, cp1, o1, o2, o3, ro2, ro3)
VALUES (#{scenicId}, #{date}, #{data.cameraShotOfMemberNum}, #{data.totalVisitorOfMemberNum}, #{data.scanCodeVisitorOfMemberNum}, #{data.uploadFaceOfMemberNum}, #{data.pushOfMemberNum}, #{data.completeVideoOfMemberNum}, #{data.completeOfVideoNum}, #{data.previewVideoOfMemberNum}, #{data.previewOfVideoNum}, #{data.clickOnPayOfMemberNum}, #{data.payOfMemberNum}, #{data.payOfOrderNum}, #{data.payOfOrderAmount}, #{data.refundOfOrderNum}, #{data.refundOfOrderAmount})
</insert>
</mapper>