add store

This commit is contained in:
Timi
2026-08-07 11:37:54 +08:00
parent 7ffdd715ee
commit 7e40e0202e
60 changed files with 1657 additions and 446 deletions
@@ -8,6 +8,9 @@
`gao_event_record`
WHERE
TRUE
<if test="storeId != null">
AND `store_id` = #{storeId}
</if>
<if test="customerId != null">
AND `customer_id` = #{customerId}
</if>
@@ -18,19 +21,48 @@
AND `registered_at` &gt;= #{beginAt}
</if>
<if test="endAt != null">
AND `registered_at` &gt;= #{endAt}
AND `registered_at` &lt;= #{endAt}
</if>
AND `deleted_at` IS NULL
</select>
<select id="countByStoreIdAndRegisteredDateValue" resultType="java.lang.Long">
SELECT
COUNT(1)
FROM `gao_event_record`
WHERE
`store_id` = #{storeId}
AND `registered_date_value` = #{registeredDateValue}
AND `deleted_at` IS NULL
</select>
<update id="updateBusinessDayNoByStoreIdAndRegisteredDateValue">
UPDATE `gao_event_record`
SET
`business_day_no` = #{businessDayNo},
`updated_at` = ROUND(UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000)
WHERE
`store_id` = #{storeId}
AND `registered_date_value` = #{registeredDateValue}
AND `deleted_at` IS NULL
</update>
<sql id="rangeFrom">
FROM `gao_event_record` r
LEFT JOIN `gao_customer` c ON r.`customer_id` = c.`id`
</sql>
<sql id="rangeWhere">
r.`registered_at` &gt;= #{beginAt}
AND r.`registered_at` &lt;= #{endAt}
TRUE
<if test="beginAt != null">
AND r.`registered_at` &gt;= #{beginAt}
</if>
<if test="endAt != null">
AND r.`registered_at` &lt;= #{endAt}
</if>
AND r.`deleted_at` IS NULL
<if test="storeId != null and storeId != ''">
AND r.`store_id` = #{storeId}
</if>
<if test="customerId != null">
AND r.`customer_id` = #{customerId}
</if>
@@ -69,6 +101,9 @@
<sql id="rankWhere">
r.`deleted_at` IS NULL
AND c.`deleted_at` IS NULL
<if test="storeId != null and storeId != ''">
AND r.`store_id` = #{storeId}
</if>
<if test="customerId != null and customerId != ''">
AND r.`customer_id` = #{customerId}
</if>
@@ -97,7 +132,7 @@
WITH `daily_stat` AS (
SELECT
r.`customer_id` AS `customerId`,
DATE(FROM_UNIXTIME(r.`registered_at` / 1000)) AS `eventDate`,
r.`business_day_no` AS `businessDayNo`,
COUNT(1) AS `dailyCount`,
MAX(r.`registered_at`) AS `latestRegisteredAt`
FROM `gao_event_record` r
@@ -106,7 +141,7 @@
<include refid="rankWhere"/>
GROUP BY
r.`customer_id`,
DATE(FROM_UNIXTIME(r.`registered_at` / 1000))
r.`business_day_no`
),
`rank_stat` AS (
SELECT
@@ -120,14 +155,14 @@
`continuous_ordered` AS (
SELECT
`customerId`,
`eventDate`,
ROW_NUMBER() OVER (PARTITION BY `customerId` ORDER BY `eventDate` DESC) AS `dayIndex`
`businessDayNo`,
ROW_NUMBER() OVER (PARTITION BY `customerId` ORDER BY `businessDayNo` DESC) AS `dayIndex`
FROM `daily_stat`
),
`latest_date` AS (
SELECT
`customerId`,
MAX(`eventDate`) AS `latestEventDate`
MAX(`businessDayNo`) AS `latestBusinessDayNo`
FROM `daily_stat`
GROUP BY `customerId`
),
@@ -137,7 +172,7 @@
COUNT(1) AS `recentContinuousEventDays`
FROM `continuous_ordered` o
LEFT JOIN `latest_date` l ON o.`customerId` = l.`customerId`
WHERE DATE_ADD(o.`eventDate`, INTERVAL o.`dayIndex` DAY) = DATE_ADD(l.`latestEventDate`, INTERVAL 1 DAY)
WHERE o.`businessDayNo` + o.`dayIndex` = l.`latestBusinessDayNo` + 1
GROUP BY o.`customerId`
),
`ranked` AS (