refactor gao module
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
RENAME TABLE `gao_registration_event` TO `gao_event`;
|
||||
|
||||
ALTER TABLE `gao_event`
|
||||
DROP KEY `idx_gao_registration_event_status`,
|
||||
ADD KEY `idx_gao_event_status` (`status`, `deleted_at`, `sort`, `created_at`);
|
||||
|
||||
RENAME TABLE `gao_registration_event_role_relation` TO `gao_event_role_relation`;
|
||||
|
||||
ALTER TABLE `gao_event_role_relation`
|
||||
DROP KEY `idx_gao_registration_event_role_relation_registration_event_id`,
|
||||
CHANGE COLUMN `registration_event_id` `event_id` VARCHAR(36) NOT NULL COMMENT '登记事件 ID',
|
||||
ADD KEY `idx_gao_event_role_relation_event_id` (`event_id`);
|
||||
|
||||
RENAME TABLE `gao_registration_event_record` TO `gao_event_record`;
|
||||
|
||||
ALTER TABLE `gao_event_record`
|
||||
DROP KEY `idx_gao_registration_event_record_customer_id`,
|
||||
DROP KEY `idx_gao_registration_event_record_registration_event_id`,
|
||||
DROP KEY `idx_gao_registration_event_record_registered_at`,
|
||||
CHANGE COLUMN `registration_event_id` `event_id` VARCHAR(36) NOT NULL COMMENT '登记事件 ID',
|
||||
ADD KEY `idx_gao_event_record_customer_id` (`customer_id`),
|
||||
ADD KEY `idx_gao_event_record_event_id` (`event_id`),
|
||||
ADD KEY `idx_gao_event_record_registered_at` (`registered_at`);
|
||||
|
||||
UPDATE `attachment`
|
||||
SET `biz_type` = 'GAO_EVENT_RECORD'
|
||||
WHERE `biz_type` = 'GAO_REGISTRATION_EVENT_RECORD';
|
||||
|
||||
UPDATE `permission`
|
||||
SET `code` = CASE `code`
|
||||
WHEN 'REGISTRATION_EVENT:CREATE' THEN 'EVENT:CREATE'
|
||||
WHEN 'REGISTRATION_EVENT:READ' THEN 'EVENT:READ'
|
||||
WHEN 'REGISTRATION_EVENT:UPDATE' THEN 'EVENT:UPDATE'
|
||||
WHEN 'REGISTRATION_EVENT:DELETE' THEN 'EVENT:DELETE'
|
||||
WHEN 'REGISTRATION_EVENT_RECORD:CREATE' THEN 'EVENT_RECORD:CREATE'
|
||||
WHEN 'REGISTRATION_EVENT_RECORD:READ' THEN 'EVENT_RECORD:READ'
|
||||
WHEN 'REGISTRATION_EVENT_RECORD:EXPORT' THEN 'EVENT_RECORD:EXPORT'
|
||||
WHEN 'REGISTRATION_EVENT_RECORD:UPDATE' THEN 'EVENT_RECORD:UPDATE'
|
||||
WHEN 'REGISTRATION_EVENT_RECORD:DELETE' THEN 'EVENT_RECORD:DELETE'
|
||||
ELSE `code`
|
||||
END
|
||||
WHERE
|
||||
`module_code` = 'GAO'
|
||||
AND `code` IN (
|
||||
'REGISTRATION_EVENT:CREATE',
|
||||
'REGISTRATION_EVENT:READ',
|
||||
'REGISTRATION_EVENT:UPDATE',
|
||||
'REGISTRATION_EVENT:DELETE',
|
||||
'REGISTRATION_EVENT_RECORD:CREATE',
|
||||
'REGISTRATION_EVENT_RECORD:READ',
|
||||
'REGISTRATION_EVENT_RECORD:EXPORT',
|
||||
'REGISTRATION_EVENT_RECORD:UPDATE',
|
||||
'REGISTRATION_EVENT_RECORD:DELETE'
|
||||
);
|
||||
@@ -14,7 +14,7 @@
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="bizIdList == null or bizIdList.isEmpty()">
|
||||
AND 1 = 0
|
||||
AND FALSE
|
||||
</if>
|
||||
AND `deleted_at` IS NULL
|
||||
AND (`destroy_at` IS NULL OR UNIX_TIMESTAMP() < `destroy_at`)
|
||||
@@ -24,6 +24,35 @@
|
||||
#{attachType}
|
||||
</foreach>
|
||||
</if>
|
||||
ORDER BY `created_at` ASC
|
||||
ORDER BY `created_at`
|
||||
</select>
|
||||
<select id="selectThumb" resultType="com.imyeyu.api.modules.common.entity.Attachment">
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
`attachment`
|
||||
WHERE
|
||||
biz_type = #{bizType}
|
||||
AND biz_id = #{sourceId}
|
||||
AND attach_type = 'THUMB'
|
||||
<choose>
|
||||
<when test="requestWidth != null">
|
||||
AND JSON_EXTRACT(metadata, '$.requestWidth') = #{requestWidth}
|
||||
</when>
|
||||
<otherwise>
|
||||
AND JSON_EXTRACT(metadata, '$.requestWidth') IS NULL
|
||||
</otherwise>
|
||||
</choose>
|
||||
<choose>
|
||||
<when test="requestHeight != null">
|
||||
AND JSON_EXTRACT(metadata, '$.requestHeight') = #{requestHeight}
|
||||
</when>
|
||||
<otherwise>
|
||||
AND JSON_EXTRACT(metadata, '$.requestHeight') IS NULL
|
||||
</otherwise>
|
||||
</choose>
|
||||
AND is_destroyed = FALSE
|
||||
AND UNIX_TIMESTAMP() * 1000 < destroy_at
|
||||
LIMIT 1
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -1,33 +1,6 @@
|
||||
<?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.imyeyu.api.modules.gao.mapper.GaoCustomerMapper">
|
||||
<sql id="searchWhere">
|
||||
1 = 1
|
||||
AND `deleted_at` IS NULL
|
||||
<if test="keyword != null and keyword != ''">
|
||||
AND (
|
||||
`code` LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR `name` LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR `telephone` LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR `address` LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR `disease` LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR CAST(`conditioning_part` AS CHAR) LIKE CONCAT('%', #{keyword}, '%')
|
||||
)
|
||||
</if>
|
||||
<if test="introducerCustomerId != null and introducerCustomerId != ''">
|
||||
AND `introducer_customer_id` = #{introducerCustomerId}
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<select id="search" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomer">
|
||||
SELECT
|
||||
*
|
||||
FROM `gao_customer`
|
||||
WHERE
|
||||
<include refid="searchWhere"/>
|
||||
ORDER BY `created_at` DESC
|
||||
</select>
|
||||
|
||||
<select id="selectByIdList" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomer">
|
||||
SELECT
|
||||
*
|
||||
@@ -40,54 +13,7 @@
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
|
||||
<select id="countSearch" resultType="java.lang.Long">
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM `gao_customer`
|
||||
WHERE
|
||||
<include refid="searchWhere"/>
|
||||
</select>
|
||||
|
||||
<select id="searchPage" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomer">
|
||||
SELECT
|
||||
*
|
||||
FROM `gao_customer`
|
||||
WHERE
|
||||
<include refid="searchWhere"/>
|
||||
ORDER BY `created_at` DESC
|
||||
LIMIT #{offset}, #{size}
|
||||
</select>
|
||||
|
||||
<select id="selectInvitedList" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomer">
|
||||
SELECT
|
||||
*
|
||||
FROM `gao_customer`
|
||||
WHERE
|
||||
`introducer_customer_id` = #{introducerCustomerId}
|
||||
AND `deleted_at` IS NULL
|
||||
ORDER BY `created_at` DESC
|
||||
</select>
|
||||
|
||||
<select id="countInvited" resultType="java.lang.Long">
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM `gao_customer`
|
||||
WHERE
|
||||
`introducer_customer_id` = #{introducerCustomerId}
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
|
||||
<update id="updateInvitedCountDelta">
|
||||
UPDATE `gao_customer`
|
||||
SET
|
||||
`invited_count` = GREATEST(IFNULL(`invited_count`, 0) + #{delta}, 0),
|
||||
`updated_at` = UNIX_TIMESTAMP() * 1000
|
||||
WHERE
|
||||
`id` = #{customerId}
|
||||
AND `deleted_at` IS NULL
|
||||
</update>
|
||||
|
||||
<select id="statDailyNewCustomer" resultType="com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStatView">
|
||||
<select id="stateDailyNewCustomer" resultType="com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView">
|
||||
SELECT
|
||||
CAST(DATE_FORMAT(FROM_UNIXTIME(`created_at` / 1000), '%Y%m%d') AS UNSIGNED) AS `dateValue`,
|
||||
COUNT(1) AS `newCustomerCount`
|
||||
@@ -109,7 +35,7 @@
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
|
||||
<select id="statGender" resultType="com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView">
|
||||
<select id="stateGender" resultType="com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView">
|
||||
SELECT
|
||||
IFNULL(CAST(`gender` AS CHAR), 'UNKNOWN') AS `genderCode`,
|
||||
COUNT(1) AS `count`
|
||||
|
||||
+9
-9
@@ -1,12 +1,12 @@
|
||||
<?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.imyeyu.api.modules.gao.mapper.GaoRegistrationEventMapper">
|
||||
<select id="selectByIdList" resultType="com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent">
|
||||
<mapper namespace="com.imyeyu.api.modules.gao.mapper.GaoEventMapper">
|
||||
<select id="selectByIdList" resultType="com.imyeyu.api.modules.gao.entity.GaoEvent">
|
||||
SELECT
|
||||
*
|
||||
FROM `gao_registration_event`
|
||||
FROM `gao_event`
|
||||
WHERE
|
||||
1 = 1
|
||||
TRUE
|
||||
<if test="idList != null and !idList.isEmpty()">
|
||||
AND `id` IN
|
||||
<foreach collection="idList" item="id" separator="," open="(" close=")">
|
||||
@@ -14,20 +14,20 @@
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="idList == null or idList.isEmpty()">
|
||||
AND 1 = 0
|
||||
AND FALSE
|
||||
</if>
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
|
||||
<select id="selectEnabledList" resultType="com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent">
|
||||
<select id="selectValidList" resultType="com.imyeyu.api.modules.gao.entity.GaoEvent">
|
||||
SELECT
|
||||
*
|
||||
FROM `gao_registration_event`
|
||||
FROM `gao_event`
|
||||
WHERE
|
||||
(`status` IS NULL OR `status` = 'ACTIVE')
|
||||
`status` = '${@com.imyeyu.api.modules.gao.entity.GaoEvent$Status@ACTIVE.name()}'
|
||||
AND (`begin_at` IS NULL OR `begin_at` <= #{now})
|
||||
AND (`end_at` IS NULL OR #{now} <= `end_at`)
|
||||
AND `deleted_at` IS NULL
|
||||
ORDER BY `sort` ASC, `created_at` ASC
|
||||
ORDER BY `sort`, `created_at`
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,171 @@
|
||||
<?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.imyeyu.api.modules.gao.mapper.GaoEventRecordMapper">
|
||||
<select id="count" resultType="java.lang.Long">
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM
|
||||
`gao_event_record`
|
||||
WHERE
|
||||
TRUE
|
||||
<if test="customerId != null">
|
||||
AND `customer_id` = #{customerId}
|
||||
</if>
|
||||
<if test="eventId != null">
|
||||
AND `event_id` = #{eventId}
|
||||
</if>
|
||||
<if test="beginAt != null">
|
||||
AND `registered_at` >= #{beginAt}
|
||||
</if>
|
||||
<if test="endAt != null">
|
||||
AND `registered_at` >= #{endAt}
|
||||
</if>
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
|
||||
<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` >= #{beginAt}
|
||||
AND r.`registered_at` <= #{endAt}
|
||||
AND r.`deleted_at` IS NULL
|
||||
<if test="customerId != null">
|
||||
AND r.`customer_id` = #{customerId}
|
||||
</if>
|
||||
<if test="eventIdList != null and eventIdList.size() > 0">
|
||||
AND r.`event_id` IN
|
||||
<foreach collection="eventIdList" item="eventId" open="(" separator="," close=")">
|
||||
#{eventId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="keyword != null and keyword.trim() != ''">
|
||||
AND (
|
||||
c.`code` LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR c.`name` LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR r.`remark` LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR r.`operator_user_id` LIKE CONCAT('%', #{keyword}, '%')
|
||||
)
|
||||
</if>
|
||||
</sql>
|
||||
<select id="countByRange" resultType="long">
|
||||
SELECT
|
||||
COUNT(1)
|
||||
<include refid="rangeFrom"/>
|
||||
WHERE
|
||||
<include refid="rangeWhere"/>
|
||||
</select>
|
||||
<select id="selectByRange" resultType="com.imyeyu.api.modules.gao.entity.GaoEventRecord">
|
||||
SELECT
|
||||
r.*
|
||||
<include refid="rangeFrom"/>
|
||||
WHERE
|
||||
<include refid="rangeWhere"/>
|
||||
ORDER BY r.`registered_at` DESC, r.`created_at` DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<sql id="rankWhere">
|
||||
r.`deleted_at` IS NULL
|
||||
AND c.`deleted_at` IS NULL
|
||||
<if test="customerId != null and customerId != ''">
|
||||
AND r.`customer_id` = #{customerId}
|
||||
</if>
|
||||
<if test="beginAt != null">
|
||||
AND r.`registered_at` >= #{beginAt}
|
||||
</if>
|
||||
<if test="endAt != null">
|
||||
AND r.`registered_at` <= #{endAt}
|
||||
</if>
|
||||
<if test="eventIdList != null and eventIdList.size() > 0">
|
||||
AND r.`event_id` IN
|
||||
<foreach collection="eventIdList" item="eventId" open="(" separator="," close=")">
|
||||
#{eventId}
|
||||
</foreach>
|
||||
</if>
|
||||
</sql>
|
||||
<select id="countRankByRange" resultType="long">
|
||||
SELECT
|
||||
COUNT(DISTINCT r.`customer_id`)
|
||||
FROM `gao_event_record` r
|
||||
LEFT JOIN `gao_customer` c ON r.`customer_id` = c.`id`
|
||||
WHERE
|
||||
<include refid="rankWhere"/>
|
||||
</select>
|
||||
<select id="selectRankByRange" resultType="com.imyeyu.api.modules.gao.vo.GaoCustomerEventRankView">
|
||||
WITH `daily_stat` AS (
|
||||
SELECT
|
||||
r.`customer_id` AS `customerId`,
|
||||
DATE(FROM_UNIXTIME(r.`registered_at` / 1000)) AS `eventDate`,
|
||||
COUNT(1) AS `dailyCount`,
|
||||
MAX(r.`registered_at`) AS `latestRegisteredAt`
|
||||
FROM `gao_event_record` r
|
||||
LEFT JOIN `gao_customer` c ON r.`customer_id` = c.`id`
|
||||
WHERE
|
||||
<include refid="rankWhere"/>
|
||||
GROUP BY
|
||||
r.`customer_id`,
|
||||
DATE(FROM_UNIXTIME(r.`registered_at` / 1000))
|
||||
),
|
||||
`rank_stat` AS (
|
||||
SELECT
|
||||
`customerId`,
|
||||
COUNT(1) AS `totalEventDays`,
|
||||
SUM(`dailyCount`) AS `totalEventCount`,
|
||||
MAX(`latestRegisteredAt`) AS `latestRegisteredAt`
|
||||
FROM `daily_stat`
|
||||
GROUP BY `customerId`
|
||||
),
|
||||
`continuous_ordered` AS (
|
||||
SELECT
|
||||
`customerId`,
|
||||
`eventDate`,
|
||||
ROW_NUMBER() OVER (PARTITION BY `customerId` ORDER BY `eventDate` DESC) AS `dayIndex`
|
||||
FROM `daily_stat`
|
||||
),
|
||||
`latest_date` AS (
|
||||
SELECT
|
||||
`customerId`,
|
||||
MAX(`eventDate`) AS `latestEventDate`
|
||||
FROM `daily_stat`
|
||||
GROUP BY `customerId`
|
||||
),
|
||||
`continuous_stat` AS (
|
||||
SELECT
|
||||
o.`customerId`,
|
||||
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)
|
||||
GROUP BY o.`customerId`
|
||||
),
|
||||
`ranked` AS (
|
||||
SELECT
|
||||
ROW_NUMBER() OVER (
|
||||
ORDER BY
|
||||
r.`totalEventDays` DESC,
|
||||
r.`totalEventCount` DESC,
|
||||
r.`latestRegisteredAt` DESC,
|
||||
r.`customerId`
|
||||
) AS `rank`,
|
||||
r.`customerId`,
|
||||
r.`totalEventDays`,
|
||||
r.`totalEventCount`,
|
||||
COALESCE(c.`recentContinuousEventDays`, 0) AS `recentContinuousEventDays`,
|
||||
r.`latestRegisteredAt`
|
||||
FROM `rank_stat` r
|
||||
LEFT JOIN `continuous_stat` c ON r.`customerId` = c.`customerId`
|
||||
)
|
||||
SELECT
|
||||
`rank`,
|
||||
`customerId`,
|
||||
`totalEventDays`,
|
||||
`totalEventCount`,
|
||||
`recentContinuousEventDays`,
|
||||
`latestRegisteredAt`
|
||||
FROM `ranked`
|
||||
ORDER BY `rank`
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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.imyeyu.api.modules.gao.mapper.GaoEventRoleRelationMapper">
|
||||
<select id="selectAllByEventIdList" resultType="com.imyeyu.api.modules.gao.entity.GaoEventRoleRelation">
|
||||
SELECT
|
||||
*
|
||||
FROM `gao_event_role_relation`
|
||||
WHERE
|
||||
TRUE
|
||||
<if test="idList != null and !idList.isEmpty()">
|
||||
AND `event_id` IN
|
||||
<foreach collection="idList" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="idList == null or idList.isEmpty()">
|
||||
AND FALSE
|
||||
</if>
|
||||
AND `deleted_at` IS NULL
|
||||
ORDER BY `created_at`
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -1,389 +0,0 @@
|
||||
<?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.imyeyu.api.modules.gao.mapper.GaoRegistrationEventRecordMapper">
|
||||
<select id="selectByRegistrationEventAndPeriod" resultType="com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRecord">
|
||||
SELECT
|
||||
*
|
||||
FROM `gao_registration_event_record`
|
||||
WHERE
|
||||
`registration_event_id` = #{registrationEventId}
|
||||
AND `deleted_at` IS NULL
|
||||
<if test='periodType.name() == "DAY"'>
|
||||
AND DATE_FORMAT(FROM_UNIXTIME(`registered_at` / 1000), '%Y%m%d') = CAST(#{periodValue} AS CHAR)
|
||||
</if>
|
||||
<if test='periodType.name() == "MONTH"'>
|
||||
AND DATE_FORMAT(FROM_UNIXTIME(`registered_at` / 1000), '%Y%m') = CAST(#{periodValue} AS CHAR)
|
||||
</if>
|
||||
<if test='periodType.name() == "YEAR"'>
|
||||
AND DATE_FORMAT(FROM_UNIXTIME(`registered_at` / 1000), '%Y') = CAST(#{periodValue} AS CHAR)
|
||||
</if>
|
||||
ORDER BY `registered_at` DESC
|
||||
</select>
|
||||
|
||||
<select id="countByCustomerIdAndRegistrationEventIdRange" resultType="java.lang.Long">
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM `gao_registration_event_record`
|
||||
WHERE
|
||||
`customer_id` = #{customerId}
|
||||
AND `registration_event_id` = #{registrationEventId}
|
||||
AND `registered_at` >= #{beginRegisteredAt}
|
||||
AND `registered_at` <= #{endRegisteredAt}
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
|
||||
<select id="countByCustomerIdAndRegistrationEventId" resultType="java.lang.Long">
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM `gao_registration_event_record`
|
||||
WHERE
|
||||
`customer_id` = #{customerId}
|
||||
AND `registration_event_id` = #{registrationEventId}
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
|
||||
<select id="countByRegistrationEventId" resultType="java.lang.Long">
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM `gao_registration_event_record`
|
||||
WHERE
|
||||
`registration_event_id` = #{registrationEventId}
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
|
||||
<select id="statByRegistrationEventAndPeriodType" resultType="com.imyeyu.api.modules.gao.vo.GaoRegistrationEventPeriodStatView">
|
||||
SELECT
|
||||
`registration_event_id` AS `registrationEventId`,
|
||||
<choose>
|
||||
<when test='periodType.name() == "DAY"'>
|
||||
CAST(DATE_FORMAT(FROM_UNIXTIME(`registered_at` / 1000), '%Y%m%d') AS UNSIGNED)
|
||||
</when>
|
||||
<when test='periodType.name() == "MONTH"'>
|
||||
CAST(DATE_FORMAT(FROM_UNIXTIME(`registered_at` / 1000), '%Y%m') AS UNSIGNED)
|
||||
</when>
|
||||
<otherwise>
|
||||
CAST(DATE_FORMAT(FROM_UNIXTIME(`registered_at` / 1000), '%Y') AS UNSIGNED)
|
||||
</otherwise>
|
||||
</choose> AS `periodValue`,
|
||||
COUNT(1) AS `count`
|
||||
FROM `gao_registration_event_record`
|
||||
WHERE
|
||||
`registration_event_id` = #{registrationEventId}
|
||||
AND `deleted_at` IS NULL
|
||||
GROUP BY
|
||||
`registration_event_id`,
|
||||
<choose>
|
||||
<when test='periodType.name() == "DAY"'>
|
||||
DATE_FORMAT(FROM_UNIXTIME(`registered_at` / 1000), '%Y%m%d')
|
||||
</when>
|
||||
<when test='periodType.name() == "MONTH"'>
|
||||
DATE_FORMAT(FROM_UNIXTIME(`registered_at` / 1000), '%Y%m')
|
||||
</when>
|
||||
<otherwise>
|
||||
DATE_FORMAT(FROM_UNIXTIME(`registered_at` / 1000), '%Y')
|
||||
</otherwise>
|
||||
</choose>
|
||||
ORDER BY `periodValue` DESC
|
||||
</select>
|
||||
|
||||
<select id="statByCustomerId" resultType="com.imyeyu.api.modules.gao.vo.GaoCustomerRegisterStatView">
|
||||
SELECT
|
||||
r.`customer_id` AS `customerId`,
|
||||
c.`name` AS `customerName`,
|
||||
r.`registration_event_id` AS `registrationEventId`,
|
||||
a.`name` AS `registrationEventName`,
|
||||
COUNT(1) AS `count`,
|
||||
MAX(r.`registered_at`) AS `latestRegisteredAt`
|
||||
FROM `gao_registration_event_record` r
|
||||
LEFT JOIN `gao_customer` c ON r.`customer_id` = c.`id`
|
||||
LEFT JOIN `gao_registration_event` a ON r.`registration_event_id` = a.`id`
|
||||
WHERE
|
||||
r.`customer_id` = #{customerId}
|
||||
AND r.`deleted_at` IS NULL
|
||||
GROUP BY r.`customer_id`, c.`name`, r.`registration_event_id`, a.`name`
|
||||
ORDER BY `latestRegisteredAt` DESC
|
||||
</select>
|
||||
|
||||
<select id="statByCustomerIdAndRange" resultType="com.imyeyu.api.modules.gao.vo.GaoCustomerRegisterStatView">
|
||||
SELECT
|
||||
r.`customer_id` AS `customerId`,
|
||||
c.`name` AS `customerName`,
|
||||
r.`registration_event_id` AS `registrationEventId`,
|
||||
a.`name` AS `registrationEventName`,
|
||||
COUNT(1) AS `count`,
|
||||
MAX(r.`registered_at`) AS `latestRegisteredAt`
|
||||
FROM `gao_registration_event_record` r
|
||||
LEFT JOIN `gao_customer` c ON r.`customer_id` = c.`id`
|
||||
LEFT JOIN `gao_registration_event` a ON r.`registration_event_id` = a.`id`
|
||||
WHERE
|
||||
r.`customer_id` = #{customerId}
|
||||
AND r.`registered_at` >= #{beginRegisteredAt}
|
||||
AND r.`registered_at` <= #{endRegisteredAt}
|
||||
AND r.`deleted_at` IS NULL
|
||||
GROUP BY r.`customer_id`, c.`name`, r.`registration_event_id`, a.`name`
|
||||
ORDER BY `latestRegisteredAt` DESC
|
||||
</select>
|
||||
|
||||
<select id="statAllCustomerByRange" resultType="com.imyeyu.api.modules.gao.vo.GaoCustomerRegisterStatView">
|
||||
SELECT
|
||||
r.`customer_id` AS `customerId`,
|
||||
c.`name` AS `customerName`,
|
||||
r.`registration_event_id` AS `registrationEventId`,
|
||||
a.`name` AS `registrationEventName`,
|
||||
COUNT(1) AS `count`,
|
||||
MAX(r.`registered_at`) AS `latestRegisteredAt`
|
||||
FROM `gao_registration_event_record` r
|
||||
LEFT JOIN `gao_customer` c ON r.`customer_id` = c.`id`
|
||||
LEFT JOIN `gao_registration_event` a ON r.`registration_event_id` = a.`id`
|
||||
WHERE
|
||||
r.`registered_at` >= #{beginRegisteredAt}
|
||||
AND r.`registered_at` <= #{endRegisteredAt}
|
||||
AND r.`deleted_at` IS NULL
|
||||
GROUP BY r.`customer_id`, c.`name`, r.`registration_event_id`, a.`name`
|
||||
ORDER BY `latestRegisteredAt` DESC
|
||||
</select>
|
||||
|
||||
<select id="statCustomerRegistrationDay" resultType="com.imyeyu.api.modules.gao.vo.GaoCustomerRegistrationDayStatView">
|
||||
SELECT
|
||||
r.`customer_id` AS `customerId`,
|
||||
c.`code` AS `customerCode`,
|
||||
c.`name` AS `customerName`,
|
||||
(
|
||||
SELECT a.`id`
|
||||
FROM `attachment` a
|
||||
WHERE
|
||||
a.`biz_type` = 'GAO_CUSTOMER'
|
||||
AND a.`biz_id` = c.`id`
|
||||
AND a.`attach_type` = 'PHOTO'
|
||||
AND a.`deleted_at` IS NULL
|
||||
AND (a.`destroy_at` IS NULL OR UNIX_TIMESTAMP() < a.`destroy_at`)
|
||||
ORDER BY a.`created_at` ASC
|
||||
LIMIT 1
|
||||
) AS `customerPhotoAttachmentId`,
|
||||
CAST(DATE_FORMAT(FROM_UNIXTIME(r.`registered_at` / 1000), '%Y%m%d') AS UNSIGNED) AS `dateValue`,
|
||||
COUNT(1) AS `dailyCount`,
|
||||
MAX(r.`registered_at`) AS `latestRegisteredAt`
|
||||
FROM `gao_registration_event_record` r
|
||||
LEFT JOIN `gao_customer` c ON r.`customer_id` = c.`id`
|
||||
WHERE
|
||||
r.`deleted_at` IS NULL
|
||||
AND c.`deleted_at` IS NULL
|
||||
<if test="req.beginRegisteredAt != null">
|
||||
AND r.`registered_at` >= #{req.beginRegisteredAt}
|
||||
</if>
|
||||
<if test="req.endRegisteredAt != null">
|
||||
AND r.`registered_at` <= #{req.endRegisteredAt}
|
||||
</if>
|
||||
<if test="req.registrationEventId != null and req.registrationEventId != ''">
|
||||
AND r.`registration_event_id` = #{req.registrationEventId}
|
||||
</if>
|
||||
<if test="req.registrationEventIdList != null and req.registrationEventIdList.size() > 0">
|
||||
AND r.`registration_event_id` IN
|
||||
<foreach collection="req.registrationEventIdList" item="registrationEventId" open="(" separator="," close=")">
|
||||
#{registrationEventId}
|
||||
</foreach>
|
||||
</if>
|
||||
GROUP BY
|
||||
r.`customer_id`,
|
||||
c.`code`,
|
||||
c.`name`,
|
||||
DATE_FORMAT(FROM_UNIXTIME(r.`registered_at` / 1000), '%Y%m%d')
|
||||
ORDER BY r.`customer_id` ASC, `dateValue` DESC
|
||||
</select>
|
||||
|
||||
<select id="statDailyCountByCustomerIdAndRegistrationEventIdRange" resultType="com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordDailyStatView">
|
||||
SELECT
|
||||
CAST(DATE_FORMAT(FROM_UNIXTIME(`registered_at` / 1000), '%Y%m%d') AS UNSIGNED) AS `dateValue`,
|
||||
COUNT(1) AS `dailyCount`
|
||||
FROM `gao_registration_event_record`
|
||||
WHERE
|
||||
`customer_id` = #{customerId}
|
||||
AND `registration_event_id` = #{registrationEventId}
|
||||
AND `registered_at` >= #{beginRegisteredAt}
|
||||
AND `registered_at` <= #{endRegisteredAt}
|
||||
AND `deleted_at` IS NULL
|
||||
GROUP BY DATE_FORMAT(FROM_UNIXTIME(`registered_at` / 1000), '%Y%m%d')
|
||||
ORDER BY `dateValue` ASC
|
||||
</select>
|
||||
|
||||
<select id="statDailyCountByRegistrationEventIdRange" resultType="com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordDailyStatView">
|
||||
SELECT
|
||||
CAST(DATE_FORMAT(FROM_UNIXTIME(`registered_at` / 1000), '%Y%m%d') AS UNSIGNED) AS `dateValue`,
|
||||
COUNT(1) AS `dailyCount`
|
||||
FROM `gao_registration_event_record`
|
||||
WHERE
|
||||
`registration_event_id` = #{registrationEventId}
|
||||
AND `registered_at` >= #{beginRegisteredAt}
|
||||
AND `registered_at` <= #{endRegisteredAt}
|
||||
AND `deleted_at` IS NULL
|
||||
GROUP BY DATE_FORMAT(FROM_UNIXTIME(`registered_at` / 1000), '%Y%m%d')
|
||||
ORDER BY `dateValue` ASC
|
||||
</select>
|
||||
|
||||
<select id="countBeforeByCustomerIdAndRegistrationEventId" resultType="java.lang.Long">
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM `gao_registration_event_record`
|
||||
WHERE
|
||||
`customer_id` = #{customerId}
|
||||
AND `registration_event_id` = #{registrationEventId}
|
||||
AND `registered_at` < #{beginRegisteredAt}
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
|
||||
<select id="countBeforeByRegistrationEventId" resultType="java.lang.Long">
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM `gao_registration_event_record`
|
||||
WHERE
|
||||
`registration_event_id` = #{registrationEventId}
|
||||
AND `registered_at` < #{beginRegisteredAt}
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
|
||||
<select id="selectLatestByCustomerIdListAndRegistrationEventId" resultType="com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRecord">
|
||||
SELECT
|
||||
r.*
|
||||
FROM `gao_registration_event_record` r
|
||||
WHERE
|
||||
r.`registration_event_id` = #{registrationEventId}
|
||||
AND r.`deleted_at` IS NULL
|
||||
AND r.`customer_id` IN
|
||||
<foreach collection="customerIdList" item="customerId" open="(" separator="," close=")">
|
||||
#{customerId}
|
||||
</foreach>
|
||||
AND NOT EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM `gao_registration_event_record` newer
|
||||
WHERE
|
||||
newer.`customer_id` = r.`customer_id`
|
||||
AND newer.`registration_event_id` = r.`registration_event_id`
|
||||
AND newer.`deleted_at` IS NULL
|
||||
AND (
|
||||
newer.`registered_at` > r.`registered_at`
|
||||
OR (newer.`registered_at` = r.`registered_at` AND newer.`created_at` > r.`created_at`)
|
||||
OR (newer.`registered_at` = r.`registered_at` AND newer.`created_at` = r.`created_at` AND newer.`id` > r.`id`)
|
||||
)
|
||||
)
|
||||
ORDER BY r.`registered_at` DESC, r.`created_at` DESC
|
||||
</select>
|
||||
|
||||
<select id="selectLatestByCustomerId" resultType="com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRecord">
|
||||
SELECT
|
||||
r.*
|
||||
FROM `gao_registration_event_record` r
|
||||
WHERE
|
||||
r.`customer_id` = #{customerId}
|
||||
AND r.`deleted_at` IS NULL
|
||||
AND NOT EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM `gao_registration_event_record` newer
|
||||
WHERE
|
||||
newer.`customer_id` = r.`customer_id`
|
||||
AND newer.`registration_event_id` = r.`registration_event_id`
|
||||
AND newer.`deleted_at` IS NULL
|
||||
AND (
|
||||
newer.`registered_at` > r.`registered_at`
|
||||
OR (newer.`registered_at` = r.`registered_at` AND newer.`created_at` > r.`created_at`)
|
||||
OR (newer.`registered_at` = r.`registered_at` AND newer.`created_at` = r.`created_at` AND newer.`id` > r.`id`)
|
||||
)
|
||||
)
|
||||
ORDER BY r.`registered_at` DESC, r.`created_at` DESC
|
||||
</select>
|
||||
|
||||
<sql id="rangeWhere">
|
||||
r.`registered_at` >= #{req.beginRegisteredAt}
|
||||
AND r.`registered_at` <= #{req.endRegisteredAt}
|
||||
AND r.`deleted_at` IS NULL
|
||||
<if test="req.customerId != null and req.customerId != ''">
|
||||
AND r.`customer_id` = #{req.customerId}
|
||||
</if>
|
||||
<if test="req.registrationEventId != null and req.registrationEventId != ''">
|
||||
AND r.`registration_event_id` = #{req.registrationEventId}
|
||||
</if>
|
||||
<if test="req.registrationEventIdList != null and req.registrationEventIdList.size() > 0">
|
||||
AND r.`registration_event_id` IN
|
||||
<foreach collection="req.registrationEventIdList" item="registrationEventId" open="(" separator="," close=")">
|
||||
#{registrationEventId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="req.keyword != null and req.keyword != ''">
|
||||
AND (
|
||||
c.`code` LIKE CONCAT('%', #{req.keyword}, '%')
|
||||
OR c.`name` LIKE CONCAT('%', #{req.keyword}, '%')
|
||||
OR e.`name` LIKE CONCAT('%', #{req.keyword}, '%')
|
||||
OR r.`remark` LIKE CONCAT('%', #{req.keyword}, '%')
|
||||
OR u.`name` LIKE CONCAT('%', #{req.keyword}, '%')
|
||||
OR u.`nick` LIKE CONCAT('%', #{req.keyword}, '%')
|
||||
OR r.`operator_user_id` LIKE CONCAT('%', #{req.keyword}, '%')
|
||||
)
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<sql id="rangeFrom">
|
||||
FROM `gao_registration_event_record` r
|
||||
LEFT JOIN `gao_customer` c ON r.`customer_id` = c.`id`
|
||||
LEFT JOIN `gao_registration_event` e ON r.`registration_event_id` = e.`id`
|
||||
LEFT JOIN `user` u ON r.`operator_user_id` = u.`id`
|
||||
</sql>
|
||||
|
||||
<select id="selectByRange" resultType="com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRecord">
|
||||
SELECT
|
||||
r.*
|
||||
<include refid="rangeFrom"/>
|
||||
WHERE
|
||||
<include refid="rangeWhere"/>
|
||||
ORDER BY r.`registered_at` DESC, r.`created_at` DESC
|
||||
</select>
|
||||
|
||||
<select id="selectCalendarByRange" resultType="com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordCalendarView">
|
||||
SELECT
|
||||
r.`id` AS `id`,
|
||||
r.`customer_id` AS `customerId`,
|
||||
c.`code` AS `customerCode`,
|
||||
c.`name` AS `customerName`,
|
||||
r.`registration_event_id` AS `registrationEventId`,
|
||||
r.`registered_at` AS `registeredAt`
|
||||
<include refid="rangeFrom"/>
|
||||
WHERE
|
||||
<include refid="rangeWhere"/>
|
||||
ORDER BY r.`registered_at` DESC, r.`created_at` DESC
|
||||
</select>
|
||||
|
||||
<select id="countByRange" resultType="java.lang.Long">
|
||||
SELECT
|
||||
COUNT(1)
|
||||
<include refid="rangeFrom"/>
|
||||
WHERE
|
||||
<include refid="rangeWhere"/>
|
||||
</select>
|
||||
|
||||
<select id="selectPageByRange" resultType="com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordListItemView">
|
||||
SELECT
|
||||
r.`id` AS `id`,
|
||||
r.`customer_id` AS `customerId`,
|
||||
c.`name` AS `customerName`,
|
||||
(
|
||||
SELECT a.`id`
|
||||
FROM `attachment` a
|
||||
WHERE
|
||||
a.`biz_type` = 'GAO_CUSTOMER'
|
||||
AND a.`biz_id` = c.`id`
|
||||
AND a.`attach_type` = 'PHOTO'
|
||||
AND a.`deleted_at` IS NULL
|
||||
AND (a.`destroy_at` IS NULL OR UNIX_TIMESTAMP() < a.`destroy_at`)
|
||||
ORDER BY a.`created_at` ASC
|
||||
LIMIT 1
|
||||
) AS `customerPhotoAttachmentId`,
|
||||
r.`registration_event_id` AS `registrationEventId`,
|
||||
e.`name` AS `registrationEventName`,
|
||||
r.`registered_at` AS `registeredAt`
|
||||
<include refid="rangeFrom"/>
|
||||
WHERE
|
||||
<include refid="rangeWhere"/>
|
||||
ORDER BY r.`registered_at` DESC, r.`created_at` DESC
|
||||
LIMIT #{offset}, #{size}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
FROM `user`
|
||||
WHERE
|
||||
1 = 1
|
||||
TRUE
|
||||
<if test="idList != null and !idList.isEmpty()">
|
||||
AND `id` IN
|
||||
<foreach collection="idList" item="item" separator="," open="(" close=")">
|
||||
@@ -14,7 +14,7 @@
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="idList == null or idList.isEmpty()">
|
||||
AND 1 = 0
|
||||
AND FALSE
|
||||
</if>
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
|
||||
Reference in New Issue
Block a user