refactor all

This commit is contained in:
Timi
2026-07-31 01:03:53 +08:00
parent 4e7f340cc6
commit e45809a0db
512 changed files with 14620 additions and 13519 deletions
@@ -0,0 +1,67 @@
<?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">
<select id="search" resultType="com.imyeyu.api.modules.gao.entity.GaoCustomer">
SELECT
*
FROM `gao_customer`
WHERE
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>
ORDER BY `created_at` DESC
</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>
<select id="statDailyNewCustomer" resultType="com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStatView">
SELECT
CAST(DATE_FORMAT(FROM_UNIXTIME(`created_at` / 1000), '%Y%m%d') AS UNSIGNED) AS `dateValue`,
COUNT(1) AS `newCustomerCount`
FROM `gao_customer`
WHERE
`created_at` >= #{beginCreatedAt}
AND `created_at` &lt;= #{endCreatedAt}
AND `deleted_at` IS NULL
GROUP BY DATE_FORMAT(FROM_UNIXTIME(`created_at` / 1000), '%Y%m%d')
ORDER BY `dateValue` ASC
</select>
<select id="countCreatedBefore" resultType="java.lang.Long">
SELECT
COUNT(1)
FROM `gao_customer`
WHERE
`created_at` &lt; #{beginCreatedAt}
AND `deleted_at` IS NULL
</select>
</mapper>
@@ -0,0 +1,233 @@
<?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="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` &lt;= #{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` &lt;= #{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` &lt;= #{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` &lt;= #{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` &lt; #{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` &lt; #{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>
<select id="selectByRange" resultType="com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRecord">
SELECT
*
FROM `gao_registration_event_record`
WHERE
`registered_at` &gt;= #{req.beginRegisteredAt}
AND `registered_at` &lt;= #{req.endRegisteredAt}
AND `deleted_at` IS NULL
<if test="req.customerId != null and req.customerId != ''">
AND `customer_id` = #{req.customerId}
</if>
<if test="req.registrationEventId != null and req.registrationEventId != ''">
AND `registration_event_id` = #{req.registrationEventId}
</if>
ORDER BY `registered_at` DESC, `created_at` DESC
</select>
</mapper>
@@ -0,0 +1,21 @@
<?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.common.mapper.MultilingualMapper">
<select id="selectByIdList" resultType="com.imyeyu.api.modules.common.entity.Multilingual">
SELECT
*
FROM `multilingual`
WHERE
1 = 1
<if test="idList != null and !idList.isEmpty()">
AND `id` IN
<foreach collection="idList" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="idList == null or idList.isEmpty()">
AND 1 = 0
</if>
AND `deleted_at` IS NULL
</select>
</mapper>
@@ -0,0 +1,49 @@
<?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.user.mapper.RoleMapper">
<select id="selectByIdList" resultType="com.imyeyu.api.modules.user.entity.Role">
SELECT
*
FROM `role`
WHERE
1 = 1
<if test="idList != null and !idList.isEmpty()">
AND `id` IN
<foreach collection="idList" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="idList == null or idList.isEmpty()">
AND 1 = 0
</if>
AND `deleted_at` IS NULL
</select>
<select id="selectByModuleCodeAndCodeList" resultType="com.imyeyu.api.modules.user.entity.Role">
SELECT
*
FROM `role`
WHERE
1 = 1
AND `module_code` = #{moduleCode}
<if test="codeList != null and !codeList.isEmpty()">
AND `code` IN
<foreach collection="codeList" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="codeList == null or codeList.isEmpty()">
AND 1 = 0
</if>
AND `deleted_at` IS NULL
</select>
<select id="selectByModuleCode" resultType="com.imyeyu.api.modules.user.entity.Role">
SELECT
*
FROM `role`
WHERE
`module_code` = #{moduleCode}
AND `deleted_at` IS NULL
ORDER BY `created_at` ASC
</select>
</mapper>
@@ -0,0 +1,51 @@
<?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.user.mapper.RolePermissionMapper">
<select id="selectByRoleIdList" resultType="com.imyeyu.api.modules.user.entity.RolePermission">
SELECT
*
FROM `role_permission`
WHERE
`role_permission`.`role_id` IN
<foreach collection="roleIdList" item="item" separator="," open="(" close=")">
#{item}
</foreach>
AND `role_permission`.`deleted_at` IS NULL
</select>
<select id="selectPermissionByRoleIdList" resultType="com.imyeyu.api.modules.user.entity.Permission">
SELECT
permission.*
FROM `role_permission`
LEFT JOIN `permission` ON permission.id = role_permission.permission_id
WHERE
`role_permission`.`role_id` IN
<foreach collection="roleIdList" item="item" separator="," open="(" close=")">
#{item}
</foreach>
AND `role_permission`.`deleted_at` IS NULL
AND `permission`.`deleted_at` IS NULL
ORDER BY
`permission`.code ASC
</select>
<insert id="createBatch">
INSERT INTO `role_permission` (
id,
role_id,
permission_id,
created_at
) VALUES
<foreach collection="rolePermissionList" item="item" separator=",">
(#{item.id}, #{item.roleId}, #{item.permissionId}, #{item.createdAt})
</foreach>
</insert>
<update id="deleteByPermissionIdList">
UPDATE `role_permission`
SET `deleted_at` = UNIX_TIMESTAMP()
WHERE
`role_id` = #{roleId}
AND `permission_id` IN
<foreach collection="permissionIdList" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</update>
</mapper>
@@ -0,0 +1,52 @@
<?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.user.mapper.RoleRelationMapper">
<select id="selectByParentRoleId" resultType="com.imyeyu.api.modules.user.entity.RoleRelation">
SELECT
*
FROM `role_relation`
WHERE
`parent_role_id` = #{parentRoleId}
AND `deleted_at` IS NULL
</select>
<select id="selectChildRoleIdListByParentRoleId" resultType="java.lang.String">
SELECT
`child_role_id`
FROM `role_relation`
WHERE
`parent_role_id` = #{parentRoleId}
AND `deleted_at` IS NULL
</select>
<select id="selectChildRoleIdListByParentRoleIdList" resultType="java.lang.String">
SELECT
`child_role_id`
FROM `role_relation`
WHERE
`parent_role_id` IN
<foreach collection="parentRoleIdList" item="item" separator="," open="(" close=")">
#{item}
</foreach>
AND `deleted_at` IS NULL
</select>
<insert id="createBatch">
INSERT INTO `role_relation` (
id,
parent_role_id,
child_role_id,
created_at
) VALUES
<foreach collection="roleRelationList" item="item" separator=",">
(#{item.id}, #{item.parentRoleId}, #{item.childRoleId}, #{item.createdAt})
</foreach>
</insert>
<update id="deleteByChildRoleIdList">
UPDATE `role_relation`
SET `deleted_at` = UNIX_TIMESTAMP()
WHERE
`parent_role_id` = #{parentRoleId}
AND `child_role_id` IN
<foreach collection="childRoleIdList" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</update>
</mapper>
@@ -0,0 +1,21 @@
<?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.user.mapper.UserMapper">
<select id="listByIdList" resultType="com.imyeyu.api.modules.user.entity.User">
SELECT
*
FROM `user`
WHERE
1 = 1
<if test="idList != null and !idList.isEmpty()">
AND `id` IN
<foreach collection="idList" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="idList == null or idList.isEmpty()">
AND 1 = 0
</if>
AND `deleted_at` IS NULL
</select>
</mapper>
@@ -0,0 +1,25 @@
<?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.user.mapper.UserRoleMapper">
<insert id="createBatch">
INSERT INTO `user_role` (
id,
user_id,
role_id,
created_at
) VALUES
<foreach collection="userRoleList" item="item" separator=",">
(#{item.id}, #{item.userId}, #{item.roleId}, #{item.createdAt})
</foreach>
</insert>
<update id="deleteByRoleIdList">
UPDATE `user_role`
SET `deleted_at` = UNIX_TIMESTAMP()
WHERE
`user_id` = #{userId}
AND `role_id` IN
<foreach collection="roleIdList" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</update>
</mapper>