Compare commits
51
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8e2e16ba5 | ||
|
|
bdc4cbb240 | ||
|
|
99b44faf09 | ||
|
|
7f6cebd4e2 | ||
|
|
75fd4bed18 | ||
|
|
b3e3cbf84b | ||
|
|
8db6f962c9 | ||
|
|
0aee11d824 | ||
|
|
e35cf3aa59 | ||
|
|
457e716b38 | ||
|
|
ab4a164680 | ||
|
|
9dfca25f8c | ||
|
|
e369a38e2e | ||
|
|
f1e10df6a7 | ||
|
|
fcf358a768 | ||
|
|
36e2a37af2 | ||
|
|
348f7396a1 | ||
|
|
619369104c | ||
|
|
c0b04fc554 | ||
|
|
5e5748b521 | ||
|
|
67d79f7527 | ||
|
|
ee530d2a8c | ||
|
|
5f36844279 | ||
|
|
5b9391a50a | ||
|
|
6bc73414d9 | ||
|
|
4f1408b9d0 | ||
|
|
d555aad9ac | ||
|
|
029eea70cc | ||
|
|
2f42204794 | ||
|
|
22b1e65385 | ||
|
|
72bdb8d49b | ||
|
|
5ec6bc472f | ||
|
|
81b7356d67 | ||
|
|
44af16f451 | ||
|
|
c6157db0de | ||
|
|
39ac73dc66 | ||
|
|
2170c48763 | ||
|
|
c2d1c48aae | ||
|
|
e14958c643 | ||
|
|
da288338cd | ||
|
|
ea430f2468 | ||
|
|
f76f79744a | ||
|
|
19daaff907 | ||
|
|
db94d8f932 | ||
|
|
53618fe362 | ||
|
|
523edffc4e | ||
|
|
c7ddb1a8b0 | ||
|
|
45c9fc814a | ||
|
|
407dc13ac4 | ||
|
|
0c06bf16c2 | ||
|
|
1db39e77d3 |
@@ -46,6 +46,11 @@ jobs:
|
||||
<username>${{ vars.TIMI_NEXUS_USERNAME }}</username>
|
||||
<password>${{ vars.TIMI_NEXUS_PASSWORD }}</password>
|
||||
</server>
|
||||
<server>
|
||||
<id>e2ins_nexus</id>
|
||||
<username>${{ vars.E2INS_NEXUS_USERNAME }}</username>
|
||||
<password>${{ vars.E2INS_NEXUS_PASSWORD }}</password>
|
||||
</server>
|
||||
</servers>
|
||||
</settings>
|
||||
EOF
|
||||
|
||||
Generated
+1
-1
@@ -3,7 +3,7 @@
|
||||
<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/V2__init_system_data.sql" dialect="GenericSQL" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources/mapper/timi-server/GaoEventRecordMapper.xml" dialect="MariaDB" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources/mapper/timi-server/gao/GaoEventRecordMapper.xml" dialect="MariaDB" />
|
||||
<file url="PROJECT" dialect="MariaDB" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
<groupId>com.imyeyu.timiserverapi</groupId>
|
||||
<artifactId>TimiServerAPI</artifactId>
|
||||
<version>1.0.8</version>
|
||||
<version>1.0.15</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>TimiServerAPI</name>
|
||||
<description>imyeyu.com API</description>
|
||||
@@ -167,6 +167,16 @@
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>e2ins_nexus</id>
|
||||
<url>https://nexus.e2ins.com/repository/maven-public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@@ -178,7 +188,7 @@
|
||||
<dependency>
|
||||
<groupId>com.imyeyu.network</groupId>
|
||||
<artifactId>timi-network</artifactId>
|
||||
<version>0.0.13</version>
|
||||
<version>0.0.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.imyeyu.lang</groupId>
|
||||
@@ -225,6 +235,11 @@
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-mysql</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.e2ins.ms.notify</groupId>
|
||||
<artifactId>e2ins-msg-notify-service-sdk</artifactId>
|
||||
<version>0.0.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-freemarker</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_DELETE("ROLE_PERMISSION:DELETE", "角色权限删除", false, true),
|
||||
|
||||
ROLE_RELATION_CREATE("ROLE_RELATION:CREATE", "角色关联创建", false, true),
|
||||
ROLE_RELATION_READ("ROLE_RELATION:READ", "角色关联读取", false, true),
|
||||
ROLE_RELATION_DELETE("ROLE_RELATION:DELETE", "角色关联删除", false, true),
|
||||
ROLE_PERMISSION_INHERIT_CREATE("ROLE_PERMISSION_INHERIT:CREATE", "角色权限继承创建", false, true),
|
||||
ROLE_PERMISSION_INHERIT_READ("ROLE_PERMISSION_INHERIT:READ", "角色权限继承读取", false, true),
|
||||
ROLE_PERMISSION_INHERIT_DELETE("ROLE_PERMISSION_INHERIT:DELETE", "角色权限继承删除", false, true),
|
||||
|
||||
SETTING_CREATE("SETTING:CREATE", "设置创建", false, true),
|
||||
SETTING_READ("SETTING:READ", "设置读取", false, true),
|
||||
@@ -39,6 +39,12 @@ public enum CorePermissionCode implements BuiltinPermissionCode {
|
||||
MULTILINGUAL_UPDATE("MULTILINGUAL:UPDATE", "多语言修改", 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_READ("USER:READ", "用户读取", false, true),
|
||||
USER_UPDATE("USER:UPDATE", "用户修改", false, true),
|
||||
|
||||
@@ -13,9 +13,7 @@ public enum CoreRoleCode implements BuiltinRoleCode {
|
||||
|
||||
SYSTEM("系统", true, null),
|
||||
|
||||
ADMIN("管理员", false, SYSTEM.name()),
|
||||
|
||||
USER_ROLE_ADMIN("授权管理", false, ADMIN.name());
|
||||
ADMIN("管理员", false, SYSTEM.name());
|
||||
|
||||
final String defaultName;
|
||||
final boolean protectedRole;
|
||||
@@ -40,4 +38,5 @@ public enum CoreRoleCode implements BuiltinRoleCode {
|
||||
public String getParentCode() {
|
||||
return parentCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.imyeyu.api.config;
|
||||
|
||||
import com.e2ins.ms.notify.SmsNotifyService;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
@@ -31,6 +32,12 @@ public class BeanConfig {
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SmsNotifyService smsNotifyService() {
|
||||
// TODO
|
||||
return new SmsNotifyService(null, null);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Yaml yaml() {
|
||||
return new Yaml();
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.imyeyu.api.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
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.config.AbstractRedisConfig;
|
||||
import com.imyeyu.spring.util.Redis;
|
||||
@@ -202,4 +203,10 @@ public class RedisConfig extends AbstractRedisConfig {
|
||||
public Redis<String, String> getClipboardRedisTemplate() {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.imyeyu.api.annotation.EnableSettingInterceptor;
|
||||
import com.imyeyu.api.annotation.RequestRateLimitInterceptor;
|
||||
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.RequireGaoRoleInterceptor;
|
||||
import com.imyeyu.api.modules.journal.util.JournalAPIInterceptor;
|
||||
import com.imyeyu.api.modules.system.util.SystemAPIInterceptor;
|
||||
import com.imyeyu.spring.annotation.RequestBodyValueArgumentResolver;
|
||||
@@ -43,8 +41,6 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
private final SystemAPIInterceptor systemAPIInterceptor;
|
||||
private final JournalAPIInterceptor journalAPIInterceptor;
|
||||
private final EnableSettingInterceptor enableSettingInterceptor;
|
||||
private final RequireGaoRoleInterceptor requireGaoRoleInterceptor;
|
||||
private final RequireCoreRoleInterceptor requireCoreRoleInterceptor;
|
||||
private final RequestRateLimitInterceptor requestRateLimitInterceptor;
|
||||
private final RequireGaoPermissionInterceptor requireGaoPermissionInterceptor;
|
||||
private final RequireCorePermissionInterceptor requireCorePermissionInterceptor;
|
||||
@@ -59,9 +55,7 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
registry.addInterceptor(systemAPIInterceptor).addPathPatterns(SystemAPIInterceptor.PATH);
|
||||
registry.addInterceptor(journalAPIInterceptor).addPathPatterns(JournalAPIInterceptor.PATH);
|
||||
registry.addInterceptor(enableSettingInterceptor).addPathPatterns("/**");
|
||||
registry.addInterceptor(requireCoreRoleInterceptor).addPathPatterns("/**");
|
||||
registry.addInterceptor(requireCorePermissionInterceptor).addPathPatterns("/**");
|
||||
registry.addInterceptor(requireGaoRoleInterceptor).addPathPatterns("/**");
|
||||
registry.addInterceptor(requireGaoPermissionInterceptor).addPathPatterns("/**");
|
||||
registry.addInterceptor(requestRateLimitInterceptor).addPathPatterns("/**");
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ public enum SettingModule {
|
||||
|
||||
TEMP_FILE(Setting.Module.TempFile.class),
|
||||
|
||||
USER(Setting.Module.User.class),
|
||||
|
||||
SYSTEM(Setting.Module.System.class),
|
||||
|
||||
SYSTEM_STATUS(Setting.Module.SystemStatus.class);
|
||||
|
||||
@@ -2,9 +2,7 @@ package com.imyeyu.api.modules.common.controller;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import com.imyeyu.api.annotation.RequireCorePermission;
|
||||
import com.imyeyu.api.annotation.RequireCoreRole;
|
||||
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.service.MultilingualService;
|
||||
import com.imyeyu.spring.annotation.AOPLog;
|
||||
@@ -40,7 +38,6 @@ public class MultilingualController {
|
||||
*/
|
||||
@JsonView(ResponseView.Admin.class)
|
||||
@RequestRateLimit
|
||||
@RequireCoreRole(CoreRoleCode.ADMIN)
|
||||
@RequireCorePermission(CorePermissionCode.MULTILINGUAL_READ)
|
||||
@PostMapping("/detail")
|
||||
public Multilingual detail(@RequestParam String id) {
|
||||
@@ -56,7 +53,6 @@ public class MultilingualController {
|
||||
@AOPLog
|
||||
@JsonView(ResponseView.Admin.class)
|
||||
@RequestRateLimit
|
||||
@RequireCoreRole(CoreRoleCode.ADMIN)
|
||||
@RequireCorePermission(CorePermissionCode.MULTILINGUAL_CREATE)
|
||||
@PostMapping("/create")
|
||||
public Multilingual create(@RequestBody Multilingual multilingual) {
|
||||
@@ -71,7 +67,6 @@ public class MultilingualController {
|
||||
*/
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCoreRole(CoreRoleCode.ADMIN)
|
||||
@RequireCorePermission(CorePermissionCode.MULTILINGUAL_UPDATE)
|
||||
@PostMapping("/update")
|
||||
public void update(@RequestBody Multilingual multilingual) {
|
||||
@@ -85,7 +80,6 @@ public class MultilingualController {
|
||||
*/
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCoreRole(CoreRoleCode.ADMIN)
|
||||
@RequireCorePermission(CorePermissionCode.MULTILINGUAL_DELETE)
|
||||
@PostMapping("/delete")
|
||||
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,23 +1,43 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import com.imyeyu.api.annotation.MultilingualField;
|
||||
import com.imyeyu.spring.annotation.table.Transient;
|
||||
import com.imyeyu.spring.entity.UUIDEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
* @since 2024-08-28 14:26
|
||||
*/
|
||||
/// 标签
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2024-08-28 14:26
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
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
|
||||
protected String value;
|
||||
@MultilingualField("nameLangId")
|
||||
protected String name;
|
||||
|
||||
/// 中文名称
|
||||
@Transient
|
||||
protected String zhCN;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import com.imyeyu.spring.annotation.table.Transient;
|
||||
import com.imyeyu.spring.entity.UUIDEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 标签应用
|
||||
*
|
||||
@@ -14,12 +17,25 @@ import lombok.EqualsAndHashCode;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class TagApply extends UUIDEntity {
|
||||
|
||||
///
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-12 14:27
|
||||
public enum BizType {
|
||||
|
||||
GAO_CUSTOMER
|
||||
}
|
||||
|
||||
/** 业务类型 */
|
||||
protected String bizType;
|
||||
protected BizType bizType;
|
||||
|
||||
/** 业务 ID */
|
||||
protected String bizId;
|
||||
|
||||
/** 标签 ID */
|
||||
protected String tagId;
|
||||
|
||||
/// 标签 ID 列表
|
||||
@Transient
|
||||
private List<String> tagIdList;
|
||||
}
|
||||
|
||||
@@ -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.spring.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
* @since 2025-05-30 22:48
|
||||
*/
|
||||
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,10 +1,10 @@
|
||||
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.entity.Setting;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.spring.service.BaseService;
|
||||
import com.imyeyu.utils.Text;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -19,7 +19,7 @@ public interface SettingService extends BaseService<Setting, String> {
|
||||
Setting getByCode(String bizType, String bizId, String code);
|
||||
|
||||
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);
|
||||
|
||||
@@ -1,11 +1,31 @@
|
||||
package com.imyeyu.api.modules.common.service;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.Tag;
|
||||
import com.imyeyu.api.modules.common.entity.TagApply;
|
||||
import com.imyeyu.spring.service.BaseService;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
* @since 2025-05-30 22:46
|
||||
*/
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/// 标签服务
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2025-05-30 22:46
|
||||
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);
|
||||
}
|
||||
|
||||
+3
@@ -41,6 +41,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -347,6 +348,8 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void updateByBizId(Attachment.BizType bizType, String bizId, List<Attachment> list) {
|
||||
list = TimiJava.defaultIfNull(list, new ArrayList<>());
|
||||
|
||||
// 数据库现有附件
|
||||
List<Attachment> dbList = mapper.selectAllByBizId(bizType, bizId);
|
||||
Set<String> dbIds = dbList.stream().map(Attachment::getId).collect(Collectors.toSet());
|
||||
|
||||
+88
-4
@@ -1,27 +1,111 @@
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
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.service.MultilingualService;
|
||||
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.service.AbstractEntityService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
* @since 2025-05-30 22:47
|
||||
*/
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
/// 标签服务实现
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2025-05-30 22:47
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TagServiceImplement extends AbstractEntityService<Tag, String> implements TagService {
|
||||
|
||||
private final TagMapper mapper;
|
||||
private final TagApplyMapper applyMapper;
|
||||
private final MultilingualService multilingualService;
|
||||
|
||||
@Override
|
||||
protected BaseMapper<Tag, String> 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), "该标签名称已存在");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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,50 +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.core.annotation.AnnotatedElementUtils;
|
||||
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) {
|
||||
annotation = AnnotatedElementUtils.findMergedAnnotation(handlerMethod.getBeanType(), 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;
|
||||
}
|
||||
}
|
||||
@@ -21,45 +21,61 @@ public enum GaoPermissionCode implements BuiltinPermissionCode {
|
||||
|
||||
STORE_DELETE("STORE:DELETE", "门店删除", false, true),
|
||||
|
||||
CUSTOMER_CREATE("CUSTOMER:CREATE", "客户创建"),
|
||||
CUSTOMER_CREATE("CUSTOMER:CREATE", "客户创建", false, false),
|
||||
|
||||
CUSTOMER_READ("CUSTOMER:READ", "客户读取"),
|
||||
CUSTOMER_READ("CUSTOMER:READ", "客户读取", false, false),
|
||||
|
||||
CUSTOMER_EXPORT("CUSTOMER:EXPORT", "客户导出", true),
|
||||
CUSTOMER_EXPORT("CUSTOMER:EXPORT", "客户导出", true, false),
|
||||
|
||||
CUSTOMER_UPDATE("CUSTOMER:UPDATE", "客户修改"),
|
||||
CUSTOMER_UPDATE("CUSTOMER:UPDATE", "客户修改", false, false),
|
||||
|
||||
CUSTOMER_DELETE("CUSTOMER:DELETE", "客户删除"),
|
||||
CUSTOMER_DELETE("CUSTOMER:DELETE", "客户删除", false, false),
|
||||
|
||||
EVENT_CREATE("EVENT:CREATE", "登记事件创建"),
|
||||
EVENT_CREATE("EVENT:CREATE", "登记事件创建", false, false),
|
||||
|
||||
EVENT_READ("EVENT:READ", "登记事件读取"),
|
||||
EVENT_READ("EVENT:READ", "登记事件读取", false, false),
|
||||
|
||||
EVENT_UPDATE("EVENT:UPDATE", "登记事件修改"),
|
||||
EVENT_UPDATE("EVENT:UPDATE", "登记事件修改", false, false),
|
||||
|
||||
EVENT_DELETE("EVENT:DELETE", "登记事件删除"),
|
||||
EVENT_DELETE("EVENT:DELETE", "登记事件删除", false, false),
|
||||
|
||||
EVENT_RECORD_CREATE("EVENT_RECORD:CREATE", "登记事件记录创建"),
|
||||
EVENT_RECORD_CREATE("EVENT_RECORD:CREATE", "登记事件记录创建", false, false),
|
||||
|
||||
EVENT_RECORD_READ("EVENT_RECORD:READ", "登记事件记录读取"),
|
||||
EVENT_RECORD_READ("EVENT_RECORD:READ", "登记事件记录读取", false, false),
|
||||
|
||||
EVENT_RECORD_EXPORT("EVENT_RECORD:EXPORT", "登记事件记录导出", true),
|
||||
EVENT_RECORD_EXPORT("EVENT_RECORD:EXPORT", "登记事件记录导出", true, false),
|
||||
|
||||
EVENT_RECORD_UPDATE("EVENT_RECORD:UPDATE", "登记事件记录修改"),
|
||||
EVENT_RECORD_UPDATE("EVENT_RECORD:UPDATE", "登记事件记录修改", false, false),
|
||||
|
||||
EVENT_RECORD_DELETE("EVENT_RECORD:DELETE", "登记事件记录删除"),
|
||||
EVENT_RECORD_DELETE("EVENT_RECORD:DELETE", "登记事件记录删除", false, false),
|
||||
|
||||
STAT_READ("STAT:READ", "统计读取"),
|
||||
POINT_ACCOUNT_READ("POINT_ACCOUNT:READ", "客户积分账户读取", true, true),
|
||||
|
||||
QR_CODE_CREATE("QR_CODE:CREATE", "二维码创建"),
|
||||
POINT_LEDGER_READ("POINT_LEDGER:READ", "客户积分流水读取", true, true),
|
||||
|
||||
USER_CREATE("USER:CREATE", "用户创建", true),
|
||||
POINT_RULE_CREATE("POINT_RULE:CREATE", "客户积分规则创建", true, true),
|
||||
|
||||
USER_READ("USER:READ", "用户读取", true),
|
||||
POINT_RULE_READ("POINT_RULE:READ", "客户积分规则读取", true, true),
|
||||
|
||||
USER_UPDATE("USER:UPDATE", "用户修改", true),
|
||||
POINT_RULE_UPDATE("POINT_RULE:UPDATE", "客户积分规则修改", true, true),
|
||||
|
||||
USER_DELETE("USER:DELETE", "用户删除", 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 defaultName;
|
||||
@@ -68,18 +84,10 @@ public enum GaoPermissionCode implements BuiltinPermissionCode {
|
||||
@Getter
|
||||
final boolean grantToStoreManager;
|
||||
|
||||
/// `true` 为初始化时授权给全局管理员角色
|
||||
/// `true` 为初始化时授权给门店管理角色
|
||||
@Getter
|
||||
final boolean grantToGlobalManager;
|
||||
|
||||
GaoPermissionCode(String value, String defaultName) {
|
||||
this(value, defaultName, false, false);
|
||||
}
|
||||
|
||||
GaoPermissionCode(String value, String defaultName, boolean grantToStoreManager) {
|
||||
this(value, defaultName, grantToStoreManager, false);
|
||||
}
|
||||
|
||||
GaoPermissionCode(String value, String defaultName, boolean grantToStoreManager, boolean grantToGlobalManager) {
|
||||
this.value = value;
|
||||
this.defaultName = defaultName;
|
||||
|
||||
@@ -12,13 +12,11 @@ import lombok.AllArgsConstructor;
|
||||
@AllArgsConstructor
|
||||
public enum GaoRoleCode implements BuiltinRoleCode {
|
||||
|
||||
/// 全局管理员
|
||||
GLOBAL_MANAGER("全局管理员", null),
|
||||
/// 门店管理
|
||||
GLOBAL_MANAGER("门店管理", null),
|
||||
|
||||
/// 店长
|
||||
STORE_MANAGER("店长", GLOBAL_MANAGER.name()),
|
||||
|
||||
EMPLOYEE("员工", STORE_MANAGER.name());
|
||||
STORE_MANAGER("店长", GLOBAL_MANAGER.name());
|
||||
|
||||
final String defaultName;
|
||||
final String parentCode;
|
||||
@@ -42,4 +40,5 @@ public enum GaoRoleCode implements BuiltinRoleCode {
|
||||
public String getParentCode() {
|
||||
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,GLOBAL_MANAGER 可为空
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,9 @@ package com.imyeyu.api.modules.gao.controller;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import com.imyeyu.api.bean.ModuleCode;
|
||||
import com.imyeyu.api.bean.RoleMatchMode;
|
||||
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.RequireGaoRole;
|
||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||
@@ -14,6 +12,7 @@ import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||
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.api.modules.gao.vo.GaoCustomerTrendStateReq;
|
||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
@@ -46,7 +45,6 @@ import java.util.Map;
|
||||
/// @author 夜雨
|
||||
/// @since 2026-07-27 14:12
|
||||
@RestController
|
||||
@RequireGaoRole(value = {GaoRoleCode.GLOBAL_MANAGER, GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/gao/customer")
|
||||
public class GaoCustomerController {
|
||||
@@ -63,8 +61,8 @@ public class GaoCustomerController {
|
||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||
@PostMapping("/list")
|
||||
@JsonView(ResponseView.Public.class)
|
||||
public PageResult<GaoCustomer> list(@RequestBody Page<GaoCustomer> page) {
|
||||
PageResult<GaoCustomer> result = service.page(page);
|
||||
public PageResult<GaoCustomer> list(@RequestBody GaoCustomerPage page) {
|
||||
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);
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.imyeyu.api.modules.gao.controller;
|
||||
|
||||
import com.imyeyu.api.bean.ModuleCode;
|
||||
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.bean.GaoPermissionCode;
|
||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
||||
@@ -30,7 +28,6 @@ import java.util.Map;
|
||||
/// @author 夜雨
|
||||
/// @since 2026-07-27 14:13
|
||||
@RestController
|
||||
@RequireGaoRole(value = {GaoRoleCode.GLOBAL_MANAGER, GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/gao/event")
|
||||
public class GaoEventController {
|
||||
@@ -65,7 +62,9 @@ public class GaoEventController {
|
||||
@RequireGaoPermission(GaoPermissionCode.EVENT_READ)
|
||||
@PostMapping("/detail")
|
||||
public GaoEvent detail(@RequestParam String id) {
|
||||
return service.get(id);
|
||||
GaoEvent event = service.get(id);
|
||||
event.setRoleCodeList(service.listRoleCode(event.getId()));
|
||||
return event;
|
||||
}
|
||||
|
||||
@AOPLog
|
||||
|
||||
@@ -2,11 +2,9 @@ package com.imyeyu.api.modules.gao.controller;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import com.imyeyu.api.bean.ModuleCode;
|
||||
import com.imyeyu.api.bean.RoleMatchMode;
|
||||
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.RequireGaoRole;
|
||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||
@@ -18,6 +16,7 @@ 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;
|
||||
@@ -48,7 +47,6 @@ import java.util.Map;
|
||||
/// @author 夜雨
|
||||
/// @since 2026-07-27 14:11
|
||||
@RestController
|
||||
@RequireGaoRole(value = {GaoRoleCode.GLOBAL_MANAGER, GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/gao/event/record")
|
||||
public class GaoEventRecordController {
|
||||
@@ -67,8 +65,12 @@ public class GaoEventRecordController {
|
||||
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_READ)
|
||||
@PostMapping("/list")
|
||||
@JsonView(ResponseView.Public.class)
|
||||
public PageResult<GaoEventRecord> list(@RequestBody GaoEventRecordPage page) {
|
||||
PageResult<GaoEventRecord> result = service.pageByRange(page);
|
||||
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());
|
||||
@@ -83,6 +85,22 @@ public class GaoEventRecordController {
|
||||
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)
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
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.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.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.RequestRateLimit;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -19,17 +20,18 @@ import java.util.List;
|
||||
/// @author 夜雨
|
||||
/// @since 2026-07-28 14:15
|
||||
@RestController
|
||||
@RequireGaoRole(GaoRoleCode.STORE_MANAGER)
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/gao/role")
|
||||
public class GaoRoleController {
|
||||
|
||||
private final RoleService roleService;
|
||||
private final UserLoginService userLoginService;
|
||||
private final AuthorizationScopeService authorizationScopeService;
|
||||
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.ROLE_READ)
|
||||
@PostMapping("/available/list")
|
||||
public List<Role> availableList() {
|
||||
return roleService.listByModuleCode(ModuleCode.GAO);
|
||||
return authorizationScopeService.listGrantableRole(userLoginService.getRequireLoginUserId(), ModuleCode.GAO);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-4
@@ -1,9 +1,7 @@
|
||||
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.modules.gao.bean.GaoPermissionCode;
|
||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoStoreBusinessDay;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreBusinessDayService;
|
||||
import com.imyeyu.spring.annotation.AOPLog;
|
||||
@@ -26,7 +24,6 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/gao/store/business/day")
|
||||
@RequireGaoRole(GaoRoleCode.GLOBAL_MANAGER)
|
||||
public class GaoStoreBusinessDayController {
|
||||
|
||||
private final GaoStoreBusinessDayService service;
|
||||
@@ -57,7 +54,7 @@ public class GaoStoreBusinessDayController {
|
||||
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireGaoPermission(GaoPermissionCode.STORE_CREATE)
|
||||
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
||||
@PostMapping("/create")
|
||||
public String create(@RequestBody GaoStoreBusinessDay businessDay) {
|
||||
service.create(businessDay);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.imyeyu.api.modules.gao.controller;
|
||||
|
||||
import com.imyeyu.api.bean.RoleMatchMode;
|
||||
import com.imyeyu.api.bean.ModuleCode;
|
||||
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.GaoRoleCode;
|
||||
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;
|
||||
@@ -34,11 +34,11 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/gao/store")
|
||||
@RequireGaoRole(GaoRoleCode.GLOBAL_MANAGER)
|
||||
public class GaoStoreController {
|
||||
|
||||
private final GaoStoreService service;
|
||||
private final UserLoginService userLoginService;
|
||||
private final PermissionChecker permissionChecker;
|
||||
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@@ -70,7 +70,19 @@ public class GaoStoreController {
|
||||
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
||||
@PostMapping("/update")
|
||||
public void update(@RequestBody GaoStore store) {
|
||||
service.update(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
|
||||
@@ -104,7 +116,6 @@ public class GaoStoreController {
|
||||
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireGaoRole(value = {GaoRoleCode.GLOBAL_MANAGER, GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
|
||||
@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());
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,18 @@ 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.RequireGaoRole;
|
||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||
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.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.User;
|
||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
||||
@@ -18,12 +24,15 @@ 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.CaptchaValid;
|
||||
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 jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -33,13 +42,13 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/// GAO 用户接口
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-07-30 14:15
|
||||
@RestController
|
||||
@RequireGaoRole(GaoRoleCode.STORE_MANAGER)
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/gao/user")
|
||||
public class GaoUserController {
|
||||
@@ -48,11 +57,38 @@ public class GaoUserController {
|
||||
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
|
||||
@RequestRateLimit
|
||||
@RequireGaoPermission(GaoPermissionCode.USER_READ)
|
||||
@@ -118,7 +154,6 @@ public class GaoUserController {
|
||||
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireGaoRole(GaoRoleCode.GLOBAL_MANAGER)
|
||||
@RequireGaoPermission(GaoPermissionCode.USER_UPDATE)
|
||||
@PostMapping("/transfer/store")
|
||||
@JsonView(ResponseView.Public.class)
|
||||
@@ -140,6 +175,7 @@ public class GaoUserController {
|
||||
@RequireGaoPermission(GaoPermissionCode.USER_READ)
|
||||
@PostMapping("/role/list")
|
||||
public List<Role> roleList() {
|
||||
// TODO 此接口获取本模块所有角色,需要限制角色
|
||||
return roleService.listByModuleCode(ModuleCode.GAO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,26 @@ public class GaoEvent extends UUIDEntity {
|
||||
DELETED
|
||||
}
|
||||
|
||||
/// 事件数值类型
|
||||
public enum ValueType {
|
||||
|
||||
/// 不携带数值
|
||||
NONE,
|
||||
|
||||
/// 携带整数数值
|
||||
NUMBER
|
||||
}
|
||||
|
||||
/// 事件数值单位
|
||||
public enum ValueUnit {
|
||||
|
||||
/// 金额分
|
||||
CENT,
|
||||
|
||||
/// 次数
|
||||
COUNT
|
||||
}
|
||||
|
||||
/// 登记限制类型
|
||||
///
|
||||
/// @author 夜雨
|
||||
@@ -70,6 +90,9 @@ public class GaoEvent extends UUIDEntity {
|
||||
final Long min;
|
||||
}
|
||||
|
||||
/// 统计图表颜色
|
||||
private String color;
|
||||
|
||||
/// 登记事件名称
|
||||
private String name;
|
||||
|
||||
@@ -79,8 +102,14 @@ public class GaoEvent extends UUIDEntity {
|
||||
/// 说明
|
||||
private String description;
|
||||
|
||||
/// 统计图表颜色
|
||||
private String color;
|
||||
/// 数值类型
|
||||
private ValueType valueType;
|
||||
|
||||
/// 数值单位
|
||||
private ValueUnit valueUnit;
|
||||
|
||||
/// true 为登记时必须提交 numberValue
|
||||
private Boolean requireValue;
|
||||
|
||||
/// 状态
|
||||
private Status status;
|
||||
|
||||
@@ -40,6 +40,15 @@ public class GaoEventRecord extends UUIDEntity {
|
||||
/// 操作管理员用户 ID
|
||||
private String operatorUserId;
|
||||
|
||||
/// 本次登记提交的积分值
|
||||
private Long pointValue;
|
||||
|
||||
/// 本次登记通过积分规则获得的积分总和
|
||||
private Long earnedPointValue;
|
||||
|
||||
/// 本次登记提交的整数业务数值
|
||||
private Long numberValue;
|
||||
|
||||
/// 备注
|
||||
private String remark;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -48,6 +48,9 @@ public class GaoStore extends UUIDEntity {
|
||||
/// 备注
|
||||
private String remark;
|
||||
|
||||
/// true 为启用自动计算营业日休息日
|
||||
private Boolean autoClosedDay;
|
||||
|
||||
/// 排序值
|
||||
private Integer sort;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public class GaoStoreBusinessDay extends UUIDEntity {
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-06
|
||||
public enum OpenStatus {
|
||||
public enum Status {
|
||||
|
||||
/// 营业
|
||||
OPEN,
|
||||
@@ -34,7 +34,7 @@ public class GaoStoreBusinessDay extends UUIDEntity {
|
||||
private Integer dateValue;
|
||||
|
||||
/// 营业状态
|
||||
private OpenStatus openStatus;
|
||||
private Status status;
|
||||
|
||||
/// 营业日递增序号,仅营业日有值
|
||||
private Long businessDayNo;
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.imyeyu.api.modules.gao.mapper;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||
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 org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -35,4 +36,16 @@ public interface GaoCustomerMapper extends BaseMapper<GaoCustomer, String> {
|
||||
///
|
||||
/// @return 性别统计列表
|
||||
List<GaoCustomerGenderStatView> stateGender(@Param("storeId") String storeId);
|
||||
|
||||
/// 查询客户总数
|
||||
///
|
||||
/// @param page 查询条件
|
||||
/// @return 客户总数
|
||||
long countByQuery(GaoCustomerPage page);
|
||||
|
||||
/// 分页查询客户
|
||||
///
|
||||
/// @param page 查询条件
|
||||
/// @return 客户列表
|
||||
List<GaoCustomer> selectByQuery(GaoCustomerPage page);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
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;
|
||||
|
||||
@@ -17,6 +21,28 @@ 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
|
||||
@@ -38,6 +64,12 @@ public interface GaoEventRecordMapper extends BaseMapper<GaoEventRecord, String>
|
||||
/// @return 登记事件记录列表
|
||||
List<GaoEventRecord> selectByRange(GaoEventRecordPage page);
|
||||
|
||||
/// 按登记记录列表条件汇总数值
|
||||
///
|
||||
/// @param page 登记记录范围查询请求
|
||||
/// @return 登记数值合计
|
||||
Long sumNumberValueByRange(GaoEventRecordPage page);
|
||||
|
||||
/// 统计客户登记排行榜总数
|
||||
///
|
||||
/// @param page 排行榜分页请求
|
||||
@@ -49,4 +81,28 @@ public interface GaoEventRecordMapper extends BaseMapper<GaoEventRecord, String>
|
||||
/// @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,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);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ 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;
|
||||
|
||||
@@ -27,7 +28,7 @@ public interface GaoStoreBusinessDayMapper extends BaseMapper<GaoStoreBusinessDa
|
||||
/// @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 `open_status` = 'OPEN' AND `deleted_at` IS NULL")
|
||||
@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);
|
||||
|
||||
/// 查询指定日期及之后的营业日
|
||||
@@ -35,9 +36,16 @@ public interface GaoStoreBusinessDayMapper extends BaseMapper<GaoStoreBusinessDa
|
||||
/// @param storeId 门店 ID
|
||||
/// @param beginDateValue 开始日期值,格式为 yyyyMMdd
|
||||
/// @return 营业日列表
|
||||
@Select("SELECT * FROM `gao_store_business_day` WHERE `store_id` = #{storeId} AND `date_value` >= #{beginDateValue} AND `open_status` = 'OPEN' AND `deleted_at` IS NULL ORDER BY `date_value` ASC")
|
||||
@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
|
||||
|
||||
@@ -3,6 +3,7 @@ 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;
|
||||
@@ -16,6 +17,12 @@ 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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -3,8 +3,10 @@ package com.imyeyu.api.modules.gao.service;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||
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.api.modules.gao.vo.GaoCustomerTrendStateReq;
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import com.imyeyu.spring.service.BaseService;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -19,6 +21,12 @@ import java.util.stream.Collectors;
|
||||
/// @since 2026-07-27 14:12
|
||||
public interface GaoCustomerService extends BaseService<GaoCustomer, String> {
|
||||
|
||||
/// 按查询条件分页查询客户
|
||||
///
|
||||
/// @param page 查询条件
|
||||
/// @return 客户分页
|
||||
PageResult<GaoCustomer> pageByQuery(GaoCustomerPage page);
|
||||
|
||||
void updateWithAttachment(GaoCustomer customer);
|
||||
|
||||
/// 按编码查询客户
|
||||
|
||||
@@ -32,6 +32,12 @@ public interface GaoEventRecordService extends BaseService<GaoEventRecord, Strin
|
||||
/// @return 登记事件记录列表
|
||||
PageResult<GaoEventRecord> pageByRange(GaoEventRecordPage req);
|
||||
|
||||
/// 按登记记录列表条件汇总数值
|
||||
///
|
||||
/// @param req 登记记录范围查询请求
|
||||
/// @return 登记数值合计
|
||||
Long sumNumberValueByRange(GaoEventRecordPage req);
|
||||
|
||||
/// 按时间范围查询客户登记排行榜
|
||||
///
|
||||
/// @param page 范围查询请求,不传时间为全部时间
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -23,6 +23,12 @@ public interface GaoStoreBusinessDayService extends BaseService<GaoStoreBusiness
|
||||
/// @param beginDateValue 开始日期值,格式为 yyyyMMdd
|
||||
void rebuildBusinessDayNo(String storeId, Integer beginDateValue);
|
||||
|
||||
/// 自动补记门店休息日
|
||||
///
|
||||
/// @param storeId 门店 ID
|
||||
/// @param dateValue 日期值,格式为 yyyyMMdd
|
||||
void autoCloseBusinessDay(String storeId, Integer dateValue);
|
||||
|
||||
/// 查询日期范围内的营业日
|
||||
///
|
||||
/// @param storeId 门店 ID
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -22,6 +22,8 @@ public interface GaoStoreService extends BaseService<GaoStore, String> {
|
||||
|
||||
String getBelongIdByRequiredLoginUserId();
|
||||
|
||||
List<GaoStore> listByAutoClosedDay();
|
||||
|
||||
/// 导出门店列表
|
||||
///
|
||||
/// @param page 分页查询条件
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
+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");
|
||||
}
|
||||
}
|
||||
+14
@@ -10,6 +10,7 @@ import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||
import com.imyeyu.api.modules.gao.util.CustomerXSSFBuilder;
|
||||
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.api.modules.gao.vo.GaoCustomerTrendStateReq;
|
||||
import com.imyeyu.api.modules.system.entity.Logger;
|
||||
import com.imyeyu.api.modules.system.service.LoggerService;
|
||||
@@ -18,6 +19,7 @@ import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
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;
|
||||
@@ -65,6 +67,16 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<GaoCustomer> pageByQuery(GaoCustomerPage page) {
|
||||
TimiException.required(page, "not found page");
|
||||
PageResult<GaoCustomer> result = new PageResult<>();
|
||||
result.setTotal(mapper.countByQuery(page));
|
||||
result.setList(mapper.selectByQuery(page));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void create(GaoCustomer customer) {
|
||||
TimiException.required(customer.getName(), "not found customer.name");
|
||||
@@ -118,6 +130,7 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void update(GaoCustomer customer) {
|
||||
TimiException.required(customer, "not found customer");
|
||||
@@ -196,6 +209,7 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void updateWithAttachment(GaoCustomer customer) {
|
||||
update(customer);
|
||||
|
||||
+94
-15
@@ -10,6 +10,7 @@ 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;
|
||||
@@ -63,6 +64,7 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
|
||||
private final AttachmentService attachmentService;
|
||||
private final GaoCustomerService customerService;
|
||||
private final GaoStoreBusinessDayService businessDayService;
|
||||
private final GaoPointTriggerService pointTriggerService;
|
||||
|
||||
private final GaoEventRecordMapper mapper;
|
||||
|
||||
@@ -85,7 +87,9 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
|
||||
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);
|
||||
@@ -116,6 +120,9 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
|
||||
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) {
|
||||
@@ -131,6 +138,7 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
|
||||
attachmentService.update(clone);
|
||||
}
|
||||
}
|
||||
pointTriggerService.onEventRecordCreated(dbRecord);
|
||||
logIdList.add(dbRecord.getId());
|
||||
}
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
@@ -149,6 +157,14 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
@@ -158,24 +174,17 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_EVENT_RECORD_UPDATE");
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(record));
|
||||
TimiException.required(record.getCustomerId(), "not found record.customerId");
|
||||
TimiException.required(record.getEventId(), "not found record.eventId");
|
||||
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);
|
||||
|
||||
record.setRegisteredAt(TimiJava.defaultIfNull(record.getRegisteredAt(), Time.now()));
|
||||
|
||||
GaoEvent event = eventService.get(record.getEventId());
|
||||
GaoEvent event = eventService.get(dbRecord.getEventId());
|
||||
TimiException.required(event, "not found event");
|
||||
TimiException.required(event.getStoreId(), "not found event.storeId");
|
||||
checkEventPermission(event);
|
||||
checkEventCreatable(record.getCustomerId(), event, record.getRegisteredAt());
|
||||
GaoCustomer customer = customerService.get(record.getCustomerId());
|
||||
TimiException.required(customer, "not found customer");
|
||||
TimiException.requiredTrue(event.getStoreId().equals(customer.getStoreId()), "客户和登记事件不属于同一门店");
|
||||
int registeredDateValue = dateValue(record.getRegisteredAt());
|
||||
record.setStoreId(event.getStoreId());
|
||||
record.setRegisteredDateValue(registeredDateValue);
|
||||
record.setBusinessDayNo(businessDayService.resolveOpenBusinessDay(event.getStoreId(), registeredDateValue).getBusinessDayNo());
|
||||
|
||||
super.update(record);
|
||||
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());
|
||||
@@ -193,6 +202,33 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
@@ -230,6 +266,12 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
|
||||
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");
|
||||
@@ -240,12 +282,29 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
|
||||
@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(), "登记事件未配置可登记角色");
|
||||
@@ -303,6 +362,26 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
+42
-1
@@ -5,6 +5,7 @@ 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;
|
||||
@@ -45,6 +46,7 @@ public class GaoEventServiceImplement extends AbstractEntityService<GaoEvent, St
|
||||
private final LoggerService loggerService;
|
||||
|
||||
private final GaoEventMapper mapper;
|
||||
private final GaoEventRecordMapper eventRecordMapper;
|
||||
private final GaoEventRoleRelationMapper roleRelationMapper;
|
||||
|
||||
@Override
|
||||
@@ -64,6 +66,8 @@ public class GaoEventServiceImplement extends AbstractEntityService<GaoEvent, St
|
||||
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));
|
||||
@@ -94,17 +98,36 @@ public class GaoEventServiceImplement extends AbstractEntityService<GaoEvent, St
|
||||
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());
|
||||
@@ -190,14 +213,32 @@ public class GaoEventServiceImplement extends AbstractEntityService<GaoEvent, St
|
||||
}
|
||||
|
||||
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()));
|
||||
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());
|
||||
|
||||
+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) {
|
||||
}
|
||||
}
|
||||
+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()));
|
||||
}
|
||||
}
|
||||
+30
-11
@@ -37,7 +37,7 @@ public class GaoStoreBusinessDayServiceImplement extends AbstractEntityService<G
|
||||
public void create(GaoStoreBusinessDay businessDay) {
|
||||
prepareBusinessDay(businessDay);
|
||||
super.create(businessDay);
|
||||
if (businessDay.getOpenStatus() == GaoStoreBusinessDay.OpenStatus.OPEN) {
|
||||
if (businessDay.getStatus() == GaoStoreBusinessDay.Status.OPEN) {
|
||||
rebuildBusinessDayNo(businessDay.getStoreId(), businessDay.getDateValue());
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class GaoStoreBusinessDayServiceImplement extends AbstractEntityService<G
|
||||
TimiException.required(dbBusinessDay, "not found dbBusinessDay");
|
||||
TimiException.requiredTrue(dbBusinessDay.getStoreId().equals(businessDay.getStoreId()), "businessDay.storeId invalid");
|
||||
TimiException.requiredTrue(dbBusinessDay.getDateValue().equals(businessDay.getDateValue()), "businessDay.dateValue invalid");
|
||||
if (businessDay.getOpenStatus() == GaoStoreBusinessDay.OpenStatus.CLOSED) {
|
||||
if (businessDay.getStatus() == GaoStoreBusinessDay.Status.CLOSED) {
|
||||
checkNoRecord(dbBusinessDay);
|
||||
}
|
||||
prepareBusinessDay(businessDay);
|
||||
@@ -64,7 +64,7 @@ public class GaoStoreBusinessDayServiceImplement extends AbstractEntityService<G
|
||||
public void delete(String id) {
|
||||
GaoStoreBusinessDay businessDay = get(id);
|
||||
TimiException.required(businessDay, "not found businessDay");
|
||||
if (businessDay.getOpenStatus() == GaoStoreBusinessDay.OpenStatus.OPEN) {
|
||||
if (businessDay.getStatus() == GaoStoreBusinessDay.Status.OPEN) {
|
||||
checkNoRecord(businessDay);
|
||||
}
|
||||
super.delete(id);
|
||||
@@ -78,14 +78,14 @@ public class GaoStoreBusinessDayServiceImplement extends AbstractEntityService<G
|
||||
TimiException.required(dateValue, "not found dateValue");
|
||||
GaoStoreBusinessDay businessDay = mapper.selectByStoreIdAndDateValue(storeId, dateValue);
|
||||
if (businessDay != null) {
|
||||
TimiException.requiredTrue(businessDay.getOpenStatus() == GaoStoreBusinessDay.OpenStatus.OPEN, "门店当日休息,不能登记");
|
||||
TimiException.requiredTrue(businessDay.getStatus() == GaoStoreBusinessDay.Status.OPEN, "门店当日休息,不能登记");
|
||||
TimiException.required(businessDay.getBusinessDayNo(), "not found businessDay.businessDayNo");
|
||||
return businessDay;
|
||||
}
|
||||
businessDay = new GaoStoreBusinessDay();
|
||||
businessDay.setStoreId(storeId);
|
||||
businessDay.setDateValue(dateValue);
|
||||
businessDay.setOpenStatus(GaoStoreBusinessDay.OpenStatus.OPEN);
|
||||
businessDay.setStatus(GaoStoreBusinessDay.Status.OPEN);
|
||||
super.create(businessDay);
|
||||
rebuildBusinessDayNo(storeId, dateValue);
|
||||
return mapper.selectByStoreIdAndDateValue(storeId, dateValue);
|
||||
@@ -97,16 +97,35 @@ public class GaoStoreBusinessDayServiceImplement extends AbstractEntityService<G
|
||||
TimiException.required(storeId, "not found storeId");
|
||||
TimiException.required(beginDateValue, "not found beginDateValue");
|
||||
long businessDayNo = TimiJava.defaultIfNull(mapper.selectLastBusinessDayNoBefore(storeId, beginDateValue), 0L);
|
||||
mapper.clearBusinessDayNoFromDate(storeId, beginDateValue);
|
||||
for (GaoStoreBusinessDay businessDay : mapper.selectOpenListFromDate(storeId, beginDateValue)) {
|
||||
businessDayNo++;
|
||||
if (!Long.valueOf(businessDayNo).equals(businessDay.getBusinessDayNo())) {
|
||||
businessDay.setBusinessDayNo(businessDayNo);
|
||||
mapper.update(businessDay);
|
||||
}
|
||||
businessDay.setBusinessDayNo(businessDayNo);
|
||||
mapper.update(businessDay);
|
||||
eventRecordMapper.updateBusinessDayNoByStoreIdAndRegisteredDateValue(storeId, businessDay.getDateValue(), businessDayNo);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void autoCloseBusinessDay(String storeId, Integer dateValue) {
|
||||
TimiException.required(storeId, "not found storeId");
|
||||
TimiException.required(dateValue, "not found dateValue");
|
||||
if (mapper.selectByStoreIdAndDateValue(storeId, dateValue) != null) {
|
||||
return;
|
||||
}
|
||||
Long count = eventRecordMapper.countByStoreIdAndRegisteredDateValue(storeId, dateValue);
|
||||
if (0 < TimiJava.defaultIfNull(count, 0L)) {
|
||||
return;
|
||||
}
|
||||
GaoStoreBusinessDay businessDay = new GaoStoreBusinessDay();
|
||||
businessDay.setStoreId(storeId);
|
||||
businessDay.setDateValue(dateValue);
|
||||
businessDay.setStatus(GaoStoreBusinessDay.Status.CLOSED);
|
||||
businessDay.setReason("系统自动判定休息");
|
||||
super.create(businessDay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GaoStoreBusinessDay> listByDateRange(String storeId, Integer beginDateValue, Integer endDateValue) {
|
||||
TimiException.required(storeId, "not found storeId");
|
||||
@@ -120,8 +139,8 @@ public class GaoStoreBusinessDayServiceImplement extends AbstractEntityService<G
|
||||
TimiException.required(businessDay, "not found businessDay");
|
||||
TimiException.required(businessDay.getStoreId(), "not found businessDay.storeId");
|
||||
TimiException.required(businessDay.getDateValue(), "not found businessDay.dateValue");
|
||||
businessDay.setOpenStatus(TimiJava.defaultIfNull(businessDay.getOpenStatus(), GaoStoreBusinessDay.OpenStatus.OPEN));
|
||||
if (businessDay.getOpenStatus() == GaoStoreBusinessDay.OpenStatus.CLOSED) {
|
||||
businessDay.setStatus(TimiJava.defaultIfNull(businessDay.getStatus(), GaoStoreBusinessDay.Status.OPEN));
|
||||
if (businessDay.getStatus() == GaoStoreBusinessDay.Status.CLOSED) {
|
||||
businessDay.setBusinessDayNo(null);
|
||||
return;
|
||||
}
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.imyeyu.api.modules.gao.service.implement;
|
||||
|
||||
import com.imyeyu.api.modules.gao.mapper.GaoEventRecordMapper;
|
||||
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||
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.GaoCustomerTrendStateReq;
|
||||
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.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 GaoStoreChartServiceImplement implements GaoStoreChartService {
|
||||
|
||||
private final GaoCustomerService customerService;
|
||||
private final GaoEventRecordMapper eventRecordMapper;
|
||||
|
||||
@Override
|
||||
public List<GaoCustomerDailyStateView> customerDailyTrend(GaoStoreChartReq req) {
|
||||
checkRangeReq(req);
|
||||
GaoCustomerTrendStateReq statReq = new GaoCustomerTrendStateReq();
|
||||
statReq.setStoreId(req.getStoreId());
|
||||
statReq.setBeginCreatedAt(req.getBeginAt());
|
||||
statReq.setEndCreatedAt(req.getEndAt());
|
||||
return customerService.stateDailyTrend(statReq);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GaoCustomerGenderStatView> customerGender(String storeId) {
|
||||
TimiException.required(storeId, "not found storeId");
|
||||
return customerService.stateGender(storeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GaoEventRecordDailyStatView> eventRecordDailyStat(GaoStoreChartReq req) {
|
||||
checkRangeReq(req);
|
||||
return eventRecordMapper.stateDailyByRange(req);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GaoEventRecordCalendarView> eventRecordCalendar(GaoStoreChartReq req) {
|
||||
checkRangeReq(req);
|
||||
return eventRecordMapper.selectCalendarByRange(req);
|
||||
}
|
||||
|
||||
private void checkRangeReq(GaoStoreChartReq req) {
|
||||
TimiException.required(req, "not found req");
|
||||
TimiException.required(req.getStoreId(), "not found req.storeId");
|
||||
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");
|
||||
}
|
||||
}
|
||||
+40
-24
@@ -50,6 +50,7 @@ public class GaoStoreServiceImplement extends AbstractEntityService<GaoStore, St
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void create(GaoStore store) {
|
||||
TimiException.required(store, "not found store");
|
||||
@@ -61,6 +62,7 @@ public class GaoStoreServiceImplement extends AbstractEntityService<GaoStore, St
|
||||
logger.setContent(jackson.writeValueAsString(store));
|
||||
checkUnique(store);
|
||||
store.setStatus(TimiJava.defaultIfNull(store.getStatus(), GaoStore.Status.ACTIVE));
|
||||
store.setAutoClosedDay(TimiJava.defaultIfNull(store.getAutoClosedDay(), false));
|
||||
store.setSort(TimiJava.defaultIfNull(store.getSort(), 0));
|
||||
super.create(store);
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
@@ -72,13 +74,14 @@ public class GaoStoreServiceImplement extends AbstractEntityService<GaoStore, St
|
||||
} catch (Exception e) {
|
||||
logger.setLevel(Logger.Level.ERROR);
|
||||
logger.setException(TimiJava.serializeThrowable(e));
|
||||
log.error("新增 GAO 门店失败", e);
|
||||
throw new TimiException(TimiCode.ERROR, "新增 GAO 门店失败", e);
|
||||
log.error("create store error", e);
|
||||
throw new TimiException(TimiCode.ERROR, "新增门店失败", e);
|
||||
} finally {
|
||||
loggerService.create(logger);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void update(GaoStore store) {
|
||||
TimiException.required(store, "not found store");
|
||||
@@ -90,15 +93,7 @@ public class GaoStoreServiceImplement extends AbstractEntityService<GaoStore, St
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(store));
|
||||
checkUnique(store);
|
||||
GaoStore dbStore = get(store.getId());
|
||||
dbStore.setCode(store.getCode());
|
||||
dbStore.setName(store.getName());
|
||||
dbStore.setStatus(store.getStatus());
|
||||
dbStore.setTelephone(store.getTelephone());
|
||||
dbStore.setAddress(store.getAddress());
|
||||
dbStore.setRemark(store.getRemark());
|
||||
super.update(dbStore);
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
super.update(store);
|
||||
logger.setResult(store.getId());
|
||||
} catch (TimiException e) {
|
||||
logger.setLevel(Logger.Level.WARN);
|
||||
@@ -107,13 +102,14 @@ public class GaoStoreServiceImplement extends AbstractEntityService<GaoStore, St
|
||||
} catch (Exception e) {
|
||||
logger.setLevel(Logger.Level.ERROR);
|
||||
logger.setException(TimiJava.serializeThrowable(e));
|
||||
log.error("修改 GAO 门店失败", e);
|
||||
throw new TimiException(TimiCode.ERROR, "修改 GAO 门店失败", e);
|
||||
log.error("update store error", e);
|
||||
throw new TimiException(TimiCode.ERROR, "修改门店失败", e);
|
||||
} finally {
|
||||
loggerService.create(logger);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void delete(String id) {
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_STORE_DELETE");
|
||||
@@ -132,8 +128,8 @@ public class GaoStoreServiceImplement extends AbstractEntityService<GaoStore, St
|
||||
} catch (Exception e) {
|
||||
logger.setLevel(Logger.Level.ERROR);
|
||||
logger.setException(TimiJava.serializeThrowable(e));
|
||||
log.error("删除 GAO 门店失败", e);
|
||||
throw new TimiException(TimiCode.ERROR, "删除 GAO 门店失败", e);
|
||||
log.error("delete store error", e);
|
||||
throw new TimiException(TimiCode.ERROR, "删除门店失败", e);
|
||||
} finally {
|
||||
loggerService.create(logger);
|
||||
}
|
||||
@@ -150,6 +146,11 @@ public class GaoStoreServiceImplement extends AbstractEntityService<GaoStore, St
|
||||
return getByUserId(userLoginService.getRequireLoginUserId()).getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GaoStore> listByAutoClosedDay() {
|
||||
return mapper.selectAllByAutoClosedDay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] export(Page<GaoStore> page) throws IOException {
|
||||
page.setIndex(0);
|
||||
@@ -164,16 +165,31 @@ public class GaoStoreServiceImplement extends AbstractEntityService<GaoStore, St
|
||||
if (TimiJava.isEmpty(idList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<GaoStore> storeList = mapper.selectByIdList(new LinkedHashSet<>(idList));
|
||||
Map<String, GaoStore> storeMap = storeList.stream().collect(Collectors.toMap(GaoStore::getId, Function.identity()));
|
||||
for (int i = 0; i < idList.size(); i++) {
|
||||
GaoStore store = storeMap.get(idList.get(i));
|
||||
if (store == null) {
|
||||
continue;
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_STORE_SORT");
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(idList));
|
||||
List<GaoStore> storeList = mapper.selectByIdList(new LinkedHashSet<>(idList));
|
||||
Map<String, GaoStore> storeMap = storeList.stream().collect(Collectors.toMap(GaoStore::getId, Function.identity()));
|
||||
for (int i = 0; i < idList.size(); i++) {
|
||||
GaoStore store = storeMap.get(idList.get(i));
|
||||
if (store == null) {
|
||||
continue;
|
||||
}
|
||||
store.setSort(i);
|
||||
mapper.update(store);
|
||||
}
|
||||
store.setSort(i);
|
||||
mapper.update(store);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+349
@@ -0,0 +1,349 @@
|
||||
package com.imyeyu.api.modules.gao.service.implement;
|
||||
|
||||
import com.imyeyu.api.bean.CoreRoleCode;
|
||||
import com.imyeyu.api.bean.ModuleCode;
|
||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||
import com.imyeyu.api.modules.gao.bean.GaoUserInviteCache;
|
||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoStore;
|
||||
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.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;
|
||||
import com.imyeyu.api.modules.system.entity.Logger;
|
||||
import com.imyeyu.api.modules.system.service.LoggerService;
|
||||
import com.imyeyu.api.modules.user.entity.Role;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import com.imyeyu.api.modules.user.entity.UserRole;
|
||||
import com.imyeyu.api.modules.user.service.AuthorizationScopeService;
|
||||
import com.imyeyu.api.modules.user.service.PermissionChecker;
|
||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
||||
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.bean.AuthOwnerType;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.spring.util.Redis;
|
||||
import com.imyeyu.utils.Digest;
|
||||
import com.imyeyu.utils.Time;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/// GAO 用户邀请注册服务实现
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-13
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class GaoUserInviteServiceImplement implements GaoUserInviteService {
|
||||
|
||||
private static final String INVITE_KEY_PREFIX = "GAO:USER:INVITE:";
|
||||
private static final String CONSUME_LOCK_KEY_PREFIX = "GAO:USER:INVITE:CONSUME:";
|
||||
private static final String CREATE_CODE_LOCK_KEY = "GAO:USER:INVITE:CREATE:LOCK";
|
||||
private static final String CODE_CHARACTERS = "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||
private static final int CODE_LENGTH = 10;
|
||||
private static final long INVITE_TTL = Time.D * 7;
|
||||
private static final long CODE_LOCK_TTL = Time.S * 5;
|
||||
private static final long CONSUME_LOCK_TTL = Time.M * 2;
|
||||
private static final long REGISTER_RATE_LIMIT_TTL = Time.M * 10;
|
||||
private static final int CODE_RATE_LIMIT = 30;
|
||||
private static final int REGISTER_VALUE_RATE_LIMIT = 10;
|
||||
|
||||
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
|
||||
|
||||
private final GaoStoreService gaoStoreService;
|
||||
private final GaoUserService gaoUserService;
|
||||
private final UserLoginService userLoginService;
|
||||
private final UserRoleService userRoleService;
|
||||
private final UserService userService;
|
||||
private final RoleService roleService;
|
||||
private final PermissionChecker permissionChecker;
|
||||
private final RoleChecker roleChecker;
|
||||
private final AuthorizationScopeService authorizationScopeService;
|
||||
private final LoggerService loggerService;
|
||||
|
||||
@Qualifier("redisGaoUserInvite")
|
||||
private final Redis<String, GaoUserInviteCache> redisInvite;
|
||||
|
||||
@Qualifier("redisLocker")
|
||||
private final Redis<String, Integer> redisLocker;
|
||||
|
||||
@Qualifier("redisRateLimit")
|
||||
private final Redis<String, Integer> redisRateLimit;
|
||||
|
||||
@Override
|
||||
public GaoUserInviteCreateResponse create(GaoUserInviteCreateRequest req) {
|
||||
Logger logger = new Logger(Logger.Module.GAO, Logger.Level.INFO, "GAO_USER_INVITE_CREATE");
|
||||
try {
|
||||
TimiException.required(req, "not found invite request");
|
||||
TimiException.required(req.getRoleId(), "not found roleId");
|
||||
|
||||
String inviterUserId = userLoginService.getRequireLoginUserId();
|
||||
logger.setUserId(inviterUserId);
|
||||
permissionChecker.checkAny(ModuleCode.GAO, GaoPermissionCode.USER_CREATE.getValue());
|
||||
Role requestedRole = roleService.get(req.getRoleId());
|
||||
boolean adminInviteGlobalManager = roleChecker.hasAny(ModuleCode.CORE, CoreRoleCode.ADMIN.name())
|
||||
&& isGlobalManagerRole(requestedRole);
|
||||
boolean globalManager = authorizationScopeService.isSystemAdmin(inviterUserId)
|
||||
|| roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name());
|
||||
boolean storeManager = !globalManager;
|
||||
GaoStore loginStore = storeManager ? gaoStoreService.getByUserId(inviterUserId) : null;
|
||||
String storeId = adminInviteGlobalManager ? null : storeManager ? loginStore == null ? null : loginStore.getId() : req.getStoreId();
|
||||
if (!adminInviteGlobalManager) {
|
||||
TimiException.required(storeId, "not found storeId");
|
||||
checkStoreScope(inviterUserId, storeId);
|
||||
}
|
||||
if (storeId != null) {
|
||||
requireActiveStore(storeId);
|
||||
}
|
||||
Role role = requireInvitableRole(inviterUserId, req.getRoleId(), storeId);
|
||||
long createdAt = Time.now();
|
||||
long expireAt = createdAt + INVITE_TTL;
|
||||
|
||||
GaoUserInviteCache cache = new GaoUserInviteCache();
|
||||
cache.setInviterUserId(inviterUserId);
|
||||
cache.setStoreId(storeId);
|
||||
cache.setRoleId(role.getId());
|
||||
cache.setScene(adminInviteGlobalManager ? "CORE_ADMIN" : storeManager ? "STORE_MANAGER" : "STORE_MANAGEMENT");
|
||||
cache.setCreatedAt(createdAt);
|
||||
cache.setExpireAt(expireAt);
|
||||
String code = saveInvite(cache);
|
||||
|
||||
logger.setContent("storeId=%s;roleId=%s;scene=%s;createdAt=%d;expireAt=%d".formatted(
|
||||
storeId, role.getId(), cache.getScene(), createdAt, expireAt));
|
||||
logger.setResult("created");
|
||||
return new GaoUserInviteCreateResponse(code, expireAt);
|
||||
} 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, "邀请创建失败", e);
|
||||
} finally {
|
||||
loggerService.create(logger);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GaoUserInviteValidateResponse validate(String code) {
|
||||
TimiException.required(code, "not found code");
|
||||
checkCodeRateLimit(code);
|
||||
GaoUserInviteCache cache = requireValidInvite(code);
|
||||
validateInviteTarget(cache);
|
||||
return new GaoUserInviteValidateResponse(true, cache.getExpireAt());
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public String register(GaoUserInviteRegisterData data) {
|
||||
TimiException.required(data, "not found register data");
|
||||
String code = data.getCode();
|
||||
TimiException.required(code, "not found code");
|
||||
checkCodeRateLimit(code);
|
||||
checkRegisterValueRateLimit("NAME", data.getName());
|
||||
checkRegisterValueRateLimit("PHONE", data.getPhoneNo());
|
||||
String lockKey = getConsumeLockKey(code);
|
||||
TimiException.requiredTrue(redisLocker.lock(lockKey, 1, CONSUME_LOCK_TTL), "邀请码无效或正在使用");
|
||||
|
||||
GaoUserInviteCache cache = null;
|
||||
Logger logger = new Logger(Logger.Module.GAO, Logger.Level.WARN, "GAO_USER_INVITE_REGISTER");
|
||||
try {
|
||||
cache = requireValidInvite(code);
|
||||
logger.setContent(buildLogContent(cache));
|
||||
validateInviteTarget(cache);
|
||||
TimiException.requiredNull(userService.getByName(data.getName()), "existed user name");
|
||||
TimiException.requiredNull(userService.getByPhoneNo(data.getPhoneNo()), "existed phone number");
|
||||
if (!redisInvite.destroy(getInviteKey(code))) {
|
||||
throw invalidInvite();
|
||||
}
|
||||
|
||||
User user = new User();
|
||||
user.setName(data.getName());
|
||||
user.setPhoneNo(data.getPhoneNo());
|
||||
user.setPassword(data.getPassword());
|
||||
|
||||
if (cache.getStoreId() == null) {
|
||||
// TODO 用更好的方式
|
||||
userService.create(user);
|
||||
userService.verifyPhoneNo(user.getId());
|
||||
} else {
|
||||
GaoUser gaoUser = new GaoUser();
|
||||
gaoUser.setStoreId(cache.getStoreId());
|
||||
gaoUser.setUser(user);
|
||||
gaoUserService.create(gaoUser);
|
||||
}
|
||||
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setId(UUID.randomUUID().toString());
|
||||
userRole.setUserId(user.getId());
|
||||
userRole.setRoleId(cache.getRoleId());
|
||||
userRole.setCreatedAt(Time.now());
|
||||
userRoleService.create(userRole);
|
||||
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
logger.setUserId(user.getId());
|
||||
logger.setResult(user.getId());
|
||||
return user.getId();
|
||||
} catch (TimiException e) {
|
||||
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, "邀请注册失败", e);
|
||||
} finally {
|
||||
loggerService.create(logger);
|
||||
redisLocker.releaseLock(lockKey);
|
||||
}
|
||||
}
|
||||
|
||||
private String saveInvite(GaoUserInviteCache cache) {
|
||||
TimiException.requiredTrue(redisLocker.lock(CREATE_CODE_LOCK_KEY, 1, CODE_LOCK_TTL), "服务繁忙,请稍后重试");
|
||||
try {
|
||||
for (int attempt = 0; attempt < 3; attempt++) {
|
||||
String code = randomCode();
|
||||
if (!redisInvite.has(getInviteKey(code))) {
|
||||
redisInvite.set(getInviteKey(code), cache, INVITE_TTL);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
throw new TimiException(TimiCode.ERROR_SERVICE_BUSY, "邀请码生成失败");
|
||||
} finally {
|
||||
redisLocker.releaseLock(CREATE_CODE_LOCK_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
private String randomCode() {
|
||||
StringBuilder code = new StringBuilder(CODE_LENGTH);
|
||||
for (int i = 0; i < CODE_LENGTH; i++) {
|
||||
code.append(CODE_CHARACTERS.charAt(SECURE_RANDOM.nextInt(CODE_CHARACTERS.length())));
|
||||
}
|
||||
return code.toString();
|
||||
}
|
||||
|
||||
private GaoUserInviteCache requireValidInvite(String code) {
|
||||
TimiException.required(code, "not found code");
|
||||
GaoUserInviteCache cache = redisInvite.get(getInviteKey(code));
|
||||
if (cache == null || cache.getExpireAt() == null || cache.getExpireAt() <= Time.now()) {
|
||||
throw invalidInvite();
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
private GaoStore requireActiveStore(String storeId) {
|
||||
GaoStore store = gaoStoreService.get(storeId);
|
||||
if (store == null || !store.isActivated()) {
|
||||
throw invalidInvite();
|
||||
}
|
||||
return store;
|
||||
}
|
||||
|
||||
private Role requireInvitableRole(String inviterUserId, String roleId, String storeId) {
|
||||
Role role = requireValidRole(roleId, storeId);
|
||||
List<String> directRoleIdList = userRoleService.listRoleByUserId(ModuleCode.GAO, inviterUserId)
|
||||
.stream()
|
||||
.map(Role::getId)
|
||||
.toList();
|
||||
boolean descendant = authorizationScopeService.listManageableRole(inviterUserId, ModuleCode.GAO)
|
||||
.stream()
|
||||
.anyMatch(item -> role.getId().equals(item.getId()))
|
||||
&& !directRoleIdList.contains(role.getId());
|
||||
if (!descendant) {
|
||||
throw new TimiException(TimiCode.PERMISSION_ERROR, "角色不在可邀请范围内");
|
||||
}
|
||||
return role;
|
||||
}
|
||||
|
||||
private Role requireValidRole(String roleId, String storeId) {
|
||||
Role role = roleService.get(roleId);
|
||||
if (role == null || role.getModuleCode() != ModuleCode.GAO || (storeId == null && !isGlobalManagerRole(role)) || !isRoleUsableForStore(role, storeId)) {
|
||||
throw invalidInvite();
|
||||
}
|
||||
return role;
|
||||
}
|
||||
|
||||
private boolean isRoleUsableForStore(Role role, String storeId) {
|
||||
return role.getOwnerType() == null
|
||||
|| role.getOwnerType() == AuthOwnerType.MODULE && (TimiJava.isEmpty(role.getOwnerId()) || ModuleCode.GAO.name().equals(role.getOwnerId()))
|
||||
|| role.getOwnerType() == AuthOwnerType.STORE && storeId != null && storeId.equals(role.getOwnerId());
|
||||
}
|
||||
|
||||
private boolean isGlobalManagerRole(Role role) {
|
||||
return role != null
|
||||
&& role.getModuleCode() == ModuleCode.GAO
|
||||
&& GaoRoleCode.GLOBAL_MANAGER.name().equals(role.getCode());
|
||||
}
|
||||
|
||||
private void validateInviteTarget(GaoUserInviteCache cache) {
|
||||
if (cache.getStoreId() != null) {
|
||||
requireActiveStore(cache.getStoreId());
|
||||
}
|
||||
requireValidRole(cache.getRoleId(), cache.getStoreId());
|
||||
}
|
||||
|
||||
private void checkStoreScope(String userId, String storeId) {
|
||||
if (authorizationScopeService.isSystemAdmin(userId) || roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
||||
return;
|
||||
}
|
||||
GaoStore userStore = gaoStoreService.getByUserId(userId);
|
||||
TimiException.requiredTrue(userStore != null && storeId.equals(userStore.getId()), "无权操作其他门店");
|
||||
}
|
||||
|
||||
private String buildLogContent(GaoUserInviteCache cache) {
|
||||
return "inviterUserId=%s;storeId=%s;roleId=%s;scene=%s".formatted(cache.getInviterUserId(), cache.getStoreId(), cache.getRoleId(), cache.getScene());
|
||||
}
|
||||
|
||||
private void checkCodeRateLimit(String code) {
|
||||
checkRateLimit("GAO:USER:INVITE:LIMIT:CODE:" + Digest.sha256(code), CODE_RATE_LIMIT, REGISTER_RATE_LIMIT_TTL);
|
||||
}
|
||||
|
||||
private void checkRegisterValueRateLimit(String type, String value) {
|
||||
checkRateLimit("GAO:USER:INVITE:LIMIT:" + type + ":" + Digest.sha256(value), REGISTER_VALUE_RATE_LIMIT, REGISTER_RATE_LIMIT_TTL);
|
||||
}
|
||||
|
||||
private void checkRateLimit(String key, int limit, long ttl) {
|
||||
String lockKey = key + ":LOCK";
|
||||
TimiException.requiredTrue(redisLocker.lock(lockKey, 1, Time.S * 5), "服务繁忙,请稍后重试");
|
||||
try {
|
||||
Integer count = redisRateLimit.get(key);
|
||||
if (count != null && limit <= count) {
|
||||
throw new TimiException(TimiCode.REQUEST_BAD, "request_rate_limit");
|
||||
}
|
||||
redisRateLimit.set(key, count == null ? 1 : count + 1, ttl);
|
||||
} finally {
|
||||
redisLocker.releaseLock(lockKey);
|
||||
}
|
||||
}
|
||||
|
||||
private String getInviteKey(String code) {
|
||||
return INVITE_KEY_PREFIX + code;
|
||||
}
|
||||
|
||||
private String getConsumeLockKey(String code) {
|
||||
return CONSUME_LOCK_KEY_PREFIX + code;
|
||||
}
|
||||
|
||||
private TimiException invalidInvite() {
|
||||
return new TimiException(TimiCode.ARG_BAD, "邀请码无效或已过期");
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -1,6 +1,5 @@
|
||||
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.GaoStore;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
||||
@@ -30,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@RequiredArgsConstructor
|
||||
public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, String> implements GaoUserService {
|
||||
|
||||
private final ObjectMapper jackson;
|
||||
private final UserService userService;
|
||||
private final LoggerService loggerService;
|
||||
private final GaoStoreService gaoStoreService;
|
||||
@@ -52,7 +50,8 @@ public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, Stri
|
||||
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_USER_CREATE");
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(gaoUser));
|
||||
logger.setContent("storeId=%s;userName=%s;phoneNo=%s".formatted(
|
||||
gaoUser.getStoreId(), gaoUser.getUser().getName(), gaoUser.getUser().getPhoneNo()));
|
||||
|
||||
GaoStore store = gaoStoreService.get(gaoUser.getStoreId());
|
||||
TimiException.required(store, "not found store");
|
||||
@@ -88,7 +87,8 @@ public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, Stri
|
||||
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_USER_UPDATE");
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(gaoUser));
|
||||
logger.setContent("gaoUserId=%s;enabled=%s;remark=%s".formatted(
|
||||
gaoUser.getId(), gaoUser.getEnabled(), gaoUser.getRemark()));
|
||||
|
||||
GaoUser dbGaoUser = super.get(gaoUser.getId());
|
||||
TimiException.required(dbGaoUser, "not found gao user");
|
||||
@@ -122,7 +122,7 @@ public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, Stri
|
||||
|
||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_USER_TRANSFER_STORE");
|
||||
try {
|
||||
logger.setContent(jackson.writeValueAsString(gaoUser));
|
||||
logger.setContent("gaoUserId=%s;storeId=%s".formatted(gaoUser.getId(), gaoUser.getStoreId()));
|
||||
|
||||
GaoStore store = gaoStoreService.get(gaoUser.getStoreId());
|
||||
TimiException.required(store, "not found store");
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.imyeyu.api.modules.gao.task;
|
||||
|
||||
import com.imyeyu.api.modules.gao.entity.GaoStore;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreBusinessDayService;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
///
|
||||
/// GAO 门店营业日自动休息任务
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-12
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class GaoStoreAutoCloseDayTask {
|
||||
|
||||
private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
|
||||
private final GaoStoreService storeService;
|
||||
private final GaoStoreBusinessDayService businessDayService;
|
||||
|
||||
/// 每天零点后自动补记前一天无登记门店的休息日
|
||||
@Scheduled(cron = "0 1 0 * * ?")
|
||||
public void run() {
|
||||
int dateValue = Integer.parseInt(DAY_FORMATTER.format(LocalDate.now().minusDays(1)));
|
||||
List<GaoStore> storeList = storeService.listByAutoClosedDay();
|
||||
for (GaoStore store : storeList) {
|
||||
try {
|
||||
businessDayService.autoCloseBusinessDay(store.getId(), dateValue);
|
||||
} catch (Exception e) {
|
||||
log.error("自动补记 GAO 门店休息日失败: storeId[{}], dateValue[{}]", store.getId(), dateValue, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class StoreXSSFBuilder extends BaseXSSFBuilder<GaoStore> {
|
||||
appendRow(sheet, 0, titleStyle, "门店列表导出");
|
||||
appendRow(sheet, 1, null, "生成时间", Time.nowString());
|
||||
appendRow(sheet, 2, null, "记录总数", String.valueOf(list.size()));
|
||||
appendRow(sheet, 3, headerStyle, "门店编码", "门店名称", "状态", "电话", "地址", "备注", "排序", "创建时间");
|
||||
appendRow(sheet, 3, headerStyle, "门店编码", "门店名称", "状态", "电话", "地址", "备注", "自动计算休息日", "排序", "创建时间");
|
||||
int rowIndex = 4;
|
||||
for (GaoStore store : list) {
|
||||
appendRow(sheet, rowIndex, null,
|
||||
@@ -45,12 +45,13 @@ public class StoreXSSFBuilder extends BaseXSSFBuilder<GaoStore> {
|
||||
text(store.getTelephone()),
|
||||
text(store.getAddress()),
|
||||
text(store.getRemark()),
|
||||
Boolean.TRUE.equals(store.getAutoClosedDay()) ? "是" : "否",
|
||||
store.getSort() == null ? "" : String.valueOf(store.getSort()),
|
||||
Time.toDateTime(store.getCreatedAt())
|
||||
);
|
||||
rowIndex++;
|
||||
}
|
||||
for (int index = 0; index < 8; index++) {
|
||||
for (int index = 0; index < 9; index++) {
|
||||
sheet.autoSizeColumn(index);
|
||||
sheet.setColumnWidth(index, Math.clamp(sheet.getColumnWidth(index), 10 * 256, 36 * 256));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/// 客户报表查询请求
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-11
|
||||
@Data
|
||||
public class GaoCustomerChartReq {
|
||||
|
||||
/// 门店 ID
|
||||
private String storeId;
|
||||
|
||||
/// 客户 ID
|
||||
private String customerId;
|
||||
|
||||
/// 开始时间
|
||||
private Long beginAt;
|
||||
|
||||
/// 结束时间
|
||||
private Long endAt;
|
||||
|
||||
/// 登记事件 ID 列表
|
||||
private List<String> eventIdList;
|
||||
}
|
||||
@@ -29,6 +29,9 @@ public class GaoCustomerEventRankView {
|
||||
/// 最近连续登记天数
|
||||
private Long recentContinuousEventDays;
|
||||
|
||||
/// 登记数值合计
|
||||
private Long totalNumberValue;
|
||||
|
||||
/// 最后登记时间
|
||||
private Long latestRegisteredAt;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import com.imyeyu.java.bean.BasePage;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/// GAO 客户分页查询请求
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-13
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class GaoCustomerPage extends BasePage {
|
||||
|
||||
/// 门店 ID
|
||||
private String storeId;
|
||||
|
||||
/// 关键字,匹配编码、姓名、电话
|
||||
private String keyword;
|
||||
|
||||
/// 标签 ID 列表,客户必须同时拥有列表内全部标签
|
||||
private List<String> tagIdList;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/// 登记事件日历记录视图
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-11
|
||||
@Data
|
||||
public class GaoEventRecordCalendarView {
|
||||
|
||||
/// 登记记录 ID
|
||||
private String id;
|
||||
|
||||
/// 客户 ID
|
||||
private String customerId;
|
||||
|
||||
/// 客户编码
|
||||
private String customerCode;
|
||||
|
||||
/// 客户姓名
|
||||
private String customerName;
|
||||
|
||||
/// 登记事件 ID
|
||||
private String eventId;
|
||||
|
||||
/// 登记时间
|
||||
private Long registeredAt;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/// 登记事件每日统计视图
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-11
|
||||
@Data
|
||||
public class GaoEventRecordDailyStatView {
|
||||
|
||||
/// 登记事件 ID
|
||||
private String eventId;
|
||||
|
||||
/// 日期值,格式为 yyyyMMdd
|
||||
private Integer dateValue;
|
||||
|
||||
/// 当日登记数
|
||||
private Long dailyCount;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import com.imyeyu.spring.util.ResponseView;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
///
|
||||
/// 登记事件记录分页查询结果
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-14
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class GaoEventRecordPageResult extends PageResult<GaoEventRecord> {
|
||||
|
||||
/// 指定单个数值事件的登记数值合计,未指定单个 NUMBER 事件时为空
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private Long numberValueTotal;
|
||||
}
|
||||
@@ -23,9 +23,26 @@ public class GaoEventRecordRankPage extends BasePage {
|
||||
/// 登记事件 ID 列表,为空查询全部登记事件
|
||||
private List<String> eventIdList;
|
||||
|
||||
/// 排行类型
|
||||
private RankType rankType;
|
||||
|
||||
/// 开始登记时间
|
||||
private Long beginAt;
|
||||
|
||||
/// 结束登记时间
|
||||
private Long endAt;
|
||||
|
||||
/// 查询当天日期值,服务端内部填充,格式为 yyyyMMdd
|
||||
private Integer todayDateValue;
|
||||
|
||||
public enum RankType {
|
||||
/// 按累计登记天数
|
||||
TOTAL_DAYS,
|
||||
/// 按累计登记次数
|
||||
TOTAL_COUNT,
|
||||
/// 按最近连续登记天数
|
||||
CONTINUOUS_DAYS,
|
||||
/// 按登记数值合计
|
||||
TOTAL_NUMBER_VALUE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/// GAO 客户积分人工调整请求
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-11
|
||||
@Data
|
||||
public class GaoPointAdjustRequest {
|
||||
|
||||
/// 人工调整请求 ID,用于生成幂等键
|
||||
private String adjustRequestId;
|
||||
|
||||
/// 门店 ID
|
||||
private String storeId;
|
||||
|
||||
/// 客户 ID
|
||||
private String customerId;
|
||||
|
||||
/// 调整积分,正数增加,负数减少
|
||||
private Long pointDelta;
|
||||
|
||||
/// 调整原因
|
||||
private String remark;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import com.imyeyu.api.modules.gao.entity.GaoPointLedger;
|
||||
import com.imyeyu.java.bean.BasePage;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/// GAO 客户积分流水查询请求
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-11
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class GaoPointLedgerPage extends BasePage {
|
||||
|
||||
/// 门店 ID
|
||||
private String storeId;
|
||||
|
||||
/// 客户 ID
|
||||
private String customerId;
|
||||
|
||||
/// 客户积分账户 ID
|
||||
private String accountId;
|
||||
|
||||
/// 流水变化类型
|
||||
private GaoPointLedger.ChangeType changeType;
|
||||
|
||||
/// 开始发生时间
|
||||
private Long beginAt;
|
||||
|
||||
/// 结束发生时间
|
||||
private Long endAt;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/// 门店报表查询请求
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-11
|
||||
@Data
|
||||
public class GaoStoreChartReq {
|
||||
|
||||
/// 门店 ID
|
||||
private String storeId;
|
||||
|
||||
/// 开始时间
|
||||
private Long beginAt;
|
||||
|
||||
/// 结束时间
|
||||
private Long endAt;
|
||||
|
||||
/// 登记事件 ID 列表
|
||||
private List<String> eventIdList;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/// GAO 用户邀请创建请求
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-13
|
||||
@Data
|
||||
public class GaoUserInviteCreateRequest {
|
||||
|
||||
/// 门店管理场景的目标门店 ID,店长场景及 ADMIN 邀请 GLOBAL_MANAGER 时不使用
|
||||
private String storeId;
|
||||
|
||||
/// 目标角色 ID
|
||||
@NotBlank
|
||||
private String roleId;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/// GAO 用户邀请创建响应
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-13
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class GaoUserInviteCreateResponse {
|
||||
|
||||
/// 邀请 code
|
||||
private String code;
|
||||
|
||||
/// 邀请过期时间,毫秒时间戳
|
||||
private Long expireAt;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import com.imyeyu.api.modules.user.validation.UserPassword;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
/// GAO 用户邀请注册数据
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-13
|
||||
@Data
|
||||
public class GaoUserInviteRegisterData {
|
||||
|
||||
/// 邀请 code
|
||||
@NotBlank
|
||||
@Pattern(regexp = "[23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{10}")
|
||||
private String code;
|
||||
|
||||
/// 手机号
|
||||
@NotBlank
|
||||
@Pattern(regexp = "^1\\d{10}$")
|
||||
private String phoneNo;
|
||||
|
||||
/// 用户名
|
||||
@NotBlank
|
||||
@Size(max = 191)
|
||||
private String name;
|
||||
|
||||
/// 明文密码
|
||||
@UserPassword
|
||||
private String password;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import com.imyeyu.spring.bean.CaptchaData;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
/// GAO 用户邀请注册请求
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-13
|
||||
public class GaoUserInviteRegisterRequest extends CaptchaData<GaoUserInviteRegisterData> {
|
||||
|
||||
/// 级联校验注册数据
|
||||
@Override
|
||||
@NotNull
|
||||
@Valid
|
||||
public GaoUserInviteRegisterData getData() {
|
||||
return super.getData();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.Data;
|
||||
|
||||
/// GAO 用户邀请校验请求
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-13
|
||||
@Data
|
||||
public class GaoUserInviteValidateRequest {
|
||||
|
||||
/// 邀请 code
|
||||
@NotBlank
|
||||
@Pattern(regexp = "[23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{10}")
|
||||
private String code;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/// GAO 用户邀请校验响应
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-13
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class GaoUserInviteValidateResponse {
|
||||
|
||||
/// true 为邀请码可用
|
||||
private boolean valid;
|
||||
|
||||
/// 邀请过期时间,毫秒时间戳
|
||||
private Long expireAt;
|
||||
}
|
||||
@@ -143,7 +143,7 @@ public class FileController implements TimiJava, OS.FileSystem {
|
||||
public void read(HttpServletRequest req, HttpServletResponse resp) {
|
||||
try {
|
||||
String path = req.getServletPath().substring("/system/file/read".length());
|
||||
path = "E:\\IDEAProject\\TimiServerAPI\\data\\file" + path;
|
||||
path = "/root/bin/data/mnt" + path;
|
||||
if (TimiJava.isEmpty(path)) {
|
||||
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
return;
|
||||
|
||||
+21
-8
@@ -3,10 +3,14 @@ package com.imyeyu.api.modules.system.service.implement;
|
||||
import com.imyeyu.api.modules.system.entity.Logger;
|
||||
import com.imyeyu.api.modules.system.mapper.LoggerMapper;
|
||||
import com.imyeyu.api.modules.system.service.LoggerService;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.spring.TimiSpring;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import com.imyeyu.spring.service.AbstractEntityService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -15,6 +19,7 @@ import org.springframework.stereotype.Service;
|
||||
* @author 夜雨
|
||||
* @since 2026-05-13 14:46
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LoggerServiceImplement extends AbstractEntityService<Logger, String> implements LoggerService {
|
||||
@@ -31,19 +36,13 @@ public class LoggerServiceImplement extends AbstractEntityService<Logger, String
|
||||
@Override
|
||||
public void create(Logger logger) {
|
||||
// 默认异步
|
||||
fillContext(logger);
|
||||
Thread.startVirtualThread(() -> createSync(logger));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createSync(Logger logger) {
|
||||
// TODO 异步请求上下文已丢失
|
||||
// if (TimiJava.isEmpty(logger.getUserId())) {
|
||||
// User loginUser = userLoginService.getLoginUser();
|
||||
// if (TimiJava.isNotEmpty(loginUser)) {
|
||||
// logger.setUserId(loginUser.getId());
|
||||
// }
|
||||
// }
|
||||
// logger.setIp(TimiJava.defaultIfEmpty(logger.getIp(), TimiSpring.getRequestIP()));
|
||||
fillContext(logger);
|
||||
super.create(logger);
|
||||
}
|
||||
|
||||
@@ -53,4 +52,18 @@ public class LoggerServiceImplement extends AbstractEntityService<Logger, String
|
||||
log.setResult(result);
|
||||
create(log);
|
||||
}
|
||||
|
||||
private void fillContext(Logger logger) {
|
||||
try {
|
||||
if (TimiJava.isEmpty(logger.getUserId())) {
|
||||
User loginUser = userLoginService.getLoginUser();
|
||||
if (TimiJava.isNotEmpty(loginUser)) {
|
||||
logger.setUserId(loginUser.getId());
|
||||
}
|
||||
}
|
||||
logger.setIp(TimiJava.defaultIfEmpty(logger.getIp(), TimiSpring.getRequestIP()));
|
||||
} catch (Exception e) {
|
||||
// 无请求上下文的后台任务允许继续写日志
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.imyeyu.api.modules.user.bean;
|
||||
|
||||
/// 授权对象归属类型
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-07
|
||||
public enum AuthOwnerType {
|
||||
|
||||
/// 系统级
|
||||
SYSTEM,
|
||||
|
||||
/// 模块级
|
||||
MODULE,
|
||||
|
||||
/// 租户级
|
||||
TENANT,
|
||||
|
||||
/// 门店级
|
||||
STORE,
|
||||
|
||||
/// 用户级
|
||||
USER
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user