333 lines
12 KiB
XML
333 lines
12 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.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="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="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>
|