Compare commits
47
Commits
v1.0.3
..
8db6f962c9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8db6f962c9 | ||
|
|
e35cf3aa59 | ||
|
|
457e716b38 | ||
|
|
ab4a164680 | ||
|
|
9dfca25f8c | ||
|
|
e369a38e2e | ||
|
|
f1e10df6a7 | ||
|
|
36e2a37af2 | ||
|
|
348f7396a1 | ||
|
|
c0b04fc554 | ||
|
|
5e5748b521 | ||
|
|
67d79f7527 | ||
|
|
ee530d2a8c | ||
|
|
5f36844279 | ||
|
|
5b9391a50a | ||
|
|
6bc73414d9 | ||
|
|
d555aad9ac | ||
|
|
2f42204794 | ||
|
|
72bdb8d49b | ||
|
|
5ec6bc472f | ||
|
|
81b7356d67 | ||
|
|
44af16f451 | ||
|
|
c6157db0de | ||
|
|
39ac73dc66 | ||
|
|
6e43ff349d | ||
|
|
ab79391cdc | ||
|
|
67bc9382c5 | ||
|
|
7e40e0202e | ||
|
|
7ffdd715ee | ||
|
|
1709316ce1 | ||
|
|
568563475e | ||
|
|
8a92e46eb1 | ||
|
|
1875cec8a5 | ||
|
|
4c162dad34 | ||
|
|
c49686c411 | ||
|
|
65161a7fad | ||
|
|
187f270866 | ||
|
|
50d4bba045 | ||
|
|
6eedc06a07 | ||
|
|
b55b43eba4 | ||
|
|
20289a3168 | ||
|
|
d45bf11477 | ||
|
|
7370b2fc98 | ||
|
|
2f366fe219 | ||
|
|
f1715a3e32 | ||
|
|
833a303bb6 | ||
|
|
1658be7d8d |
Generated
-7
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="DataSourcePerFileMappings">
|
|
||||||
<file url="file://$PROJECT_DIR$/src/main/java/com/imyeyu/api/modules/user/mapper/UserMapper.java" value="05742bdc-a11a-4147-9168-ef976a70258a" />
|
|
||||||
<file url="file://$PROJECT_DIR$/src/main/resources/mapper/timi-server/GaoCustomerMapper.xml" value="05742bdc-a11a-4147-9168-ef976a70258a" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
Generated
+1
@@ -3,6 +3,7 @@
|
|||||||
<component name="SqlDialectMappings">
|
<component name="SqlDialectMappings">
|
||||||
<file url="file://$PROJECT_DIR$/src/main/resources/db/migration/timiserver/V1__init_schema.sql" dialect="MariaDB" />
|
<file url="file://$PROJECT_DIR$/src/main/resources/db/migration/timiserver/V1__init_schema.sql" dialect="MariaDB" />
|
||||||
<file url="file://$PROJECT_DIR$/src/main/resources/db/migration/timiserver/V2__init_system_data.sql" dialect="GenericSQL" />
|
<file url="file://$PROJECT_DIR$/src/main/resources/db/migration/timiserver/V2__init_system_data.sql" dialect="GenericSQL" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources/mapper/timi-server/gao/GaoEventRecordMapper.xml" dialect="MariaDB" />
|
||||||
<file url="PROJECT" dialect="MariaDB" />
|
<file url="PROJECT" dialect="MariaDB" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<groupId>com.imyeyu.timiserverapi</groupId>
|
<groupId>com.imyeyu.timiserverapi</groupId>
|
||||||
<artifactId>TimiServerAPI</artifactId>
|
<artifactId>TimiServerAPI</artifactId>
|
||||||
<version>1.0.3</version>
|
<version>1.0.14</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>TimiServerAPI</name>
|
<name>TimiServerAPI</name>
|
||||||
<description>imyeyu.com API</description>
|
<description>imyeyu.com API</description>
|
||||||
@@ -173,12 +173,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.spring</groupId>
|
<groupId>com.imyeyu.spring</groupId>
|
||||||
<artifactId>timi-spring</artifactId>
|
<artifactId>timi-spring</artifactId>
|
||||||
<version>0.0.17</version>
|
<version>0.0.19</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.network</groupId>
|
<groupId>com.imyeyu.network</groupId>
|
||||||
<artifactId>timi-network</artifactId>
|
<artifactId>timi-network</artifactId>
|
||||||
<version>0.0.13</version>
|
<version>0.0.14</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.lang</groupId>
|
<groupId>com.imyeyu.lang</groupId>
|
||||||
@@ -188,12 +188,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.java</groupId>
|
<groupId>com.imyeyu.java</groupId>
|
||||||
<artifactId>timi-java</artifactId>
|
<artifactId>timi-java</artifactId>
|
||||||
<version>0.0.6</version>
|
<version>0.0.7</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.utils</groupId>
|
<groupId>com.imyeyu.utils</groupId>
|
||||||
<artifactId>timi-utils</artifactId>
|
<artifactId>timi-utils</artifactId>
|
||||||
<version>0.0.12</version>
|
<version>0.0.13</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.font.icon</groupId>
|
<groupId>com.imyeyu.font.icon</groupId>
|
||||||
@@ -230,6 +230,10 @@
|
|||||||
<artifactId>spring-boot-starter-freemarker</artifactId>
|
<artifactId>spring-boot-starter-freemarker</artifactId>
|
||||||
<version>${springboot.version}</version>
|
<version>${springboot.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
package com.imyeyu.api.annotation;
|
|
||||||
|
|
||||||
import com.imyeyu.api.bean.RoleMatchMode;
|
|
||||||
import com.imyeyu.api.bean.CoreRoleCode;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 要求 CORE 模块角色
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-26
|
|
||||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface RequireCoreRole {
|
|
||||||
|
|
||||||
/// 所需角色
|
|
||||||
///
|
|
||||||
/// @return 角色列表
|
|
||||||
CoreRoleCode[] value();
|
|
||||||
|
|
||||||
/// 匹配模式
|
|
||||||
///
|
|
||||||
/// @return 匹配模式
|
|
||||||
RoleMatchMode mode() default RoleMatchMode.ALL;
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package com.imyeyu.api.annotation;
|
|
||||||
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
|
||||||
import com.imyeyu.api.bean.RoleMatchMode;
|
|
||||||
import com.imyeyu.api.bean.CoreRoleCode;
|
|
||||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
|
||||||
import com.imyeyu.java.TimiJava;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import org.springframework.lang.NonNull;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.method.HandlerMethod;
|
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// CORE 角色注解处理器
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-27
|
|
||||||
@Component
|
|
||||||
public class RequireCoreRoleInterceptor implements HandlerInterceptor {
|
|
||||||
|
|
||||||
private final RoleChecker roleChecker;
|
|
||||||
|
|
||||||
public RequireCoreRoleInterceptor(RoleChecker roleChecker) {
|
|
||||||
this.roleChecker = roleChecker;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean preHandle(@NonNull HttpServletRequest req, @NonNull HttpServletResponse resp, @NonNull Object handler) {
|
|
||||||
if (!(handler instanceof HandlerMethod handlerMethod)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
RequireCoreRole annotation = handlerMethod.getMethodAnnotation(RequireCoreRole.class);
|
|
||||||
if (annotation == null || TimiJava.isEmpty(annotation.value())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
String[] roleCodeList = java.util.Arrays.stream(annotation.value()).map(CoreRoleCode::name).toArray(String[]::new);
|
|
||||||
if (annotation.mode() == RoleMatchMode.ANY) {
|
|
||||||
roleChecker.checkAny(ModuleCode.CORE, roleCodeList);
|
|
||||||
} else {
|
|
||||||
roleChecker.checkAll(ModuleCode.CORE, roleCodeList);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,9 +25,9 @@ public enum CorePermissionCode implements BuiltinPermissionCode {
|
|||||||
ROLE_PERMISSION_READ("ROLE_PERMISSION:READ", "角色权限读取", false, true),
|
ROLE_PERMISSION_READ("ROLE_PERMISSION:READ", "角色权限读取", false, true),
|
||||||
ROLE_PERMISSION_DELETE("ROLE_PERMISSION:DELETE", "角色权限删除", false, true),
|
ROLE_PERMISSION_DELETE("ROLE_PERMISSION:DELETE", "角色权限删除", false, true),
|
||||||
|
|
||||||
ROLE_RELATION_CREATE("ROLE_RELATION:CREATE", "角色关联创建", false, true),
|
ROLE_PERMISSION_INHERIT_CREATE("ROLE_PERMISSION_INHERIT:CREATE", "角色权限继承创建", false, true),
|
||||||
ROLE_RELATION_READ("ROLE_RELATION:READ", "角色关联读取", false, true),
|
ROLE_PERMISSION_INHERIT_READ("ROLE_PERMISSION_INHERIT:READ", "角色权限继承读取", false, true),
|
||||||
ROLE_RELATION_DELETE("ROLE_RELATION:DELETE", "角色关联删除", false, true),
|
ROLE_PERMISSION_INHERIT_DELETE("ROLE_PERMISSION_INHERIT:DELETE", "角色权限继承删除", false, true),
|
||||||
|
|
||||||
SETTING_CREATE("SETTING:CREATE", "设置创建", false, true),
|
SETTING_CREATE("SETTING:CREATE", "设置创建", false, true),
|
||||||
SETTING_READ("SETTING:READ", "设置读取", false, true),
|
SETTING_READ("SETTING:READ", "设置读取", false, true),
|
||||||
@@ -39,6 +39,12 @@ public enum CorePermissionCode implements BuiltinPermissionCode {
|
|||||||
MULTILINGUAL_UPDATE("MULTILINGUAL:UPDATE", "多语言修改", false, true),
|
MULTILINGUAL_UPDATE("MULTILINGUAL:UPDATE", "多语言修改", false, true),
|
||||||
MULTILINGUAL_DELETE("MULTILINGUAL:DELETE", "多语言删除", false, true),
|
MULTILINGUAL_DELETE("MULTILINGUAL:DELETE", "多语言删除", false, true),
|
||||||
|
|
||||||
|
TAG_CREATE("TAG:CREATE", "标签创建", false, true),
|
||||||
|
TAG_READ("TAG:READ", "标签读取", false, true),
|
||||||
|
TAG_APPLY("TAG:APPLY", "标签应用", false, true),
|
||||||
|
TAG_UPDATE("TAG:UPDATE", "标签修改", false, true),
|
||||||
|
TAG_DELETE("TAG:DELETE", "标签删除", false, true),
|
||||||
|
|
||||||
USER_CREATE("USER:CREATE", "用户创建", false, true),
|
USER_CREATE("USER:CREATE", "用户创建", false, true),
|
||||||
USER_READ("USER:READ", "用户读取", false, true),
|
USER_READ("USER:READ", "用户读取", false, true),
|
||||||
USER_UPDATE("USER:UPDATE", "用户修改", false, true),
|
USER_UPDATE("USER:UPDATE", "用户修改", false, true),
|
||||||
|
|||||||
@@ -13,9 +13,7 @@ public enum CoreRoleCode implements BuiltinRoleCode {
|
|||||||
|
|
||||||
SYSTEM("系统", true, null),
|
SYSTEM("系统", true, null),
|
||||||
|
|
||||||
ADMIN("管理员", false, SYSTEM.name()),
|
ADMIN("管理员", false, SYSTEM.name());
|
||||||
|
|
||||||
USER_ROLE_ADMIN("授权管理", false, ADMIN.name());
|
|
||||||
|
|
||||||
final String defaultName;
|
final String defaultName;
|
||||||
final boolean protectedRole;
|
final boolean protectedRole;
|
||||||
@@ -40,4 +38,5 @@ public enum CoreRoleCode implements BuiltinRoleCode {
|
|||||||
public String getParentCode() {
|
public String getParentCode() {
|
||||||
return parentCode;
|
return parentCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import com.imyeyu.utils.Time;
|
import com.imyeyu.utils.Time;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -22,6 +23,7 @@ public class BeanConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public ObjectMapper jackson() {
|
public ObjectMapper jackson() {
|
||||||
return JsonMapper.builder()
|
return JsonMapper.builder()
|
||||||
|
.addModule(new JavaTimeModule())
|
||||||
.serializationInclusion(JsonInclude.Include.NON_NULL)
|
.serializationInclusion(JsonInclude.Include.NON_NULL)
|
||||||
.defaultDateFormat(Time.dateTime)
|
.defaultDateFormat(Time.dateTime)
|
||||||
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
|
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.imyeyu.api.config;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.imyeyu.api.modules.common.entity.Multilingual;
|
import com.imyeyu.api.modules.common.entity.Multilingual;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoUserInviteCache;
|
||||||
import com.imyeyu.spring.bean.RedisConfigParams;
|
import com.imyeyu.spring.bean.RedisConfigParams;
|
||||||
import com.imyeyu.spring.config.AbstractRedisConfig;
|
import com.imyeyu.spring.config.AbstractRedisConfig;
|
||||||
import com.imyeyu.spring.util.Redis;
|
import com.imyeyu.spring.util.Redis;
|
||||||
@@ -202,4 +203,10 @@ public class RedisConfig extends AbstractRedisConfig {
|
|||||||
public Redis<String, String> getClipboardRedisTemplate() {
|
public Redis<String, String> getClipboardRedisTemplate() {
|
||||||
return getRedis(database, RedisSerializers.STRING, RedisSerializers.STRING);
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @return GAO 用户邀请,code: 邀请缓存
|
||||||
|
@Bean("redisGaoUserInvite")
|
||||||
|
public Redis<String, GaoUserInviteCache> getGaoUserInviteRedisTemplate() {
|
||||||
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.jacksonSerializer(jackson, GaoUserInviteCache.class));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,11 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
|
|||||||
import com.fasterxml.jackson.databind.MapperFeature;
|
import com.fasterxml.jackson.databind.MapperFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import com.imyeyu.api.annotation.EnableSettingInterceptor;
|
import com.imyeyu.api.annotation.EnableSettingInterceptor;
|
||||||
import com.imyeyu.api.annotation.RequestRateLimitInterceptor;
|
import com.imyeyu.api.annotation.RequestRateLimitInterceptor;
|
||||||
import com.imyeyu.api.annotation.RequireCorePermissionInterceptor;
|
import com.imyeyu.api.annotation.RequireCorePermissionInterceptor;
|
||||||
import com.imyeyu.api.annotation.RequireCoreRoleInterceptor;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermissionInterceptor;
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermissionInterceptor;
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoRoleInterceptor;
|
|
||||||
import com.imyeyu.api.modules.journal.util.JournalAPIInterceptor;
|
import com.imyeyu.api.modules.journal.util.JournalAPIInterceptor;
|
||||||
import com.imyeyu.api.modules.system.util.SystemAPIInterceptor;
|
import com.imyeyu.api.modules.system.util.SystemAPIInterceptor;
|
||||||
import com.imyeyu.spring.annotation.RequestBodyValueArgumentResolver;
|
import com.imyeyu.spring.annotation.RequestBodyValueArgumentResolver;
|
||||||
@@ -42,8 +41,6 @@ public class WebConfig implements WebMvcConfigurer {
|
|||||||
private final SystemAPIInterceptor systemAPIInterceptor;
|
private final SystemAPIInterceptor systemAPIInterceptor;
|
||||||
private final JournalAPIInterceptor journalAPIInterceptor;
|
private final JournalAPIInterceptor journalAPIInterceptor;
|
||||||
private final EnableSettingInterceptor enableSettingInterceptor;
|
private final EnableSettingInterceptor enableSettingInterceptor;
|
||||||
private final RequireGaoRoleInterceptor requireGaoRoleInterceptor;
|
|
||||||
private final RequireCoreRoleInterceptor requireCoreRoleInterceptor;
|
|
||||||
private final RequestRateLimitInterceptor requestRateLimitInterceptor;
|
private final RequestRateLimitInterceptor requestRateLimitInterceptor;
|
||||||
private final RequireGaoPermissionInterceptor requireGaoPermissionInterceptor;
|
private final RequireGaoPermissionInterceptor requireGaoPermissionInterceptor;
|
||||||
private final RequireCorePermissionInterceptor requireCorePermissionInterceptor;
|
private final RequireCorePermissionInterceptor requireCorePermissionInterceptor;
|
||||||
@@ -58,9 +55,7 @@ public class WebConfig implements WebMvcConfigurer {
|
|||||||
registry.addInterceptor(systemAPIInterceptor).addPathPatterns(SystemAPIInterceptor.PATH);
|
registry.addInterceptor(systemAPIInterceptor).addPathPatterns(SystemAPIInterceptor.PATH);
|
||||||
registry.addInterceptor(journalAPIInterceptor).addPathPatterns(JournalAPIInterceptor.PATH);
|
registry.addInterceptor(journalAPIInterceptor).addPathPatterns(JournalAPIInterceptor.PATH);
|
||||||
registry.addInterceptor(enableSettingInterceptor).addPathPatterns("/**");
|
registry.addInterceptor(enableSettingInterceptor).addPathPatterns("/**");
|
||||||
registry.addInterceptor(requireCoreRoleInterceptor).addPathPatterns("/**");
|
|
||||||
registry.addInterceptor(requireCorePermissionInterceptor).addPathPatterns("/**");
|
registry.addInterceptor(requireCorePermissionInterceptor).addPathPatterns("/**");
|
||||||
registry.addInterceptor(requireGaoRoleInterceptor).addPathPatterns("/**");
|
|
||||||
registry.addInterceptor(requireGaoPermissionInterceptor).addPathPatterns("/**");
|
registry.addInterceptor(requireGaoPermissionInterceptor).addPathPatterns("/**");
|
||||||
registry.addInterceptor(requestRateLimitInterceptor).addPathPatterns("/**");
|
registry.addInterceptor(requestRateLimitInterceptor).addPathPatterns("/**");
|
||||||
}
|
}
|
||||||
@@ -78,6 +73,7 @@ public class WebConfig implements WebMvcConfigurer {
|
|||||||
@Override
|
@Override
|
||||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||||
JsonMapper jsonMapper = JsonMapper.builder()
|
JsonMapper jsonMapper = JsonMapper.builder()
|
||||||
|
.addModule(new JavaTimeModule())
|
||||||
// 设置默认属性包含规则:忽略 null 值
|
// 设置默认属性包含规则:忽略 null 值
|
||||||
.serializationInclusion(JsonInclude.Include.NON_NULL)
|
.serializationInclusion(JsonInclude.Include.NON_NULL)
|
||||||
// 日期格式化
|
// 日期格式化
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ public enum SettingModule {
|
|||||||
|
|
||||||
TEMP_FILE(Setting.Module.TempFile.class),
|
TEMP_FILE(Setting.Module.TempFile.class),
|
||||||
|
|
||||||
|
USER(Setting.Module.User.class),
|
||||||
|
|
||||||
SYSTEM(Setting.Module.System.class),
|
SYSTEM(Setting.Module.System.class),
|
||||||
|
|
||||||
SYSTEM_STATUS(Setting.Module.SystemStatus.class);
|
SYSTEM_STATUS(Setting.Module.SystemStatus.class);
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ package com.imyeyu.api.modules.common.controller;
|
|||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
import com.imyeyu.api.modules.common.service.TempFileService;
|
import com.imyeyu.api.modules.common.service.TempFileService;
|
||||||
import com.imyeyu.api.modules.common.vo.attach.BizDeleteReq;
|
|
||||||
import com.imyeyu.api.modules.common.vo.attach.BizUpdateReq;
|
|
||||||
import com.imyeyu.api.modules.common.vo.attach.TempFileResp;
|
import com.imyeyu.api.modules.common.vo.attach.TempFileResp;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.network.Network;
|
import com.imyeyu.network.Network;
|
||||||
@@ -183,32 +181,7 @@ public class AttachmentController {
|
|||||||
return service.pageByBizId(bizType, bizId, attachTypeList, page);
|
return service.pageByBizId(bizType, bizId, attachTypeList, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 按业务差分更新附件
|
|
||||||
*
|
|
||||||
* @param req 更新请求
|
|
||||||
*/
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
|
||||||
@PostMapping("/update/biz")
|
|
||||||
public void updateByBiz(@RequestBody BizUpdateReq req) {
|
|
||||||
service.updateByBiz(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 按业务删除全部附件
|
|
||||||
*
|
|
||||||
* @param req 删除请求
|
|
||||||
*/
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@PostMapping("/delete/biz")
|
|
||||||
public void deleteByBiz(@RequestBody BizDeleteReq req) {
|
|
||||||
service.deleteByBiz(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@IgnoreGlobalReturn
|
@IgnoreGlobalReturn
|
||||||
@GetMapping({"/read/{id}", "/download/{id}"})
|
@GetMapping({"/read/{id}", "/download/{id}"})
|
||||||
public void readById(@PathVariable String id, @RequestParam(required = false) Integer thumbWidth, @RequestParam(required = false) Integer thumbHeight) throws UnsupportedEncodingException {
|
public void readById(@PathVariable String id, @RequestParam(required = false) Integer thumbWidth, @RequestParam(required = false) Integer thumbHeight) throws UnsupportedEncodingException {
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ package com.imyeyu.api.modules.common.controller;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonView;
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
import com.imyeyu.api.annotation.RequireCorePermission;
|
import com.imyeyu.api.annotation.RequireCorePermission;
|
||||||
import com.imyeyu.api.annotation.RequireCoreRole;
|
|
||||||
import com.imyeyu.api.bean.CorePermissionCode;
|
import com.imyeyu.api.bean.CorePermissionCode;
|
||||||
import com.imyeyu.api.bean.CoreRoleCode;
|
|
||||||
import com.imyeyu.api.modules.common.entity.Multilingual;
|
import com.imyeyu.api.modules.common.entity.Multilingual;
|
||||||
import com.imyeyu.api.modules.common.service.MultilingualService;
|
import com.imyeyu.api.modules.common.service.MultilingualService;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
@@ -40,7 +38,6 @@ public class MultilingualController {
|
|||||||
*/
|
*/
|
||||||
@JsonView(ResponseView.Admin.class)
|
@JsonView(ResponseView.Admin.class)
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireCoreRole(CoreRoleCode.ADMIN)
|
|
||||||
@RequireCorePermission(CorePermissionCode.MULTILINGUAL_READ)
|
@RequireCorePermission(CorePermissionCode.MULTILINGUAL_READ)
|
||||||
@PostMapping("/detail")
|
@PostMapping("/detail")
|
||||||
public Multilingual detail(@RequestParam String id) {
|
public Multilingual detail(@RequestParam String id) {
|
||||||
@@ -56,7 +53,6 @@ public class MultilingualController {
|
|||||||
@AOPLog
|
@AOPLog
|
||||||
@JsonView(ResponseView.Admin.class)
|
@JsonView(ResponseView.Admin.class)
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireCoreRole(CoreRoleCode.ADMIN)
|
|
||||||
@RequireCorePermission(CorePermissionCode.MULTILINGUAL_CREATE)
|
@RequireCorePermission(CorePermissionCode.MULTILINGUAL_CREATE)
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public Multilingual create(@RequestBody Multilingual multilingual) {
|
public Multilingual create(@RequestBody Multilingual multilingual) {
|
||||||
@@ -71,7 +67,6 @@ public class MultilingualController {
|
|||||||
*/
|
*/
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireCoreRole(CoreRoleCode.ADMIN)
|
|
||||||
@RequireCorePermission(CorePermissionCode.MULTILINGUAL_UPDATE)
|
@RequireCorePermission(CorePermissionCode.MULTILINGUAL_UPDATE)
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
public void update(@RequestBody Multilingual multilingual) {
|
public void update(@RequestBody Multilingual multilingual) {
|
||||||
@@ -85,7 +80,6 @@ public class MultilingualController {
|
|||||||
*/
|
*/
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireCoreRole(CoreRoleCode.ADMIN)
|
|
||||||
@RequireCorePermission(CorePermissionCode.MULTILINGUAL_DELETE)
|
@RequireCorePermission(CorePermissionCode.MULTILINGUAL_DELETE)
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
public void delete(@RequestParam String id) {
|
public void delete(@RequestParam String id) {
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package com.imyeyu.api.modules.common.controller;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Tag;
|
||||||
|
import com.imyeyu.api.modules.common.entity.TagApply;
|
||||||
|
import com.imyeyu.api.modules.common.service.TagService;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import com.imyeyu.spring.util.ResponseView;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// 标签接口
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-12 15:09
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/tag")
|
||||||
|
public class TagController {
|
||||||
|
|
||||||
|
private final TagService service;
|
||||||
|
|
||||||
|
/// 查询标签列表
|
||||||
|
///
|
||||||
|
/// @param page 分页参数
|
||||||
|
/// @return 标签分页
|
||||||
|
@RequestRateLimit
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@PostMapping("/list")
|
||||||
|
public PageResult<Tag> list(@RequestBody Page<Tag> page) {
|
||||||
|
return service.page(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询标签详情
|
||||||
|
///
|
||||||
|
/// @param id 标签 ID
|
||||||
|
/// @return 标签详情
|
||||||
|
@RequestRateLimit
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
public Tag detail(@RequestParam String id) {
|
||||||
|
return service.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 创建标签
|
||||||
|
///
|
||||||
|
/// @param tag 标签
|
||||||
|
/// @return 标签
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@PostMapping("/create")
|
||||||
|
public Tag create(@RequestBody Tag tag) {
|
||||||
|
service.create(tag);
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 更新标签
|
||||||
|
///
|
||||||
|
/// @param tag 标签
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@PostMapping("/update")
|
||||||
|
public void update(@RequestBody Tag tag) {
|
||||||
|
service.update(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 删除标签
|
||||||
|
///
|
||||||
|
/// @param id 标签 ID
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public void delete(@RequestParam String id) {
|
||||||
|
service.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 按业务查询标签
|
||||||
|
///
|
||||||
|
/// @param bizType 业务类型
|
||||||
|
/// @param bizId 业务 ID
|
||||||
|
/// @return 标签列表
|
||||||
|
@RequestRateLimit
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@GetMapping("/list/biz/id")
|
||||||
|
public List<Tag> listByBizType(@RequestParam TagApply.BizType bizType, @RequestParam String bizId) {
|
||||||
|
return service.listByBizType(bizType, bizId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 差分保存业务标签
|
||||||
|
///
|
||||||
|
/// @param apply 标签请求
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@PostMapping("/apply")
|
||||||
|
public void apply(@RequestBody TagApply apply) {
|
||||||
|
service.apply(apply.getBizType(), apply.getBizId(), apply.getTagIdList());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
package com.imyeyu.api.modules.common.entity;
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import com.imyeyu.api.TimiServerAPI;
|
import com.imyeyu.api.TimiServerAPI;
|
||||||
import com.imyeyu.api.modules.common.bean.attachment.AccessKey;
|
import com.imyeyu.api.modules.common.bean.attachment.AccessKey;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.java.ref.Ref;
|
import com.imyeyu.java.ref.Ref;
|
||||||
import com.imyeyu.spring.TimiSpring;
|
import com.imyeyu.spring.TimiSpring;
|
||||||
import com.imyeyu.spring.annotation.table.Transient;
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
@@ -33,7 +34,7 @@ public class Attachment extends UUIDEntity {
|
|||||||
|
|
||||||
GAO_CUSTOMER,
|
GAO_CUSTOMER,
|
||||||
|
|
||||||
GAO_REGISTRATION_EVENT_RECORD,
|
GAO_EVENT_RECORD,
|
||||||
|
|
||||||
TEMP_FILE,
|
TEMP_FILE,
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ public class Attachment extends UUIDEntity {
|
|||||||
|
|
||||||
protected String mimeType;
|
protected String mimeType;
|
||||||
|
|
||||||
protected JsonNode metadata;
|
protected ObjectNode metadata;
|
||||||
|
|
||||||
protected Long size;
|
protected Long size;
|
||||||
|
|
||||||
@@ -82,6 +83,14 @@ public class Attachment extends UUIDEntity {
|
|||||||
@Transient
|
@Transient
|
||||||
protected MultipartFile file;
|
protected MultipartFile file;
|
||||||
|
|
||||||
|
public String buildMongoName() {
|
||||||
|
StringBuilder result = new StringBuilder(bizType.name());
|
||||||
|
if (TimiJava.isNotEmpty(attachType)) {
|
||||||
|
result.append('_').append(attachType.toUpperCase());
|
||||||
|
}
|
||||||
|
return result.append('_').append(name).toString();
|
||||||
|
}
|
||||||
|
|
||||||
public InputStream openInputStream() {
|
public InputStream openInputStream() {
|
||||||
AttachmentService service = TimiServerAPI.applicationContext.getBean(AttachmentService.class);
|
AttachmentService service = TimiServerAPI.applicationContext.getBean(AttachmentService.class);
|
||||||
return service.getInputStreamByMongoId(mongoId);
|
return service.getInputStreamByMongoId(mongoId);
|
||||||
|
|||||||
@@ -1,23 +1,43 @@
|
|||||||
package com.imyeyu.api.modules.common.entity;
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
|
import com.imyeyu.api.annotation.MultilingualField;
|
||||||
import com.imyeyu.spring.annotation.table.Transient;
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
/**
|
/// 标签
|
||||||
* @author 夜雨
|
///
|
||||||
* @since 2024-08-28 14:26
|
/// @author 夜雨
|
||||||
*/
|
/// @since 2024-08-28 14:26
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class Tag extends UUIDEntity {
|
public class Tag extends UUIDEntity {
|
||||||
|
|
||||||
protected String langKey;
|
///
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-12 16:49
|
||||||
|
public enum OwnerType {
|
||||||
|
|
||||||
|
GAO_STORE
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 归属类型
|
||||||
|
protected OwnerType ownerType;
|
||||||
|
|
||||||
|
/// 归属 ID
|
||||||
|
protected String ownerId;
|
||||||
|
|
||||||
|
/// 名称多语言 ID
|
||||||
|
protected String nameLangId;
|
||||||
|
|
||||||
|
/// 当前语言名称
|
||||||
@Transient
|
@Transient
|
||||||
protected String value;
|
@MultilingualField("nameLangId")
|
||||||
|
protected String name;
|
||||||
|
|
||||||
|
/// 中文名称
|
||||||
@Transient
|
@Transient
|
||||||
protected String zhCN;
|
protected String zhCN;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package com.imyeyu.api.modules.common.entity;
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标签应用
|
* 标签应用
|
||||||
*
|
*
|
||||||
@@ -14,12 +17,25 @@ import lombok.EqualsAndHashCode;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class TagApply extends UUIDEntity {
|
public class TagApply extends UUIDEntity {
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-12 14:27
|
||||||
|
public enum BizType {
|
||||||
|
|
||||||
|
GAO_CUSTOMER
|
||||||
|
}
|
||||||
|
|
||||||
/** 业务类型 */
|
/** 业务类型 */
|
||||||
protected String bizType;
|
protected BizType bizType;
|
||||||
|
|
||||||
/** 业务 ID */
|
/** 业务 ID */
|
||||||
protected String bizId;
|
protected String bizId;
|
||||||
|
|
||||||
/** 标签 ID */
|
/** 标签 ID */
|
||||||
protected String tagId;
|
protected String tagId;
|
||||||
|
|
||||||
|
/// 标签 ID 列表
|
||||||
|
@Transient
|
||||||
|
private List<String> tagIdList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.imyeyu.spring.mapper.BaseMapper;
|
|||||||
import com.imyeyu.spring.mapper.RawMapper;
|
import com.imyeyu.spring.mapper.RawMapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +32,8 @@ public interface AttachmentMapper extends BaseMapper<Attachment, String>, RawMap
|
|||||||
|
|
||||||
List<Attachment> selectByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes, Page<Attachment> page);
|
List<Attachment> selectByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes, Page<Attachment> page);
|
||||||
|
|
||||||
|
List<Attachment> selectByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, List<String> attachTypes);
|
||||||
|
|
||||||
long countByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes);
|
long countByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.imyeyu.api.modules.common.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.TagApply;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/// 标签应用 Mapper
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-12 15:05
|
||||||
|
public interface TagApplyMapper extends BaseMapper<TagApply, String> {
|
||||||
|
}
|
||||||
@@ -2,10 +2,18 @@ package com.imyeyu.api.modules.common.mapper;
|
|||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Tag;
|
import com.imyeyu.api.modules.common.entity.Tag;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 夜雨
|
* @author 夜雨
|
||||||
* @since 2025-05-30 22:48
|
* @since 2025-05-30 22:48
|
||||||
*/
|
*/
|
||||||
public interface TagMapper extends BaseMapper<Tag, String> {
|
public interface TagMapper extends BaseMapper<Tag, String> {
|
||||||
|
|
||||||
|
List<Tag> selectByIdList(Collection<String> idList);
|
||||||
|
|
||||||
|
Tag selectByOwnerAndZhCN(@Param("ownerType") Tag.OwnerType ownerType, @Param("ownerId") String ownerId, @Param("zhCN") String zhCN);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package com.imyeyu.api.modules.common.service;
|
package com.imyeyu.api.modules.common.service;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.vo.attach.BizDeleteReq;
|
|
||||||
import com.imyeyu.api.modules.common.vo.attach.BizUpdateReq;
|
|
||||||
import com.imyeyu.spring.bean.Page;
|
import com.imyeyu.spring.bean.Page;
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 附件服务
|
* 附件服务
|
||||||
@@ -18,6 +18,13 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface AttachmentService extends BaseService<Attachment, String> {
|
public interface AttachmentService extends BaseService<Attachment, String> {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 克隆附件,复制业务属性和文件内容并生成新的附件记录
|
||||||
|
///
|
||||||
|
/// @param id 源附件 ID
|
||||||
|
/// @return 克隆后的附件
|
||||||
|
Attachment clone(String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按需获取或创建缩略图附件。
|
* 按需获取或创建缩略图附件。
|
||||||
* <p>当附件为图片或视频时,若指定尺寸的缩略图已存在则直接返回缓存,
|
* <p>当附件为图片或视频时,若指定尺寸的缩略图已存在则直接返回缓存,
|
||||||
@@ -50,6 +57,16 @@ public interface AttachmentService extends BaseService<Attachment, String> {
|
|||||||
*/
|
*/
|
||||||
List<Attachment> listByBizId(Attachment.BizType bizType, String bizId, String... attachTypes);
|
List<Attachment> listByBizId(Attachment.BizType bizType, String bizId, String... attachTypes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据多个业务 ID 批量获取附件
|
||||||
|
*
|
||||||
|
* @param bizType 业务类型
|
||||||
|
* @param bizIdList 业务 ID 列表
|
||||||
|
* @param attachTypes 附件类型,可为 null
|
||||||
|
* @return 按业务 ID 分组的附件列表
|
||||||
|
*/
|
||||||
|
Map<String, List<Attachment>> mapByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, String... attachTypes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据业务获取所有附件
|
* 根据业务获取所有附件
|
||||||
*
|
*
|
||||||
@@ -73,10 +90,8 @@ public interface AttachmentService extends BaseService<Attachment, String> {
|
|||||||
* <li>请求有、数据库有、无 tempFileId → 仅更新元数据</li>
|
* <li>请求有、数据库有、无 tempFileId → 仅更新元数据</li>
|
||||||
* <li>请求有、数据库有、有 tempFileId → 更新文件与元数据</li>
|
* <li>请求有、数据库有、有 tempFileId → 更新文件与元数据</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
|
||||||
* @param req 差分更新请求
|
|
||||||
*/
|
*/
|
||||||
void updateByBiz(BizUpdateReq req);
|
void updateByBizId(Attachment.BizType bizType, String bizId, List<Attachment> list);
|
||||||
|
|
||||||
void deleteByBiz(BizDeleteReq req);
|
void deleteByBizId(Attachment.BizType bizType, String bizId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.imyeyu.api.modules.common.service;
|
package com.imyeyu.api.modules.common.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.bean.SettingModule;
|
||||||
import com.imyeyu.api.modules.common.bean.attachment.SettingSupport;
|
import com.imyeyu.api.modules.common.bean.attachment.SettingSupport;
|
||||||
import com.imyeyu.api.modules.common.entity.Setting;
|
import com.imyeyu.api.modules.common.entity.Setting;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
import com.imyeyu.utils.Text;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ public interface SettingService extends BaseService<Setting, String> {
|
|||||||
Setting getByCode(String bizType, String bizId, String code);
|
Setting getByCode(String bizType, String bizId, String code);
|
||||||
|
|
||||||
default Setting getSystem(Enum<?> bizType) {
|
default Setting getSystem(Enum<?> bizType) {
|
||||||
return getByCode(Text.bizClassName(bizType.getClass()), TimiJava.ZERO_UUID, bizType.toString());
|
return getByCode(SettingModule.fromClass(bizType.getClass()).name(), TimiJava.ZERO_UUID, bizType.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Setting> listByBizId(String bizType, String bizId);
|
List<Setting> listByBizId(String bizType, String bizId);
|
||||||
|
|||||||
@@ -1,11 +1,31 @@
|
|||||||
package com.imyeyu.api.modules.common.service;
|
package com.imyeyu.api.modules.common.service;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Tag;
|
import com.imyeyu.api.modules.common.entity.Tag;
|
||||||
|
import com.imyeyu.api.modules.common.entity.TagApply;
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
/**
|
import java.util.Collection;
|
||||||
* @author 夜雨
|
import java.util.List;
|
||||||
* @since 2025-05-30 22:46
|
|
||||||
*/
|
/// 标签服务
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2025-05-30 22:46
|
||||||
public interface TagService extends BaseService<Tag, String> {
|
public interface TagService extends BaseService<Tag, String> {
|
||||||
|
|
||||||
|
List<Tag> listByIdList(Collection<String> idList);
|
||||||
|
|
||||||
|
/// 按业务查询标签列表
|
||||||
|
///
|
||||||
|
/// @param bizType 业务类型
|
||||||
|
/// @param bizId 业务 ID
|
||||||
|
/// @return 标签列表
|
||||||
|
List<Tag> listByBizType(TagApply.BizType bizType, String bizId);
|
||||||
|
|
||||||
|
/// 差分保存业务标签
|
||||||
|
///
|
||||||
|
/// @param bizType 业务类型
|
||||||
|
/// @param bizId 业务 ID
|
||||||
|
/// @param tagIdList 标签 ID 列表
|
||||||
|
void apply(TagApply.BizType bizType, String bizId, List<String> tagIdList);
|
||||||
}
|
}
|
||||||
|
|||||||
+119
-104
@@ -8,8 +8,6 @@ import com.imyeyu.api.modules.common.bean.attachment.Metadata;
|
|||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.mapper.AttachmentMapper;
|
import com.imyeyu.api.modules.common.mapper.AttachmentMapper;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
import com.imyeyu.api.modules.common.vo.attach.BizDeleteReq;
|
|
||||||
import com.imyeyu.api.modules.common.vo.attach.BizUpdateReq;
|
|
||||||
import com.imyeyu.api.util.JavaCV;
|
import com.imyeyu.api.util.JavaCV;
|
||||||
import com.imyeyu.io.IO;
|
import com.imyeyu.io.IO;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
@@ -43,7 +41,10 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -69,6 +70,88 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
return mapper;
|
return mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void create(Attachment attachment) {
|
||||||
|
TimiException.required(attachment.getBizType(), "not found String");
|
||||||
|
TimiException.required(attachment.getName(), "not found attachment.name");
|
||||||
|
String mongoId = null;
|
||||||
|
try {
|
||||||
|
if (attachment.getFile() != null) {
|
||||||
|
attachment.setInputStream(attachment.getFile().getInputStream());
|
||||||
|
}
|
||||||
|
InputStream is = attachment.getInputStream();
|
||||||
|
TimiException.required(is, "not found attachment.inputStream");
|
||||||
|
|
||||||
|
mongoId = gridFsTemplate.store(attachment.getInputStream(), attachment.buildMongoName()).toString();
|
||||||
|
GridFSFile gridFSFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(mongoId)));
|
||||||
|
attachment.setMongoId(mongoId);
|
||||||
|
attachment.setSize(gridFSFile.getLength());
|
||||||
|
attachment.setMd5(IO.md5(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
||||||
|
attachment.setMimeType(new Tika().detect(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
||||||
|
attachment.setUploaderIp(TimiSpring.getRequestIP());
|
||||||
|
attachment.setIsDestroyed(false);
|
||||||
|
if (attachment.getMimeType().startsWith("image")) {
|
||||||
|
BufferedImage image = ImageIO.read(gridFSBucket.openDownloadStream(gridFSFile.getObjectId()));
|
||||||
|
ObjectNode metadata = TimiJava.defaultIfNull(attachment.getMetadata(), jackson.createObjectNode());
|
||||||
|
metadata.put("width", image.getWidth());
|
||||||
|
metadata.put("height", image.getHeight());
|
||||||
|
attachment.setMetadata(metadata);
|
||||||
|
}
|
||||||
|
mapper.insert(attachment);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (mongoId != null) {
|
||||||
|
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(mongoId)));
|
||||||
|
}
|
||||||
|
log.error("create error", e);
|
||||||
|
throw new TimiException(TimiCode.ARG_BAD, "TODO read attachment input stream error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void update(Attachment attachment) {
|
||||||
|
String newMongoId = null;
|
||||||
|
try {
|
||||||
|
if (attachment.getFile() != null) {
|
||||||
|
attachment.setInputStream(attachment.getFile().getInputStream());
|
||||||
|
}
|
||||||
|
InputStream stream = attachment.getInputStream();
|
||||||
|
if (stream == null) {
|
||||||
|
// 无新文件,仅更新元数据字段
|
||||||
|
super.update(attachment);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 有新文件时,先查旧记录获取旧 mongoId 和兜底字段
|
||||||
|
Attachment old = mapper.selectRaw(attachment.getId());
|
||||||
|
// 存储新文件
|
||||||
|
newMongoId = gridFsTemplate.store(stream, attachment.buildMongoName()).toString();
|
||||||
|
GridFSFile gridFSFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(newMongoId)));
|
||||||
|
attachment.setMongoId(newMongoId);
|
||||||
|
attachment.setSize(gridFSFile.getLength());
|
||||||
|
attachment.setMd5(IO.md5(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
||||||
|
attachment.setMimeType(new Tika().detect(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
||||||
|
if (attachment.getMimeType().startsWith("image")) {
|
||||||
|
BufferedImage image = ImageIO.read(gridFSBucket.openDownloadStream(gridFSFile.getObjectId()));
|
||||||
|
ObjectNode metadata = TimiJava.defaultIfNull(attachment.getMetadata(), jackson.createObjectNode());
|
||||||
|
metadata.put("width", image.getWidth());
|
||||||
|
metadata.put("height", image.getHeight());
|
||||||
|
attachment.setMetadata(metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新数据库后删除旧 GridFS 文件
|
||||||
|
super.update(attachment);
|
||||||
|
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(old.getMongoId())));
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 新文件已上传但后续操作失败,清理新文件防止孤儿数据
|
||||||
|
if (TimiJava.isNotEmpty(newMongoId)) {
|
||||||
|
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(newMongoId)));
|
||||||
|
}
|
||||||
|
log.error("update error", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "TODO update file error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void delete(String id) {
|
public void delete(String id) {
|
||||||
@@ -106,101 +189,30 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void create(Attachment attachment) {
|
public Attachment clone(String id) {
|
||||||
TimiException.required(attachment.getBizType(), "not found String");
|
TimiException.required(id, "not found id");
|
||||||
TimiException.required(attachment.getName(), "not found attachment.name");
|
Attachment source = mapper.selectRaw(id);
|
||||||
String mongoId = null;
|
TimiException.required(source, "not found attachment");
|
||||||
try {
|
TimiException.required(source.getMongoId(), "not found mongoId");
|
||||||
if (attachment.getFile() != null) {
|
|
||||||
attachment.setInputStream(attachment.getFile().getInputStream());
|
|
||||||
}
|
|
||||||
InputStream is = attachment.getInputStream();
|
|
||||||
TimiException.required(is, "not found attachment.inputStream");
|
|
||||||
|
|
||||||
StringBuilder mongoName = new StringBuilder(attachment.getBizType().name());
|
Attachment target = new Attachment();
|
||||||
if (TimiJava.isNotEmpty(attachment.getAttachType())) {
|
target.setBizType(source.getBizType());
|
||||||
mongoName.append("_").append(attachment.getAttachType().toUpperCase()).append("_");
|
target.setBizId(source.getBizId());
|
||||||
|
target.setAttachType(source.getAttachType());
|
||||||
|
target.setTitle(source.getTitle());
|
||||||
|
target.setName(source.getName());
|
||||||
|
target.setMetadata(source.getMetadata() == null ? null : source.getMetadata().deepCopy());
|
||||||
|
target.setDestroyAt(source.getDestroyAt());
|
||||||
|
try (InputStream inputStream = getInputStreamByMongoId(source.getMongoId())) {
|
||||||
|
target.setInputStream(inputStream);
|
||||||
|
create(target);
|
||||||
|
return target;
|
||||||
|
} catch (IOException e) {
|
||||||
|
if (target.getMongoId() != null) {
|
||||||
|
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(target.getMongoId())));
|
||||||
}
|
}
|
||||||
mongoName.append(attachment.getName());
|
log.error("clone attachment error, id={}", id, e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "clone attachment error", e);
|
||||||
mongoId = gridFsTemplate.store(attachment.getInputStream(), mongoName.toString()).toString();
|
|
||||||
GridFSFile gridFSFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(mongoId)));
|
|
||||||
attachment.setMongoId(mongoId);
|
|
||||||
attachment.setSize(gridFSFile.getLength());
|
|
||||||
attachment.setMd5(IO.md5(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
|
||||||
attachment.setMimeType(new Tika().detect(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
|
||||||
attachment.setUploaderIp(TimiSpring.getRequestIP());
|
|
||||||
attachment.setIsDestroyed(false);
|
|
||||||
if (attachment.getMimeType().startsWith("image")) {
|
|
||||||
BufferedImage image = ImageIO.read(gridFSBucket.openDownloadStream(gridFSFile.getObjectId()));
|
|
||||||
attachment.setMetadata(TimiJava.defaultIfNull(attachment.getMetadata(), jackson.createObjectNode()));
|
|
||||||
if (attachment.getMetadata() instanceof ObjectNode obj) {
|
|
||||||
obj.put("width", image.getWidth());
|
|
||||||
obj.put("height", image.getHeight());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mapper.insert(attachment);
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (mongoId != null) {
|
|
||||||
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(mongoId)));
|
|
||||||
}
|
|
||||||
log.error("create error", e);
|
|
||||||
throw new TimiException(TimiCode.ARG_BAD, "TODO read attachment input stream error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void update(Attachment attachment) {
|
|
||||||
String newMongoId = null;
|
|
||||||
try {
|
|
||||||
if (attachment.getFile() != null) {
|
|
||||||
attachment.setInputStream(attachment.getFile().getInputStream());
|
|
||||||
}
|
|
||||||
InputStream stream = attachment.getInputStream();
|
|
||||||
if (stream == null) {
|
|
||||||
// 无新文件,仅更新元数据字段
|
|
||||||
super.update(attachment);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 有新文件时,先查旧记录获取旧 mongoId 和兜底字段
|
|
||||||
Attachment old = mapper.selectRaw(attachment.getId());
|
|
||||||
// 构建存储名,优先取调用方设置的字段,否则沿用旧值
|
|
||||||
Attachment.BizType bizType = TimiJava.defaultIfNull(attachment.getBizType(), old.getBizType());
|
|
||||||
String attachType = TimiJava.defaultIfEmpty(attachment.getAttachType(), old.getAttachType());
|
|
||||||
String name = TimiJava.defaultIfEmpty(attachment.getName(), old.getName());
|
|
||||||
StringBuilder mongoName = new StringBuilder(bizType.name());
|
|
||||||
if (TimiJava.isNotEmpty(attachType)) {
|
|
||||||
mongoName.append("_").append(attachType.toUpperCase()).append("_");
|
|
||||||
}
|
|
||||||
mongoName.append(name);
|
|
||||||
|
|
||||||
// 存储新文件
|
|
||||||
newMongoId = gridFsTemplate.store(stream, mongoName.toString()).toString();
|
|
||||||
GridFSFile gridFSFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(newMongoId)));
|
|
||||||
attachment.setMongoId(newMongoId);
|
|
||||||
attachment.setSize(gridFSFile.getLength());
|
|
||||||
attachment.setMd5(IO.md5(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
|
||||||
attachment.setMimeType(new Tika().detect(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
|
||||||
if (attachment.getMimeType().startsWith("image")) {
|
|
||||||
BufferedImage image = ImageIO.read(gridFSBucket.openDownloadStream(gridFSFile.getObjectId()));
|
|
||||||
attachment.setMetadata(TimiJava.defaultIfNull(attachment.getMetadata(), jackson.createObjectNode()));
|
|
||||||
if (attachment.getMetadata() instanceof ObjectNode obj) {
|
|
||||||
obj.put("width", image.getWidth());
|
|
||||||
obj.put("height", image.getHeight());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新数据库后删除旧 GridFS 文件
|
|
||||||
super.update(attachment);
|
|
||||||
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(old.getMongoId())));
|
|
||||||
} catch (Exception e) {
|
|
||||||
// 新文件已上传但后续操作失败,清理新文件防止孤儿数据
|
|
||||||
if (newMongoId != null) {
|
|
||||||
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(newMongoId)));
|
|
||||||
}
|
|
||||||
log.error("update error", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "TODO update file error");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,9 +226,9 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
if (!isImage && !isVideo) {
|
if (!isImage && !isVideo) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// 命中缓存直接返回
|
|
||||||
Attachment cached = mapper.selectThumb(source.getBizType(), source.getId(), requestWidth, requestHeight);
|
Attachment cached = mapper.selectThumb(source.getBizType(), source.getId(), requestWidth, requestHeight);
|
||||||
if (cached != null) {
|
if (cached != null) {
|
||||||
|
// 命中缓存直接返回
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -310,6 +322,11 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
return mapper.selectByBizId(bizType, bizId, List.of(attachTypes), null);
|
return mapper.selectByBizId(bizType, bizId, List.of(attachTypes), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, List<Attachment>> mapByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, String... attachTypes) {
|
||||||
|
return mapper.selectByBizIdList(bizType, bizIdList, List.of(attachTypes)).stream().collect(Collectors.groupingBy(Attachment::getBizId));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long countByBizId(Attachment.BizType bizType, String bizId, String... attachTypes) {
|
public long countByBizId(Attachment.BizType bizType, String bizId, String... attachTypes) {
|
||||||
return mapper.countByBizId(bizType, bizId, List.of(attachTypes));
|
return mapper.countByBizId(bizType, bizId, List.of(attachTypes));
|
||||||
@@ -330,16 +347,14 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void updateByBiz(BizUpdateReq req) {
|
public void updateByBizId(Attachment.BizType bizType, String bizId, List<Attachment> list) {
|
||||||
Attachment.BizType bizType = req.getBizType();
|
list = TimiJava.defaultIfNull(list, new ArrayList<>());
|
||||||
String bizId = req.getBizId();
|
|
||||||
List<Attachment> items = req.getItems();
|
|
||||||
|
|
||||||
// 数据库现有附件
|
// 数据库现有附件
|
||||||
List<Attachment> dbList = mapper.selectAllByBizId(bizType, bizId);
|
List<Attachment> dbList = mapper.selectAllByBizId(bizType, bizId);
|
||||||
Set<String> dbIds = dbList.stream().map(Attachment::getId).collect(Collectors.toSet());
|
Set<String> dbIds = dbList.stream().map(Attachment::getId).collect(Collectors.toSet());
|
||||||
// 请求附件 ID
|
// 请求附件 ID
|
||||||
Set<String> reqIds = items.stream().map(Attachment::getId).filter(Objects::nonNull).collect(Collectors.toSet());
|
Set<String> reqIds = list.stream().map(Attachment::getId).filter(Objects::nonNull).collect(Collectors.toSet());
|
||||||
// 数据库有、请求无:删除
|
// 数据库有、请求无:删除
|
||||||
for (Attachment attach : dbList) {
|
for (Attachment attach : dbList) {
|
||||||
if (!reqIds.contains(attach.getId())) {
|
if (!reqIds.contains(attach.getId())) {
|
||||||
@@ -347,7 +362,7 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Attachment item : items) {
|
for (Attachment item : list) {
|
||||||
boolean isNew = item.getId() == null || !dbIds.contains(item.getId());
|
boolean isNew = item.getId() == null || !dbIds.contains(item.getId());
|
||||||
String tempFileId = item.getTempFileId();
|
String tempFileId = item.getTempFileId();
|
||||||
|
|
||||||
@@ -414,8 +429,8 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void deleteByBiz(BizDeleteReq req) {
|
public void deleteByBizId(Attachment.BizType bizType, String bizId) {
|
||||||
List<Attachment> attachmentList = mapper.selectAllByBizId(req.getBizType(), req.getBizId());
|
List<Attachment> attachmentList = mapper.selectAllByBizId(bizType, bizId);
|
||||||
for (Attachment attachment : attachmentList) {
|
for (Attachment attachment : attachmentList) {
|
||||||
delete(attachment.getId());
|
delete(attachment.getId());
|
||||||
}
|
}
|
||||||
|
|||||||
+88
-4
@@ -1,27 +1,111 @@
|
|||||||
package com.imyeyu.api.modules.common.service.implement;
|
package com.imyeyu.api.modules.common.service.implement;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Tag;
|
import com.imyeyu.api.modules.common.entity.Tag;
|
||||||
|
import com.imyeyu.api.modules.common.entity.TagApply;
|
||||||
|
import com.imyeyu.api.modules.common.mapper.TagApplyMapper;
|
||||||
import com.imyeyu.api.modules.common.mapper.TagMapper;
|
import com.imyeyu.api.modules.common.mapper.TagMapper;
|
||||||
|
import com.imyeyu.api.modules.common.service.MultilingualService;
|
||||||
import com.imyeyu.api.modules.common.service.TagService;
|
import com.imyeyu.api.modules.common.service.TagService;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
import java.util.Collection;
|
||||||
* @author 夜雨
|
import java.util.HashSet;
|
||||||
* @since 2025-05-30 22:47
|
import java.util.LinkedHashSet;
|
||||||
*/
|
import java.util.List;
|
||||||
|
|
||||||
|
/// 标签服务实现
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2025-05-30 22:47
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class TagServiceImplement extends AbstractEntityService<Tag, String> implements TagService {
|
public class TagServiceImplement extends AbstractEntityService<Tag, String> implements TagService {
|
||||||
|
|
||||||
private final TagMapper mapper;
|
private final TagMapper mapper;
|
||||||
|
private final TagApplyMapper applyMapper;
|
||||||
|
private final MultilingualService multilingualService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BaseMapper<Tag, String> mapper() {
|
protected BaseMapper<Tag, String> mapper() {
|
||||||
return mapper;
|
return mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void create(Tag tag) {
|
||||||
|
TimiException.required(tag, "not found tag");
|
||||||
|
TimiException.required(tag.getZhCN(), "not found tag.zhCN");
|
||||||
|
TimiException.required(tag.getOwnerType(), "not found ownerType");
|
||||||
|
TimiException.required(tag.getOwnerId(), "not found ownerId");
|
||||||
|
checkZhCNUniqueInOwner(tag, null);
|
||||||
|
tag.setNameLangId(multilingualService.create(tag.getZhCN()));
|
||||||
|
super.create(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(Tag tag) {
|
||||||
|
TimiException.required(tag, "not found tag");
|
||||||
|
TimiException.required(tag.getId(), "not found tag.id");
|
||||||
|
Tag dbTag = get(tag.getId());
|
||||||
|
TimiException.required(dbTag, "not found tag");
|
||||||
|
tag.setOwnerType(dbTag.getOwnerType());
|
||||||
|
tag.setOwnerId(dbTag.getOwnerId());
|
||||||
|
if (tag.getZhCN() != null) {
|
||||||
|
if (tag.getNameLangId() == null) {
|
||||||
|
tag.setNameLangId(dbTag.getNameLangId());
|
||||||
|
}
|
||||||
|
checkZhCNUniqueInOwner(tag, tag.getId());
|
||||||
|
tag.setNameLangId(multilingualService.createIfDifferent(tag.getNameLangId(), tag.getZhCN()));
|
||||||
|
}
|
||||||
|
super.update(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Tag> listByIdList(Collection<String> idList) {
|
||||||
|
return mapper.selectByIdList(new HashSet<>(idList));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Tag> listByBizType(TagApply.BizType bizType, String bizId) {
|
||||||
|
return listByIdList(listApply(bizType, bizId).stream().map(TagApply::getTagId).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(TagApply.BizType bizType, String bizId, List<String> tagIdList) {
|
||||||
|
LinkedHashSet<String> tagIdSet = new LinkedHashSet<>(tagIdList == null ? List.of() : tagIdList);
|
||||||
|
for (TagApply apply : listApply(bizType, bizId)) {
|
||||||
|
if (tagIdSet.remove(apply.getTagId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
applyMapper.delete(apply.getId());
|
||||||
|
}
|
||||||
|
List<Tag> tagList = listByIdList(tagIdSet);
|
||||||
|
for (Tag tag : tagList) {
|
||||||
|
TagApply apply = new TagApply();
|
||||||
|
apply.setBizType(bizType);
|
||||||
|
apply.setBizId(bizId);
|
||||||
|
apply.setTagId(tag.getId());
|
||||||
|
applyMapper.insert(apply);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<TagApply> listApply(TagApply.BizType bizType, String bizId) {
|
||||||
|
TimiException.required(bizType, "not found bizType");
|
||||||
|
TimiException.required(bizId, "not found bizId");
|
||||||
|
|
||||||
|
TagApply example = new TagApply();
|
||||||
|
example.setBizType(bizType);
|
||||||
|
example.setBizId(bizId);
|
||||||
|
return applyMapper.selectAllByExample(example);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkZhCNUniqueInOwner(Tag tag, String allowedId) {
|
||||||
|
Tag existed = mapper.selectByOwnerAndZhCN(tag.getOwnerType(), tag.getOwnerId(), tag.getZhCN());
|
||||||
|
TimiException.requiredTrue(existed == null || existed.getId().equals(allowedId), "该标签名称已存在");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -46,8 +46,8 @@ public class TempFileServiceImplement implements TempFileService {
|
|||||||
|
|
||||||
public List<TempFileResp> create(List<MultipartFile> files, Long ttl) throws TimiException {
|
public List<TempFileResp> create(List<MultipartFile> files, Long ttl) throws TimiException {
|
||||||
Logger logger = new Logger();
|
Logger logger = new Logger();
|
||||||
logger.setModule("TEMP_FILE");
|
logger.setModule(Logger.Module.COMMON);
|
||||||
logger.setOperation("STORE");
|
logger.setOperation("TEMP_FILE_STORE");
|
||||||
logger.setIp(TimiSpring.getRequestIP());
|
logger.setIp(TimiSpring.getRequestIP());
|
||||||
try {
|
try {
|
||||||
logger.setContent(jackson.writeValueAsString(logRequestArgs(files, ttl)));
|
logger.setContent(jackson.writeValueAsString(logRequestArgs(files, ttl)));
|
||||||
@@ -116,8 +116,8 @@ public class TempFileServiceImplement implements TempFileService {
|
|||||||
@Override
|
@Override
|
||||||
public void save(TempFileSaveReq request) {
|
public void save(TempFileSaveReq request) {
|
||||||
Logger logger = new Logger();
|
Logger logger = new Logger();
|
||||||
logger.setModule("TEMP_FILE");
|
logger.setModule(Logger.Module.COMMON);
|
||||||
logger.setOperation("SAVE");
|
logger.setOperation("TEMP_FILE_SAVE");
|
||||||
logger.setIp(TimiSpring.getRequestIP());
|
logger.setIp(TimiSpring.getRequestIP());
|
||||||
try {
|
try {
|
||||||
logger.setContent(jackson.writeValueAsString(request));
|
logger.setContent(jackson.writeValueAsString(request));
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.common.vo.attach;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 业务附件差分更新请求
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-03-11 00:00
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class BizDeleteReq {
|
|
||||||
|
|
||||||
/** 业务类型 */
|
|
||||||
private Attachment.BizType bizType;
|
|
||||||
|
|
||||||
/** 业务 ID */
|
|
||||||
private String bizId;
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.common.vo.attach;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 业务附件差分更新请求
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-03-11 00:00
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class BizUpdateReq {
|
|
||||||
|
|
||||||
/** 业务类型 */
|
|
||||||
private Attachment.BizType bizType;
|
|
||||||
|
|
||||||
/** 业务 ID */
|
|
||||||
private String bizId;
|
|
||||||
|
|
||||||
/** 附件项列表 */
|
|
||||||
private List<Attachment> items = new ArrayList<>();
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.common.vo.tag;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2025-05-30 22:58
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class TagRequest {
|
|
||||||
|
|
||||||
private String bizId;
|
|
||||||
|
|
||||||
private String zhCN;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.imyeyu.api.modules.forevermc.controller;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务器接口
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2024-08-06 17:20
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Validated
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/fmc/server")
|
||||||
|
public class ServerController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务器状态报告,由 FMCServer 服务端插件发送
|
||||||
|
*/
|
||||||
|
@PostMapping("/report")
|
||||||
|
public void report() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.annotation;
|
|
||||||
|
|
||||||
import com.imyeyu.api.bean.RoleMatchMode;
|
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 要求 GAO 模块角色
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-26
|
|
||||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface RequireGaoRole {
|
|
||||||
|
|
||||||
/// 所需角色
|
|
||||||
///
|
|
||||||
/// @return 角色列表
|
|
||||||
GaoRoleCode[] value();
|
|
||||||
|
|
||||||
/// 匹配模式
|
|
||||||
///
|
|
||||||
/// @return 匹配模式
|
|
||||||
RoleMatchMode mode() default RoleMatchMode.ALL;
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.annotation;
|
|
||||||
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
|
||||||
import com.imyeyu.api.bean.RoleMatchMode;
|
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
|
||||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
|
||||||
import com.imyeyu.java.TimiJava;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import org.springframework.lang.NonNull;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.method.HandlerMethod;
|
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// GAO 角色注解处理器
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-27
|
|
||||||
@Component
|
|
||||||
public class RequireGaoRoleInterceptor implements HandlerInterceptor {
|
|
||||||
|
|
||||||
private final RoleChecker roleChecker;
|
|
||||||
|
|
||||||
public RequireGaoRoleInterceptor(RoleChecker roleChecker) {
|
|
||||||
this.roleChecker = roleChecker;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean preHandle(@NonNull HttpServletRequest req, @NonNull HttpServletResponse resp, @NonNull Object handler) {
|
|
||||||
if (!(handler instanceof HandlerMethod handlerMethod)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
RequireGaoRole annotation = handlerMethod.getMethodAnnotation(RequireGaoRole.class);
|
|
||||||
if (annotation == null || TimiJava.isEmpty(annotation.value())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
String[] roleCodeList = java.util.Arrays.stream(annotation.value()).map(GaoRoleCode::name).toArray(String[]::new);
|
|
||||||
if (annotation.mode() == RoleMatchMode.ANY) {
|
|
||||||
roleChecker.checkAny(ModuleCode.GAO, roleCodeList);
|
|
||||||
} else {
|
|
||||||
roleChecker.checkAll(ModuleCode.GAO, roleCodeList);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@ package com.imyeyu.api.modules.gao.bean;
|
|||||||
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
import com.imyeyu.api.modules.user.bean.BuiltinPermissionCode;
|
import com.imyeyu.api.modules.user.bean.BuiltinPermissionCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// GAO 模块权限枚举
|
/// GAO 模块权限枚举
|
||||||
@@ -10,54 +11,88 @@ import com.imyeyu.api.modules.user.bean.BuiltinPermissionCode;
|
|||||||
/// @since 2026-07-26
|
/// @since 2026-07-26
|
||||||
public enum GaoPermissionCode implements BuiltinPermissionCode {
|
public enum GaoPermissionCode implements BuiltinPermissionCode {
|
||||||
|
|
||||||
CUSTOMER_CREATE("CUSTOMER:CREATE", "客户创建"),
|
STORE_CREATE("STORE:CREATE", "门店创建", false, true),
|
||||||
|
|
||||||
CUSTOMER_READ("CUSTOMER:READ", "客户读取"),
|
STORE_READ("STORE:READ", "门店读取", true, true),
|
||||||
|
|
||||||
CUSTOMER_UPDATE("CUSTOMER:UPDATE", "客户修改"),
|
STORE_EXPORT("STORE:EXPORT", "门店导出", false, true),
|
||||||
|
|
||||||
CUSTOMER_DELETE("CUSTOMER:DELETE", "客户删除"),
|
STORE_UPDATE("STORE:UPDATE", "门店修改", true, true),
|
||||||
|
|
||||||
REGISTRATION_EVENT_CREATE("REGISTRATION_EVENT:CREATE", "登记事件创建"),
|
STORE_DELETE("STORE:DELETE", "门店删除", false, true),
|
||||||
|
|
||||||
REGISTRATION_EVENT_READ("REGISTRATION_EVENT:READ", "登记事件读取"),
|
CUSTOMER_CREATE("CUSTOMER:CREATE", "客户创建", false, false),
|
||||||
|
|
||||||
REGISTRATION_EVENT_UPDATE("REGISTRATION_EVENT:UPDATE", "登记事件修改"),
|
CUSTOMER_READ("CUSTOMER:READ", "客户读取", false, false),
|
||||||
|
|
||||||
REGISTRATION_EVENT_DELETE("REGISTRATION_EVENT:DELETE", "登记事件删除"),
|
CUSTOMER_EXPORT("CUSTOMER:EXPORT", "客户导出", true, false),
|
||||||
|
|
||||||
REGISTRATION_EVENT_RECORD_CREATE("REGISTRATION_EVENT_RECORD:CREATE", "登记事件记录创建"),
|
CUSTOMER_UPDATE("CUSTOMER:UPDATE", "客户修改", false, false),
|
||||||
|
|
||||||
REGISTRATION_EVENT_RECORD_READ("REGISTRATION_EVENT_RECORD:READ", "登记事件记录读取"),
|
CUSTOMER_DELETE("CUSTOMER:DELETE", "客户删除", false, false),
|
||||||
|
|
||||||
REGISTRATION_EVENT_RECORD_UPDATE("REGISTRATION_EVENT_RECORD:UPDATE", "登记事件记录修改"),
|
EVENT_CREATE("EVENT:CREATE", "登记事件创建", false, false),
|
||||||
|
|
||||||
REGISTRATION_EVENT_RECORD_DELETE("REGISTRATION_EVENT_RECORD:DELETE", "登记事件记录删除"),
|
EVENT_READ("EVENT:READ", "登记事件读取", false, false),
|
||||||
|
|
||||||
STAT_READ("STAT:READ", "统计读取"),
|
EVENT_UPDATE("EVENT:UPDATE", "登记事件修改", false, false),
|
||||||
|
|
||||||
QR_CODE_CREATE("QR_CODE:CREATE", "二维码创建"),
|
EVENT_DELETE("EVENT:DELETE", "登记事件删除", false, false),
|
||||||
|
|
||||||
USER_CREATE("USER:CREATE", "用户创建", true),
|
EVENT_RECORD_CREATE("EVENT_RECORD:CREATE", "登记事件记录创建", false, false),
|
||||||
|
|
||||||
USER_READ("USER:READ", "用户读取", true),
|
EVENT_RECORD_READ("EVENT_RECORD:READ", "登记事件记录读取", false, false),
|
||||||
|
|
||||||
USER_UPDATE("USER:UPDATE", "用户修改", true),
|
EVENT_RECORD_EXPORT("EVENT_RECORD:EXPORT", "登记事件记录导出", true, false),
|
||||||
|
|
||||||
USER_DELETE("USER:DELETE", "用户删除", true);
|
EVENT_RECORD_UPDATE("EVENT_RECORD:UPDATE", "登记事件记录修改", false, false),
|
||||||
|
|
||||||
|
EVENT_RECORD_DELETE("EVENT_RECORD:DELETE", "登记事件记录删除", false, false),
|
||||||
|
|
||||||
|
POINT_ACCOUNT_READ("POINT_ACCOUNT:READ", "客户积分账户读取", true, true),
|
||||||
|
|
||||||
|
POINT_LEDGER_READ("POINT_LEDGER:READ", "客户积分流水读取", true, true),
|
||||||
|
|
||||||
|
POINT_RULE_CREATE("POINT_RULE:CREATE", "客户积分规则创建", true, true),
|
||||||
|
|
||||||
|
POINT_RULE_READ("POINT_RULE:READ", "客户积分规则读取", true, true),
|
||||||
|
|
||||||
|
POINT_RULE_UPDATE("POINT_RULE:UPDATE", "客户积分规则修改", true, true),
|
||||||
|
|
||||||
|
POINT_RULE_DELETE("POINT_RULE:DELETE", "客户积分规则删除", true, true),
|
||||||
|
|
||||||
|
POINT_ADJUST("POINT:ADJUST", "客户积分人工调整", true, true),
|
||||||
|
|
||||||
|
POINT_SOURCE_VALUE("POINT:SOURCE_VALUE", "登记提交自定义积分值", true, true),
|
||||||
|
|
||||||
|
STAT_READ("STAT:READ", "统计读取", false, false),
|
||||||
|
|
||||||
|
QR_CODE_CREATE("QR_CODE:CREATE", "二维码创建", false, false),
|
||||||
|
|
||||||
|
USER_CREATE("USER:CREATE", "用户创建", true, false),
|
||||||
|
|
||||||
|
USER_READ("USER:READ", "用户读取", true, false),
|
||||||
|
|
||||||
|
USER_UPDATE("USER:UPDATE", "用户修改", true, false),
|
||||||
|
|
||||||
|
USER_DELETE("USER:DELETE", "用户删除", true, false);
|
||||||
|
|
||||||
final String value;
|
final String value;
|
||||||
final String defaultName;
|
final String defaultName;
|
||||||
|
|
||||||
|
/// `true` 为初始化时授权给店长角色
|
||||||
|
@Getter
|
||||||
final boolean grantToStoreManager;
|
final boolean grantToStoreManager;
|
||||||
|
|
||||||
GaoPermissionCode(String value, String defaultName) {
|
/// `true` 为初始化时授权给门店管理角色
|
||||||
this(value, defaultName, false);
|
@Getter
|
||||||
}
|
final boolean grantToGlobalManager;
|
||||||
|
|
||||||
GaoPermissionCode(String value, String defaultName, boolean grantToStoreManager) {
|
GaoPermissionCode(String value, String defaultName, boolean grantToStoreManager, boolean grantToGlobalManager) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.defaultName = defaultName;
|
this.defaultName = defaultName;
|
||||||
this.grantToStoreManager = grantToStoreManager;
|
this.grantToStoreManager = grantToStoreManager;
|
||||||
|
this.grantToGlobalManager = grantToGlobalManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -84,11 +119,4 @@ public enum GaoPermissionCode implements BuiltinPermissionCode {
|
|||||||
public boolean isGrantToAdmin() {
|
public boolean isGrantToAdmin() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// true 为初始化时授权给店长角色
|
|
||||||
///
|
|
||||||
/// @return 是否授权给店长角色
|
|
||||||
public boolean isGrantToStoreManager() {
|
|
||||||
return grantToStoreManager;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,12 +12,14 @@ import lombok.AllArgsConstructor;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum GaoRoleCode implements BuiltinRoleCode {
|
public enum GaoRoleCode implements BuiltinRoleCode {
|
||||||
|
|
||||||
/// 店长
|
/// 门店管理
|
||||||
STORE_MANAGER("店长"),
|
GLOBAL_MANAGER("门店管理", null),
|
||||||
|
|
||||||
EMPLOYEE("员工");
|
/// 店长
|
||||||
|
STORE_MANAGER("店长", GLOBAL_MANAGER.name());
|
||||||
|
|
||||||
final String defaultName;
|
final String defaultName;
|
||||||
|
final String parentCode;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModuleCode getModuleCode() {
|
public ModuleCode getModuleCode() {
|
||||||
@@ -36,6 +38,7 @@ public enum GaoRoleCode implements BuiltinRoleCode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getParentCode() {
|
public String getParentCode() {
|
||||||
return null;
|
return parentCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.bean;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/// GAO 用户邀请缓存
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-13
|
||||||
|
@Data
|
||||||
|
public class GaoUserInviteCache {
|
||||||
|
|
||||||
|
/// 发起邀请的用户 ID
|
||||||
|
private String inviterUserId;
|
||||||
|
|
||||||
|
/// 门店 ID
|
||||||
|
private String storeId;
|
||||||
|
|
||||||
|
/// 角色 ID
|
||||||
|
private String roleId;
|
||||||
|
|
||||||
|
/// 邀请来源或场景
|
||||||
|
private String scene;
|
||||||
|
|
||||||
|
/// 邀请创建时间,毫秒时间戳
|
||||||
|
private Long createdAt;
|
||||||
|
|
||||||
|
/// 邀请过期时间,毫秒时间戳
|
||||||
|
private Long expireAt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoCustomerChartService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerChartReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordCalendarView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordDailyStatView;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// GAO 客户报表接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/customer/chart")
|
||||||
|
public class GaoCustomerChartController {
|
||||||
|
|
||||||
|
private final GaoCustomerChartService service;
|
||||||
|
|
||||||
|
/// 查询客户登记每日统计,可同时支撑登记趋势和登记事件结构图表
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/event/record/daily")
|
||||||
|
public List<GaoEventRecordDailyStatView> eventRecordDaily(@RequestBody GaoCustomerChartReq req) {
|
||||||
|
return service.eventRecordDailyStat(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询客户登记日历记录
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/event/record/calendar")
|
||||||
|
public List<GaoEventRecordCalendarView> eventRecordCalendar(@RequestBody GaoCustomerChartReq req) {
|
||||||
|
return service.eventRecordCalendar(req);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +1,33 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||||
import com.imyeyu.api.bean.RoleMatchMode;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoRole;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRecord;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoRegistrationEventService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoRegistrationEventRecordService;
|
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStatView;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerInviteUpdateReq;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerSearchReq;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerPage;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStatReq;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStateReq;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoQuickRegistrationEventRecordReq;
|
import com.imyeyu.api.modules.user.service.RoleChecker;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserService;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.network.Network;
|
||||||
|
import com.imyeyu.spring.TimiSpring;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
import com.imyeyu.spring.bean.Page;
|
import com.imyeyu.spring.bean.Page;
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import com.imyeyu.spring.util.ResponseView;
|
||||||
|
import com.imyeyu.utils.Time;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@@ -30,113 +37,71 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// GAO 客户接口
|
/// GAO 客户接口
|
||||||
///
|
///
|
||||||
/// @author Codex
|
/// @author 夜雨
|
||||||
/// @since 2026-07-27
|
/// @since 2026-07-27 14:12
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping("/gao/customer")
|
@RequestMapping("/gao/customer")
|
||||||
@RequireGaoRole(value = {GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
|
|
||||||
public class GaoCustomerController {
|
public class GaoCustomerController {
|
||||||
|
|
||||||
private static final String SIGN_IN_REGISTRATION_EVENT_NAME = "签到";
|
private final UserService userService;
|
||||||
|
private final RoleChecker roleChecker;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
private final GaoCustomerService service;
|
private final GaoCustomerService service;
|
||||||
private final GaoRegistrationEventRecordService registrationEventRecordService;
|
private final GaoStoreService gaoStoreService;
|
||||||
private final GaoRegistrationEventService registrationEventService;
|
private final UserLoginService userLoginService;
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
public PageResult<GaoCustomer> list(@RequestBody Page<GaoCustomer> page) {
|
@JsonView(ResponseView.Public.class)
|
||||||
PageResult<GaoCustomer> result = service.page(page);
|
public PageResult<GaoCustomer> list(@RequestBody GaoCustomerPage page) {
|
||||||
fillLastSignInAt(result.getList());
|
PageResult<GaoCustomer> result = service.pageByQuery(page);
|
||||||
|
|
||||||
|
List<String> idList = result.getList().stream().map(GaoCustomer::getId).distinct().toList();
|
||||||
|
Map<String, List<Attachment>> attachmentMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, idList);
|
||||||
|
for (GaoCustomer customer : result.getList()) {
|
||||||
|
customer.setAttachmentList(attachmentMap.get(customer.getId()));
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
|
||||||
@PostMapping("/search")
|
|
||||||
public List<GaoCustomer> search(@RequestBody GaoCustomerSearchReq req) {
|
|
||||||
return service.search(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
|
||||||
@PostMapping("/search/page")
|
|
||||||
public PageResult<GaoCustomer> searchPage(@RequestBody Page<GaoCustomerSearchReq> page) {
|
|
||||||
return service.searchPage(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@IgnoreGlobalReturn
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
|
||||||
@PostMapping("/export")
|
|
||||||
public void export(@RequestBody GaoCustomerSearchReq req, HttpServletResponse resp) throws IOException {
|
|
||||||
String fileName = URLEncoder.encode("客户列表.xlsx", "UTF-8").replace("+", "%20");
|
|
||||||
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
||||||
resp.setHeader("Content-Disposition", "attachment; filename=\"gao-customer.xlsx\"; filename*=UTF-8''" + fileName);
|
|
||||||
resp.getOutputStream().write(service.exportSearchExcel(req));
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
@PostMapping("/detail")
|
@PostMapping("/detail")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
public GaoCustomer detail(@RequestParam String id) {
|
public GaoCustomer detail(@RequestParam String id) {
|
||||||
return service.get(id);
|
GaoCustomer customer = service.get(id);
|
||||||
}
|
if (TimiJava.isNotEmpty(customer.getIntroducerCustomerId())) {
|
||||||
|
GaoCustomer introducerCustomer = service.get(customer.getIntroducerCustomerId());
|
||||||
@AOPLog
|
introducerCustomer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, introducerCustomer.getId()));
|
||||||
@RequestRateLimit
|
customer.setIntroducerCustomer(introducerCustomer);
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
}
|
||||||
@PostMapping("/detail/code")
|
if (TimiJava.isNotEmpty(customer.getCreatorUserId())) {
|
||||||
public GaoCustomer detailByCode(@RequestParam String code) {
|
customer.setCreatorUser(userService.get(customer.getCreatorUserId()));
|
||||||
return service.getByCode(code);
|
}
|
||||||
}
|
customer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId()));
|
||||||
|
return customer;
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
|
||||||
@PostMapping("/detail/code/nullable")
|
|
||||||
public GaoCustomer nullableDetailByCode(@RequestParam String code) {
|
|
||||||
return service.getNullableByCode(code);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
|
||||||
@PostMapping("/invited/list")
|
|
||||||
public List<GaoCustomer> invitedList(@RequestParam String introducerCustomerId) {
|
|
||||||
return service.listInvited(introducerCustomerId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_CREATE)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_CREATE)
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public GaoCustomer create(@RequestBody GaoCustomer customer) {
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public String create(@RequestBody GaoCustomer customer) {
|
||||||
|
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||||
|
customer.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
||||||
|
}
|
||||||
service.create(customer);
|
service.create(customer);
|
||||||
return customer;
|
return customer.getId();
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@PostMapping("/quick/register")
|
|
||||||
public GaoRegistrationEventRecord quickRegister(@RequestBody GaoQuickRegistrationEventRecordReq req) {
|
|
||||||
return registrationEventRecordService.quickRegister(req);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -144,7 +109,10 @@ public class GaoCustomerController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
public void update(@RequestBody GaoCustomer customer) {
|
public void update(@RequestBody GaoCustomer customer) {
|
||||||
service.update(customer);
|
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||||
|
customer.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
||||||
|
}
|
||||||
|
service.updateWithAttachment(customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -157,26 +125,78 @@ public class GaoCustomerController {
|
|||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
@PostMapping("/invite/create")
|
@PostMapping("/find/id")
|
||||||
public void createInvite(@RequestBody GaoCustomerInviteUpdateReq req) {
|
@JsonView(ResponseView.Public.class)
|
||||||
service.saveInviteRelation(req);
|
public GaoCustomer findById(@RequestParam String id) {
|
||||||
|
GaoCustomer customer = service.get(id);
|
||||||
|
TimiException.required(customer, "not found customer");
|
||||||
|
customer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId()));
|
||||||
|
return customer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
@PostMapping("/invite/detail")
|
@PostMapping("/find/code")
|
||||||
public GaoCustomer inviteDetail(@RequestParam String customerId) {
|
@JsonView(ResponseView.Public.class)
|
||||||
return service.get(customerId);
|
public GaoCustomer findByCode(@RequestParam String storeId, @RequestParam String code) {
|
||||||
|
GaoCustomer customer = service.getByCode(storeId, code);
|
||||||
|
if (customer == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
customer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId()));
|
||||||
|
return customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
|
@PostMapping("/find/name")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public GaoCustomer findByName(@RequestParam String storeId, @RequestParam String name) {
|
||||||
|
GaoCustomer customer = service.getByName(storeId, name);
|
||||||
|
if (customer == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
customer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId()));
|
||||||
|
return customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@IgnoreGlobalReturn
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_EXPORT)
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(@RequestBody Page<GaoCustomer> page) throws IOException {
|
||||||
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
|
String contentDisposition = Network.getFileDownloadHeader("客户列表-%s.xlsx".formatted(Time.serialize.format(Time.now())));
|
||||||
|
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
|
resp.setHeader("Content-Disposition", contentDisposition);
|
||||||
|
resp.getOutputStream().write(service.export(page));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
|
@PostMapping("/invited/list")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public List<GaoCustomer> listInvited(@RequestParam String introducerCustomerId) {
|
||||||
|
List<GaoCustomer> result = service.listInvited(introducerCustomerId);
|
||||||
|
List<String> idList = result.stream().map(GaoCustomer::getId).distinct().toList();
|
||||||
|
Map<String, List<Attachment>> attachMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, idList);
|
||||||
|
for (GaoCustomer customer : result) {
|
||||||
|
customer.setAttachmentList(attachMap.get(customer.getId()));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
||||||
@PostMapping("/invite/update")
|
@PostMapping("/invite/save")
|
||||||
public void updateInvite(@RequestBody GaoCustomerInviteUpdateReq req) {
|
public void saveInvite(@RequestParam String introducerCustomerId, @RequestParam String customerId) {
|
||||||
service.saveInviteRelation(req);
|
service.saveInviteRelation(introducerCustomerId, customerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -187,37 +207,21 @@ public class GaoCustomerController {
|
|||||||
service.deleteInviteRelation(customerId);
|
service.deleteInviteRelation(customerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 按天统计客户新增数和累计总数
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
@PostMapping("/stat/daily")
|
@PostMapping("/state/daily")
|
||||||
/// 按天统计客户新增数和累计总数
|
public List<GaoCustomerDailyStateView> dailyStat(@RequestBody GaoCustomerTrendStateReq req) {
|
||||||
public List<GaoCustomerDailyStatView> dailyStat(@RequestBody GaoCustomerTrendStatReq req) {
|
return service.stateDailyTrend(req);
|
||||||
return service.statDailyTrend(req);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillLastSignInAt(List<GaoCustomer> customerList) {
|
/// 统计客户性别分布
|
||||||
if (customerList == null || customerList.isEmpty()) {
|
@AOPLog
|
||||||
return;
|
@RequestRateLimit
|
||||||
}
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
String signInRegistrationEventId = null;
|
@PostMapping("/state/gender")
|
||||||
for (GaoRegistrationEvent registrationEvent : registrationEventService.listEnabled()) {
|
public List<GaoCustomerGenderStatView> genderStat(@RequestParam String storeId) {
|
||||||
if (SIGN_IN_REGISTRATION_EVENT_NAME.equals(registrationEvent.getName())) {
|
return service.stateGender(storeId);
|
||||||
signInRegistrationEventId = registrationEvent.getId();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (signInRegistrationEventId == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<String> customerIdList = customerList.stream().map(GaoCustomer::getId).toList();
|
|
||||||
Map<String, GaoRegistrationEventRecord> recordMap = registrationEventRecordService.listLatestByCustomerIdListAndRegistrationEventId(customerIdList, signInRegistrationEventId).stream()
|
|
||||||
.collect(Collectors.toMap(GaoRegistrationEventRecord::getCustomerId, Function.identity(), (left, right) -> left));
|
|
||||||
for (GaoCustomer customer : customerList) {
|
|
||||||
GaoRegistrationEventRecord record = recordMap.get(customer.getId());
|
|
||||||
if (record != null) {
|
|
||||||
customer.setLastSignInAt(record.getRegisteredAt());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoEventService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||||
|
import com.imyeyu.api.modules.user.service.RoleChecker;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/// GAO 登记事件接口
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-07-27 14:13
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/event")
|
||||||
|
public class GaoEventController {
|
||||||
|
|
||||||
|
private final GaoEventService service;
|
||||||
|
private final RoleChecker roleChecker;
|
||||||
|
private final GaoStoreService gaoStoreService;
|
||||||
|
private final UserLoginService userLoginService;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
public PageResult<GaoEvent> list(@RequestBody Page<GaoEvent> page) {
|
||||||
|
PageResult<GaoEvent> result = service.page(page);
|
||||||
|
Map<String, List<String>> roleMap = service.mapRoleCodeListByEventIdList(result.getList().stream().map(GaoEvent::getId).toList());
|
||||||
|
for (GaoEvent event : result.getList()) {
|
||||||
|
event.setRoleCodeList(roleMap.get(event.getId()));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@PostMapping("/list/valid")
|
||||||
|
public List<GaoEvent> listValid(@RequestParam String storeId) {
|
||||||
|
return service.listValid(storeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_READ)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
public GaoEvent detail(@RequestParam String id) {
|
||||||
|
return service.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_CREATE)
|
||||||
|
@PostMapping("/create")
|
||||||
|
public void create(@RequestBody GaoEvent event) {
|
||||||
|
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||||
|
event.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
||||||
|
}
|
||||||
|
service.create(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_UPDATE)
|
||||||
|
@PostMapping("/update")
|
||||||
|
public void update(@RequestBody GaoEvent event) {
|
||||||
|
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||||
|
event.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
||||||
|
}
|
||||||
|
service.update(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_UPDATE)
|
||||||
|
@PostMapping("/sort")
|
||||||
|
public void sort(@RequestBody List<String> idList) {
|
||||||
|
service.sort(idList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_DELETE)
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public void delete(@RequestParam String id) {
|
||||||
|
service.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,212 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoEventRecordService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoEventService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerEventRankView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordPage;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordPageResult;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordRankPage;
|
||||||
|
import com.imyeyu.api.modules.user.service.RoleChecker;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserService;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.network.Network;
|
||||||
|
import com.imyeyu.spring.TimiSpring;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import com.imyeyu.spring.util.ResponseView;
|
||||||
|
import com.imyeyu.utils.Time;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/// GAO 登记事件记录接口
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-07-27 14:11
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/event/record")
|
||||||
|
public class GaoEventRecordController {
|
||||||
|
|
||||||
|
private final UserService userService;
|
||||||
|
private final RoleChecker roleChecker;
|
||||||
|
private final GaoEventService eventService;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
private final GaoCustomerService customerService;
|
||||||
|
private final GaoStoreService gaoStoreService;
|
||||||
|
private final GaoEventRecordService service;
|
||||||
|
private final UserLoginService userLoginService;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public GaoEventRecordPageResult list(@RequestBody GaoEventRecordPage page) {
|
||||||
|
PageResult<GaoEventRecord> pageResult = service.pageByRange(page);
|
||||||
|
GaoEventRecordPageResult result = new GaoEventRecordPageResult();
|
||||||
|
result.setTotal(pageResult.getTotal());
|
||||||
|
result.setList(pageResult.getList());
|
||||||
|
result.setNumberValueTotal(resolveNumberValueTotal(page));
|
||||||
|
{
|
||||||
|
List<String> customerIdList = result.getList().stream().map(GaoEventRecord::getCustomerId).toList();
|
||||||
|
Map<String, GaoEvent> eventMap = eventService.mapByIdList(result.getList().stream().map(GaoEventRecord::getEventId).toList());
|
||||||
|
Map<String, GaoCustomer> customerMap = customerService.mapByIdList(customerIdList);
|
||||||
|
Map<String, List<Attachment>> attachMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, customerIdList);
|
||||||
|
for (GaoEventRecord record : result.getList()) {
|
||||||
|
record.setEvent(eventMap.get(record.getEventId()));
|
||||||
|
record.setCustomer(customerMap.get(record.getCustomerId()));
|
||||||
|
record.getCustomer().setAttachmentList(attachMap.get(record.getCustomerId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 根据列表筛选条件返回单个 NUMBER 事件的数值合计
|
||||||
|
///
|
||||||
|
/// @param page 登记记录范围查询请求
|
||||||
|
/// @return 数值合计,不满足单个 NUMBER 事件条件时为空
|
||||||
|
private Long resolveNumberValueTotal(GaoEventRecordPage page) {
|
||||||
|
List<String> eventIdList = page.getEventIdList();
|
||||||
|
if (eventIdList == null || eventIdList.size() != 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
GaoEvent event = eventService.mapByIdList(eventIdList).get(eventIdList.get(0));
|
||||||
|
if (event == null || event.getValueType() != GaoEvent.ValueType.NUMBER) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return service.sumNumberValueByRange(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_READ)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public GaoEventRecord detail(@RequestParam String id) {
|
||||||
|
GaoEventRecord record = service.get(id);
|
||||||
|
record.setCustomer(customerService.get(record.getCustomerId()));
|
||||||
|
record.getCustomer().setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, record.getCustomerId()));
|
||||||
|
record.setEvent(eventService.get(record.getEventId()));
|
||||||
|
record.setOperator(userService.get(record.getOperatorUserId()));
|
||||||
|
record.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_EVENT_RECORD, record.getId()));
|
||||||
|
return record;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_CREATE)
|
||||||
|
@PostMapping("/create")
|
||||||
|
public void create(@RequestBody GaoEventRecord record) {
|
||||||
|
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||||
|
record.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
||||||
|
}
|
||||||
|
service.create(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_CREATE)
|
||||||
|
@PostMapping("/create/batch")
|
||||||
|
public void createBatch(@RequestBody List<GaoEventRecord> recordList) {
|
||||||
|
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||||
|
String storeId = gaoStoreService.getBelongIdByRequiredLoginUserId();
|
||||||
|
for (GaoEventRecord record : recordList) {
|
||||||
|
record.setStoreId(storeId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
service.createBatch(recordList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_CREATE)
|
||||||
|
@PostMapping("/create/customer")
|
||||||
|
public void createWithCustomer(@RequestBody GaoCustomer customer) {
|
||||||
|
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||||
|
String storeId = gaoStoreService.getBelongIdByRequiredLoginUserId();
|
||||||
|
for (GaoEventRecord record : TimiJava.safeIterable(customer.getEventRecordList())) {
|
||||||
|
record.setStoreId(storeId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
service.createWithCustomer(customer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_UPDATE)
|
||||||
|
@PostMapping("/update")
|
||||||
|
public void update(@RequestBody GaoEventRecord record) {
|
||||||
|
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||||
|
record.setStoreId(gaoStoreService.getBelongIdByRequiredLoginUserId());
|
||||||
|
}
|
||||||
|
service.update(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_DELETE)
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public void delete(@RequestParam String id) {
|
||||||
|
service.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@IgnoreGlobalReturn
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_EXPORT)
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(@RequestBody GaoEventRecordPage page) throws IOException {
|
||||||
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
|
String contentDisposition = Network.getFileDownloadHeader("登记事件记录-%s.xlsx".formatted(Time.serialize.format(Time.now())));
|
||||||
|
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
|
resp.setHeader("Content-Disposition", contentDisposition);
|
||||||
|
resp.getOutputStream().write(service.export(page));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 按时间范围查询客户登记排行榜
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/rank")
|
||||||
|
public PageResult<GaoCustomerEventRankView> eventRank(@RequestBody GaoEventRecordRankPage page) {
|
||||||
|
PageResult<GaoCustomerEventRankView> result = service.pageRankByRange(page);
|
||||||
|
List<String> customerIdList = result.getList().stream().map(GaoCustomerEventRankView::getCustomerId).distinct().toList();
|
||||||
|
if (customerIdList.isEmpty()) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
Map<String, GaoCustomer> customerMap = customerService.mapByIdList(customerIdList);
|
||||||
|
Map<String, List<Attachment>> attachmentMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, customerIdList);
|
||||||
|
for (GaoCustomerEventRankView view : result.getList()) {
|
||||||
|
GaoCustomer customer = customerMap.get(view.getCustomerId());
|
||||||
|
if (customer != null) {
|
||||||
|
customer.setAttachmentList(attachmentMap.get(view.getCustomerId()));
|
||||||
|
}
|
||||||
|
view.setCustomer(customer);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointAccount;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoPointAccountService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||||
|
import com.imyeyu.api.modules.user.service.RoleChecker;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/// GAO 客户积分账户接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/customer/point")
|
||||||
|
public class GaoPointAccountController {
|
||||||
|
|
||||||
|
private final RoleChecker roleChecker;
|
||||||
|
private final GaoStoreService storeService;
|
||||||
|
private final GaoPointAccountService accountService;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.POINT_ACCOUNT_READ)
|
||||||
|
@PostMapping("/account/detail")
|
||||||
|
public GaoPointAccount detail(@RequestParam String customerId, @RequestParam(required = false) String storeId) {
|
||||||
|
storeId = resolveStoreId(storeId);
|
||||||
|
return accountService.getByCustomerId(storeId, customerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveStoreId(String requestedStoreId) {
|
||||||
|
if (roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||||
|
return requestedStoreId;
|
||||||
|
}
|
||||||
|
return storeService.getBelongIdByRequiredLoginUserId();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointLedger;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoPointLedgerService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoPointTriggerService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoPointAdjustRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoPointLedgerPage;
|
||||||
|
import com.imyeyu.api.modules.user.service.RoleChecker;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/// GAO 客户积分流水接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/customer/point")
|
||||||
|
public class GaoPointLedgerController {
|
||||||
|
|
||||||
|
private final RoleChecker roleChecker;
|
||||||
|
private final GaoStoreService storeService;
|
||||||
|
private final GaoPointLedgerService ledgerService;
|
||||||
|
private final GaoPointTriggerService triggerService;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.POINT_LEDGER_READ)
|
||||||
|
@PostMapping("/ledger/list")
|
||||||
|
public PageResult<GaoPointLedger> list(@RequestBody GaoPointLedgerPage page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
page.setStoreId(resolveStoreId(page.getStoreId()));
|
||||||
|
return ledgerService.pageByQuery(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.POINT_ADJUST)
|
||||||
|
@PostMapping("/adjust")
|
||||||
|
public void adjust(@RequestBody GaoPointAdjustRequest request) {
|
||||||
|
request.setStoreId(resolveStoreId(request.getStoreId()));
|
||||||
|
triggerService.adjust(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveStoreId(String requestedStoreId) {
|
||||||
|
if (roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||||
|
return requestedStoreId;
|
||||||
|
}
|
||||||
|
return storeService.getBelongIdByRequiredLoginUserId();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointRule;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoPointRuleService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||||
|
import com.imyeyu.api.modules.user.service.RoleChecker;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/// GAO 客户积分规则接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/customer/point")
|
||||||
|
public class GaoPointRuleController {
|
||||||
|
|
||||||
|
private final RoleChecker roleChecker;
|
||||||
|
private final GaoStoreService storeService;
|
||||||
|
private final GaoPointRuleService ruleService;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.POINT_RULE_READ)
|
||||||
|
@PostMapping("/rule/list")
|
||||||
|
public PageResult<GaoPointRule> list(@RequestBody Page<GaoPointRule> page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
if (!isGlobalManager()) {
|
||||||
|
GaoPointRule example = TimiJava.defaultIfNull(page.getEqualsExample(), new GaoPointRule());
|
||||||
|
example.setStoreId(resolveStoreId(null));
|
||||||
|
page.setEqualsExample(example);
|
||||||
|
}
|
||||||
|
return ruleService.page(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.POINT_RULE_READ)
|
||||||
|
@PostMapping("/rule/detail")
|
||||||
|
public GaoPointRule detail(@RequestParam String id) {
|
||||||
|
GaoPointRule rule = ruleService.get(id);
|
||||||
|
TimiException.required(rule, "not found point rule");
|
||||||
|
checkStore(rule.getStoreId());
|
||||||
|
return rule;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.POINT_RULE_CREATE)
|
||||||
|
@PostMapping("/rule/create")
|
||||||
|
public String create(@RequestBody GaoPointRule rule) {
|
||||||
|
rule.setStoreId(resolveStoreId(rule.getStoreId()));
|
||||||
|
ruleService.create(rule);
|
||||||
|
return rule.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.POINT_RULE_UPDATE)
|
||||||
|
@PostMapping("/rule/update")
|
||||||
|
public void update(@RequestBody GaoPointRule rule) {
|
||||||
|
rule.setStoreId(resolveStoreId(rule.getStoreId()));
|
||||||
|
ruleService.update(rule);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.POINT_RULE_DELETE)
|
||||||
|
@PostMapping("/rule/delete")
|
||||||
|
public void delete(@RequestParam String id) {
|
||||||
|
GaoPointRule rule = ruleService.get(id);
|
||||||
|
TimiException.required(rule, "not found point rule");
|
||||||
|
checkStore(rule.getStoreId());
|
||||||
|
ruleService.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveStoreId(String requestedStoreId) {
|
||||||
|
if (isGlobalManager()) {
|
||||||
|
return requestedStoreId;
|
||||||
|
}
|
||||||
|
return storeService.getBelongIdByRequiredLoginUserId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkStore(String storeId) {
|
||||||
|
if (!isGlobalManager()) {
|
||||||
|
TimiException.requiredTrue(resolveStoreId(null).equals(storeId), "无权操作其他门店数据");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isGlobalManager() {
|
||||||
|
return roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
-82
@@ -1,82 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoRole;
|
|
||||||
import com.imyeyu.api.bean.RoleMatchMode;
|
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoRegistrationEventService;
|
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
|
||||||
import com.imyeyu.spring.bean.Page;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// GAO 登记事件接口
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-27
|
|
||||||
@RestController
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@RequestMapping("/gao/registration-event")
|
|
||||||
@RequireGaoRole(value = {GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
|
|
||||||
public class GaoRegistrationEventController {
|
|
||||||
|
|
||||||
private final GaoRegistrationEventService service;
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_READ)
|
|
||||||
@PostMapping("/list")
|
|
||||||
public PageResult<GaoRegistrationEvent> list(@RequestBody Page<GaoRegistrationEvent> page) {
|
|
||||||
return service.pageWithRegistrationEventLimit(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@PostMapping("/enabled/list")
|
|
||||||
public List<GaoRegistrationEvent> enabledList() {
|
|
||||||
return service.listEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_READ)
|
|
||||||
@PostMapping("/detail")
|
|
||||||
public GaoRegistrationEvent detail(@RequestParam String id) {
|
|
||||||
return service.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_CREATE)
|
|
||||||
@PostMapping("/create")
|
|
||||||
public void create(@RequestBody GaoRegistrationEvent registrationEvent) {
|
|
||||||
service.create(registrationEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_UPDATE)
|
|
||||||
@PostMapping("/update")
|
|
||||||
public void update(@RequestBody GaoRegistrationEvent registrationEvent) {
|
|
||||||
service.update(registrationEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_DELETE)
|
|
||||||
@PostMapping("/delete")
|
|
||||||
public void delete(@RequestParam String id) {
|
|
||||||
service.delete(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-174
@@ -1,174 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
|
||||||
import com.imyeyu.api.bean.RoleMatchMode;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoRole;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRecord;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoRegistrationEventRecordService;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventPeriodStatView;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerRegisterStatView;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordCreateReq;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordDailyStatView;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordPeriodReq;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordRangeReq;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordStatReq;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordTrendStatReq;
|
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
|
||||||
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
|
||||||
import com.imyeyu.spring.bean.Page;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// GAO 登记事件记录接口
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-27
|
|
||||||
@RestController
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@RequestMapping("/gao/registration-event-record")
|
|
||||||
@RequireGaoRole(value = {GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
|
|
||||||
public class GaoRegistrationEventRecordController {
|
|
||||||
|
|
||||||
private final GaoRegistrationEventRecordService service;
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_READ)
|
|
||||||
@PostMapping("/list")
|
|
||||||
public PageResult<GaoRegistrationEventRecord> list(@RequestBody Page<GaoRegistrationEventRecord> page) {
|
|
||||||
return service.page(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_READ)
|
|
||||||
@PostMapping("/range/page")
|
|
||||||
public PageResult<GaoRegistrationEventRecord> rangePage(@RequestBody Page<GaoRegistrationEventRecordRangeReq> page) {
|
|
||||||
return service.pageByRange(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_READ)
|
|
||||||
@PostMapping("/detail")
|
|
||||||
public GaoRegistrationEventRecord detail(@RequestParam String id) {
|
|
||||||
return service.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@PostMapping("/create")
|
|
||||||
public GaoRegistrationEventRecord create(@RequestBody GaoRegistrationEventRecordCreateReq req) {
|
|
||||||
return service.createRecord(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_UPDATE)
|
|
||||||
@PostMapping("/update")
|
|
||||||
public void update(@RequestBody GaoRegistrationEventRecord record) {
|
|
||||||
service.update(record);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_DELETE)
|
|
||||||
@PostMapping("/delete")
|
|
||||||
public void delete(@RequestParam String id) {
|
|
||||||
service.delete(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_READ)
|
|
||||||
@PostMapping("/period/list")
|
|
||||||
public List<GaoRegistrationEventRecord> periodList(@RequestBody GaoRegistrationEventRecordPeriodReq req) {
|
|
||||||
return service.listByRegistrationEventAndPeriod(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_READ)
|
|
||||||
@PostMapping("/range/list")
|
|
||||||
public List<GaoRegistrationEventRecord> rangeList(@RequestBody GaoRegistrationEventRecordRangeReq req) {
|
|
||||||
return service.listByRange(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@IgnoreGlobalReturn
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_READ)
|
|
||||||
@PostMapping("/range/export")
|
|
||||||
public void rangeExport(@RequestBody GaoRegistrationEventRecordRangeReq req, HttpServletResponse resp) throws IOException {
|
|
||||||
String fileName = URLEncoder.encode("登记事件记录.xlsx", "UTF-8").replace("+", "%20");
|
|
||||||
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
||||||
resp.setHeader("Content-Disposition", "attachment; filename=\"gao-registration-event-record.xlsx\"; filename*=UTF-8''" + fileName);
|
|
||||||
resp.getOutputStream().write(service.exportRangeExcel(req));
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
|
||||||
@PostMapping("/period/stat")
|
|
||||||
public List<GaoRegistrationEventPeriodStatView> periodStat(@RequestBody GaoRegistrationEventRecordPeriodReq req) {
|
|
||||||
return service.statByRegistrationEventAndPeriodType(req.getRegistrationEventId(), req.getPeriodType());
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
|
||||||
@PostMapping("/customer/stat")
|
|
||||||
public List<GaoCustomerRegisterStatView> customerStat(@RequestParam String customerId) {
|
|
||||||
return service.statByCustomerId(customerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
|
||||||
@PostMapping("/customer/range/stat")
|
|
||||||
/// 按时间段统计单个客户各登记事件记录数
|
|
||||||
public List<GaoCustomerRegisterStatView> customerRangeStat(@RequestBody GaoRegistrationEventRecordStatReq req) {
|
|
||||||
return service.statByCustomerAndRange(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
|
||||||
@PostMapping("/all-customer/range/stat")
|
|
||||||
/// 按时间段统计全部客户各登记事件记录数
|
|
||||||
public List<GaoCustomerRegisterStatView> allCustomerRangeStat(@RequestBody GaoRegistrationEventRecordStatReq req) {
|
|
||||||
return service.statAllCustomerByRange(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
|
||||||
@PostMapping("/customer/registration-event/daily/stat")
|
|
||||||
/// 按天统计单个客户单个登记事件记录趋势
|
|
||||||
public List<GaoRegistrationEventRecordDailyStatView> customerRegistrationEventDailyStat(@RequestBody GaoRegistrationEventRecordTrendStatReq req) {
|
|
||||||
return service.statDailyByCustomerAndRegistrationEvent(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
|
||||||
@PostMapping("/all-customer/registration-event/daily/stat")
|
|
||||||
/// 按天统计全部客户单个登记事件记录趋势
|
|
||||||
public List<GaoRegistrationEventRecordDailyStatView> allCustomerRegistrationEventDailyStat(@RequestBody GaoRegistrationEventRecordTrendStatReq req) {
|
|
||||||
return service.statDailyByRegistrationEvent(req);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.annotation.RequireCorePermission;
|
||||||
|
import com.imyeyu.api.bean.CorePermissionCode;
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoRole;
|
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
|
||||||
import com.imyeyu.api.modules.user.entity.Role;
|
import com.imyeyu.api.modules.user.entity.Role;
|
||||||
import com.imyeyu.api.modules.user.service.RoleService;
|
import com.imyeyu.api.modules.user.service.AuthorizationScopeService;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -14,23 +15,23 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
///
|
|
||||||
/// GAO 角色接口
|
/// GAO 角色接口
|
||||||
///
|
///
|
||||||
/// @author Codex
|
/// @author 夜雨
|
||||||
/// @since 2026-07-28
|
/// @since 2026-07-28 14:15
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping("/gao/role")
|
@RequestMapping("/gao/role")
|
||||||
@RequireGaoRole(GaoRoleCode.STORE_MANAGER)
|
|
||||||
public class GaoRoleController {
|
public class GaoRoleController {
|
||||||
|
|
||||||
private final RoleService roleService;
|
private final UserLoginService userLoginService;
|
||||||
|
private final AuthorizationScopeService authorizationScopeService;
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.ROLE_READ)
|
||||||
@PostMapping("/available/list")
|
@PostMapping("/available/list")
|
||||||
public List<Role> availableList() {
|
public List<Role> availableList() {
|
||||||
return roleService.listByModuleCode(ModuleCode.GAO);
|
return authorizationScopeService.listGrantableRole(userLoginService.getRequireLoginUserId(), ModuleCode.GAO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+79
@@ -0,0 +1,79 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoStoreBusinessDay;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreBusinessDayService;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// GAO 门店营业日接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-06
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/store/business/day")
|
||||||
|
public class GaoStoreBusinessDayController {
|
||||||
|
|
||||||
|
private final GaoStoreBusinessDayService service;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
public PageResult<GaoStoreBusinessDay> list(@RequestBody Page<GaoStoreBusinessDay> page) {
|
||||||
|
return service.page(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
||||||
|
@PostMapping("/calendar")
|
||||||
|
public List<GaoStoreBusinessDay> calendar(@RequestParam String storeId, @RequestParam Integer beginDateValue, @RequestParam Integer endDateValue) {
|
||||||
|
return service.listByDateRange(storeId, beginDateValue, endDateValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
public GaoStoreBusinessDay detail(@RequestParam String id) {
|
||||||
|
return service.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
||||||
|
@PostMapping("/create")
|
||||||
|
public String create(@RequestBody GaoStoreBusinessDay businessDay) {
|
||||||
|
service.create(businessDay);
|
||||||
|
return businessDay.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
||||||
|
@PostMapping("/update")
|
||||||
|
public void update(@RequestBody GaoStoreBusinessDay businessDay) {
|
||||||
|
service.update(businessDay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_DELETE)
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public void delete(@RequestParam String id) {
|
||||||
|
service.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreChartService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordCalendarView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoStoreChartReq;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// GAO 门店报表接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/store/chart")
|
||||||
|
public class GaoStoreChartController {
|
||||||
|
|
||||||
|
private final GaoStoreChartService service;
|
||||||
|
|
||||||
|
/// 查询客户增长趋势
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/customer/daily")
|
||||||
|
public List<GaoCustomerDailyStateView> customerDaily(@RequestBody GaoStoreChartReq req) {
|
||||||
|
return service.customerDailyTrend(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询客户性别统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/customer/gender")
|
||||||
|
public List<GaoCustomerGenderStatView> customerGender(@RequestParam String storeId) {
|
||||||
|
return service.customerGender(storeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询登记事件每日统计,可同时支撑登记趋势和事件结构图表
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/event/record/daily")
|
||||||
|
public List<GaoEventRecordDailyStatView> eventRecordDaily(@RequestBody GaoStoreChartReq req) {
|
||||||
|
return service.eventRecordDailyStat(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询登记事件日历记录
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/event/record/calendar")
|
||||||
|
public List<GaoEventRecordCalendarView> eventRecordCalendar(@RequestBody GaoStoreChartReq req) {
|
||||||
|
return service.eventRecordCalendar(req);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoStore;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||||
|
import com.imyeyu.api.modules.user.service.PermissionChecker;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.network.Network;
|
||||||
|
import com.imyeyu.spring.TimiSpring;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import com.imyeyu.utils.Time;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// GAO 门店接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-06
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/store")
|
||||||
|
public class GaoStoreController {
|
||||||
|
|
||||||
|
private final GaoStoreService service;
|
||||||
|
private final UserLoginService userLoginService;
|
||||||
|
private final PermissionChecker permissionChecker;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
public PageResult<GaoStore> list(@RequestBody Page<GaoStore> page) {
|
||||||
|
return service.page(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
public GaoStore detail(@RequestParam String id) {
|
||||||
|
return service.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_CREATE)
|
||||||
|
@PostMapping("/create")
|
||||||
|
public String create(@RequestBody GaoStore store) {
|
||||||
|
service.create(store);
|
||||||
|
return store.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
||||||
|
@PostMapping("/update")
|
||||||
|
public void update(@RequestBody GaoStore store) {
|
||||||
|
if (permissionChecker.hasAny(ModuleCode.GAO, GaoPermissionCode.STORE_CREATE.getValue())) {
|
||||||
|
// 门店管理
|
||||||
|
service.update(store);
|
||||||
|
} else {
|
||||||
|
// 店长
|
||||||
|
GaoStore dbStore = service.get(store.getId());
|
||||||
|
dbStore.setName(store.getName());
|
||||||
|
dbStore.setTelephone(store.getTelephone());
|
||||||
|
dbStore.setAddress(store.getAddress());
|
||||||
|
dbStore.setRemark(store.getRemark());
|
||||||
|
dbStore.setAutoClosedDay(TimiJava.defaultIfNull(store.getAutoClosedDay(), false));
|
||||||
|
service.update(dbStore);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_DELETE)
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public void delete(@RequestParam String id) {
|
||||||
|
service.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
||||||
|
@PostMapping("/sort")
|
||||||
|
public void sort(@RequestBody List<String> idList) {
|
||||||
|
service.sort(idList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@IgnoreGlobalReturn
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_EXPORT)
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(@RequestBody Page<GaoStore> page) throws IOException {
|
||||||
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
|
String contentDisposition = Network.getFileDownloadHeader("门店列表-%s.xlsx".formatted(Time.serialize.format(Time.now())));
|
||||||
|
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
|
resp.setHeader("Content-Disposition", contentDisposition);
|
||||||
|
resp.getOutputStream().write(service.export(page));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@PostMapping("/user")
|
||||||
|
public GaoStore getLoginStore() {
|
||||||
|
return service.getByUserId(userLoginService.getRequireLoginUserId());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
|
import com.imyeyu.api.annotation.RequireCorePermission;
|
||||||
|
import com.imyeyu.api.bean.CorePermissionCode;
|
||||||
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Tag;
|
||||||
|
import com.imyeyu.api.modules.common.entity.TagApply;
|
||||||
|
import com.imyeyu.api.modules.common.service.TagService;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||||
|
import com.imyeyu.api.modules.user.service.RoleChecker;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import com.imyeyu.spring.util.ResponseView;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// GAO 标签接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-13
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/tag")
|
||||||
|
public class GaoTagController {
|
||||||
|
|
||||||
|
private final TagService service;
|
||||||
|
private final RoleChecker roleChecker;
|
||||||
|
private final GaoStoreService storeService;
|
||||||
|
|
||||||
|
/// 查询标签列表
|
||||||
|
///
|
||||||
|
/// @param page 分页参数
|
||||||
|
/// @return 标签分页
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.TAG_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
public PageResult<Tag> list(@RequestBody Page<Tag> page) {
|
||||||
|
TimiException.required(page, "未找到分页参数");
|
||||||
|
page.setEqualsExample(TimiJava.defaultIfNull(page.getEqualsExample(), new Tag()));
|
||||||
|
page.getEqualsExample().setOwnerType(Tag.OwnerType.GAO_STORE);
|
||||||
|
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||||
|
page.getEqualsExample().setOwnerId(storeService.getBelongIdByRequiredLoginUserId());
|
||||||
|
}
|
||||||
|
return service.page(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询标签详情
|
||||||
|
///
|
||||||
|
/// @param id 标签 ID
|
||||||
|
/// @return 标签详情
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.TAG_READ)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
public Tag detail(@RequestParam String id) {
|
||||||
|
return service.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 创建标签
|
||||||
|
///
|
||||||
|
/// @param tag 标签
|
||||||
|
/// @return 标签
|
||||||
|
@AOPLog
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.TAG_CREATE)
|
||||||
|
@PostMapping("/create")
|
||||||
|
public Tag create(@RequestBody Tag tag) {
|
||||||
|
tag.setOwnerType(Tag.OwnerType.GAO_STORE);
|
||||||
|
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||||
|
tag.setOwnerId(storeService.getBelongIdByRequiredLoginUserId());
|
||||||
|
}
|
||||||
|
service.create(tag);
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 更新标签
|
||||||
|
///
|
||||||
|
/// @param tag 标签
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.TAG_UPDATE)
|
||||||
|
@PostMapping("/update")
|
||||||
|
public void update(@RequestBody Tag tag) {
|
||||||
|
Tag dbTag = service.get(tag.getId());
|
||||||
|
tag.setOwnerType(dbTag.getOwnerType());
|
||||||
|
tag.setOwnerId(dbTag.getOwnerId());
|
||||||
|
service.update(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 删除标签
|
||||||
|
///
|
||||||
|
/// @param id 标签 ID
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.TAG_DELETE)
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public void delete(@RequestParam String id) {
|
||||||
|
service.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 按业务查询标签
|
||||||
|
///
|
||||||
|
/// @param bizType 业务类型
|
||||||
|
/// @param bizId 业务 ID
|
||||||
|
/// @return 标签列表
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.TAG_READ)
|
||||||
|
@GetMapping("/list/biz/id")
|
||||||
|
public List<Tag> listByBizType(@RequestParam TagApply.BizType bizType, @RequestParam String bizId) {
|
||||||
|
return service.listByBizType(bizType, bizId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 差分保存业务标签
|
||||||
|
///
|
||||||
|
/// @param apply 标签请求
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.TAG_APPLY)
|
||||||
|
@PostMapping("/apply")
|
||||||
|
public void apply(@RequestBody TagApply apply) {
|
||||||
|
service.apply(apply.getBizType(), apply.getBizId(), apply.getTagIdList());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,38 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoRole;
|
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoUserInviteService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoUserService;
|
import com.imyeyu.api.modules.gao.service.GaoUserService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoUserInviteCreateRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoUserInviteCreateResponse;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoUserInviteRegisterData;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoUserInviteRegisterRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoUserInviteValidateRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoUserInviteValidateResponse;
|
||||||
import com.imyeyu.api.modules.user.entity.Role;
|
import com.imyeyu.api.modules.user.entity.Role;
|
||||||
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
|
import com.imyeyu.api.modules.user.service.RoleChecker;
|
||||||
import com.imyeyu.api.modules.user.service.RoleService;
|
import com.imyeyu.api.modules.user.service.RoleService;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserRoleService;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserService;
|
||||||
|
import com.imyeyu.api.modules.user.vo.LoginResponse;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.CaptchaValid;
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
import com.imyeyu.spring.bean.Page;
|
import com.imyeyu.spring.bean.Page;
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import com.imyeyu.spring.util.ResponseView;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
@@ -21,50 +41,103 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
///
|
|
||||||
/// GAO 用户接口
|
/// GAO 用户接口
|
||||||
///
|
///
|
||||||
/// @author Codex
|
/// @author 夜雨
|
||||||
/// @since 2026-07-30
|
/// @since 2026-07-30 14:15
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping("/gao/user")
|
@RequestMapping("/gao/user")
|
||||||
@RequireGaoRole(GaoRoleCode.STORE_MANAGER)
|
|
||||||
public class GaoUserController {
|
public class GaoUserController {
|
||||||
|
|
||||||
private final GaoUserService service;
|
private final UserService userService;
|
||||||
private final RoleService roleService;
|
private final RoleService roleService;
|
||||||
|
private final RoleChecker roleChecker;
|
||||||
|
private final GaoUserService service;
|
||||||
|
private final GaoUserInviteService inviteService;
|
||||||
|
private final UserRoleService userRoleService;
|
||||||
|
private final GaoStoreService gaoStoreService;
|
||||||
|
private final UserLoginService userLoginService;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.USER_CREATE)
|
||||||
|
@PostMapping("/invite")
|
||||||
|
public GaoUserInviteCreateResponse invite(@RequestBody @Valid GaoUserInviteCreateRequest req) {
|
||||||
|
return inviteService.create(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit(20)
|
||||||
|
@PostMapping("/invite/validate")
|
||||||
|
public GaoUserInviteValidateResponse validateInvite(@RequestBody @Valid GaoUserInviteValidateRequest req) {
|
||||||
|
return inviteService.validate(req.getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@CaptchaValid
|
||||||
|
@RequestRateLimit(value = 5, inSeconds = 60)
|
||||||
|
@PostMapping("/invite/register")
|
||||||
|
public LoginResponse registerByInvite(@RequestBody @Valid GaoUserInviteRegisterRequest req) {
|
||||||
|
GaoUserInviteRegisterData data = req.getData();
|
||||||
|
String userId = inviteService.register(data);
|
||||||
|
return userLoginService.login(UUID.randomUUID().toString(), userId);
|
||||||
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.USER_READ)
|
@RequireGaoPermission(GaoPermissionCode.USER_READ)
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
public PageResult<GaoUser> list(@RequestBody Page<GaoUser> page) {
|
public PageResult<GaoUser> list(@RequestBody Page<GaoUser> page) {
|
||||||
return service.pageWithUser(page);
|
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||||
|
// 非全局管理只能看所在店用户
|
||||||
|
page.setEqualsExample(TimiJava.defaultIfNull(page.getEqualsExample(), new GaoUser()));
|
||||||
|
page.getEqualsExample().setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
||||||
|
}
|
||||||
|
PageResult<GaoUser> result = service.page(page);
|
||||||
|
{
|
||||||
|
List<String> userIdList = result.getList().stream().map(GaoUser::getUserId).toList();
|
||||||
|
Map<String, User> userMap = userService.mapByIdList(userIdList);
|
||||||
|
Map<String, List<Role>> roleMap = userRoleService.mapRoleListByUserIdList(userIdList);
|
||||||
|
for (GaoUser gaoUser : result.getList()) {
|
||||||
|
gaoUser.setUser(userMap.get(gaoUser.getUserId()));
|
||||||
|
gaoUser.getUser().setRoleEntityList(roleMap.get(gaoUser.getUserId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.USER_READ)
|
@RequireGaoPermission(GaoPermissionCode.USER_READ)
|
||||||
@PostMapping("/detail")
|
@PostMapping("/detail")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
public GaoUser detail(@RequestParam String id) {
|
public GaoUser detail(@RequestParam String id) {
|
||||||
return service.get(id);
|
GaoUser result = service.get(id);
|
||||||
}
|
{
|
||||||
|
User user = userService.get(result.getUserId());
|
||||||
@AOPLog
|
user.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.USER, user.getId()));
|
||||||
@RequestRateLimit
|
user.setRoleEntityList(userRoleService.listRoleByUserId(user.getId()));
|
||||||
@RequireGaoPermission(GaoPermissionCode.USER_READ)
|
result.setUser(user);
|
||||||
@PostMapping("/detail/user")
|
}
|
||||||
public GaoUser detailByUserId(@RequestParam String userId) {
|
return result;
|
||||||
return service.getByUserId(userId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.USER_CREATE)
|
@RequireGaoPermission(GaoPermissionCode.USER_CREATE)
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
public GaoUser create(@RequestBody GaoUser gaoUser) {
|
public GaoUser create(@RequestBody GaoUser gaoUser) {
|
||||||
|
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||||
|
gaoUser.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
||||||
|
}
|
||||||
service.create(gaoUser);
|
service.create(gaoUser);
|
||||||
return service.get(gaoUser.getId());
|
return service.get(gaoUser.getId());
|
||||||
}
|
}
|
||||||
@@ -73,11 +146,22 @@ public class GaoUserController {
|
|||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.USER_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.USER_UPDATE)
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
public GaoUser update(@RequestBody GaoUser gaoUser) {
|
public GaoUser update(@RequestBody GaoUser gaoUser) {
|
||||||
service.update(gaoUser);
|
service.update(gaoUser);
|
||||||
return service.get(gaoUser.getId());
|
return service.get(gaoUser.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.USER_UPDATE)
|
||||||
|
@PostMapping("/transfer/store")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public GaoUser transferStore(@RequestBody GaoUser gaoUser) {
|
||||||
|
service.transferStore(gaoUser);
|
||||||
|
return service.get(gaoUser.getId());
|
||||||
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.USER_DELETE)
|
@RequireGaoPermission(GaoPermissionCode.USER_DELETE)
|
||||||
@@ -91,6 +175,7 @@ public class GaoUserController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.USER_READ)
|
@RequireGaoPermission(GaoPermissionCode.USER_READ)
|
||||||
@PostMapping("/role/list")
|
@PostMapping("/role/list")
|
||||||
public List<Role> roleList() {
|
public List<Role> roleList() {
|
||||||
|
// TODO 此接口获取本模块所有角色,需要限制角色
|
||||||
return roleService.listByModuleCode(ModuleCode.GAO);
|
return roleService.listByModuleCode(ModuleCode.GAO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
package com.imyeyu.api.modules.gao.entity;
|
package com.imyeyu.api.modules.gao.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.user.bean.Gender;
|
import com.imyeyu.api.modules.user.bean.Gender;
|
||||||
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.spring.annotation.table.Transient;
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -29,9 +33,24 @@ public class GaoCustomer extends UUIDEntity {
|
|||||||
PHOTO
|
PHOTO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 出生日期使用的历法
|
||||||
|
///
|
||||||
|
public enum BirthdateCalendar {
|
||||||
|
|
||||||
|
/// 公历
|
||||||
|
SOLAR,
|
||||||
|
|
||||||
|
/// 农历
|
||||||
|
LUNAR
|
||||||
|
}
|
||||||
|
|
||||||
/// 客户编码
|
/// 客户编码
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
|
/// 门店 ID
|
||||||
|
private String storeId;
|
||||||
|
|
||||||
/// 姓名
|
/// 姓名
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@@ -39,7 +58,14 @@ public class GaoCustomer extends UUIDEntity {
|
|||||||
private Gender gender;
|
private Gender gender;
|
||||||
|
|
||||||
/// 年龄
|
/// 年龄
|
||||||
private Integer age;
|
private Long age;
|
||||||
|
|
||||||
|
/// 出生日期,数据库只保存公历日期
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
|
private LocalDate birthdate;
|
||||||
|
|
||||||
|
/// 出生日期录入时使用的历法
|
||||||
|
private BirthdateCalendar birthdateCalendar;
|
||||||
|
|
||||||
/// 电话
|
/// 电话
|
||||||
private String telephone;
|
private String telephone;
|
||||||
@@ -59,19 +85,27 @@ public class GaoCustomer extends UUIDEntity {
|
|||||||
/// 介绍人客户 ID
|
/// 介绍人客户 ID
|
||||||
private String introducerCustomerId;
|
private String introducerCustomerId;
|
||||||
|
|
||||||
@Transient
|
private Long invitedCount;
|
||||||
private Long lastSignInAt;
|
|
||||||
|
/// 录入用户 ID
|
||||||
|
private String creatorUserId;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private GaoCustomer introducerCustomer;
|
private GaoCustomer introducerCustomer;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private Long invitedCount;
|
private User creatorUser;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private List<Attachment> attachmentList;
|
private List<Attachment> attachmentList;
|
||||||
|
|
||||||
/// 临时照片附件 ID 列表
|
|
||||||
@Transient
|
@Transient
|
||||||
private List<String> attachmentIdList;
|
private GaoEventRecord eventRecord;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private List<GaoEventRecord> eventRecordList;
|
||||||
|
|
||||||
|
public boolean hasIntroducer() {
|
||||||
|
return TimiJava.isNotEmpty(introducerCustomerId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.entity;
|
||||||
|
|
||||||
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class GaoEvent extends UUIDEntity {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件状态
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-01
|
||||||
|
public enum Status {
|
||||||
|
|
||||||
|
/// 草稿,未发布不可登记
|
||||||
|
DRAFT,
|
||||||
|
|
||||||
|
/// 可登记
|
||||||
|
ACTIVE,
|
||||||
|
|
||||||
|
/// 无效,不可登记但保留统计
|
||||||
|
INACTIVE,
|
||||||
|
|
||||||
|
/// 已删除,不可登记但保留统计
|
||||||
|
DELETED
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 事件数值类型
|
||||||
|
public enum ValueType {
|
||||||
|
|
||||||
|
/// 不携带数值
|
||||||
|
NONE,
|
||||||
|
|
||||||
|
/// 携带整数数值
|
||||||
|
NUMBER
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 事件数值单位
|
||||||
|
public enum ValueUnit {
|
||||||
|
|
||||||
|
/// 金额分
|
||||||
|
CENT,
|
||||||
|
|
||||||
|
/// 次数
|
||||||
|
COUNT
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 登记限制类型
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-01 14:37
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum LimitType {
|
||||||
|
|
||||||
|
/// 不限制
|
||||||
|
NONE(null),
|
||||||
|
|
||||||
|
/// 每天上午、下午各 N 次
|
||||||
|
DAILY_HALF_DAY(1L),
|
||||||
|
|
||||||
|
/// 每个自然日 N 次
|
||||||
|
NATURAL_DAY(1L),
|
||||||
|
|
||||||
|
/// 每隔 N 小时一次
|
||||||
|
INTERVAL_HOUR(1L),
|
||||||
|
|
||||||
|
/// 每个自然月 N 次
|
||||||
|
NATURAL_MONTH(1L),
|
||||||
|
|
||||||
|
/// 事件总登记次数上限
|
||||||
|
TOTAL_LIMIT(1L),
|
||||||
|
|
||||||
|
/// 单个客户总登记次数上限
|
||||||
|
CUSTOMER_TOTAL_LIMIT(1L);
|
||||||
|
|
||||||
|
final Long min;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 统计图表颜色
|
||||||
|
private String color;
|
||||||
|
|
||||||
|
/// 登记事件名称
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/// 门店 ID
|
||||||
|
private String storeId;
|
||||||
|
|
||||||
|
/// 说明
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/// 数值类型
|
||||||
|
private ValueType valueType;
|
||||||
|
|
||||||
|
/// 数值单位
|
||||||
|
private ValueUnit valueUnit;
|
||||||
|
|
||||||
|
/// true 为登记时必须提交 numberValue
|
||||||
|
private Boolean requireValue;
|
||||||
|
|
||||||
|
/// 状态
|
||||||
|
private Status status;
|
||||||
|
|
||||||
|
/// true 为登记时要求拍照
|
||||||
|
private Boolean requirePhoto;
|
||||||
|
|
||||||
|
/// 登记限制类型
|
||||||
|
private LimitType limitType;
|
||||||
|
|
||||||
|
/// 登记限制数值,按限制类型表示小时数或次数
|
||||||
|
private Integer limitValue;
|
||||||
|
|
||||||
|
/// 可登记起始时间戳,毫秒,空为不限制
|
||||||
|
private Long beginAt;
|
||||||
|
|
||||||
|
/// 可登记终止时间戳,毫秒,空为不限制
|
||||||
|
private Long endAt;
|
||||||
|
|
||||||
|
/// 排序值
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
/// 可登记角色代码列表
|
||||||
|
@Transient
|
||||||
|
private List<String> roleCodeList;
|
||||||
|
}
|
||||||
+23
-5
@@ -16,7 +16,7 @@ import java.util.List;
|
|||||||
/// @since 2026-07-27
|
/// @since 2026-07-27
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class GaoRegistrationEventRecord extends UUIDEntity {
|
public class GaoEventRecord extends UUIDEntity {
|
||||||
|
|
||||||
///
|
///
|
||||||
/// 登记事件记录附件类型
|
/// 登记事件记录附件类型
|
||||||
@@ -31,23 +31,41 @@ public class GaoRegistrationEventRecord extends UUIDEntity {
|
|||||||
/// 客户 ID
|
/// 客户 ID
|
||||||
private String customerId;
|
private String customerId;
|
||||||
|
|
||||||
|
/// 门店 ID
|
||||||
|
private String storeId;
|
||||||
|
|
||||||
/// 登记登记事件 ID
|
/// 登记登记事件 ID
|
||||||
private String registrationEventId;
|
private String eventId;
|
||||||
|
|
||||||
/// 操作管理员用户 ID
|
/// 操作管理员用户 ID
|
||||||
private String operatorUserId;
|
private String operatorUserId;
|
||||||
|
|
||||||
|
/// 本次登记提交的积分值
|
||||||
|
private Long pointValue;
|
||||||
|
|
||||||
|
/// 本次登记通过积分规则获得的积分总和
|
||||||
|
private Long earnedPointValue;
|
||||||
|
|
||||||
|
/// 本次登记提交的整数业务数值
|
||||||
|
private Long numberValue;
|
||||||
|
|
||||||
/// 备注
|
/// 备注
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
/// 登记时间
|
/// 登记时间
|
||||||
private Long registeredAt;
|
private Long registeredAt;
|
||||||
|
|
||||||
|
/// 登记日期值,格式为 yyyyMMdd
|
||||||
|
private Integer registeredDateValue;
|
||||||
|
|
||||||
|
/// 营业日递增序号
|
||||||
|
private Long businessDayNo;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private GaoCustomer customer;
|
private GaoCustomer customer;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private GaoRegistrationEvent registrationEvent;
|
private GaoEvent event;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private User operator;
|
private User operator;
|
||||||
@@ -55,7 +73,7 @@ public class GaoRegistrationEventRecord extends UUIDEntity {
|
|||||||
@Transient
|
@Transient
|
||||||
private List<Attachment> attachmentList;
|
private List<Attachment> attachmentList;
|
||||||
|
|
||||||
/// 临时照片附件 ID 列表
|
/// 客户 ID 列表,批量登记时使用
|
||||||
@Transient
|
@Transient
|
||||||
private List<String> attachmentIdList;
|
private List<String> customerIdList;
|
||||||
}
|
}
|
||||||
+2
-2
@@ -11,10 +11,10 @@ import lombok.EqualsAndHashCode;
|
|||||||
/// @since 2026-07-28
|
/// @since 2026-07-28
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class GaoRegistrationEventRoleRelation extends UUIDEntity {
|
public class GaoEventRoleRelation extends UUIDEntity {
|
||||||
|
|
||||||
/// 登记事件 ID
|
/// 登记事件 ID
|
||||||
private String registrationEventId;
|
private String eventId;
|
||||||
|
|
||||||
/// 角色代码
|
/// 角色代码
|
||||||
private String roleCode;
|
private String roleCode;
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.entity;
|
||||||
|
|
||||||
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/// GAO 客户积分账户
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class GaoPointAccount extends UUIDEntity {
|
||||||
|
|
||||||
|
/// 门店 ID
|
||||||
|
private String storeId;
|
||||||
|
|
||||||
|
/// 客户 ID
|
||||||
|
private String customerId;
|
||||||
|
|
||||||
|
/// 当前可用积分余额
|
||||||
|
private Long balance;
|
||||||
|
|
||||||
|
/// 累计获得积分
|
||||||
|
private Long totalEarned;
|
||||||
|
|
||||||
|
/// 累计撤销积分
|
||||||
|
private Long totalRevoked;
|
||||||
|
|
||||||
|
/// 累计人工调整积分,可正可负
|
||||||
|
private Long totalAdjusted;
|
||||||
|
|
||||||
|
/// 乐观锁版本
|
||||||
|
private Long version;
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/// GAO 客户积分流水
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class GaoPointLedger extends UUIDEntity {
|
||||||
|
|
||||||
|
/// 流水变化类型
|
||||||
|
public enum ChangeType {
|
||||||
|
|
||||||
|
/// 登记事件获得积分
|
||||||
|
EARN,
|
||||||
|
|
||||||
|
/// 删除登记记录撤销积分
|
||||||
|
REVOKE,
|
||||||
|
|
||||||
|
/// 人工调整积分
|
||||||
|
ADJUST
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 流水方向
|
||||||
|
public enum Direction {
|
||||||
|
|
||||||
|
/// 增加积分
|
||||||
|
INCREASE,
|
||||||
|
|
||||||
|
/// 减少积分
|
||||||
|
DECREASE
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 客户积分账户 ID
|
||||||
|
private String accountId;
|
||||||
|
|
||||||
|
/// 门店 ID
|
||||||
|
private String storeId;
|
||||||
|
|
||||||
|
/// 客户 ID
|
||||||
|
private String customerId;
|
||||||
|
|
||||||
|
/// 变化类型
|
||||||
|
private ChangeType changeType;
|
||||||
|
|
||||||
|
/// 方向
|
||||||
|
private Direction direction;
|
||||||
|
|
||||||
|
/// 本次变化积分,增加为正,减少为负
|
||||||
|
private Long pointDelta;
|
||||||
|
|
||||||
|
/// 变化前余额
|
||||||
|
private Long balanceBefore;
|
||||||
|
|
||||||
|
/// 变化后余额
|
||||||
|
private Long balanceAfter;
|
||||||
|
|
||||||
|
/// 命中的积分规则 ID
|
||||||
|
private String ruleId;
|
||||||
|
|
||||||
|
/// 登记事件 ID
|
||||||
|
private String eventId;
|
||||||
|
|
||||||
|
/// 登记记录 ID
|
||||||
|
private String eventRecordId;
|
||||||
|
|
||||||
|
/// 来源快照
|
||||||
|
private JsonNode sourcePayload;
|
||||||
|
|
||||||
|
/// 幂等键
|
||||||
|
private String idempotencyKey;
|
||||||
|
|
||||||
|
/// 备注
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/// 操作用户 ID
|
||||||
|
private String operatorUserId;
|
||||||
|
|
||||||
|
/// 发生时间
|
||||||
|
private Long occurredAt;
|
||||||
|
|
||||||
|
/// 客户信息
|
||||||
|
@Transient
|
||||||
|
private GaoCustomer customer;
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/// GAO 客户积分规则
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class GaoPointRule extends UUIDEntity {
|
||||||
|
|
||||||
|
/// 规则状态
|
||||||
|
public enum Status {
|
||||||
|
|
||||||
|
/// 草稿,不参与触发
|
||||||
|
DRAFT,
|
||||||
|
|
||||||
|
/// 启用,参与触发
|
||||||
|
ACTIVE,
|
||||||
|
|
||||||
|
/// 停用,不参与触发
|
||||||
|
INACTIVE,
|
||||||
|
|
||||||
|
/// 已删除,不参与触发
|
||||||
|
DELETED
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 触发类型
|
||||||
|
public enum TriggerType {
|
||||||
|
|
||||||
|
/// 每登记一次触发一次
|
||||||
|
EVERY_TIME,
|
||||||
|
|
||||||
|
/// 客户首次登记该事件触发一次
|
||||||
|
FIRST_TIME,
|
||||||
|
|
||||||
|
/// 客户累计登记达到 N 次后每次触发
|
||||||
|
AFTER_COUNT_EVERY_TIME,
|
||||||
|
|
||||||
|
/// 使用登记接口提交的积分值触发
|
||||||
|
SOURCE_VALUE,
|
||||||
|
|
||||||
|
/// 按来源事件数值累计分档触发
|
||||||
|
CUSTOMER_EVENT_VALUE_TIER
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 积分值模式
|
||||||
|
public enum PointMode {
|
||||||
|
|
||||||
|
/// 使用规则固定积分值
|
||||||
|
FIXED,
|
||||||
|
|
||||||
|
/// 使用登记接口提交的积分值
|
||||||
|
SOURCE_VALUE,
|
||||||
|
|
||||||
|
/// 使用条件配置中的分档积分值
|
||||||
|
TIER
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 门店 ID
|
||||||
|
private String storeId;
|
||||||
|
|
||||||
|
/// 登记事件 ID
|
||||||
|
private String eventId;
|
||||||
|
|
||||||
|
/// 规则名称
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/// 规则状态
|
||||||
|
private Status status;
|
||||||
|
|
||||||
|
/// 触发类型
|
||||||
|
private TriggerType triggerType;
|
||||||
|
|
||||||
|
/// 积分值模式
|
||||||
|
private PointMode pointMode;
|
||||||
|
|
||||||
|
/// 固定积分值
|
||||||
|
private Long pointValue;
|
||||||
|
|
||||||
|
/// 条件配置
|
||||||
|
private JsonNode conditionJson;
|
||||||
|
|
||||||
|
/// 生效开始时间戳,毫秒,空为不限制
|
||||||
|
private Long beginAt;
|
||||||
|
|
||||||
|
/// 生效结束时间戳,毫秒,空为不限制
|
||||||
|
private Long endAt;
|
||||||
|
|
||||||
|
/// 优先级,数值小优先
|
||||||
|
private Integer priority;
|
||||||
|
|
||||||
|
/// true 为命中后停止继续匹配后续规则
|
||||||
|
private Boolean exclusive;
|
||||||
|
|
||||||
|
/// 备注
|
||||||
|
private String remark;
|
||||||
|
}
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.entity;
|
|
||||||
|
|
||||||
import com.imyeyu.spring.annotation.table.Transient;
|
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 登记事件
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-27
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class GaoRegistrationEvent extends UUIDEntity {
|
|
||||||
|
|
||||||
/// 登记事件名称
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/// 说明
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
/// true 为启用
|
|
||||||
private Boolean enabled;
|
|
||||||
|
|
||||||
/// true 为登记时要求拍照
|
|
||||||
private Boolean requirePhoto;
|
|
||||||
|
|
||||||
/// 排序值
|
|
||||||
private Integer sort;
|
|
||||||
|
|
||||||
/// 可登记角色代码列表
|
|
||||||
@Transient
|
|
||||||
private List<String> roleCodeList;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.entity;
|
||||||
|
|
||||||
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// GAO 门店
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-06
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class GaoStore extends UUIDEntity {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 门店状态
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-06
|
||||||
|
public enum Status {
|
||||||
|
|
||||||
|
/// 可用
|
||||||
|
ACTIVE,
|
||||||
|
|
||||||
|
/// 停用
|
||||||
|
INACTIVE,
|
||||||
|
|
||||||
|
/// 已删除
|
||||||
|
DELETED
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 门店编码
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/// 门店名称
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/// 状态
|
||||||
|
private Status status;
|
||||||
|
|
||||||
|
/// 电话
|
||||||
|
private String telephone;
|
||||||
|
|
||||||
|
/// 地址
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
/// 备注
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/// true 为启用自动计算营业日休息日
|
||||||
|
private Boolean autoClosedDay;
|
||||||
|
|
||||||
|
/// 排序值
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
public boolean isActivated() {
|
||||||
|
return status == Status.ACTIVE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.entity;
|
||||||
|
|
||||||
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// GAO 门店营业日
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-06
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class GaoStoreBusinessDay extends UUIDEntity {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 营业状态
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-06
|
||||||
|
public enum Status {
|
||||||
|
|
||||||
|
/// 营业
|
||||||
|
OPEN,
|
||||||
|
|
||||||
|
/// 休息
|
||||||
|
CLOSED
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 门店 ID
|
||||||
|
private String storeId;
|
||||||
|
|
||||||
|
/// 日期值,格式为 yyyyMMdd
|
||||||
|
private Integer dateValue;
|
||||||
|
|
||||||
|
/// 营业状态
|
||||||
|
private Status status;
|
||||||
|
|
||||||
|
/// 营业日递增序号,仅营业日有值
|
||||||
|
private Long businessDayNo;
|
||||||
|
|
||||||
|
/// 原因
|
||||||
|
private String reason;
|
||||||
|
}
|
||||||
@@ -1,14 +1,11 @@
|
|||||||
package com.imyeyu.api.modules.gao.entity;
|
package com.imyeyu.api.modules.gao.entity;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.user.entity.User;
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
import com.imyeyu.api.modules.user.entity.Role;
|
|
||||||
import com.imyeyu.spring.annotation.table.Transient;
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// GAO 用户
|
/// GAO 用户
|
||||||
///
|
///
|
||||||
@@ -21,6 +18,9 @@ public class GaoUser extends UUIDEntity {
|
|||||||
/// 用户 ID
|
/// 用户 ID
|
||||||
private String userId;
|
private String userId;
|
||||||
|
|
||||||
|
/// 门店 ID
|
||||||
|
private String storeId;
|
||||||
|
|
||||||
/// true 为启用
|
/// true 为启用
|
||||||
private Boolean enabled;
|
private Boolean enabled;
|
||||||
|
|
||||||
@@ -29,10 +29,4 @@ public class GaoUser extends UUIDEntity {
|
|||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
@Transient
|
|
||||||
private List<Role> roleList;
|
|
||||||
|
|
||||||
@Transient
|
|
||||||
private List<String> roleIdList;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package com.imyeyu.api.modules.gao.mapper;
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStatView;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerPage;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.Select;
|
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -15,32 +17,35 @@ import java.util.List;
|
|||||||
/// @since 2026-07-27
|
/// @since 2026-07-27
|
||||||
public interface GaoCustomerMapper extends BaseMapper<GaoCustomer, String> {
|
public interface GaoCustomerMapper extends BaseMapper<GaoCustomer, String> {
|
||||||
|
|
||||||
@Select("SELECT * FROM `gao_customer` WHERE `code` = #{code} AND `deleted_at` IS NULL LIMIT 1")
|
List<GaoCustomer> selectByIdList(Collection<String> idList);
|
||||||
GaoCustomer selectByCode(@Param("code") String code);
|
|
||||||
|
|
||||||
@Select("SELECT * FROM `gao_customer` WHERE `name` = #{name} AND `deleted_at` IS NULL LIMIT 1")
|
|
||||||
GaoCustomer selectByName(@Param("name") String name);
|
|
||||||
|
|
||||||
List<GaoCustomer> search(@Param("keyword") String keyword, @Param("introducerCustomerId") String introducerCustomerId);
|
|
||||||
|
|
||||||
Long countSearch(@Param("keyword") String keyword, @Param("introducerCustomerId") String introducerCustomerId);
|
|
||||||
|
|
||||||
List<GaoCustomer> searchPage(@Param("keyword") String keyword, @Param("introducerCustomerId") String introducerCustomerId, @Param("offset") Long offset, @Param("size") Long size);
|
|
||||||
|
|
||||||
List<GaoCustomer> selectInvitedList(@Param("introducerCustomerId") String introducerCustomerId);
|
|
||||||
|
|
||||||
Long countInvited(@Param("introducerCustomerId") String introducerCustomerId);
|
|
||||||
|
|
||||||
/// 统计每日新增客户数
|
/// 统计每日新增客户数
|
||||||
///
|
///
|
||||||
/// @param beginCreatedAt 开始创建时间
|
/// @param beginCreatedAt 开始创建时间
|
||||||
/// @param endCreatedAt 结束创建时间
|
/// @param endCreatedAt 结束创建时间
|
||||||
/// @return 每日新增客户数
|
/// @return 每日新增客户数
|
||||||
List<GaoCustomerDailyStatView> statDailyNewCustomer(@Param("beginCreatedAt") Long beginCreatedAt, @Param("endCreatedAt") Long endCreatedAt);
|
List<GaoCustomerDailyStateView> stateDailyNewCustomer(@Param("storeId") String storeId, @Param("beginCreatedAt") Long beginCreatedAt, @Param("endCreatedAt") Long endCreatedAt);
|
||||||
|
|
||||||
/// 统计开始时间前客户总数
|
/// 统计开始时间前客户总数
|
||||||
///
|
///
|
||||||
/// @param beginCreatedAt 开始创建时间
|
/// @param beginCreatedAt 开始创建时间
|
||||||
/// @return 客户总数
|
/// @return 客户总数
|
||||||
Long countCreatedBefore(@Param("beginCreatedAt") Long beginCreatedAt);
|
Long countCreatedBefore(@Param("storeId") String storeId, @Param("beginCreatedAt") Long beginCreatedAt);
|
||||||
|
|
||||||
|
/// 统计客户性别分布
|
||||||
|
///
|
||||||
|
/// @return 性别统计列表
|
||||||
|
List<GaoCustomerGenderStatView> stateGender(@Param("storeId") String storeId);
|
||||||
|
|
||||||
|
/// 查询客户总数
|
||||||
|
///
|
||||||
|
/// @param page 查询条件
|
||||||
|
/// @return 客户总数
|
||||||
|
long countByQuery(GaoCustomerPage page);
|
||||||
|
|
||||||
|
/// 分页查询客户
|
||||||
|
///
|
||||||
|
/// @param page 查询条件
|
||||||
|
/// @return 客户列表
|
||||||
|
List<GaoCustomer> selectByQuery(GaoCustomerPage page);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件 Mapper
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-07-27 15:53
|
||||||
|
public interface GaoEventMapper extends BaseMapper<GaoEvent, String> {
|
||||||
|
|
||||||
|
List<GaoEvent> selectByIdList(Collection<String> idList);
|
||||||
|
|
||||||
|
List<GaoEvent> selectValidList(@Param("storeId") String storeId, @Param("now") Long now);
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerChartReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerEventRankView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordCalendarView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordPage;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordRankPage;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoStoreChartReq;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// 登记事件记录 Mapper
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-07-27 14:11
|
||||||
|
public interface GaoEventRecordMapper extends BaseMapper<GaoEventRecord, String> {
|
||||||
|
|
||||||
|
Long count(String storeId, String customerId, String eventId, Long beginAt, Long endAt);
|
||||||
|
|
||||||
|
/// 查询事件中已携带数值的登记记录数量
|
||||||
|
///
|
||||||
|
/// @param eventId 事件 ID
|
||||||
|
/// @return 携带数值的登记记录数量
|
||||||
|
Long countByEventIdAndNumberValue(String eventId);
|
||||||
|
|
||||||
|
/// 汇总客户指定来源事件在时间范围内的数值
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param customerId 客户 ID
|
||||||
|
/// @param eventId 来源事件 ID
|
||||||
|
/// @param beginAt 起始时间,包含
|
||||||
|
/// @param endAt 结束时间,不包含
|
||||||
|
/// @return 数值总和
|
||||||
|
Long sumNumberValue(@Param("storeId") String storeId, @Param("customerId") String customerId, @Param("eventId") String eventId, @Param("beginAt") Long beginAt, @Param("endAt") Long endAt);
|
||||||
|
|
||||||
|
/// 回写登记记录最终获得的积分快照
|
||||||
|
///
|
||||||
|
/// @param id 登记记录 ID
|
||||||
|
/// @param earnedPointValue 获得积分总和
|
||||||
|
void updateEarnedPointValue(@Param("id") String id, @Param("earnedPointValue") Long earnedPointValue);
|
||||||
|
|
||||||
|
/// 按门店和登记日期统计登记记录数
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param registeredDateValue 登记日期值,格式为 yyyyMMdd
|
||||||
|
/// @return 登记记录数
|
||||||
|
Long countByStoreIdAndRegisteredDateValue(@Param("storeId") String storeId, @Param("registeredDateValue") Integer registeredDateValue);
|
||||||
|
|
||||||
|
/// 同步门店指定日期的登记记录营业日序号快照
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param registeredDateValue 登记日期值,格式为 yyyyMMdd
|
||||||
|
/// @param businessDayNo 营业日序号
|
||||||
|
void updateBusinessDayNoByStoreIdAndRegisteredDateValue(@Param("storeId") String storeId, @Param("registeredDateValue") Integer registeredDateValue, @Param("businessDayNo") Long businessDayNo);
|
||||||
|
|
||||||
|
long countByRange(GaoEventRecordPage page);
|
||||||
|
|
||||||
|
/// 按任意时间范围查询登记事件记录
|
||||||
|
///
|
||||||
|
/// @return 登记事件记录列表
|
||||||
|
List<GaoEventRecord> selectByRange(GaoEventRecordPage page);
|
||||||
|
|
||||||
|
/// 按登记记录列表条件汇总数值
|
||||||
|
///
|
||||||
|
/// @param page 登记记录范围查询请求
|
||||||
|
/// @return 登记数值合计
|
||||||
|
Long sumNumberValueByRange(GaoEventRecordPage page);
|
||||||
|
|
||||||
|
/// 统计客户登记排行榜总数
|
||||||
|
///
|
||||||
|
/// @param page 排行榜分页请求
|
||||||
|
/// @return 客户数
|
||||||
|
long countRankByRange(GaoEventRecordRankPage page);
|
||||||
|
|
||||||
|
/// 分页查询客户登记排行榜
|
||||||
|
///
|
||||||
|
/// @param page 排行榜分页请求
|
||||||
|
/// @return 客户登记排行榜
|
||||||
|
List<GaoCustomerEventRankView> selectRankByRange(GaoEventRecordRankPage page);
|
||||||
|
|
||||||
|
/// 按时间范围和事件批量统计每日登记数
|
||||||
|
///
|
||||||
|
/// @param req 门店报表查询请求
|
||||||
|
/// @return 每日登记数
|
||||||
|
List<GaoEventRecordDailyStatView> stateDailyByRange(GaoStoreChartReq req);
|
||||||
|
|
||||||
|
/// 按时间范围查询登记日历记录
|
||||||
|
///
|
||||||
|
/// @param req 门店报表查询请求
|
||||||
|
/// @return 日历记录列表
|
||||||
|
List<GaoEventRecordCalendarView> selectCalendarByRange(GaoStoreChartReq req);
|
||||||
|
|
||||||
|
/// 按客户、时间范围和事件批量统计每日登记数
|
||||||
|
///
|
||||||
|
/// @param req 客户报表查询请求
|
||||||
|
/// @return 每日登记数
|
||||||
|
List<GaoEventRecordDailyStatView> stateCustomerDailyByRange(GaoCustomerChartReq req);
|
||||||
|
|
||||||
|
/// 按客户和时间范围查询登记日历记录
|
||||||
|
///
|
||||||
|
/// @param req 客户报表查询请求
|
||||||
|
/// @return 日历记录列表
|
||||||
|
List<GaoEventRecordCalendarView> selectCustomerCalendarByRange(GaoCustomerChartReq req);
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEventRoleRelation;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// 登记事件角色关联 Mapper
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-07-28 14:23
|
||||||
|
public interface GaoEventRoleRelationMapper extends BaseMapper<GaoEventRoleRelation, String> {
|
||||||
|
|
||||||
|
List<GaoEventRoleRelation> selectAllByEventIdList(Collection<String> idList);
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointAccount;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
/// GAO 客户积分账户 Mapper
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
public interface GaoPointAccountMapper extends BaseMapper<GaoPointAccount, String> {
|
||||||
|
|
||||||
|
/// 查询客户当前有效积分账户
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param customerId 客户 ID
|
||||||
|
/// @return 积分账户
|
||||||
|
GaoPointAccount selectByStoreIdAndCustomerId(@Param("storeId") String storeId, @Param("customerId") String customerId);
|
||||||
|
|
||||||
|
/// 创建客户积分账户,已存在时保持原账户不变
|
||||||
|
///
|
||||||
|
/// @param account 积分账户
|
||||||
|
void insertIfAbsent(@Param("account") GaoPointAccount account);
|
||||||
|
|
||||||
|
/// 锁定积分账户
|
||||||
|
///
|
||||||
|
/// @param id 账户 ID
|
||||||
|
/// @return 积分账户
|
||||||
|
GaoPointAccount selectForUpdate(@Param("id") String id);
|
||||||
|
|
||||||
|
/// 原子更新积分账户余额和统计值
|
||||||
|
///
|
||||||
|
/// @param id 账户 ID
|
||||||
|
/// @param delta 本次余额变化
|
||||||
|
/// @param totalEarnedDelta 累计获得积分变化
|
||||||
|
/// @param totalRevokedDelta 累计撤销积分变化
|
||||||
|
/// @param totalAdjustedDelta 累计人工调整积分变化
|
||||||
|
/// @param updatedAt 更新时间
|
||||||
|
/// @return 更新行数
|
||||||
|
int updateBalance(@Param("id") String id, @Param("delta") long delta, @Param("totalEarnedDelta") long totalEarnedDelta, @Param("totalRevokedDelta") long totalRevokedDelta, @Param("totalAdjustedDelta") long totalAdjustedDelta, @Param("updatedAt") long updatedAt);
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointLedger;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoPointLedgerPage;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// GAO 客户积分流水 Mapper
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
public interface GaoPointLedgerMapper extends BaseMapper<GaoPointLedger, String> {
|
||||||
|
|
||||||
|
/// 按幂等键查询流水
|
||||||
|
///
|
||||||
|
/// @param idempotencyKey 幂等键
|
||||||
|
/// @return 流水
|
||||||
|
GaoPointLedger selectByIdempotencyKey(@Param("idempotencyKey") String idempotencyKey);
|
||||||
|
|
||||||
|
/// 查询登记记录产生的原始获得积分流水
|
||||||
|
///
|
||||||
|
/// @param eventRecordId 登记记录 ID
|
||||||
|
/// @return 获得积分流水
|
||||||
|
List<GaoPointLedger> selectEarnByEventRecordId(@Param("eventRecordId") String eventRecordId);
|
||||||
|
|
||||||
|
/// 批量查询幂等键对应的流水
|
||||||
|
///
|
||||||
|
/// @param idempotencyKeyList 幂等键列表
|
||||||
|
/// @return 已存在流水
|
||||||
|
List<GaoPointLedger> selectByIdempotencyKeyList(@Param("idempotencyKeyList") List<String> idempotencyKeyList);
|
||||||
|
|
||||||
|
/// 查询积分流水总数
|
||||||
|
///
|
||||||
|
/// @param page 查询条件
|
||||||
|
/// @return 流水总数
|
||||||
|
long countByQuery(GaoPointLedgerPage page);
|
||||||
|
|
||||||
|
/// 分页查询积分流水
|
||||||
|
///
|
||||||
|
/// @param page 查询条件
|
||||||
|
/// @return 流水列表
|
||||||
|
List<GaoPointLedger> selectByQuery(GaoPointLedgerPage page);
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointRule;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// GAO 客户积分规则 Mapper
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
public interface GaoPointRuleMapper extends BaseMapper<GaoPointRule, String> {
|
||||||
|
|
||||||
|
/// 查询当前时间可匹配的启用规则
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param eventId 登记事件 ID
|
||||||
|
/// @param now 当前时间戳
|
||||||
|
/// @return 按优先级排序的规则列表
|
||||||
|
List<GaoPointRule> selectActiveByStoreIdAndEventId(@Param("storeId") String storeId, @Param("eventId") String eventId, @Param("now") long now);
|
||||||
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.mapper;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent;
|
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Select;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 登记事件 Mapper
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-27
|
|
||||||
public interface GaoRegistrationEventMapper extends BaseMapper<GaoRegistrationEvent, String> {
|
|
||||||
|
|
||||||
@Select("SELECT * FROM `gao_registration_event` WHERE `enabled` = TRUE AND `deleted_at` IS NULL ORDER BY `sort` ASC, `created_at` ASC")
|
|
||||||
List<GaoRegistrationEvent> selectEnabledList();
|
|
||||||
}
|
|
||||||
-120
@@ -1,120 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.mapper;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRecord;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventPeriodStatView;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerRegisterStatView;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordDailyStatView;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordPeriodReq;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordRangeReq;
|
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 登记事件记录 Mapper
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-27
|
|
||||||
public interface GaoRegistrationEventRecordMapper extends BaseMapper<GaoRegistrationEventRecord, String> {
|
|
||||||
|
|
||||||
/// 按登记事件查询客户最后登记事件记录
|
|
||||||
///
|
|
||||||
/// @param customerIdList 客户 ID 列表
|
|
||||||
/// @param registrationEventId 登记事件 ID
|
|
||||||
/// @return 最后登记事件记录列表
|
|
||||||
List<GaoRegistrationEventRecord> selectByRegistrationEventAndPeriod(@Param("registrationEventId") String registrationEventId, @Param("periodType") GaoRegistrationEventRecordPeriodReq.PeriodType periodType, @Param("periodValue") Integer periodValue);
|
|
||||||
|
|
||||||
/// 按周期统计登记事件记录
|
|
||||||
///
|
|
||||||
/// @param registrationEventId 登记事件 ID
|
|
||||||
/// @param periodType 周期类型
|
|
||||||
/// @return 统计结果
|
|
||||||
List<GaoRegistrationEventPeriodStatView> statByRegistrationEventAndPeriodType(@Param("registrationEventId") String registrationEventId, @Param("periodType") GaoRegistrationEventRecordPeriodReq.PeriodType periodType);
|
|
||||||
|
|
||||||
/// 统计客户所有登记
|
|
||||||
///
|
|
||||||
/// @param customerId 客户 ID
|
|
||||||
/// @return 统计结果
|
|
||||||
List<GaoCustomerRegisterStatView> statByCustomerId(@Param("customerId") String customerId);
|
|
||||||
|
|
||||||
/// 按时间段统计单个客户登记
|
|
||||||
///
|
|
||||||
/// @param customerId 客户 ID
|
|
||||||
/// @param beginRegisteredAt 开始登记时间
|
|
||||||
/// @param endRegisteredAt 结束登记时间
|
|
||||||
/// @return 统计结果
|
|
||||||
List<GaoCustomerRegisterStatView> statByCustomerIdAndRange(@Param("customerId") String customerId, @Param("beginRegisteredAt") Long beginRegisteredAt, @Param("endRegisteredAt") Long endRegisteredAt);
|
|
||||||
|
|
||||||
/// 按时间段统计全部客户登记
|
|
||||||
///
|
|
||||||
/// @param beginRegisteredAt 开始登记时间
|
|
||||||
/// @param endRegisteredAt 结束登记时间
|
|
||||||
/// @return 统计结果
|
|
||||||
List<GaoCustomerRegisterStatView> statAllCustomerByRange(@Param("beginRegisteredAt") Long beginRegisteredAt, @Param("endRegisteredAt") Long endRegisteredAt);
|
|
||||||
|
|
||||||
/// 统计单个客户单个登记事件的每日登记事件记录数
|
|
||||||
///
|
|
||||||
/// @param customerId 客户 ID
|
|
||||||
/// @param registrationEventId 登记事件 ID
|
|
||||||
/// @param beginRegisteredAt 开始登记时间
|
|
||||||
/// @param endRegisteredAt 结束登记时间
|
|
||||||
/// @return 每日统计
|
|
||||||
List<GaoRegistrationEventRecordDailyStatView> statDailyCountByCustomerIdAndRegistrationEventIdRange(@Param("customerId") String customerId, @Param("registrationEventId") String registrationEventId, @Param("beginRegisteredAt") Long beginRegisteredAt, @Param("endRegisteredAt") Long endRegisteredAt);
|
|
||||||
|
|
||||||
/// 统计全部客户单个登记事件的每日登记事件记录数
|
|
||||||
///
|
|
||||||
/// @param registrationEventId 登记事件 ID
|
|
||||||
/// @param beginRegisteredAt 开始登记时间
|
|
||||||
/// @param endRegisteredAt 结束登记时间
|
|
||||||
/// @return 每日统计
|
|
||||||
List<GaoRegistrationEventRecordDailyStatView> statDailyCountByRegistrationEventIdRange(@Param("registrationEventId") String registrationEventId, @Param("beginRegisteredAt") Long beginRegisteredAt, @Param("endRegisteredAt") Long endRegisteredAt);
|
|
||||||
|
|
||||||
/// 统计时间段前单个客户单个登记事件累计登记事件记录数
|
|
||||||
///
|
|
||||||
/// @param customerId 客户 ID
|
|
||||||
/// @param registrationEventId 登记事件 ID
|
|
||||||
/// @param beginRegisteredAt 开始登记时间
|
|
||||||
/// @return 累计登记数
|
|
||||||
Long countBeforeByCustomerIdAndRegistrationEventId(@Param("customerId") String customerId, @Param("registrationEventId") String registrationEventId, @Param("beginRegisteredAt") Long beginRegisteredAt);
|
|
||||||
|
|
||||||
/// 统计时间段前全部客户单个登记事件累计登记事件记录数
|
|
||||||
///
|
|
||||||
/// @param registrationEventId 登记事件 ID
|
|
||||||
/// @param beginRegisteredAt 开始登记时间
|
|
||||||
/// @return 累计登记数
|
|
||||||
Long countBeforeByRegistrationEventId(@Param("registrationEventId") String registrationEventId, @Param("beginRegisteredAt") Long beginRegisteredAt);
|
|
||||||
|
|
||||||
/// 查询客户指定登记事件的最后登记事件记录
|
|
||||||
///
|
|
||||||
/// @param customerIdList 客户 ID 列表
|
|
||||||
/// @param registrationEventId 登记事件 ID
|
|
||||||
/// @return 最后登记事件记录列表
|
|
||||||
List<GaoRegistrationEventRecord> selectLatestByCustomerIdListAndRegistrationEventId(@Param("customerIdList") List<String> customerIdList, @Param("registrationEventId") String registrationEventId);
|
|
||||||
|
|
||||||
/// 查询客户全部登记事件的最后登记事件记录
|
|
||||||
///
|
|
||||||
/// @param customerId 客户 ID
|
|
||||||
/// @return 最后登记事件记录列表
|
|
||||||
List<GaoRegistrationEventRecord> selectLatestByCustomerId(@Param("customerId") String customerId);
|
|
||||||
|
|
||||||
/// 按任意时间范围查询登记事件记录
|
|
||||||
///
|
|
||||||
/// @param req 范围查询请求
|
|
||||||
/// @return 登记事件记录列表
|
|
||||||
List<GaoRegistrationEventRecord> selectByRange(@Param("req") GaoRegistrationEventRecordRangeReq req);
|
|
||||||
|
|
||||||
/// 按任意时间范围统计登记事件记录
|
|
||||||
///
|
|
||||||
/// @param req 范围查询请求
|
|
||||||
/// @return 登记事件记录数
|
|
||||||
Long countByRange(@Param("req") GaoRegistrationEventRecordRangeReq req);
|
|
||||||
|
|
||||||
/// 按任意时间范围分页查询登记事件记录
|
|
||||||
///
|
|
||||||
/// @param req 范围查询请求
|
|
||||||
/// @param offset 偏移量
|
|
||||||
/// @param size 每页条数
|
|
||||||
/// @return 登记事件记录列表
|
|
||||||
List<GaoRegistrationEventRecord> selectPageByRange(@Param("req") GaoRegistrationEventRecordRangeReq req, @Param("offset") Long offset, @Param("size") Long size);
|
|
||||||
}
|
|
||||||
-23
@@ -1,23 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.mapper;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRoleRelation;
|
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.apache.ibatis.annotations.Select;
|
|
||||||
import org.apache.ibatis.annotations.Update;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 登记事件角色关联 Mapper
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-28
|
|
||||||
public interface GaoRegistrationEventRoleRelationMapper extends BaseMapper<GaoRegistrationEventRoleRelation, String> {
|
|
||||||
|
|
||||||
@Select("SELECT `role_code` FROM `gao_registration_event_role_relation` WHERE `registration_event_id` = #{registrationEventId} AND `deleted_at` IS NULL ORDER BY `created_at` ASC")
|
|
||||||
List<String> selectRoleCodeListByRegistrationEventId(@Param("registrationEventId") String registrationEventId);
|
|
||||||
|
|
||||||
@Update("UPDATE `gao_registration_event_role_relation` SET `deleted_at` = UNIX_TIMESTAMP() WHERE `registration_event_id` = #{registrationEventId} AND `deleted_at` IS NULL")
|
|
||||||
void deleteByRegistrationEventId(@Param("registrationEventId") String registrationEventId);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoStoreBusinessDay;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// GAO 门店营业日 Mapper
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-06
|
||||||
|
public interface GaoStoreBusinessDayMapper extends BaseMapper<GaoStoreBusinessDay, String> {
|
||||||
|
|
||||||
|
/// 按门店和日期查询营业日
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param dateValue 日期值,格式为 yyyyMMdd
|
||||||
|
/// @return 营业日
|
||||||
|
@Select("SELECT * FROM `gao_store_business_day` WHERE `store_id` = #{storeId} AND `date_value` = #{dateValue} AND `deleted_at` IS NULL LIMIT 1")
|
||||||
|
GaoStoreBusinessDay selectByStoreIdAndDateValue(@Param("storeId") String storeId, @Param("dateValue") Integer dateValue);
|
||||||
|
|
||||||
|
/// 查询指定日期前最后一个营业日序号
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param dateValue 日期值,格式为 yyyyMMdd
|
||||||
|
/// @return 营业日序号
|
||||||
|
@Select("SELECT MAX(`business_day_no`) FROM `gao_store_business_day` WHERE `store_id` = #{storeId} AND `date_value` < #{dateValue} AND `status` = 'OPEN' AND `deleted_at` IS NULL")
|
||||||
|
Long selectLastBusinessDayNoBefore(@Param("storeId") String storeId, @Param("dateValue") Integer dateValue);
|
||||||
|
|
||||||
|
/// 查询指定日期及之后的营业日
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param beginDateValue 开始日期值,格式为 yyyyMMdd
|
||||||
|
/// @return 营业日列表
|
||||||
|
@Select("SELECT * FROM `gao_store_business_day` WHERE `store_id` = #{storeId} AND `date_value` >= #{beginDateValue} AND `status` = 'OPEN' AND `deleted_at` IS NULL ORDER BY `date_value` ASC")
|
||||||
|
List<GaoStoreBusinessDay> selectOpenListFromDate(@Param("storeId") String storeId, @Param("beginDateValue") Integer beginDateValue);
|
||||||
|
|
||||||
|
/// 清空指定日期及之后的营业日序号
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param beginDateValue 开始日期值,格式为 yyyyMMdd
|
||||||
|
@Update("UPDATE `gao_store_business_day` SET `business_day_no` = NULL, `updated_at` = ROUND(UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000) WHERE `store_id` = #{storeId} AND `date_value` >= #{beginDateValue} AND `status` = 'OPEN' AND `deleted_at` IS NULL")
|
||||||
|
void clearBusinessDayNoFromDate(@Param("storeId") String storeId, @Param("beginDateValue") Integer beginDateValue);
|
||||||
|
|
||||||
|
/// 查询日期范围内的营业日
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param beginDateValue 开始日期值,格式为 yyyyMMdd
|
||||||
|
/// @param endDateValue 结束日期值,格式为 yyyyMMdd
|
||||||
|
/// @return 营业日列表
|
||||||
|
@Select("SELECT * FROM `gao_store_business_day` WHERE `store_id` = #{storeId} AND `date_value` >= #{beginDateValue} AND `date_value` <= #{endDateValue} AND `deleted_at` IS NULL ORDER BY `date_value` ASC")
|
||||||
|
List<GaoStoreBusinessDay> selectByStoreIdAndDateRange(@Param("storeId") String storeId, @Param("beginDateValue") Integer beginDateValue, @Param("endDateValue") Integer endDateValue);
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoStore;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// GAO 门店 Mapper
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-06
|
||||||
|
public interface GaoStoreMapper extends BaseMapper<GaoStore, String> {
|
||||||
|
|
||||||
|
List<GaoStore> selectByIdList(@Param("idList") Collection<String> idList);
|
||||||
|
|
||||||
|
/// 查询启用自动计算营业日休息日的可用门店
|
||||||
|
///
|
||||||
|
/// @return 门店列表
|
||||||
|
@Select("SELECT * FROM `gao_store` WHERE `auto_closed_day` = TRUE AND `status` = 'ACTIVE' " + NOT_DELETE)
|
||||||
|
List<GaoStore> selectAllByAutoClosedDay();
|
||||||
|
|
||||||
|
/// 查询用户所属的可用门店
|
||||||
|
///
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @return 门店
|
||||||
|
GaoStore selectByUserId(@Param("userId") String userId);
|
||||||
|
}
|
||||||
@@ -2,8 +2,6 @@ package com.imyeyu.api.modules.gao.mapper;
|
|||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.apache.ibatis.annotations.Select;
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// GAO 用户 Mapper
|
/// GAO 用户 Mapper
|
||||||
@@ -11,7 +9,4 @@ import org.apache.ibatis.annotations.Select;
|
|||||||
/// @author Codex
|
/// @author Codex
|
||||||
/// @since 2026-07-30
|
/// @since 2026-07-30
|
||||||
public interface GaoUserMapper extends BaseMapper<GaoUser, String> {
|
public interface GaoUserMapper extends BaseMapper<GaoUser, String> {
|
||||||
|
|
||||||
@Select("SELECT * FROM `gao_user` WHERE `user_id` = #{userId} AND `deleted_at` IS NULL LIMIT 1")
|
|
||||||
GaoUser selectByUserId(@Param("userId") String userId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerChartReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordCalendarView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordDailyStatView;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// 客户报表服务
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
public interface GaoCustomerChartService {
|
||||||
|
|
||||||
|
/// 查询客户登记每日统计
|
||||||
|
List<GaoEventRecordDailyStatView> eventRecordDailyStat(GaoCustomerChartReq req);
|
||||||
|
|
||||||
|
/// 查询客户登记日历记录
|
||||||
|
List<GaoEventRecordCalendarView> eventRecordCalendar(GaoCustomerChartReq req);
|
||||||
|
}
|
||||||
@@ -1,59 +1,58 @@
|
|||||||
package com.imyeyu.api.modules.gao.service;
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStatView;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerInviteUpdateReq;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerSearchReq;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerPage;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStatReq;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStateReq;
|
||||||
import com.imyeyu.spring.bean.Page;
|
import com.imyeyu.spring.bean.Page;
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
///
|
|
||||||
/// 客户服务
|
/// 客户服务
|
||||||
///
|
///
|
||||||
/// @author Codex
|
/// @author 夜雨
|
||||||
/// @since 2026-07-27
|
/// @since 2026-07-27 14:12
|
||||||
public interface GaoCustomerService extends BaseService<GaoCustomer, String> {
|
public interface GaoCustomerService extends BaseService<GaoCustomer, String> {
|
||||||
|
|
||||||
|
/// 按查询条件分页查询客户
|
||||||
|
///
|
||||||
|
/// @param page 查询条件
|
||||||
|
/// @return 客户分页
|
||||||
|
PageResult<GaoCustomer> pageByQuery(GaoCustomerPage page);
|
||||||
|
|
||||||
|
void updateWithAttachment(GaoCustomer customer);
|
||||||
|
|
||||||
/// 按编码查询客户
|
/// 按编码查询客户
|
||||||
///
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
/// @param code 客户编码
|
/// @param code 客户编码
|
||||||
/// @return 客户
|
/// @return 客户
|
||||||
GaoCustomer getByCode(String code);
|
GaoCustomer getByCode(String storeId, String code);
|
||||||
|
|
||||||
/// 按编码查询客户,不存在时返回 null
|
/// 按姓名查询客户
|
||||||
///
|
///
|
||||||
/// @param code 客户编码
|
/// @param storeId 门店 ID
|
||||||
|
/// @param name 姓名
|
||||||
/// @return 客户
|
/// @return 客户
|
||||||
GaoCustomer getNullableByCode(String code);
|
GaoCustomer getByName(String storeId, String name);
|
||||||
|
|
||||||
/// 按编码获取或快速创建客户
|
List<GaoCustomer> listByIdList(Collection<String> idList);
|
||||||
///
|
|
||||||
/// @param code 客户编码
|
|
||||||
/// @return 客户
|
|
||||||
GaoCustomer getOrQuickCreateByCode(String code);
|
|
||||||
|
|
||||||
/// 搜索客户
|
default Map<String, GaoCustomer> mapByIdList(Collection<String> idList) {
|
||||||
///
|
return listByIdList(idList).stream().collect(Collectors.toMap(GaoCustomer::getId, item -> item));
|
||||||
/// @param req 搜索请求
|
}
|
||||||
/// @return 客户列表
|
|
||||||
List<GaoCustomer> search(GaoCustomerSearchReq req);
|
|
||||||
|
|
||||||
/// 分页搜索客户
|
|
||||||
///
|
|
||||||
/// @param page 分页搜索请求
|
|
||||||
/// @return 客户分页结果
|
|
||||||
PageResult<GaoCustomer> searchPage(Page<GaoCustomerSearchReq> page);
|
|
||||||
|
|
||||||
/// 按搜索条件导出客户 Excel
|
/// 按搜索条件导出客户 Excel
|
||||||
///
|
///
|
||||||
/// @param req 搜索请求
|
|
||||||
/// @return xlsx 文件字节
|
/// @return xlsx 文件字节
|
||||||
byte[] exportSearchExcel(GaoCustomerSearchReq req) throws IOException;
|
byte[] export(Page<GaoCustomer> page) throws IOException;
|
||||||
|
|
||||||
/// 查询邀请的客户
|
/// 查询邀请的客户
|
||||||
///
|
///
|
||||||
@@ -63,8 +62,9 @@ public interface GaoCustomerService extends BaseService<GaoCustomer, String> {
|
|||||||
|
|
||||||
/// 保存邀请关系
|
/// 保存邀请关系
|
||||||
///
|
///
|
||||||
/// @param req 邀请关系请求
|
/// @param introducerCustomerId 邀请来源客户 ID
|
||||||
void saveInviteRelation(GaoCustomerInviteUpdateReq req);
|
/// @param customerId 客户 ID
|
||||||
|
void saveInviteRelation(String introducerCustomerId, String customerId);
|
||||||
|
|
||||||
/// 删除邀请关系
|
/// 删除邀请关系
|
||||||
///
|
///
|
||||||
@@ -75,5 +75,11 @@ public interface GaoCustomerService extends BaseService<GaoCustomer, String> {
|
|||||||
///
|
///
|
||||||
/// @param req 趋势统计请求
|
/// @param req 趋势统计请求
|
||||||
/// @return 每日趋势列表
|
/// @return 每日趋势列表
|
||||||
List<GaoCustomerDailyStatView> statDailyTrend(GaoCustomerTrendStatReq req);
|
List<GaoCustomerDailyStateView> stateDailyTrend(GaoCustomerTrendStateReq req);
|
||||||
|
|
||||||
|
/// 统计客户性别分布
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @return 性别统计列表
|
||||||
|
List<GaoCustomerGenderStatView> stateGender(String storeId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerEventRankView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordPage;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordRankPage;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// 登记事件记录服务
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-07-27 14:09
|
||||||
|
public interface GaoEventRecordService extends BaseService<GaoEventRecord, String> {
|
||||||
|
|
||||||
|
default void createBatch(List<GaoEventRecord> recordList) {
|
||||||
|
for (GaoEventRecord record : TimiJava.safeIterable(recordList)) {
|
||||||
|
create(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void createWithCustomer(GaoCustomer customer);
|
||||||
|
|
||||||
|
/// 按任意时间范围查询登记事件记录
|
||||||
|
///
|
||||||
|
/// @param req 范围查询请求
|
||||||
|
/// @return 登记事件记录列表
|
||||||
|
PageResult<GaoEventRecord> pageByRange(GaoEventRecordPage req);
|
||||||
|
|
||||||
|
/// 按登记记录列表条件汇总数值
|
||||||
|
///
|
||||||
|
/// @param req 登记记录范围查询请求
|
||||||
|
/// @return 登记数值合计
|
||||||
|
Long sumNumberValueByRange(GaoEventRecordPage req);
|
||||||
|
|
||||||
|
/// 按时间范围查询客户登记排行榜
|
||||||
|
///
|
||||||
|
/// @param page 范围查询请求,不传时间为全部时间
|
||||||
|
/// @return 客户登记排行榜
|
||||||
|
PageResult<GaoCustomerEventRankView> pageRankByRange(GaoEventRecordRankPage page);
|
||||||
|
|
||||||
|
/// 按任意时间范围导出登记事件记录 Excel
|
||||||
|
///
|
||||||
|
/// @param page 范围查询请求
|
||||||
|
/// @return xlsx 文件字节
|
||||||
|
byte[] export(GaoEventRecordPage page) throws IOException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
||||||
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件服务
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
public interface GaoEventService extends BaseService<GaoEvent, String> {
|
||||||
|
|
||||||
|
Map<String, GaoEvent> mapByIdList(Collection<String> idList);
|
||||||
|
|
||||||
|
Map<String, List<String>> mapRoleCodeListByEventIdList(Collection<String> eventIdList);
|
||||||
|
|
||||||
|
/// 查询启用的登记事件
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @return 登记事件列表
|
||||||
|
List<GaoEvent> listValid(String storeId);
|
||||||
|
|
||||||
|
/// 查询登记事件要求的角色
|
||||||
|
///
|
||||||
|
/// @param eventId 登记事件 ID
|
||||||
|
/// @return 角色代码列表
|
||||||
|
List<String> listRoleCode(String eventId);
|
||||||
|
|
||||||
|
/// 按客户端提交的顺序更新登记事件排序
|
||||||
|
///
|
||||||
|
/// @param idList 登记事件 ID 列表
|
||||||
|
void sort(List<String> idList);
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointAccount;
|
||||||
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
|
/// GAO 客户积分账户服务
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
public interface GaoPointAccountService extends BaseService<GaoPointAccount, String> {
|
||||||
|
|
||||||
|
/// 查询客户当前有效积分账户
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param customerId 客户 ID
|
||||||
|
/// @return 积分账户,不存在时返回 null
|
||||||
|
GaoPointAccount getByCustomerId(String storeId, String customerId);
|
||||||
|
|
||||||
|
/// 获取并锁定客户积分账户,不存在时创建
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param customerId 客户 ID
|
||||||
|
/// @return 已锁定的积分账户
|
||||||
|
GaoPointAccount getOrCreateForUpdate(String storeId, String customerId);
|
||||||
|
|
||||||
|
/// 原子更新账户余额
|
||||||
|
///
|
||||||
|
/// @param accountId 账户 ID
|
||||||
|
/// @param delta 本次余额变化
|
||||||
|
/// @param totalEarnedDelta 累计获得积分变化
|
||||||
|
/// @param totalRevokedDelta 累计撤销积分变化
|
||||||
|
/// @param totalAdjustedDelta 累计人工调整积分变化
|
||||||
|
/// @return 更新行数
|
||||||
|
int updateBalance(String accountId, long delta, long totalEarnedDelta, long totalRevokedDelta, long totalAdjustedDelta);
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointLedger;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointRule;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoPointAdjustRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoPointLedgerPage;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
|
/// GAO 客户积分流水服务
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
public interface GaoPointLedgerService extends BaseService<GaoPointLedger, String> {
|
||||||
|
|
||||||
|
/// 写入登记获得积分流水
|
||||||
|
///
|
||||||
|
/// @param record 登记记录
|
||||||
|
/// @param rule 命中规则
|
||||||
|
/// @param pointDelta 积分变化
|
||||||
|
/// @param sourcePayload 来源快照
|
||||||
|
/// @return 积分流水
|
||||||
|
GaoPointLedger earn(GaoEventRecord record, GaoPointRule rule, long pointDelta, JsonNode sourcePayload);
|
||||||
|
|
||||||
|
/// 写入删除登记记录的撤销流水
|
||||||
|
///
|
||||||
|
/// @param originLedger 原始获得积分流水
|
||||||
|
/// @param record 登记记录
|
||||||
|
/// @return 撤销流水
|
||||||
|
GaoPointLedger revoke(GaoPointLedger originLedger, GaoEventRecord record);
|
||||||
|
|
||||||
|
/// 写入人工调整流水
|
||||||
|
///
|
||||||
|
/// @param request 人工调整请求
|
||||||
|
/// @param operatorUserId 操作用户 ID
|
||||||
|
/// @return 调整流水
|
||||||
|
GaoPointLedger adjust(GaoPointAdjustRequest request, String operatorUserId);
|
||||||
|
|
||||||
|
/// 分页查询积分流水
|
||||||
|
///
|
||||||
|
/// @param page 查询条件
|
||||||
|
/// @return 分页结果
|
||||||
|
PageResult<GaoPointLedger> pageByQuery(GaoPointLedgerPage page);
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointRule;
|
||||||
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// GAO 客户积分规则服务
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
public interface GaoPointRuleService extends BaseService<GaoPointRule, String> {
|
||||||
|
|
||||||
|
/// 查询当前时间可匹配的启用规则
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param eventId 登记事件 ID
|
||||||
|
/// @param now 当前时间戳
|
||||||
|
/// @return 规则列表
|
||||||
|
List<GaoPointRule> listActive(String storeId, String eventId, long now);
|
||||||
|
|
||||||
|
/// 创建积分规则
|
||||||
|
///
|
||||||
|
/// @param rule 积分规则
|
||||||
|
void create(GaoPointRule rule);
|
||||||
|
|
||||||
|
/// 修改积分规则
|
||||||
|
///
|
||||||
|
/// @param rule 积分规则
|
||||||
|
void update(GaoPointRule rule);
|
||||||
|
|
||||||
|
/// 删除积分规则
|
||||||
|
///
|
||||||
|
/// @param id 规则 ID
|
||||||
|
void delete(String id);
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointLedger;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoPointAdjustRequest;
|
||||||
|
|
||||||
|
/// GAO 客户积分触发服务
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
public interface GaoPointTriggerService {
|
||||||
|
|
||||||
|
/// 在登记记录创建成功后触发积分
|
||||||
|
///
|
||||||
|
/// @param record 登记记录
|
||||||
|
void onEventRecordCreated(GaoEventRecord record);
|
||||||
|
|
||||||
|
/// 撤销登记记录产生的全部获得积分
|
||||||
|
///
|
||||||
|
/// @param record 登记记录
|
||||||
|
void revokeByEventRecord(GaoEventRecord record);
|
||||||
|
|
||||||
|
/// 执行人工调整
|
||||||
|
///
|
||||||
|
/// @param request 人工调整请求
|
||||||
|
/// @return 调整流水
|
||||||
|
GaoPointLedger adjust(GaoPointAdjustRequest request);
|
||||||
|
}
|
||||||
-112
@@ -1,112 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRecord;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventPeriodStatView;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerRegisterStatView;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoQuickRegistrationEventRecordReq;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordCreateReq;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordDailyStatView;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordPeriodReq;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordRangeReq;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordStatReq;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordTrendStatReq;
|
|
||||||
import com.imyeyu.spring.bean.Page;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
import com.imyeyu.spring.service.BaseService;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 登记事件记录服务
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-27
|
|
||||||
public interface GaoRegistrationEventRecordService extends BaseService<GaoRegistrationEventRecord, String> {
|
|
||||||
|
|
||||||
/// 创建登记事件记录
|
|
||||||
///
|
|
||||||
/// @param req 创建请求
|
|
||||||
/// @return 创建后的登记事件记录
|
|
||||||
GaoRegistrationEventRecord createRecord(GaoRegistrationEventRecordCreateReq req);
|
|
||||||
|
|
||||||
/// 快速录入客户并创建登记事件记录
|
|
||||||
///
|
|
||||||
/// @param req 快速录入请求
|
|
||||||
/// @return 创建后的登记事件记录
|
|
||||||
GaoRegistrationEventRecord quickRegister(GaoQuickRegistrationEventRecordReq req);
|
|
||||||
|
|
||||||
/// 按任意时间范围查询登记事件记录
|
|
||||||
///
|
|
||||||
/// @param req 范围查询请求
|
|
||||||
/// @return 登记事件记录列表
|
|
||||||
List<GaoRegistrationEventRecord> listByRange(GaoRegistrationEventRecordRangeReq req);
|
|
||||||
|
|
||||||
/// 按任意时间范围分页查询登记事件记录
|
|
||||||
///
|
|
||||||
/// @param page 分页参数
|
|
||||||
/// @return 登记事件记录分页结果
|
|
||||||
PageResult<GaoRegistrationEventRecord> pageByRange(Page<GaoRegistrationEventRecordRangeReq> page);
|
|
||||||
|
|
||||||
/// 按任意时间范围导出登记事件记录 Excel
|
|
||||||
///
|
|
||||||
/// @param req 范围查询请求
|
|
||||||
/// @return xlsx 文件字节
|
|
||||||
byte[] exportRangeExcel(GaoRegistrationEventRecordRangeReq req) throws IOException;
|
|
||||||
|
|
||||||
/// 按周期查询登记事件记录
|
|
||||||
///
|
|
||||||
/// @param req 周期请求
|
|
||||||
/// @return 登记事件记录列表
|
|
||||||
List<GaoRegistrationEventRecord> listByRegistrationEventAndPeriod(GaoRegistrationEventRecordPeriodReq req);
|
|
||||||
|
|
||||||
/// 按周期统计登记事件记录
|
|
||||||
///
|
|
||||||
/// @param registrationEventId 登记事件 ID
|
|
||||||
/// @param periodType 周期类型
|
|
||||||
/// @return 统计列表
|
|
||||||
List<GaoRegistrationEventPeriodStatView> statByRegistrationEventAndPeriodType(String registrationEventId, GaoRegistrationEventRecordPeriodReq.PeriodType periodType);
|
|
||||||
|
|
||||||
/// 查询客户指定登记事件的最后登记事件记录
|
|
||||||
///
|
|
||||||
/// @param customerIdList 客户 ID 列表
|
|
||||||
/// @param registrationEventId 登记事件 ID
|
|
||||||
/// @return 每个客户的最后登记事件记录
|
|
||||||
List<GaoRegistrationEventRecord> listLatestByCustomerIdListAndRegistrationEventId(List<String> customerIdList, String registrationEventId);
|
|
||||||
|
|
||||||
/// 统计客户所有登记
|
|
||||||
///
|
|
||||||
/// @param customerId 客户 ID
|
|
||||||
/// @return 统计结果
|
|
||||||
List<GaoCustomerRegisterStatView> statByCustomerId(String customerId);
|
|
||||||
|
|
||||||
/// 按时间段统计单个客户登记
|
|
||||||
///
|
|
||||||
/// @param req 统计请求
|
|
||||||
/// @return 统计结果
|
|
||||||
List<GaoCustomerRegisterStatView> statByCustomerAndRange(GaoRegistrationEventRecordStatReq req);
|
|
||||||
|
|
||||||
/// 按时间段统计全部客户登记
|
|
||||||
///
|
|
||||||
/// @param req 统计请求
|
|
||||||
/// @return 统计结果
|
|
||||||
List<GaoCustomerRegisterStatView> statAllCustomerByRange(GaoRegistrationEventRecordStatReq req);
|
|
||||||
|
|
||||||
/// 按时间段统计单个客户单个登记事件每日趋势
|
|
||||||
///
|
|
||||||
/// @param req 趋势统计请求
|
|
||||||
/// @return 每日趋势列表
|
|
||||||
List<GaoRegistrationEventRecordDailyStatView> statDailyByCustomerAndRegistrationEvent(GaoRegistrationEventRecordTrendStatReq req);
|
|
||||||
|
|
||||||
/// 按时间段统计全部客户单个登记事件每日趋势
|
|
||||||
///
|
|
||||||
/// @param req 趋势统计请求
|
|
||||||
/// @return 每日趋势列表
|
|
||||||
List<GaoRegistrationEventRecordDailyStatView> statDailyByRegistrationEvent(GaoRegistrationEventRecordTrendStatReq req);
|
|
||||||
|
|
||||||
/// 查询客户全部登记事件的最后登记事件记录
|
|
||||||
///
|
|
||||||
/// @param customerId 客户 ID
|
|
||||||
/// @return 每个登记事件的最后登记事件记录
|
|
||||||
List<GaoRegistrationEventRecord> listLatestByCustomerId(String customerId);
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent;
|
|
||||||
import com.imyeyu.spring.bean.Page;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
import com.imyeyu.spring.service.BaseService;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 登记事件服务
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-27
|
|
||||||
public interface GaoRegistrationEventService extends BaseService<GaoRegistrationEvent, String> {
|
|
||||||
|
|
||||||
/// 分页查询登记事件并填充可登记角色
|
|
||||||
///
|
|
||||||
/// @param page 分页参数
|
|
||||||
/// @return 登记事件分页
|
|
||||||
PageResult<GaoRegistrationEvent> pageWithRegistrationEventLimit(Page<GaoRegistrationEvent> page);
|
|
||||||
|
|
||||||
/// 查询启用的登记事件
|
|
||||||
///
|
|
||||||
/// @return 登记事件列表
|
|
||||||
List<GaoRegistrationEvent> listEnabled();
|
|
||||||
|
|
||||||
/// 查询登记事件要求的角色
|
|
||||||
///
|
|
||||||
/// @param registrationEventId 登记事件 ID
|
|
||||||
/// @return 角色代码列表
|
|
||||||
List<String> listRoleCode(String registrationEventId);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoStoreBusinessDay;
|
||||||
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// GAO 门店营业日服务
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-06
|
||||||
|
public interface GaoStoreBusinessDayService extends BaseService<GaoStoreBusinessDay, String> {
|
||||||
|
|
||||||
|
/// 解析营业日,不存在时按默认营业日创建
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param dateValue 日期值,格式为 yyyyMMdd
|
||||||
|
/// @return 营业日
|
||||||
|
GaoStoreBusinessDay resolveOpenBusinessDay(String storeId, Integer dateValue);
|
||||||
|
|
||||||
|
/// 重算门店营业日序号并同步登记记录快照
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param beginDateValue 开始日期值,格式为 yyyyMMdd
|
||||||
|
void rebuildBusinessDayNo(String storeId, Integer beginDateValue);
|
||||||
|
|
||||||
|
/// 自动补记门店休息日
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param dateValue 日期值,格式为 yyyyMMdd
|
||||||
|
void autoCloseBusinessDay(String storeId, Integer dateValue);
|
||||||
|
|
||||||
|
/// 查询日期范围内的营业日
|
||||||
|
///
|
||||||
|
/// @param storeId 门店 ID
|
||||||
|
/// @param beginDateValue 开始日期值,格式为 yyyyMMdd
|
||||||
|
/// @param endDateValue 结束日期值,格式为 yyyyMMdd
|
||||||
|
/// @return 营业日列表
|
||||||
|
java.util.List<GaoStoreBusinessDay> listByDateRange(String storeId, Integer beginDateValue, Integer endDateValue);
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordCalendarView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoStoreChartReq;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// 门店报表服务
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
public interface GaoStoreChartService {
|
||||||
|
|
||||||
|
/// 查询客户每日趋势
|
||||||
|
List<GaoCustomerDailyStateView> customerDailyTrend(GaoStoreChartReq req);
|
||||||
|
|
||||||
|
/// 查询客户性别统计
|
||||||
|
List<GaoCustomerGenderStatView> customerGender(String storeId);
|
||||||
|
|
||||||
|
/// 查询登记事件每日统计
|
||||||
|
List<GaoEventRecordDailyStatView> eventRecordDailyStat(GaoStoreChartReq req);
|
||||||
|
|
||||||
|
/// 查询登记事件日历记录
|
||||||
|
List<GaoEventRecordCalendarView> eventRecordCalendar(GaoStoreChartReq req);
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoStore;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// GAO 门店服务
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-06
|
||||||
|
public interface GaoStoreService extends BaseService<GaoStore, String> {
|
||||||
|
|
||||||
|
/// 查询用户所属门店
|
||||||
|
///
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @return 门店
|
||||||
|
GaoStore getByUserId(String userId);
|
||||||
|
|
||||||
|
String getBelongIdByRequiredLoginUserId();
|
||||||
|
|
||||||
|
List<GaoStore> listByAutoClosedDay();
|
||||||
|
|
||||||
|
/// 导出门店列表
|
||||||
|
///
|
||||||
|
/// @param page 分页查询条件
|
||||||
|
/// @return xlsx 文件字节
|
||||||
|
byte[] export(Page<GaoStore> page) throws IOException;
|
||||||
|
|
||||||
|
/// 按客户端提交的顺序更新排序
|
||||||
|
///
|
||||||
|
/// @param idList 门店 ID 列表
|
||||||
|
void sort(List<String> idList);
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoUserInviteCreateRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoUserInviteCreateResponse;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoUserInviteRegisterData;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoUserInviteValidateResponse;
|
||||||
|
|
||||||
|
/// GAO 用户邀请注册服务
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-13
|
||||||
|
public interface GaoUserInviteService {
|
||||||
|
|
||||||
|
/// 创建 GAO 用户邀请
|
||||||
|
///
|
||||||
|
/// @param req 邀请创建请求
|
||||||
|
/// @return 邀请 code 和过期时间
|
||||||
|
GaoUserInviteCreateResponse create(GaoUserInviteCreateRequest req);
|
||||||
|
|
||||||
|
/// 校验 GAO 用户邀请是否可用
|
||||||
|
///
|
||||||
|
/// @param code 邀请 code
|
||||||
|
/// @return 校验结果
|
||||||
|
GaoUserInviteValidateResponse validate(String code);
|
||||||
|
|
||||||
|
/// 使用邀请注册 GAO 用户
|
||||||
|
///
|
||||||
|
/// @param data 注册数据
|
||||||
|
/// @return 注册成功的用户 ID
|
||||||
|
String register(GaoUserInviteRegisterData data);
|
||||||
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.imyeyu.api.modules.gao.service;
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
||||||
import com.imyeyu.spring.bean.Page;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -12,15 +10,8 @@ import com.imyeyu.spring.service.BaseService;
|
|||||||
/// @since 2026-07-30
|
/// @since 2026-07-30
|
||||||
public interface GaoUserService extends BaseService<GaoUser, String> {
|
public interface GaoUserService extends BaseService<GaoUser, String> {
|
||||||
|
|
||||||
/// 按用户 ID 查询 GAO 用户
|
/// 调整 GAO 用户所属门店
|
||||||
///
|
///
|
||||||
/// @param userId 用户 ID
|
/// @param gaoUser GAO 用户,必须包含 ID 和目标门店 ID
|
||||||
/// @return GAO 用户
|
void transferStore(GaoUser gaoUser);
|
||||||
GaoUser getByUserId(String userId);
|
|
||||||
|
|
||||||
/// 分页查询并填充用户详情
|
|
||||||
///
|
|
||||||
/// @param page 分页请求
|
|
||||||
/// @return GAO 用户分页
|
|
||||||
PageResult<GaoUser> pageWithUser(Page<GaoUser> page);
|
|
||||||
}
|
}
|
||||||
|
|||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service.implement;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoEventRecordMapper;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoCustomerChartService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerChartReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordCalendarView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordDailyStatView;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// 客户报表服务实现
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GaoCustomerChartServiceImplement implements GaoCustomerChartService {
|
||||||
|
|
||||||
|
private final GaoEventRecordMapper eventRecordMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoEventRecordDailyStatView> eventRecordDailyStat(GaoCustomerChartReq req) {
|
||||||
|
checkRangeReq(req);
|
||||||
|
return eventRecordMapper.stateCustomerDailyByRange(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoEventRecordCalendarView> eventRecordCalendar(GaoCustomerChartReq req) {
|
||||||
|
checkRangeReq(req);
|
||||||
|
return eventRecordMapper.selectCustomerCalendarByRange(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkRangeReq(GaoCustomerChartReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
TimiException.required(req.getStoreId(), "not found req.storeId");
|
||||||
|
TimiException.required(req.getCustomerId(), "not found req.customerId");
|
||||||
|
TimiException.required(req.getBeginAt(), "not found req.beginAt");
|
||||||
|
TimiException.required(req.getEndAt(), "not found req.endAt");
|
||||||
|
TimiException.requiredTrue(req.getBeginAt() <= req.getEndAt(), "req.endAt lt req.beginAt");
|
||||||
|
}
|
||||||
|
}
|
||||||
+273
-243
@@ -1,16 +1,20 @@
|
|||||||
package com.imyeyu.api.modules.gao.service.implement;
|
package com.imyeyu.api.modules.gao.service.implement;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
import com.imyeyu.api.modules.common.vo.attach.BizUpdateReq;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoCustomerMapper;
|
import com.imyeyu.api.modules.gao.mapper.GaoCustomerMapper;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStatView;
|
import com.imyeyu.api.modules.gao.util.CustomerXSSFBuilder;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerInviteUpdateReq;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerSearchReq;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStatReq;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerPage;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStateReq;
|
||||||
|
import com.imyeyu.api.modules.system.entity.Logger;
|
||||||
|
import com.imyeyu.api.modules.system.service.LoggerService;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.java.bean.timi.TimiCode;
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
@@ -19,16 +23,10 @@ import com.imyeyu.spring.bean.PageResult;
|
|||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.poi.ss.usermodel.Font;
|
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
@@ -36,24 +34,33 @@ import java.time.ZoneId;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
///
|
|
||||||
/// 客户服务实现
|
/// 客户服务实现
|
||||||
///
|
///
|
||||||
/// @author Codex
|
/// @author Codex
|
||||||
/// @since 2026-07-27
|
/// @since 2026-07-27
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustomer, String> implements GaoCustomerService {
|
public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustomer, String> implements GaoCustomerService {
|
||||||
|
|
||||||
private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||||
private static final DateTimeFormatter EXPORT_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault());
|
|
||||||
|
private final ObjectMapper jackson;
|
||||||
|
|
||||||
|
private final LoggerService loggerService;
|
||||||
|
private final UserLoginService userLoginService;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
|
||||||
private final GaoCustomerMapper mapper;
|
private final GaoCustomerMapper mapper;
|
||||||
private final AttachmentService attachmentService;
|
|
||||||
|
private final CustomerXSSFBuilder customerXSSFBuilder;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BaseMapper<GaoCustomer, String> mapper() {
|
protected BaseMapper<GaoCustomer, String> mapper() {
|
||||||
@@ -61,180 +68,300 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create(GaoCustomer entity) {
|
public PageResult<GaoCustomer> pageByQuery(GaoCustomerPage page) {
|
||||||
checkEntity(entity, false);
|
TimiException.required(page, "not found page");
|
||||||
super.create(entity);
|
PageResult<GaoCustomer> result = new PageResult<>();
|
||||||
saveAttachment(entity.getId(), resolveAttachmentList(entity));
|
result.setTotal(mapper.countByQuery(page));
|
||||||
loadTransient(entity);
|
result.setList(mapper.selectByQuery(page));
|
||||||
}
|
return result;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(GaoCustomer entity) {
|
|
||||||
checkEntity(entity, true);
|
|
||||||
super.update(entity);
|
|
||||||
saveAttachment(entity.getId(), resolveAttachmentList(entity));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GaoCustomer get(String id) {
|
|
||||||
GaoCustomer customer = super.get(id);
|
|
||||||
loadTransient(customer);
|
|
||||||
return customer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GaoCustomer getByCode(String code) {
|
|
||||||
TimiException.required(code, "not found customer.code");
|
|
||||||
GaoCustomer customer = mapper.selectByCode(code);
|
|
||||||
TimiException.required(customer, "not found customer");
|
|
||||||
loadTransient(customer);
|
|
||||||
return customer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GaoCustomer getNullableByCode(String code) {
|
|
||||||
TimiException.required(code, "not found customer.code");
|
|
||||||
GaoCustomer customer = mapper.selectByCode(code);
|
|
||||||
loadTransient(customer);
|
|
||||||
return customer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public GaoCustomer getOrQuickCreateByCode(String code) {
|
public void create(GaoCustomer customer) {
|
||||||
GaoCustomer customer = getNullableByCode(code);
|
TimiException.required(customer.getName(), "not found customer.name");
|
||||||
if (customer != null) {
|
TimiException.required(customer.getStoreId(), "not found customer.storeId");
|
||||||
return customer;
|
|
||||||
|
Logger logger = new Logger(Logger.Module.GAO, "GAO_CUSTOMER_CREATE");
|
||||||
|
try {
|
||||||
|
logger.setContent(jackson.writeValueAsString(customer));
|
||||||
|
{
|
||||||
|
GaoCustomer byName = getByName(customer.getStoreId(), customer.getName());
|
||||||
|
TimiException.requiredNull(byName, "该姓名客户已登记");
|
||||||
|
}
|
||||||
|
if (TimiJava.isNotEmpty(customer.getCode())) {
|
||||||
|
GaoCustomer byCode = getByCode(customer.getStoreId(), customer.getCode());
|
||||||
|
TimiException.requiredNull(byCode, "该编码客户已登记");
|
||||||
|
}
|
||||||
|
if (TimiJava.isNotEmpty(customer.getIntroducerCustomerId())) {
|
||||||
|
TimiException.requiredTrue(!customer.getIntroducerCustomerId().equals(customer.getId()), "customer.introducerCustomerId invalid");
|
||||||
|
GaoCustomer introducerCustomer = super.get(customer.getIntroducerCustomerId());
|
||||||
|
TimiException.required(introducerCustomer, "not found introducer customer");
|
||||||
|
TimiException.requiredTrue(customer.getStoreId().equals(introducerCustomer.getStoreId()), "介绍人和客户不属于同一门店");
|
||||||
|
}
|
||||||
|
|
||||||
|
customer.setBirthdateCalendar(TimiJava.defaultIfNull(customer.getBirthdateCalendar(), GaoCustomer.BirthdateCalendar.SOLAR));
|
||||||
|
if (TimiJava.isNotEmpty(customer.getBirthdate())) {
|
||||||
|
customer.setAge(ChronoUnit.YEARS.between(customer.getBirthdate(), LocalDate.now()));
|
||||||
|
}
|
||||||
|
customer.setInvitedCount(0L);
|
||||||
|
if (customer.hasIntroducer()) {
|
||||||
|
customer.setInvitedCount(1L);
|
||||||
|
}
|
||||||
|
customer.setCreatorUserId(userLoginService.getRequireLoginUserId());
|
||||||
|
|
||||||
|
super.create(customer);
|
||||||
|
// 附件
|
||||||
|
attachmentService.updateByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId(), customer.getAttachmentList());
|
||||||
|
|
||||||
|
logger.setLevel(Logger.Level.INFO);
|
||||||
|
logger.setResult(customer.getId());
|
||||||
|
} catch (TimiException e) {
|
||||||
|
logger.setLevel(Logger.Level.WARN);
|
||||||
|
logger.setException(e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.setLevel(Logger.Level.ERROR);
|
||||||
|
logger.setException(TimiJava.serializeThrowable(e));
|
||||||
|
log.error("新增 GAO 客户失败", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "新增 GAO 客户失败", e);
|
||||||
|
} finally {
|
||||||
|
loggerService.create(logger);
|
||||||
}
|
}
|
||||||
customer = new GaoCustomer();
|
}
|
||||||
customer.setCode(code);
|
|
||||||
customer.setName(code);
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
create(customer);
|
@Override
|
||||||
return customer;
|
public void update(GaoCustomer customer) {
|
||||||
|
TimiException.required(customer, "not found customer");
|
||||||
|
TimiException.required(customer.getId(), "not found customer.id");
|
||||||
|
TimiException.required(customer.getName(), "not found customer.name");
|
||||||
|
TimiException.required(customer.getStoreId(), "not found customer.storeId");
|
||||||
|
|
||||||
|
Logger logger = new Logger(Logger.Module.GAO, "GAO_CUSTOMER_UPDATE");
|
||||||
|
try {
|
||||||
|
logger.setContent(jackson.writeValueAsString(customer));
|
||||||
|
GaoCustomer dbCustomer = get(customer.getId());
|
||||||
|
TimiException.requiredTrue(dbCustomer.getStoreId().equals(customer.getStoreId()), "customer.storeId invalid");
|
||||||
|
dbCustomer.setCode(TimiJava.defaultIfEmpty(customer.getCode(), null));
|
||||||
|
{
|
||||||
|
if (!Objects.equals(dbCustomer.getCode(), customer.getCode()) && TimiJava.isNotEmpty(customer.getCode())) {
|
||||||
|
GaoCustomer byCode = getByCode(customer.getStoreId(), customer.getCode());
|
||||||
|
TimiException.requiredTrue(byCode == null || !byCode.getId().equals(dbCustomer.getId()), "该姓名客户已登记");
|
||||||
|
}
|
||||||
|
if (!Objects.equals(dbCustomer.getName(), customer.getName())) {
|
||||||
|
GaoCustomer byName = getByName(customer.getStoreId(), customer.getName());
|
||||||
|
TimiException.requiredTrue(byName == null || !byName.getId().equals(dbCustomer.getId()), "该姓名客户已登记");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dbCustomer.setName(customer.getName());
|
||||||
|
dbCustomer.setGender(customer.getGender());
|
||||||
|
dbCustomer.setAge(customer.getAge());
|
||||||
|
dbCustomer.setBirthdateCalendar(customer.getBirthdateCalendar());
|
||||||
|
if (TimiJava.isNotEmpty(customer.getBirthdate())) {
|
||||||
|
dbCustomer.setAge(ChronoUnit.YEARS.between(customer.getBirthdate(), LocalDate.now()));
|
||||||
|
}
|
||||||
|
dbCustomer.setTelephone(customer.getTelephone());
|
||||||
|
dbCustomer.setAddress(customer.getAddress());
|
||||||
|
dbCustomer.setRemark(customer.getRemark());
|
||||||
|
dbCustomer.setDisease(customer.getDisease());
|
||||||
|
dbCustomer.setConditioningPart(customer.getConditioningPart());
|
||||||
|
mapper.update(dbCustomer);
|
||||||
|
|
||||||
|
logger.setLevel(Logger.Level.INFO);
|
||||||
|
logger.setResult(customer.getId());
|
||||||
|
} catch (TimiException e) {
|
||||||
|
logger.setLevel(Logger.Level.WARN);
|
||||||
|
logger.setException(e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.setLevel(Logger.Level.ERROR);
|
||||||
|
logger.setException(TimiJava.serializeThrowable(e));
|
||||||
|
log.error("修改 GAO 客户失败", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "修改 GAO 客户失败", e);
|
||||||
|
} finally {
|
||||||
|
loggerService.create(logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void delete(String id) {
|
||||||
|
Logger logger = new Logger(Logger.Module.GAO, "GAO_CUSTOMER_DELETE");
|
||||||
|
try {
|
||||||
|
logger.setContent(id);
|
||||||
|
GaoCustomer customer = get(id);
|
||||||
|
super.delete(id);
|
||||||
|
changeInvitedCount(customer.getIntroducerCustomerId(), -1);
|
||||||
|
logger.setLevel(Logger.Level.INFO);
|
||||||
|
logger.setResult(id);
|
||||||
|
} catch (TimiException e) {
|
||||||
|
logger.setLevel(Logger.Level.WARN);
|
||||||
|
logger.setException(e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.setLevel(Logger.Level.ERROR);
|
||||||
|
logger.setException(TimiJava.serializeThrowable(e));
|
||||||
|
log.error("删除 GAO 客户失败", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "删除 GAO 客户失败", e);
|
||||||
|
} finally {
|
||||||
|
loggerService.create(logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void updateWithAttachment(GaoCustomer customer) {
|
||||||
|
update(customer);
|
||||||
|
attachmentService.updateByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId(), customer.getAttachmentList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GaoCustomer> search(GaoCustomerSearchReq req) {
|
public GaoCustomer getByCode(String storeId, String code) {
|
||||||
req = resolveSearchReq(req);
|
TimiException.required(storeId, "not found storeId");
|
||||||
List<GaoCustomer> list = mapper.search(req.getKeyword(), req.getIntroducerCustomerId());
|
TimiException.required(code, "not found code");
|
||||||
list.forEach(this::loadTransient);
|
GaoCustomer example = new GaoCustomer();
|
||||||
return list;
|
example.setStoreId(storeId);
|
||||||
|
example.setCode(code);
|
||||||
|
return mapper.selectByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<GaoCustomer> searchPage(Page<GaoCustomerSearchReq> page) {
|
public GaoCustomer getByName(String storeId, String name) {
|
||||||
TimiException.required(page, "not found page");
|
TimiException.required(storeId, "not found storeId");
|
||||||
TimiException.required(page.getIndex(), "not found page.index");
|
TimiException.required(name, "not found name");
|
||||||
TimiException.required(page.getSize(), "not found page.size");
|
GaoCustomer example = new GaoCustomer();
|
||||||
TimiException.requiredTrue(0 <= page.getIndex(), "page.index lt 0");
|
example.setStoreId(storeId);
|
||||||
TimiException.requiredTrue(0 < page.getSize(), "page.size lte 0");
|
example.setName(name);
|
||||||
GaoCustomerSearchReq req = resolveSearchReq(page.getEqualsExample());
|
return mapper.selectByExample(example);
|
||||||
Long total = TimiJava.defaultIfNull(mapper.countSearch(req.getKeyword(), req.getIntroducerCustomerId()), 0L);
|
|
||||||
List<GaoCustomer> list = mapper.searchPage(req.getKeyword(), req.getIntroducerCustomerId(), page.getIndex() * page.getSize(), page.getSize());
|
|
||||||
list.forEach(this::loadTransient);
|
|
||||||
PageResult<GaoCustomer> result = new PageResult<>();
|
|
||||||
result.setTotal(total);
|
|
||||||
result.setList(list);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] exportSearchExcel(GaoCustomerSearchReq req) throws IOException {
|
public List<GaoCustomer> listByIdList(Collection<String> idList) {
|
||||||
List<GaoCustomer> list = search(req);
|
return mapper.selectByIdList(new HashSet<>(idList));
|
||||||
try (Workbook workbook = new XSSFWorkbook(); ByteArrayOutputStream output = new ByteArrayOutputStream()) {
|
}
|
||||||
Sheet sheet = workbook.createSheet("客户列表");
|
|
||||||
CellStyle titleStyle = workbook.createCellStyle();
|
|
||||||
Font titleFont = workbook.createFont();
|
|
||||||
titleFont.setBold(true);
|
|
||||||
titleFont.setFontHeightInPoints((short) 14);
|
|
||||||
titleStyle.setFont(titleFont);
|
|
||||||
CellStyle headerStyle = workbook.createCellStyle();
|
|
||||||
Font headerFont = workbook.createFont();
|
|
||||||
headerFont.setBold(true);
|
|
||||||
headerStyle.setFont(headerFont);
|
|
||||||
|
|
||||||
appendRow(sheet, 0, titleStyle, "客户列表导出");
|
@Override
|
||||||
appendRow(sheet, 1, null, "生成时间", EXPORT_TIME_FORMATTER.format(Instant.now()));
|
public byte[] export(Page<GaoCustomer> page) throws IOException {
|
||||||
appendRow(sheet, 2, null, "关键词", req == null || req.getKeyword() == null || req.getKeyword().isBlank() ? "全部" : req.getKeyword().trim());
|
page.setIndex(0);
|
||||||
appendRow(sheet, 3, null, "记录总数", String.valueOf(list.size()));
|
page.setSize(Long.MAX_VALUE);
|
||||||
appendRow(sheet, 5, headerStyle, "客户编码", "姓名", "性别", "年龄", "电话", "地址", "病症", "备注", "邀请人", "邀请客户数", "创建时间");
|
List<GaoCustomer> list = mapper.selectByPage(page);
|
||||||
int rowIndex = 6;
|
{
|
||||||
|
List<String> idList = list.stream().map(GaoCustomer::getIntroducerCustomerId).filter(TimiJava::isNotEmpty).distinct().toList();
|
||||||
|
Map<String, GaoCustomer> map = mapByIdList(idList);
|
||||||
for (GaoCustomer customer : list) {
|
for (GaoCustomer customer : list) {
|
||||||
appendRow(sheet, rowIndex, null,
|
customer.setIntroducerCustomer(map.get(customer.getIntroducerCustomerId()));
|
||||||
text(customer.getCode()),
|
|
||||||
text(customer.getName()),
|
|
||||||
formatGender(customer),
|
|
||||||
customer.getAge() == null ? "" : String.valueOf(customer.getAge()),
|
|
||||||
text(customer.getTelephone()),
|
|
||||||
text(customer.getAddress()),
|
|
||||||
text(customer.getDisease()),
|
|
||||||
text(customer.getRemark()),
|
|
||||||
customer.getIntroducerCustomer() == null ? "" : text(customer.getIntroducerCustomer().getName()),
|
|
||||||
customer.getInvitedCount() == null ? "0" : String.valueOf(customer.getInvitedCount()),
|
|
||||||
formatExportTime(customer.getCreatedAt())
|
|
||||||
);
|
|
||||||
rowIndex++;
|
|
||||||
}
|
}
|
||||||
for (int index = 0; index < 11; index++) {
|
|
||||||
sheet.autoSizeColumn(index);
|
|
||||||
sheet.setColumnWidth(index, Math.min(Math.max(sheet.getColumnWidth(index), 10 * 256), 36 * 256));
|
|
||||||
}
|
|
||||||
workbook.write(output);
|
|
||||||
return output.toByteArray();
|
|
||||||
}
|
}
|
||||||
|
return customerXSSFBuilder.build(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GaoCustomer> listInvited(String introducerCustomerId) {
|
public List<GaoCustomer> listInvited(String introducerCustomerId) {
|
||||||
TimiException.required(introducerCustomerId, "not found introducerCustomerId");
|
TimiException.required(introducerCustomerId, "not found introducerCustomerId");
|
||||||
List<GaoCustomer> list = mapper.selectInvitedList(introducerCustomerId);
|
GaoCustomer example = new GaoCustomer();
|
||||||
list.forEach(this::loadTransient);
|
example.setIntroducerCustomerId(introducerCustomerId);
|
||||||
return list;
|
return mapper.selectAllByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void saveInviteRelation(GaoCustomerInviteUpdateReq req) {
|
public void saveInviteRelation(String introducerCustomerId, String customerId) {
|
||||||
TimiException.required(req, "not found invite req");
|
TimiException.required(customerId, "not found customerId");
|
||||||
TimiException.required(req.getCustomerId(), "not found invite req.customerId");
|
TimiException.required(introducerCustomerId, "not found introducerCustomerId");
|
||||||
GaoCustomer customer = super.get(req.getCustomerId());
|
|
||||||
customer.setIntroducerCustomerId(req.getIntroducerCustomerId());
|
Logger logger = new Logger(Logger.Module.GAO, "GAO_CUSTOMER_SAVE_INVITE_RELATION");
|
||||||
checkEntity(customer, true);
|
try {
|
||||||
super.update(customer);
|
logger.setContent("introducerCustomerId: %s, customerId: %s".formatted(introducerCustomerId, customerId));
|
||||||
|
GaoCustomer customer = get(customerId);
|
||||||
|
TimiException.required(customer, "not found customer");
|
||||||
|
GaoCustomer introducerCustomer = get(introducerCustomerId);
|
||||||
|
TimiException.required(introducerCustomer, "not found introducerCustomer");
|
||||||
|
TimiException.requiredTrue(customer.getStoreId().equals(introducerCustomer.getStoreId()), "介绍人和客户不属于同一门店");
|
||||||
|
if (introducerCustomer.getIntroducerCustomerId().equals(customer.getIntroducerCustomerId())) {
|
||||||
|
throw new TimiException(TimiCode.ARG_BAD, "customer can not upper be introducer customer");
|
||||||
|
}
|
||||||
|
// 存在旧的邀请来源
|
||||||
|
if (TimiJava.isNotEmpty(customer.getIntroducerCustomerId())) {
|
||||||
|
if (customer.getIntroducerCustomerId().equals(introducerCustomerId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
changeInvitedCount(customer.getIntroducerCustomerId(), -1);
|
||||||
|
}
|
||||||
|
customer.setIntroducerCustomerId(introducerCustomerId);
|
||||||
|
mapper.update(customer);
|
||||||
|
changeInvitedCount(introducerCustomerId, +1);
|
||||||
|
logger.setLevel(Logger.Level.INFO);
|
||||||
|
} catch (TimiException e) {
|
||||||
|
logger.setLevel(Logger.Level.WARN);
|
||||||
|
logger.setException(e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.setLevel(Logger.Level.ERROR);
|
||||||
|
logger.setException(TimiJava.serializeThrowable(e));
|
||||||
|
log.error("保存 GAO 客户邀请关系失败", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "保存 GAO 客户邀请关系失败", e);
|
||||||
|
} finally {
|
||||||
|
loggerService.create(logger);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void deleteInviteRelation(String customerId) {
|
public void deleteInviteRelation(String customerId) {
|
||||||
TimiException.required(customerId, "not found customerId");
|
TimiException.required(customerId, "not found customerId");
|
||||||
GaoCustomer customer = super.get(customerId);
|
|
||||||
customer.setIntroducerCustomerId(null);
|
Logger logger = new Logger(Logger.Module.GAO, "GAO_CUSTOMER_DELETE_INVITE_RELATION");
|
||||||
super.update(customer);
|
try {
|
||||||
|
logger.setContent(customerId);
|
||||||
|
GaoCustomer customer = get(customerId);
|
||||||
|
customer.setIntroducerCustomerId(null);
|
||||||
|
mapper.update(customer);
|
||||||
|
|
||||||
|
changeInvitedCount(customer.getIntroducerCustomerId(), -1);
|
||||||
|
logger.setLevel(Logger.Level.INFO);
|
||||||
|
logger.setResult(customerId);
|
||||||
|
} catch (TimiException e) {
|
||||||
|
logger.setLevel(Logger.Level.WARN);
|
||||||
|
logger.setException(e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.setLevel(Logger.Level.ERROR);
|
||||||
|
logger.setException(TimiJava.serializeThrowable(e));
|
||||||
|
log.error("删除 GAO 客户邀请关系失败", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "删除 GAO 客户邀请关系失败", e);
|
||||||
|
} finally {
|
||||||
|
loggerService.create(logger);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GaoCustomerDailyStatView> statDailyTrend(GaoCustomerTrendStatReq req) {
|
public List<GaoCustomerDailyStateView> stateDailyTrend(GaoCustomerTrendStateReq req) {
|
||||||
TimiException.required(req, "not found req");
|
TimiException.required(req, "not found req");
|
||||||
|
TimiException.required(req.getStoreId(), "not found req.storeId");
|
||||||
TimiException.required(req.getBeginCreatedAt(), "not found req.beginCreatedAt");
|
TimiException.required(req.getBeginCreatedAt(), "not found req.beginCreatedAt");
|
||||||
TimiException.required(req.getEndCreatedAt(), "not found req.endCreatedAt");
|
TimiException.required(req.getEndCreatedAt(), "not found req.endCreatedAt");
|
||||||
TimiException.requiredTrue(req.getEndCreatedAt() >= req.getBeginCreatedAt(), "req.endCreatedAt lt req.beginCreatedAt");
|
TimiException.requiredTrue(req.getEndCreatedAt() >= req.getBeginCreatedAt(), "req.endCreatedAt lt req.beginCreatedAt");
|
||||||
ZoneId zoneId = ZoneId.systemDefault();
|
ZoneId zoneId = ZoneId.systemDefault();
|
||||||
LocalDate beginDate = Instant.ofEpochMilli(req.getBeginCreatedAt()).atZone(zoneId).toLocalDate();
|
LocalDate beginDate = Instant.ofEpochMilli(req.getBeginCreatedAt()).atZone(zoneId).toLocalDate();
|
||||||
LocalDate endDate = Instant.ofEpochMilli(req.getEndCreatedAt()).atZone(zoneId).toLocalDate();
|
LocalDate endDate = Instant.ofEpochMilli(req.getEndCreatedAt()).atZone(zoneId).toLocalDate();
|
||||||
checkDailyStatRange(beginDate, endDate);
|
|
||||||
|
long days = ChronoUnit.DAYS.between(beginDate, endDate) + 1;
|
||||||
|
TimiException.requiredTrue(days <= 366, "daily stat range too large");
|
||||||
|
|
||||||
long beginCreatedAt = beginDate.atStartOfDay(zoneId).toInstant().toEpochMilli();
|
long beginCreatedAt = beginDate.atStartOfDay(zoneId).toInstant().toEpochMilli();
|
||||||
long endCreatedAt = endDate.plusDays(1).atStartOfDay(zoneId).toInstant().toEpochMilli() - 1;
|
long endCreatedAt = endDate.plusDays(1).atStartOfDay(zoneId).toInstant().toEpochMilli() - 1;
|
||||||
Map<Integer, Long> newCustomerCountMap = new HashMap<>();
|
Map<Integer, Long> newCustomerCountMap = new HashMap<>();
|
||||||
for (GaoCustomerDailyStatView view : mapper.statDailyNewCustomer(beginCreatedAt, endCreatedAt)) {
|
for (GaoCustomerDailyStateView view : mapper.stateDailyNewCustomer(req.getStoreId(), beginCreatedAt, endCreatedAt)) {
|
||||||
newCustomerCountMap.put(view.getDateValue(), TimiJava.defaultIfNull(view.getNewCustomerCount(), 0L));
|
newCustomerCountMap.put(view.getDateValue(), TimiJava.defaultIfNull(view.getNewCustomerCount(), 0L));
|
||||||
}
|
}
|
||||||
long totalCustomerCount = TimiJava.defaultIfNull(mapper.countCreatedBefore(beginCreatedAt), 0L);
|
long totalCustomerCount = TimiJava.defaultIfNull(mapper.countCreatedBefore(req.getStoreId(), beginCreatedAt), 0L);
|
||||||
List<GaoCustomerDailyStatView> list = new ArrayList<>();
|
List<GaoCustomerDailyStateView> list = new ArrayList<>();
|
||||||
for (LocalDate date = beginDate; !date.isAfter(endDate); date = date.plusDays(1)) {
|
for (LocalDate date = beginDate; !date.isAfter(endDate); date = date.plusDays(1)) {
|
||||||
int dateValue = Integer.parseInt(DAY_FORMATTER.format(date));
|
int dateValue = Integer.parseInt(DAY_FORMATTER.format(date));
|
||||||
long newCustomerCount = TimiJava.defaultIfNull(newCustomerCountMap.get(dateValue), 0L);
|
long newCustomerCount = TimiJava.defaultIfNull(newCustomerCountMap.get(dateValue), 0L);
|
||||||
totalCustomerCount += newCustomerCount;
|
totalCustomerCount += newCustomerCount;
|
||||||
GaoCustomerDailyStatView view = new GaoCustomerDailyStatView();
|
GaoCustomerDailyStateView view = new GaoCustomerDailyStateView();
|
||||||
view.setDateValue(dateValue);
|
view.setDateValue(dateValue);
|
||||||
view.setNewCustomerCount(newCustomerCount);
|
view.setNewCustomerCount(newCustomerCount);
|
||||||
view.setTotalCustomerCount(totalCustomerCount);
|
view.setTotalCustomerCount(totalCustomerCount);
|
||||||
@@ -243,115 +370,18 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkDailyStatRange(LocalDate beginDate, LocalDate endDate) {
|
@Override
|
||||||
long days = ChronoUnit.DAYS.between(beginDate, endDate) + 1;
|
public List<GaoCustomerGenderStatView> stateGender(String storeId) {
|
||||||
TimiException.requiredTrue(days <= 366, "daily stat range too large");
|
TimiException.required(storeId, "not found storeId");
|
||||||
|
return mapper.stateGender(storeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GaoCustomerSearchReq resolveSearchReq(GaoCustomerSearchReq req) {
|
private void changeInvitedCount(String customerId, long delta) {
|
||||||
return req == null ? new GaoCustomerSearchReq() : req;
|
if (delta == 0) {
|
||||||
}
|
|
||||||
|
|
||||||
private void checkEntity(GaoCustomer entity, boolean requireId) {
|
|
||||||
TimiException.required(entity, "not found customer");
|
|
||||||
if (requireId) {
|
|
||||||
TimiException.required(entity.getId(), "not found customer.id");
|
|
||||||
}
|
|
||||||
TimiException.required(entity.getName(), "not found customer.name");
|
|
||||||
entity.setName(entity.getName().trim());
|
|
||||||
TimiException.requiredTrue(!entity.getName().isEmpty(), "not found customer.name");
|
|
||||||
GaoCustomer dbCustomer = mapper.selectByName(entity.getName());
|
|
||||||
if (dbCustomer != null && !dbCustomer.getId().equals(entity.getId())) {
|
|
||||||
throw new TimiException(TimiCode.ARG_BAD, "客户姓名已存在");
|
|
||||||
}
|
|
||||||
if (TimiJava.isNotEmpty(entity.getCode())) {
|
|
||||||
dbCustomer = mapper.selectByCode(entity.getCode());
|
|
||||||
if (dbCustomer != null && !dbCustomer.getId().equals(entity.getId())) {
|
|
||||||
throw new TimiException(TimiCode.ARG_BAD, "客户编码已存在");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (TimiJava.isNotEmpty(entity.getIntroducerCustomerId())) {
|
|
||||||
TimiException.requiredTrue(!entity.getIntroducerCustomerId().equals(entity.getId()), "customer.introducerCustomerId invalid");
|
|
||||||
TimiException.required(super.get(entity.getIntroducerCustomerId()), "not found introducer customer");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadTransient(GaoCustomer customer) {
|
|
||||||
if (customer == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (TimiJava.isNotEmpty(customer.getIntroducerCustomerId())) {
|
GaoCustomer customer = get(customerId);
|
||||||
customer.setIntroducerCustomer(super.get(customer.getIntroducerCustomerId()));
|
customer.setInvitedCount(customer.getInvitedCount() + delta);
|
||||||
}
|
mapper.update(customer);
|
||||||
customer.setInvitedCount(mapper.countInvited(customer.getId()));
|
|
||||||
customer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId(), GaoCustomer.AttachType.PHOTO.name()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveAttachment(String customerId, List<Attachment> attachmentList) {
|
|
||||||
if (attachmentList == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (Attachment attachment : attachmentList) {
|
|
||||||
attachment.setBizType(Attachment.BizType.GAO_CUSTOMER);
|
|
||||||
attachment.setBizId(customerId);
|
|
||||||
attachment.setAttachType(GaoCustomer.AttachType.PHOTO.name());
|
|
||||||
}
|
|
||||||
BizUpdateReq req = new BizUpdateReq();
|
|
||||||
req.setBizType(Attachment.BizType.GAO_CUSTOMER);
|
|
||||||
req.setBizId(customerId);
|
|
||||||
req.setItems(attachmentList);
|
|
||||||
attachmentService.updateByBiz(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Attachment> resolveAttachmentList(GaoCustomer customer) {
|
|
||||||
if (customer.getAttachmentIdList() != null) {
|
|
||||||
return buildPhotoAttachmentList(customer.getAttachmentIdList());
|
|
||||||
}
|
|
||||||
return customer.getAttachmentList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Attachment> buildPhotoAttachmentList(List<String> attachmentIdList) {
|
|
||||||
List<Attachment> list = new ArrayList<>();
|
|
||||||
for (String attachmentId : attachmentIdList) {
|
|
||||||
if (attachmentId == null || attachmentId.isBlank()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Attachment attachment = new Attachment();
|
|
||||||
attachment.setTempFileId(attachmentId.trim());
|
|
||||||
attachment.setAttachType(GaoCustomer.AttachType.PHOTO.name());
|
|
||||||
list.add(attachment);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendRow(Sheet sheet, int rowIndex, CellStyle style, String... values) {
|
|
||||||
Row row = sheet.createRow(rowIndex);
|
|
||||||
for (int index = 0; index < values.length; index++) {
|
|
||||||
row.createCell(index).setCellValue(values[index]);
|
|
||||||
if (style != null) {
|
|
||||||
row.getCell(index).setCellStyle(style);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String formatGender(GaoCustomer customer) {
|
|
||||||
if (customer.getGender() == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return switch (customer.getGender()) {
|
|
||||||
case MALE -> "男";
|
|
||||||
case FEMALE -> "女";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private String formatExportTime(Long value) {
|
|
||||||
if (value == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return EXPORT_TIME_FORMATTER.format(Instant.ofEpochMilli(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String text(Object value) {
|
|
||||||
return value == null ? "" : value.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+389
@@ -0,0 +1,389 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service.implement;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoEventRecordMapper;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoPointTriggerService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoEventRecordService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoEventService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreBusinessDayService;
|
||||||
|
import com.imyeyu.api.modules.gao.util.EventRecordXSSFBuilder;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerEventRankView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordPage;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordRankPage;
|
||||||
|
import com.imyeyu.api.modules.system.entity.Logger;
|
||||||
|
import com.imyeyu.api.modules.system.service.LoggerService;
|
||||||
|
import com.imyeyu.api.modules.user.service.RoleChecker;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
|
import com.imyeyu.utils.Time;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.time.temporal.TemporalAdjusters;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// 登记事件记录服务实现
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-07-27 14:11
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEventRecord, String> implements GaoEventRecordService {
|
||||||
|
|
||||||
|
private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||||
|
|
||||||
|
private final ObjectMapper jackson;
|
||||||
|
private final RoleChecker roleChecker;
|
||||||
|
private final LoggerService loggerService;
|
||||||
|
private final GaoEventService eventService;
|
||||||
|
private final UserLoginService userLoginService;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
private final GaoCustomerService customerService;
|
||||||
|
private final GaoStoreBusinessDayService businessDayService;
|
||||||
|
private final GaoPointTriggerService pointTriggerService;
|
||||||
|
|
||||||
|
private final GaoEventRecordMapper mapper;
|
||||||
|
|
||||||
|
private final EventRecordXSSFBuilder xssfBuilder;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseMapper<GaoEventRecord, String> mapper() {
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void create(GaoEventRecord record) {
|
||||||
|
TimiException.required(record, "not found record");
|
||||||
|
|
||||||
|
Logger logger = new Logger(Logger.Module.GAO, "GAO_EVENT_RECORD_BATCH_CREATE");
|
||||||
|
try {
|
||||||
|
logger.setContent(jackson.writeValueAsString(record));
|
||||||
|
|
||||||
|
String loginUserId = userLoginService.getRequireLoginUserId();
|
||||||
|
Long registeredAt = TimiJava.defaultIfNull(record.getRegisteredAt(), Time.now());
|
||||||
|
GaoEvent event = eventService.get(record.getEventId());
|
||||||
|
TimiException.required(event, "not found event");
|
||||||
|
TimiException.required(event.getStoreId(), "not found event.storeId");
|
||||||
|
verifyRecordValue(event, record.getNumberValue());
|
||||||
|
// 检查权限
|
||||||
|
checkEventPermission(event);
|
||||||
|
int registeredDateValue = dateValue(registeredAt);
|
||||||
|
long businessDayNo = businessDayService.resolveOpenBusinessDay(event.getStoreId(), registeredDateValue).getBusinessDayNo();
|
||||||
|
|
||||||
|
List<String> customerIdList = record.getCustomerIdList();
|
||||||
|
if (TimiJava.isEmpty(customerIdList)) {
|
||||||
|
customerIdList = List.of(record.getCustomerId());
|
||||||
|
}
|
||||||
|
TimiException.required(customerIdList, "not found customerId or empty customerIdList");
|
||||||
|
|
||||||
|
GaoEventRecord firstRecord = null;
|
||||||
|
List<String> logIdList = new ArrayList<>();
|
||||||
|
for (int i = 0; i < customerIdList.size(); i++) {
|
||||||
|
String customerId = customerIdList.get(i);
|
||||||
|
// 检查事件可登记
|
||||||
|
checkEventCreatable(customerId, event, registeredAt);
|
||||||
|
GaoCustomer customer = customerService.get(customerId);
|
||||||
|
TimiException.required(customer, "not found customer");
|
||||||
|
TimiException.requiredTrue(event.getStoreId().equals(customer.getStoreId()), "客户和登记事件不属于同一门店");
|
||||||
|
|
||||||
|
GaoEventRecord dbRecord = new GaoEventRecord();
|
||||||
|
dbRecord.setCustomerId(customerId);
|
||||||
|
dbRecord.setStoreId(event.getStoreId());
|
||||||
|
dbRecord.setEventId(record.getEventId());
|
||||||
|
dbRecord.setOperatorUserId(loginUserId);
|
||||||
|
dbRecord.setRemark(record.getRemark());
|
||||||
|
dbRecord.setRegisteredAt(registeredAt);
|
||||||
|
dbRecord.setRegisteredDateValue(registeredDateValue);
|
||||||
|
dbRecord.setBusinessDayNo(businessDayNo);
|
||||||
|
dbRecord.setPointValue(record.getPointValue());
|
||||||
|
dbRecord.setNumberValue(record.getNumberValue());
|
||||||
|
dbRecord.setEarnedPointValue(0L);
|
||||||
|
super.create(dbRecord);
|
||||||
|
// 附件
|
||||||
|
if (i == 0) {
|
||||||
|
// 第一个记录储存附件
|
||||||
|
firstRecord = dbRecord;
|
||||||
|
attachmentService.updateByBizId(Attachment.BizType.GAO_EVENT_RECORD, dbRecord.getId(), record.getAttachmentList());
|
||||||
|
} else {
|
||||||
|
// 其他记录克隆第一个记录附件
|
||||||
|
List<Attachment> attachmentList = attachmentService.listByBizId(Attachment.BizType.GAO_EVENT_RECORD, firstRecord.getId());
|
||||||
|
for (Attachment attachment : attachmentList) {
|
||||||
|
Attachment clone = attachmentService.clone(attachment.getId());
|
||||||
|
clone.setId(dbRecord.getId());
|
||||||
|
attachmentService.update(clone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pointTriggerService.onEventRecordCreated(dbRecord);
|
||||||
|
logIdList.add(dbRecord.getId());
|
||||||
|
}
|
||||||
|
logger.setLevel(Logger.Level.INFO);
|
||||||
|
logger.setResult(String.join(",", logIdList));
|
||||||
|
} catch (TimiException e) {
|
||||||
|
logger.setLevel(Logger.Level.WARN);
|
||||||
|
logger.setException(e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.setLevel(Logger.Level.ERROR);
|
||||||
|
logger.setException(TimiJava.serializeThrowable(e));
|
||||||
|
log.error("create event record error", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "create event record error", e);
|
||||||
|
} finally {
|
||||||
|
loggerService.create(logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void createBatch(List<GaoEventRecord> recordList) {
|
||||||
|
for (GaoEventRecord record : TimiJava.safeIterable(recordList)) {
|
||||||
|
create(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void update(GaoEventRecord record) {
|
||||||
|
TimiException.required(record, "not found record");
|
||||||
|
TimiException.required(record.getId(), "not found record.id");
|
||||||
|
|
||||||
|
Logger logger = new Logger(Logger.Module.GAO, "GAO_EVENT_RECORD_UPDATE");
|
||||||
|
try {
|
||||||
|
logger.setContent(jackson.writeValueAsString(record));
|
||||||
|
GaoEventRecord dbRecord = get(record.getId());
|
||||||
|
TimiException.required(dbRecord, "not found event record");
|
||||||
|
TimiException.required(record.getStoreId() == null || record.getStoreId().equals(dbRecord.getStoreId()), "record.storeId invalid");
|
||||||
|
verifyImmutableRecordFields(record, dbRecord);
|
||||||
|
|
||||||
|
GaoEvent event = eventService.get(dbRecord.getEventId());
|
||||||
|
TimiException.required(event, "not found event");
|
||||||
|
TimiException.required(event.getStoreId(), "not found event.storeId");
|
||||||
|
checkEventPermission(event);
|
||||||
|
dbRecord.setRemark(record.getRemark());
|
||||||
|
super.update(dbRecord);
|
||||||
|
attachmentService.updateByBizId(Attachment.BizType.GAO_EVENT_RECORD, record.getId(), record.getAttachmentList());
|
||||||
|
logger.setLevel(Logger.Level.INFO);
|
||||||
|
logger.setResult(record.getId());
|
||||||
|
} catch (TimiException e) {
|
||||||
|
logger.setLevel(Logger.Level.WARN);
|
||||||
|
logger.setException(e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.setLevel(Logger.Level.ERROR);
|
||||||
|
logger.setException(TimiJava.serializeThrowable(e));
|
||||||
|
log.error("修改 GAO 登记记录失败", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "修改 GAO 登记记录失败", e);
|
||||||
|
} finally {
|
||||||
|
loggerService.create(logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void delete(String id) {
|
||||||
|
TimiException.required(id, "not found record.id");
|
||||||
|
Logger logger = new Logger(Logger.Module.GAO, "GAO_EVENT_RECORD_DELETE");
|
||||||
|
try {
|
||||||
|
logger.setContent(id);
|
||||||
|
GaoEventRecord record = get(id);
|
||||||
|
TimiException.required(record, "not found event record");
|
||||||
|
pointTriggerService.revokeByEventRecord(record);
|
||||||
|
super.delete(id);
|
||||||
|
logger.setLevel(Logger.Level.INFO);
|
||||||
|
logger.setResult(id);
|
||||||
|
} catch (TimiException e) {
|
||||||
|
logger.setLevel(Logger.Level.WARN);
|
||||||
|
logger.setException(e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.setLevel(Logger.Level.ERROR);
|
||||||
|
logger.setException(TimiJava.serializeThrowable(e));
|
||||||
|
log.error("删除 GAO 登记记录失败", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "删除 GAO 登记记录失败", e);
|
||||||
|
} finally {
|
||||||
|
loggerService.create(logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void createWithCustomer(GaoCustomer customer) {
|
||||||
|
TimiException.required(customer, "not found customer");
|
||||||
|
if (TimiJava.isNotEmpty(customer.getId())) {
|
||||||
|
// 有 ID 表示给已有客户绑定新编码;编码不能被其他客户占用
|
||||||
|
GaoCustomer dbCustomer = customerService.get(customer.getId());
|
||||||
|
TimiException.required(dbCustomer, "not found customer");
|
||||||
|
if (TimiJava.isNotEmpty(customer.getCode())) {
|
||||||
|
GaoCustomer byCode = customerService.getByCode(dbCustomer.getStoreId(), customer.getCode());
|
||||||
|
TimiException.requiredTrue(byCode == null || dbCustomer.getId().equals(byCode.getId()), "该编码客户已登记");
|
||||||
|
dbCustomer.setCode(customer.getCode());
|
||||||
|
customerService.update(dbCustomer);
|
||||||
|
}
|
||||||
|
customer.setId(dbCustomer.getId());
|
||||||
|
} else {
|
||||||
|
// 无 ID 表示新开客户档案;创建客户只强制姓名唯一,其余字段按请求透传
|
||||||
|
customerService.create(customer);
|
||||||
|
}
|
||||||
|
if (TimiJava.isEmpty(customer.getEventRecordList())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (GaoEventRecord record : TimiJava.safeIterable(customer.getEventRecordList())) {
|
||||||
|
record.setCustomerId(customer.getId());
|
||||||
|
}
|
||||||
|
createBatch(customer.getEventRecordList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<GaoEventRecord> pageByRange(GaoEventRecordPage page) {
|
||||||
|
TimiException.required(page.getStoreId(), "not found page.storeId");
|
||||||
|
PageResult<GaoEventRecord> result = new PageResult<>();
|
||||||
|
result.setTotal(mapper.countByRange(page));
|
||||||
|
result.setList(mapper.selectByRange(page));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long sumNumberValueByRange(GaoEventRecordPage page) {
|
||||||
|
TimiException.required(page.getStoreId(), "not found page.storeId");
|
||||||
|
return mapper.sumNumberValueByRange(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] export(GaoEventRecordPage page) throws IOException {
|
||||||
|
TimiException.required(page.getStoreId(), "not found page.storeId");
|
||||||
|
List<GaoEventRecord> list = mapper.selectByRange(page);
|
||||||
|
return xssfBuilder.build(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<GaoCustomerEventRankView> pageRankByRange(GaoEventRecordRankPage page) {
|
||||||
|
TimiException.required(page.getStoreId(), "not found page.storeId");
|
||||||
|
validateRankPage(page);
|
||||||
|
if (page.getRankType() == GaoEventRecordRankPage.RankType.CONTINUOUS_DAYS) {
|
||||||
|
page.setTodayDateValue(dateValue(Time.now()));
|
||||||
|
}
|
||||||
|
PageResult<GaoCustomerEventRankView> result = new PageResult<>();
|
||||||
|
result.setTotal(mapper.countRankByRange(page));
|
||||||
|
result.setList(mapper.selectRankByRange(page));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 校验登记数值排行的事件范围
|
||||||
|
///
|
||||||
|
/// @param page 排行榜查询请求
|
||||||
|
private void validateRankPage(GaoEventRecordRankPage page) {
|
||||||
|
if (page.getRankType() != GaoEventRecordRankPage.RankType.TOTAL_NUMBER_VALUE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> eventIdList = page.getEventIdList();
|
||||||
|
TimiException.requiredTrue(eventIdList != null && eventIdList.size() == 1, "按登记数值排行必须选择单个事件");
|
||||||
|
GaoEvent event = eventService.mapByIdList(eventIdList).get(eventIdList.get(0));
|
||||||
|
TimiException.requiredTrue(event != null && event.getValueType() == GaoEvent.ValueType.NUMBER, "按登记数值排行只能选择 NUMBER 事件");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkEventPermission(GaoEvent event) {
|
||||||
|
List<String> roleCodeList = eventService.listRoleCode(event.getId());
|
||||||
|
TimiException.requiredTrue(roleCodeList != null && !roleCodeList.isEmpty(), "登记事件未配置可登记角色");
|
||||||
|
roleChecker.checkAny(ModuleCode.GAO, roleCodeList.toArray(String[]::new));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkEventCreatable(String customerId, GaoEvent event, long registeredAt) {
|
||||||
|
TimiException.requiredTrue(event.getStatus() == null || event.getStatus() == GaoEvent.Status.ACTIVE, "登记事件不可登记");
|
||||||
|
TimiException.requiredTrue(event.getBeginAt() == null || event.getBeginAt() <= registeredAt, "登记事件未到可登记时间");
|
||||||
|
TimiException.requiredTrue(event.getEndAt() == null || registeredAt <= event.getEndAt(), "登记事件已过可登记时间");
|
||||||
|
GaoEvent.LimitType limitType = TimiJava.defaultIfNull(event.getLimitType(), GaoEvent.LimitType.NONE);
|
||||||
|
switch (limitType) {
|
||||||
|
case DAILY_HALF_DAY -> {
|
||||||
|
long today = Time.today(registeredAt);
|
||||||
|
long noon = today + Time.D / 2;
|
||||||
|
long beginAt = today, endAt;
|
||||||
|
if (today + registeredAt < noon) {
|
||||||
|
// 上半日
|
||||||
|
endAt = noon;
|
||||||
|
} else {
|
||||||
|
// 下半日
|
||||||
|
beginAt = noon;
|
||||||
|
endAt = today + Time.D;
|
||||||
|
}
|
||||||
|
Long count = mapper.count(event.getStoreId(), customerId, event.getId(), beginAt, endAt);
|
||||||
|
TimiException.requiredTrue(TimiJava.defaultIfNull(count, 0L) < 1, "该客户当前半日已登记该事件");
|
||||||
|
}
|
||||||
|
case NATURAL_DAY -> {
|
||||||
|
long beginAt = Time.today(registeredAt);
|
||||||
|
long endAt = beginAt + Time.D;
|
||||||
|
Long count = mapper.count(event.getStoreId(), customerId, event.getId(), beginAt, endAt);
|
||||||
|
TimiException.requiredTrue(TimiJava.defaultIfNull(count, 0L) < 1, "该客户当前半日已登记该事件");
|
||||||
|
}
|
||||||
|
case INTERVAL_HOUR -> {
|
||||||
|
long beginAt = registeredAt - event.getLimitValue() * Time.H;
|
||||||
|
Long count = mapper.count(event.getStoreId(), customerId, event.getId(), beginAt, registeredAt);
|
||||||
|
TimiException.requiredTrue(TimiJava.defaultIfNull(count, 0L) < 1, "该客户登记该事件间隔不足");
|
||||||
|
}
|
||||||
|
case NATURAL_MONTH -> {
|
||||||
|
ZoneId zone = ZoneId.systemDefault();
|
||||||
|
ZonedDateTime zdt = Instant.ofEpochMilli(registeredAt).atZone(zone);
|
||||||
|
long beginAt = zdt.with(TemporalAdjusters.firstDayOfMonth()).truncatedTo(ChronoUnit.DAYS).toInstant().toEpochMilli();
|
||||||
|
long endAt = zdt.with(TemporalAdjusters.firstDayOfNextMonth()).truncatedTo(ChronoUnit.DAYS).toInstant().toEpochMilli();
|
||||||
|
Long count = mapper.count(event.getStoreId(), customerId, event.getId(), beginAt, endAt);
|
||||||
|
TimiException.requiredTrue(TimiJava.defaultIfNull(count, 0L) < 1, "该客户当月已登记该事件");
|
||||||
|
}
|
||||||
|
case TOTAL_LIMIT -> {
|
||||||
|
Long count = mapper.count(event.getStoreId(), null, event.getId(), null, null);
|
||||||
|
TimiException.requiredTrue(TimiJava.defaultIfNull(count, 0L) < event.getLimitValue(), "登记事件总次数已达上限");
|
||||||
|
}
|
||||||
|
case CUSTOMER_TOTAL_LIMIT -> {
|
||||||
|
Long count = mapper.count(event.getStoreId(), customerId, event.getId(), null, null);
|
||||||
|
TimiException.requiredTrue(TimiJava.defaultIfNull(count, 0L) < event.getLimitValue(), "该客户登记该事件次数已达上限");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyRecordValue(GaoEvent event, Long numberValue) {
|
||||||
|
GaoEvent.ValueType valueType = TimiJava.defaultIfNull(event.getValueType(), GaoEvent.ValueType.NONE);
|
||||||
|
if (numberValue != null) {
|
||||||
|
TimiException.requiredTrue(0 <= numberValue, "numberValue 不能为负数");
|
||||||
|
}
|
||||||
|
if (valueType == GaoEvent.ValueType.NONE) {
|
||||||
|
TimiException.requiredNull(numberValue, "NONE 事件不能提交 numberValue");
|
||||||
|
} else if (Boolean.TRUE.equals(event.getRequireValue())) {
|
||||||
|
TimiException.required(numberValue, "该事件必须提交 numberValue");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyImmutableRecordFields(GaoEventRecord request, GaoEventRecord dbRecord) {
|
||||||
|
TimiException.requiredTrue(request.getCustomerId() == null || request.getCustomerId().equals(dbRecord.getCustomerId()), "登记记录 customerId 创建后不可修改");
|
||||||
|
TimiException.requiredTrue(request.getEventId() == null || request.getEventId().equals(dbRecord.getEventId()), "登记记录 eventId 创建后不可修改");
|
||||||
|
TimiException.requiredTrue(request.getRegisteredAt() == null || request.getRegisteredAt().equals(dbRecord.getRegisteredAt()), "登记记录 registeredAt 创建后不可修改");
|
||||||
|
TimiException.requiredTrue(request.getPointValue() == null || request.getPointValue().equals(dbRecord.getPointValue()), "登记记录 pointValue 创建后不可修改");
|
||||||
|
TimiException.requiredTrue(request.getNumberValue() == null || request.getNumberValue().equals(dbRecord.getNumberValue()), "登记记录 numberValue 创建后不可修改");
|
||||||
|
}
|
||||||
|
|
||||||
|
private int dateValue(long time) {
|
||||||
|
LocalDate date = Instant.ofEpochMilli(time).atZone(ZoneId.systemDefault()).toLocalDate();
|
||||||
|
return Integer.parseInt(DAY_FORMATTER.format(date));
|
||||||
|
}
|
||||||
|
}
|
||||||
+265
@@ -0,0 +1,265 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service.implement;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEventRoleRelation;
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoEventMapper;
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoEventRecordMapper;
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoEventRoleRelationMapper;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoEventService;
|
||||||
|
import com.imyeyu.api.modules.system.entity.Logger;
|
||||||
|
import com.imyeyu.api.modules.system.service.LoggerService;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
|
import com.imyeyu.utils.Time;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件服务实现
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-07-27 09:00
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GaoEventServiceImplement extends AbstractEntityService<GaoEvent, String> implements GaoEventService {
|
||||||
|
|
||||||
|
private final ObjectMapper jackson;
|
||||||
|
|
||||||
|
private final LoggerService loggerService;
|
||||||
|
|
||||||
|
private final GaoEventMapper mapper;
|
||||||
|
private final GaoEventRecordMapper eventRecordMapper;
|
||||||
|
private final GaoEventRoleRelationMapper roleRelationMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseMapper<GaoEvent, String> mapper() {
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void create(GaoEvent event) {
|
||||||
|
TimiException.required(event, "not found event");
|
||||||
|
TimiException.required(event.getStoreId(), "not found event.storeId");
|
||||||
|
TimiException.required(event.getName(), "not found event.name");
|
||||||
|
|
||||||
|
Logger logger = new Logger(Logger.Module.GAO, "GAO_EVENT_CREATE");
|
||||||
|
try {
|
||||||
|
logger.setContent(jackson.writeValueAsString(event));
|
||||||
|
|
||||||
|
event.setStatus(TimiJava.defaultIfNull(event.getStatus(), GaoEvent.Status.DRAFT));
|
||||||
|
event.setValueType(TimiJava.defaultIfNull(event.getValueType(), GaoEvent.ValueType.NONE));
|
||||||
|
event.setRequireValue(TimiJava.defaultIfNull(event.getRequireValue(), false));
|
||||||
|
event.setRequirePhoto(TimiJava.defaultIfNull(event.getRequirePhoto(), false));
|
||||||
|
event.setLimitType(TimiJava.defaultIfNull(event.getLimitType(), GaoEvent.LimitType.NONE));
|
||||||
|
event.setSort(TimiJava.defaultIfNull(event.getSort(), 0));
|
||||||
|
verifyEvent(event);
|
||||||
|
super.create(event);
|
||||||
|
|
||||||
|
saveRoleRelation(event.getId(), event.getRoleCodeList());
|
||||||
|
logger.setLevel(Logger.Level.INFO);
|
||||||
|
logger.setResult(event.getId());
|
||||||
|
} catch (TimiException e) {
|
||||||
|
logger.setLevel(Logger.Level.WARN);
|
||||||
|
logger.setException(e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.setLevel(Logger.Level.ERROR);
|
||||||
|
logger.setException(TimiJava.serializeThrowable(e));
|
||||||
|
log.error("create event error", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "create event error", e);
|
||||||
|
} finally {
|
||||||
|
loggerService.create(logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void update(GaoEvent event) {
|
||||||
|
Logger logger = new Logger(Logger.Module.GAO, "GAO_EVENT_UPDATE");
|
||||||
|
try {
|
||||||
|
logger.setContent(jackson.writeValueAsString(event));
|
||||||
|
GaoEvent dbEvent = get(event.getId());
|
||||||
|
TimiException.required(dbEvent, "not found event");
|
||||||
|
TimiException.requiredTrue(dbEvent.getStoreId().equals(event.getStoreId()), "event.storeId invalid");
|
||||||
|
GaoEvent.ValueType oldValueType = dbEvent.getValueType();
|
||||||
|
GaoEvent.ValueUnit oldValueUnit = dbEvent.getValueUnit();
|
||||||
|
dbEvent.setName(event.getName());
|
||||||
|
dbEvent.setDescription(event.getDescription());
|
||||||
|
dbEvent.setColor(event.getColor());
|
||||||
|
dbEvent.setStatus(event.getStatus());
|
||||||
|
dbEvent.setValueType(TimiJava.defaultIfNull(event.getValueType(), oldValueType));
|
||||||
|
if (event.getValueUnit() != null) {
|
||||||
|
dbEvent.setValueUnit(event.getValueUnit());
|
||||||
|
} else if (event.getValueType() != null && event.getValueType() != oldValueType) {
|
||||||
|
dbEvent.setValueUnit(null);
|
||||||
|
} else {
|
||||||
|
dbEvent.setValueUnit(oldValueUnit);
|
||||||
|
}
|
||||||
|
if (event.getRequireValue() != null) {
|
||||||
|
dbEvent.setRequireValue(event.getRequireValue());
|
||||||
|
} else if (event.getValueType() != null && event.getValueType() != oldValueType) {
|
||||||
|
dbEvent.setRequireValue(false);
|
||||||
|
} else {
|
||||||
|
dbEvent.setRequireValue(dbEvent.getRequireValue());
|
||||||
|
}
|
||||||
|
dbEvent.setRequirePhoto(event.getRequirePhoto());
|
||||||
|
dbEvent.setLimitType(event.getLimitType());
|
||||||
|
dbEvent.setLimitValue(event.getLimitValue());
|
||||||
|
dbEvent.setBeginAt(event.getBeginAt());
|
||||||
|
dbEvent.setEndAt(event.getEndAt());
|
||||||
|
|
||||||
|
verifyValueDefinitionChange(dbEvent, oldValueType, oldValueUnit);
|
||||||
|
verifyEvent(dbEvent);
|
||||||
|
mapper.update(dbEvent);
|
||||||
|
saveRoleRelation(event.getId(), event.getRoleCodeList());
|
||||||
|
logger.setLevel(Logger.Level.INFO);
|
||||||
|
logger.setResult(event.getId());
|
||||||
|
} catch (TimiException e) {
|
||||||
|
logger.setLevel(Logger.Level.WARN);
|
||||||
|
logger.setException(e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.setLevel(Logger.Level.ERROR);
|
||||||
|
logger.setException(TimiJava.serializeThrowable(e));
|
||||||
|
log.error("update event error", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "update event error", e);
|
||||||
|
} finally {
|
||||||
|
loggerService.create(logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void delete(String id) {
|
||||||
|
Logger logger = new Logger(Logger.Module.GAO, "GAO_EVENT_DELETE");
|
||||||
|
try {
|
||||||
|
logger.setContent(id);
|
||||||
|
GaoEvent event = get(id);
|
||||||
|
event.setStatus(GaoEvent.Status.DELETED);
|
||||||
|
super.update(event);
|
||||||
|
logger.setLevel(Logger.Level.INFO);
|
||||||
|
logger.setResult(id);
|
||||||
|
} catch (TimiException e) {
|
||||||
|
logger.setLevel(Logger.Level.WARN);
|
||||||
|
logger.setException(e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.setLevel(Logger.Level.ERROR);
|
||||||
|
logger.setException(TimiJava.serializeThrowable(e));
|
||||||
|
log.error("delete event error", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "delete event error", e);
|
||||||
|
} finally {
|
||||||
|
loggerService.create(logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, GaoEvent> mapByIdList(Collection<String> idList) {
|
||||||
|
return mapper.selectByIdList(new HashSet<>(idList)).stream().collect(Collectors.toMap(GaoEvent::getId, Function.identity()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, List<String>> mapRoleCodeListByEventIdList(Collection<String> eventIdList) {
|
||||||
|
return roleRelationMapper.selectAllByEventIdList(new HashSet<>(eventIdList))
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.groupingBy(GaoEventRoleRelation::getEventId, Collectors.mapping(GaoEventRoleRelation::getRoleCode, Collectors.toList())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoEvent> listValid(String storeId) {
|
||||||
|
TimiException.required(storeId, "not found storeId");
|
||||||
|
return mapper.selectValidList(storeId, Time.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> listRoleCode(String eventId) {
|
||||||
|
GaoEventRoleRelation example = new GaoEventRoleRelation();
|
||||||
|
example.setEventId(eventId);
|
||||||
|
return roleRelationMapper.selectAllByExample(example).stream().map(GaoEventRoleRelation::getRoleCode).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void sort(List<String> idList) {
|
||||||
|
if (TimiJava.isEmpty(idList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
idList = new ArrayList<>(new LinkedHashSet<>(idList));
|
||||||
|
Map<String, GaoEvent> eventMap = mapper.selectByIdList(idList).stream().collect(Collectors.toMap(GaoEvent::getId, Function.identity()));
|
||||||
|
for (int i = 0; i < idList.size(); i++) {
|
||||||
|
GaoEvent event = eventMap.get(idList.get(i));
|
||||||
|
event.setSort(i);
|
||||||
|
mapper.update(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyEvent(GaoEvent event) {
|
||||||
|
GaoEvent.ValueType valueType = TimiJava.defaultIfNull(event.getValueType(), GaoEvent.ValueType.NONE);
|
||||||
|
if (valueType == GaoEvent.ValueType.NONE) {
|
||||||
|
TimiException.requiredNull(event.getValueUnit(), "NONE 事件不能配置数值单位");
|
||||||
|
TimiException.requiredTrue(!Boolean.TRUE.equals(event.getRequireValue()), "NONE 事件不能要求提交数值");
|
||||||
|
} else {
|
||||||
|
TimiException.required(event.getValueUnit(), "NUMBER 事件必须配置数值单位");
|
||||||
|
}
|
||||||
|
if (TimiJava.isNotEmpty(event.getLimitType()) && event.getLimitType() != GaoEvent.LimitType.NONE) {
|
||||||
|
TimiException.requiredTrue(event.getLimitType().getMin() < event.getLimitValue(), "约束值最低 %s".formatted(event.getLimitType().getMin()));
|
||||||
|
}
|
||||||
|
if (event.getBeginAt() != null || event.getEndAt() != null) {
|
||||||
|
TimiException.requiredTrue(event.getBeginAt() == null || event.getEndAt() == null || event.getBeginAt() <= event.getEndAt(), "invalid beginAt or endAt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyValueDefinitionChange(GaoEvent event, GaoEvent.ValueType oldValueType, GaoEvent.ValueUnit oldValueUnit) {
|
||||||
|
if (oldValueType == event.getValueType() && oldValueUnit == event.getValueUnit()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Long count = eventRecordMapper.countByEventIdAndNumberValue(event.getId());
|
||||||
|
if (0 < TimiJava.defaultIfNull(count, 0L)) {
|
||||||
|
TimiException.requiredTrue(oldValueUnit == event.getValueUnit(), "事件已有数值登记记录,禁止修改 valueUnit");
|
||||||
|
TimiException.requiredTrue(event.getValueType() == GaoEvent.ValueType.NUMBER, "事件已有数值登记记录,不能改为 NONE");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveRoleRelation(String eventId, List<String> roleCodeList) {
|
||||||
|
List<GaoEventRoleRelation> dbRoleRelationList = roleRelationMapper.selectAllByEventIdList(List.of(eventId));
|
||||||
|
Set<String> roleCodeSet = TimiJava.defaultIfEmpty(roleCodeList, List.<String>of()).stream().filter(TimiJava::isNotEmpty).collect(Collectors.toSet());
|
||||||
|
Set<String> retainedRoleCodeSet = new HashSet<>();
|
||||||
|
for (GaoEventRoleRelation dbEventRole : dbRoleRelationList) {
|
||||||
|
String roleCode = dbEventRole.getRoleCode();
|
||||||
|
if (roleCode != null) {
|
||||||
|
roleCode = roleCode.trim();
|
||||||
|
}
|
||||||
|
if (!roleCodeSet.contains(roleCode) || !retainedRoleCodeSet.add(roleCode)) {
|
||||||
|
roleRelationMapper.delete(dbEventRole.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String roleCode : roleCodeSet) {
|
||||||
|
if (retainedRoleCodeSet.contains(roleCode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
GaoEventRoleRelation relation = new GaoEventRoleRelation();
|
||||||
|
relation.setEventId(eventId);
|
||||||
|
relation.setRoleCode(roleCode);
|
||||||
|
roleRelationMapper.insert(relation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service.implement;
|
||||||
|
|
||||||
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointAccount;
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoPointAccountMapper;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoPointAccountService;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
|
import com.imyeyu.utils.Time;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/// GAO 客户积分账户服务实现
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GaoPointAccountServiceImplement extends AbstractEntityService<GaoPointAccount, String> implements GaoPointAccountService {
|
||||||
|
|
||||||
|
private final GaoPointAccountMapper mapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseMapper<GaoPointAccount, String> mapper() {
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoPointAccount getByCustomerId(String storeId, String customerId) {
|
||||||
|
TimiException.required(storeId, "not found storeId");
|
||||||
|
TimiException.required(customerId, "not found customerId");
|
||||||
|
return mapper.selectByStoreIdAndCustomerId(storeId, customerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public GaoPointAccount getOrCreateForUpdate(String storeId, String customerId) {
|
||||||
|
TimiException.required(storeId, "not found storeId");
|
||||||
|
TimiException.required(customerId, "not found customerId");
|
||||||
|
|
||||||
|
GaoPointAccount account = mapper.selectByStoreIdAndCustomerId(storeId, customerId);
|
||||||
|
if (account == null) {
|
||||||
|
account = new GaoPointAccount();
|
||||||
|
account.setId(UUID.randomUUID().toString());
|
||||||
|
account.setStoreId(storeId);
|
||||||
|
account.setCustomerId(customerId);
|
||||||
|
account.setBalance(0L);
|
||||||
|
account.setTotalEarned(0L);
|
||||||
|
account.setTotalRevoked(0L);
|
||||||
|
account.setTotalAdjusted(0L);
|
||||||
|
account.setVersion(0L);
|
||||||
|
account.setCreatedAt(Time.now());
|
||||||
|
mapper.insertIfAbsent(account);
|
||||||
|
account = mapper.selectByStoreIdAndCustomerId(storeId, customerId);
|
||||||
|
}
|
||||||
|
TimiException.required(account, "not found customer point account");
|
||||||
|
GaoPointAccount lockedAccount = mapper.selectForUpdate(account.getId());
|
||||||
|
TimiException.required(lockedAccount, "not found customer point account");
|
||||||
|
return lockedAccount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int updateBalance(String accountId, long delta, long totalEarnedDelta, long totalRevokedDelta, long totalAdjustedDelta) {
|
||||||
|
TimiException.required(accountId, "not found accountId");
|
||||||
|
return mapper.updateBalance(accountId, delta, totalEarnedDelta, totalRevokedDelta, totalAdjustedDelta, Time.now());
|
||||||
|
}
|
||||||
|
}
|
||||||
+196
@@ -0,0 +1,196 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service.implement;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointAccount;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointLedger;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointRule;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoPointLedgerMapper;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoPointAccountService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoPointLedgerService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoPointAdjustRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoPointLedgerPage;
|
||||||
|
import com.imyeyu.api.modules.system.entity.Logger;
|
||||||
|
import com.imyeyu.api.modules.system.service.LoggerService;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
|
import com.imyeyu.utils.Time;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/// GAO 客户积分流水服务实现
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GaoPointLedgerServiceImplement extends AbstractEntityService<GaoPointLedger, String> implements GaoPointLedgerService {
|
||||||
|
|
||||||
|
private final GaoPointLedgerMapper mapper;
|
||||||
|
private final GaoPointAccountService accountService;
|
||||||
|
private final GaoCustomerService customerService;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
private final LoggerService loggerService;
|
||||||
|
private final UserLoginService userLoginService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseMapper<GaoPointLedger, String> mapper() {
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(GaoPointLedger ledger) {
|
||||||
|
throw new TimiException(TimiCode.ERROR_NOT_SUPPORT, "积分流水只允许追加,禁止修改");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(String id) {
|
||||||
|
throw new TimiException(TimiCode.ERROR_NOT_SUPPORT, "积分流水只允许追加,禁止删除");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy(String id) {
|
||||||
|
throw new TimiException(TimiCode.ERROR_NOT_SUPPORT, "积分流水只允许追加,禁止物理删除");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public GaoPointLedger earn(GaoEventRecord record, GaoPointRule rule, long pointDelta, JsonNode sourcePayload) {
|
||||||
|
TimiException.required(record, "not found event record");
|
||||||
|
TimiException.required(rule, "not found point rule");
|
||||||
|
TimiException.requiredTrue(0 < pointDelta, "pointDelta invalid");
|
||||||
|
String idempotencyKey = "GAO_EVENT_RECORD:%s:RULE:%s:EARN".formatted(record.getId(), rule.getId());
|
||||||
|
return apply(record.getStoreId(), record.getCustomerId(), GaoPointLedger.ChangeType.EARN, pointDelta, rule.getId(), record.getEventId(), record.getId(), sourcePayload, idempotencyKey, rule.getRemark(), record.getOperatorUserId(), record.getRegisteredAt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public GaoPointLedger revoke(GaoPointLedger originLedger, GaoEventRecord record) {
|
||||||
|
TimiException.required(originLedger, "not found origin ledger");
|
||||||
|
TimiException.required(record, "not found event record");
|
||||||
|
TimiException.requiredTrue(0 < originLedger.getPointDelta(), "origin ledger pointDelta invalid");
|
||||||
|
String idempotencyKey = "GAO_EVENT_RECORD:%s:LEDGER:%s:REVOKE".formatted(record.getId(), originLedger.getId());
|
||||||
|
return apply(originLedger.getStoreId(), originLedger.getCustomerId(), GaoPointLedger.ChangeType.REVOKE, -originLedger.getPointDelta(), originLedger.getRuleId(), originLedger.getEventId(), originLedger.getEventRecordId(), originLedger.getSourcePayload(), idempotencyKey, "撤销登记记录积分", userLoginService.getRequireLoginUserId(), Time.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public GaoPointLedger adjust(GaoPointAdjustRequest request, String operatorUserId) {
|
||||||
|
TimiException.required(request, "not found adjust request");
|
||||||
|
TimiException.requiredTrue(TimiJava.isNotEmpty(request.getAdjustRequestId()), "not found adjustRequestId");
|
||||||
|
TimiException.required(request.getStoreId(), "not found storeId");
|
||||||
|
TimiException.required(request.getCustomerId(), "not found customerId");
|
||||||
|
TimiException.required(request.getPointDelta(), "not found pointDelta");
|
||||||
|
TimiException.requiredTrue(request.getPointDelta() != 0, "pointDelta invalid");
|
||||||
|
TimiException.requiredTrue(TimiJava.isNotEmpty(request.getRemark()), "not found adjust remark");
|
||||||
|
TimiException.required(operatorUserId, "not found operatorUserId");
|
||||||
|
String idempotencyKey = "MANUAL_ADJUST:%s".formatted(request.getAdjustRequestId());
|
||||||
|
return apply(request.getStoreId(), request.getCustomerId(), GaoPointLedger.ChangeType.ADJUST, request.getPointDelta(), null, null, null, null, idempotencyKey, request.getRemark(), operatorUserId, Time.now());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<GaoPointLedger> pageByQuery(GaoPointLedgerPage page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
PageResult<GaoPointLedger> result = new PageResult<>();
|
||||||
|
result.setTotal(mapper.countByQuery(page));
|
||||||
|
result.setList(mapper.selectByQuery(page));
|
||||||
|
fillCustomer(result.getList());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillCustomer(List<GaoPointLedger> ledgerList) {
|
||||||
|
List<String> customerIdList = ledgerList.stream().map(GaoPointLedger::getCustomerId).filter(TimiJava::isNotEmpty).distinct().toList();
|
||||||
|
if (customerIdList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, GaoCustomer> customerMap = customerService.mapByIdList(customerIdList);
|
||||||
|
Map<String, List<Attachment>> attachmentMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, customerIdList);
|
||||||
|
for (GaoPointLedger ledger : ledgerList) {
|
||||||
|
GaoCustomer customer = customerMap.get(ledger.getCustomerId());
|
||||||
|
if (customer == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
customer.setAttachmentList(attachmentMap.get(customer.getId()));
|
||||||
|
ledger.setCustomer(customer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private GaoPointLedger apply(String storeId, String customerId, GaoPointLedger.ChangeType changeType, long pointDelta, String ruleId, String eventId, String eventRecordId, JsonNode sourcePayload, String idempotencyKey, String remark, String operatorUserId, Long occurredAt) {
|
||||||
|
Logger logger = new Logger(Logger.Module.GAO, "GAO_POINT_LEDGER_APPLY");
|
||||||
|
logger.setContent("storeId=%s, customerId=%s, changeType=%s, pointDelta=%d, idempotencyKey=%s, remark=%s".formatted(storeId, customerId, changeType, pointDelta, idempotencyKey, remark));
|
||||||
|
try {
|
||||||
|
GaoPointLedger existing = mapper.selectByIdempotencyKey(idempotencyKey);
|
||||||
|
if (existing != null) {
|
||||||
|
logger.setLevel(Logger.Level.INFO);
|
||||||
|
logger.setResult(existing.getId());
|
||||||
|
return existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
GaoPointAccount account = accountService.getOrCreateForUpdate(storeId, customerId);
|
||||||
|
existing = mapper.selectByIdempotencyKey(idempotencyKey);
|
||||||
|
if (existing != null) {
|
||||||
|
logger.setLevel(Logger.Level.INFO);
|
||||||
|
logger.setResult(existing.getId());
|
||||||
|
return existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
long balanceBefore = account.getBalance();
|
||||||
|
long balanceAfter = Math.addExact(balanceBefore, pointDelta);
|
||||||
|
long totalEarnedDelta = changeType == GaoPointLedger.ChangeType.EARN ? pointDelta : 0L;
|
||||||
|
long totalRevokedDelta = changeType == GaoPointLedger.ChangeType.REVOKE ? -pointDelta : 0L;
|
||||||
|
long totalAdjustedDelta = changeType == GaoPointLedger.ChangeType.ADJUST ? pointDelta : 0L;
|
||||||
|
|
||||||
|
GaoPointLedger ledger = new GaoPointLedger();
|
||||||
|
ledger.setAccountId(account.getId());
|
||||||
|
ledger.setStoreId(storeId);
|
||||||
|
ledger.setCustomerId(customerId);
|
||||||
|
ledger.setChangeType(changeType);
|
||||||
|
ledger.setDirection(0 < pointDelta ? GaoPointLedger.Direction.INCREASE : GaoPointLedger.Direction.DECREASE);
|
||||||
|
ledger.setPointDelta(pointDelta);
|
||||||
|
ledger.setBalanceBefore(balanceBefore);
|
||||||
|
ledger.setBalanceAfter(balanceAfter);
|
||||||
|
ledger.setRuleId(ruleId);
|
||||||
|
ledger.setEventId(eventId);
|
||||||
|
ledger.setEventRecordId(eventRecordId);
|
||||||
|
ledger.setSourcePayload(sourcePayload);
|
||||||
|
ledger.setIdempotencyKey(idempotencyKey);
|
||||||
|
ledger.setRemark(remark);
|
||||||
|
ledger.setOperatorUserId(operatorUserId);
|
||||||
|
ledger.setOccurredAt(occurredAt);
|
||||||
|
create(ledger);
|
||||||
|
int updated = accountService.updateBalance(account.getId(), pointDelta, totalEarnedDelta, totalRevokedDelta, totalAdjustedDelta);
|
||||||
|
TimiException.requiredTrue(0 < updated, "积分余额不足");
|
||||||
|
logger.setLevel(Logger.Level.INFO);
|
||||||
|
logger.setResult(ledger.getId());
|
||||||
|
return ledger;
|
||||||
|
} catch (TimiException e) {
|
||||||
|
logger.setLevel(Logger.Level.WARN);
|
||||||
|
logger.setException(e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.setLevel(Logger.Level.ERROR);
|
||||||
|
logger.setException(TimiJava.serializeThrowable(e));
|
||||||
|
log.error("应用 GAO 积分流水失败", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "应用 GAO 积分流水失败", e);
|
||||||
|
} finally {
|
||||||
|
loggerService.create(logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+220
@@ -0,0 +1,220 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service.implement;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointRule;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoPointRuleMapper;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoPointRuleService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoEventService;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// GAO 客户积分规则服务实现
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GaoPointRuleServiceImplement extends AbstractEntityService<GaoPointRule, String> implements GaoPointRuleService {
|
||||||
|
|
||||||
|
private static final int MAX_TIER_COUNT = 100;
|
||||||
|
|
||||||
|
private final GaoPointRuleMapper mapper;
|
||||||
|
private final GaoEventService eventService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseMapper<GaoPointRule, String> mapper() {
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoPointRule> listActive(String storeId, String eventId, long now) {
|
||||||
|
TimiException.required(storeId, "not found storeId");
|
||||||
|
TimiException.required(eventId, "not found eventId");
|
||||||
|
return mapper.selectActiveByStoreIdAndEventId(storeId, eventId, now);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void create(GaoPointRule rule) {
|
||||||
|
TimiException.required(rule, "not found rule");
|
||||||
|
TimiException.required(rule.getStoreId(), "not found rule.storeId");
|
||||||
|
TimiException.required(rule.getEventId(), "not found rule.eventId");
|
||||||
|
TimiException.required(rule.getName(), "not found rule.name");
|
||||||
|
checkEvent(rule.getStoreId(), rule.getEventId());
|
||||||
|
rule.setStatus(TimiJava.defaultIfNull(rule.getStatus(), GaoPointRule.Status.DRAFT));
|
||||||
|
rule.setPriority(TimiJava.defaultIfNull(rule.getPriority(), 0));
|
||||||
|
rule.setExclusive(TimiJava.defaultIfNull(rule.getExclusive(), false));
|
||||||
|
verifyRule(rule);
|
||||||
|
super.create(rule);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void update(GaoPointRule rule) {
|
||||||
|
TimiException.required(rule, "not found rule");
|
||||||
|
TimiException.required(rule.getId(), "not found rule.id");
|
||||||
|
TimiException.required(rule.getStoreId(), "not found rule.storeId");
|
||||||
|
TimiException.required(rule.getEventId(), "not found rule.eventId");
|
||||||
|
TimiException.required(rule.getName(), "not found rule.name");
|
||||||
|
GaoPointRule dbRule = get(rule.getId());
|
||||||
|
TimiException.required(dbRule, "not found rule");
|
||||||
|
TimiException.requiredTrue(dbRule.getStoreId().equals(rule.getStoreId()), "rule.storeId invalid");
|
||||||
|
checkEvent(rule.getStoreId(), rule.getEventId());
|
||||||
|
rule.setPriority(TimiJava.defaultIfNull(rule.getPriority(), 0));
|
||||||
|
rule.setExclusive(TimiJava.defaultIfNull(rule.getExclusive(), false));
|
||||||
|
verifyRule(rule);
|
||||||
|
dbRule.setEventId(rule.getEventId());
|
||||||
|
dbRule.setName(rule.getName());
|
||||||
|
dbRule.setStatus(rule.getStatus());
|
||||||
|
dbRule.setTriggerType(rule.getTriggerType());
|
||||||
|
dbRule.setPointMode(rule.getPointMode());
|
||||||
|
dbRule.setPointValue(rule.getPointValue());
|
||||||
|
dbRule.setConditionJson(rule.getConditionJson());
|
||||||
|
dbRule.setBeginAt(rule.getBeginAt());
|
||||||
|
dbRule.setEndAt(rule.getEndAt());
|
||||||
|
dbRule.setPriority(rule.getPriority());
|
||||||
|
dbRule.setExclusive(rule.getExclusive());
|
||||||
|
dbRule.setRemark(rule.getRemark());
|
||||||
|
mapper.update(dbRule);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void delete(String id) {
|
||||||
|
TimiException.required(id, "not found rule.id");
|
||||||
|
GaoPointRule rule = get(id);
|
||||||
|
TimiException.required(rule, "not found rule");
|
||||||
|
rule.setStatus(GaoPointRule.Status.DELETED);
|
||||||
|
super.update(rule);
|
||||||
|
super.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkEvent(String storeId, String eventId) {
|
||||||
|
GaoEvent event = eventService.get(eventId);
|
||||||
|
TimiException.required(event, "not found event");
|
||||||
|
TimiException.requiredTrue(storeId.equals(event.getStoreId()), "规则和登记事件不属于同一门店");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyRule(GaoPointRule rule) {
|
||||||
|
TimiException.required(rule.getStatus(), "not found rule.status");
|
||||||
|
TimiException.required(rule.getTriggerType(), "not found rule.triggerType");
|
||||||
|
TimiException.required(rule.getPointMode(), "not found rule.pointMode");
|
||||||
|
TimiException.requiredTrue(rule.getPriority() != null && 0 <= rule.getPriority(), "rule.priority invalid");
|
||||||
|
TimiException.requiredTrue(rule.getBeginAt() == null || rule.getEndAt() == null || rule.getBeginAt() <= rule.getEndAt(), "rule.beginAt or rule.endAt invalid");
|
||||||
|
|
||||||
|
if (rule.getTriggerType() == GaoPointRule.TriggerType.SOURCE_VALUE) {
|
||||||
|
TimiException.requiredTrue(rule.getPointMode() == GaoPointRule.PointMode.SOURCE_VALUE, "SOURCE_VALUE 规则必须使用 SOURCE_VALUE 积分值模式");
|
||||||
|
TimiException.requiredNull(rule.getPointValue(), "SOURCE_VALUE 规则不能填写固定积分值");
|
||||||
|
verifySourceCondition(rule.getConditionJson());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rule.getTriggerType() == GaoPointRule.TriggerType.CUSTOMER_EVENT_VALUE_TIER) {
|
||||||
|
TimiException.requiredTrue(rule.getPointMode() == GaoPointRule.PointMode.TIER, "CUSTOMER_EVENT_VALUE_TIER 规则必须使用 TIER 积分值模式");
|
||||||
|
TimiException.requiredNull(rule.getPointValue(), "TIER 规则不能填写规则级积分值");
|
||||||
|
verifyTierCondition(rule.getStoreId(), rule.getConditionJson());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TimiException.requiredTrue(rule.getPointMode() == GaoPointRule.PointMode.FIXED, "固定触发规则必须使用 FIXED 积分值模式");
|
||||||
|
TimiException.required(rule.getPointValue(), "not found rule.pointValue");
|
||||||
|
TimiException.requiredTrue(0 < rule.getPointValue(), "rule.pointValue invalid");
|
||||||
|
if (rule.getTriggerType() == GaoPointRule.TriggerType.AFTER_COUNT_EVERY_TIME) {
|
||||||
|
JsonNode condition = requireObjectCondition(rule.getConditionJson());
|
||||||
|
JsonNode threshold = condition.get("threshold");
|
||||||
|
TimiException.requiredTrue(threshold != null && threshold.isIntegralNumber() && 0 < threshold.longValue(), "AFTER_COUNT_EVERY_TIME.threshold invalid");
|
||||||
|
JsonNode includeCurrent = condition.get("includeCurrent");
|
||||||
|
TimiException.requiredTrue(includeCurrent == null || includeCurrent.isNull() || includeCurrent.isBoolean(), "AFTER_COUNT_EVERY_TIME.includeCurrent invalid");
|
||||||
|
verifyScope(condition);
|
||||||
|
} else if (rule.getTriggerType() == GaoPointRule.TriggerType.FIRST_TIME) {
|
||||||
|
verifyScope(requireObjectCondition(rule.getConditionJson()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyTierCondition(String storeId, JsonNode conditionJson) {
|
||||||
|
JsonNode condition = requireObjectCondition(conditionJson);
|
||||||
|
JsonNode sourceEventIdNode = condition.get("sourceEventId");
|
||||||
|
TimiException.requiredTrue(sourceEventIdNode != null && sourceEventIdNode.isTextual() && TimiJava.isNotEmpty(sourceEventIdNode.asText().trim()), "TIER.sourceEventId invalid");
|
||||||
|
String sourceEventId = sourceEventIdNode.asText().trim();
|
||||||
|
GaoEvent sourceEvent = eventService.get(sourceEventId);
|
||||||
|
TimiException.required(sourceEvent, "TIER.sourceEventId 对应事件不存在");
|
||||||
|
TimiException.requiredTrue(storeId.equals(sourceEvent.getStoreId()), "TIER 来源事件和规则不属于同一门店");
|
||||||
|
TimiException.requiredTrue(sourceEvent.getValueType() == GaoEvent.ValueType.NUMBER, "TIER 来源事件必须配置为 NUMBER 类型");
|
||||||
|
|
||||||
|
JsonNode sourceValueField = condition.get("sourceValueField");
|
||||||
|
TimiException.requiredTrue(sourceValueField != null && sourceValueField.isTextual() && "numberValue".equals(sourceValueField.asText()), "TIER.sourceValueField 目前只能是 numberValue");
|
||||||
|
|
||||||
|
JsonNode window = condition.get("window");
|
||||||
|
TimiException.requiredTrue(window != null && window.isObject(), "TIER.window 必须是对象");
|
||||||
|
JsonNode windowType = window.get("type");
|
||||||
|
TimiException.requiredTrue(windowType != null && windowType.isTextual() && "ROLLING".equals(windowType.asText()), "TIER.window.type 目前只能是 ROLLING");
|
||||||
|
JsonNode windowAmount = window.get("amount");
|
||||||
|
TimiException.requiredTrue(windowAmount != null && windowAmount.isIntegralNumber() && 0 < windowAmount.longValue(), "TIER.window.amount invalid");
|
||||||
|
JsonNode windowUnit = window.get("unit");
|
||||||
|
TimiException.requiredTrue(windowUnit != null && windowUnit.isTextual() && "YEAR".equals(windowUnit.asText()), "TIER.window.unit 目前只能是 YEAR");
|
||||||
|
|
||||||
|
JsonNode tiers = condition.get("tiers");
|
||||||
|
TimiException.requiredTrue(tiers != null && tiers.isArray() && !tiers.isEmpty(), "TIER.tiers 不能为空");
|
||||||
|
TimiException.requiredTrue(tiers.size() <= MAX_TIER_COUNT, "TIER.tiers 数量不能超过 %d".formatted(MAX_TIER_COUNT));
|
||||||
|
Long previousMax = null;
|
||||||
|
for (int i = 0; i < tiers.size(); i++) {
|
||||||
|
JsonNode tier = tiers.get(i);
|
||||||
|
TimiException.requiredTrue(tier != null && tier.isObject(), "TIER.tiers[%d] 必须是对象".formatted(i));
|
||||||
|
JsonNode minNode = tier.get("min");
|
||||||
|
TimiException.requiredTrue(minNode != null && minNode.isIntegralNumber() && 0 <= minNode.longValue(), "TIER.tiers[%d].min invalid".formatted(i));
|
||||||
|
long min = minNode.longValue();
|
||||||
|
if (i == 0) {
|
||||||
|
TimiException.requiredTrue(min == 0, "TIER 第一档 min 必须为 0");
|
||||||
|
} else {
|
||||||
|
TimiException.requiredTrue(previousMax != null && previousMax < Long.MAX_VALUE && min == previousMax + 1, "TIER 分档必须连续且不能重叠");
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonNode maxNode = tier.get("max");
|
||||||
|
Long max = null;
|
||||||
|
if (maxNode != null && !maxNode.isNull()) {
|
||||||
|
TimiException.requiredTrue(maxNode.isIntegralNumber(), "TIER.tiers[%d].max invalid".formatted(i));
|
||||||
|
max = maxNode.longValue();
|
||||||
|
TimiException.requiredTrue(min <= max, "TIER.tiers[%d].min 或 max invalid".formatted(i));
|
||||||
|
}
|
||||||
|
if (i < tiers.size() - 1) {
|
||||||
|
TimiException.requiredTrue(max != null, "除最后一档外 TIER.max 不能为空");
|
||||||
|
TimiException.requiredTrue(max < Long.MAX_VALUE, "TIER 分档上限过大,无法继续配置下一档");
|
||||||
|
} else {
|
||||||
|
TimiException.requiredTrue(max == null, "最后一档 TIER.max 必须为空");
|
||||||
|
}
|
||||||
|
JsonNode pointValue = tier.get("pointValue");
|
||||||
|
TimiException.requiredTrue(pointValue != null && pointValue.isIntegralNumber() && 0 <= pointValue.longValue(), "TIER.tiers[%d].pointValue invalid".formatted(i));
|
||||||
|
previousMax = max;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifySourceCondition(JsonNode conditionJson) {
|
||||||
|
JsonNode condition = conditionJson == null ? null : requireObjectCondition(conditionJson);
|
||||||
|
Long min = condition == null || condition.get("min") == null || condition.get("min").isNull() ? null : condition.get("min").isIntegralNumber() ? condition.get("min").longValue() : null;
|
||||||
|
Long max = condition == null || condition.get("max") == null || condition.get("max").isNull() ? null : condition.get("max").isIntegralNumber() ? condition.get("max").longValue() : null;
|
||||||
|
TimiException.requiredTrue(condition == null || min != null || condition.get("min") == null || condition.get("min").isNull(), "SOURCE_VALUE.min invalid");
|
||||||
|
TimiException.requiredTrue(condition == null || max != null || condition.get("max") == null || condition.get("max").isNull(), "SOURCE_VALUE.max invalid");
|
||||||
|
TimiException.requiredTrue(min == null || 0 < min, "SOURCE_VALUE.min invalid");
|
||||||
|
TimiException.requiredTrue(max == null || 0 < max, "SOURCE_VALUE.max invalid");
|
||||||
|
TimiException.requiredTrue(min == null || max == null || min <= max, "SOURCE_VALUE.min or SOURCE_VALUE.max invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
private JsonNode requireObjectCondition(JsonNode conditionJson) {
|
||||||
|
TimiException.requiredTrue(conditionJson != null && conditionJson.isObject(), "rule.conditionJson must be object");
|
||||||
|
return conditionJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyScope(JsonNode condition) {
|
||||||
|
JsonNode scope = condition.get("scope");
|
||||||
|
TimiException.requiredTrue(scope == null || scope.isNull() || "CUSTOMER_EVENT".equals(scope.asText()), "rule.conditionJson.scope invalid");
|
||||||
|
}
|
||||||
|
}
|
||||||
+206
@@ -0,0 +1,206 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service.implement;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointLedger;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPointRule;
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoEventRecordMapper;
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoPointLedgerMapper;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoPointLedgerService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoPointRuleService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoPointTriggerService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoPointAdjustRequest;
|
||||||
|
import com.imyeyu.api.modules.user.service.PermissionChecker;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.utils.Time;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/// GAO 客户积分触发服务实现
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-11
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GaoPointTriggerServiceImplement implements GaoPointTriggerService {
|
||||||
|
|
||||||
|
private final ObjectMapper jackson;
|
||||||
|
private final PermissionChecker permissionChecker;
|
||||||
|
private final UserLoginService userLoginService;
|
||||||
|
private final GaoPointRuleService ruleService;
|
||||||
|
private final GaoPointLedgerService ledgerService;
|
||||||
|
private final GaoCustomerService customerService;
|
||||||
|
private final GaoPointLedgerMapper ledgerMapper;
|
||||||
|
private final GaoEventRecordMapper eventRecordMapper;
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void onEventRecordCreated(GaoEventRecord record) {
|
||||||
|
TimiException.required(record, "not found event record");
|
||||||
|
TimiException.required(record.getId(), "not found event record.id");
|
||||||
|
TimiException.required(record.getStoreId(), "not found record.storeId");
|
||||||
|
TimiException.required(record.getCustomerId(), "not found record.customerId");
|
||||||
|
TimiException.required(record.getEventId(), "not found record.eventId");
|
||||||
|
TimiException.required(record.getRegisteredAt(), "not found record.registeredAt");
|
||||||
|
|
||||||
|
List<GaoPointRule> ruleList = ruleService.listActive(record.getStoreId(), record.getEventId(), Time.now());
|
||||||
|
Long count = null;
|
||||||
|
long earnedPointValue = 0L;
|
||||||
|
for (GaoPointRule rule : ruleList) {
|
||||||
|
RuleResolution resolution = resolveRule(record, rule, count);
|
||||||
|
if (resolution == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (rule.getTriggerType() == GaoPointRule.TriggerType.FIRST_TIME || rule.getTriggerType() == GaoPointRule.TriggerType.AFTER_COUNT_EVERY_TIME) {
|
||||||
|
count = count == null ? count(record) : count;
|
||||||
|
}
|
||||||
|
long pointDelta = resolution.pointDelta();
|
||||||
|
if (0 < pointDelta) {
|
||||||
|
ledgerService.earn(record, rule, pointDelta, resolution.sourcePayload());
|
||||||
|
earnedPointValue = Math.addExact(earnedPointValue, pointDelta);
|
||||||
|
}
|
||||||
|
if (Boolean.TRUE.equals(rule.getExclusive())) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
record.setEarnedPointValue(earnedPointValue);
|
||||||
|
eventRecordMapper.updateEarnedPointValue(record.getId(), earnedPointValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void revokeByEventRecord(GaoEventRecord record) {
|
||||||
|
TimiException.required(record, "not found event record");
|
||||||
|
List<GaoPointLedger> originLedgerList = ledgerMapper.selectEarnByEventRecordId(record.getId());
|
||||||
|
if (originLedgerList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Set<String> revokedKeySet = new HashSet<>();
|
||||||
|
List<String> revokeKeyList = originLedgerList.stream().map(origin -> revokeKey(record, origin)).toList();
|
||||||
|
for (GaoPointLedger ledger : ledgerMapper.selectByIdempotencyKeyList(revokeKeyList)) {
|
||||||
|
revokedKeySet.add(ledger.getIdempotencyKey());
|
||||||
|
}
|
||||||
|
for (GaoPointLedger originLedger : originLedgerList) {
|
||||||
|
if (!revokedKeySet.contains(revokeKey(record, originLedger))) {
|
||||||
|
ledgerService.revoke(originLedger, record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoPointLedger adjust(GaoPointAdjustRequest request) {
|
||||||
|
TimiException.required(request, "not found adjust request");
|
||||||
|
TimiException.required(request.getStoreId(), "not found storeId");
|
||||||
|
TimiException.required(request.getCustomerId(), "not found customerId");
|
||||||
|
GaoCustomer customer = customerService.get(request.getCustomerId());
|
||||||
|
TimiException.required(customer, "not found customer");
|
||||||
|
TimiException.requiredTrue(request.getStoreId().equals(customer.getStoreId()), "客户和积分调整门店不一致");
|
||||||
|
return ledgerService.adjust(request, userLoginService.getRequireLoginUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private RuleResolution resolveRule(GaoEventRecord record, GaoPointRule rule, Long count) {
|
||||||
|
return switch (rule.getTriggerType()) {
|
||||||
|
case EVERY_TIME -> new RuleResolution(rule.getPointValue(), null);
|
||||||
|
case FIRST_TIME -> {
|
||||||
|
long currentCount = count == null ? count(record) : count;
|
||||||
|
yield currentCount == 1 ? new RuleResolution(rule.getPointValue(), null) : null;
|
||||||
|
}
|
||||||
|
case AFTER_COUNT_EVERY_TIME -> {
|
||||||
|
JsonNode condition = rule.getConditionJson();
|
||||||
|
long threshold = condition.get("threshold").longValue();
|
||||||
|
boolean includeCurrent = condition.get("includeCurrent") == null || condition.get("includeCurrent").isNull() || condition.get("includeCurrent").asBoolean();
|
||||||
|
long currentCount = count == null ? count(record) : count;
|
||||||
|
yield includeCurrent ? threshold <= currentCount ? new RuleResolution(rule.getPointValue(), null) : null : threshold < currentCount ? new RuleResolution(rule.getPointValue(), null) : null;
|
||||||
|
}
|
||||||
|
case SOURCE_VALUE -> resolveSourceValue(record, rule);
|
||||||
|
case CUSTOMER_EVENT_VALUE_TIER -> resolveTier(record, rule);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private RuleResolution resolveSourceValue(GaoEventRecord record, GaoPointRule rule) {
|
||||||
|
if (record.getPointValue() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
permissionChecker.checkAny(ModuleCode.GAO, GaoPermissionCode.POINT_SOURCE_VALUE.getValue());
|
||||||
|
long pointValue = record.getPointValue();
|
||||||
|
TimiException.requiredTrue(0 < pointValue, "pointValue invalid");
|
||||||
|
JsonNode condition = rule.getConditionJson();
|
||||||
|
if (condition != null) {
|
||||||
|
JsonNode min = condition.get("min");
|
||||||
|
JsonNode max = condition.get("max");
|
||||||
|
TimiException.requiredTrue(min == null || min.isNull() || min.longValue() <= pointValue, "pointValue 小于规则最小值");
|
||||||
|
TimiException.requiredTrue(max == null || max.isNull() || pointValue <= max.longValue(), "pointValue 大于规则最大值");
|
||||||
|
}
|
||||||
|
ObjectNode payload = jackson.createObjectNode();
|
||||||
|
payload.put("submittedPointValue", pointValue);
|
||||||
|
payload.put("validatedPointValue", pointValue);
|
||||||
|
return new RuleResolution(pointValue, payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
private RuleResolution resolveTier(GaoEventRecord record, GaoPointRule rule) {
|
||||||
|
JsonNode condition = rule.getConditionJson();
|
||||||
|
String sourceEventId = condition.get("sourceEventId").asText();
|
||||||
|
long amount = condition.get("window").get("amount").longValue();
|
||||||
|
ZoneId zone = ZoneId.systemDefault();
|
||||||
|
LocalDate currentDate = Instant.ofEpochMilli(record.getRegisteredAt()).atZone(zone).toLocalDate();
|
||||||
|
long windowBeginAt = currentDate.minusYears(amount).atStartOfDay(zone).toInstant().toEpochMilli();
|
||||||
|
long windowEndAt = Math.addExact(record.getRegisteredAt(), 1L);
|
||||||
|
long sumValue = TimiJava.defaultIfNull(eventRecordMapper.sumNumberValue(record.getStoreId(), record.getCustomerId(), sourceEventId, windowBeginAt, windowEndAt), 0L);
|
||||||
|
|
||||||
|
JsonNode matchedTier = null;
|
||||||
|
for (JsonNode tier : condition.get("tiers")) {
|
||||||
|
long min = tier.get("min").longValue();
|
||||||
|
JsonNode maxNode = tier.get("max");
|
||||||
|
if (min <= sumValue && (maxNode == null || maxNode.isNull() || sumValue <= maxNode.longValue())) {
|
||||||
|
matchedTier = tier;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TimiException.required(matchedTier, "TIER 没有匹配的分档");
|
||||||
|
long pointDelta = matchedTier.get("pointValue").longValue();
|
||||||
|
ObjectNode payload = jackson.createObjectNode();
|
||||||
|
payload.put("triggerType", GaoPointRule.TriggerType.CUSTOMER_EVENT_VALUE_TIER.name());
|
||||||
|
payload.put("sourceEventId", sourceEventId);
|
||||||
|
payload.put("sourceValueField", "numberValue");
|
||||||
|
payload.put("windowBeginAt", windowBeginAt);
|
||||||
|
payload.put("windowEndAt", windowEndAt);
|
||||||
|
payload.put("sumValue", sumValue);
|
||||||
|
ObjectNode tierPayload = payload.putObject("tier");
|
||||||
|
tierPayload.put("min", matchedTier.get("min").longValue());
|
||||||
|
JsonNode maxNode = matchedTier.get("max");
|
||||||
|
if (maxNode != null && !maxNode.isNull()) {
|
||||||
|
tierPayload.put("max", maxNode.longValue());
|
||||||
|
}
|
||||||
|
tierPayload.put("pointValue", pointDelta);
|
||||||
|
payload.put("pointDelta", pointDelta);
|
||||||
|
return new RuleResolution(pointDelta, payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
private long count(GaoEventRecord record) {
|
||||||
|
return TimiJava.defaultIfNull(eventRecordMapper.count(record.getStoreId(), record.getCustomerId(), record.getEventId(), null, null), 0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String revokeKey(GaoEventRecord record, GaoPointLedger originLedger) {
|
||||||
|
return "GAO_EVENT_RECORD:%s:LEDGER:%s:REVOKE".formatted(record.getId(), originLedger.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private record RuleResolution(Long pointDelta, JsonNode sourcePayload) {
|
||||||
|
}
|
||||||
|
}
|
||||||
-448
@@ -1,448 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service.implement;
|
|
||||||
|
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
|
||||||
import com.imyeyu.api.modules.common.vo.attach.BizUpdateReq;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRecord;
|
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoRegistrationEventRecordMapper;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoRegistrationEventService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoRegistrationEventRecordService;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventPeriodStatView;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerRegisterStatView;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoQuickRegistrationEventRecordReq;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordCreateReq;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordDailyStatView;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordPeriodReq;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordRangeReq;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordStatReq;
|
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordTrendStatReq;
|
|
||||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
|
||||||
import com.imyeyu.api.modules.user.service.UserService;
|
|
||||||
import com.imyeyu.java.TimiJava;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
|
||||||
import com.imyeyu.spring.bean.Page;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
|
||||||
import com.imyeyu.utils.Time;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
|
||||||
import org.apache.poi.ss.usermodel.Font;
|
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.StringJoiner;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 登记事件记录服务实现
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-27
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class GaoRegistrationEventRecordServiceImplement extends AbstractEntityService<GaoRegistrationEventRecord, String> implements GaoRegistrationEventRecordService {
|
|
||||||
|
|
||||||
private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
||||||
private static final DateTimeFormatter EXPORT_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault());
|
|
||||||
|
|
||||||
private final GaoRegistrationEventRecordMapper mapper;
|
|
||||||
private final AttachmentService attachmentService;
|
|
||||||
private final RoleChecker roleChecker;
|
|
||||||
private final UserLoginService userLoginService;
|
|
||||||
private final UserService userService;
|
|
||||||
private final GaoCustomerService customerService;
|
|
||||||
private final GaoRegistrationEventService registrationEventService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BaseMapper<GaoRegistrationEventRecord, String> mapper() {
|
|
||||||
return mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public GaoRegistrationEventRecord createRecord(GaoRegistrationEventRecordCreateReq req) {
|
|
||||||
TimiException.required(req, "not found req");
|
|
||||||
TimiException.required(req.getRegistrationEventId(), "not found req.registrationEventId");
|
|
||||||
String customerId = resolveCustomerId(req);
|
|
||||||
GaoRegistrationEvent registrationEvent = registrationEventService.get(req.getRegistrationEventId());
|
|
||||||
checkRegistrationEventPermission(registrationEvent);
|
|
||||||
if (Boolean.TRUE.equals(registrationEvent.getRequirePhoto())) {
|
|
||||||
TimiException.requiredTrue(req.getAttachmentIdList() != null && !req.getAttachmentIdList().isEmpty(), "required record photo");
|
|
||||||
}
|
|
||||||
|
|
||||||
GaoRegistrationEventRecord record = new GaoRegistrationEventRecord();
|
|
||||||
record.setCustomerId(customerId);
|
|
||||||
record.setRegistrationEventId(req.getRegistrationEventId());
|
|
||||||
record.setOperatorUserId(userLoginService.getRequireLoginUserId());
|
|
||||||
record.setRemark(req.getRemark());
|
|
||||||
record.setRegisteredAt(TimiJava.defaultIfNull(req.getRegisteredAt(), Time.now()));
|
|
||||||
super.create(record);
|
|
||||||
saveAttachment(record.getId(), buildPhotoAttachmentList(req.getAttachmentIdList()));
|
|
||||||
return get(record.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public GaoRegistrationEventRecord quickRegister(GaoQuickRegistrationEventRecordReq req) {
|
|
||||||
TimiException.required(req, "not found req");
|
|
||||||
TimiException.required(req.getCustomerCode(), "not found req.customerCode");
|
|
||||||
TimiException.required(req.getRegistrationEventId(), "not found req.registrationEventId");
|
|
||||||
GaoCustomer customer = customerService.getOrQuickCreateByCode(req.getCustomerCode());
|
|
||||||
GaoRegistrationEventRecordCreateReq recordReq = new GaoRegistrationEventRecordCreateReq();
|
|
||||||
recordReq.setCustomerId(customer.getId());
|
|
||||||
recordReq.setRegistrationEventId(req.getRegistrationEventId());
|
|
||||||
recordReq.setRemark(req.getRemark());
|
|
||||||
recordReq.setAttachmentIdList(req.getAttachmentIdList());
|
|
||||||
return createRecord(recordReq);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void update(GaoRegistrationEventRecord entity) {
|
|
||||||
TimiException.required(entity, "not found record");
|
|
||||||
TimiException.required(entity.getId(), "not found record.id");
|
|
||||||
TimiException.required(entity.getCustomerId(), "not found record.customerId");
|
|
||||||
TimiException.required(entity.getRegistrationEventId(), "not found record.registrationEventId");
|
|
||||||
customerService.get(entity.getCustomerId());
|
|
||||||
GaoRegistrationEvent registrationEvent = registrationEventService.get(entity.getRegistrationEventId());
|
|
||||||
checkRegistrationEventPermission(registrationEvent);
|
|
||||||
entity.setRegisteredAt(TimiJava.defaultIfNull(entity.getRegisteredAt(), Time.now()));
|
|
||||||
super.update(entity);
|
|
||||||
saveAttachment(entity.getId(), resolveAttachmentList(entity));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GaoRegistrationEventRecord get(String id) {
|
|
||||||
GaoRegistrationEventRecord record = super.get(id);
|
|
||||||
loadTransient(record);
|
|
||||||
return record;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GaoRegistrationEventRecord> listByRegistrationEventAndPeriod(GaoRegistrationEventRecordPeriodReq req) {
|
|
||||||
TimiException.required(req, "not found req");
|
|
||||||
TimiException.required(req.getRegistrationEventId(), "not found req.registrationEventId");
|
|
||||||
TimiException.required(req.getPeriodType(), "not found req.periodType");
|
|
||||||
TimiException.required(req.getPeriodValue(), "not found req.periodValue");
|
|
||||||
List<GaoRegistrationEventRecord> list = mapper.selectByRegistrationEventAndPeriod(req.getRegistrationEventId(), req.getPeriodType(), req.getPeriodValue());
|
|
||||||
list.forEach(this::loadTransient);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GaoRegistrationEventRecord> listByRange(GaoRegistrationEventRecordRangeReq req) {
|
|
||||||
TimiException.required(req, "not found req");
|
|
||||||
checkStatRange(req.getBeginRegisteredAt(), req.getEndRegisteredAt());
|
|
||||||
List<GaoRegistrationEventRecord> list = mapper.selectByRange(req);
|
|
||||||
list.forEach(this::loadTransient);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageResult<GaoRegistrationEventRecord> pageByRange(Page<GaoRegistrationEventRecordRangeReq> page) {
|
|
||||||
TimiException.required(page, "not found page");
|
|
||||||
TimiException.required(page.getIndex(), "not found page.index");
|
|
||||||
TimiException.required(page.getSize(), "not found page.size");
|
|
||||||
TimiException.requiredTrue(0 <= page.getIndex(), "page.index lt 0");
|
|
||||||
TimiException.requiredTrue(0 < page.getSize(), "page.size lte 0");
|
|
||||||
GaoRegistrationEventRecordRangeReq req = TimiJava.defaultIfNull(page.getEqualsExample(), new GaoRegistrationEventRecordRangeReq());
|
|
||||||
checkStatRange(req.getBeginRegisteredAt(), req.getEndRegisteredAt());
|
|
||||||
Long total = TimiJava.defaultIfNull(mapper.countByRange(req), 0L);
|
|
||||||
List<GaoRegistrationEventRecord> list = mapper.selectPageByRange(req, page.getIndex() * page.getSize(), page.getSize());
|
|
||||||
list.forEach(this::loadTransient);
|
|
||||||
PageResult<GaoRegistrationEventRecord> result = new PageResult<>();
|
|
||||||
result.setTotal(total);
|
|
||||||
result.setList(list);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] exportRangeExcel(GaoRegistrationEventRecordRangeReq req) throws IOException {
|
|
||||||
List<GaoRegistrationEventRecord> list = listByRange(req);
|
|
||||||
try (Workbook workbook = new XSSFWorkbook(); ByteArrayOutputStream output = new ByteArrayOutputStream()) {
|
|
||||||
Sheet sheet = workbook.createSheet("登记事件记录");
|
|
||||||
CellStyle titleStyle = workbook.createCellStyle();
|
|
||||||
Font titleFont = workbook.createFont();
|
|
||||||
titleFont.setBold(true);
|
|
||||||
titleFont.setFontHeightInPoints((short) 14);
|
|
||||||
titleStyle.setFont(titleFont);
|
|
||||||
CellStyle headerStyle = workbook.createCellStyle();
|
|
||||||
Font headerFont = workbook.createFont();
|
|
||||||
headerFont.setBold(true);
|
|
||||||
headerStyle.setFont(headerFont);
|
|
||||||
|
|
||||||
appendRow(sheet, 0, titleStyle, "登记事件记录导出");
|
|
||||||
appendRow(sheet, 1, null, "生成时间", EXPORT_TIME_FORMATTER.format(Instant.now()));
|
|
||||||
appendRow(sheet, 2, null, "时间范围", "%s ~ %s".formatted(formatExportTime(req.getBeginRegisteredAt()), formatExportTime(req.getEndRegisteredAt())));
|
|
||||||
appendRow(sheet, 3, null, "事件筛选", buildEventFilterText(req));
|
|
||||||
appendRow(sheet, 4, null, "关键词", req.getKeyword() == null || req.getKeyword().isBlank() ? "全部" : req.getKeyword().trim());
|
|
||||||
appendRow(sheet, 5, null, "记录总数", String.valueOf(list.size()));
|
|
||||||
appendRow(sheet, 7, headerStyle, "客户编码", "客户姓名", "登记事件", "登记时间", "登记人", "备注");
|
|
||||||
int rowIndex = 8;
|
|
||||||
for (GaoRegistrationEventRecord record : list) {
|
|
||||||
appendRow(sheet, rowIndex, null,
|
|
||||||
record.getCustomer() == null ? "" : text(record.getCustomer().getCode()),
|
|
||||||
record.getCustomer() == null ? "" : text(record.getCustomer().getName()),
|
|
||||||
record.getRegistrationEvent() == null ? "" : text(record.getRegistrationEvent().getName()),
|
|
||||||
formatExportTime(record.getRegisteredAt()),
|
|
||||||
getOperatorName(record),
|
|
||||||
text(record.getRemark())
|
|
||||||
);
|
|
||||||
rowIndex++;
|
|
||||||
}
|
|
||||||
for (int index = 0; index < 6; index++) {
|
|
||||||
sheet.autoSizeColumn(index);
|
|
||||||
sheet.setColumnWidth(index, Math.min(Math.max(sheet.getColumnWidth(index), 12 * 256), 40 * 256));
|
|
||||||
}
|
|
||||||
workbook.write(output);
|
|
||||||
return output.toByteArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GaoRegistrationEventPeriodStatView> statByRegistrationEventAndPeriodType(String registrationEventId, GaoRegistrationEventRecordPeriodReq.PeriodType periodType) {
|
|
||||||
TimiException.required(registrationEventId, "not found registrationEventId");
|
|
||||||
TimiException.required(periodType, "not found periodType");
|
|
||||||
return mapper.statByRegistrationEventAndPeriodType(registrationEventId, periodType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GaoRegistrationEventRecord> listLatestByCustomerIdListAndRegistrationEventId(List<String> customerIdList, String registrationEventId) {
|
|
||||||
TimiException.required(registrationEventId, "not found registrationEventId");
|
|
||||||
if (TimiJava.isEmpty(customerIdList)) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
List<GaoRegistrationEventRecord> list = mapper.selectLatestByCustomerIdListAndRegistrationEventId(customerIdList, registrationEventId);
|
|
||||||
list.forEach(this::loadTransient);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GaoCustomerRegisterStatView> statByCustomerId(String customerId) {
|
|
||||||
TimiException.required(customerId, "not found customerId");
|
|
||||||
return mapper.statByCustomerId(customerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GaoCustomerRegisterStatView> statByCustomerAndRange(GaoRegistrationEventRecordStatReq req) {
|
|
||||||
TimiException.required(req, "not found req");
|
|
||||||
TimiException.required(req.getCustomerId(), "not found req.customerId");
|
|
||||||
checkStatRange(req.getBeginRegisteredAt(), req.getEndRegisteredAt());
|
|
||||||
return mapper.statByCustomerIdAndRange(req.getCustomerId(), req.getBeginRegisteredAt(), req.getEndRegisteredAt());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GaoCustomerRegisterStatView> statAllCustomerByRange(GaoRegistrationEventRecordStatReq req) {
|
|
||||||
TimiException.required(req, "not found req");
|
|
||||||
checkStatRange(req.getBeginRegisteredAt(), req.getEndRegisteredAt());
|
|
||||||
return mapper.statAllCustomerByRange(req.getBeginRegisteredAt(), req.getEndRegisteredAt());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GaoRegistrationEventRecordDailyStatView> statDailyByCustomerAndRegistrationEvent(GaoRegistrationEventRecordTrendStatReq req) {
|
|
||||||
TimiException.required(req, "not found req");
|
|
||||||
TimiException.required(req.getCustomerId(), "not found req.customerId");
|
|
||||||
customerService.get(req.getCustomerId());
|
|
||||||
return buildDailyTrend(req, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GaoRegistrationEventRecordDailyStatView> statDailyByRegistrationEvent(GaoRegistrationEventRecordTrendStatReq req) {
|
|
||||||
TimiException.required(req, "not found req");
|
|
||||||
return buildDailyTrend(req, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GaoRegistrationEventRecord> listLatestByCustomerId(String customerId) {
|
|
||||||
TimiException.required(customerId, "not found customerId");
|
|
||||||
List<GaoRegistrationEventRecord> list = mapper.selectLatestByCustomerId(customerId);
|
|
||||||
list.forEach(this::loadTransient);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String resolveCustomerId(GaoRegistrationEventRecordCreateReq req) {
|
|
||||||
if (TimiJava.isNotEmpty(req.getCustomerId())) {
|
|
||||||
customerService.get(req.getCustomerId());
|
|
||||||
return req.getCustomerId();
|
|
||||||
}
|
|
||||||
TimiException.required(req.getCustomerCode(), "not found req.customerCode");
|
|
||||||
GaoCustomer customer = customerService.getByCode(req.getCustomerCode());
|
|
||||||
return customer.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkRegistrationEventPermission(GaoRegistrationEvent registrationEvent) {
|
|
||||||
List<String> roleCodeList = registrationEventService.listRoleCode(registrationEvent.getId());
|
|
||||||
if (roleCodeList != null && !roleCodeList.isEmpty()) {
|
|
||||||
roleChecker.checkAny(ModuleCode.GAO, roleCodeList.toArray(String[]::new));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkStatRange(Long beginRegisteredAt, Long endRegisteredAt) {
|
|
||||||
TimiException.required(beginRegisteredAt, "not found beginRegisteredAt");
|
|
||||||
TimiException.required(endRegisteredAt, "not found endRegisteredAt");
|
|
||||||
TimiException.requiredTrue(endRegisteredAt >= beginRegisteredAt, "endRegisteredAt lt beginRegisteredAt");
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<GaoRegistrationEventRecordDailyStatView> buildDailyTrend(GaoRegistrationEventRecordTrendStatReq req, boolean byCustomer) {
|
|
||||||
TimiException.required(req.getRegistrationEventId(), "not found req.registrationEventId");
|
|
||||||
registrationEventService.get(req.getRegistrationEventId());
|
|
||||||
checkStatRange(req.getBeginRegisteredAt(), req.getEndRegisteredAt());
|
|
||||||
ZoneId zoneId = ZoneId.systemDefault();
|
|
||||||
LocalDate beginDate = Instant.ofEpochMilli(req.getBeginRegisteredAt()).atZone(zoneId).toLocalDate();
|
|
||||||
LocalDate endDate = Instant.ofEpochMilli(req.getEndRegisteredAt()).atZone(zoneId).toLocalDate();
|
|
||||||
checkDailyStatRange(beginDate, endDate);
|
|
||||||
long beginRegisteredAt = beginDate.atStartOfDay(zoneId).toInstant().toEpochMilli();
|
|
||||||
long endRegisteredAt = endDate.plusDays(1).atStartOfDay(zoneId).toInstant().toEpochMilli() - 1;
|
|
||||||
Map<Integer, Long> dailyCountMap = new HashMap<>();
|
|
||||||
List<GaoRegistrationEventRecordDailyStatView> dbList = byCustomer
|
|
||||||
? mapper.statDailyCountByCustomerIdAndRegistrationEventIdRange(req.getCustomerId(), req.getRegistrationEventId(), beginRegisteredAt, endRegisteredAt)
|
|
||||||
: mapper.statDailyCountByRegistrationEventIdRange(req.getRegistrationEventId(), beginRegisteredAt, endRegisteredAt);
|
|
||||||
for (GaoRegistrationEventRecordDailyStatView view : dbList) {
|
|
||||||
dailyCountMap.put(view.getDateValue(), TimiJava.defaultIfNull(view.getDailyCount(), 0L));
|
|
||||||
}
|
|
||||||
long totalCount = byCustomer
|
|
||||||
? TimiJava.defaultIfNull(mapper.countBeforeByCustomerIdAndRegistrationEventId(req.getCustomerId(), req.getRegistrationEventId(), beginRegisteredAt), 0L)
|
|
||||||
: TimiJava.defaultIfNull(mapper.countBeforeByRegistrationEventId(req.getRegistrationEventId(), beginRegisteredAt), 0L);
|
|
||||||
List<GaoRegistrationEventRecordDailyStatView> list = new ArrayList<>();
|
|
||||||
for (LocalDate date = beginDate; !date.isAfter(endDate); date = date.plusDays(1)) {
|
|
||||||
int dateValue = Integer.parseInt(DAY_FORMATTER.format(date));
|
|
||||||
long dailyCount = TimiJava.defaultIfNull(dailyCountMap.get(dateValue), 0L);
|
|
||||||
totalCount += dailyCount;
|
|
||||||
GaoRegistrationEventRecordDailyStatView view = new GaoRegistrationEventRecordDailyStatView();
|
|
||||||
view.setDateValue(dateValue);
|
|
||||||
view.setDailyCount(dailyCount);
|
|
||||||
view.setTotalCount(totalCount);
|
|
||||||
list.add(view);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadTransient(GaoRegistrationEventRecord record) {
|
|
||||||
if (record == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
record.setCustomer(customerService.get(record.getCustomerId()));
|
|
||||||
record.setRegistrationEvent(registrationEventService.get(record.getRegistrationEventId()));
|
|
||||||
if (TimiJava.isNotEmpty(record.getOperatorUserId())) {
|
|
||||||
record.setOperator(userService.get(record.getOperatorUserId()));
|
|
||||||
}
|
|
||||||
record.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_REGISTRATION_EVENT_RECORD, record.getId(), GaoRegistrationEventRecord.AttachType.PHOTO.name()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkDailyStatRange(LocalDate beginDate, LocalDate endDate) {
|
|
||||||
long days = ChronoUnit.DAYS.between(beginDate, endDate) + 1;
|
|
||||||
TimiException.requiredTrue(days <= 366, "daily stat range too large");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveAttachment(String recordId, List<Attachment> attachmentList) {
|
|
||||||
if (attachmentList == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (Attachment attachment : attachmentList) {
|
|
||||||
attachment.setBizType(Attachment.BizType.GAO_REGISTRATION_EVENT_RECORD);
|
|
||||||
attachment.setBizId(recordId);
|
|
||||||
attachment.setAttachType(GaoRegistrationEventRecord.AttachType.PHOTO.name());
|
|
||||||
}
|
|
||||||
BizUpdateReq req = new BizUpdateReq();
|
|
||||||
req.setBizType(Attachment.BizType.GAO_REGISTRATION_EVENT_RECORD);
|
|
||||||
req.setBizId(recordId);
|
|
||||||
req.setItems(attachmentList);
|
|
||||||
attachmentService.updateByBiz(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Attachment> resolveAttachmentList(GaoRegistrationEventRecord record) {
|
|
||||||
if (record.getAttachmentIdList() != null) {
|
|
||||||
return buildPhotoAttachmentList(record.getAttachmentIdList());
|
|
||||||
}
|
|
||||||
return record.getAttachmentList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Attachment> buildPhotoAttachmentList(List<String> attachmentIdList) {
|
|
||||||
if (attachmentIdList == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
List<Attachment> list = new ArrayList<>();
|
|
||||||
for (String attachmentId : attachmentIdList) {
|
|
||||||
if (attachmentId == null || attachmentId.isBlank()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Attachment attachment = new Attachment();
|
|
||||||
attachment.setTempFileId(attachmentId.trim());
|
|
||||||
attachment.setAttachType(GaoRegistrationEventRecord.AttachType.PHOTO.name());
|
|
||||||
list.add(attachment);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendRow(Sheet sheet, int rowIndex, CellStyle style, String... values) {
|
|
||||||
Row row = sheet.createRow(rowIndex);
|
|
||||||
for (int index = 0; index < values.length; index++) {
|
|
||||||
row.createCell(index).setCellValue(values[index]);
|
|
||||||
if (style != null) {
|
|
||||||
row.getCell(index).setCellStyle(style);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String buildEventFilterText(GaoRegistrationEventRecordRangeReq req) {
|
|
||||||
if ((req.getRegistrationEventId() == null || req.getRegistrationEventId().isBlank()) && (req.getRegistrationEventIdList() == null || req.getRegistrationEventIdList().isEmpty())) {
|
|
||||||
return "全部事件";
|
|
||||||
}
|
|
||||||
if (req.getRegistrationEventId() != null && !req.getRegistrationEventId().isBlank()) {
|
|
||||||
return "事件 ID:" + req.getRegistrationEventId();
|
|
||||||
}
|
|
||||||
StringJoiner joiner = new StringJoiner("、");
|
|
||||||
req.getRegistrationEventIdList().stream()
|
|
||||||
.filter(Objects::nonNull)
|
|
||||||
.filter(item -> !item.isBlank())
|
|
||||||
.forEach(joiner::add);
|
|
||||||
return "事件 ID:" + joiner;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String formatExportTime(Long value) {
|
|
||||||
if (value == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return EXPORT_TIME_FORMATTER.format(Instant.ofEpochMilli(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getOperatorName(GaoRegistrationEventRecord record) {
|
|
||||||
if (record.getOperator() == null) {
|
|
||||||
return text(record.getOperatorUserId());
|
|
||||||
}
|
|
||||||
if (record.getOperator().getNick() != null && !record.getOperator().getNick().isBlank()) {
|
|
||||||
return record.getOperator().getNick();
|
|
||||||
}
|
|
||||||
if (record.getOperator().getName() != null && !record.getOperator().getName().isBlank()) {
|
|
||||||
return record.getOperator().getName();
|
|
||||||
}
|
|
||||||
return text(record.getOperatorUserId());
|
|
||||||
}
|
|
||||||
|
|
||||||
private String text(Object value) {
|
|
||||||
return value == null ? "" : value.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-127
@@ -1,127 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service.implement;
|
|
||||||
|
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRoleRelation;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent;
|
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoRegistrationEventRoleRelationMapper;
|
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoRegistrationEventMapper;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoRegistrationEventService;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
|
||||||
import com.imyeyu.spring.bean.Page;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 登记事件服务实现
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-27
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class GaoRegistrationEventServiceImplement extends AbstractEntityService<GaoRegistrationEvent, String> implements GaoRegistrationEventService {
|
|
||||||
|
|
||||||
private final GaoRegistrationEventMapper mapper;
|
|
||||||
private final GaoRegistrationEventRoleRelationMapper roleRelationMapper;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BaseMapper<GaoRegistrationEvent, String> mapper() {
|
|
||||||
return mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageResult<GaoRegistrationEvent> pageWithRegistrationEventLimit(Page<GaoRegistrationEvent> page) {
|
|
||||||
PageResult<GaoRegistrationEvent> result = page(page);
|
|
||||||
if (result.getList() != null) {
|
|
||||||
result.getList().forEach(this::loadRegistrationEventLimit);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void create(GaoRegistrationEvent entity) {
|
|
||||||
checkEntity(entity, false);
|
|
||||||
super.create(entity);
|
|
||||||
saveRoleRelation(entity.getId(), entity.getRoleCodeList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void update(GaoRegistrationEvent entity) {
|
|
||||||
checkEntity(entity, true);
|
|
||||||
super.update(entity);
|
|
||||||
saveRoleRelation(entity.getId(), entity.getRoleCodeList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void delete(String id) {
|
|
||||||
roleRelationMapper.deleteByRegistrationEventId(id);
|
|
||||||
super.delete(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GaoRegistrationEvent get(String id) {
|
|
||||||
GaoRegistrationEvent registrationEvent = super.get(id);
|
|
||||||
registrationEvent.setRoleCodeList(roleRelationMapper.selectRoleCodeListByRegistrationEventId(id));
|
|
||||||
return registrationEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GaoRegistrationEvent> listEnabled() {
|
|
||||||
List<GaoRegistrationEvent> list = mapper.selectEnabledList();
|
|
||||||
list.forEach(this::loadRegistrationEventLimit);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> listRoleCode(String registrationEventId) {
|
|
||||||
return roleRelationMapper.selectRoleCodeListByRegistrationEventId(registrationEventId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkEntity(GaoRegistrationEvent entity, boolean requireId) {
|
|
||||||
TimiException.required(entity, "not found registrationEvent");
|
|
||||||
if (requireId) {
|
|
||||||
TimiException.required(entity.getId(), "not found registrationEvent.id");
|
|
||||||
}
|
|
||||||
TimiException.required(entity.getName(), "not found registrationEvent.name");
|
|
||||||
if (entity.getEnabled() == null) {
|
|
||||||
entity.setEnabled(true);
|
|
||||||
}
|
|
||||||
if (entity.getRequirePhoto() == null) {
|
|
||||||
entity.setRequirePhoto(false);
|
|
||||||
}
|
|
||||||
if (entity.getSort() == null) {
|
|
||||||
entity.setSort(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveRoleRelation(String registrationEventId, List<String> roleCodeList) {
|
|
||||||
roleRelationMapper.deleteByRegistrationEventId(registrationEventId);
|
|
||||||
if (roleCodeList == null || roleCodeList.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Set<String> distinctCodeSet = new LinkedHashSet<>(roleCodeList);
|
|
||||||
for (String roleCode : distinctCodeSet) {
|
|
||||||
if (roleCode == null || roleCode.isBlank()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
GaoRegistrationEventRoleRelation relation = new GaoRegistrationEventRoleRelation();
|
|
||||||
relation.setRegistrationEventId(registrationEventId);
|
|
||||||
relation.setRoleCode(roleCode.trim());
|
|
||||||
roleRelationMapper.insert(relation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadRegistrationEventLimit(GaoRegistrationEvent registrationEvent) {
|
|
||||||
registrationEvent.setRoleCodeList(roleRelationMapper.selectRoleCodeListByRegistrationEventId(registrationEvent.getId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service.implement;
|
||||||
|
|
||||||
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
|
import com.imyeyu.api.bean.CoreRoleCode;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoStore;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||||
|
import com.imyeyu.api.modules.user.bean.AuthOwnerType;
|
||||||
|
import com.imyeyu.api.modules.user.entity.Role;
|
||||||
|
import com.imyeyu.api.modules.user.entity.UserRole;
|
||||||
|
import com.imyeyu.api.modules.user.mapper.RoleMapper;
|
||||||
|
import com.imyeyu.api.modules.user.mapper.UserRoleMapper;
|
||||||
|
import com.imyeyu.api.modules.user.service.ModuleResourceScopeResolver;
|
||||||
|
import com.imyeyu.api.modules.user.service.RoleHierarchyService;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// GAO 资源范围解析器
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-07
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GaoResourceScopeResolver implements ModuleResourceScopeResolver {
|
||||||
|
|
||||||
|
private final RoleMapper roleMapper;
|
||||||
|
private final UserRoleMapper userRoleMapper;
|
||||||
|
private final GaoStoreService gaoStoreService;
|
||||||
|
private final RoleHierarchyService roleHierarchyService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModuleCode moduleCode() {
|
||||||
|
return ModuleCode.GAO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canManageUser(String operatorUserId, String targetUserId) {
|
||||||
|
if (hasCoreRole(operatorUserId, CoreRoleCode.ADMIN)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (hasGaoRole(operatorUserId, GaoRoleCode.GLOBAL_MANAGER)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!hasGaoRole(operatorUserId, GaoRoleCode.STORE_MANAGER)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
GaoStore operatorStore = gaoStoreService.getByUserId(operatorUserId);
|
||||||
|
GaoStore targetStore = gaoStoreService.getByUserId(targetUserId);
|
||||||
|
return operatorStore != null && targetStore != null && operatorStore.getId().equals(targetStore.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canManageRole(String operatorUserId, Role role) {
|
||||||
|
if (hasCoreRole(operatorUserId, CoreRoleCode.ADMIN)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (hasGaoRole(operatorUserId, GaoRoleCode.GLOBAL_MANAGER)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!hasGaoRole(operatorUserId, GaoRoleCode.STORE_MANAGER)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (canUseOwnerScope(operatorUserId, role.getOwnerType(), role.getOwnerId())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return ModuleCode.GAO == role.getModuleCode()
|
||||||
|
&& role.getOwnerType() == AuthOwnerType.MODULE
|
||||||
|
&& (TimiJava.isEmpty(role.getOwnerId()) || ModuleCode.GAO.name().equals(role.getOwnerId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUseOwnerScope(String operatorUserId, AuthOwnerType ownerType, String ownerId) {
|
||||||
|
if (hasCoreRole(operatorUserId, CoreRoleCode.ADMIN)) {
|
||||||
|
return ownerType == AuthOwnerType.MODULE && ModuleCode.GAO.name().equals(ownerId) || ownerType == AuthOwnerType.STORE;
|
||||||
|
}
|
||||||
|
if (hasGaoRole(operatorUserId, GaoRoleCode.GLOBAL_MANAGER)) {
|
||||||
|
return ownerType == AuthOwnerType.MODULE && ModuleCode.GAO.name().equals(ownerId) || ownerType == AuthOwnerType.STORE;
|
||||||
|
}
|
||||||
|
if (!hasGaoRole(operatorUserId, GaoRoleCode.STORE_MANAGER) || ownerType != AuthOwnerType.STORE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
GaoStore store = gaoStoreService.getByUserId(operatorUserId);
|
||||||
|
return store != null && store.getId().equals(ownerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasGaoRole(String userId, GaoRoleCode roleCode) {
|
||||||
|
if (TimiJava.isEmpty(userId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
List<String> roleIdList = userRoleMapper.selectByUserIdList(List.of(userId)).stream().map(UserRole::getRoleId).toList();
|
||||||
|
if (TimiJava.isEmpty(roleIdList)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 身份角色只依赖系统、模块级继承,不能依赖当前正在计算的门店作用域
|
||||||
|
List<String> allRoleIdList = roleHierarchyService.listAllRoleIdIncludingChildren(roleIdList);
|
||||||
|
return roleMapper.selectByIdList(allRoleIdList).stream().anyMatch(role -> ModuleCode.GAO == role.getModuleCode() && roleCode.name().equals(role.getCode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasCoreRole(String userId, CoreRoleCode roleCode) {
|
||||||
|
if (TimiJava.isEmpty(userId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
List<String> roleIdList = userRoleMapper.selectByUserIdList(List.of(userId)).stream().map(UserRole::getRoleId).toList();
|
||||||
|
if (TimiJava.isEmpty(roleIdList)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
List<String> allRoleIdList = roleHierarchyService.listAllRoleIdIncludingChildren(roleIdList);
|
||||||
|
return roleMapper.selectByIdList(allRoleIdList).stream().anyMatch(role -> ModuleCode.CORE == role.getModuleCode() && roleCode.name().equals(role.getCode()));
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user