Compare commits
51
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a150f9e017 | ||
|
|
a523df6a07 | ||
|
|
31c583eeb5 | ||
|
|
e3ef3e5275 | ||
|
|
84190b9773 | ||
|
|
7808d22775 | ||
|
|
fba559cd22 | ||
|
|
ecd2fa1c33 | ||
|
|
dcc75efa87 | ||
|
|
a9465299a9 | ||
|
|
42152c7b79 | ||
|
|
1a896ef457 | ||
|
|
9d8990a028 | ||
|
|
17d88fc338 | ||
|
|
bb40f347a3 | ||
|
|
e3236d262d | ||
|
|
3d4e32e5da | ||
|
|
c8e2e16ba5 | ||
|
|
bdc4cbb240 | ||
|
|
99b44faf09 | ||
|
|
7f6cebd4e2 | ||
|
|
75fd4bed18 | ||
|
|
b3e3cbf84b | ||
|
|
8db6f962c9 | ||
|
|
0aee11d824 | ||
|
|
e35cf3aa59 | ||
|
|
457e716b38 | ||
|
|
ab4a164680 | ||
|
|
9dfca25f8c | ||
|
|
e369a38e2e | ||
|
|
f1e10df6a7 | ||
|
|
fcf358a768 | ||
|
|
619369104c | ||
|
|
4f1408b9d0 | ||
|
|
029eea70cc | ||
|
|
22b1e65385 | ||
|
|
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
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
<groupId>com.imyeyu.timiserverapi</groupId>
|
||||
<artifactId>TimiServerAPI</artifactId>
|
||||
<version>1.0.13</version>
|
||||
<version>1.0.18</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>
|
||||
@@ -225,6 +235,20 @@
|
||||
<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>com.tencentcloudapi</groupId>
|
||||
<artifactId>tencentcloud-sdk-java-sms</artifactId>
|
||||
<version>3.1.1281</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-freemarker</artifactId>
|
||||
|
||||
@@ -50,6 +50,16 @@ public enum CorePermissionCode implements BuiltinPermissionCode {
|
||||
USER_UPDATE("USER:UPDATE", "用户修改", false, true),
|
||||
USER_DELETE("USER:DELETE", "用户删除", false, true),
|
||||
|
||||
FEEDBACK_CREATE("FEEDBACK:CREATE", "反馈创建", false, true),
|
||||
FEEDBACK_READ("FEEDBACK:READ", "反馈读取", false, true),
|
||||
FEEDBACK_UPDATE("FEEDBACK:UPDATE", "反馈修改", false, true),
|
||||
FEEDBACK_DELETE("FEEDBACK:DELETE", "反馈删除", false, true),
|
||||
|
||||
NOTIFY_CREATE("NOTIFY:CREATE", "通知创建", false, true),
|
||||
NOTIFY_READ("NOTIFY:READ", "通知读取", false, true),
|
||||
NOTIFY_DELETE("NOTIFY:DELETE", "通知删除", false, true),
|
||||
NOTIFY_CANCEL("NOTIFY:CANCEL", "通知取消", false, true),
|
||||
|
||||
USER_ROLE_CREATE("USER_ROLE:CREATE", "用户角色创建", true, true),
|
||||
USER_ROLE_READ("USER_ROLE:READ", "用户角色读取", true, true),
|
||||
USER_ROLE_DELETE("USER_ROLE:DELETE", "用户角色删除", true, true);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.imyeyu.api.modules.common.config;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/// 通知消息队列配置
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "notify.queue")
|
||||
public class NotifyQueueConfig {
|
||||
|
||||
private Mail mail = new Mail();
|
||||
|
||||
private Sms sms = new Sms();
|
||||
|
||||
private Wechat wechat = new Wechat();
|
||||
|
||||
private HTTP http = new HTTP();
|
||||
|
||||
/// 邮件队列配置
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class Mail extends Queue {
|
||||
|
||||
private String defaultFrom;
|
||||
}
|
||||
|
||||
/// 短信队列配置
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class Sms extends Queue {
|
||||
|
||||
private String appId;
|
||||
|
||||
private String sign;
|
||||
|
||||
private String secretId;
|
||||
|
||||
private String secretKey;
|
||||
}
|
||||
|
||||
/// 微信队列配置
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class Wechat extends Queue {
|
||||
}
|
||||
|
||||
/// HTTP 队列配置
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class HTTP extends Queue {
|
||||
}
|
||||
|
||||
/// 通用队列配置
|
||||
@Data
|
||||
public static class Queue {
|
||||
|
||||
/// true 为启用
|
||||
private boolean enable;
|
||||
|
||||
private String cron = "0/30 * * * * ?";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.imyeyu.api.modules.common.controller;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import com.imyeyu.api.annotation.RequireCorePermission;
|
||||
import com.imyeyu.api.bean.CorePermissionCode;
|
||||
import com.imyeyu.api.modules.common.entity.Feedback;
|
||||
import com.imyeyu.api.modules.common.service.FeedbackService;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
import com.imyeyu.spring.TimiSpring;
|
||||
import com.imyeyu.spring.annotation.AOPLog;
|
||||
import com.imyeyu.spring.annotation.CaptchaValid;
|
||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||
import com.imyeyu.spring.bean.CaptchaData;
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/// 通用反馈接口
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-19
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/feedback")
|
||||
public class FeedbackController {
|
||||
|
||||
private final FeedbackService service;
|
||||
private final UserLoginService userLoginService;
|
||||
|
||||
/// 提交反馈。登录用户和匿名用户均需提交图形验证码,匿名用户按 IP 限流
|
||||
///
|
||||
/// @param captchaData 带图形验证码的反馈请求
|
||||
@AOPLog
|
||||
@JsonView(ResponseView.Public.class)
|
||||
@CaptchaValid
|
||||
@RequestRateLimit(value = 3, inSeconds = 60)
|
||||
@PostMapping("/create")
|
||||
public void create(@RequestBody @Valid CaptchaData<Feedback> captchaData) {
|
||||
Feedback feedback = captchaData.getData();
|
||||
feedback.setIp(TimiSpring.getRequestIP());
|
||||
if (userLoginService.isLogged()) {
|
||||
feedback.setUserId(userLoginService.getRequireLoginUserId());
|
||||
}
|
||||
service.create(feedback);
|
||||
}
|
||||
|
||||
/// 查询反馈列表
|
||||
///
|
||||
/// @param page 分页参数
|
||||
/// @return 反馈分页
|
||||
@JsonView(ResponseView.Admin.class)
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FEEDBACK_READ)
|
||||
@PostMapping("/list")
|
||||
public PageResult<Feedback> list(@RequestBody Page<Feedback> page) {
|
||||
return service.page(page);
|
||||
}
|
||||
|
||||
/// 查询反馈详情
|
||||
///
|
||||
/// @param id 反馈 ID
|
||||
/// @return 反馈详情
|
||||
@JsonView(ResponseView.Admin.class)
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FEEDBACK_READ)
|
||||
@PostMapping("/detail")
|
||||
public Feedback detail(@RequestParam String id) {
|
||||
return service.get(id);
|
||||
}
|
||||
|
||||
/// 更新反馈
|
||||
///
|
||||
/// @param feedback 反馈
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FEEDBACK_UPDATE)
|
||||
@PostMapping("/update")
|
||||
public void update(@RequestBody Feedback feedback) {
|
||||
feedback.setRespondedBy(userLoginService.getRequireLoginUserId());
|
||||
service.update(feedback);
|
||||
}
|
||||
|
||||
/// 删除反馈
|
||||
///
|
||||
/// @param id 反馈 ID
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FEEDBACK_DELETE)
|
||||
@PostMapping("/delete")
|
||||
public void delete(@RequestParam String id) {
|
||||
service.delete(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package com.imyeyu.api.modules.common.controller;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import com.imyeyu.api.annotation.RequireCorePermission;
|
||||
import com.imyeyu.api.bean.CorePermissionCode;
|
||||
import com.imyeyu.api.modules.common.entity.Notify;
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
||||
import com.imyeyu.api.modules.common.service.NotifyService;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
import com.imyeyu.api.modules.user.service.UserService;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.spring.annotation.RequiredToken;
|
||||
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.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/// 通知接口
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/notify")
|
||||
public class NotifyController {
|
||||
|
||||
private final UserService userService;
|
||||
private final NotifyService service;
|
||||
private final UserLoginService userLoginService;
|
||||
private final NotifyDetailService detailService;
|
||||
|
||||
/// 创建通知,同时创建通知详情
|
||||
///
|
||||
/// @param notify 通知及通知详情
|
||||
/// @return 创建后的通知
|
||||
@RequireCorePermission(CorePermissionCode.NOTIFY_CREATE)
|
||||
@RequiredToken
|
||||
@PostMapping("/create")
|
||||
public Notify create(@RequestBody Notify notify) {
|
||||
service.create(notify);
|
||||
return notify;
|
||||
}
|
||||
|
||||
/// 查询通知详情
|
||||
///
|
||||
/// @param id 通知 ID
|
||||
/// @return 通知及通知详情
|
||||
@JsonView(ResponseView.Public.class)
|
||||
@RequireCorePermission(CorePermissionCode.NOTIFY_READ)
|
||||
@RequiredToken
|
||||
@RequestMapping("/detail")
|
||||
public Notify detail(@RequestParam String id) {
|
||||
Notify notify = service.get(id);
|
||||
{
|
||||
List<NotifyDetail> detailList = detailService.listByNotifyId(id);
|
||||
Set<String> userIdSet = detailList.stream()
|
||||
.filter(item -> item.getMsgType() == NotifyDetail.MsgType.INTERNAL)
|
||||
.flatMap(item -> Stream.of(item.getSendFrom(), item.getSendTo()))
|
||||
.collect(Collectors.toSet());
|
||||
Map<String, User> userMap = userService.mapByIdList(userIdSet);
|
||||
for (NotifyDetail detail : detailList) {
|
||||
if (TimiJava.isNotEmpty(detail.getSendFrom())) {
|
||||
detail.setFromUser(userMap.get(detail.getSendFrom()));
|
||||
}
|
||||
if (TimiJava.isNotEmpty(detail.getSendTo())) {
|
||||
detail.setToUser(userMap.get(detail.getSendTo()));
|
||||
}
|
||||
}
|
||||
notify.setDetailList(detailList);
|
||||
}
|
||||
return notify;
|
||||
}
|
||||
|
||||
/// 删除通知及其通知详情
|
||||
///
|
||||
/// @param id 通知 ID
|
||||
@RequireCorePermission(CorePermissionCode.NOTIFY_DELETE)
|
||||
@RequiredToken
|
||||
@PostMapping("/delete")
|
||||
public void delete(@RequestParam String id) {
|
||||
service.delete(id);
|
||||
}
|
||||
|
||||
/// 取消尚未成功发送的通知详情
|
||||
///
|
||||
/// @param id 通知 ID
|
||||
@RequireCorePermission(CorePermissionCode.NOTIFY_CANCEL)
|
||||
@RequiredToken
|
||||
@PostMapping("/cancel")
|
||||
public void cancel(@RequestParam String id) {
|
||||
service.cancel(id);
|
||||
}
|
||||
|
||||
/// 查询当前用户的站内通知
|
||||
///
|
||||
/// @param page 分页参数
|
||||
/// @param unreadOnly true 为只查询未读通知
|
||||
/// @return 站内通知分页结果
|
||||
@RequireCorePermission(CorePermissionCode.NOTIFY_READ)
|
||||
@RequiredToken
|
||||
@PostMapping("/internal/internal")
|
||||
public PageResult<NotifyDetail> listInternal(
|
||||
@RequestBody(required = false) Page<NotifyDetail> page,
|
||||
@RequestParam(defaultValue = "false") boolean unreadOnly
|
||||
) {
|
||||
return detailService.pageInternalByUserId(page, userLoginService.getRequireLoginUserId(), unreadOnly);
|
||||
}
|
||||
|
||||
@JsonView(ResponseView.Public.class)
|
||||
@RequireCorePermission(CorePermissionCode.NOTIFY_READ)
|
||||
@RequiredToken
|
||||
@PostMapping("/internal/detail")
|
||||
public NotifyDetail internalDetail(@RequestParam String id) {
|
||||
NotifyDetail detail = detailService.getInternalByUserId(id, userLoginService.getRequireLoginUserId());
|
||||
if (TimiJava.isNotEmpty(detail.getSendFrom())) {
|
||||
detail.setFromUser(userService.get(detail.getSendFrom()));
|
||||
}
|
||||
if (TimiJava.isNotEmpty(detail.getSendTo())) {
|
||||
detail.setToUser(userService.get(detail.getSendTo()));
|
||||
}
|
||||
return detail;
|
||||
}
|
||||
|
||||
/// 删除当前用户的一条站内通知
|
||||
///
|
||||
/// @param id 通知详情 ID
|
||||
@RequireCorePermission(CorePermissionCode.NOTIFY_READ)
|
||||
@RequiredToken
|
||||
@PostMapping("/internal/delete")
|
||||
public void deleteInternal(@RequestParam String id) {
|
||||
detailService.deleteInternalByUserId(id, userLoginService.getRequireLoginUserId());
|
||||
}
|
||||
|
||||
/// 查询当前用户未读通知数量
|
||||
///
|
||||
/// @return 未读通知数量
|
||||
@RequireCorePermission(CorePermissionCode.NOTIFY_READ)
|
||||
@RequiredToken
|
||||
@PostMapping("/internal/unread/count")
|
||||
public long countUnreadSite() {
|
||||
return detailService.countUnreadSiteByUserId(userLoginService.getRequireLoginUserId());
|
||||
}
|
||||
|
||||
/// 标记当前用户的一条站内通知已读
|
||||
///
|
||||
/// @param id 通知详情 ID
|
||||
@RequireCorePermission(CorePermissionCode.NOTIFY_READ)
|
||||
@RequiredToken
|
||||
@PostMapping("/internal/read")
|
||||
public void markSiteRead(@RequestParam String id) {
|
||||
detailService.markSiteRead(userLoginService.getRequireLoginUserId(), id);
|
||||
}
|
||||
|
||||
/// 标记当前用户全部站内通知已读
|
||||
@RequireCorePermission(CorePermissionCode.NOTIFY_READ)
|
||||
@RequiredToken
|
||||
@PostMapping("/internal/read/all")
|
||||
public void markAllSiteRead() {
|
||||
detailService.markAllSiteRead(userLoginService.getRequireLoginUserId());
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,10 @@ public class Article extends UUIDEntity implements SettingSupport {
|
||||
public enum BizType {
|
||||
|
||||
/** 博客 */
|
||||
BLOG
|
||||
BLOG,
|
||||
|
||||
/// 反馈
|
||||
FEEDBACK
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,6 +52,19 @@ public class Article extends UUIDEntity implements SettingSupport {
|
||||
TIP_TAP
|
||||
}
|
||||
|
||||
/// 文章状态
|
||||
public enum Status {
|
||||
|
||||
/// 草稿
|
||||
DART,
|
||||
|
||||
/// 正常
|
||||
NORMAL,
|
||||
|
||||
/// 隐藏
|
||||
HIDDEN
|
||||
}
|
||||
|
||||
/** 业务类型 */
|
||||
protected BizType bizType;
|
||||
|
||||
@@ -58,8 +74,8 @@ public class Article extends UUIDEntity implements SettingSupport {
|
||||
/** 标题 */
|
||||
protected String title;
|
||||
|
||||
/** 摘要 */
|
||||
protected String digest;
|
||||
/** 描述 */
|
||||
protected String description;
|
||||
|
||||
/** 正文类型 */
|
||||
protected ContentType contentType;
|
||||
@@ -74,9 +90,15 @@ public class Article extends UUIDEntity implements SettingSupport {
|
||||
/** 喜欢数量 */
|
||||
protected Integer likes;
|
||||
|
||||
/** 文章状态 */
|
||||
protected Status status;
|
||||
|
||||
@Transient
|
||||
protected List<Setting> settingList;
|
||||
|
||||
@Transient
|
||||
protected List<Comment> commentList;
|
||||
|
||||
@Transient
|
||||
protected List<Attachment> attachmentList;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ public class Attachment extends UUIDEntity {
|
||||
/// @since 2026-07-17 20:52
|
||||
public enum BizType {
|
||||
|
||||
ARTICLE,
|
||||
|
||||
USER,
|
||||
|
||||
GAO_CUSTOMER,
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import com.imyeyu.spring.annotation.table.AutoUUID;
|
||||
import com.imyeyu.spring.annotation.table.Id;
|
||||
import com.imyeyu.spring.entity.Creatable;
|
||||
import com.imyeyu.spring.entity.Destroyable;
|
||||
import com.imyeyu.spring.entity.IDEntity;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/// 通知基础队列实体
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class BaseQueueEntity implements IDEntity<String>, Creatable, Destroyable {
|
||||
|
||||
/** 主键 */
|
||||
@Id
|
||||
@AutoUUID
|
||||
protected String id;
|
||||
|
||||
/** 所属通知详情 ID */
|
||||
protected String notifyDetailId;
|
||||
|
||||
/** 内容 */
|
||||
protected String data;
|
||||
|
||||
/** 参数 */
|
||||
protected String args;
|
||||
|
||||
/** 发送去向 */
|
||||
protected String sendTo;
|
||||
|
||||
/** 发送时间 */
|
||||
protected Long sendAt;
|
||||
|
||||
/** 剩余重试次数 */
|
||||
protected Integer retry;
|
||||
|
||||
/** 超时时间 */
|
||||
protected Long timeoutAt;
|
||||
|
||||
/** 创建时间 */
|
||||
protected Long createdAt;
|
||||
|
||||
/// 从通知详情创建队列实体
|
||||
///
|
||||
/// @param detail 通知详情
|
||||
public BaseQueueEntity(NotifyDetail detail) {
|
||||
notifyDetailId = detail.getId();
|
||||
data = detail.getData();
|
||||
args = detail.getArgs();
|
||||
sendTo = detail.getSendTo();
|
||||
sendAt = detail.getSendAt();
|
||||
retry = detail.getRetry();
|
||||
timeoutAt = detail.getTimeoutAt();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import com.imyeyu.api.bean.ModuleCode;
|
||||
import com.imyeyu.spring.annotation.table.Transient;
|
||||
import com.imyeyu.spring.entity.UUIDEntity;
|
||||
import com.imyeyu.spring.util.ResponseView;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/// 通用反馈
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-19
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Feedback extends UUIDEntity {
|
||||
|
||||
/// 反馈处理状态
|
||||
public enum Status {
|
||||
|
||||
/// 待处理
|
||||
PENDING,
|
||||
|
||||
/// 已回复
|
||||
REPLIED,
|
||||
|
||||
/// 已关闭
|
||||
CLOSED
|
||||
}
|
||||
|
||||
/// 所属模块
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private ModuleCode module;
|
||||
|
||||
/// 提交用户 ID,匿名反馈为 null
|
||||
@JsonView(ResponseView.Admin.class)
|
||||
private String userId;
|
||||
|
||||
/// 反馈内容文章 ID
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private String contentId;
|
||||
|
||||
/// 联系方式
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private String contact;
|
||||
|
||||
/// 提交 IP
|
||||
@JsonView(ResponseView.Admin.class)
|
||||
private String ip;
|
||||
|
||||
/// 处理状态
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private Status status;
|
||||
|
||||
/// 管理员回复文章 ID
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private String responseId;
|
||||
|
||||
/// 回复用户 ID
|
||||
@JsonView(ResponseView.Admin.class)
|
||||
private String respondedBy;
|
||||
|
||||
/// 回复时间
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private Long respondedAt;
|
||||
|
||||
/// 管理员回复文章
|
||||
@Transient
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private Article content;
|
||||
|
||||
/// 管理员回复文章
|
||||
@Transient
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private Article response;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import com.imyeyu.spring.annotation.table.Table;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/// HTTP 回调队列
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("http_queue")
|
||||
public class HTTPQueue extends BaseQueueEntity {
|
||||
|
||||
/** HTTP 请求方法 */
|
||||
protected String method;
|
||||
|
||||
/// 从通知详情创建 HTTP 队列
|
||||
///
|
||||
/// @param detail 通知详情
|
||||
public HTTPQueue(NotifyDetail detail) {
|
||||
super(detail);
|
||||
method = "POST";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/// 邮件发送队列
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class MailQueue extends BaseQueueEntity {
|
||||
|
||||
/** 邮件标题 */
|
||||
protected String subject;
|
||||
|
||||
/** 邮件附件 */
|
||||
protected String attachments;
|
||||
|
||||
/** 发送来源 */
|
||||
protected String sendFrom;
|
||||
|
||||
/// 从通知详情创建邮件队列
|
||||
///
|
||||
/// @param detail 通知详情
|
||||
public MailQueue(NotifyDetail detail) {
|
||||
super(detail);
|
||||
subject = detail.getSubject();
|
||||
sendFrom = detail.getSendFrom();
|
||||
}
|
||||
|
||||
/// 邮件附件
|
||||
@Data
|
||||
public static class Attachment {
|
||||
|
||||
/** 附件类型 */
|
||||
private Type type;
|
||||
|
||||
/** 附件值 */
|
||||
private String value;
|
||||
|
||||
/// 附件来源类型
|
||||
public enum Type {
|
||||
|
||||
/** 系统附件 */
|
||||
E2INS_ATTACH,
|
||||
|
||||
/** URL 附件 */
|
||||
URL
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import com.imyeyu.spring.annotation.table.AutoUUID;
|
||||
import com.imyeyu.spring.annotation.table.Id;
|
||||
import com.imyeyu.spring.annotation.table.Transient;
|
||||
import com.imyeyu.spring.entity.UUIDEntity;
|
||||
import lombok.Data;
|
||||
@@ -19,11 +17,6 @@ import java.util.List;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Notify extends UUIDEntity {
|
||||
|
||||
/** 主键 */
|
||||
@Id
|
||||
@AutoUUID
|
||||
private String id;
|
||||
|
||||
/** 业务类型 */
|
||||
private String bizType;
|
||||
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import com.imyeyu.api.TimiServerAPI;
|
||||
import com.imyeyu.api.modules.common.service.BaseQueueService;
|
||||
import com.imyeyu.api.modules.common.service.HTTPQueueService;
|
||||
import com.imyeyu.api.modules.common.service.MailQueueService;
|
||||
import com.imyeyu.api.modules.common.service.SmsQueueService;
|
||||
import com.imyeyu.api.modules.common.service.WechatQueueService;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import com.imyeyu.spring.annotation.table.Transient;
|
||||
import com.imyeyu.spring.entity.UUIDEntity;
|
||||
import com.imyeyu.spring.util.ResponseView;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -25,13 +34,32 @@ public class NotifyDetail extends UUIDEntity {
|
||||
@AllArgsConstructor
|
||||
public enum MsgType {
|
||||
|
||||
SMS,
|
||||
/** 站内通知,不进入外部消息队列 */
|
||||
INTERNAL(null),
|
||||
|
||||
MAIL,
|
||||
SMS(SmsQueueService.class),
|
||||
|
||||
HTTP,
|
||||
MAIL(MailQueueService.class),
|
||||
|
||||
WECHAT;
|
||||
HTTP(HTTPQueueService.class),
|
||||
|
||||
WECHAT(WechatQueueService.class);
|
||||
|
||||
private final Class<? extends BaseQueueService<?>> queueServiceClass;
|
||||
|
||||
/// 获取消息队列服务
|
||||
///
|
||||
/// @return 消息队列服务
|
||||
public BaseQueueService<?> getService() {
|
||||
return TimiServerAPI.applicationContext.getBean(queueServiceClass);
|
||||
}
|
||||
|
||||
/// 判断是否需要外部消息队列
|
||||
///
|
||||
/// @return true 为需要外部消息队列
|
||||
public boolean isQueue() {
|
||||
return queueServiceClass != null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,44 +82,67 @@ public class NotifyDetail extends UUIDEntity {
|
||||
}
|
||||
|
||||
/** 所属通知 ID */
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private String notifyId;
|
||||
|
||||
/** 消息类型 */
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private MsgType msgType;
|
||||
|
||||
/** 模板 ID */
|
||||
@JsonView(ResponseView.Admin.class)
|
||||
private String templateId;
|
||||
|
||||
/** 标题 */
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private String subject;
|
||||
|
||||
/** 内容 */
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private String data;
|
||||
|
||||
/** 参数 */
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private String args;
|
||||
|
||||
/** 发送来源 */
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private String sendFrom;
|
||||
|
||||
/** 发送去向 */
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private String sendTo;
|
||||
|
||||
/** 发送时间 */
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private Long sendAt;
|
||||
|
||||
/** 重试计数 */
|
||||
@JsonView(ResponseView.Admin.class)
|
||||
private Integer retry;
|
||||
|
||||
/** 超时时间 */
|
||||
@JsonView(ResponseView.Admin.class)
|
||||
private Long timeoutAt;
|
||||
|
||||
/** 结果描述 */
|
||||
@JsonView(ResponseView.Admin.class)
|
||||
private String resultDesc;
|
||||
|
||||
/** 状态 */
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private Status status;
|
||||
|
||||
/** 已读时间,站内通知未读时为空 */
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private Long readAt;
|
||||
|
||||
@Transient
|
||||
protected Notify notify;
|
||||
|
||||
@Transient
|
||||
protected User fromUser;
|
||||
|
||||
@Transient
|
||||
protected User toUser;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/// 短信发送队列
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SmsQueue extends BaseQueueEntity {
|
||||
|
||||
/** 短信模板 ID */
|
||||
protected String templateId;
|
||||
|
||||
/// 从通知详情创建短信队列
|
||||
///
|
||||
/// @param detail 通知详情
|
||||
public SmsQueue(NotifyDetail detail) {
|
||||
super(detail);
|
||||
templateId = detail.getTemplateId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/// 微信消息发送队列
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class WechatQueue extends BaseQueueEntity {
|
||||
|
||||
/// 从通知详情创建微信队列
|
||||
///
|
||||
/// @param detail 通知详情
|
||||
public WechatQueue(NotifyDetail detail) {
|
||||
super(detail);
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public interface AttachmentMapper extends BaseMapper<Attachment, String>, RawMap
|
||||
|
||||
List<Attachment> selectByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes, Page<Attachment> page);
|
||||
|
||||
List<Attachment> selectByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, List<String> attachTypes);
|
||||
List<Attachment> selectAllByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, List<String> attachTypes);
|
||||
|
||||
long countByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes);
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.imyeyu.api.modules.common.mapper;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.BaseQueueEntity;
|
||||
import com.imyeyu.api.modules.common.util.QueueSQLProvider;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.DeleteProvider;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.SelectProvider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/// 通知队列基础 Mapper
|
||||
///
|
||||
/// @param <T> 队列实体类型
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
public interface BaseQueueMapper<T extends BaseQueueEntity> extends BaseMapper<T, String> {
|
||||
|
||||
/** 查询已到发送时间的队列 */
|
||||
@SelectProvider(type = QueueSQLProvider.class, method = "listReadyQueue")
|
||||
List<T> listReadyQueue();
|
||||
|
||||
/** 根据通知详情 ID 物理删除队列 */
|
||||
@DeleteProvider(type = QueueSQLProvider.class, method = "destroyByNotifyDetailId")
|
||||
void destroyByNotifyDetailId(@Param("notifyDetailId") String notifyDetailId);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.imyeyu.api.modules.common.mapper;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.Feedback;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
|
||||
/// 通用反馈 Mapper
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-19
|
||||
public interface FeedbackMapper extends BaseMapper<Feedback, String> {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.imyeyu.api.modules.common.mapper;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.HTTPQueue;
|
||||
|
||||
/// HTTP 队列 Mapper
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
public interface HTTPQueueMapper extends BaseQueueMapper<HTTPQueue> {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.imyeyu.api.modules.common.mapper;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.MailQueue;
|
||||
|
||||
/// 邮件队列 Mapper
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
public interface MailQueueMapper extends BaseQueueMapper<MailQueue> {
|
||||
}
|
||||
@@ -2,6 +2,11 @@ package com.imyeyu.api.modules.common.mapper;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 通知详情 Mapper
|
||||
@@ -10,4 +15,36 @@ import com.imyeyu.spring.mapper.BaseMapper;
|
||||
* @since 2026-05-13 14:46
|
||||
*/
|
||||
public interface NotifyDetailMapper extends BaseMapper<NotifyDetail, String> {
|
||||
|
||||
/** 查询用户的站内通知 */
|
||||
@Select("SELECT * FROM `notify_detail` WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} " + NOT_DELETE + " ORDER BY `created_at` DESC LIMIT #{offset}, #{limit}")
|
||||
List<NotifyDetail> selectSiteByUserId(@Param("userId") String userId, @Param("offset") long offset, @Param("limit") long limit);
|
||||
|
||||
/** 查询用户的未读站内通知 */
|
||||
@Select("SELECT * FROM `notify_detail` WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `read_at` IS NULL " + NOT_DELETE + " ORDER BY `created_at` DESC LIMIT #{offset}, #{limit}")
|
||||
List<NotifyDetail> selectUnreadSiteByUserId(@Param("userId") String userId, @Param("offset") long offset, @Param("limit") long limit);
|
||||
|
||||
/** 统计用户的站内通知数量 */
|
||||
@Select("SELECT COUNT(*) FROM `notify_detail` WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} " + NOT_DELETE)
|
||||
long countSiteByUserId(@Param("userId") String userId);
|
||||
|
||||
/** 统计用户的未读站内通知数量 */
|
||||
@Select("SELECT COUNT(*) FROM `notify_detail` WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `read_at` IS NULL " + NOT_DELETE)
|
||||
long countUnreadSiteByUserId(@Param("userId") String userId);
|
||||
|
||||
/** 查询用户拥有的站内通知 */
|
||||
@Select("SELECT * FROM `notify_detail` WHERE `id` = #{detailId} AND `msg_type` = 'INTERNAL' AND `send_to` = #{userId} " + NOT_DELETE + " LIMIT 1")
|
||||
NotifyDetail selectSiteByIdAndUserId(@Param("detailId") String detailId, @Param("userId") String userId);
|
||||
|
||||
/** 删除用户的站内通知 */
|
||||
@Update("UPDATE `notify_detail` SET `deleted_at` = " + UNIX_TIME + ", `updated_at` = " + UNIX_TIME + " WHERE `id` = #{detailId} AND `msg_type` = 'INTERNAL' AND `send_to` = #{userId} " + NOT_DELETE)
|
||||
int deleteSiteByIdAndUserId(@Param("detailId") String detailId, @Param("userId") String userId);
|
||||
|
||||
/** 标记站内通知已读 */
|
||||
@Update("UPDATE `notify_detail` SET `read_at` = #{readAt}, `updated_at` = " + UNIX_TIME + " WHERE `id` = #{detailId} AND `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `read_at` IS NULL " + NOT_DELETE)
|
||||
int markSiteRead(@Param("detailId") String detailId, @Param("userId") String userId, @Param("readAt") long readAt);
|
||||
|
||||
/** 标记用户全部站内通知已读 */
|
||||
@Update("UPDATE `notify_detail` SET `read_at` = #{readAt}, `updated_at` = " + UNIX_TIME + " WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `read_at` IS NULL " + NOT_DELETE)
|
||||
int markAllSiteRead(@Param("userId") String userId, @Param("readAt") long readAt);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.imyeyu.api.modules.common.mapper;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.SmsQueue;
|
||||
|
||||
/// 短信队列 Mapper
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
public interface SmsQueueMapper extends BaseQueueMapper<SmsQueue> {
|
||||
}
|
||||
@@ -15,5 +15,23 @@ public interface TagMapper extends BaseMapper<Tag, String> {
|
||||
|
||||
List<Tag> selectByIdList(Collection<String> idList);
|
||||
|
||||
/// 按归属和名称关键词查询标签总数
|
||||
///
|
||||
/// @param ownerType 归属类型
|
||||
/// @param ownerId 归属 ID
|
||||
/// @param keyword 名称关键词
|
||||
/// @return 标签总数
|
||||
long countByOwnerAndKeyword(@Param("ownerType") Tag.OwnerType ownerType, @Param("ownerId") String ownerId, @Param("keyword") String keyword);
|
||||
|
||||
/// 按归属和名称关键词分页查询标签
|
||||
///
|
||||
/// @param ownerType 归属类型
|
||||
/// @param ownerId 归属 ID
|
||||
/// @param keyword 名称关键词
|
||||
/// @param offset 分页偏移量
|
||||
/// @param limit 分页数量
|
||||
/// @return 标签列表
|
||||
List<Tag> selectByOwnerAndKeyword(@Param("ownerType") Tag.OwnerType ownerType, @Param("ownerId") String ownerId, @Param("keyword") String keyword, @Param("offset") long offset, @Param("limit") long limit);
|
||||
|
||||
Tag selectByOwnerAndZhCN(@Param("ownerType") Tag.OwnerType ownerType, @Param("ownerId") String ownerId, @Param("zhCN") String zhCN);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.imyeyu.api.modules.common.mapper;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.WechatQueue;
|
||||
|
||||
/// 微信队列 Mapper
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
public interface WechatQueueMapper extends BaseQueueMapper<WechatQueue> {
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.imyeyu.api.modules.common.service;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.BaseQueueEntity;
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
|
||||
/// 通知队列基础服务
|
||||
///
|
||||
/// @param <T> 队列实体类型
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
public interface BaseQueueService<T extends BaseQueueEntity> {
|
||||
|
||||
/// 创建队列
|
||||
///
|
||||
/// @param detail 通知详情
|
||||
void createQueue(NotifyDetail detail);
|
||||
|
||||
/// 删除队列
|
||||
///
|
||||
/// @param detail 通知详情
|
||||
void destroyQueue(NotifyDetail detail);
|
||||
|
||||
/// 执行已到期队列
|
||||
void invokeQueue();
|
||||
|
||||
/// 发送队列消息
|
||||
///
|
||||
/// @param queue 队列
|
||||
void send(T queue);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.imyeyu.api.modules.common.service;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.Feedback;
|
||||
import com.imyeyu.spring.service.BaseService;
|
||||
|
||||
/// 通用反馈服务
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-19
|
||||
public interface FeedbackService extends BaseService<Feedback, String> {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.imyeyu.api.modules.common.service;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.HTTPQueue;
|
||||
|
||||
/// HTTP 队列服务
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
public interface HTTPQueueService extends BaseQueueService<HTTPQueue> {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.imyeyu.api.modules.common.service;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.MailQueue;
|
||||
|
||||
/// 邮件队列服务
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
public interface MailQueueService extends BaseQueueService<MailQueue> {
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
package com.imyeyu.api.modules.common.service;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import com.imyeyu.spring.service.BaseService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 通知详情服务
|
||||
*
|
||||
@@ -10,4 +14,53 @@ import com.imyeyu.spring.service.BaseService;
|
||||
* @since 2026-05-13 14:46
|
||||
*/
|
||||
public interface NotifyDetailService extends BaseService<NotifyDetail, String> {
|
||||
|
||||
/// 查询通知下的全部详情
|
||||
///
|
||||
/// @param notifyId 通知 ID
|
||||
/// @return 通知详情列表
|
||||
List<NotifyDetail> listByNotifyId(String notifyId);
|
||||
|
||||
/// 重新将通知详情放入消息队列
|
||||
///
|
||||
/// @param detailId 通知详情 ID
|
||||
void requeue(String detailId);
|
||||
|
||||
/// 分页查询用户的站内通知
|
||||
///
|
||||
/// @param page 分页参数
|
||||
/// @param userId 用户 ID
|
||||
/// @param unreadOnly true 为只查询未读通知
|
||||
/// @return 站内通知分页结果
|
||||
PageResult<NotifyDetail> pageInternalByUserId(Page<NotifyDetail> page, String userId, boolean unreadOnly);
|
||||
|
||||
/// 查询当前用户拥有的站内通知详情
|
||||
///
|
||||
/// @param detailId 通知详情 ID
|
||||
/// @param userId 用户 ID
|
||||
/// @return 通知详情
|
||||
NotifyDetail getInternalByUserId(String detailId, String userId);
|
||||
|
||||
/// 删除当前用户拥有的站内通知详情
|
||||
///
|
||||
/// @param detailId 通知详情 ID
|
||||
/// @param userId 用户 ID
|
||||
void deleteInternalByUserId(String detailId, String userId);
|
||||
|
||||
/// 查询用户未读站内通知数量
|
||||
///
|
||||
/// @param userId 用户 ID
|
||||
/// @return 未读数量
|
||||
long countUnreadSiteByUserId(String userId);
|
||||
|
||||
/// 标记站内通知已读
|
||||
///
|
||||
/// @param userId 用户 ID
|
||||
/// @param detailId 通知详情 ID
|
||||
void markSiteRead(String userId, String detailId);
|
||||
|
||||
/// 标记用户全部站内通知已读
|
||||
///
|
||||
/// @param userId 用户 ID
|
||||
void markAllSiteRead(String userId);
|
||||
}
|
||||
|
||||
@@ -10,4 +10,9 @@ import com.imyeyu.spring.service.BaseService;
|
||||
* @since 2026-05-13 14:46
|
||||
*/
|
||||
public interface NotifyService extends BaseService<Notify, String> {
|
||||
|
||||
/// 取消通知中尚未成功发送的通知详情
|
||||
///
|
||||
/// @param notifyId 通知 ID
|
||||
void cancel(String notifyId);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.imyeyu.api.modules.common.service;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.SmsQueue;
|
||||
|
||||
/// 短信队列服务
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
public interface SmsQueueService extends BaseQueueService<SmsQueue> {
|
||||
}
|
||||
@@ -2,6 +2,8 @@ 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.bean.Page;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import com.imyeyu.spring.service.BaseService;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -15,6 +17,15 @@ public interface TagService extends BaseService<Tag, String> {
|
||||
|
||||
List<Tag> listByIdList(Collection<String> idList);
|
||||
|
||||
/// 按归属和名称关键词分页查询标签
|
||||
///
|
||||
/// @param page 分页参数
|
||||
/// @param ownerType 归属类型
|
||||
/// @param ownerId 归属 ID
|
||||
/// @param keyword 名称关键词
|
||||
/// @return 标签分页
|
||||
PageResult<Tag> pageByOwnerAndKeyword(Page<Tag> page, Tag.OwnerType ownerType, String ownerId, String keyword);
|
||||
|
||||
/// 按业务查询标签列表
|
||||
///
|
||||
/// @param bizType 业务类型
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.imyeyu.api.modules.common.service;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.WechatQueue;
|
||||
|
||||
/// 微信队列服务
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
public interface WechatQueueService extends BaseQueueService<WechatQueue> {
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
import com.imyeyu.api.modules.common.config.NotifyQueueConfig;
|
||||
import com.imyeyu.api.modules.common.entity.BaseQueueEntity;
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.api.modules.common.mapper.BaseQueueMapper;
|
||||
import com.imyeyu.api.modules.common.service.BaseQueueService;
|
||||
import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.utils.Time;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/// 通知队列抽象服务
|
||||
///
|
||||
/// @param <T> 队列实体类型
|
||||
/// @param <C> 队列配置类型
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
@Slf4j
|
||||
public abstract class AbstractQueueService<T extends BaseQueueEntity, C extends NotifyQueueConfig.Queue> implements BaseQueueService<T> {
|
||||
|
||||
private NotifyDetailService notifyDetailService;
|
||||
|
||||
/// 注入通知详情服务
|
||||
@Autowired
|
||||
private void setNotifyDetailService(NotifyDetailService notifyDetailService) {
|
||||
this.notifyDetailService = notifyDetailService;
|
||||
}
|
||||
|
||||
/// 获取队列 Mapper
|
||||
///
|
||||
/// @return 队列 Mapper
|
||||
protected abstract BaseQueueMapper<T> mapper();
|
||||
|
||||
/// 获取队列配置
|
||||
///
|
||||
/// @return 队列配置
|
||||
protected abstract C config();
|
||||
|
||||
/// 校验发送目标
|
||||
///
|
||||
/// @param sendTo 发送目标
|
||||
protected abstract void validateSendTo(String sendTo);
|
||||
|
||||
@Override
|
||||
public void destroyQueue(NotifyDetail detail) {
|
||||
TimiException.required(detail, "未找到通知详情");
|
||||
TimiException.required(detail.getId(), "未找到通知详情 ID");
|
||||
mapper().destroyByNotifyDetailId(detail.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invokeQueue() {
|
||||
for (T queue : mapper().listReadyQueue()) {
|
||||
send(queue);
|
||||
}
|
||||
}
|
||||
|
||||
/// 处理单个队列消息
|
||||
///
|
||||
/// @param queue 队列
|
||||
@Override
|
||||
public final void send(T queue) {
|
||||
TimiException.required(queue, "未找到通知队列");
|
||||
NotifyDetail detail = notifyDetailService.get(queue.getNotifyDetailId());
|
||||
if (detail == null) {
|
||||
mapper().destroy(queue.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
long now = Time.now();
|
||||
queue.setSendAt(now);
|
||||
if (queue.getTimeoutAt() < now) {
|
||||
throw new TimiException(TimiCode.RESULT_TIMEOUT, "通知队列已超时");
|
||||
}
|
||||
validateSendTo(queue.getSendTo());
|
||||
if (!config().isEnable()) {
|
||||
throw new TimiException(TimiCode.IGNORE, "通知队列未启用");
|
||||
}
|
||||
doSend(queue);
|
||||
detail.setStatus(NotifyDetail.Status.REMINDED);
|
||||
} catch (TimiException e) {
|
||||
if (e.getCode() == TimiCode.IGNORE) {
|
||||
detail.setStatus(NotifyDetail.Status.CANCEL);
|
||||
detail.setResultDesc(e.getMessage());
|
||||
} else if (e.getCode() == TimiCode.RESULT_TIMEOUT) {
|
||||
detail.setStatus(NotifyDetail.Status.TIMEOUT);
|
||||
detail.setResultDesc(e.getMessage());
|
||||
} else {
|
||||
log.error("处理通知队列失败", e);
|
||||
detail.setStatus(NotifyDetail.Status.FAIL);
|
||||
detail.setResultDesc(TimiJava.serializeThrowable(e));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("处理通知队列失败", e);
|
||||
detail.setStatus(NotifyDetail.Status.FAIL);
|
||||
detail.setResultDesc(TimiJava.serializeThrowable(e));
|
||||
} finally {
|
||||
try {
|
||||
notifyDetailService.update(detail);
|
||||
if (detail.getStatus() == NotifyDetail.Status.REMINDED
|
||||
|| detail.getStatus() == NotifyDetail.Status.CANCEL
|
||||
|| queue.getRetry() < 0
|
||||
) {
|
||||
mapper().destroy(queue.getId());
|
||||
} else {
|
||||
queue.setRetry(queue.getRetry() - 1);
|
||||
mapper().update(queue);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("通知队列收尾处理失败", e);
|
||||
mapper().destroy(queue.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 执行实际发送动作
|
||||
///
|
||||
/// @param queue 队列
|
||||
/// @throws Exception 发送异常
|
||||
protected abstract void doSend(T queue) throws Exception;
|
||||
}
|
||||
+54
@@ -1,8 +1,15 @@
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.Article;
|
||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||
import com.imyeyu.api.modules.common.mapper.ArticleMapper;
|
||||
import com.imyeyu.api.modules.common.service.ArticleService;
|
||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||
import com.imyeyu.api.modules.system.entity.Logger;
|
||||
import com.imyeyu.api.modules.system.service.LoggerService;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import com.imyeyu.spring.service.AbstractEntityService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -20,10 +27,57 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
public class ArticleServiceImplement extends AbstractEntityService<Article, String> implements ArticleService {
|
||||
|
||||
private final LoggerService loggerService;
|
||||
private final AttachmentService attachmentService;
|
||||
|
||||
private final ArticleMapper mapper;
|
||||
|
||||
@Override
|
||||
protected BaseMapper<Article, String> mapper() {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(Article article) {
|
||||
Logger logger = new Logger(Logger.Module.COMMON, "COMMON_ARTICLE_CREATE");
|
||||
try {
|
||||
super.create(article);
|
||||
attachmentService.updateByBizId(Attachment.BizType.ARTICLE, article.getId(), article.getAttachmentList());
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
logger.setResult(article.getId());
|
||||
} catch (TimiException e) {
|
||||
logger.setLevel(Logger.Level.WARN);
|
||||
logger.setException(e.getMessage());
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
logger.setLevel(Logger.Level.ERROR);
|
||||
logger.setException(TimiJava.serializeThrowable(e));
|
||||
log.error("create article error", e);
|
||||
throw new TimiException(TimiCode.ERROR, "create article error", e);
|
||||
} finally {
|
||||
loggerService.create(logger);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Article article) {
|
||||
Logger logger = new Logger(Logger.Module.COMMON, "COMMON_ARTICLE_UPDATE");
|
||||
try {
|
||||
super.update(article);
|
||||
attachmentService.updateByBizId(Attachment.BizType.ARTICLE, article.getId(), article.getAttachmentList());
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
logger.setResult(article.getId());
|
||||
} catch (TimiException e) {
|
||||
logger.setLevel(Logger.Level.WARN);
|
||||
logger.setException(e.getMessage());
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
logger.setLevel(Logger.Level.ERROR);
|
||||
logger.setException(TimiJava.serializeThrowable(e));
|
||||
log.error("update article error", e);
|
||||
throw new TimiException(TimiCode.ERROR, "update article error", e);
|
||||
} finally {
|
||||
loggerService.create(logger);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -319,12 +319,12 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
||||
|
||||
@Override
|
||||
public List<Attachment> listByBizId(Attachment.BizType bizType, String bizId, String... attachTypes) {
|
||||
return mapper.selectByBizId(bizType, bizId, List.of(attachTypes), null);
|
||||
return mapper.selectAllByBizIdList(bizType, List.of(bizId), List.of(attachTypes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<Attachment>> mapByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, String... attachTypes) {
|
||||
return mapper.selectByBizIdList(bizType, bizIdList, List.of(attachTypes)).stream().collect(Collectors.groupingBy(Attachment::getBizId));
|
||||
return mapper.selectAllByBizIdList(bizType, bizIdList, List.of(attachTypes)).stream().collect(Collectors.groupingBy(Attachment::getBizId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||
import com.imyeyu.api.modules.common.entity.Feedback;
|
||||
import com.imyeyu.api.modules.common.mapper.FeedbackMapper;
|
||||
import com.imyeyu.api.modules.common.service.ArticleService;
|
||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||
import com.imyeyu.api.modules.common.service.FeedbackService;
|
||||
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.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;
|
||||
|
||||
/// 通用反馈服务实现
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-08-19
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class FeedbackServiceImplement extends AbstractEntityService<Feedback, String> implements FeedbackService {
|
||||
|
||||
private static final long ANONYMOUS_ATTACHMENT_MAX_SIZE = 500L * 1024;
|
||||
|
||||
private final LoggerService loggerService;
|
||||
private final ArticleService articleService;
|
||||
private final UserLoginService userLoginService;
|
||||
private final AttachmentService attachmentService;
|
||||
|
||||
private final FeedbackMapper mapper;
|
||||
|
||||
@Override
|
||||
protected BaseMapper<Feedback, String> mapper() {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void create(Feedback feedback) {
|
||||
Logger logger = new Logger(Logger.Module.COMMON, "COMMON_FEEDBACK_CREATE");
|
||||
try {
|
||||
TimiException.required(feedback, "未找到反馈");
|
||||
articleService.create(feedback.getContent());
|
||||
feedback.setContentId(feedback.getContent().getId());
|
||||
feedback.setStatus(TimiJava.defaultIfNull(feedback.getStatus(), Feedback.Status.PENDING));
|
||||
super.create(feedback);
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
logger.setResult(feedback.getId());
|
||||
} catch (TimiException e) {
|
||||
logger.setLevel(Logger.Level.WARN);
|
||||
logger.setException(e.getMessage());
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
logger.setLevel(Logger.Level.ERROR);
|
||||
logger.setException(TimiJava.serializeThrowable(e));
|
||||
log.error("create feedback error", e);
|
||||
throw new TimiException(TimiCode.ERROR, "create feedback error", e);
|
||||
} finally {
|
||||
loggerService.create(logger);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void update(Feedback feedback) {
|
||||
Logger logger = new Logger(Logger.Module.COMMON, "COMMON_FEEDBACK_UPDATE");
|
||||
try {
|
||||
TimiException.required(feedback, "未找到反馈");
|
||||
TimiException.required(feedback.getId(), "未找到反馈 ID");
|
||||
Feedback dbFeedback = get(feedback.getId());
|
||||
TimiException.required(dbFeedback, "未找到反馈");
|
||||
|
||||
feedback.getContent().setId(dbFeedback.getContentId());
|
||||
articleService.update(feedback.getContent());
|
||||
|
||||
dbFeedback.setModule(TimiJava.defaultIfNull(feedback.getModule(), dbFeedback.getModule()));
|
||||
if (TimiJava.isNotEmpty(feedback.getResponse())) {
|
||||
if (TimiJava.isEmpty(feedback.getResponseId())) {
|
||||
articleService.create(feedback.getResponse());
|
||||
dbFeedback.setResponseId(feedback.getResponse().getId());
|
||||
dbFeedback.setRespondedAt(Time.now());
|
||||
} else {
|
||||
feedback.getResponse().setId(dbFeedback.getResponseId());
|
||||
articleService.update(feedback.getResponse());
|
||||
}
|
||||
dbFeedback.setStatus(Feedback.Status.REPLIED);
|
||||
dbFeedback.setRespondedBy(userLoginService.getRequireLoginUserId());
|
||||
}
|
||||
super.update(dbFeedback);
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
logger.setResult(feedback.getId());
|
||||
} catch (TimiException e) {
|
||||
logger.setLevel(Logger.Level.WARN);
|
||||
logger.setException(e.getMessage());
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
logger.setLevel(Logger.Level.ERROR);
|
||||
logger.setException(TimiJava.serializeThrowable(e));
|
||||
log.error("修改反馈失败", 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.COMMON, "COMMON_FEEDBACK_DELETE");
|
||||
try {
|
||||
Feedback feedback = get(id);
|
||||
articleService.delete(feedback.getContentId());
|
||||
if (TimiJava.isNotEmpty(feedback.getResponseId())) {
|
||||
articleService.delete(feedback.getResponseId());
|
||||
}
|
||||
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("delete feedback error", e);
|
||||
throw new TimiException(TimiCode.ERROR, "delete feedback error", e);
|
||||
} finally {
|
||||
loggerService.create(logger);
|
||||
}
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
import com.imyeyu.api.modules.common.config.NotifyQueueConfig;
|
||||
import com.imyeyu.api.modules.common.entity.HTTPQueue;
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.api.modules.common.mapper.BaseQueueMapper;
|
||||
import com.imyeyu.api.modules.common.mapper.HTTPQueueMapper;
|
||||
import com.imyeyu.api.modules.common.service.HTTPQueueService;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/// HTTP 队列服务实现
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class HTTPQueueServiceImplement extends AbstractQueueService<HTTPQueue, NotifyQueueConfig.HTTP> implements HTTPQueueService {
|
||||
|
||||
private final NotifyQueueConfig config;
|
||||
|
||||
private final HTTPQueueMapper mapper;
|
||||
|
||||
@Override
|
||||
protected NotifyQueueConfig.HTTP config() {
|
||||
return config.getHttp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BaseQueueMapper<HTTPQueue> mapper() {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateSendTo(String sendTo) {
|
||||
try {
|
||||
URI uri = URI.create(sendTo);
|
||||
TimiException.requiredTrue(uri.isAbsolute(), "发送目标不是有效 URI");
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new TimiException(TimiCode.ARG_BAD, "发送目标不是有效 URI", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createQueue(NotifyDetail detail) {
|
||||
mapper.insert(new HTTPQueue(detail));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doSend(HTTPQueue queue) {
|
||||
throw new TimiException(TimiCode.ERROR_NOT_SUPPORT, "HTTP 推送暂未实现");
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
import com.imyeyu.api.modules.common.config.NotifyQueueConfig;
|
||||
import com.imyeyu.api.modules.common.entity.MailQueue;
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.api.modules.common.mapper.BaseQueueMapper;
|
||||
import com.imyeyu.api.modules.common.mapper.MailQueueMapper;
|
||||
import com.imyeyu.api.modules.common.service.MailQueueService;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.utils.Regex;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/// 邮件队列服务实现
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MailQueueServiceImplement extends AbstractQueueService<MailQueue, NotifyQueueConfig.Mail> implements MailQueueService {
|
||||
|
||||
private final NotifyQueueConfig config;
|
||||
private final JavaMailSender mailSender;
|
||||
|
||||
private final MailQueueMapper mapper;
|
||||
|
||||
@Override
|
||||
protected NotifyQueueConfig.Mail config() {
|
||||
return config.getMail();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BaseQueueMapper<MailQueue> mapper() {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateSendTo(String sendTo) {
|
||||
TimiException.requiredTrue(Regex.isMatch(Regex.EMAIL, sendTo), "发送目标不是有效邮箱");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createQueue(NotifyDetail detail) {
|
||||
MailQueue queue = new MailQueue(detail);
|
||||
queue.setSendFrom(TimiJava.defaultIfEmpty(queue.getSendFrom(), config.getMail().getDefaultFrom()));
|
||||
mapper.insert(queue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doSend(MailQueue queue) {
|
||||
TimiException.required(queue.getSendFrom(), "邮件发送来源不能为空");
|
||||
TimiException.required(queue.getSubject(), "邮件标题不能为空");
|
||||
|
||||
SimpleMailMessage message = new SimpleMailMessage();
|
||||
message.setFrom(queue.getSendFrom());
|
||||
message.setTo(queue.getSendTo());
|
||||
message.setSubject(queue.getSubject());
|
||||
message.setText(queue.getData());
|
||||
mailSender.send(message);
|
||||
log.info("邮件发送成功,目标:{}", queue.getSendTo());
|
||||
}
|
||||
}
|
||||
+176
@@ -1,12 +1,24 @@
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.api.modules.common.entity.Notify;
|
||||
import com.imyeyu.api.modules.common.mapper.NotifyDetailMapper;
|
||||
import com.imyeyu.api.modules.common.mapper.NotifyMapper;
|
||||
import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
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.List;
|
||||
|
||||
/**
|
||||
* 通知详情服务实现
|
||||
@@ -18,10 +30,174 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
public class NotifyDetailServiceImplement extends AbstractEntityService<NotifyDetail, String> implements NotifyDetailService {
|
||||
|
||||
private final NotifyMapper notifyMapper;
|
||||
|
||||
private final NotifyDetailMapper mapper;
|
||||
|
||||
@Override
|
||||
protected BaseMapper<NotifyDetail, String> mapper() {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
/// 创建通知详情,同时初始化投递状态和时间参数
|
||||
///
|
||||
/// @param detail 通知详情
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void create(NotifyDetail detail) {
|
||||
TimiException.required(detail, "未找到通知详情");
|
||||
TimiException.required(detail.getNotifyId(), "未找到通知 ID");
|
||||
TimiException.required(detail.getMsgType(), "未找到消息类型");
|
||||
Notify notify = notifyMapper.select(detail.getNotifyId());
|
||||
TimiException.required(notify, "未找到通知");
|
||||
if (detail.getMsgType() == NotifyDetail.MsgType.INTERNAL) {
|
||||
TimiException.required(detail.getSendTo(), "未找到站内通知接收用户 ID");
|
||||
}
|
||||
|
||||
detail.setRetry(TimiJava.defaultIfNull(detail.getRetry(), 1));
|
||||
detail.setSendAt(TimiJava.defaultIfNull(detail.getSendAt(), Time.now()));
|
||||
detail.setTimeoutAt(TimiJava.defaultIfNull(detail.getTimeoutAt(), detail.getSendAt() + Time.D));
|
||||
detail.setStatus(detail.getMsgType() == NotifyDetail.MsgType.INTERNAL
|
||||
? NotifyDetail.Status.REMINDED
|
||||
: NotifyDetail.Status.WAITING);
|
||||
detail.setReadAt(null);
|
||||
super.create(detail);
|
||||
|
||||
if (detail.getMsgType().isQueue()) {
|
||||
// 加入外部消息队列
|
||||
detail.getMsgType().getService().createQueue(detail);
|
||||
}
|
||||
}
|
||||
|
||||
/// 查询通知下的全部详情
|
||||
///
|
||||
/// @param notifyId 通知 ID
|
||||
/// @return 通知详情列表
|
||||
@Override
|
||||
public List<NotifyDetail> listByNotifyId(String notifyId) {
|
||||
NotifyDetail example = new NotifyDetail();
|
||||
example.setNotifyId(notifyId);
|
||||
return mapper.selectAllByExample(example);
|
||||
}
|
||||
|
||||
/// 删除通知详情
|
||||
///
|
||||
/// @param detailId 通知详情 ID
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void delete(String detailId) {
|
||||
TimiException.required(detailId, "未找到通知详情 ID");
|
||||
NotifyDetail detail = get(detailId);
|
||||
TimiException.required(detail, "未找到通知详情");
|
||||
if (detail.getMsgType().isQueue()) {
|
||||
detail.getMsgType().getService().destroyQueue(detail);
|
||||
}
|
||||
super.delete(detailId);
|
||||
}
|
||||
|
||||
/// 重新将通知详情放入消息队列
|
||||
///
|
||||
/// @param detailId 通知详情 ID
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void requeue(String detailId) {
|
||||
NotifyDetail detail = get(detailId);
|
||||
TimiException.required(detail, "未找到通知详情");
|
||||
TimiException.required(detail.getMsgType(), "未找到消息类型");
|
||||
TimiException.requiredTrue(detail.getMsgType().isQueue(), "站内通知不支持重新入队");
|
||||
if (detail.getStatus() == NotifyDetail.Status.WAITING) {
|
||||
throw new TimiException(TimiCode.RESULT_BAD, "通知详情已经在等待队列中");
|
||||
}
|
||||
|
||||
detail.getMsgType().getService().destroyQueue(detail);
|
||||
detail.setStatus(NotifyDetail.Status.WAITING);
|
||||
detail.setResultDesc(null);
|
||||
detail.setRetry(1);
|
||||
detail.setSendAt(Time.now());
|
||||
detail.setTimeoutAt(detail.getSendAt() + Time.D);
|
||||
update(detail);
|
||||
|
||||
// 加入消息队列
|
||||
detail.getMsgType().getService().createQueue(detail);
|
||||
}
|
||||
|
||||
/// 分页查询用户的站内通知
|
||||
///
|
||||
/// @param page 分页参数
|
||||
/// @param userId 用户 ID
|
||||
/// @param unreadOnly true 为只查询未读通知
|
||||
/// @return 站内通知分页结果
|
||||
@Override
|
||||
public PageResult<NotifyDetail> pageInternalByUserId(Page<NotifyDetail> page, String userId, boolean unreadOnly) {
|
||||
TimiException.required(userId, "未找到用户 ID");
|
||||
Page<NotifyDetail> validPage = TimiJava.defaultIfNull(page, new Page<>());
|
||||
PageResult<NotifyDetail> result = new PageResult<>();
|
||||
result.setTotal(unreadOnly
|
||||
? mapper.countUnreadSiteByUserId(userId)
|
||||
: mapper.countSiteByUserId(userId));
|
||||
result.setList(unreadOnly
|
||||
? mapper.selectUnreadSiteByUserId(userId, validPage.getOffset(), validPage.getLimit())
|
||||
: mapper.selectSiteByUserId(userId, validPage.getOffset(), validPage.getLimit()));
|
||||
return result;
|
||||
}
|
||||
|
||||
/// 查询当前用户拥有的站内通知详情
|
||||
///
|
||||
/// @param detailId 通知详情 ID
|
||||
/// @param userId 用户 ID
|
||||
/// @return 通知详情
|
||||
@Override
|
||||
public NotifyDetail getInternalByUserId(String detailId, String userId) {
|
||||
TimiException.required(detailId, "未找到通知详情 ID");
|
||||
TimiException.required(userId, "未找到用户 ID");
|
||||
NotifyDetail detail = mapper.selectSiteByIdAndUserId(detailId, userId);
|
||||
TimiException.required(detail, "未找到站内通知");
|
||||
return detail;
|
||||
}
|
||||
|
||||
/// 删除当前用户拥有的站内通知详情
|
||||
///
|
||||
/// @param detailId 通知详情 ID
|
||||
/// @param userId 用户 ID
|
||||
@Override
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
public void deleteInternalByUserId(String detailId, String userId) {
|
||||
TimiException.required(detailId, "未找到通知详情 ID");
|
||||
TimiException.required(userId, "未找到用户 ID");
|
||||
int affected = mapper.deleteSiteByIdAndUserId(detailId, userId);
|
||||
TimiException.requiredTrue(0 < affected, "未找到站内通知");
|
||||
}
|
||||
|
||||
/// 查询用户未读站内通知数量
|
||||
///
|
||||
/// @param userId 用户 ID
|
||||
/// @return 未读数量
|
||||
@Override
|
||||
public long countUnreadSiteByUserId(String userId) {
|
||||
TimiException.required(userId, "未找到用户 ID");
|
||||
return mapper.countUnreadSiteByUserId(userId);
|
||||
}
|
||||
|
||||
/// 标记站内通知已读
|
||||
///
|
||||
/// @param userId 用户 ID
|
||||
/// @param detailId 通知详情 ID
|
||||
@Override
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
public void markSiteRead(String userId, String detailId) {
|
||||
TimiException.required(userId, "未找到用户 ID");
|
||||
TimiException.required(detailId, "未找到通知详情 ID");
|
||||
TimiException.required(mapper.selectSiteByIdAndUserId(detailId, userId), "未找到站内通知");
|
||||
mapper.markSiteRead(detailId, userId, Time.now());
|
||||
}
|
||||
|
||||
/// 标记用户全部站内通知已读
|
||||
///
|
||||
/// @param userId 用户 ID
|
||||
@Override
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
public void markAllSiteRead(String userId) {
|
||||
TimiException.required(userId, "未找到用户 ID");
|
||||
mapper.markAllSiteRead(userId, Time.now());
|
||||
}
|
||||
}
|
||||
|
||||
+117
@@ -1,12 +1,25 @@
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||
import com.imyeyu.api.modules.common.entity.Notify;
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.api.modules.common.mapper.NotifyMapper;
|
||||
import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
||||
import com.imyeyu.api.modules.common.service.NotifyService;
|
||||
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.mapper.BaseMapper;
|
||||
import com.imyeyu.spring.service.AbstractEntityService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 通知服务实现
|
||||
@@ -14,14 +27,118 @@ import org.springframework.stereotype.Service;
|
||||
* @author 夜雨
|
||||
* @since 2026-05-13 14:46
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class NotifyServiceImplement extends AbstractEntityService<Notify, String> implements NotifyService {
|
||||
|
||||
private final LoggerService loggerService;
|
||||
private final UserLoginService userLoginService;
|
||||
private final NotifyDetailService detailService;
|
||||
|
||||
private final NotifyMapper mapper;
|
||||
|
||||
@Override
|
||||
protected BaseMapper<Notify, String> mapper() {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
/// 创建通知并级联创建通知详情
|
||||
///
|
||||
/// @param notify 通知
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void create(Notify notify) {
|
||||
Logger logger = new Logger(Logger.Module.COMMON, "COMMON_NOTIFY_CREATE");
|
||||
try {
|
||||
TimiException.required(notify, "未找到通知");
|
||||
TimiException.required(notify.getDetailList(), "未找到通知详情列表");
|
||||
super.create(notify);
|
||||
|
||||
String sendFrom = null;
|
||||
if (userLoginService.isLogged()) {
|
||||
sendFrom = userLoginService.getRequireLoginUserId();
|
||||
}
|
||||
for (NotifyDetail detail : notify.getDetailList()) {
|
||||
detail.setNotifyId(notify.getId());
|
||||
if (TimiJava.isNotEmpty(sendFrom)) {
|
||||
detail.setSendFrom(sendFrom);
|
||||
}
|
||||
detailService.create(detail);
|
||||
}
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
logger.setResult(notify.getId());
|
||||
} catch (TimiException e) {
|
||||
logger.setLevel(Logger.Level.WARN);
|
||||
logger.setException(e.getMessage());
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
logger.setLevel(Logger.Level.ERROR);
|
||||
logger.setException(TimiJava.serializeThrowable(e));
|
||||
log.error("创建通知失败", e);
|
||||
throw new TimiException(TimiCode.ERROR, "创建通知失败", e);
|
||||
} finally {
|
||||
loggerService.create(logger);
|
||||
}
|
||||
}
|
||||
|
||||
/// 删除通知并级联软删除通知详情
|
||||
///
|
||||
/// @param notifyId 通知 ID
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void delete(String notifyId) {
|
||||
Logger logger = new Logger(Logger.Module.COMMON, "COMMON_NOTIFY_DELETE");
|
||||
try {
|
||||
TimiException.required(notifyId, "未找到通知 ID");
|
||||
TimiException.required(get(notifyId), "未找到通知");
|
||||
List<NotifyDetail> detailList = detailService.listByNotifyId(notifyId);
|
||||
for (NotifyDetail detail : detailList) {
|
||||
detailService.delete(detail.getId());
|
||||
}
|
||||
super.delete(notifyId);
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
logger.setResult(notifyId);
|
||||
} 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("删除通知失败", e);
|
||||
throw new TimiException(TimiCode.ERROR, "删除通知失败", e);
|
||||
} finally {
|
||||
loggerService.create(logger);
|
||||
}
|
||||
}
|
||||
|
||||
/// 取消通知中尚未成功发送的通知详情
|
||||
///
|
||||
/// @param notifyId 通知 ID
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void cancel(String notifyId) {
|
||||
TimiException.required(notifyId, "未找到通知 ID");
|
||||
TimiException.required(get(notifyId), "未找到通知");
|
||||
|
||||
boolean canceled = false;
|
||||
for (NotifyDetail detail : detailService.listByNotifyId(notifyId)) {
|
||||
if (detail.getStatus() == NotifyDetail.Status.REMINDED
|
||||
|| detail.getStatus() == NotifyDetail.Status.CANCEL
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (detail.getMsgType() != null && detail.getMsgType().isQueue()) {
|
||||
detail.getMsgType().getService().destroyQueue(detail);
|
||||
}
|
||||
detail.setStatus(NotifyDetail.Status.CANCEL);
|
||||
detail.setResultDesc("通知已取消");
|
||||
detailService.update(detail);
|
||||
canceled = true;
|
||||
}
|
||||
if (!canceled) {
|
||||
throw new TimiException(TimiCode.RESULT_BAD, "通知没有可取消的通知详情");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.imyeyu.api.modules.common.config.NotifyQueueConfig;
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.api.modules.common.entity.SmsQueue;
|
||||
import com.imyeyu.api.modules.common.mapper.BaseQueueMapper;
|
||||
import com.imyeyu.api.modules.common.mapper.SmsQueueMapper;
|
||||
import com.imyeyu.api.modules.common.service.SmsQueueService;
|
||||
import com.imyeyu.api.modules.common.util.QCloudSmsProxy;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendStatus;
|
||||
import com.imyeyu.utils.Regex;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/// 短信队列服务实现
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SmsQueueServiceImplement extends AbstractQueueService<SmsQueue, NotifyQueueConfig.Sms> implements SmsQueueService {
|
||||
|
||||
private final NotifyQueueConfig config;
|
||||
private final ObjectMapper jackson;
|
||||
private final QCloudSmsProxy smsProxy;
|
||||
|
||||
private final SmsQueueMapper mapper;
|
||||
|
||||
@Override
|
||||
protected NotifyQueueConfig.Sms config() {
|
||||
return config.getSms();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BaseQueueMapper<SmsQueue> mapper() {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateSendTo(String sendTo) {
|
||||
TimiException.requiredTrue(Regex.isMatch(Regex.MOBILE_PHONE, sendTo), "发送目标不是手机号");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createQueue(NotifyDetail detail) {
|
||||
mapper.insert(new SmsQueue(detail));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doSend(SmsQueue queue) {
|
||||
try {
|
||||
String[] args = new String[0];
|
||||
if (queue.getArgs() != null && !queue.getArgs().isBlank()) {
|
||||
JsonNode argsNode = jackson.readTree(queue.getArgs());
|
||||
TimiException.requiredTrue(argsNode != null && argsNode.isArray(), "短信参数必须是数组");
|
||||
args = jackson.treeToValue(argsNode, String[].class);
|
||||
}
|
||||
SendSmsResponse response = smsProxy.send(queue.getSendTo(), queue.getTemplateId(), args);
|
||||
TimiException.required(response, "未找到短信响应");
|
||||
SendStatus[] statusSet = response.getSendStatusSet();
|
||||
TimiException.requiredTrue(statusSet != null && 0 < statusSet.length, "短信响应为空");
|
||||
if (!"ok".equalsIgnoreCase(statusSet[0].getCode())) {
|
||||
throw new TimiException(TimiCode.ERROR, jackson.writeValueAsString(response));
|
||||
}
|
||||
} catch (TimiException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new TimiException(TimiCode.ERROR, "短信发送失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -7,6 +7,8 @@ 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.bean.Page;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import com.imyeyu.spring.service.AbstractEntityService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -70,6 +72,14 @@ public class TagServiceImplement extends AbstractEntityService<Tag, String> impl
|
||||
return mapper.selectByIdList(new HashSet<>(idList));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Tag> pageByOwnerAndKeyword(Page<Tag> page, Tag.OwnerType ownerType, String ownerId, String keyword) {
|
||||
PageResult<Tag> result = new PageResult<>();
|
||||
result.setTotal(mapper.countByOwnerAndKeyword(ownerType, ownerId, keyword));
|
||||
result.setList(mapper.selectByOwnerAndKeyword(ownerType, ownerId, keyword, page.getOffset(), page.getLimit()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> listByBizType(TagApply.BizType bizType, String bizId) {
|
||||
return listByIdList(listApply(bizType, bizId).stream().map(TagApply::getTagId).toList());
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
import com.imyeyu.api.modules.common.config.NotifyQueueConfig;
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.api.modules.common.entity.WechatQueue;
|
||||
import com.imyeyu.api.modules.common.mapper.BaseQueueMapper;
|
||||
import com.imyeyu.api.modules.common.mapper.WechatQueueMapper;
|
||||
import com.imyeyu.api.modules.common.service.WechatQueueService;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/// 微信队列服务实现
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class WechatQueueServiceImplement extends AbstractQueueService<WechatQueue, NotifyQueueConfig.Wechat> implements WechatQueueService {
|
||||
|
||||
private final NotifyQueueConfig config;
|
||||
|
||||
private final WechatQueueMapper mapper;
|
||||
|
||||
@Override
|
||||
protected NotifyQueueConfig.Wechat config() {
|
||||
return config.getWechat();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BaseQueueMapper<WechatQueue> mapper() {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateSendTo(String sendTo) {
|
||||
TimiException.required(sendTo, "发送目标不能为空");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createQueue(NotifyDetail detail) {
|
||||
mapper.insert(new WechatQueue(detail));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doSend(WechatQueue queue) {
|
||||
throw new TimiException(TimiCode.ERROR_NOT_SUPPORT, "微信推送暂未实现");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.imyeyu.api.modules.common.task;
|
||||
|
||||
import com.imyeyu.api.modules.common.config.NotifyQueueConfig;
|
||||
import com.imyeyu.api.modules.common.service.MailQueueService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/// 邮件队列定时任务
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MailQueueTask implements SchedulingConfigurer {
|
||||
|
||||
private final NotifyQueueConfig config;
|
||||
|
||||
private final MailQueueService service;
|
||||
|
||||
private boolean running;
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
if (!config.getMail().isEnable()) {
|
||||
log.warn("邮件队列任务已禁用");
|
||||
return;
|
||||
}
|
||||
taskRegistrar.addTriggerTask(() -> {
|
||||
if (running) {
|
||||
log.info("邮件队列任务正在运行,跳过本次执行");
|
||||
return;
|
||||
}
|
||||
running = true;
|
||||
try {
|
||||
service.invokeQueue();
|
||||
} finally {
|
||||
running = false;
|
||||
}
|
||||
}, triggerContext -> new CronTrigger(config.getMail().getCron()).nextExecution(triggerContext));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.imyeyu.api.modules.common.task;
|
||||
|
||||
import com.imyeyu.api.modules.common.config.NotifyQueueConfig;
|
||||
import com.imyeyu.api.modules.common.service.SmsQueueService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/// 短信队列定时任务
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SmsQueueTask implements SchedulingConfigurer {
|
||||
|
||||
private final NotifyQueueConfig config;
|
||||
|
||||
private final SmsQueueService service;
|
||||
|
||||
private boolean running;
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
if (!config.getSms().isEnable()) {
|
||||
log.warn("短信队列任务已禁用");
|
||||
return;
|
||||
}
|
||||
taskRegistrar.addTriggerTask(() -> {
|
||||
if (running) {
|
||||
log.info("短信队列任务正在运行,跳过本次执行");
|
||||
return;
|
||||
}
|
||||
running = true;
|
||||
try {
|
||||
service.invokeQueue();
|
||||
} finally {
|
||||
running = false;
|
||||
}
|
||||
}, triggerContext -> new CronTrigger(config.getSms().getCron()).nextExecution(triggerContext));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.imyeyu.api.modules.common.task;
|
||||
|
||||
/// 微信队列定时任务占位
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
public class WechatQueueTask {
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.imyeyu.api.modules.common.util;
|
||||
|
||||
import com.imyeyu.api.modules.common.config.NotifyQueueConfig;
|
||||
import com.tencentcloudapi.common.Credential;
|
||||
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
||||
import com.tencentcloudapi.common.profile.ClientProfile;
|
||||
import com.tencentcloudapi.common.profile.HttpProfile;
|
||||
import com.tencentcloudapi.sms.v20210111.SmsClient;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/// 腾讯云短信服务代理
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class QCloudSmsProxy {
|
||||
|
||||
private final NotifyQueueConfig config;
|
||||
|
||||
/// 发送短信
|
||||
///
|
||||
/// @param mobilePhone 手机号
|
||||
/// @param templateId 模板 ID
|
||||
/// @param args 模板参数
|
||||
/// @return 腾讯云短信响应
|
||||
/// @throws TencentCloudSDKException 腾讯云 SDK 调用异常
|
||||
public SendSmsResponse send(String mobilePhone, String templateId, String[] args) throws TencentCloudSDKException {
|
||||
return send(List.of(mobilePhone), templateId, args);
|
||||
}
|
||||
|
||||
/// 批量发送短信
|
||||
///
|
||||
/// @param mobilePhoneList 手机号列表
|
||||
/// @param templateId 模板 ID
|
||||
/// @param args 模板参数
|
||||
/// @return 腾讯云短信响应
|
||||
/// @throws TencentCloudSDKException 腾讯云 SDK 调用异常
|
||||
public SendSmsResponse send(List<String> mobilePhoneList, String templateId, String[] args) throws TencentCloudSDKException {
|
||||
SmsClient client = createSmsClient();
|
||||
NotifyQueueConfig.Sms sms = config.getSms();
|
||||
|
||||
SendSmsRequest request = new SendSmsRequest();
|
||||
request.setSmsSdkAppId(sms.getAppId().trim());
|
||||
request.setSignName(sms.getSign().trim());
|
||||
request.setTemplateId(templateId);
|
||||
request.setTemplateParamSet(args);
|
||||
request.setPhoneNumberSet(mobilePhoneList.toArray(new String[0]));
|
||||
return client.SendSms(request);
|
||||
}
|
||||
|
||||
private SmsClient createSmsClient() {
|
||||
NotifyQueueConfig.Sms sms = config.getSms();
|
||||
Credential credential = new Credential(sms.getSecretId().trim(), sms.getSecretKey().trim());
|
||||
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setReqMethod("GET");
|
||||
httpProfile.setConnTimeout(10);
|
||||
httpProfile.setWriteTimeout(10);
|
||||
httpProfile.setReadTimeout(10);
|
||||
httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
||||
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setSignMethod("HmacSHA256");
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
return new SmsClient(credential, "ap-guangzhou", clientProfile);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.imyeyu.api.modules.common.util;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.BaseQueueEntity;
|
||||
import com.imyeyu.spring.util.SQLProvider;
|
||||
import com.imyeyu.utils.Time;
|
||||
import org.apache.ibatis.builder.annotation.ProviderContext;
|
||||
|
||||
/// 通知队列 SQL 提供器
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-20
|
||||
public class QueueSQLProvider extends SQLProvider {
|
||||
|
||||
/// 查询已到发送时间的队列
|
||||
///
|
||||
/// @param context Mapper 上下文
|
||||
/// @return 查询 SQL
|
||||
public String listReadyQueue(ProviderContext context) {
|
||||
EntityMeta meta = getEntityMeta(context);
|
||||
StringBuilder sql = new StringBuilder("SELECT * FROM %s WHERE 1 = 1".formatted(meta.getTable()));
|
||||
if (BaseQueueEntity.class.isAssignableFrom(meta.getEntityClass())) {
|
||||
sql.append(" AND `send_at` < %d".formatted(Time.now()));
|
||||
}
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
/// 根据通知详情 ID 物理删除队列
|
||||
///
|
||||
/// @param context Mapper 上下文
|
||||
/// @return 删除 SQL
|
||||
public String destroyByNotifyDetailId(ProviderContext context) {
|
||||
EntityMeta meta = getEntityMeta(context);
|
||||
return "DELETE FROM %s WHERE `notify_detail_id` = #{notifyDetailId}".formatted(meta.getTable());
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public enum GaoPermissionCode implements BuiltinPermissionCode {
|
||||
@Getter
|
||||
final boolean grantToStoreManager;
|
||||
|
||||
/// `true` 为初始化时授权给全局管理员角色
|
||||
/// `true` 为初始化时授权给门店管理角色
|
||||
@Getter
|
||||
final boolean grantToGlobalManager;
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ import lombok.AllArgsConstructor;
|
||||
@AllArgsConstructor
|
||||
public enum GaoRoleCode implements BuiltinRoleCode {
|
||||
|
||||
/// 全局管理员
|
||||
GLOBAL_MANAGER("全局管理员", null),
|
||||
/// 门店管理
|
||||
GLOBAL_MANAGER("门店管理", null),
|
||||
|
||||
/// 店长
|
||||
STORE_MANAGER("店长", GLOBAL_MANAGER.name());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -62,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
|
||||
|
||||
@@ -16,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;
|
||||
@@ -64,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());
|
||||
@@ -80,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)
|
||||
|
||||
@@ -21,6 +21,8 @@ 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
|
||||
@@ -78,6 +80,19 @@ public class GaoPointRuleController {
|
||||
ruleService.update(rule);
|
||||
}
|
||||
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireGaoPermission(GaoPermissionCode.POINT_RULE_UPDATE)
|
||||
@PostMapping("/rule/sort")
|
||||
public void sort(@RequestBody List<String> idList) {
|
||||
if (idList != null) {
|
||||
for (GaoPointRule rule : ruleService.listByIdList(idList)) {
|
||||
checkStore(rule.getStoreId());
|
||||
}
|
||||
}
|
||||
ruleService.sort(idList);
|
||||
}
|
||||
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireGaoPermission(GaoPermissionCode.POINT_RULE_DELETE)
|
||||
|
||||
@@ -7,6 +7,7 @@ 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.GaoEventRecordNumberValueDailyStatView;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoStoreChartReq;
|
||||
import com.imyeyu.spring.annotation.AOPLog;
|
||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||
@@ -57,6 +58,15 @@ public class GaoStoreChartController {
|
||||
return service.eventRecordDailyStat(req);
|
||||
}
|
||||
|
||||
/// 查询登记事件每日数值合计
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||
@PostMapping("/event/record/number-value/daily")
|
||||
public List<GaoEventRecordNumberValueDailyStatView> eventRecordNumberValueDaily(@RequestBody GaoStoreChartReq req) {
|
||||
return service.eventRecordNumberValueDailyStat(req);
|
||||
}
|
||||
|
||||
/// 查询登记事件日历记录
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
|
||||
@@ -50,10 +50,16 @@ public class GaoTagController {
|
||||
@PostMapping("/list")
|
||||
public PageResult<Tag> list(@RequestBody Page<Tag> page) {
|
||||
TimiException.required(page, "未找到分页参数");
|
||||
String ownerId = null;
|
||||
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());
|
||||
ownerId = storeService.getBelongIdByRequiredLoginUserId();
|
||||
page.getEqualsExample().setOwnerId(ownerId);
|
||||
}
|
||||
String keyword = page.getLikesExample() == null ? null : page.getLikesExample().getName();
|
||||
if (TimiJava.isNotEmpty(keyword)) {
|
||||
return service.pageByOwnerAndKeyword(page, Tag.OwnerType.GAO_STORE, ownerId, keyword.trim());
|
||||
}
|
||||
return service.page(page);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,14 @@ 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;
|
||||
@@ -17,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;
|
||||
@@ -32,6 +42,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/// GAO 用户接口
|
||||
///
|
||||
@@ -46,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)
|
||||
@@ -85,7 +123,9 @@ public class GaoUserController {
|
||||
{
|
||||
User user = userService.get(result.getUserId());
|
||||
user.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.USER, user.getId()));
|
||||
user.setRoleList(userRoleService.listAllRoleCodeByUserId(user.getId()));
|
||||
user.setRoleEntityList(userRoleService.listRoleByUserId(user.getId()));
|
||||
user.setPermissionList(userRoleService.listAllPermissionCodeByUserId(user.getId()));
|
||||
result.setUser(user);
|
||||
}
|
||||
return result;
|
||||
@@ -137,6 +177,7 @@ public class GaoUserController {
|
||||
@RequireGaoPermission(GaoPermissionCode.USER_READ)
|
||||
@PostMapping("/role/list")
|
||||
public List<Role> roleList() {
|
||||
// TODO 此接口获取本模块所有角色,需要限制角色
|
||||
return roleService.listByModuleCode(ModuleCode.GAO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.imyeyu.api.modules.gao.entity;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||
import com.imyeyu.api.modules.common.entity.TagApply;
|
||||
import com.imyeyu.api.modules.user.bean.Gender;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
@@ -30,7 +31,11 @@ public class GaoCustomer extends UUIDEntity {
|
||||
/// @since 2026-07-27
|
||||
public enum AttachType {
|
||||
|
||||
PHOTO
|
||||
PHOTO,
|
||||
|
||||
POINT_CARD,
|
||||
|
||||
OTHER
|
||||
}
|
||||
|
||||
///
|
||||
@@ -105,6 +110,9 @@ public class GaoCustomer extends UUIDEntity {
|
||||
@Transient
|
||||
private List<GaoEventRecord> eventRecordList;
|
||||
|
||||
@Transient
|
||||
private TagApply tagApply;
|
||||
|
||||
public boolean hasIntroducer() {
|
||||
return TimiJava.isNotEmpty(introducerCustomerId);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -52,10 +61,6 @@ public class GaoEventRecord extends UUIDEntity {
|
||||
/// 营业日递增序号
|
||||
private Long businessDayNo;
|
||||
|
||||
/// 本次登记提交的积分值,只参与积分触发,不落库
|
||||
@Transient
|
||||
private Long pointValue;
|
||||
|
||||
@Transient
|
||||
private GaoCustomer customer;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class GaoPointLedger extends UUIDEntity {
|
||||
/// 流水变化类型
|
||||
public enum ChangeType {
|
||||
|
||||
/// 登记事件获得积分
|
||||
/// 登记事件积分变化
|
||||
EARN,
|
||||
|
||||
/// 删除登记记录撤销积分
|
||||
|
||||
@@ -42,7 +42,10 @@ public class GaoPointRule extends UUIDEntity {
|
||||
AFTER_COUNT_EVERY_TIME,
|
||||
|
||||
/// 使用登记接口提交的积分值触发
|
||||
SOURCE_VALUE
|
||||
SOURCE_VALUE,
|
||||
|
||||
/// 按来源事件数值累计分档触发
|
||||
CUSTOMER_EVENT_VALUE_TIER
|
||||
}
|
||||
|
||||
/// 积分值模式
|
||||
@@ -52,7 +55,10 @@ public class GaoPointRule extends UUIDEntity {
|
||||
FIXED,
|
||||
|
||||
/// 使用登记接口提交的积分值
|
||||
SOURCE_VALUE
|
||||
SOURCE_VALUE,
|
||||
|
||||
/// 使用条件配置中的分档积分值
|
||||
TIER
|
||||
}
|
||||
|
||||
/// 门店 ID
|
||||
|
||||
@@ -5,6 +5,7 @@ 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.GaoEventRecordNumberValueDailyStatView;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoEventRecordPage;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoEventRecordRankPage;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoStoreChartReq;
|
||||
@@ -21,6 +22,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
|
||||
@@ -42,6 +65,12 @@ public interface GaoEventRecordMapper extends BaseMapper<GaoEventRecord, String>
|
||||
/// @return 登记事件记录列表
|
||||
List<GaoEventRecord> selectByRange(GaoEventRecordPage page);
|
||||
|
||||
/// 按登记记录列表条件汇总数值
|
||||
///
|
||||
/// @param page 登记记录范围查询请求
|
||||
/// @return 登记数值合计
|
||||
Long sumNumberValueByRange(GaoEventRecordPage page);
|
||||
|
||||
/// 统计客户登记排行榜总数
|
||||
///
|
||||
/// @param page 排行榜分页请求
|
||||
@@ -60,6 +89,9 @@ public interface GaoEventRecordMapper extends BaseMapper<GaoEventRecord, String>
|
||||
/// @return 每日登记数
|
||||
List<GaoEventRecordDailyStatView> stateDailyByRange(GaoStoreChartReq req);
|
||||
|
||||
/// 按时间范围和事件统计每日登记数值合计
|
||||
List<GaoEventRecordNumberValueDailyStatView> stateNumberValueDailyByRange(GaoStoreChartReq req);
|
||||
|
||||
/// 按时间范围查询登记日历记录
|
||||
///
|
||||
/// @param req 门店报表查询请求
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.imyeyu.api.modules.gao.entity.GaoPointRule;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/// GAO 客户积分规则 Mapper
|
||||
@@ -12,6 +13,8 @@ import java.util.List;
|
||||
/// @since 2026-08-11
|
||||
public interface GaoPointRuleMapper extends BaseMapper<GaoPointRule, String> {
|
||||
|
||||
List<GaoPointRule> selectByIdList(Collection<String> idList);
|
||||
|
||||
/// 查询当前时间可匹配的启用规则
|
||||
///
|
||||
/// @param storeId 门店 ID
|
||||
|
||||
@@ -18,6 +18,12 @@ import java.util.List;
|
||||
/// @since 2026-07-27 14:09
|
||||
public interface GaoEventRecordService extends BaseService<GaoEventRecord, String> {
|
||||
|
||||
/// 按客户查询登记事件记录
|
||||
///
|
||||
/// @param customerId 客户 ID
|
||||
/// @return 登记事件记录列表
|
||||
List<GaoEventRecord> listByCustomerId(String customerId);
|
||||
|
||||
default void createBatch(List<GaoEventRecord> recordList) {
|
||||
for (GaoEventRecord record : TimiJava.safeIterable(recordList)) {
|
||||
create(record);
|
||||
@@ -32,6 +38,12 @@ public interface GaoEventRecordService extends BaseService<GaoEventRecord, Strin
|
||||
/// @return 登记事件记录列表
|
||||
PageResult<GaoEventRecord> pageByRange(GaoEventRecordPage req);
|
||||
|
||||
/// 按登记记录列表条件汇总数值
|
||||
///
|
||||
/// @param req 登记记录范围查询请求
|
||||
/// @return 登记数值合计
|
||||
Long sumNumberValueByRange(GaoEventRecordPage req);
|
||||
|
||||
/// 按时间范围查询客户登记排行榜
|
||||
///
|
||||
/// @param page 范围查询请求,不传时间为全部时间
|
||||
|
||||
@@ -19,6 +19,17 @@ public interface GaoPointRuleService extends BaseService<GaoPointRule, String> {
|
||||
/// @return 规则列表
|
||||
List<GaoPointRule> listActive(String storeId, String eventId, long now);
|
||||
|
||||
/// 查询规则 ID 列表
|
||||
///
|
||||
/// @param idList 规则 ID 列表
|
||||
/// @return 规则列表
|
||||
List<GaoPointRule> listByIdList(List<String> idList);
|
||||
|
||||
/// 按客户端提交的顺序更新启用规则优先级
|
||||
///
|
||||
/// @param idList 规则 ID 列表
|
||||
void sort(List<String> idList);
|
||||
|
||||
/// 创建积分规则
|
||||
///
|
||||
/// @param rule 积分规则
|
||||
|
||||
@@ -4,6 +4,7 @@ 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.GaoEventRecordNumberValueDailyStatView;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoStoreChartReq;
|
||||
|
||||
import java.util.List;
|
||||
@@ -23,6 +24,9 @@ public interface GaoStoreChartService {
|
||||
/// 查询登记事件每日统计
|
||||
List<GaoEventRecordDailyStatView> eventRecordDailyStat(GaoStoreChartReq req);
|
||||
|
||||
/// 查询登记事件每日数值合计
|
||||
List<GaoEventRecordNumberValueDailyStatView> eventRecordNumberValueDailyStat(GaoStoreChartReq req);
|
||||
|
||||
/// 查询登记事件日历记录
|
||||
List<GaoEventRecordCalendarView> eventRecordCalendar(GaoStoreChartReq req);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
+41
-1
@@ -3,10 +3,16 @@ 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.common.entity.Attachment;
|
||||
import com.imyeyu.api.modules.common.entity.TagApply;
|
||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||
import com.imyeyu.api.modules.common.service.TagService;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoPointAccount;
|
||||
import com.imyeyu.api.modules.gao.mapper.GaoCustomerMapper;
|
||||
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||
import com.imyeyu.api.modules.gao.service.GaoEventRecordService;
|
||||
import com.imyeyu.api.modules.gao.service.GaoPointAccountService;
|
||||
import com.imyeyu.api.modules.gao.util.CustomerXSSFBuilder;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
||||
@@ -24,6 +30,7 @@ import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import com.imyeyu.spring.service.AbstractEntityService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -54,9 +61,12 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
||||
|
||||
private final ObjectMapper jackson;
|
||||
|
||||
private final TagService tagService;
|
||||
private final LoggerService loggerService;
|
||||
private final UserLoginService userLoginService;
|
||||
private final AttachmentService attachmentService;
|
||||
private final GaoPointAccountService pointAccountService;
|
||||
private final ObjectProvider<GaoEventRecordService> eventRecordServiceProvider;
|
||||
|
||||
private final GaoCustomerMapper mapper;
|
||||
|
||||
@@ -111,6 +121,10 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
||||
customer.setCreatorUserId(userLoginService.getRequireLoginUserId());
|
||||
|
||||
super.create(customer);
|
||||
// 标签
|
||||
if (customer.getTagApply() != null) {
|
||||
tagService.apply(TagApply.BizType.GAO_CUSTOMER, customer.getId(), customer.getTagApply().getTagIdList());
|
||||
}
|
||||
// 附件
|
||||
attachmentService.updateByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId(), customer.getAttachmentList());
|
||||
|
||||
@@ -168,6 +182,11 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
||||
dbCustomer.setConditioningPart(customer.getConditioningPart());
|
||||
mapper.update(dbCustomer);
|
||||
|
||||
// 标签
|
||||
if (customer.getTagApply() != null) {
|
||||
tagService.apply(TagApply.BizType.GAO_CUSTOMER, customer.getId(), customer.getTagApply().getTagIdList());
|
||||
}
|
||||
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
logger.setResult(customer.getId());
|
||||
} catch (TimiException e) {
|
||||
@@ -191,7 +210,28 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
||||
try {
|
||||
logger.setContent(id);
|
||||
GaoCustomer customer = get(id);
|
||||
TimiException.required(customer, "not found customer");
|
||||
// 登记事件
|
||||
GaoEventRecordService eventRecordService = eventRecordServiceProvider.getObject();
|
||||
for (GaoEventRecord record : eventRecordService.listByCustomerId(customer.getId())) {
|
||||
eventRecordService.delete(record.getId());
|
||||
}
|
||||
// 积分账户
|
||||
GaoPointAccount account = pointAccountService.getByCustomerId(customer.getStoreId(), customer.getId());
|
||||
if (account != null) {
|
||||
pointAccountService.delete(account.getId());
|
||||
}
|
||||
// 邀请人
|
||||
for (GaoCustomer invitedCustomer : listInvited(customer.getId())) {
|
||||
invitedCustomer.setIntroducerCustomerId(null);
|
||||
mapper.update(invitedCustomer);
|
||||
}
|
||||
// 标签
|
||||
tagService.apply(TagApply.BizType.GAO_CUSTOMER, customer.getId(), List.of());
|
||||
// 附件
|
||||
attachmentService.deleteByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId());
|
||||
super.delete(id);
|
||||
// 邀请来源计数
|
||||
changeInvitedCount(customer.getIntroducerCustomerId(), -1);
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
logger.setResult(id);
|
||||
@@ -377,7 +417,7 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
||||
}
|
||||
|
||||
private void changeInvitedCount(String customerId, long delta) {
|
||||
if (delta == 0) {
|
||||
if (TimiJava.isEmpty(customerId) || delta == 0) {
|
||||
return;
|
||||
}
|
||||
GaoCustomer customer = get(customerId);
|
||||
|
||||
+66
-18
@@ -10,9 +10,9 @@ 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.GaoPointTriggerService;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreBusinessDayService;
|
||||
import com.imyeyu.api.modules.gao.util.EventRecordXSSFBuilder;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerEventRankView;
|
||||
@@ -63,8 +63,8 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
|
||||
private final UserLoginService userLoginService;
|
||||
private final AttachmentService attachmentService;
|
||||
private final GaoCustomerService customerService;
|
||||
private final GaoStoreBusinessDayService businessDayService;
|
||||
private final GaoPointTriggerService pointTriggerService;
|
||||
private final GaoStoreBusinessDayService businessDayService;
|
||||
|
||||
private final GaoEventRecordMapper mapper;
|
||||
|
||||
@@ -75,6 +75,14 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GaoEventRecord> listByCustomerId(String customerId) {
|
||||
TimiException.required(customerId, "not found customerId");
|
||||
GaoEventRecord example = new GaoEventRecord();
|
||||
example.setCustomerId(customerId);
|
||||
return mapper.selectAllByExample(example);
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void create(GaoEventRecord record) {
|
||||
@@ -87,7 +95,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);
|
||||
@@ -119,6 +129,8 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
|
||||
dbRecord.setRegisteredDateValue(registeredDateValue);
|
||||
dbRecord.setBusinessDayNo(businessDayNo);
|
||||
dbRecord.setPointValue(record.getPointValue());
|
||||
dbRecord.setNumberValue(record.getNumberValue());
|
||||
dbRecord.setEarnedPointValue(0L);
|
||||
super.create(dbRecord);
|
||||
// 附件
|
||||
if (i == 0) {
|
||||
@@ -170,24 +182,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());
|
||||
@@ -215,6 +220,7 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
|
||||
GaoEventRecord record = get(id);
|
||||
TimiException.required(record, "not found event record");
|
||||
pointTriggerService.revokeByEventRecord(record);
|
||||
attachmentService.deleteByBizId(Attachment.BizType.GAO_EVENT_RECORD, record.getId());
|
||||
super.delete(id);
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
logger.setResult(id);
|
||||
@@ -269,6 +275,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");
|
||||
@@ -279,13 +291,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(), "登记事件未配置可登记角色");
|
||||
@@ -302,7 +330,7 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
|
||||
long today = Time.today(registeredAt);
|
||||
long noon = today + Time.D / 2;
|
||||
long beginAt = today, endAt;
|
||||
if (today + registeredAt < noon) {
|
||||
if (registeredAt < noon) {
|
||||
// 上半日
|
||||
endAt = noon;
|
||||
} else {
|
||||
@@ -343,6 +371,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());
|
||||
|
||||
+2
-2
@@ -74,7 +74,7 @@ public class GaoPointLedgerServiceImplement extends AbstractEntityService<GaoPoi
|
||||
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");
|
||||
TimiException.requiredTrue(pointDelta != 0, "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());
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class GaoPointLedgerServiceImplement extends AbstractEntityService<GaoPoi
|
||||
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");
|
||||
TimiException.requiredTrue(originLedger.getPointDelta() != 0, "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());
|
||||
}
|
||||
|
||||
+100
-3
@@ -16,6 +16,11 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/// GAO 客户积分规则服务实现
|
||||
///
|
||||
@@ -25,6 +30,8 @@ import java.util.List;
|
||||
@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;
|
||||
|
||||
@@ -40,6 +47,32 @@ public class GaoPointRuleServiceImplement extends AbstractEntityService<GaoPoint
|
||||
return mapper.selectActiveByStoreIdAndEventId(storeId, eventId, now);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GaoPointRule> listByIdList(List<String> idList) {
|
||||
if (TimiJava.isEmpty(idList)) {
|
||||
return List.of();
|
||||
}
|
||||
return mapper.selectByIdList(new LinkedHashSet<>(idList));
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void sort(List<String> idList) {
|
||||
if (TimiJava.isEmpty(idList)) {
|
||||
return;
|
||||
}
|
||||
List<String> distinctIdList = new ArrayList<>(new LinkedHashSet<>(idList));
|
||||
Map<String, GaoPointRule> ruleMap = mapper.selectByIdList(new LinkedHashSet<>(distinctIdList)).stream()
|
||||
.collect(Collectors.toMap(GaoPointRule::getId, Function.identity()));
|
||||
TimiException.requiredTrue(ruleMap.size() == distinctIdList.size(), "积分规则列表包含不存在的规则");
|
||||
for (int i = 0; i < distinctIdList.size(); i++) {
|
||||
GaoPointRule rule = ruleMap.get(distinctIdList.get(i));
|
||||
TimiException.requiredTrue(rule.getStatus() == GaoPointRule.Status.ACTIVE, "只能调整启用规则排序");
|
||||
rule.setPriority(i);
|
||||
mapper.update(rule);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void create(GaoPointRule rule) {
|
||||
@@ -116,9 +149,16 @@ public class GaoPointRuleServiceImplement extends AbstractEntityService<GaoPoint
|
||||
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");
|
||||
TimiException.requiredTrue(rule.getPointValue() != 0, "rule.pointValue invalid");
|
||||
if (rule.getTriggerType() == GaoPointRule.TriggerType.AFTER_COUNT_EVERY_TIME) {
|
||||
JsonNode condition = requireObjectCondition(rule.getConditionJson());
|
||||
JsonNode threshold = condition.get("threshold");
|
||||
@@ -131,15 +171,72 @@ public class GaoPointRuleServiceImplement extends AbstractEntityService<GaoPoint
|
||||
}
|
||||
}
|
||||
|
||||
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 类型");
|
||||
TimiException.required(sourceEvent.getValueUnit(), "TIER 来源事件必须配置数值单位");
|
||||
|
||||
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 (0 < i) {
|
||||
TimiException.requiredTrue(previousMax != null && 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(), "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 || min != 0, "SOURCE_VALUE.min invalid");
|
||||
TimiException.requiredTrue(max == null || max != 0, "SOURCE_VALUE.max invalid");
|
||||
TimiException.requiredTrue(min == null || max == null || min <= max, "SOURCE_VALUE.min or SOURCE_VALUE.max invalid");
|
||||
TimiException.requiredTrue(min == null || max == null || (min < 0) == (max < 0), "SOURCE_VALUE.min or SOURCE_VALUE.max direction invalid");
|
||||
}
|
||||
|
||||
private JsonNode requireObjectCondition(JsonNode conditionJson) {
|
||||
|
||||
+71
-22
@@ -6,16 +6,16 @@ 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.GaoPointLedger;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoPointRule;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
||||
import com.imyeyu.api.modules.gao.mapper.GaoPointLedgerMapper;
|
||||
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.service.GaoCustomerService;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoPointAdjustRequest;
|
||||
import com.imyeyu.api.modules.user.service.PermissionChecker;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
@@ -26,6 +26,9 @@ 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;
|
||||
@@ -51,26 +54,34 @@ public class GaoPointTriggerServiceImplement implements GaoPointTriggerService {
|
||||
@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 pointDeltaTotal = 0L;
|
||||
for (GaoPointRule rule : ruleList) {
|
||||
Long pointDelta = resolvePointDelta(record, rule, count);
|
||||
if (pointDelta == null) {
|
||||
RuleResolution resolution = resolveRule(record, rule, count);
|
||||
if (resolution == null) {
|
||||
continue;
|
||||
}
|
||||
if (count == null) {
|
||||
count = eventRecordMapper.count(record.getStoreId(), record.getCustomerId(), record.getEventId(), null, null);
|
||||
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 (pointDelta != 0) {
|
||||
ledgerService.earn(record, rule, pointDelta, resolution.sourcePayload());
|
||||
pointDeltaTotal = Math.addExact(pointDeltaTotal, pointDelta);
|
||||
}
|
||||
JsonNode sourcePayload = sourcePayload(record, rule, pointDelta);
|
||||
ledgerService.earn(record, rule, pointDelta, sourcePayload);
|
||||
if (Boolean.TRUE.equals(rule.getExclusive())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
record.setEarnedPointValue(pointDeltaTotal);
|
||||
eventRecordMapper.updateEarnedPointValue(record.getId(), pointDeltaTotal);
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@@ -104,31 +115,32 @@ public class GaoPointTriggerServiceImplement implements GaoPointTriggerService {
|
||||
return ledgerService.adjust(request, userLoginService.getRequireLoginUserId());
|
||||
}
|
||||
|
||||
private Long resolvePointDelta(GaoEventRecord record, GaoPointRule rule, Long count) {
|
||||
private RuleResolution resolveRule(GaoEventRecord record, GaoPointRule rule, Long count) {
|
||||
return switch (rule.getTriggerType()) {
|
||||
case EVERY_TIME -> rule.getPointValue();
|
||||
case EVERY_TIME -> new RuleResolution(rule.getPointValue(), null);
|
||||
case FIRST_TIME -> {
|
||||
long currentCount = count == null ? count(record) : count;
|
||||
yield currentCount == 1 ? rule.getPointValue() : null;
|
||||
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 ? rule.getPointValue() : null : threshold < currentCount ? rule.getPointValue() : null;
|
||||
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 Long resolveSourceValue(GaoEventRecord record, GaoPointRule 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");
|
||||
TimiException.requiredTrue(pointValue != 0, "pointValue invalid");
|
||||
JsonNode condition = rule.getConditionJson();
|
||||
if (condition != null) {
|
||||
JsonNode min = condition.get("min");
|
||||
@@ -136,17 +148,51 @@ public class GaoPointTriggerServiceImplement implements GaoPointTriggerService {
|
||||
TimiException.requiredTrue(min == null || min.isNull() || min.longValue() <= pointValue, "pointValue 小于规则最小值");
|
||||
TimiException.requiredTrue(max == null || max.isNull() || pointValue <= max.longValue(), "pointValue 大于规则最大值");
|
||||
}
|
||||
return pointValue;
|
||||
ObjectNode payload = jackson.createObjectNode();
|
||||
payload.put("submittedPointValue", pointValue);
|
||||
payload.put("validatedPointValue", pointValue);
|
||||
return new RuleResolution(pointValue, payload);
|
||||
}
|
||||
|
||||
private JsonNode sourcePayload(GaoEventRecord record, GaoPointRule rule, long pointDelta) {
|
||||
if (rule.getTriggerType() != GaoPointRule.TriggerType.SOURCE_VALUE) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (matchedTier == null) {
|
||||
return null;
|
||||
}
|
||||
long pointDelta = matchedTier.get("pointValue").longValue();
|
||||
ObjectNode payload = jackson.createObjectNode();
|
||||
payload.put("submittedPointValue", record.getPointValue());
|
||||
payload.put("validatedPointValue", pointDelta);
|
||||
return payload;
|
||||
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) {
|
||||
@@ -156,4 +202,7 @@ public class GaoPointTriggerServiceImplement implements GaoPointTriggerService {
|
||||
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) {
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -8,6 +8,7 @@ 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.GaoEventRecordNumberValueDailyStatView;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoStoreChartReq;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -48,6 +49,12 @@ public class GaoStoreChartServiceImplement implements GaoStoreChartService {
|
||||
return eventRecordMapper.stateDailyByRange(req);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GaoEventRecordNumberValueDailyStatView> eventRecordNumberValueDailyStat(GaoStoreChartReq req) {
|
||||
checkRangeReq(req);
|
||||
return eventRecordMapper.stateNumberValueDailyByRange(req);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GaoEventRecordCalendarView> eventRecordCalendar(GaoStoreChartReq req) {
|
||||
checkRangeReq(req);
|
||||
|
||||
+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");
|
||||
|
||||
@@ -29,6 +29,9 @@ public class GaoCustomerEventRankView {
|
||||
/// 最近连续登记天数
|
||||
private Long recentContinuousEventDays;
|
||||
|
||||
/// 登记数值合计
|
||||
private Long totalNumberValue;
|
||||
|
||||
/// 最后登记时间
|
||||
private Long latestRegisteredAt;
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/// 登记事件数值每日统计视图
|
||||
@Data
|
||||
public class GaoEventRecordNumberValueDailyStatView {
|
||||
|
||||
/// 登记事件 ID
|
||||
private String eventId;
|
||||
|
||||
/// 日期值,格式为 yyyyMMdd
|
||||
private Integer dateValue;
|
||||
|
||||
/// 当日登记数值合计
|
||||
private Long dailyNumberValue;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -41,6 +41,8 @@ public class GaoEventRecordRankPage extends BasePage {
|
||||
/// 按累计登记次数
|
||||
TOTAL_COUNT,
|
||||
/// 按最近连续登记天数
|
||||
CONTINUOUS_DAYS
|
||||
CONTINUOUS_DAYS,
|
||||
/// 按登记数值合计
|
||||
TOTAL_NUMBER_VALUE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.imyeyu.api.modules.user.service;
|
||||
|
||||
import com.e2ins.ms.notify.vo.sms.CaptchaVerifyReq;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import com.imyeyu.api.modules.user.vo.LoginRequest;
|
||||
import com.imyeyu.api.modules.user.vo.LoginResponse;
|
||||
@@ -23,6 +24,8 @@ public interface UserLoginService {
|
||||
|
||||
LoginResponse login(String token, String userId);
|
||||
|
||||
LoginResponse loginBySms(CaptchaVerifyReq req);
|
||||
|
||||
/**
|
||||
* 根据令牌获取用户
|
||||
*
|
||||
@@ -32,6 +35,10 @@ public interface UserLoginService {
|
||||
return getLoginUser(TimiSpring.getToken());
|
||||
}
|
||||
|
||||
default boolean isLogged() {
|
||||
return getLoginUser() != null;
|
||||
}
|
||||
|
||||
User getLoginUser(String token);
|
||||
|
||||
/**
|
||||
|
||||
+30
-12
@@ -1,5 +1,8 @@
|
||||
package com.imyeyu.api.modules.user.service.implement;
|
||||
|
||||
import com.e2ins.ms.notify.SmsNotifyService;
|
||||
import com.e2ins.ms.notify.bean.NotifyDetail;
|
||||
import com.e2ins.ms.notify.vo.sms.CaptchaVerifyReq;
|
||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||
import com.imyeyu.api.modules.common.entity.Setting;
|
||||
@@ -7,17 +10,18 @@ import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||
import com.imyeyu.api.modules.common.service.SettingService;
|
||||
import com.imyeyu.api.modules.user.bean.BootstrapData;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
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.LoginRequest;
|
||||
import com.imyeyu.api.modules.user.vo.LoginResponse;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.spring.TimiSpring;
|
||||
import com.imyeyu.spring.util.Redis;
|
||||
import com.imyeyu.utils.Digest;
|
||||
import com.imyeyu.utils.Regex;
|
||||
import com.imyeyu.utils.Time;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -26,6 +30,7 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@@ -38,15 +43,14 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
||||
public class UserLoginServiceImplement implements UserLoginService, TimiJava {
|
||||
|
||||
private static final String REGEX_PHONE_NO = "^1\\d{10}$";
|
||||
private static final String USER_TOKEN_KEY_PREFIX = "USER:TOKEN:";
|
||||
private static final String PHONE_VERIFY_KEY_PREFIX = "USER:PHONE:VERIFY:";
|
||||
private static final long PHONE_VERIFY_CODE_TTL = Time.M * 5;
|
||||
|
||||
private final UserService userService;
|
||||
private final RoleService roleService;
|
||||
private final SettingService settingService;
|
||||
private final UserRoleService userRoleService;
|
||||
private final SmsNotifyService smsNotifyService;
|
||||
private final AttachmentService attachmentService;
|
||||
|
||||
private final Redis<String, String> redisUserToken;
|
||||
@@ -61,7 +65,7 @@ public class UserLoginServiceImplement implements UserLoginService, TimiJava {
|
||||
User dbUser = userService.get(req.getUser());
|
||||
if (dbUser == null && req.getUser().contains("@")) {
|
||||
dbUser = userService.getByVerifiedEmail(req.getUser());
|
||||
} else if (dbUser == null && isPhoneNo(req.getUser())) {
|
||||
} else if (dbUser == null && Regex.isMatch(Regex.MOBILE_PHONE, req.getUser())) {
|
||||
dbUser = userService.getByVerifiedPhoneNo(req.getUser());
|
||||
} else if (dbUser == null) {
|
||||
dbUser = userService.getByName(req.getUser());
|
||||
@@ -98,6 +102,24 @@ public class UserLoginServiceImplement implements UserLoginService, TimiJava {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public LoginResponse loginBySms(CaptchaVerifyReq req) {
|
||||
try {
|
||||
NotifyDetail detail = smsNotifyService.captchaVerify(req);
|
||||
// 无报错即成功
|
||||
User user = userService.getByPhoneNo(detail.getSendTo());
|
||||
if (!user.isValidPhone()) {
|
||||
user.setPhoneNoVerifyAt(Time.now());
|
||||
userService.update(user);
|
||||
}
|
||||
return login(UUID.randomUUID().toString(), user.getId());
|
||||
} catch (IOException e) {
|
||||
log.error("login by sms error", e);
|
||||
throw new TimiException(TimiCode.ERROR, "验证短信失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getLoginUser(String token) {
|
||||
if (TimiJava.isEmpty(token)) {
|
||||
@@ -143,8 +165,8 @@ public class UserLoginServiceImplement implements UserLoginService, TimiJava {
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void sendPhoneVerifyCode(String phoneNo) {
|
||||
TimiException.requiredTrue(isPhoneNo(phoneNo), "invalid phone number");
|
||||
User verifiedUser = userService.getByVerifiedPhoneNo(phoneNo);
|
||||
TimiException.requiredTrue(Regex.isMatch(Regex.MOBILE_PHONE, phoneNo), "invalid phone number");
|
||||
User verifiedUser = userService.getByPhoneNo(phoneNo);
|
||||
User loginUser = getRequireLoginUser();
|
||||
TimiException.requiredTrue(verifiedUser == null || verifiedUser.getId().equals(loginUser.getId()), "existed phone number");
|
||||
|
||||
@@ -156,11 +178,11 @@ public class UserLoginServiceImplement implements UserLoginService, TimiJava {
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public void verifyPhoneNo(String phoneNo, String verifyCode) {
|
||||
TimiException.requiredTrue(isPhoneNo(phoneNo), "invalid phone number");
|
||||
TimiException.requiredTrue(Regex.isMatch(Regex.MOBILE_PHONE, phoneNo), "invalid phone number");
|
||||
TimiException.required(verifyCode, "not found verify code");
|
||||
|
||||
User user = getRequireLoginUser();
|
||||
User verifiedUser = userService.getByVerifiedPhoneNo(phoneNo);
|
||||
User verifiedUser = userService.getByPhoneNo(phoneNo);
|
||||
TimiException.requiredTrue(verifiedUser == null || verifiedUser.getId().equals(user.getId()), "existed phone number");
|
||||
|
||||
String cacheCode = redisUserPhoneVerify.get(getPhoneVerifyKey(phoneNo));
|
||||
@@ -188,10 +210,6 @@ public class UserLoginServiceImplement implements UserLoginService, TimiJava {
|
||||
userService.delete(user.getId());
|
||||
}
|
||||
|
||||
private boolean isPhoneNo(String value) {
|
||||
return TimiJava.isNotEmpty(value) && value.matches(REGEX_PHONE_NO);
|
||||
}
|
||||
|
||||
private String getPhoneVerifyKey(String phoneNo) {
|
||||
return "%s%s".formatted(PHONE_VERIFY_KEY_PREFIX, phoneNo);
|
||||
}
|
||||
|
||||
+2
-2
@@ -57,7 +57,7 @@ public class UserServiceImplement extends AbstractEntityService<User, String> im
|
||||
{
|
||||
if (TimiJava.isNotEmpty(user.getPhoneNo())) {
|
||||
TimiException.requiredTrue(user.isValidPhone(), "invalid phone");
|
||||
User byPhoneNo = getByVerifiedPhoneNo(user.getPhoneNo());
|
||||
User byPhoneNo = getByPhoneNo(user.getPhoneNo());
|
||||
TimiException.requiredNull(byPhoneNo, "existed phone number");
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class UserServiceImplement extends AbstractEntityService<User, String> im
|
||||
if (TimiJava.isNotEmpty(phoneNo)) {
|
||||
TimiException.requiredTrue(user.isValidPhone(), "invalid phone");
|
||||
if (!phoneNo.equals(dbUser.getPhoneNo())) {
|
||||
User byPhoneNo = getByVerifiedPhoneNo(phoneNo);
|
||||
User byPhoneNo = getByPhoneNo(phoneNo);
|
||||
TimiException.requiredTrue(byPhoneNo == null || byPhoneNo.getId().equals(dbUser.getId()), "existed phone number");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,3 +51,24 @@ cors:
|
||||
# 允许访问的客户端域名,如:http://web.xxx.com,* 表示不做任何限制(不做任何限制时 allow-credentials 无效)
|
||||
allow-origin:
|
||||
- "http://localhost:8080"
|
||||
|
||||
# 通知消息队列
|
||||
notify:
|
||||
queue:
|
||||
mail:
|
||||
enable: false
|
||||
cron: "*/10 * * * * *"
|
||||
default-from:
|
||||
sms:
|
||||
enable: false
|
||||
cron: "*/10 * * * * *"
|
||||
app-id:
|
||||
sign:
|
||||
secret-id:
|
||||
secret-key:
|
||||
wechat:
|
||||
enable: false
|
||||
cron: "*/10 * * * * *"
|
||||
http:
|
||||
enable: false
|
||||
cron: "*/10 * * * * *"
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
ALTER TABLE `gao_event`
|
||||
ADD COLUMN `value_type` VARCHAR(16) NOT NULL DEFAULT 'NONE' COMMENT '数值类型,NONE 不携带数值,NUMBER 携带整数数值' AFTER `description`,
|
||||
ADD COLUMN `value_unit` VARCHAR(16) NULL COMMENT '数值单位,CENT 金额分,COUNT 次数' AFTER `value_type`,
|
||||
ADD COLUMN `require_value` BOOLEAN NOT NULL DEFAULT FALSE COMMENT 'true 为登记时必须提交 numberValue' AFTER `value_unit`;
|
||||
|
||||
ALTER TABLE `gao_event_record`
|
||||
ADD COLUMN `point_value` BIGINT NULL COMMENT '本次登记提交的积分值' AFTER `operator_user_id`,
|
||||
ADD COLUMN `earned_point_value` BIGINT NOT NULL DEFAULT 0 COMMENT '本次登记通过积分规则获得的积分总和' AFTER `point_value`,
|
||||
ADD COLUMN `number_value` BIGINT NULL COMMENT '本次登记提交的整数业务数值' AFTER `earned_point_value`,
|
||||
ADD KEY `idx_gao_event_record_value_sum` (`store_id`, `customer_id`, `event_id`, `deleted_at`, `registered_at`);
|
||||
@@ -0,0 +1,21 @@
|
||||
CREATE TABLE `feedback` (
|
||||
`id` CHAR(36) NOT NULL COMMENT '主键',
|
||||
`module` VARCHAR(32) NOT NULL COMMENT '所属模块',
|
||||
`user_id` CHAR(36) NULL COMMENT '提交用户 ID,匿名反馈为空',
|
||||
`content_id` VARCHAR(36) NOT NULL COMMENT '反馈内容文章 ID',
|
||||
`contact` VARCHAR(255) NULL COMMENT '联系方式',
|
||||
`ip` VARCHAR(64) NULL COMMENT '提交 IP',
|
||||
`status` VARCHAR(16) NOT NULL DEFAULT 'PENDING' COMMENT '处理状态',
|
||||
`response_id` VARCHAR(36) NULL COMMENT '管理员回复文章 ID',
|
||||
`responded_by` CHAR(36) NULL COMMENT '回复用户 ID',
|
||||
`responded_at` BIGINT NULL COMMENT '回复时间',
|
||||
`created_at` BIGINT NOT NULL COMMENT '创建时间',
|
||||
`updated_at` BIGINT NOT NULL COMMENT '更新时间',
|
||||
`deleted_at` BIGINT NULL COMMENT '删除时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_feedback_module_status_created` (`module`, `status`, `created_at`),
|
||||
KEY `idx_feedback_user_created` (`user_id`, `created_at`),
|
||||
KEY `idx_feedback_content_id` (`content_id`),
|
||||
KEY `idx_feedback_response_id` (`response_id`),
|
||||
KEY `idx_feedback_deleted_at` (`deleted_at`)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT = '通用反馈';
|
||||
@@ -0,0 +1,72 @@
|
||||
ALTER TABLE `notify_detail`
|
||||
ADD COLUMN `read_at` BIGINT(20) COMMENT '已读时间' AFTER `status`,
|
||||
ADD INDEX `idx_site_user_read`(`msg_type` ASC, `send_to` ASC, `read_at` ASC, `created_at` ASC) USING BTREE;
|
||||
|
||||
CREATE TABLE `sms_queue` (
|
||||
`id` VARCHAR(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`notify_detail_id` VARCHAR(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '所属通知详情 ID',
|
||||
`template_id` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '模板 ID',
|
||||
`data` LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '内容',
|
||||
`args` LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '参数',
|
||||
`send_to` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '发送去向',
|
||||
`send_at` BIGINT(20) COMMENT '发送时间',
|
||||
`retry` INT(11) COMMENT '重试计数',
|
||||
`timeout_at` BIGINT(20) COMMENT '超时时间',
|
||||
`created_at` BIGINT(20) COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_notify_detail_id`(`notify_detail_id` ASC) USING BTREE,
|
||||
INDEX `idx_send_at`(`send_at` ASC) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '短信推送队列' ROW_FORMAT = Dynamic;
|
||||
|
||||
CREATE TABLE `mail_queue` (
|
||||
`id` VARCHAR(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`notify_detail_id` VARCHAR(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '所属通知详情 ID',
|
||||
`subject` LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '标题',
|
||||
`data` LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '内容',
|
||||
`args` LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '参数',
|
||||
`attachments` LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '附件',
|
||||
`send_from` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '发送来源',
|
||||
`send_to` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '发送去向',
|
||||
`send_at` BIGINT(20) COMMENT '发送时间',
|
||||
`retry` INT(11) COMMENT '重试计数',
|
||||
`timeout_at` BIGINT(20) COMMENT '超时时间',
|
||||
`created_at` BIGINT(20) COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_notify_detail_id`(`notify_detail_id` ASC) USING BTREE,
|
||||
INDEX `idx_send_at`(`send_at` ASC) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT = '邮件推送队列' ROW_FORMAT = Dynamic;
|
||||
|
||||
CREATE TABLE `http_queue` (
|
||||
`id` VARCHAR(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`notify_detail_id` VARCHAR(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '所属通知详情 ID',
|
||||
`data` LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '内容',
|
||||
`method` VARCHAR(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '请求方法',
|
||||
`args` LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '参数',
|
||||
`send_to` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '发送去向',
|
||||
`send_at` BIGINT(20) COMMENT '发送时间',
|
||||
`retry` INT(11) COMMENT '重试计数',
|
||||
`timeout_at` BIGINT(20) COMMENT '超时时间',
|
||||
`created_at` BIGINT(20) COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_notify_detail_id`(`notify_detail_id` ASC) USING BTREE,
|
||||
INDEX `idx_send_at`(`send_at` ASC) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT = 'HTTP 推送队列' ROW_FORMAT = Dynamic;
|
||||
|
||||
CREATE TABLE `wechat_queue` (
|
||||
`id` VARCHAR(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`notify_detail_id` VARCHAR(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '所属通知详情 ID',
|
||||
`app_id` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '微信 AppId',
|
||||
`app_secret` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '微信 AppSecret',
|
||||
`template_id` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '模板 ID',
|
||||
`subject` LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '标题',
|
||||
`data` LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '内容',
|
||||
`args` LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '参数',
|
||||
`send_to` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '发送去向',
|
||||
`send_at` BIGINT(20) COMMENT '发送时间',
|
||||
`retry` INT(11) COMMENT '重试计数',
|
||||
`timeout_at` BIGINT(20) COMMENT '超时时间',
|
||||
`created_at` BIGINT(20) COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_notify_detail_id`(`notify_detail_id` ASC) USING BTREE,
|
||||
INDEX `idx_send_at`(`send_at` ASC) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT = '微信消息推送队列' ROW_FORMAT = Dynamic;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user