Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b98dcdfe9 | ||
|
|
1e62576d36 | ||
|
|
b373cbbe46 | ||
|
|
bb5abcb48e | ||
|
|
acd97c7b9b | ||
|
|
4a549e77cb | ||
|
|
118bdb1666 | ||
|
|
461af4d581 | ||
|
|
37dc1c9904 | ||
|
|
3a4386261c | ||
|
|
01d33a1122 | ||
|
|
db2fca5715 | ||
|
|
f3166f0413 | ||
|
|
41f692aad9 | ||
|
|
df16ac3c8e | ||
|
|
913dc3d278 | ||
|
|
731c777b8b | ||
|
|
944de228f7 | ||
|
|
a81c8476e7 | ||
|
|
25c9cd4dfc | ||
|
|
e7cf1a72e3 | ||
|
|
882cd226ec | ||
|
|
eec665109e | ||
|
|
f6a2f5a6f5 | ||
|
|
9ba610de86 | ||
|
|
e59dc363f4 | ||
|
|
eeb7b5b32e | ||
|
|
b4b6a13f8d | ||
|
|
4a7de1909c | ||
|
|
b7fcecfa7b | ||
|
|
3b68e6dd85 | ||
|
|
feb4d7af66 | ||
|
|
5cfcd24657 | ||
|
|
712118556b | ||
|
|
d75ab1ed5f | ||
|
|
4496619eeb | ||
|
|
c85b400a94 | ||
|
|
94c99e3444 | ||
|
|
44c2095d77 | ||
|
|
a501eb7443 | ||
|
|
35ec38ed9c | ||
|
|
2b5be16ad7 | ||
|
|
d747a0fdae | ||
|
|
9f884e2b74 | ||
|
|
0239697a2b | ||
|
|
2b11bdf65e | ||
|
|
19941d9480 | ||
|
|
81933d4e61 | ||
|
|
43d76040d8 | ||
|
|
cd3d522d4f | ||
|
|
8de739cbb7 | ||
|
|
181c5078e9 | ||
|
|
e2e0023d13 | ||
|
|
8c6eed2379 | ||
|
|
c32ecd1f8c | ||
|
|
3c56e21efa | ||
|
|
376f0ecd05 | ||
|
|
e97f46e6b4 | ||
|
|
a208947a1b | ||
|
|
c0f89deb83 | ||
|
|
fc62663f2c | ||
|
|
fcae2eac09 | ||
|
|
2e9225852d | ||
|
|
3a3809b661 | ||
|
|
1b8936f197 | ||
|
|
ce695463d3 | ||
|
|
aff056712e | ||
|
|
af18b0999d | ||
|
|
83c683d473 | ||
|
|
4963988ec2 | ||
|
|
9555474b0b | ||
|
|
022185079c | ||
|
|
acc3f05f12 | ||
|
|
a150f9e017 | ||
|
|
a523df6a07 | ||
|
|
31c583eeb5 | ||
|
|
e3ef3e5275 | ||
|
|
84190b9773 | ||
|
|
7808d22775 | ||
|
|
fba559cd22 | ||
|
|
ecd2fa1c33 | ||
|
|
dcc75efa87 | ||
|
|
a9465299a9 | ||
|
|
42152c7b79 | ||
|
|
1a896ef457 | ||
|
|
9d8990a028 | ||
|
|
17d88fc338 | ||
|
|
bb40f347a3 | ||
|
|
e3236d262d | ||
|
|
3d4e32e5da |
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<groupId>com.imyeyu.timiserverapi</groupId>
|
<groupId>com.imyeyu.timiserverapi</groupId>
|
||||||
<artifactId>TimiServerAPI</artifactId>
|
<artifactId>TimiServerAPI</artifactId>
|
||||||
<version>1.0.15</version>
|
<version>1.0.34</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>TimiServerAPI</name>
|
<name>TimiServerAPI</name>
|
||||||
<description>imyeyu.com API</description>
|
<description>imyeyu.com API</description>
|
||||||
@@ -180,6 +180,11 @@
|
|||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.groovy</groupId>
|
||||||
|
<artifactId>groovy</artifactId>
|
||||||
|
<version>4.0.29</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.spring</groupId>
|
<groupId>com.imyeyu.spring</groupId>
|
||||||
<artifactId>timi-spring</artifactId>
|
<artifactId>timi-spring</artifactId>
|
||||||
@@ -198,17 +203,22 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.java</groupId>
|
<groupId>com.imyeyu.java</groupId>
|
||||||
<artifactId>timi-java</artifactId>
|
<artifactId>timi-java</artifactId>
|
||||||
<version>0.0.7</version>
|
<version>0.0.11</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.utils</groupId>
|
<groupId>com.imyeyu.utils</groupId>
|
||||||
<artifactId>timi-utils</artifactId>
|
<artifactId>timi-utils</artifactId>
|
||||||
<version>0.0.13</version>
|
<version>0.0.13</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.majiajie</groupId>
|
||||||
|
<artifactId>tinypinyin</artifactId>
|
||||||
|
<version>2.0.3</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.font.icon</groupId>
|
<groupId>com.imyeyu.font.icon</groupId>
|
||||||
<artifactId>timi-icon-font</artifactId>
|
<artifactId>timi-icon-font</artifactId>
|
||||||
<version>0.0.1</version>
|
<version>0.0.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@@ -236,9 +246,13 @@
|
|||||||
<artifactId>flyway-mysql</artifactId>
|
<artifactId>flyway-mysql</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.e2ins.ms.notify</groupId>
|
<groupId>com.tencentcloudapi</groupId>
|
||||||
<artifactId>e2ins-msg-notify-service-sdk</artifactId>
|
<artifactId>tencentcloud-sdk-java-sms</artifactId>
|
||||||
<version>0.0.9</version>
|
<version>3.1.1281</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-mail</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
@@ -50,6 +50,16 @@ public enum CorePermissionCode implements BuiltinPermissionCode {
|
|||||||
USER_UPDATE("USER:UPDATE", "用户修改", false, true),
|
USER_UPDATE("USER:UPDATE", "用户修改", false, true),
|
||||||
USER_DELETE("USER:DELETE", "用户删除", 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_CREATE("USER_ROLE:CREATE", "用户角色创建", true, true),
|
||||||
USER_ROLE_READ("USER_ROLE:READ", "用户角色读取", true, true),
|
USER_ROLE_READ("USER_ROLE:READ", "用户角色读取", true, true),
|
||||||
USER_ROLE_DELETE("USER_ROLE:DELETE", "用户角色删除", true, true);
|
USER_ROLE_DELETE("USER_ROLE:DELETE", "用户角色删除", true, true);
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
package com.imyeyu.api.config;
|
package com.imyeyu.api.config;
|
||||||
|
|
||||||
import com.e2ins.ms.notify.SmsNotifyService;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.MapperFeature;
|
import com.fasterxml.jackson.databind.MapperFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
|
||||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
|
||||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import com.imyeyu.utils.Time;
|
import com.imyeyu.utils.Time;
|
||||||
@@ -32,12 +29,6 @@ public class BeanConfig {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public SmsNotifyService smsNotifyService() {
|
|
||||||
// TODO
|
|
||||||
return new SmsNotifyService(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Yaml yaml() {
|
public Yaml yaml() {
|
||||||
return new Yaml();
|
return new Yaml();
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.imyeyu.api.modules.common.bean;
|
||||||
|
|
||||||
|
/// Groovy 脚本执行结果
|
||||||
|
///
|
||||||
|
/// @param <T> 脚本返回值类型
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-04
|
||||||
|
public record GroovyScriptExecutionResult<T>(String scriptId, String versionId, Integer version, String checksum, T result) {
|
||||||
|
}
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.common.bean.attachment;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2025-12-11 18:14
|
|
||||||
*/
|
|
||||||
public class Metadata {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 图片
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2025-12-11 18:15
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public static class Image {
|
|
||||||
|
|
||||||
private int width;
|
|
||||||
|
|
||||||
private int height;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缩略图
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
|
||||||
* @since 2026-01-04 18:10
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public static class ThumbImage extends Image {
|
|
||||||
|
|
||||||
private String sourceId;
|
|
||||||
|
|
||||||
private String sourceMongoId;
|
|
||||||
|
|
||||||
private String sourceMimeType;
|
|
||||||
|
|
||||||
/** 请求宽度(缓存键之一,null 表示未指定) */
|
|
||||||
private Integer requestWidth;
|
|
||||||
|
|
||||||
/** 请求高度(缓存键之一,null 表示未指定) */
|
|
||||||
private Integer requestHeight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.imyeyu.api.modules.common.bean.attachment;
|
||||||
|
|
||||||
|
/// 缩略图缩放模式
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-21
|
||||||
|
public enum ThumbnailFitMode {
|
||||||
|
|
||||||
|
/// 保持比例完整放入目标尺寸
|
||||||
|
FIT,
|
||||||
|
|
||||||
|
/// 保持比例裁剪填满目标尺寸
|
||||||
|
COVER,
|
||||||
|
|
||||||
|
/// 强制缩放到目标尺寸,可能导致图片变形
|
||||||
|
STRETCH
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
private Captcha captcha;
|
||||||
|
|
||||||
|
/// 短信验证码
|
||||||
|
@Data
|
||||||
|
public static class Captcha {
|
||||||
|
|
||||||
|
private String templateId;
|
||||||
|
|
||||||
|
private int ttlMinute;
|
||||||
|
|
||||||
|
private int argIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 微信队列配置
|
||||||
|
@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 * * * * ?";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.imyeyu.api.modules.common.controller;
|
package com.imyeyu.api.modules.common.controller;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.bean.attachment.ThumbnailFitMode;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentVariantService;
|
||||||
import com.imyeyu.api.modules.common.service.TempFileService;
|
import com.imyeyu.api.modules.common.service.TempFileService;
|
||||||
import com.imyeyu.api.modules.common.vo.attach.TempFileResp;
|
import com.imyeyu.api.modules.common.vo.attach.TempFileResp;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
@@ -41,6 +43,7 @@ public class AttachmentController {
|
|||||||
|
|
||||||
private final TempFileService tempFileService;
|
private final TempFileService tempFileService;
|
||||||
private final AttachmentService service;
|
private final AttachmentService service;
|
||||||
|
private final AttachmentVariantService variantService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询附件详情
|
* 查询附件详情
|
||||||
@@ -184,14 +187,19 @@ public class AttachmentController {
|
|||||||
@AOPLog
|
@AOPLog
|
||||||
@IgnoreGlobalReturn
|
@IgnoreGlobalReturn
|
||||||
@GetMapping({"/read/{id}", "/download/{id}"})
|
@GetMapping({"/read/{id}", "/download/{id}"})
|
||||||
public void readById(@PathVariable String id, @RequestParam(required = false) Integer thumbWidth, @RequestParam(required = false) Integer thumbHeight) throws UnsupportedEncodingException {
|
public void readById(
|
||||||
|
@PathVariable String id,
|
||||||
|
@RequestParam(required = false) Integer thumbWidth,
|
||||||
|
@RequestParam(required = false) Integer thumbHeight,
|
||||||
|
@RequestParam(defaultValue = "FIT") ThumbnailFitMode fitMode
|
||||||
|
) throws UnsupportedEncodingException {
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
Attachment attach = service.get(id);
|
Attachment attach = service.get(id);
|
||||||
if (attach == null) {
|
if (attach == null) {
|
||||||
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
responseAttachment(attach, thumbWidth, thumbHeight);
|
responseAttachment(attach, thumbWidth, thumbHeight, fitMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -207,21 +215,31 @@ public class AttachmentController {
|
|||||||
public void read(@RequestParam String id) throws UnsupportedEncodingException {
|
public void read(@RequestParam String id) throws UnsupportedEncodingException {
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
Attachment attach = service.get(id);
|
Attachment attach = service.get(id);
|
||||||
|
if (attach == null) {
|
||||||
|
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (TimiSpring.getRequest().getRequestURI().endsWith("/download")) {
|
if (TimiSpring.getRequest().getRequestURI().endsWith("/download")) {
|
||||||
resp.setHeader("Content-Disposition", Network.getFileDownloadHeader(attach.getName()));
|
resp.setHeader("Content-Disposition", Network.getFileDownloadHeader(attach.getName()));
|
||||||
}
|
}
|
||||||
response(attach);
|
response(attach, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void responseAttachment(Attachment attach, Integer thumbWidth, Integer thumbHeight) throws UnsupportedEncodingException {
|
private void responseAttachment(
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
Attachment attach,
|
||||||
if (attach != null && TimiSpring.getRequest().getRequestURI().endsWith("/download") && attach.getName() != null) {
|
Integer thumbWidth,
|
||||||
resp.setHeader("Content-Disposition", Network.getFileDownloadHeader(attach.getName()));
|
Integer thumbHeight,
|
||||||
}
|
ThumbnailFitMode fitMode
|
||||||
responseThumb(attach, thumbWidth, thumbHeight);
|
) throws UnsupportedEncodingException {
|
||||||
|
responseThumb(attach, thumbWidth, thumbHeight, fitMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void responseThumb(Attachment attachment, Integer thumbWidth, Integer thumbHeight) {
|
protected void responseThumb(
|
||||||
|
Attachment attachment,
|
||||||
|
Integer thumbWidth,
|
||||||
|
Integer thumbHeight,
|
||||||
|
ThumbnailFitMode fitMode
|
||||||
|
) throws UnsupportedEncodingException {
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
if (TimiJava.isEmpty(attachment)) {
|
if (TimiJava.isEmpty(attachment)) {
|
||||||
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
@@ -229,21 +247,65 @@ public class AttachmentController {
|
|||||||
}
|
}
|
||||||
if (thumbWidth == null && thumbHeight == null) {
|
if (thumbWidth == null && thumbHeight == null) {
|
||||||
// 原图
|
// 原图
|
||||||
|
setDownloadHeader(attachment);
|
||||||
response(attachment);
|
response(attachment);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 缩略图
|
// 缩略图
|
||||||
Attachment thumb = service.fetchThumb(attachment, thumbWidth, thumbHeight);
|
Attachment thumb = variantService.fetchThumb(attachment, thumbWidth, thumbHeight, fitMode);
|
||||||
response(TimiJava.defaultIfNull(thumb, attachment));
|
setDownloadHeader(thumb);
|
||||||
|
response(thumb);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDownloadHeader(Attachment attachment) throws UnsupportedEncodingException {
|
||||||
|
if (attachment != null && TimiSpring.getRequest().getRequestURI().endsWith("/download") && attachment.getName() != null) {
|
||||||
|
TimiSpring.getResponse().setHeader("Content-Disposition", Network.getFileDownloadHeader(attachment.getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 设置附件缓存头并处理条件请求
|
||||||
|
///
|
||||||
|
/// @param attachment 实际响应附件
|
||||||
|
/// @return true 表示客户端缓存仍有效,已返回 304
|
||||||
|
private boolean responseCache(Attachment attachment) {
|
||||||
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
|
resp.setHeader("Cache-Control", "private, no-cache");
|
||||||
|
String md5 = attachment.getMd5();
|
||||||
|
if (md5 == null || md5.isBlank()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String etag = "\"%s\"".formatted(md5);
|
||||||
|
resp.setHeader("ETag", etag);
|
||||||
|
String ifNoneMatch = TimiSpring.getHeader("If-None-Match");
|
||||||
|
if (ifNoneMatch == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (String value : ifNoneMatch.split(",")) {
|
||||||
|
String candidate = value.trim();
|
||||||
|
if ("*".equals(candidate) || etag.equals(candidate) || ("W/" + etag).equals(candidate)) {
|
||||||
|
resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void response(Attachment attachment) {
|
protected void response(Attachment attachment) {
|
||||||
|
response(attachment, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void response(Attachment attachment, boolean cacheable) {
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
try {
|
try {
|
||||||
if (TimiJava.isEmpty(attachment)) {
|
if (TimiJava.isEmpty(attachment)) {
|
||||||
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!cacheable) {
|
||||||
|
resp.setHeader("Cache-Control", "private, no-store");
|
||||||
|
} else if (responseCache(attachment)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
resp.setContentType(attachment.getMimeType());
|
resp.setContentType(attachment.getMimeType());
|
||||||
attachment.doResponse();
|
attachment.doResponse();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -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,242 @@
|
|||||||
|
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.common.service.SmsService;
|
||||||
|
import com.imyeyu.api.modules.common.vo.NotifyManagementItem;
|
||||||
|
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.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.CaptchaValid;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.annotation.RequiredToken;
|
||||||
|
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 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 SmsService smsService;
|
||||||
|
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) {
|
||||||
|
return fillDetailList(service.get(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询管理端通知列表
|
||||||
|
///
|
||||||
|
/// @param page 分页参数
|
||||||
|
/// @return 管理端通知列表
|
||||||
|
@JsonView(ResponseView.Admin.class)
|
||||||
|
@RequireCorePermission(CorePermissionCode.NOTIFY_READ)
|
||||||
|
@RequiredToken
|
||||||
|
@PostMapping("/management/list")
|
||||||
|
public PageResult<NotifyManagementItem> managementList(@RequestBody(required = false) Page<Notify> page) {
|
||||||
|
return service.pageManagement(page, userLoginService.getRequireLoginUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询管理端通知详情及收件人
|
||||||
|
///
|
||||||
|
/// @param id 通知 ID
|
||||||
|
/// @return 通知详情及收件人
|
||||||
|
@JsonView(ResponseView.Admin.class)
|
||||||
|
@RequireCorePermission(CorePermissionCode.NOTIFY_READ)
|
||||||
|
@RequiredToken
|
||||||
|
@PostMapping("/management/detail")
|
||||||
|
public Notify managementDetail(@RequestParam String id) {
|
||||||
|
return fillDetailList(service.getManagement(id, userLoginService.getRequireLoginUserId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 删除通知及其通知详情
|
||||||
|
///
|
||||||
|
/// @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 id 通知 ID
|
||||||
|
@RequireCorePermission(CorePermissionCode.NOTIFY_DELETE)
|
||||||
|
@RequiredToken
|
||||||
|
@PostMapping("/management/delete")
|
||||||
|
public void managementDelete(@RequestParam String id) {
|
||||||
|
service.deleteManagement(id, userLoginService.getRequireLoginUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 取消管理端尚未成功发送的通知
|
||||||
|
///
|
||||||
|
/// @param id 通知 ID
|
||||||
|
@RequireCorePermission(CorePermissionCode.NOTIFY_CANCEL)
|
||||||
|
@RequiredToken
|
||||||
|
@PostMapping("/management/cancel")
|
||||||
|
public void managementCancel(@RequestParam String id) {
|
||||||
|
service.cancelManagement(id, userLoginService.getRequireLoginUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@CaptchaValid
|
||||||
|
@RequestRateLimit(value = 1, inSeconds = 59)
|
||||||
|
@PostMapping("/sms/captcha/create")
|
||||||
|
public String smsCaptchaCreate(@RequestBody CaptchaData<Notify> req) {
|
||||||
|
return smsService.captchaCreate(req.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询当前用户的站内通知
|
||||||
|
///
|
||||||
|
/// @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.hideInternalByUserId(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());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 回填通知详情中的用户信息
|
||||||
|
///
|
||||||
|
/// @param notify 通知
|
||||||
|
/// @return 已回填用户信息的通知
|
||||||
|
private Notify fillDetailList(Notify notify) {
|
||||||
|
if (notify == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<NotifyDetail> detailList = detailService.listByNotifyId(notify.getId());
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.imyeyu.api.modules.common.entity;
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.bean.attachment.SettingSupport;
|
import com.imyeyu.api.modules.common.bean.attachment.SettingSupport;
|
||||||
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
import com.imyeyu.spring.annotation.table.PageIgnore;
|
import com.imyeyu.spring.annotation.table.PageIgnore;
|
||||||
import com.imyeyu.spring.annotation.table.Transient;
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
@@ -28,7 +29,13 @@ public class Article extends UUIDEntity implements SettingSupport {
|
|||||||
public enum BizType {
|
public enum BizType {
|
||||||
|
|
||||||
/** 博客 */
|
/** 博客 */
|
||||||
BLOG
|
BLOG,
|
||||||
|
|
||||||
|
/// GAO 门店日记
|
||||||
|
GAO_STORE_DIARY,
|
||||||
|
|
||||||
|
/// 反馈
|
||||||
|
FEEDBACK
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,6 +56,19 @@ public class Article extends UUIDEntity implements SettingSupport {
|
|||||||
TIP_TAP
|
TIP_TAP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 文章状态
|
||||||
|
public enum Status {
|
||||||
|
|
||||||
|
/// 草稿
|
||||||
|
DART,
|
||||||
|
|
||||||
|
/// 正常
|
||||||
|
NORMAL,
|
||||||
|
|
||||||
|
/// 隐藏
|
||||||
|
HIDDEN
|
||||||
|
}
|
||||||
|
|
||||||
/** 业务类型 */
|
/** 业务类型 */
|
||||||
protected BizType bizType;
|
protected BizType bizType;
|
||||||
|
|
||||||
@@ -58,8 +78,8 @@ public class Article extends UUIDEntity implements SettingSupport {
|
|||||||
/** 标题 */
|
/** 标题 */
|
||||||
protected String title;
|
protected String title;
|
||||||
|
|
||||||
/** 摘要 */
|
/** 描述 */
|
||||||
protected String digest;
|
protected String description;
|
||||||
|
|
||||||
/** 正文类型 */
|
/** 正文类型 */
|
||||||
protected ContentType contentType;
|
protected ContentType contentType;
|
||||||
@@ -74,9 +94,21 @@ public class Article extends UUIDEntity implements SettingSupport {
|
|||||||
/** 喜欢数量 */
|
/** 喜欢数量 */
|
||||||
protected Integer likes;
|
protected Integer likes;
|
||||||
|
|
||||||
|
/** 文章状态 */
|
||||||
|
protected Status status;
|
||||||
|
|
||||||
|
/// 最后更新用户 ID
|
||||||
|
protected String updatedBy;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
protected User updater;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
protected List<Setting> settingList;
|
protected List<Setting> settingList;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
protected List<Comment> commentList;
|
protected List<Comment> commentList;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
protected List<Attachment> attachmentList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,12 +30,28 @@ public class Attachment extends UUIDEntity {
|
|||||||
/// @since 2026-07-17 20:52
|
/// @since 2026-07-17 20:52
|
||||||
public enum BizType {
|
public enum BizType {
|
||||||
|
|
||||||
|
ARTICLE,
|
||||||
|
|
||||||
|
NOTIFY_DETAIL,
|
||||||
|
|
||||||
USER,
|
USER,
|
||||||
|
|
||||||
GAO_CUSTOMER,
|
GAO_CUSTOMER,
|
||||||
|
|
||||||
|
GAO_PRODUCT,
|
||||||
|
|
||||||
|
GAO_PRODUCT_SKU,
|
||||||
|
|
||||||
GAO_EVENT_RECORD,
|
GAO_EVENT_RECORD,
|
||||||
|
|
||||||
|
GAO_FUND_RECORD,
|
||||||
|
|
||||||
|
GAO_STOCK_RECORD,
|
||||||
|
|
||||||
|
GAO_ORDER_FULFILLMENT,
|
||||||
|
|
||||||
|
GAO_SALES_ORDER,
|
||||||
|
|
||||||
TEMP_FILE,
|
TEMP_FILE,
|
||||||
|
|
||||||
MIRROR
|
MIRROR
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.imyeyu.api.modules.common.bean.attachment.ThumbnailFitMode;
|
||||||
|
import com.imyeyu.spring.annotation.table.AutoUUID;
|
||||||
|
import com.imyeyu.spring.annotation.table.Id;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/// 附件缩略图变体记录
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-21
|
||||||
|
@Data
|
||||||
|
public class AttachmentVariant {
|
||||||
|
|
||||||
|
/// 变体 ID
|
||||||
|
@Id
|
||||||
|
@AutoUUID
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/// 源附件 ID
|
||||||
|
private String sourceAttachmentId;
|
||||||
|
|
||||||
|
/// 源文件版本,使用源 GridFS ID
|
||||||
|
private String sourceMongoId;
|
||||||
|
|
||||||
|
/// 源文件摘要
|
||||||
|
private String sourceMd5;
|
||||||
|
|
||||||
|
/// 请求宽度,0 表示未指定
|
||||||
|
private int requestWidth;
|
||||||
|
|
||||||
|
/// 请求高度,0 表示未指定
|
||||||
|
private int requestHeight;
|
||||||
|
|
||||||
|
/// 缩放模式
|
||||||
|
private ThumbnailFitMode fitMode;
|
||||||
|
|
||||||
|
/// 输出格式
|
||||||
|
private String outputFormat;
|
||||||
|
|
||||||
|
/// 缩略图算法版本
|
||||||
|
private String algorithmVersion;
|
||||||
|
|
||||||
|
/// 缩略图 GridFS ID
|
||||||
|
private String mongoId;
|
||||||
|
|
||||||
|
/// 缩略图名称
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/// 缩略图 MIME 类型
|
||||||
|
private String mimeType;
|
||||||
|
|
||||||
|
/// 缩略图元数据
|
||||||
|
private ObjectNode metadata;
|
||||||
|
|
||||||
|
/// 缩略图大小
|
||||||
|
private long size;
|
||||||
|
|
||||||
|
/// 缩略图摘要
|
||||||
|
private String md5;
|
||||||
|
|
||||||
|
/// 创建时间
|
||||||
|
private long createdAt;
|
||||||
|
|
||||||
|
/// 过期时间
|
||||||
|
private long expireAt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
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 content;
|
||||||
|
|
||||||
|
/** 参数 */
|
||||||
|
protected JsonNode 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();
|
||||||
|
content = detail.getContent();
|
||||||
|
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,42 @@
|
|||||||
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/// Groovy 脚本
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-04
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class GroovyScript extends UUIDEntity {
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026/9/4 14:54
|
||||||
|
public enum BizType {
|
||||||
|
|
||||||
|
/// GAO 积分规则
|
||||||
|
GAO_POINT_RULE
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 业务归属
|
||||||
|
private BizType bizType;
|
||||||
|
|
||||||
|
/// 业务内唯一代码
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/// 名称
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/// 说明
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/// true 为允许执行已发布版本
|
||||||
|
private Boolean enabled;
|
||||||
|
|
||||||
|
/// 当前发布版本 ID
|
||||||
|
private String publishedVersionId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/// Groovy 脚本版本
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-04
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class GroovyScriptVersion extends UUIDEntity {
|
||||||
|
|
||||||
|
/// 脚本 ID
|
||||||
|
private String scriptId;
|
||||||
|
|
||||||
|
/// 版本号
|
||||||
|
private Integer version;
|
||||||
|
|
||||||
|
/// 脚本内容
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/// 脚本内容 SHA-256
|
||||||
|
private String checksum;
|
||||||
|
}
|
||||||
@@ -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,6 +1,8 @@
|
|||||||
package com.imyeyu.api.modules.common.entity;
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.imyeyu.java.bean.Language;
|
import com.imyeyu.java.bean.Language;
|
||||||
|
import com.imyeyu.spring.annotation.table.Column;
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
@@ -15,6 +17,18 @@ public class Multilingual extends UUIDEntity {
|
|||||||
|
|
||||||
protected String zhCN;
|
protected String zhCN;
|
||||||
|
|
||||||
|
@Column("zh_cn_pinyin_full")
|
||||||
|
@JsonIgnore
|
||||||
|
protected String zhCNPinyinFull;
|
||||||
|
|
||||||
|
@Column("zh_cn_pinyin_initial")
|
||||||
|
@JsonIgnore
|
||||||
|
protected String zhCNPinyinInitial;
|
||||||
|
|
||||||
|
@Column("zh_cn_pinyin_mixed")
|
||||||
|
@JsonIgnore
|
||||||
|
protected String zhCNPinyinMixed;
|
||||||
|
|
||||||
protected String zhTW;
|
protected String zhTW;
|
||||||
|
|
||||||
protected String enUS;
|
protected String enUS;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.imyeyu.api.modules.common.entity;
|
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.annotation.table.Transient;
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -19,11 +17,6 @@ import java.util.List;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class Notify extends UUIDEntity {
|
public class Notify extends UUIDEntity {
|
||||||
|
|
||||||
/** 主键 */
|
|
||||||
@Id
|
|
||||||
@AutoUUID
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
/** 业务类型 */
|
/** 业务类型 */
|
||||||
private String bizType;
|
private String bizType;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,24 @@
|
|||||||
package com.imyeyu.api.modules.common.entity;
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
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.annotation.table.Transient;
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
|
import com.imyeyu.spring.util.ResponseView;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通知详情
|
* 通知详情
|
||||||
*
|
*
|
||||||
@@ -25,13 +38,32 @@ public class NotifyDetail extends UUIDEntity {
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum MsgType {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,45 +85,94 @@ public class NotifyDetail extends UUIDEntity {
|
|||||||
FAIL
|
FAIL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 内容类型
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-24
|
||||||
|
public enum ContentType {
|
||||||
|
|
||||||
|
/** 纯文本 */
|
||||||
|
TEXT,
|
||||||
|
|
||||||
|
/** TipTap 富文本 */
|
||||||
|
TIP_TAP
|
||||||
|
}
|
||||||
|
|
||||||
/** 所属通知 ID */
|
/** 所属通知 ID */
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
private String notifyId;
|
private String notifyId;
|
||||||
|
|
||||||
/** 消息类型 */
|
/** 消息类型 */
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
private MsgType msgType;
|
private MsgType msgType;
|
||||||
|
|
||||||
/** 模板 ID */
|
/** 模板 ID */
|
||||||
|
@JsonView(ResponseView.Admin.class)
|
||||||
private String templateId;
|
private String templateId;
|
||||||
|
|
||||||
/** 标题 */
|
/** 标题 */
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
private String subject;
|
private String subject;
|
||||||
|
|
||||||
/** 内容 */
|
/** 内容 */
|
||||||
private String data;
|
@JsonView(ResponseView.Public.class)
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/// 内容类型
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
private ContentType contentType;
|
||||||
|
|
||||||
/** 参数 */
|
/** 参数 */
|
||||||
private String args;
|
@JsonView(ResponseView.Public.class)
|
||||||
|
private JsonNode args;
|
||||||
|
|
||||||
/** 发送来源 */
|
/** 发送来源 */
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
private String sendFrom;
|
private String sendFrom;
|
||||||
|
|
||||||
/** 发送去向 */
|
/** 发送去向 */
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
private String sendTo;
|
private String sendTo;
|
||||||
|
|
||||||
/** 发送时间 */
|
/** 发送时间 */
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
private Long sendAt;
|
private Long sendAt;
|
||||||
|
|
||||||
/** 重试计数 */
|
/** 重试计数 */
|
||||||
|
@JsonView(ResponseView.Admin.class)
|
||||||
private Integer retry;
|
private Integer retry;
|
||||||
|
|
||||||
/** 超时时间 */
|
/** 超时时间 */
|
||||||
|
@JsonView(ResponseView.Admin.class)
|
||||||
private Long timeoutAt;
|
private Long timeoutAt;
|
||||||
|
|
||||||
/** 结果描述 */
|
/** 结果描述 */
|
||||||
|
@JsonView(ResponseView.Admin.class)
|
||||||
private String resultDesc;
|
private String resultDesc;
|
||||||
|
|
||||||
/** 状态 */
|
/** 状态 */
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
private Status status;
|
private Status status;
|
||||||
|
|
||||||
|
/** 已读时间,站内通知未读时为空 */
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
private Long readAt;
|
||||||
|
|
||||||
|
/// 收件人隐藏时间,仅站内通知生效
|
||||||
|
@JsonIgnore
|
||||||
|
private Long hiddenAt;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
protected Notify notify;
|
protected Notify notify;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
protected User fromUser;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
protected User toUser;
|
||||||
|
|
||||||
|
/// 媒体附件列表
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@Transient
|
||||||
|
protected List<Attachment> attachmentList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,30 +32,12 @@ public interface AttachmentMapper extends BaseMapper<Attachment, String>, RawMap
|
|||||||
|
|
||||||
List<Attachment> selectByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes, Page<Attachment> page);
|
List<Attachment> selectByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes, Page<Attachment> page);
|
||||||
|
|
||||||
List<Attachment> selectByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, List<String> attachTypes);
|
List<Attachment> selectAllByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, List<String> attachTypes);
|
||||||
|
|
||||||
|
List<Attachment> selectImageByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, String attachType);
|
||||||
|
|
||||||
long countByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes);
|
long countByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes);
|
||||||
|
|
||||||
/**
|
|
||||||
* 按源附件 ID 与请求尺寸查询已缓存缩略图
|
|
||||||
*
|
|
||||||
* @param bizType 源附件业务类型
|
|
||||||
* @param sourceId 源附件 ID
|
|
||||||
* @param requestWidth 请求宽度,{@code null} 表示未指定
|
|
||||||
* @param requestHeight 请求高度,{@code null} 表示未指定
|
|
||||||
* @return 缩略图附件,不存在返回 {@code null}
|
|
||||||
*/
|
|
||||||
Attachment selectThumb(Attachment.BizType bizType, String sourceId, Integer requestWidth, Integer requestHeight);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询源附件的所有未销毁缩略图(含已软删除)
|
|
||||||
*
|
|
||||||
* @param sourceId 源附件 ID
|
|
||||||
* @return 缩略图列表
|
|
||||||
*/
|
|
||||||
@Select("SELECT * FROM attachment WHERE biz_id = #{sourceId} AND attach_type = 'THUMB' AND is_destroyed = FALSE")
|
|
||||||
List<Attachment> selectThumbsBySourceId(String sourceId);
|
|
||||||
|
|
||||||
@Select("SELECT * FROM attachment WHERE `is_destroyed` = FALSE AND `destroy_at` < " + UNIX_TIME)
|
@Select("SELECT * FROM attachment WHERE `is_destroyed` = FALSE AND `destroy_at` < " + UNIX_TIME)
|
||||||
List<Attachment> selectNeedDestroy();
|
List<Attachment> selectNeedDestroy();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.imyeyu.api.modules.common.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.entity.AttachmentVariant;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// 附件缩略图变体 Mapper
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-21
|
||||||
|
public interface AttachmentVariantMapper {
|
||||||
|
|
||||||
|
/// 查询有效缩略图附件
|
||||||
|
///
|
||||||
|
/// @param sourceAttachmentId 源附件 ID
|
||||||
|
/// @param sourceMongoId 源 GridFS ID
|
||||||
|
/// @param requestWidth 请求宽度,0 表示未指定
|
||||||
|
/// @param requestHeight 请求高度,0 表示未指定
|
||||||
|
/// @param fitMode 缩放模式
|
||||||
|
/// @param outputFormat 输出格式
|
||||||
|
/// @param algorithmVersion 算法版本
|
||||||
|
/// @param now 当前时间
|
||||||
|
/// @return 缩略图附件
|
||||||
|
Attachment selectValidAttachment(
|
||||||
|
@Param("sourceAttachmentId") String sourceAttachmentId,
|
||||||
|
@Param("sourceMongoId") String sourceMongoId,
|
||||||
|
@Param("requestWidth") int requestWidth,
|
||||||
|
@Param("requestHeight") int requestHeight,
|
||||||
|
@Param("fitMode") String fitMode,
|
||||||
|
@Param("outputFormat") String outputFormat,
|
||||||
|
@Param("algorithmVersion") String algorithmVersion,
|
||||||
|
@Param("now") long now
|
||||||
|
);
|
||||||
|
|
||||||
|
/// 查询指定变体记录,不判断是否过期
|
||||||
|
///
|
||||||
|
/// @param sourceAttachmentId 源附件 ID
|
||||||
|
/// @param sourceMongoId 源 GridFS ID
|
||||||
|
/// @param requestWidth 请求宽度,0 表示未指定
|
||||||
|
/// @param requestHeight 请求高度,0 表示未指定
|
||||||
|
/// @param fitMode 缩放模式
|
||||||
|
/// @param outputFormat 输出格式
|
||||||
|
/// @param algorithmVersion 算法版本
|
||||||
|
/// @return 变体记录
|
||||||
|
AttachmentVariant selectByKey(
|
||||||
|
@Param("sourceAttachmentId") String sourceAttachmentId,
|
||||||
|
@Param("sourceMongoId") String sourceMongoId,
|
||||||
|
@Param("requestWidth") int requestWidth,
|
||||||
|
@Param("requestHeight") int requestHeight,
|
||||||
|
@Param("fitMode") String fitMode,
|
||||||
|
@Param("outputFormat") String outputFormat,
|
||||||
|
@Param("algorithmVersion") String algorithmVersion
|
||||||
|
);
|
||||||
|
|
||||||
|
/// 查询源附件的所有变体
|
||||||
|
///
|
||||||
|
/// @param sourceAttachmentId 源附件 ID
|
||||||
|
/// @return 变体列表
|
||||||
|
List<AttachmentVariant> selectBySourceAttachmentId(@Param("sourceAttachmentId") String sourceAttachmentId);
|
||||||
|
|
||||||
|
/// 查询已过期变体
|
||||||
|
///
|
||||||
|
/// @param now 当前时间
|
||||||
|
/// @return 已过期变体列表
|
||||||
|
List<AttachmentVariant> selectExpired(@Param("now") long now);
|
||||||
|
|
||||||
|
/// 新增变体
|
||||||
|
///
|
||||||
|
/// @param variant 变体
|
||||||
|
void insert(AttachmentVariant variant);
|
||||||
|
|
||||||
|
/// 延长缩略图变体的过期时间
|
||||||
|
///
|
||||||
|
/// @param id 变体 ID
|
||||||
|
/// @param now 当前时间
|
||||||
|
/// @param expireAt 新的过期时间
|
||||||
|
/// @return 更新记录数
|
||||||
|
int updateExpireAt(@Param("id") String id, @Param("now") long now, @Param("expireAt") long expireAt);
|
||||||
|
|
||||||
|
/// 删除变体
|
||||||
|
///
|
||||||
|
/// @param id 变体 ID
|
||||||
|
void delete(@Param("id") String id);
|
||||||
|
}
|
||||||
@@ -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,11 @@
|
|||||||
|
package com.imyeyu.api.modules.common.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.GroovyScript;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/// Groovy 脚本 Mapper
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-04
|
||||||
|
public interface GroovyScriptMapper extends BaseMapper<GroovyScript, String> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.imyeyu.api.modules.common.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.GroovyScriptVersion;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/// Groovy 脚本版本 Mapper
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-04
|
||||||
|
public interface GroovyScriptVersionMapper extends BaseMapper<GroovyScriptVersion, 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.api.modules.common.entity.NotifyDetail;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
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
|
* 通知详情 Mapper
|
||||||
@@ -10,4 +15,38 @@ import com.imyeyu.spring.mapper.BaseMapper;
|
|||||||
* @since 2026-05-13 14:46
|
* @since 2026-05-13 14:46
|
||||||
*/
|
*/
|
||||||
public interface NotifyDetailMapper extends BaseMapper<NotifyDetail, String> {
|
public interface NotifyDetailMapper extends BaseMapper<NotifyDetail, String> {
|
||||||
|
|
||||||
|
String NOT_HIDDEN = " AND `hidden_at` IS NULL";
|
||||||
|
|
||||||
|
/** 查询用户的站内通知 */
|
||||||
|
@Select("SELECT * FROM `notify_detail` WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `send_at` < " + UNIX_TIME + NOT_HIDDEN + 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 `send_at` < " + UNIX_TIME + " AND `read_at` IS NULL " + NOT_HIDDEN + 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} AND `send_at` < " + UNIX_TIME + NOT_HIDDEN + NOT_DELETE)
|
||||||
|
long countSiteByUserId(@Param("userId") String userId);
|
||||||
|
|
||||||
|
/** 统计用户的未读站内通知数量 */
|
||||||
|
@Select("SELECT COUNT(*) FROM `notify_detail` WHERE `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `send_at` < " + UNIX_TIME + " AND `read_at` IS NULL " + NOT_HIDDEN + NOT_DELETE)
|
||||||
|
long countUnreadSiteByUserId(@Param("userId") String userId);
|
||||||
|
|
||||||
|
/** 查询用户拥有的站内通知 */
|
||||||
|
@Select("SELECT * FROM `notify_detail` WHERE `id` = #{detailId} AND `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `send_at` < " + UNIX_TIME + NOT_HIDDEN + NOT_DELETE + " LIMIT 1")
|
||||||
|
NotifyDetail selectSiteByIdAndUserId(@Param("detailId") String detailId, @Param("userId") String userId);
|
||||||
|
|
||||||
|
/** 隐藏用户的站内通知 */
|
||||||
|
@Update("UPDATE `notify_detail` SET `hidden_at` = " + UNIX_TIME + ", `updated_at` = " + UNIX_TIME + " WHERE `id` = #{detailId} AND `msg_type` = 'INTERNAL' AND `send_to` = #{userId} AND `send_at` < " + UNIX_TIME + NOT_HIDDEN + NOT_DELETE)
|
||||||
|
int hideSiteByIdAndUserId(@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 `send_at` < " + UNIX_TIME + " AND `read_at` IS NULL " + NOT_HIDDEN + 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 `send_at` < " + UNIX_TIME + " AND `read_at` IS NULL " + NOT_HIDDEN + NOT_DELETE)
|
||||||
|
int markAllSiteRead(@Param("userId") String userId, @Param("readAt") long readAt);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
package com.imyeyu.api.modules.common.mapper;
|
package com.imyeyu.api.modules.common.mapper;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Notify;
|
import com.imyeyu.api.modules.common.entity.Notify;
|
||||||
|
import com.imyeyu.api.modules.common.vo.NotifyManagementItem;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通知 Mapper
|
* 通知 Mapper
|
||||||
*
|
*
|
||||||
@@ -10,4 +15,29 @@ import com.imyeyu.spring.mapper.BaseMapper;
|
|||||||
* @since 2026-05-13 14:46
|
* @since 2026-05-13 14:46
|
||||||
*/
|
*/
|
||||||
public interface NotifyMapper extends BaseMapper<Notify, String> {
|
public interface NotifyMapper extends BaseMapper<Notify, String> {
|
||||||
|
|
||||||
|
/// 查询业务提醒是否已创建
|
||||||
|
@Select("SELECT EXISTS (SELECT 1 FROM `notify` WHERE `biz_type` = #{bizType} AND `biz_reminded_type` = #{bizRemindedType} AND `biz_reminded_id` = #{bizRemindedId} AND `deleted_at` IS NULL)")
|
||||||
|
boolean existsByBizReminded(@Param("bizType") String bizType, @Param("bizRemindedType") String bizRemindedType, @Param("bizRemindedId") String bizRemindedId);
|
||||||
|
|
||||||
|
/// 分页查询管理端通知
|
||||||
|
///
|
||||||
|
/// @param userId 管理员用户 ID
|
||||||
|
/// @param offset 分页偏移量
|
||||||
|
/// @param limit 分页大小
|
||||||
|
/// @return 通知列表
|
||||||
|
List<NotifyManagementItem> selectManagementPage(@Param("userId") String userId, @Param("offset") long offset, @Param("limit") long limit);
|
||||||
|
|
||||||
|
/// 统计管理端通知数量
|
||||||
|
///
|
||||||
|
/// @param userId 管理员用户 ID
|
||||||
|
/// @return 通知数量
|
||||||
|
long countManagement(@Param("userId") String userId);
|
||||||
|
|
||||||
|
/// 查询管理员可管理的通知
|
||||||
|
///
|
||||||
|
/// @param notifyId 通知 ID
|
||||||
|
/// @param userId 管理员用户 ID
|
||||||
|
/// @return 通知
|
||||||
|
Notify selectManagement(@Param("notifyId") String notifyId, @Param("userId") String userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
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);
|
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> {
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@ package com.imyeyu.api.modules.common.service;
|
|||||||
import com.imyeyu.api.modules.common.entity.Article;
|
import com.imyeyu.api.modules.common.entity.Article;
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文章服务
|
* 文章服务
|
||||||
*
|
*
|
||||||
@@ -10,4 +12,10 @@ import com.imyeyu.spring.service.BaseService;
|
|||||||
* @since 2021-02-23 21:33
|
* @since 2021-02-23 21:33
|
||||||
*/
|
*/
|
||||||
public interface ArticleService extends BaseService<Article, String> {
|
public interface ArticleService extends BaseService<Article, String> {
|
||||||
|
|
||||||
|
/// 按示例查询文章
|
||||||
|
///
|
||||||
|
/// @param example 查询示例
|
||||||
|
/// @return 文章列表
|
||||||
|
List<Article> listByExample(Article example);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,18 +25,6 @@ public interface AttachmentService extends BaseService<Attachment, String> {
|
|||||||
/// @return 克隆后的附件
|
/// @return 克隆后的附件
|
||||||
Attachment clone(String id);
|
Attachment clone(String id);
|
||||||
|
|
||||||
/**
|
|
||||||
* 按需获取或创建缩略图附件。
|
|
||||||
* <p>当附件为图片或视频时,若指定尺寸的缩略图已存在则直接返回缓存,
|
|
||||||
* 否则生成并持久化后返回。不支持缩略图的附件类型返回 {@code null}。</p>
|
|
||||||
*
|
|
||||||
* @param source 源附件(必须已持久化,mimeType 已填充)
|
|
||||||
* @param requestWidth 请求宽度,{@code null} 表示未指定
|
|
||||||
* @param requestHeight 请求高度,{@code null} 表示未指定
|
|
||||||
* @return 缩略图附件,不支持时返回 {@code null}
|
|
||||||
*/
|
|
||||||
Attachment fetchThumb(Attachment source, Integer requestWidth, Integer requestHeight);
|
|
||||||
|
|
||||||
Attachment getByBizId(Attachment.BizType bizType, String bizId);
|
Attachment getByBizId(Attachment.BizType bizType, String bizId);
|
||||||
|
|
||||||
Attachment getByAttachType(Attachment.BizType bizType, String bizId, String attachType);
|
Attachment getByAttachType(Attachment.BizType bizType, String bizId, String attachType);
|
||||||
@@ -57,6 +45,12 @@ public interface AttachmentService extends BaseService<Attachment, String> {
|
|||||||
*/
|
*/
|
||||||
List<Attachment> listByBizId(Attachment.BizType bizType, String bizId, String... attachTypes);
|
List<Attachment> listByBizId(Attachment.BizType bizType, String bizId, String... attachTypes);
|
||||||
|
|
||||||
|
default Map<String, Attachment> mapFirstImageByIdList(Attachment.BizType bizType, Collection<String> bizIdList) {
|
||||||
|
return mapFirstImageByIdList(bizType, bizIdList, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Attachment> mapFirstImageByIdList(Attachment.BizType bizType, Collection<String> bizIdList, String attachType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据多个业务 ID 批量获取附件
|
* 根据多个业务 ID 批量获取附件
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.imyeyu.api.modules.common.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.bean.attachment.ThumbnailFitMode;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
|
||||||
|
/// 附件缩略图变体服务
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-21
|
||||||
|
public interface AttachmentVariantService {
|
||||||
|
|
||||||
|
/// 按需获取或创建缩略图附件
|
||||||
|
///
|
||||||
|
/// @param source 源附件
|
||||||
|
/// @param requestWidth 请求宽度
|
||||||
|
/// @param requestHeight 请求高度
|
||||||
|
/// @param fitMode 缩放模式
|
||||||
|
/// @return 缩略图附件
|
||||||
|
Attachment fetchThumb(Attachment source, Integer requestWidth, Integer requestHeight, ThumbnailFitMode fitMode);
|
||||||
|
|
||||||
|
/// 删除源附件对应的全部缩略图变体
|
||||||
|
///
|
||||||
|
/// @param sourceAttachmentId 源附件 ID
|
||||||
|
void deleteBySourceId(String sourceAttachmentId);
|
||||||
|
|
||||||
|
/// 清理已过期的缩略图变体
|
||||||
|
void clearExpired();
|
||||||
|
}
|
||||||
@@ -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,120 @@
|
|||||||
|
package com.imyeyu.api.modules.common.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.GroovyScript;
|
||||||
|
import com.imyeyu.api.modules.common.entity.GroovyScriptVersion;
|
||||||
|
import com.imyeyu.api.modules.common.bean.GroovyScriptExecutionResult;
|
||||||
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/// Groovy 脚本服务
|
||||||
|
///
|
||||||
|
/// 脚本仅限可信管理员维护,不能作为不可信用户代码的执行环境
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-04
|
||||||
|
public interface GroovyScriptService extends BaseService<GroovyScript, String> {
|
||||||
|
|
||||||
|
/// 按业务归属和代码查询脚本
|
||||||
|
///
|
||||||
|
/// @param bizType 业务归属
|
||||||
|
/// @param code 业务内唯一代码
|
||||||
|
/// @return 脚本,不存在时返回 null
|
||||||
|
GroovyScript getByCode(GroovyScript.BizType bizType, String code);
|
||||||
|
|
||||||
|
/// 创建脚本元数据
|
||||||
|
///
|
||||||
|
/// 新建脚本默认停用,且没有已发布版本
|
||||||
|
///
|
||||||
|
/// @param script 脚本元数据
|
||||||
|
void create(GroovyScript script);
|
||||||
|
|
||||||
|
/// 更新脚本元数据
|
||||||
|
///
|
||||||
|
/// 业务归属和代码是脚本稳定标识,创建后不可变更
|
||||||
|
///
|
||||||
|
/// @param script 脚本元数据
|
||||||
|
void update(GroovyScript script);
|
||||||
|
|
||||||
|
/// 设置脚本启用状态
|
||||||
|
///
|
||||||
|
/// @param id 脚本 ID
|
||||||
|
/// @param enabled true 为允许执行已发布版本
|
||||||
|
void setEnabled(String id, boolean enabled);
|
||||||
|
|
||||||
|
/// 创建不可变的脚本版本
|
||||||
|
///
|
||||||
|
/// @param scriptId 脚本 ID
|
||||||
|
/// @param content 脚本内容
|
||||||
|
/// @return 新版本
|
||||||
|
GroovyScriptVersion createVersion(String scriptId, String content);
|
||||||
|
|
||||||
|
/// 查询脚本的全部版本
|
||||||
|
///
|
||||||
|
/// @param scriptId 脚本 ID
|
||||||
|
/// @return 按版本号升序的版本列表
|
||||||
|
List<GroovyScriptVersion> listVersion(String scriptId);
|
||||||
|
|
||||||
|
/// 发布指定版本
|
||||||
|
///
|
||||||
|
/// @param scriptId 脚本 ID
|
||||||
|
/// @param versionId 脚本版本 ID
|
||||||
|
void publish(String scriptId, String versionId);
|
||||||
|
|
||||||
|
/// 取消当前发布版本
|
||||||
|
///
|
||||||
|
/// @param scriptId 脚本 ID
|
||||||
|
void unpublish(String scriptId);
|
||||||
|
|
||||||
|
/// 删除脚本
|
||||||
|
///
|
||||||
|
/// @param id 脚本 ID
|
||||||
|
void delete(String id);
|
||||||
|
|
||||||
|
/// 执行已发布且启用的脚本
|
||||||
|
///
|
||||||
|
/// @param bizType 业务归属
|
||||||
|
/// @param code 业务内唯一代码
|
||||||
|
/// @param bindings 传给脚本的变量
|
||||||
|
/// @return 脚本返回值
|
||||||
|
Object execute(GroovyScript.BizType bizType, String code, Map<String, Object> bindings);
|
||||||
|
|
||||||
|
/// 执行已发布且启用的脚本并返回实际执行版本
|
||||||
|
///
|
||||||
|
/// @param bizType 业务归属
|
||||||
|
/// @param code 业务内唯一代码
|
||||||
|
/// @param bindings 传给脚本的变量
|
||||||
|
/// @param resultType 返回值类型
|
||||||
|
/// @param <T> 返回值类型
|
||||||
|
/// @return 脚本执行结果
|
||||||
|
<T> GroovyScriptExecutionResult<T> executePublished(GroovyScript.BizType bizType, String code, Map<String, Object> bindings, Class<T> resultType);
|
||||||
|
|
||||||
|
/// 按指定历史版本执行脚本
|
||||||
|
///
|
||||||
|
/// 用于按积分发生时的脚本版本复算,脚本当前是否发布或启用不影响执行;脚本返回 null 表示未命中,属合法结果
|
||||||
|
///
|
||||||
|
/// @param versionId 脚本版本 ID
|
||||||
|
/// @param bindings 传给脚本的变量
|
||||||
|
/// @param resultType 返回值类型
|
||||||
|
/// @param <T> 返回值类型
|
||||||
|
/// @return 脚本执行结果
|
||||||
|
<T> GroovyScriptExecutionResult<T> executeVersion(String versionId, Map<String, Object> bindings, Class<T> resultType);
|
||||||
|
|
||||||
|
/// 执行已发布且启用的脚本并验证返回值类型
|
||||||
|
///
|
||||||
|
/// @param bizType 业务归属
|
||||||
|
/// @param code 业务内唯一代码
|
||||||
|
/// @param bindings 传给脚本的变量
|
||||||
|
/// @param resultType 返回值类型
|
||||||
|
/// @param <T> 返回值类型
|
||||||
|
/// @return 脚本返回值
|
||||||
|
<T> T execute(GroovyScript.BizType bizType, String code, Map<String, Object> bindings, Class<T> resultType);
|
||||||
|
|
||||||
|
/// 清除脚本的本地编译缓存
|
||||||
|
///
|
||||||
|
/// 多实例部署时,其他节点在收到脚本变更通知后调用此方法
|
||||||
|
///
|
||||||
|
/// @param scriptId 脚本 ID
|
||||||
|
void invalidate(String scriptId);
|
||||||
|
}
|
||||||
@@ -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;
|
package com.imyeyu.api.modules.common.service;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
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 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
|
* @since 2026-05-13 14:46
|
||||||
*/
|
*/
|
||||||
public interface NotifyDetailService extends BaseService<NotifyDetail, String> {
|
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 hideInternalByUserId(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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.imyeyu.api.modules.common.service;
|
package com.imyeyu.api.modules.common.service;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Notify;
|
import com.imyeyu.api.modules.common.entity.Notify;
|
||||||
|
import com.imyeyu.api.modules.common.vo.NotifyManagementItem;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,4 +13,43 @@ import com.imyeyu.spring.service.BaseService;
|
|||||||
* @since 2026-05-13 14:46
|
* @since 2026-05-13 14:46
|
||||||
*/
|
*/
|
||||||
public interface NotifyService extends BaseService<Notify, String> {
|
public interface NotifyService extends BaseService<Notify, String> {
|
||||||
|
|
||||||
|
/// 查询业务提醒是否已创建
|
||||||
|
///
|
||||||
|
/// @param bizType 业务类型
|
||||||
|
/// @param bizRemindedType 被提醒业务类型
|
||||||
|
/// @param bizRemindedId 被提醒业务 ID
|
||||||
|
/// @return true 为已创建
|
||||||
|
boolean existsByBizReminded(String bizType, String bizRemindedType, String bizRemindedId);
|
||||||
|
|
||||||
|
/// 分页查询当前用户创建的通知
|
||||||
|
///
|
||||||
|
/// @param page 分页参数
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @return 管理端通知列表
|
||||||
|
PageResult<NotifyManagementItem> pageManagement(Page<Notify> page, String userId);
|
||||||
|
|
||||||
|
/// 查询当前用户可管理的通知
|
||||||
|
///
|
||||||
|
/// @param notifyId 通知 ID
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @return 通知
|
||||||
|
Notify getManagement(String notifyId, String userId);
|
||||||
|
|
||||||
|
/// 删除当前用户创建的通知
|
||||||
|
///
|
||||||
|
/// @param notifyId 通知 ID
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
void deleteManagement(String notifyId, String userId);
|
||||||
|
|
||||||
|
/// 取消当前用户创建的通知
|
||||||
|
///
|
||||||
|
/// @param notifyId 通知 ID
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
void cancelManagement(String notifyId, String userId);
|
||||||
|
|
||||||
|
/// 取消通知中尚未成功发送的通知详情
|
||||||
|
///
|
||||||
|
/// @param notifyId 通知 ID
|
||||||
|
void cancel(String notifyId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.imyeyu.api.modules.common.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.Notify;
|
||||||
|
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2026-05-14 12:12
|
||||||
|
*/
|
||||||
|
public interface SmsService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建短信验证码通知
|
||||||
|
*
|
||||||
|
* @param detail 通知
|
||||||
|
* @return 通知详情 ID
|
||||||
|
*/
|
||||||
|
String captchaCreate(Notify detail);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验短信验证码
|
||||||
|
*
|
||||||
|
* @param detailId 通知详情 ID
|
||||||
|
* @param captcha 请求验证码
|
||||||
|
* @return 通知详情
|
||||||
|
*/
|
||||||
|
NotifyDetail captchaVerify(String detailId, String captcha);
|
||||||
|
}
|
||||||
@@ -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.Tag;
|
||||||
import com.imyeyu.api.modules.common.entity.TagApply;
|
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 com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -15,6 +17,15 @@ public interface TagService extends BaseService<Tag, String> {
|
|||||||
|
|
||||||
List<Tag> listByIdList(Collection<String> idList);
|
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 业务类型
|
/// @param bizType 业务类型
|
||||||
@@ -28,4 +39,10 @@ public interface TagService extends BaseService<Tag, String> {
|
|||||||
/// @param bizId 业务 ID
|
/// @param bizId 业务 ID
|
||||||
/// @param tagIdList 标签 ID 列表
|
/// @param tagIdList 标签 ID 列表
|
||||||
void apply(TagApply.BizType bizType, String bizId, List<String> tagIdList);
|
void apply(TagApply.BizType bizType, String bizId, List<String> tagIdList);
|
||||||
|
|
||||||
|
/// 删除指定归属下的全部标签
|
||||||
|
///
|
||||||
|
/// @param ownerType 归属类型
|
||||||
|
/// @param ownerId 归属 ID
|
||||||
|
void deleteByOwner(Tag.OwnerType ownerType, String ownerId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
+61
@@ -1,14 +1,23 @@
|
|||||||
package com.imyeyu.api.modules.common.service.implement;
|
package com.imyeyu.api.modules.common.service.implement;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Article;
|
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.mapper.ArticleMapper;
|
||||||
import com.imyeyu.api.modules.common.service.ArticleService;
|
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.mapper.BaseMapper;
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文章服务实现
|
* 文章服务实现
|
||||||
*
|
*
|
||||||
@@ -20,10 +29,62 @@ import org.springframework.stereotype.Service;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ArticleServiceImplement extends AbstractEntityService<Article, String> implements ArticleService {
|
public class ArticleServiceImplement extends AbstractEntityService<Article, String> implements ArticleService {
|
||||||
|
|
||||||
|
private final LoggerService loggerService;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
|
||||||
private final ArticleMapper mapper;
|
private final ArticleMapper mapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BaseMapper<Article, String> mapper() {
|
protected BaseMapper<Article, String> mapper() {
|
||||||
return mapper;
|
return mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Article> listByExample(Article example) {
|
||||||
|
return mapper.selectAllByExample(example);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-102
@@ -3,19 +3,14 @@ package com.imyeyu.api.modules.common.service.implement;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
import com.imyeyu.api.modules.common.bean.attachment.MediaAttach;
|
|
||||||
import com.imyeyu.api.modules.common.bean.attachment.Metadata;
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.mapper.AttachmentMapper;
|
import com.imyeyu.api.modules.common.mapper.AttachmentMapper;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
import com.imyeyu.api.util.JavaCV;
|
import com.imyeyu.api.modules.common.service.AttachmentVariantService;
|
||||||
import com.imyeyu.io.IO;
|
import com.imyeyu.io.IO;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.java.bean.CallbackArg;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiCode;
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
import com.imyeyu.java.ref.Ref;
|
|
||||||
import com.imyeyu.network.Network;
|
|
||||||
import com.imyeyu.spring.TimiSpring;
|
import com.imyeyu.spring.TimiSpring;
|
||||||
import com.imyeyu.spring.bean.Page;
|
import com.imyeyu.spring.bean.Page;
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
@@ -26,7 +21,6 @@ import com.mongodb.client.gridfs.GridFSBucket;
|
|||||||
import com.mongodb.client.gridfs.model.GridFSFile;
|
import com.mongodb.client.gridfs.model.GridFSFile;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.coobird.thumbnailator.Thumbnails;
|
|
||||||
import org.apache.tika.Tika;
|
import org.apache.tika.Tika;
|
||||||
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
@@ -36,18 +30,16 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,6 +56,7 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
private final ObjectMapper jackson;
|
private final ObjectMapper jackson;
|
||||||
private final GridFSBucket gridFSBucket;
|
private final GridFSBucket gridFSBucket;
|
||||||
private final GridFsTemplate gridFsTemplate;
|
private final GridFsTemplate gridFsTemplate;
|
||||||
|
private final AttachmentVariantService variantService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BaseMapper<Attachment, String> mapper() {
|
protected BaseMapper<Attachment, String> mapper() {
|
||||||
@@ -124,6 +117,7 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
}
|
}
|
||||||
// 有新文件时,先查旧记录获取旧 mongoId 和兜底字段
|
// 有新文件时,先查旧记录获取旧 mongoId 和兜底字段
|
||||||
Attachment old = mapper.selectRaw(attachment.getId());
|
Attachment old = mapper.selectRaw(attachment.getId());
|
||||||
|
TimiException.required(old, "not found attachment");
|
||||||
// 存储新文件
|
// 存储新文件
|
||||||
newMongoId = gridFsTemplate.store(stream, attachment.buildMongoName()).toString();
|
newMongoId = gridFsTemplate.store(stream, attachment.buildMongoName()).toString();
|
||||||
GridFSFile gridFSFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(newMongoId)));
|
GridFSFile gridFSFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(newMongoId)));
|
||||||
@@ -141,6 +135,8 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
|
|
||||||
// 更新数据库后删除旧 GridFS 文件
|
// 更新数据库后删除旧 GridFS 文件
|
||||||
super.update(attachment);
|
super.update(attachment);
|
||||||
|
// 源文件版本已变化,旧缩略图全部失效
|
||||||
|
variantService.deleteBySourceId(attachment.getId());
|
||||||
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(old.getMongoId())));
|
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(old.getMongoId())));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 新文件已上传但后续操作失败,清理新文件防止孤儿数据
|
// 新文件已上传但后续操作失败,清理新文件防止孤儿数据
|
||||||
@@ -155,36 +151,18 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void delete(String id) {
|
public void delete(String id) {
|
||||||
mapper.selectThumbsBySourceId(id).forEach(thumb -> super.delete(thumb.getId()));
|
variantService.deleteBySourceId(id);
|
||||||
super.delete(id);
|
super.delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void destroy(String id) {
|
public void destroy(String id) {
|
||||||
CallbackArg<Attachment> doDestroy = attach -> {
|
variantService.deleteBySourceId(id);
|
||||||
try {
|
Attachment attachment = mapper.selectRaw(id);
|
||||||
if (attach.getMongoId() != null) {
|
if (attachment != null) {
|
||||||
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(attach.getMongoId())));
|
destroyAttachment(attachment);
|
||||||
}
|
}
|
||||||
if (!attach.isDeleted()) {
|
|
||||||
attach.setDeletedAt(Time.now());
|
|
||||||
}
|
|
||||||
attach.setIsDestroyed(true);
|
|
||||||
attach.setDestroyAt(Time.now());
|
|
||||||
mapper.update(attach);
|
|
||||||
|
|
||||||
if (Ref.toType(MediaAttach.Type.class, attach.getAttachType()) == MediaAttach.Type.THUMB) {
|
|
||||||
// 缩略图记录物理删除
|
|
||||||
mapper.destroy(attach.getId());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("delete mongo file error, id={}", attach.getId(), e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "TODO delete mongo file error");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mapper.selectThumbsBySourceId(id).forEach(doDestroy::handler);
|
|
||||||
doDestroy.handler(mapper.selectRaw(id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@@ -216,74 +194,20 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
private void destroyAttachment(Attachment attachment) {
|
||||||
@Override
|
|
||||||
public Attachment fetchThumb(Attachment source, Integer requestWidth, Integer requestHeight) {
|
|
||||||
TimiException.requiredTrue(requestWidth != null || requestHeight != null, "required width or height");
|
|
||||||
String mimeType = source.getMimeType();
|
|
||||||
boolean isImage = mimeType != null && Set.of("image/png", "image/bmp", "image/jpeg").contains(mimeType);
|
|
||||||
boolean isVideo = mimeType != null && Set.of("video/mp4", "video/quicktime").contains(mimeType);
|
|
||||||
if (!isImage && !isVideo) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Attachment cached = mapper.selectThumb(source.getBizType(), source.getId(), requestWidth, requestHeight);
|
|
||||||
if (cached != null) {
|
|
||||||
// 命中缓存直接返回
|
|
||||||
return cached;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream thumbStream = new ByteArrayOutputStream();
|
if (attachment.getMongoId() != null) {
|
||||||
CallbackArg<InputStream> applyThumbSize = inputStream -> {
|
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(attachment.getMongoId())));
|
||||||
try {
|
|
||||||
Thumbnails.Builder<? extends InputStream> builder = Thumbnails.of(inputStream);
|
|
||||||
if (requestWidth != null && requestHeight != null) {
|
|
||||||
builder.size(requestWidth, requestHeight).keepAspectRatio(false).toOutputStream(thumbStream);
|
|
||||||
} else if (requestWidth != null) {
|
|
||||||
builder.width(requestWidth).keepAspectRatio(true).toOutputStream(thumbStream);
|
|
||||||
} else {
|
|
||||||
builder.height(requestHeight).keepAspectRatio(true).toOutputStream(thumbStream);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("applyThumbSize error for fetchThumb", e);
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (isImage) {
|
|
||||||
applyThumbSize.handler(source.openInputStream());
|
|
||||||
} else {
|
|
||||||
String name = source.getName();
|
|
||||||
File tempFile = IO.file("temp/%s_%s".formatted(UUID.randomUUID(), name));
|
|
||||||
try {
|
|
||||||
IO.toFile(tempFile, source.openInputStream());
|
|
||||||
ByteArrayOutputStream baos = JavaCV.captureThumbnail(IO.getInputStream(tempFile), 2);
|
|
||||||
applyThumbSize.handler(IO.toInputStream(baos));
|
|
||||||
} finally {
|
|
||||||
IO.destroy(tempFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Metadata.ThumbImage thumbMeta = new Metadata.ThumbImage();
|
if (!attachment.isDeleted()) {
|
||||||
thumbMeta.setSourceId(source.getId());
|
attachment.setDeletedAt(Time.now());
|
||||||
thumbMeta.setSourceMongoId(source.getMongoId());
|
}
|
||||||
thumbMeta.setSourceMimeType(mimeType);
|
attachment.setIsDestroyed(true);
|
||||||
thumbMeta.setRequestWidth(requestWidth);
|
attachment.setDestroyAt(Time.now());
|
||||||
thumbMeta.setRequestHeight(requestHeight);
|
mapper.update(attachment);
|
||||||
|
|
||||||
Attachment thumb = new Attachment();
|
|
||||||
thumb.setName(Network.simpleURIFileName(source.getName()) + ".png");
|
|
||||||
thumb.setBizType(source.getBizType());
|
|
||||||
thumb.setBizId(source.getId());
|
|
||||||
thumb.setAttachType(MediaAttach.Type.THUMB.toString());
|
|
||||||
thumb.setMetadata(jackson.valueToTree(thumbMeta));
|
|
||||||
thumb.setInputStream(new ByteArrayInputStream(thumbStream.toByteArray()));
|
|
||||||
// 缩略图 7 天后过期,额外 1 天宽限供后台任务销毁
|
|
||||||
long expireAt = Time.now() + 7 * Time.D;
|
|
||||||
thumb.setDeletedAt(expireAt);
|
|
||||||
thumb.setDestroyAt(expireAt + Time.D);
|
|
||||||
create(thumb);
|
|
||||||
return thumb;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("create thumbnail error", e);
|
log.error("delete mongo file error, id={}", attachment.getId(), e);
|
||||||
throw new TimiException(TimiCode.ERROR, "exception.attachment.create.error");
|
throw new TimiException(TimiCode.ERROR, "TODO delete mongo file error", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,12 +243,17 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Attachment> listByBizId(Attachment.BizType bizType, String bizId, String... attachTypes) {
|
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, Attachment> mapFirstImageByIdList(Attachment.BizType bizType, Collection<String> bizIdList, String attachType) {
|
||||||
|
return mapper.selectImageByBizIdList(bizType, new HashSet<>(bizIdList), attachType).stream().collect(Collectors.toMap(Attachment::getBizId, Function.identity()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, List<Attachment>> mapByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, String... attachTypes) {
|
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, new HashSet<>(bizIdList), List.of(attachTypes)).stream().collect(Collectors.groupingBy(Attachment::getBizId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -390,6 +319,8 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
// 将临时文件的 GridFS 存储转移至当前永久记录,废弃临时记录
|
// 将临时文件的 GridFS 存储转移至当前永久记录,废弃临时记录
|
||||||
Attachment current = mapper.selectRaw(item.getId());
|
Attachment current = mapper.selectRaw(item.getId());
|
||||||
Attachment tempFile = mapper.selectRaw(tempFileId);
|
Attachment tempFile = mapper.selectRaw(tempFileId);
|
||||||
|
// 源文件版本已变化,旧缩略图全部失效
|
||||||
|
variantService.deleteBySourceId(current.getId());
|
||||||
// 删除旧 GridFS 文件
|
// 删除旧 GridFS 文件
|
||||||
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(current.getMongoId())));
|
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(current.getMongoId())));
|
||||||
// 将存储信息从临时记录迁移到永久记录
|
// 将存储信息从临时记录迁移到永久记录
|
||||||
|
|||||||
+377
@@ -0,0 +1,377 @@
|
|||||||
|
package com.imyeyu.api.modules.common.service.implement;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
|
import com.imyeyu.api.modules.common.bean.attachment.MediaAttach;
|
||||||
|
import com.imyeyu.api.modules.common.bean.attachment.ThumbnailFitMode;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.entity.AttachmentVariant;
|
||||||
|
import com.imyeyu.api.modules.common.mapper.AttachmentVariantMapper;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentVariantService;
|
||||||
|
import com.imyeyu.api.util.JavaCV;
|
||||||
|
import com.imyeyu.io.IO;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.network.Network;
|
||||||
|
import com.imyeyu.spring.util.Redis;
|
||||||
|
import com.imyeyu.utils.Time;
|
||||||
|
import com.mongodb.client.gridfs.GridFSBucket;
|
||||||
|
import com.mongodb.client.gridfs.model.GridFSFile;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.coobird.thumbnailator.Thumbnails;
|
||||||
|
import net.coobird.thumbnailator.geometry.Positions;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
|
import org.springframework.data.mongodb.gridfs.GridFsTemplate;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/// 附件缩略图变体服务实现
|
||||||
|
///
|
||||||
|
/// 负责缩略图生成、变体缓存、并发控制和变体文件清理,源附件生命周期由 `AttachmentService` 负责
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-21
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AttachmentVariantServiceImplement implements AttachmentVariantService {
|
||||||
|
|
||||||
|
private static final int THUMB_MAX_WIDTH = 4096;
|
||||||
|
private static final int THUMB_MAX_HEIGHT = 4096;
|
||||||
|
private static final long THUMB_MAX_PIXELS = 16_000_000L;
|
||||||
|
private static final long THUMB_CACHE_TTL = Time.D * 7;
|
||||||
|
private static final long THUMB_LOCK_TTL = Time.M * 10;
|
||||||
|
private static final double THUMB_TARGET_SECONDS = 2;
|
||||||
|
private static final int VARIANT_NAME_MAX_LENGTH = 255;
|
||||||
|
private static final String THUMB_OUTPUT_FORMAT = "png";
|
||||||
|
private static final String THUMB_ALGORITHM_VERSION = "v3";
|
||||||
|
private static final String THUMB_LOCK_KEY_PREFIX = "ATTACHMENT:THUMB:LOCK:";
|
||||||
|
|
||||||
|
private final AttachmentVariantMapper variantMapper;
|
||||||
|
private final ObjectMapper jackson;
|
||||||
|
private final GridFSBucket gridFSBucket;
|
||||||
|
private final GridFsTemplate gridFsTemplate;
|
||||||
|
|
||||||
|
@Qualifier("redisLocker")
|
||||||
|
private final Redis<String, Integer> redisLocker;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Attachment fetchThumb(Attachment source, Integer requestWidth, Integer requestHeight, ThumbnailFitMode fitMode) {
|
||||||
|
TimiException.required(source, "not found source attachment");
|
||||||
|
TimiException.required(source.getId(), "not found source attachment.id");
|
||||||
|
TimiException.required(source.getMongoId(), "not found source attachment.mongoId");
|
||||||
|
TimiException.requiredTrue(requestWidth != null || requestHeight != null, "required width or height");
|
||||||
|
if (requestWidth != null && !(0 < requestWidth && requestWidth < THUMB_MAX_WIDTH + 1)) {
|
||||||
|
throw new TimiException(TimiCode.ARG_BAD, "attachment.thumbnail.width.invalid");
|
||||||
|
}
|
||||||
|
if (requestHeight != null && !(0 < requestHeight && requestHeight < THUMB_MAX_HEIGHT + 1)) {
|
||||||
|
throw new TimiException(TimiCode.ARG_BAD, "attachment.thumbnail.height.invalid");
|
||||||
|
}
|
||||||
|
if (requestWidth != null && requestHeight != null) {
|
||||||
|
long pixels = (long) requestWidth * requestHeight;
|
||||||
|
if (THUMB_MAX_PIXELS < pixels) {
|
||||||
|
throw new TimiException(TimiCode.ARG_BAD, "attachment.thumbnail.area.invalid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fitMode = TimiJava.defaultIfNull(fitMode, ThumbnailFitMode.FIT);
|
||||||
|
|
||||||
|
String mimeType = source.getMimeType();
|
||||||
|
boolean isImage = mimeType != null && Set.of("image/png", "image/bmp", "image/jpeg").contains(mimeType);
|
||||||
|
boolean isVideo = mimeType != null && Set.of("video/mp4", "video/quicktime").contains(mimeType);
|
||||||
|
if (!isImage && !isVideo) {
|
||||||
|
throw new TimiException(TimiCode.ARG_BAD, "attachment.thumbnail.not.support");
|
||||||
|
}
|
||||||
|
|
||||||
|
int width = TimiJava.defaultIfNull(requestWidth, 0);
|
||||||
|
int height = TimiJava.defaultIfNull(requestHeight, 0);
|
||||||
|
long now = Time.now();
|
||||||
|
Attachment cached = variantMapper.selectValidAttachment(
|
||||||
|
source.getId(),
|
||||||
|
source.getMongoId(),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
fitMode.toString(),
|
||||||
|
THUMB_OUTPUT_FORMAT,
|
||||||
|
THUMB_ALGORITHM_VERSION,
|
||||||
|
now
|
||||||
|
);
|
||||||
|
if (cached != null) {
|
||||||
|
Attachment refreshed = refreshCachedThumb(cached);
|
||||||
|
if (refreshed != null) {
|
||||||
|
return refreshed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String lockKey = buildThumbLockKey(source, width, height, fitMode);
|
||||||
|
if (!redisLocker.lock(lockKey, 1, THUMB_LOCK_TTL)) {
|
||||||
|
throw new TimiException(TimiCode.ERROR_SERVICE_BUSY, "attachment.thumbnail.generating");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
cached = variantMapper.selectValidAttachment(
|
||||||
|
source.getId(),
|
||||||
|
source.getMongoId(),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
fitMode.toString(),
|
||||||
|
THUMB_OUTPUT_FORMAT,
|
||||||
|
THUMB_ALGORITHM_VERSION,
|
||||||
|
Time.now()
|
||||||
|
);
|
||||||
|
if (cached != null) {
|
||||||
|
Attachment refreshed = refreshCachedThumb(cached);
|
||||||
|
if (refreshed != null) {
|
||||||
|
return refreshed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AttachmentVariant oldVariant = variantMapper.selectByKey(
|
||||||
|
source.getId(),
|
||||||
|
source.getMongoId(),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
fitMode.toString(),
|
||||||
|
THUMB_OUTPUT_FORMAT,
|
||||||
|
THUMB_ALGORITHM_VERSION
|
||||||
|
);
|
||||||
|
if (oldVariant != null) {
|
||||||
|
deleteVariant(oldVariant);
|
||||||
|
}
|
||||||
|
File thumbFile = null;
|
||||||
|
AttachmentVariant variant = null;
|
||||||
|
boolean variantInserted = false;
|
||||||
|
try {
|
||||||
|
thumbFile = createThumbFile(source, requestWidth, requestHeight, fitMode, isImage);
|
||||||
|
variant = new AttachmentVariant();
|
||||||
|
variant.setId(UUID.randomUUID().toString());
|
||||||
|
variant.setName(buildVariantName(source.getName()));
|
||||||
|
variant.setMimeType("image/" + THUMB_OUTPUT_FORMAT);
|
||||||
|
long expireAt = Time.now() + THUMB_CACHE_TTL;
|
||||||
|
variant.setSourceAttachmentId(source.getId());
|
||||||
|
variant.setSourceMongoId(source.getMongoId());
|
||||||
|
variant.setSourceMd5(source.getMd5());
|
||||||
|
variant.setRequestWidth(width);
|
||||||
|
variant.setRequestHeight(height);
|
||||||
|
variant.setFitMode(fitMode);
|
||||||
|
variant.setOutputFormat(THUMB_OUTPUT_FORMAT);
|
||||||
|
variant.setAlgorithmVersion(THUMB_ALGORITHM_VERSION);
|
||||||
|
variant.setCreatedAt(Time.now());
|
||||||
|
variant.setExpireAt(expireAt);
|
||||||
|
BufferedImage image = ImageIO.read(thumbFile);
|
||||||
|
if (image != null) {
|
||||||
|
ObjectNode metadata = jackson.createObjectNode();
|
||||||
|
metadata.put("width", image.getWidth());
|
||||||
|
metadata.put("height", image.getHeight());
|
||||||
|
variant.setMetadata(metadata);
|
||||||
|
}
|
||||||
|
try (InputStream inputStream = Files.newInputStream(thumbFile.toPath())) {
|
||||||
|
String mongoId = gridFsTemplate.store(inputStream, variant.getName()).toString();
|
||||||
|
GridFSFile gridFSFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(mongoId)));
|
||||||
|
variant.setMongoId(mongoId);
|
||||||
|
variant.setSize(gridFSFile.getLength());
|
||||||
|
try (InputStream md5InputStream = gridFSBucket.openDownloadStream(gridFSFile.getObjectId())) {
|
||||||
|
variant.setMd5(IO.md5(md5InputStream));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
variantMapper.insert(variant);
|
||||||
|
variantInserted = true;
|
||||||
|
} catch (DuplicateKeyException e) {
|
||||||
|
destroyVariantFile(variant);
|
||||||
|
Attachment concurrent = variantMapper.selectValidAttachment(
|
||||||
|
source.getId(),
|
||||||
|
source.getMongoId(),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
fitMode.toString(),
|
||||||
|
THUMB_OUTPUT_FORMAT,
|
||||||
|
THUMB_ALGORITHM_VERSION,
|
||||||
|
Time.now()
|
||||||
|
);
|
||||||
|
if (concurrent != null) {
|
||||||
|
Attachment refreshed = refreshCachedThumb(concurrent);
|
||||||
|
if (refreshed != null) {
|
||||||
|
return refreshed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
return toThumbAttachment(source, variant);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (variant != null) {
|
||||||
|
destroyVariantFile(variant);
|
||||||
|
if (variantInserted) {
|
||||||
|
variantMapper.delete(variant.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
IO.destroy(thumbFile);
|
||||||
|
}
|
||||||
|
} catch (TimiException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("create thumbnail error", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "exception.attachment.create.error", e);
|
||||||
|
} finally {
|
||||||
|
redisLocker.releaseLock(lockKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 延长已命中缩略图缓存的有效期
|
||||||
|
///
|
||||||
|
/// @param cached 已命中的缩略图
|
||||||
|
/// @return 更新成功时返回刷新后的缩略图,记录已不存在或已过期时返回 `null`
|
||||||
|
private Attachment refreshCachedThumb(Attachment cached) {
|
||||||
|
long now = Time.now();
|
||||||
|
long expireAt = now + THUMB_CACHE_TTL;
|
||||||
|
if (!(0 < variantMapper.updateExpireAt(cached.getId(), now, expireAt))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
cached.setDestroyAt(expireAt);
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildThumbLockKey(Attachment source, int width, int height, ThumbnailFitMode fitMode) {
|
||||||
|
return "%s%s:%s:%s:%s:%s".formatted(
|
||||||
|
THUMB_LOCK_KEY_PREFIX,
|
||||||
|
source.getId(),
|
||||||
|
source.getMongoId(),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
fitMode
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 构建不超过数据库字段长度的变体名称
|
||||||
|
///
|
||||||
|
/// @param sourceName 源附件名称
|
||||||
|
/// @return 变体名称
|
||||||
|
private String buildVariantName(String sourceName) {
|
||||||
|
String suffix = "." + THUMB_OUTPUT_FORMAT;
|
||||||
|
String baseName = Network.simpleURIFileName(sourceName);
|
||||||
|
int maxBaseLength = VARIANT_NAME_MAX_LENGTH - suffix.length();
|
||||||
|
if (maxBaseLength < baseName.codePointCount(0, baseName.length())) {
|
||||||
|
baseName = baseName.substring(0, baseName.offsetByCodePoints(0, maxBaseLength));
|
||||||
|
}
|
||||||
|
return baseName + suffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
private File createThumbFile(
|
||||||
|
Attachment source,
|
||||||
|
Integer requestWidth,
|
||||||
|
Integer requestHeight,
|
||||||
|
ThumbnailFitMode fitMode,
|
||||||
|
boolean isImage
|
||||||
|
) throws Exception {
|
||||||
|
File thumbFile = Files.createTempFile("timi-thumb-", ".png").toFile();
|
||||||
|
try {
|
||||||
|
if (isImage) {
|
||||||
|
try (InputStream inputStream = source.openInputStream()) {
|
||||||
|
resize(inputStream, thumbFile, requestWidth, requestHeight, fitMode);
|
||||||
|
}
|
||||||
|
return thumbFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (InputStream inputStream = source.openInputStream()) {
|
||||||
|
ByteArrayOutputStream frame = JavaCV.captureThumbnail(inputStream, THUMB_TARGET_SECONDS);
|
||||||
|
if (!(0 < frame.size())) {
|
||||||
|
throw new TimiException(TimiCode.ERROR_NOT_SUPPORT, "attachment.thumbnail.video.frame.empty");
|
||||||
|
}
|
||||||
|
try (InputStream frameInputStream = new ByteArrayInputStream(frame.toByteArray())) {
|
||||||
|
resize(frameInputStream, thumbFile, requestWidth, requestHeight, fitMode);
|
||||||
|
}
|
||||||
|
return thumbFile;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
IO.destroy(thumbFile);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resize(
|
||||||
|
InputStream inputStream,
|
||||||
|
File outputFile,
|
||||||
|
Integer requestWidth,
|
||||||
|
Integer requestHeight,
|
||||||
|
ThumbnailFitMode fitMode
|
||||||
|
) throws IOException {
|
||||||
|
Thumbnails.Builder<? extends InputStream> builder = Thumbnails.of(inputStream)
|
||||||
|
.useExifOrientation(true)
|
||||||
|
.outputFormat(THUMB_OUTPUT_FORMAT);
|
||||||
|
if (requestWidth != null && requestHeight != null) {
|
||||||
|
switch (fitMode) {
|
||||||
|
case FIT -> builder.size(requestWidth, requestHeight).keepAspectRatio(true);
|
||||||
|
case COVER -> builder.size(requestWidth, requestHeight).keepAspectRatio(true).crop(Positions.CENTER);
|
||||||
|
case STRETCH -> builder.size(requestWidth, requestHeight).keepAspectRatio(false);
|
||||||
|
}
|
||||||
|
} else if (requestWidth != null) {
|
||||||
|
builder.width(requestWidth).keepAspectRatio(true);
|
||||||
|
} else {
|
||||||
|
builder.height(requestHeight).keepAspectRatio(true);
|
||||||
|
}
|
||||||
|
builder.toFile(outputFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void deleteBySourceId(String sourceAttachmentId) {
|
||||||
|
for (AttachmentVariant variant : variantMapper.selectBySourceAttachmentId(sourceAttachmentId)) {
|
||||||
|
deleteVariant(variant);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteVariant(AttachmentVariant variant) {
|
||||||
|
destroyVariantFile(variant);
|
||||||
|
variantMapper.delete(variant.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void destroyVariantFile(AttachmentVariant variant) {
|
||||||
|
if (variant.getMongoId() != null) {
|
||||||
|
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(variant.getMongoId())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Attachment toThumbAttachment(Attachment source, AttachmentVariant variant) {
|
||||||
|
Attachment thumb = new Attachment();
|
||||||
|
thumb.setId(variant.getId());
|
||||||
|
thumb.setBizType(source.getBizType());
|
||||||
|
thumb.setBizId(source.getId());
|
||||||
|
thumb.setAttachType(MediaAttach.Type.THUMB.toString());
|
||||||
|
thumb.setMongoId(variant.getMongoId());
|
||||||
|
thumb.setName(variant.getName());
|
||||||
|
thumb.setMimeType(variant.getMimeType());
|
||||||
|
thumb.setMetadata(variant.getMetadata());
|
||||||
|
thumb.setSize(variant.getSize());
|
||||||
|
thumb.setMd5(variant.getMd5());
|
||||||
|
thumb.setIsDestroyed(false);
|
||||||
|
thumb.setDestroyAt(variant.getExpireAt());
|
||||||
|
return thumb;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearExpired() {
|
||||||
|
for (AttachmentVariant variant : variantMapper.selectExpired(Time.now())) {
|
||||||
|
try {
|
||||||
|
deleteVariant(variant);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("clear expired thumbnail variant error, id={}", variant.getId(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+293
@@ -0,0 +1,293 @@
|
|||||||
|
package com.imyeyu.api.modules.common.service.implement;
|
||||||
|
|
||||||
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
|
import com.imyeyu.api.modules.common.entity.GroovyScript;
|
||||||
|
import com.imyeyu.api.modules.common.entity.GroovyScriptVersion;
|
||||||
|
import com.imyeyu.api.modules.common.bean.GroovyScriptExecutionResult;
|
||||||
|
import com.imyeyu.api.modules.common.mapper.GroovyScriptMapper;
|
||||||
|
import com.imyeyu.api.modules.common.mapper.GroovyScriptVersionMapper;
|
||||||
|
import com.imyeyu.api.modules.common.service.GroovyScriptService;
|
||||||
|
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 groovy.lang.Binding;
|
||||||
|
import groovy.lang.GroovyClassLoader;
|
||||||
|
import groovy.lang.Script;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.transaction.support.TransactionSynchronization;
|
||||||
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/// Groovy 脚本服务实现
|
||||||
|
///
|
||||||
|
/// 每个已编译版本使用独立类加载器,缓存失效后可释放对应类及其元数据
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-04
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GroovyScriptServiceImplement extends AbstractEntityService<GroovyScript, String> implements GroovyScriptService {
|
||||||
|
|
||||||
|
private final GroovyScriptMapper mapper;
|
||||||
|
private final GroovyScriptVersionMapper versionMapper;
|
||||||
|
private final Map<String, CompiledScript> compiledScriptMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseMapper<GroovyScript, String> mapper() {
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GroovyScript getByCode(GroovyScript.BizType bizType, String code) {
|
||||||
|
GroovyScript example = new GroovyScript();
|
||||||
|
example.setBizType(bizType);
|
||||||
|
example.setCode(code);
|
||||||
|
return mapper.selectByExample(example);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void create(GroovyScript script) {
|
||||||
|
TimiException.required(script, "未找到脚本");
|
||||||
|
TimiException.required(script.getBizType(), "未找到脚本业务归属");
|
||||||
|
TimiException.required(script.getCode(), "未找到脚本代码");
|
||||||
|
TimiException.required(script.getName(), "未找到脚本名称");
|
||||||
|
TimiException.requiredNull(getByCode(script.getBizType(), script.getCode()), "Groovy 脚本已存在");
|
||||||
|
script.setEnabled(false);
|
||||||
|
script.setPublishedVersionId(null);
|
||||||
|
super.create(script);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void update(GroovyScript script) {
|
||||||
|
TimiException.required(script, "未找到脚本");
|
||||||
|
TimiException.required(script.getId(), "未找到脚本 ID");
|
||||||
|
TimiException.required(script.getName(), "未找到脚本名称");
|
||||||
|
GroovyScript dbScript = get(script.getId());
|
||||||
|
TimiException.required(dbScript, "未找到脚本");
|
||||||
|
dbScript.setName(script.getName());
|
||||||
|
dbScript.setDescription(script.getDescription());
|
||||||
|
mapper.update(dbScript);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void setEnabled(String id, boolean enabled) {
|
||||||
|
GroovyScript script = requireScript(id);
|
||||||
|
script.setEnabled(enabled);
|
||||||
|
mapper.update(script);
|
||||||
|
invalidateAfterCommit(script.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public GroovyScriptVersion createVersion(String scriptId, String content) {
|
||||||
|
requireScript(scriptId);
|
||||||
|
TimiException.required(content, "未找到脚本内容");
|
||||||
|
TimiException.requiredTrue(!content.isBlank(), "脚本内容不能为空");
|
||||||
|
|
||||||
|
GroovyScriptVersion version = new GroovyScriptVersion();
|
||||||
|
version.setScriptId(scriptId);
|
||||||
|
version.setVersion(nextVersion(scriptId));
|
||||||
|
version.setContent(content);
|
||||||
|
version.setChecksum(checksum(content));
|
||||||
|
versionMapper.insert(version);
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GroovyScriptVersion> listVersion(String scriptId) {
|
||||||
|
TimiException.required(scriptId, "未找到脚本 ID");
|
||||||
|
GroovyScriptVersion example = new GroovyScriptVersion();
|
||||||
|
example.setScriptId(scriptId);
|
||||||
|
List<GroovyScriptVersion> versionList = new ArrayList<>(versionMapper.selectAllByExample(example));
|
||||||
|
versionList.sort(Comparator.comparing(GroovyScriptVersion::getVersion));
|
||||||
|
return versionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void publish(String scriptId, String versionId) {
|
||||||
|
GroovyScript script = requireScript(scriptId);
|
||||||
|
GroovyScriptVersion version = requireVersion(versionId);
|
||||||
|
TimiException.requiredTrue(script.getId().equals(version.getScriptId()), "脚本版本不属于当前脚本");
|
||||||
|
script.setPublishedVersionId(version.getId());
|
||||||
|
mapper.update(script);
|
||||||
|
invalidateAfterCommit(script.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void unpublish(String scriptId) {
|
||||||
|
GroovyScript script = requireScript(scriptId);
|
||||||
|
script.setPublishedVersionId(null);
|
||||||
|
mapper.update(script);
|
||||||
|
invalidateAfterCommit(script.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void delete(String id) {
|
||||||
|
requireScript(id);
|
||||||
|
super.delete(id);
|
||||||
|
invalidateAfterCommit(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object execute(GroovyScript.BizType bizType, String code, Map<String, Object> bindings) {
|
||||||
|
return executePublished(bizType, code, bindings, Object.class).result();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> GroovyScriptExecutionResult<T> executePublished(GroovyScript.BizType bizType, String code, Map<String, Object> bindings, Class<T> resultType) {
|
||||||
|
TimiException.required(bizType, "未找到脚本业务归属");
|
||||||
|
TimiException.required(code, "未找到脚本代码");
|
||||||
|
TimiException.required(resultType, "未找到返回值类型");
|
||||||
|
GroovyScript script = getByCode(bizType, code);
|
||||||
|
TimiException.required(script, "未找到 Groovy 脚本");
|
||||||
|
TimiException.requiredTrue(Boolean.TRUE.equals(script.getEnabled()), "Groovy 脚本已停用");
|
||||||
|
TimiException.required(script.getPublishedVersionId(), "Groovy 脚本尚未发布");
|
||||||
|
GroovyScriptExecutionResult<T> result = executeVersion(script.getPublishedVersionId(), bindings, resultType);
|
||||||
|
TimiException.requiredTrue(script.getId().equals(result.scriptId()), "Groovy 脚本已发布版本无效");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T execute(GroovyScript.BizType bizType, String code, Map<String, Object> bindings, Class<T> resultType) {
|
||||||
|
return executePublished(bizType, code, bindings, resultType).result();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> GroovyScriptExecutionResult<T> executeVersion(String versionId, Map<String, Object> bindings, Class<T> resultType) {
|
||||||
|
TimiException.required(resultType, "未找到返回值类型");
|
||||||
|
GroovyScriptVersion version = requireVersion(versionId);
|
||||||
|
CompiledScript compiledScript = compiledScriptMap.computeIfAbsent(cacheKey(version), key -> compile(version.getScriptId(), version));
|
||||||
|
try {
|
||||||
|
Object result = compiledScript.execute(bindings);
|
||||||
|
TimiException.requiredTrue(result == null || resultType.isInstance(result), "Groovy 脚本返回值类型不匹配");
|
||||||
|
return new GroovyScriptExecutionResult<>(version.getScriptId(), version.getId(), version.getVersion(), version.getChecksum(), resultType.cast(result));
|
||||||
|
} catch (TimiException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
log.warn("Groovy 脚本执行失败,scriptId={}, versionId={}", version.getScriptId(), version.getId(), e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "Groovy 脚本执行失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invalidate(String scriptId) {
|
||||||
|
if (scriptId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
compiledScriptMap.entrySet().removeIf(entry -> {
|
||||||
|
if (!scriptId.equals(entry.getValue().scriptId())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
entry.getValue().close();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private GroovyScript requireScript(String id) {
|
||||||
|
TimiException.required(id, "未找到脚本 ID");
|
||||||
|
GroovyScript script = get(id);
|
||||||
|
TimiException.required(script, "未找到脚本");
|
||||||
|
return script;
|
||||||
|
}
|
||||||
|
|
||||||
|
private GroovyScriptVersion requireVersion(String id) {
|
||||||
|
TimiException.required(id, "未找到脚本版本 ID");
|
||||||
|
GroovyScriptVersion version = versionMapper.select(id);
|
||||||
|
TimiException.required(version, "未找到脚本版本");
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int nextVersion(String scriptId) {
|
||||||
|
return listVersion(scriptId).stream()
|
||||||
|
.map(GroovyScriptVersion::getVersion)
|
||||||
|
.max(Integer::compareTo)
|
||||||
|
.orElse(0) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String cacheKey(GroovyScriptVersion version) {
|
||||||
|
return "%s:%s".formatted(version.getId(), version.getChecksum());
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompiledScript compile(String scriptId, GroovyScriptVersion version) {
|
||||||
|
GroovyClassLoader classLoader = new GroovyClassLoader(getClass().getClassLoader());
|
||||||
|
try {
|
||||||
|
Class<?> type = classLoader.parseClass(version.getContent(), "GroovyScript_%s_%d.groovy".formatted(version.getId().replace('-', '_'), version.getVersion()));
|
||||||
|
return new CompiledScript(scriptId, type.asSubclass(Script.class), classLoader);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
close(classLoader);
|
||||||
|
log.warn("Groovy 脚本编译失败,scriptId={}, versionId={}", scriptId, version.getId(), e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "Groovy 脚本编译失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String checksum(String content) {
|
||||||
|
try {
|
||||||
|
return java.util.HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(content.getBytes(StandardCharsets.UTF_8)));
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new IllegalStateException("JVM 缺少 SHA-256 算法", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void invalidateAfterCommit(String scriptId) {
|
||||||
|
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||||
|
invalidate(scriptId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterCommit() {
|
||||||
|
invalidate(scriptId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void close(GroovyClassLoader classLoader) {
|
||||||
|
try {
|
||||||
|
classLoader.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.warn("关闭 Groovy 脚本类加载器失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private record CompiledScript(String scriptId, Class<? extends Script> type, GroovyClassLoader classLoader) {
|
||||||
|
|
||||||
|
private Object execute(Map<String, Object> bindings) {
|
||||||
|
try {
|
||||||
|
Script script = type.getDeclaredConstructor().newInstance();
|
||||||
|
script.setBinding(new Binding(bindings == null ? Map.of() : new HashMap<>(bindings)));
|
||||||
|
return script.run();
|
||||||
|
} catch (ReflectiveOperationException e) {
|
||||||
|
throw new IllegalStateException("Groovy 脚本实例化失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void close() {
|
||||||
|
try {
|
||||||
|
classLoader.close();
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+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.getContent());
|
||||||
|
mailSender.send(message);
|
||||||
|
log.info("邮件发送成功,目标:{}", queue.getSendTo());
|
||||||
|
}
|
||||||
|
}
|
||||||
+23
@@ -3,6 +3,7 @@ package com.imyeyu.api.modules.common.service.implement;
|
|||||||
import com.imyeyu.api.modules.common.entity.Multilingual;
|
import com.imyeyu.api.modules.common.entity.Multilingual;
|
||||||
import com.imyeyu.api.modules.common.mapper.MultilingualMapper;
|
import com.imyeyu.api.modules.common.mapper.MultilingualMapper;
|
||||||
import com.imyeyu.api.modules.common.service.MultilingualService;
|
import com.imyeyu.api.modules.common.service.MultilingualService;
|
||||||
|
import com.imyeyu.api.util.PinyinUtil;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
import com.imyeyu.spring.util.Redis;
|
import com.imyeyu.spring.util.Redis;
|
||||||
@@ -34,6 +35,18 @@ public class MultilingualServiceImplement extends AbstractEntityService<Multilin
|
|||||||
return mapper;
|
return mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void create(Multilingual multilingual) {
|
||||||
|
fillPinyin(multilingual);
|
||||||
|
super.create(multilingual);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(Multilingual multilingual) {
|
||||||
|
fillPinyin(multilingual);
|
||||||
|
super.update(multilingual);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Multilingual get(String id) {
|
public Multilingual get(String id) {
|
||||||
Multilingual result = redisLanguage.get(getKey(id));
|
Multilingual result = redisLanguage.get(getKey(id));
|
||||||
@@ -81,4 +94,14 @@ public class MultilingualServiceImplement extends AbstractEntityService<Multilin
|
|||||||
private String getKey(String id) {
|
private String getKey(String id) {
|
||||||
return "%s%s".formatted(KEY_PREFIX, id);
|
return "%s%s".formatted(KEY_PREFIX, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fillPinyin(Multilingual multilingual) {
|
||||||
|
if (multilingual == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String zhCN = multilingual.getZhCN();
|
||||||
|
multilingual.setZhCNPinyinFull(PinyinUtil.full(zhCN));
|
||||||
|
multilingual.setZhCNPinyinInitial(PinyinUtil.initial(zhCN));
|
||||||
|
multilingual.setZhCNPinyinMixed(PinyinUtil.mixed(zhCN));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+223
@@ -1,12 +1,27 @@
|
|||||||
package com.imyeyu.api.modules.common.service.implement;
|
package com.imyeyu.api.modules.common.service.implement;
|
||||||
|
|
||||||
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Notify;
|
||||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||||
import com.imyeyu.api.modules.common.mapper.NotifyDetailMapper;
|
import com.imyeyu.api.modules.common.mapper.NotifyDetailMapper;
|
||||||
|
import com.imyeyu.api.modules.common.mapper.NotifyMapper;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
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.mapper.BaseMapper;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
|
import com.imyeyu.utils.Time;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通知详情服务实现
|
* 通知详情服务实现
|
||||||
@@ -18,10 +33,218 @@ import org.springframework.stereotype.Service;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class NotifyDetailServiceImplement extends AbstractEntityService<NotifyDetail, String> implements NotifyDetailService {
|
public class NotifyDetailServiceImplement extends AbstractEntityService<NotifyDetail, String> implements NotifyDetailService {
|
||||||
|
|
||||||
|
private final NotifyMapper notifyMapper;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
|
||||||
private final NotifyDetailMapper mapper;
|
private final NotifyDetailMapper mapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BaseMapper<NotifyDetail, String> mapper() {
|
protected BaseMapper<NotifyDetail, String> mapper() {
|
||||||
return 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.setContentType(TimiJava.defaultIfNull(detail.getContentType(), detail.getMsgType() == NotifyDetail.MsgType.INTERNAL
|
||||||
|
? NotifyDetail.ContentType.TIP_TAP
|
||||||
|
: NotifyDetail.ContentType.TEXT));
|
||||||
|
|
||||||
|
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));
|
||||||
|
boolean scheduled = Time.now() < detail.getSendAt();
|
||||||
|
detail.setStatus(detail.getMsgType() == NotifyDetail.MsgType.INTERNAL && !scheduled
|
||||||
|
? NotifyDetail.Status.REMINDED
|
||||||
|
: NotifyDetail.Status.WAITING);
|
||||||
|
detail.setReadAt(null);
|
||||||
|
super.create(detail);
|
||||||
|
if (detail.getMsgType() == NotifyDetail.MsgType.INTERNAL) {
|
||||||
|
attachmentService.updateByBizId(Attachment.BizType.NOTIFY_DETAIL, detail.getId(), detail.getAttachmentList());
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
List<NotifyDetail> detailList = mapper.selectAllByExample(example);
|
||||||
|
loadAttachments(detailList);
|
||||||
|
return detailList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 删除通知详情
|
||||||
|
///
|
||||||
|
/// @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));
|
||||||
|
List<NotifyDetail> detailList = unreadOnly
|
||||||
|
? mapper.selectUnreadSiteByUserId(userId, validPage.getOffset(), validPage.getLimit())
|
||||||
|
: mapper.selectSiteByUserId(userId, validPage.getOffset(), validPage.getLimit());
|
||||||
|
loadAttachments(detailList);
|
||||||
|
result.setList(detailList);
|
||||||
|
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, "未找到站内通知");
|
||||||
|
loadAttachments(detail);
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 回填通知详情的媒体附件
|
||||||
|
///
|
||||||
|
/// @param detailList 通知详情列表
|
||||||
|
private void loadAttachments(List<NotifyDetail> detailList) {
|
||||||
|
List<String> detailIdList = detailList.stream()
|
||||||
|
.filter(detail -> detail.getMsgType() == NotifyDetail.MsgType.INTERNAL)
|
||||||
|
.map(NotifyDetail::getId)
|
||||||
|
.toList();
|
||||||
|
if (detailIdList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, List<Attachment>> attachmentMap = attachmentService.mapByBizIdList(
|
||||||
|
Attachment.BizType.NOTIFY_DETAIL,
|
||||||
|
detailIdList
|
||||||
|
);
|
||||||
|
for (NotifyDetail detail : detailList) {
|
||||||
|
if (detail.getMsgType() == NotifyDetail.MsgType.INTERNAL) {
|
||||||
|
detail.setAttachmentList(attachmentMap.getOrDefault(detail.getId(), List.of()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 回填通知详情的媒体附件
|
||||||
|
///
|
||||||
|
/// @param detail 通知详情
|
||||||
|
private void loadAttachments(NotifyDetail detail) {
|
||||||
|
if (detail.getMsgType() == NotifyDetail.MsgType.INTERNAL) {
|
||||||
|
detail.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.NOTIFY_DETAIL, detail.getId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 隐藏当前用户拥有的站内通知详情
|
||||||
|
///
|
||||||
|
/// @param detailId 通知详情 ID
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
@Override
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
public void hideInternalByUserId(String detailId, String userId) {
|
||||||
|
TimiException.required(detailId, "未找到通知详情 ID");
|
||||||
|
TimiException.required(userId, "未找到用户 ID");
|
||||||
|
int affected = mapper.hideSiteByIdAndUserId(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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+172
@@ -1,12 +1,28 @@
|
|||||||
package com.imyeyu.api.modules.common.service.implement;
|
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.Notify;
|
||||||
|
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||||
import com.imyeyu.api.modules.common.mapper.NotifyMapper;
|
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.common.service.NotifyService;
|
||||||
|
import com.imyeyu.api.modules.system.entity.Logger;
|
||||||
|
import com.imyeyu.api.modules.system.service.LoggerService;
|
||||||
|
import com.imyeyu.api.modules.common.vo.NotifyManagementItem;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通知服务实现
|
* 通知服务实现
|
||||||
@@ -14,14 +30,170 @@ import org.springframework.stereotype.Service;
|
|||||||
* @author 夜雨
|
* @author 夜雨
|
||||||
* @since 2026-05-13 14:46
|
* @since 2026-05-13 14:46
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class NotifyServiceImplement extends AbstractEntityService<Notify, String> implements NotifyService {
|
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;
|
private final NotifyMapper mapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BaseMapper<Notify, String> mapper() {
|
protected BaseMapper<Notify, String> mapper() {
|
||||||
return mapper;
|
return mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean existsByBizReminded(String bizType, String bizRemindedType, String bizRemindedId) {
|
||||||
|
return mapper.existsByBizReminded(bizType, bizRemindedType, bizRemindedId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 创建通知并级联创建通知详情
|
||||||
|
///
|
||||||
|
/// @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(), "未找到通知详情列表");
|
||||||
|
String sendFrom = userLoginService.isLogged() ? userLoginService.getRequireLoginUserId() : null;
|
||||||
|
notify.setCreatedBy(sendFrom);
|
||||||
|
super.create(notify);
|
||||||
|
|
||||||
|
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 page 分页参数
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @return 管理端通知列表
|
||||||
|
@Override
|
||||||
|
public PageResult<NotifyManagementItem> pageManagement(Page<Notify> page, String userId) {
|
||||||
|
TimiException.required(userId, "未找到用户 ID");
|
||||||
|
Page<Notify> validPage = TimiJava.defaultIfNull(page, new Page<>());
|
||||||
|
PageResult<NotifyManagementItem> result = new PageResult<>();
|
||||||
|
result.setTotal(mapper.countManagement(userId));
|
||||||
|
result.setList(mapper.selectManagementPage(userId, validPage.getOffset(), validPage.getLimit()));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询当前用户可管理的通知
|
||||||
|
///
|
||||||
|
/// @param notifyId 通知 ID
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @return 通知
|
||||||
|
@Override
|
||||||
|
public Notify getManagement(String notifyId, String userId) {
|
||||||
|
TimiException.required(notifyId, "未找到通知 ID");
|
||||||
|
TimiException.required(userId, "未找到用户 ID");
|
||||||
|
Notify notify = mapper.selectManagement(notifyId, userId);
|
||||||
|
TimiException.required(notify, "未找到可管理的通知");
|
||||||
|
return notify;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 删除当前用户创建的通知
|
||||||
|
///
|
||||||
|
/// @param notifyId 通知 ID
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
@Override
|
||||||
|
public void deleteManagement(String notifyId, String userId) {
|
||||||
|
getManagement(notifyId, userId);
|
||||||
|
delete(notifyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 取消当前用户创建的通知
|
||||||
|
///
|
||||||
|
/// @param notifyId 通知 ID
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
@Override
|
||||||
|
public void cancelManagement(String notifyId, String userId) {
|
||||||
|
getManagement(notifyId, userId);
|
||||||
|
cancel(notifyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 删除通知并级联软删除通知详情
|
||||||
|
///
|
||||||
|
/// @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, "通知没有可取消的通知详情");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+72
@@ -0,0 +1,72 @@
|
|||||||
|
package com.imyeyu.api.modules.common.service.implement;
|
||||||
|
|
||||||
|
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.imyeyu.utils.Regex;
|
||||||
|
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
||||||
|
import com.tencentcloudapi.sms.v20210111.models.SendStatus;
|
||||||
|
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 = jackson.treeToValue(queue.getArgs(), 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+85
@@ -0,0 +1,85 @@
|
|||||||
|
package com.imyeyu.api.modules.common.service.implement;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
import com.imyeyu.api.modules.common.config.NotifyQueueConfig;
|
||||||
|
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.common.service.SmsService;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.utils.Regex;
|
||||||
|
import com.imyeyu.utils.Text;
|
||||||
|
import com.imyeyu.utils.Time;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2026-05-14 12:12
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SmsServiceImplement implements SmsService {
|
||||||
|
|
||||||
|
@Value("${spring.profiles.active}")
|
||||||
|
private String env;
|
||||||
|
|
||||||
|
private final NotifyQueueConfig config;
|
||||||
|
private final ObjectMapper jackson;
|
||||||
|
|
||||||
|
private final NotifyService notifyService;
|
||||||
|
private final NotifyDetailService notifyDetailService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String captchaCreate(Notify notify) {
|
||||||
|
NotifyQueueConfig.Sms.Captcha captchaConf = config.getSms().getCaptcha();
|
||||||
|
|
||||||
|
NotifyDetail detail = notify.getDetailList().getFirst();
|
||||||
|
|
||||||
|
TimiException.requiredTrue(Regex.isMatch(Regex.MOBILE_PHONE, detail.getSendTo()), "invalid mobilePhone");
|
||||||
|
|
||||||
|
String code = Text.randomString("0123456789", 6);
|
||||||
|
if (!env.equalsIgnoreCase("prod")) {
|
||||||
|
code = "123456";
|
||||||
|
}
|
||||||
|
detail.setMsgType(NotifyDetail.MsgType.SMS);
|
||||||
|
detail.setTemplateId(captchaConf.getTemplateId());
|
||||||
|
detail.setArgs(jackson.valueToTree(List.of(code, captchaConf.getTtlMinute())));
|
||||||
|
|
||||||
|
notifyService.create(notify);
|
||||||
|
return notifyDetailService.listByNotifyId(notify.getId()).getFirst().getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NotifyDetail captchaVerify(String detailId, String captcha) {
|
||||||
|
NotifyQueueConfig.Sms.Captcha captchaConf = config.getSms().getCaptcha();
|
||||||
|
|
||||||
|
NotifyDetail detail = notifyDetailService.get(detailId);
|
||||||
|
TimiException.required(detail, "短信验证码无效");
|
||||||
|
TimiException.required(detail.getSendAt(), "短信验证码无效");
|
||||||
|
TimiException.requiredTrue(NotifyDetail.MsgType.SMS == detail.getMsgType(), "短信验证码无效");
|
||||||
|
if (Time.M * captchaConf.getTtlMinute() < Time.now() - detail.getSendAt()) {
|
||||||
|
throw new TimiException(TimiCode.ARG_EXPIRED, "验证码过期");
|
||||||
|
}
|
||||||
|
if (detail.getArgs() instanceof ArrayNode array) {
|
||||||
|
String dbCaptcha = array.get(captchaConf.getArgIndex()).asText();
|
||||||
|
if (!dbCaptcha.equalsIgnoreCase(captcha)) {
|
||||||
|
throw new TimiException(TimiCode.RESULT_BAD, "验证码错误");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new TimiException(TimiCode.ERROR, "not array args");
|
||||||
|
}
|
||||||
|
detail.setNotify(notifyService.get(detail.getNotifyId()));
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -1,5 +1,6 @@
|
|||||||
package com.imyeyu.api.modules.common.service.implement;
|
package com.imyeyu.api.modules.common.service.implement;
|
||||||
|
|
||||||
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
import com.imyeyu.api.modules.common.entity.Tag;
|
import com.imyeyu.api.modules.common.entity.Tag;
|
||||||
import com.imyeyu.api.modules.common.entity.TagApply;
|
import com.imyeyu.api.modules.common.entity.TagApply;
|
||||||
import com.imyeyu.api.modules.common.mapper.TagApplyMapper;
|
import com.imyeyu.api.modules.common.mapper.TagApplyMapper;
|
||||||
@@ -7,11 +8,14 @@ import com.imyeyu.api.modules.common.mapper.TagMapper;
|
|||||||
import com.imyeyu.api.modules.common.service.MultilingualService;
|
import com.imyeyu.api.modules.common.service.MultilingualService;
|
||||||
import com.imyeyu.api.modules.common.service.TagService;
|
import com.imyeyu.api.modules.common.service.TagService;
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
import com.imyeyu.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.mapper.BaseMapper;
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -70,6 +74,14 @@ public class TagServiceImplement extends AbstractEntityService<Tag, String> impl
|
|||||||
return mapper.selectByIdList(new HashSet<>(idList));
|
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
|
@Override
|
||||||
public List<Tag> listByBizType(TagApply.BizType bizType, String bizId) {
|
public List<Tag> listByBizType(TagApply.BizType bizType, String bizId) {
|
||||||
return listByIdList(listApply(bizType, bizId).stream().map(TagApply::getTagId).toList());
|
return listByIdList(listApply(bizType, bizId).stream().map(TagApply::getTagId).toList());
|
||||||
@@ -94,6 +106,19 @@ public class TagServiceImplement extends AbstractEntityService<Tag, String> impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void deleteByOwner(Tag.OwnerType ownerType, String ownerId) {
|
||||||
|
TimiException.required(ownerType, "not found ownerType");
|
||||||
|
TimiException.required(ownerId, "not found ownerId");
|
||||||
|
Tag example = new Tag();
|
||||||
|
example.setOwnerType(ownerType);
|
||||||
|
example.setOwnerId(ownerId);
|
||||||
|
for (Tag tag : mapper.selectAllByExample(example)) {
|
||||||
|
super.delete(tag.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<TagApply> listApply(TagApply.BizType bizType, String bizId) {
|
private List<TagApply> listApply(TagApply.BizType bizType, String bizId) {
|
||||||
TimiException.required(bizType, "not found bizType");
|
TimiException.required(bizType, "not found bizType");
|
||||||
TimiException.required(bizId, "not found bizId");
|
TimiException.required(bizId, "not found bizId");
|
||||||
|
|||||||
+1
@@ -71,6 +71,7 @@ public class TempFileServiceImplement implements TempFileService {
|
|||||||
page.setSize(Long.MAX_VALUE);
|
page.setSize(Long.MAX_VALUE);
|
||||||
{
|
{
|
||||||
Attachment example = new Attachment();
|
Attachment example = new Attachment();
|
||||||
|
example.setBizType(BIZ_TYPE);
|
||||||
example.setUploaderIp(TimiSpring.getRequestIP());
|
example.setUploaderIp(TimiSpring.getRequestIP());
|
||||||
page.setEqualsExample(example);
|
page.setEqualsExample(example);
|
||||||
}
|
}
|
||||||
|
|||||||
+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, "微信推送暂未实现");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.imyeyu.api.modules.common.task;
|
|||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentVariantService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -23,6 +24,7 @@ import java.util.List;
|
|||||||
public class AttachmentClearTask {
|
public class AttachmentClearTask {
|
||||||
|
|
||||||
private final AttachmentService attachmentService;
|
private final AttachmentService attachmentService;
|
||||||
|
private final AttachmentVariantService attachmentVariantService;
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 1 * * ?")
|
@Scheduled(cron = "0 0 1 * * ?")
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -31,19 +33,20 @@ public class AttachmentClearTask {
|
|||||||
List<Attachment> needDestroyList = attachmentService.listNeedDestroy();
|
List<Attachment> needDestroyList = attachmentService.listNeedDestroy();
|
||||||
if (needDestroyList.isEmpty()) {
|
if (needDestroyList.isEmpty()) {
|
||||||
log.info("nothing attachment need clear");
|
log.info("nothing attachment need clear");
|
||||||
return;
|
} else {
|
||||||
}
|
for (Attachment attach : needDestroyList) {
|
||||||
for (Attachment attach : needDestroyList) {
|
try {
|
||||||
try {
|
attachmentService.destroy(attach.getId());
|
||||||
attachmentService.destroy(attach.getId());
|
log.info("clear attachment success: id[{}]", attach.getId());
|
||||||
log.info("clear attachment success: id[{}]", attach.getId());
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
log.error("clear attachment error: id[{}]", attach.getId(), e);
|
||||||
log.error("clear attachment error: id[{}]", attach.getId(), e);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
attachmentVariantService.clearExpired();
|
||||||
log.info("end clear expired attachments");
|
log.info("end clear expired attachments");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("attachment clear task error", e);
|
log.error("attachment clear task error", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.imyeyu.api.modules.common.vo;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/// 管理端通知列表项
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-25
|
||||||
|
@Data
|
||||||
|
public class NotifyManagementItem {
|
||||||
|
|
||||||
|
/// 通知 ID
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/// 创建者用户 ID
|
||||||
|
private String createdBy;
|
||||||
|
|
||||||
|
/// 创建时间
|
||||||
|
private Long createdAt;
|
||||||
|
|
||||||
|
/// 更新时间
|
||||||
|
private Long updatedAt;
|
||||||
|
|
||||||
|
/// 通知标题
|
||||||
|
private String subject;
|
||||||
|
|
||||||
|
/// 通知内容
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/// 内容类型
|
||||||
|
private NotifyDetail.ContentType contentType;
|
||||||
|
|
||||||
|
/// 发送时间
|
||||||
|
private Long sendAt;
|
||||||
|
|
||||||
|
/// 接收用户数量
|
||||||
|
private Long recipientCount;
|
||||||
|
|
||||||
|
/// 已读用户数量
|
||||||
|
private Long readCount;
|
||||||
|
|
||||||
|
/// 等待发送数量
|
||||||
|
private Long waitingCount;
|
||||||
|
|
||||||
|
/// 已发送数量
|
||||||
|
private Long remindedCount;
|
||||||
|
|
||||||
|
/// 超时数量
|
||||||
|
private Long timeoutCount;
|
||||||
|
|
||||||
|
/// 已取消数量
|
||||||
|
private Long cancelCount;
|
||||||
|
|
||||||
|
/// 失败数量
|
||||||
|
private Long failCount;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.imyeyu.api.modules.common.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// @author 夜雨
|
||||||
|
/// @since 2026-08-21 17:59
|
||||||
|
@Data
|
||||||
|
public class SmsCaptchaVerifyRequest {
|
||||||
|
|
||||||
|
private String detailId;
|
||||||
|
|
||||||
|
private String captcha;
|
||||||
|
}
|
||||||
@@ -21,6 +21,14 @@ public enum GaoPermissionCode implements BuiltinPermissionCode {
|
|||||||
|
|
||||||
STORE_DELETE("STORE:DELETE", "门店删除", false, true),
|
STORE_DELETE("STORE:DELETE", "门店删除", false, true),
|
||||||
|
|
||||||
|
STORE_DIARY_CREATE("STORE_DIARY:CREATE", "门店日记创建", true, false),
|
||||||
|
|
||||||
|
STORE_DIARY_READ("STORE_DIARY:READ", "门店日记读取", true, false),
|
||||||
|
|
||||||
|
STORE_DIARY_UPDATE("STORE_DIARY:UPDATE", "门店日记修改", true, false),
|
||||||
|
|
||||||
|
STORE_DIARY_DELETE("STORE_DIARY:DELETE", "门店日记删除", true, false),
|
||||||
|
|
||||||
CUSTOMER_CREATE("CUSTOMER:CREATE", "客户创建", false, false),
|
CUSTOMER_CREATE("CUSTOMER:CREATE", "客户创建", false, false),
|
||||||
|
|
||||||
CUSTOMER_READ("CUSTOMER:READ", "客户读取", false, false),
|
CUSTOMER_READ("CUSTOMER:READ", "客户读取", false, false),
|
||||||
@@ -43,12 +51,76 @@ public enum GaoPermissionCode implements BuiltinPermissionCode {
|
|||||||
|
|
||||||
EVENT_RECORD_READ("EVENT_RECORD:READ", "登记事件记录读取", false, false),
|
EVENT_RECORD_READ("EVENT_RECORD:READ", "登记事件记录读取", false, false),
|
||||||
|
|
||||||
|
EVENT_RECORD_VERIFY("EVENT_RECORD:VERIFY", "登记事件核销", true, false),
|
||||||
|
|
||||||
EVENT_RECORD_EXPORT("EVENT_RECORD:EXPORT", "登记事件记录导出", true, false),
|
EVENT_RECORD_EXPORT("EVENT_RECORD:EXPORT", "登记事件记录导出", true, false),
|
||||||
|
|
||||||
EVENT_RECORD_UPDATE("EVENT_RECORD:UPDATE", "登记事件记录修改", false, false),
|
EVENT_RECORD_UPDATE("EVENT_RECORD:UPDATE", "登记事件记录修改", false, false),
|
||||||
|
|
||||||
EVENT_RECORD_DELETE("EVENT_RECORD:DELETE", "登记事件记录删除", false, false),
|
EVENT_RECORD_DELETE("EVENT_RECORD:DELETE", "登记事件记录删除", false, false),
|
||||||
|
|
||||||
|
PRODUCT_CATEGORY_CREATE("PRODUCT_CATEGORY:CREATE", "产品分类创建", true, true),
|
||||||
|
|
||||||
|
PRODUCT_CATEGORY_READ("PRODUCT_CATEGORY:READ", "产品分类读取", true, true),
|
||||||
|
|
||||||
|
PRODUCT_CATEGORY_UPDATE("PRODUCT_CATEGORY:UPDATE", "产品分类修改", true, true),
|
||||||
|
|
||||||
|
PRODUCT_CREATE("PRODUCT:CREATE", "产品创建", true, true),
|
||||||
|
|
||||||
|
PRODUCT_READ("PRODUCT:READ", "产品读取", true, true),
|
||||||
|
|
||||||
|
PRODUCT_UPDATE("PRODUCT:UPDATE", "产品修改", true, true),
|
||||||
|
|
||||||
|
PRODUCT_STOCK_READ("PRODUCT_STOCK:READ", "产品库存读取", true, true),
|
||||||
|
|
||||||
|
PRODUCT_STOCK_CREATE("PRODUCT_STOCK:CREATE", "产品库存操作", true, true),
|
||||||
|
|
||||||
|
PRODUCT_STOCK_MANUAL_REVOKE("PRODUCT_STOCK:MANUAL_REVOKE", "手工库存流水冲正", true, true),
|
||||||
|
|
||||||
|
SALES_ORDER_CREATE("SALES_ORDER:CREATE", "销售订单创建", true, true),
|
||||||
|
|
||||||
|
SALES_ORDER_READ("SALES_ORDER:READ", "销售订单读取", true, true),
|
||||||
|
|
||||||
|
SALES_ORDER_UPDATE("SALES_ORDER:UPDATE", "销售订单修改", true, true),
|
||||||
|
|
||||||
|
SALES_ORDER_CANCEL("SALES_ORDER:CANCEL", "销售订单取消", true, true),
|
||||||
|
|
||||||
|
SALES_ORDER_PRICE_OVERRIDE("SALES_ORDER:PRICE_OVERRIDE", "销售订单价格修改", true, true),
|
||||||
|
|
||||||
|
ORDER_FULFILLMENT_CREATE("ORDER_FULFILLMENT:CREATE", "统一履约创建", true, true),
|
||||||
|
|
||||||
|
ORDER_FULFILLMENT_READ("ORDER_FULFILLMENT:READ", "统一履约读取", true, true),
|
||||||
|
|
||||||
|
ORDER_FULFILLMENT_VERIFY("ORDER_FULFILLMENT:VERIFY", "统一履约核销", true, true),
|
||||||
|
|
||||||
|
ORDER_FULFILLMENT_REVOKE("ORDER_FULFILLMENT:REVOKE", "统一履约冲正", true, true),
|
||||||
|
|
||||||
|
PACKAGE_CONFIG_CREATE("PACKAGE_CONFIG:CREATE", "套餐配置创建", true, true),
|
||||||
|
|
||||||
|
PACKAGE_CONFIG_READ("PACKAGE_CONFIG:READ", "套餐配置读取", true, true),
|
||||||
|
|
||||||
|
PACKAGE_CONFIG_UPDATE("PACKAGE_CONFIG:UPDATE", "套餐配置修改", true, true),
|
||||||
|
|
||||||
|
PACKAGE_CONFIG_DELETE("PACKAGE_CONFIG:DELETE", "套餐配置删除", true, true),
|
||||||
|
|
||||||
|
CUSTOMER_PACKAGE_CREATE("CUSTOMER_PACKAGE:CREATE", "客户套餐创建", true, true),
|
||||||
|
|
||||||
|
CUSTOMER_PACKAGE_READ("CUSTOMER_PACKAGE:READ", "客户套餐读取", true, true),
|
||||||
|
|
||||||
|
CUSTOMER_PACKAGE_CANCEL("CUSTOMER_PACKAGE:CANCEL", "客户套餐取消", true, true),
|
||||||
|
|
||||||
|
CUSTOMER_PACKAGE_PRICE_OVERRIDE("CUSTOMER_PACKAGE:PRICE_OVERRIDE", "客户套餐成交价和权益配额调整", true, true),
|
||||||
|
|
||||||
|
FUND_RECORD_READ("FUND_RECORD:READ", "资金流水读取", true, true),
|
||||||
|
|
||||||
|
FUND_RECEIVE_CREATE("FUND_RECEIVE:CREATE", "线下收款创建", true, true),
|
||||||
|
|
||||||
|
FUND_RECEIVE_VERIFY("FUND_RECEIVE:VERIFY", "线下收款核销", true, true),
|
||||||
|
|
||||||
|
FUND_REFUND("FUND:REFUND", "套餐退款", true, true),
|
||||||
|
|
||||||
|
FUND_REVOKE("FUND:REVOKE", "资金流水冲正", true, true),
|
||||||
|
|
||||||
POINT_ACCOUNT_READ("POINT_ACCOUNT:READ", "客户积分账户读取", true, true),
|
POINT_ACCOUNT_READ("POINT_ACCOUNT:READ", "客户积分账户读取", true, true),
|
||||||
|
|
||||||
POINT_LEDGER_READ("POINT_LEDGER:READ", "客户积分流水读取", true, true),
|
POINT_LEDGER_READ("POINT_LEDGER:READ", "客户积分流水读取", true, true),
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public enum GaoRoleCode implements BuiltinRoleCode {
|
|||||||
GLOBAL_MANAGER("门店管理", null),
|
GLOBAL_MANAGER("门店管理", null),
|
||||||
|
|
||||||
/// 店长
|
/// 店长
|
||||||
STORE_MANAGER("店长", GLOBAL_MANAGER.name());
|
STORE_MANAGER("店长", null);
|
||||||
|
|
||||||
final String defaultName;
|
final String defaultName;
|
||||||
final String parentCode;
|
final String parentCode;
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ package com.imyeyu.api.modules.gao.controller;
|
|||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoCustomerChartService;
|
import com.imyeyu.api.modules.gao.service.GaoCustomerChartService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerChartReq;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerChartReq;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoEventRecordCalendarView;
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordCalendarView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoEventRecordDailyStatView;
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordDailyStatView;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -26,6 +28,7 @@ import java.util.List;
|
|||||||
public class GaoCustomerChartController {
|
public class GaoCustomerChartController {
|
||||||
|
|
||||||
private final GaoCustomerChartService service;
|
private final GaoCustomerChartService service;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
|
||||||
/// 查询客户登记每日统计,可同时支撑登记趋势和登记事件结构图表
|
/// 查询客户登记每日统计,可同时支撑登记趋势和登记事件结构图表
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -33,6 +36,8 @@ public class GaoCustomerChartController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
@PostMapping("/event/record/daily")
|
@PostMapping("/event/record/daily")
|
||||||
public List<GaoEventRecordDailyStatView> eventRecordDaily(@RequestBody GaoCustomerChartReq req) {
|
public List<GaoEventRecordDailyStatView> eventRecordDaily(@RequestBody GaoCustomerChartReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
req.setStoreId(storeScopeService.resolveStoreId(req.getStoreId()));
|
||||||
return service.eventRecordDailyStat(req);
|
return service.eventRecordDailyStat(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,6 +47,8 @@ public class GaoCustomerChartController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
@PostMapping("/event/record/calendar")
|
@PostMapping("/event/record/calendar")
|
||||||
public List<GaoEventRecordCalendarView> eventRecordCalendar(@RequestBody GaoCustomerChartReq req) {
|
public List<GaoEventRecordCalendarView> eventRecordCalendar(@RequestBody GaoCustomerChartReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
req.setStoreId(storeScopeService.resolveStoreId(req.getStoreId()));
|
||||||
return service.eventRecordCalendar(req);
|
return service.eventRecordCalendar(req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoCustomerConsumptionRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoCustomerConsumptionRecordService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerConsumptionRecordPage;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerConsumptionRecordPageResult;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/// GAO 客户消费事实接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-07
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/customer/consumption-record")
|
||||||
|
public class GaoCustomerConsumptionRecordController {
|
||||||
|
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
private final GaoCustomerService customerService;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
private final GaoCustomerConsumptionRecordService service;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.SALES_ORDER_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
public GaoCustomerConsumptionRecordPageResult list(@RequestBody GaoCustomerConsumptionRecordPage page) {
|
||||||
|
TimiException.required(page, "not found consumption record page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
|
||||||
|
GaoCustomerConsumptionRecordPageResult result = service.pageByQuery(page);
|
||||||
|
List<String> customerIdList = result.getList()
|
||||||
|
.stream()
|
||||||
|
.map(GaoCustomerConsumptionRecord::getCustomerId)
|
||||||
|
.filter(customerId -> customerId != null && !customerId.isBlank())
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
var customerMap = customerService.mapByIdList(customerIdList);
|
||||||
|
Map<String, List<Attachment>> attachmentMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, customerIdList);
|
||||||
|
for (GaoCustomerConsumptionRecord record : result.getList()) {
|
||||||
|
var customer = customerMap.get(record.getCustomerId());
|
||||||
|
if (customer == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
customer.setAttachmentList(attachmentMap.getOrDefault(customer.getId(), List.of()));
|
||||||
|
record.setCustomer(customer);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +1,17 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonView;
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerPage;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerPage;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStateReq;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStateReq;
|
||||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
|
||||||
import com.imyeyu.api.modules.user.service.UserService;
|
import com.imyeyu.api.modules.user.service.UserService;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
@@ -50,11 +46,9 @@ import java.util.Map;
|
|||||||
public class GaoCustomerController {
|
public class GaoCustomerController {
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final RoleChecker roleChecker;
|
|
||||||
private final AttachmentService attachmentService;
|
private final AttachmentService attachmentService;
|
||||||
private final GaoCustomerService service;
|
private final GaoCustomerService service;
|
||||||
private final GaoStoreService gaoStoreService;
|
private final GaoStoreScopeService storeScopeService;
|
||||||
private final UserLoginService userLoginService;
|
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@@ -62,6 +56,8 @@ public class GaoCustomerController {
|
|||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
public PageResult<GaoCustomer> list(@RequestBody GaoCustomerPage page) {
|
public PageResult<GaoCustomer> list(@RequestBody GaoCustomerPage page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
PageResult<GaoCustomer> result = service.pageByQuery(page);
|
PageResult<GaoCustomer> result = service.pageByQuery(page);
|
||||||
|
|
||||||
List<String> idList = result.getList().stream().map(GaoCustomer::getId).distinct().toList();
|
List<String> idList = result.getList().stream().map(GaoCustomer::getId).distinct().toList();
|
||||||
@@ -79,6 +75,8 @@ public class GaoCustomerController {
|
|||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
public GaoCustomer detail(@RequestParam String id) {
|
public GaoCustomer detail(@RequestParam String id) {
|
||||||
GaoCustomer customer = service.get(id);
|
GaoCustomer customer = service.get(id);
|
||||||
|
TimiException.required(customer, "not found customer");
|
||||||
|
storeScopeService.checkStoreId(customer.getStoreId());
|
||||||
if (TimiJava.isNotEmpty(customer.getIntroducerCustomerId())) {
|
if (TimiJava.isNotEmpty(customer.getIntroducerCustomerId())) {
|
||||||
GaoCustomer introducerCustomer = service.get(customer.getIntroducerCustomerId());
|
GaoCustomer introducerCustomer = service.get(customer.getIntroducerCustomerId());
|
||||||
introducerCustomer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, introducerCustomer.getId()));
|
introducerCustomer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, introducerCustomer.getId()));
|
||||||
@@ -97,9 +95,7 @@ public class GaoCustomerController {
|
|||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
public String create(@RequestBody GaoCustomer customer) {
|
public String create(@RequestBody GaoCustomer customer) {
|
||||||
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
customer.setStoreId(storeScopeService.resolveStoreId(customer.getStoreId()));
|
||||||
customer.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
|
||||||
}
|
|
||||||
service.create(customer);
|
service.create(customer);
|
||||||
return customer.getId();
|
return customer.getId();
|
||||||
}
|
}
|
||||||
@@ -109,9 +105,12 @@ public class GaoCustomerController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
public void update(@RequestBody GaoCustomer customer) {
|
public void update(@RequestBody GaoCustomer customer) {
|
||||||
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
TimiException.required(customer, "not found customer");
|
||||||
customer.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
TimiException.required(customer.getId(), "not found customer.id");
|
||||||
}
|
GaoCustomer dbCustomer = service.get(customer.getId());
|
||||||
|
TimiException.required(dbCustomer, "not found customer");
|
||||||
|
storeScopeService.checkStoreId(dbCustomer.getStoreId());
|
||||||
|
customer.setStoreId(dbCustomer.getStoreId());
|
||||||
service.updateWithAttachment(customer);
|
service.updateWithAttachment(customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +119,9 @@ public class GaoCustomerController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_DELETE)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_DELETE)
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
public void delete(@RequestParam String id) {
|
public void delete(@RequestParam String id) {
|
||||||
|
GaoCustomer customer = service.get(id);
|
||||||
|
TimiException.required(customer, "not found customer");
|
||||||
|
storeScopeService.checkStoreId(customer.getStoreId());
|
||||||
service.delete(id);
|
service.delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,6 +133,7 @@ public class GaoCustomerController {
|
|||||||
public GaoCustomer findById(@RequestParam String id) {
|
public GaoCustomer findById(@RequestParam String id) {
|
||||||
GaoCustomer customer = service.get(id);
|
GaoCustomer customer = service.get(id);
|
||||||
TimiException.required(customer, "not found customer");
|
TimiException.required(customer, "not found customer");
|
||||||
|
storeScopeService.checkStoreId(customer.getStoreId());
|
||||||
customer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId()));
|
customer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId()));
|
||||||
return customer;
|
return customer;
|
||||||
}
|
}
|
||||||
@@ -141,7 +144,7 @@ public class GaoCustomerController {
|
|||||||
@PostMapping("/find/code")
|
@PostMapping("/find/code")
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
public GaoCustomer findByCode(@RequestParam String storeId, @RequestParam String code) {
|
public GaoCustomer findByCode(@RequestParam String storeId, @RequestParam String code) {
|
||||||
GaoCustomer customer = service.getByCode(storeId, code);
|
GaoCustomer customer = service.getByCode(storeScopeService.resolveStoreId(storeId), code);
|
||||||
if (customer == null) {
|
if (customer == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -155,7 +158,7 @@ public class GaoCustomerController {
|
|||||||
@PostMapping("/find/name")
|
@PostMapping("/find/name")
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
public GaoCustomer findByName(@RequestParam String storeId, @RequestParam String name) {
|
public GaoCustomer findByName(@RequestParam String storeId, @RequestParam String name) {
|
||||||
GaoCustomer customer = service.getByName(storeId, name);
|
GaoCustomer customer = service.getByName(storeScopeService.resolveStoreId(storeId), name);
|
||||||
if (customer == null) {
|
if (customer == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -169,6 +172,12 @@ public class GaoCustomerController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_EXPORT)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_EXPORT)
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
public void export(@RequestBody Page<GaoCustomer> page) throws IOException {
|
public void export(@RequestBody Page<GaoCustomer> page) throws IOException {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
if (!storeScopeService.hasGlobalScope()) {
|
||||||
|
GaoCustomer example = TimiJava.defaultIfNull(page.getEqualsExample(), new GaoCustomer());
|
||||||
|
example.setStoreId(storeScopeService.resolveStoreId(example.getStoreId()));
|
||||||
|
page.setEqualsExample(example);
|
||||||
|
}
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
String contentDisposition = Network.getFileDownloadHeader("客户列表-%s.xlsx".formatted(Time.serialize.format(Time.now())));
|
String contentDisposition = Network.getFileDownloadHeader("客户列表-%s.xlsx".formatted(Time.serialize.format(Time.now())));
|
||||||
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
@@ -182,6 +191,9 @@ public class GaoCustomerController {
|
|||||||
@PostMapping("/invited/list")
|
@PostMapping("/invited/list")
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
public List<GaoCustomer> listInvited(@RequestParam String introducerCustomerId) {
|
public List<GaoCustomer> listInvited(@RequestParam String introducerCustomerId) {
|
||||||
|
GaoCustomer introducerCustomer = service.get(introducerCustomerId);
|
||||||
|
TimiException.required(introducerCustomer, "not found introducerCustomer");
|
||||||
|
storeScopeService.checkStoreId(introducerCustomer.getStoreId());
|
||||||
List<GaoCustomer> result = service.listInvited(introducerCustomerId);
|
List<GaoCustomer> result = service.listInvited(introducerCustomerId);
|
||||||
List<String> idList = result.stream().map(GaoCustomer::getId).distinct().toList();
|
List<String> idList = result.stream().map(GaoCustomer::getId).distinct().toList();
|
||||||
Map<String, List<Attachment>> attachMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, idList);
|
Map<String, List<Attachment>> attachMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, idList);
|
||||||
@@ -196,6 +208,9 @@ public class GaoCustomerController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
||||||
@PostMapping("/invite/save")
|
@PostMapping("/invite/save")
|
||||||
public void saveInvite(@RequestParam String introducerCustomerId, @RequestParam String customerId) {
|
public void saveInvite(@RequestParam String introducerCustomerId, @RequestParam String customerId) {
|
||||||
|
GaoCustomer customer = service.get(customerId);
|
||||||
|
TimiException.required(customer, "not found customer");
|
||||||
|
storeScopeService.checkStoreId(customer.getStoreId());
|
||||||
service.saveInviteRelation(introducerCustomerId, customerId);
|
service.saveInviteRelation(introducerCustomerId, customerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,6 +219,9 @@ public class GaoCustomerController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
||||||
@PostMapping("/invite/delete")
|
@PostMapping("/invite/delete")
|
||||||
public void deleteInvite(@RequestParam String customerId) {
|
public void deleteInvite(@RequestParam String customerId) {
|
||||||
|
GaoCustomer customer = service.get(customerId);
|
||||||
|
TimiException.required(customer, "not found customer");
|
||||||
|
storeScopeService.checkStoreId(customer.getStoreId());
|
||||||
service.deleteInviteRelation(customerId);
|
service.deleteInviteRelation(customerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,6 +231,8 @@ public class GaoCustomerController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
@PostMapping("/state/daily")
|
@PostMapping("/state/daily")
|
||||||
public List<GaoCustomerDailyStateView> dailyStat(@RequestBody GaoCustomerTrendStateReq req) {
|
public List<GaoCustomerDailyStateView> dailyStat(@RequestBody GaoCustomerTrendStateReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
req.setStoreId(storeScopeService.resolveStoreId(req.getStoreId()));
|
||||||
return service.stateDailyTrend(req);
|
return service.stateDailyTrend(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,6 +242,6 @@ public class GaoCustomerController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
@PostMapping("/state/gender")
|
@PostMapping("/state/gender")
|
||||||
public List<GaoCustomerGenderStatView> genderStat(@RequestParam String storeId) {
|
public List<GaoCustomerGenderStatView> genderStat(@RequestParam String storeId) {
|
||||||
return service.stateGender(storeId);
|
return service.stateGender(storeScopeService.resolveStoreId(storeId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+143
@@ -0,0 +1,143 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoCustomerPackage;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoSalesOrder;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoCustomerPackageService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoOrderFulfillmentService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoSalesOrderService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerPackageCancelRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerPackagePage;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerPackagePurchaseRequest;
|
||||||
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserService;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/// GAO 客户套餐接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-31
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/customer/package")
|
||||||
|
public class GaoCustomerPackageController {
|
||||||
|
|
||||||
|
private final GaoCustomerPackageService service;
|
||||||
|
private final GaoCustomerService customerService;
|
||||||
|
private final GaoOrderFulfillmentService fulfillmentService;
|
||||||
|
private final GaoSalesOrderService salesOrderService;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_PACKAGE_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
public PageResult<GaoCustomerPackage> list(@RequestBody GaoCustomerPackagePage page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
PageResult<GaoCustomerPackage> result = service.pageByQuery(page);
|
||||||
|
fillTransient(result.getList());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_PACKAGE_READ)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
public GaoCustomerPackage detail(@RequestParam String id) {
|
||||||
|
GaoCustomerPackage result = service.get(id);
|
||||||
|
TimiException.required(result, "not found customer package");
|
||||||
|
storeScopeService.checkStoreId(result.getStoreId());
|
||||||
|
fillTransient(List.of(result));
|
||||||
|
GaoCustomer customer = customerService.get(result.getCustomerId());
|
||||||
|
if (customer != null) {
|
||||||
|
customer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId()));
|
||||||
|
}
|
||||||
|
result.setCustomer(customer);
|
||||||
|
result.setFulfillmentList(fulfillmentService.listBySalesOrderId(result.getSalesOrderId()));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_PACKAGE_CREATE)
|
||||||
|
@PostMapping("/purchase")
|
||||||
|
public GaoCustomerPackage purchase(@RequestBody GaoCustomerPackagePurchaseRequest request) {
|
||||||
|
GaoCustomerPackage result = service.purchase(request);
|
||||||
|
fillTransient(List.of(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_PACKAGE_CANCEL)
|
||||||
|
@PostMapping("/cancel")
|
||||||
|
public GaoCustomerPackage cancel(@RequestBody GaoCustomerPackageCancelRequest request) {
|
||||||
|
GaoCustomerPackage result = service.cancel(request);
|
||||||
|
fillTransient(List.of(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillTransient(List<GaoCustomerPackage> packageList) {
|
||||||
|
if (packageList == null || packageList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, GaoSalesOrder> orderMap = salesOrderService.mapByIdList(packageList.stream()
|
||||||
|
.map(GaoCustomerPackage::getSalesOrderId)
|
||||||
|
.filter(value -> value != null && !value.isBlank())
|
||||||
|
.distinct()
|
||||||
|
.toList());
|
||||||
|
List<String> customerIdList = packageList.stream()
|
||||||
|
.map(GaoCustomerPackage::getCustomerId)
|
||||||
|
.filter(value -> value != null && !value.isBlank())
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
Map<String, GaoCustomer> customerMap = customerIdList.isEmpty() ? Map.of() : customerService.mapByIdList(customerIdList);
|
||||||
|
Map<String, List<Attachment>> attachmentMap = customerIdList.isEmpty()
|
||||||
|
? Map.of() : attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, customerIdList, GaoCustomer.AttachType.PHOTO.name());
|
||||||
|
List<String> userIdList = packageList.stream()
|
||||||
|
.map(packageEntity -> orderMap.get(packageEntity.getSalesOrderId()))
|
||||||
|
.filter(order -> order != null)
|
||||||
|
.map(GaoSalesOrder::getCancelOperatorUserId)
|
||||||
|
.filter(value -> value != null && !value.isBlank())
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
Map<String, User> userMap = userIdList.isEmpty() ? Map.of() : userService.mapByIdList(userIdList);
|
||||||
|
for (GaoCustomerPackage packageEntity : packageList) {
|
||||||
|
GaoSalesOrder order = orderMap.get(packageEntity.getSalesOrderId());
|
||||||
|
packageEntity.setSalesOrder(order);
|
||||||
|
packageEntity.setStatus(order == null ? null : order.getStatus());
|
||||||
|
packageEntity.setCancelledAt(order == null ? null : order.getCancelledAt());
|
||||||
|
packageEntity.setCancelOperatorUserId(order == null ? null : order.getCancelOperatorUserId());
|
||||||
|
packageEntity.setCancelReason(order == null ? null : order.getCancelReason());
|
||||||
|
packageEntity.setItemList(order == null ? List.of() : order.getItemList());
|
||||||
|
GaoCustomer customer = customerMap.get(packageEntity.getCustomerId());
|
||||||
|
if (customer != null) {
|
||||||
|
customer.setAttachmentList(attachmentMap.getOrDefault(customer.getId(), List.of()));
|
||||||
|
}
|
||||||
|
packageEntity.setCustomer(customer);
|
||||||
|
String cancelOperatorUserId = order == null ? null : order.getCancelOperatorUserId();
|
||||||
|
packageEntity.setCancelOperator(cancelOperatorUserId == null ? null : userMap.get(cancelOperatorUserId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEventOptionGroup;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPackageConfig;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPackageConfigItem;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoEventService;
|
import com.imyeyu.api.modules.gao.service.GaoEventService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
import com.imyeyu.api.modules.gao.service.GaoPackageConfigService;
|
||||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
import com.imyeyu.spring.bean.Page;
|
import com.imyeyu.spring.bean.Page;
|
||||||
@@ -33,28 +35,76 @@ import java.util.Map;
|
|||||||
public class GaoEventController {
|
public class GaoEventController {
|
||||||
|
|
||||||
private final GaoEventService service;
|
private final GaoEventService service;
|
||||||
private final RoleChecker roleChecker;
|
private final GaoPackageConfigService packageConfigService;
|
||||||
private final GaoStoreService gaoStoreService;
|
private final GaoStoreScopeService storeScopeService;
|
||||||
private final UserLoginService userLoginService;
|
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_READ)
|
@RequireGaoPermission(GaoPermissionCode.EVENT_READ)
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
public PageResult<GaoEvent> list(@RequestBody Page<GaoEvent> page) {
|
public PageResult<GaoEvent> list(@RequestBody Page<GaoEvent> page) {
|
||||||
PageResult<GaoEvent> result = service.page(page);
|
TimiException.required(page, "not found page");
|
||||||
Map<String, List<String>> roleMap = service.mapRoleCodeListByEventIdList(result.getList().stream().map(GaoEvent::getId).toList());
|
resolveStoreScope(page);
|
||||||
for (GaoEvent event : result.getList()) {
|
PageResult<GaoEvent> result = service.pageWithoutDeleted(page);
|
||||||
event.setRoleCodeList(roleMap.get(event.getId()));
|
return attachEventRelations(result);
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_CREATE)
|
||||||
|
@PostMapping("/list/history")
|
||||||
|
public PageResult<GaoEvent> listHistory(@RequestBody Page<GaoEvent> page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
resolveStoreScope(page);
|
||||||
|
return attachEventRelations(service.page(page));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resolveStoreScope(Page<GaoEvent> page) {
|
||||||
|
if (!storeScopeService.hasGlobalScope()) {
|
||||||
|
GaoEvent example = TimiJava.defaultIfNull(page.getEqualsExample(), new GaoEvent());
|
||||||
|
example.setStoreId(storeScopeService.resolveStoreId(example.getStoreId()));
|
||||||
|
page.setEqualsExample(example);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PageResult<GaoEvent> attachEventRelations(PageResult<GaoEvent> result) {
|
||||||
|
Map<String, List<String>> roleMap = service.mapRoleCodeListByEventIdList(result.getList().stream().map(GaoEvent::getId).toList());
|
||||||
|
for (GaoEvent event : result.getList()) {
|
||||||
|
event.setRoleCodeList(roleMap.get(event.getId()));
|
||||||
|
}
|
||||||
|
service.attachOptionGroupList(result.getList());
|
||||||
|
attachPackageConfig(result.getList());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void attachPackageConfig(List<GaoEvent> eventList) {
|
||||||
|
List<String> packageConfigIdList = eventList.stream()
|
||||||
|
.map(GaoEvent::getPackageConfigId)
|
||||||
|
.filter(TimiJava::isNotEmpty)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
if (packageConfigIdList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, GaoPackageConfig> packageConfigMap = packageConfigService.mapByIdList(packageConfigIdList);
|
||||||
|
Map<String, List<GaoPackageConfigItem>> itemMap = packageConfigService.mapItemListByPackageConfigIdList(packageConfigIdList);
|
||||||
|
for (GaoEvent event : eventList) {
|
||||||
|
GaoPackageConfig packageConfig = packageConfigMap.get(event.getPackageConfigId());
|
||||||
|
if (packageConfig != null) {
|
||||||
|
packageConfig.setItemList(itemMap.getOrDefault(packageConfig.getId(), List.of()));
|
||||||
|
event.setPackageConfig(packageConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_READ)
|
||||||
@PostMapping("/list/valid")
|
@PostMapping("/list/valid")
|
||||||
public List<GaoEvent> listValid(@RequestParam String storeId) {
|
public List<GaoEvent> listValid(@RequestParam String storeId) {
|
||||||
return service.listValid(storeId);
|
List<GaoEvent> result = service.listValid(storeScopeService.resolveStoreId(storeId));
|
||||||
|
attachPackageConfig(result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -63,7 +113,11 @@ public class GaoEventController {
|
|||||||
@PostMapping("/detail")
|
@PostMapping("/detail")
|
||||||
public GaoEvent detail(@RequestParam String id) {
|
public GaoEvent detail(@RequestParam String id) {
|
||||||
GaoEvent event = service.get(id);
|
GaoEvent event = service.get(id);
|
||||||
|
TimiException.required(event, "not found event");
|
||||||
|
storeScopeService.checkStoreId(event.getStoreId());
|
||||||
event.setRoleCodeList(service.listRoleCode(event.getId()));
|
event.setRoleCodeList(service.listRoleCode(event.getId()));
|
||||||
|
service.attachOptionGroupList(List.of(event));
|
||||||
|
attachPackageConfig(List.of(event));
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,9 +126,8 @@ public class GaoEventController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_CREATE)
|
@RequireGaoPermission(GaoPermissionCode.EVENT_CREATE)
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public void create(@RequestBody GaoEvent event) {
|
public void create(@RequestBody GaoEvent event) {
|
||||||
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
event.setStoreId(storeScopeService.resolveStoreId(event.getStoreId()));
|
||||||
event.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
validatePackageConfigBinding(event);
|
||||||
}
|
|
||||||
service.create(event);
|
service.create(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,17 +136,48 @@ public class GaoEventController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.EVENT_UPDATE)
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
public void update(@RequestBody GaoEvent event) {
|
public void update(@RequestBody GaoEvent event) {
|
||||||
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
TimiException.required(event, "not found event");
|
||||||
event.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
TimiException.required(event.getId(), "not found event.id");
|
||||||
}
|
GaoEvent dbEvent = service.get(event.getId());
|
||||||
|
TimiException.required(dbEvent, "not found event");
|
||||||
|
storeScopeService.checkStoreId(dbEvent.getStoreId());
|
||||||
|
event.setStoreId(dbEvent.getStoreId());
|
||||||
|
validatePackageConfigBinding(event);
|
||||||
service.update(event);
|
service.update(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validatePackageConfigBinding(GaoEvent event) {
|
||||||
|
if (event.getBizType() == GaoEvent.BizType.PACKAGE_PURCHASE) {
|
||||||
|
TimiException.required(event.getPackageConfigId(), "购买套餐事件必须绑定套餐配置");
|
||||||
|
GaoPackageConfig packageConfig = packageConfigService.get(event.getPackageConfigId());
|
||||||
|
TimiException.required(packageConfig, "购买套餐事件绑定的套餐配置不存在");
|
||||||
|
TimiException.requiredTrue(event.getStoreId().equals(packageConfig.getStoreId()), "购买事件和套餐配置不属于同一门店");
|
||||||
|
} else {
|
||||||
|
TimiException.requiredNull(event.getPackageConfigId(), "普通事件不能绑定套餐配置");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_UPDATE)
|
||||||
|
@PostMapping("/options/update")
|
||||||
|
public void updateOptions(@RequestParam String id, @RequestBody List<GaoEventOptionGroup> optionGroupList) {
|
||||||
|
GaoEvent event = service.get(id);
|
||||||
|
TimiException.required(event, "not found event");
|
||||||
|
storeScopeService.checkStoreId(event.getStoreId());
|
||||||
|
service.updateOptionGroupList(id, optionGroupList);
|
||||||
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.EVENT_UPDATE)
|
||||||
@PostMapping("/sort")
|
@PostMapping("/sort")
|
||||||
public void sort(@RequestBody List<String> idList) {
|
public void sort(@RequestBody List<String> idList) {
|
||||||
|
for (String id : TimiJava.safeIterable(idList)) {
|
||||||
|
GaoEvent event = service.get(id);
|
||||||
|
TimiException.required(event, "not found event");
|
||||||
|
storeScopeService.checkStoreId(event.getStoreId());
|
||||||
|
}
|
||||||
service.sort(idList);
|
service.sort(idList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +186,9 @@ public class GaoEventController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_DELETE)
|
@RequireGaoPermission(GaoPermissionCode.EVENT_DELETE)
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
public void delete(@RequestParam String id) {
|
public void delete(@RequestParam String id) {
|
||||||
|
GaoEvent event = service.get(id);
|
||||||
|
TimiException.required(event, "not found event");
|
||||||
|
storeScopeService.checkStoreId(event.getStoreId());
|
||||||
service.delete(id);
|
service.delete(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,25 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonView;
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoEventRecordService;
|
import com.imyeyu.api.modules.gao.service.GaoEventRecordService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoEventService;
|
import com.imyeyu.api.modules.gao.service.GaoEventService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerEventRankView;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerEventRankView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoEventOptionStatView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoEventRecordPage;
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordPage;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoEventRecordPageResult;
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordPageResult;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoEventRecordRankPage;
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordRankPage;
|
||||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
|
||||||
import com.imyeyu.api.modules.user.service.UserService;
|
import com.imyeyu.api.modules.user.service.UserService;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
import com.imyeyu.network.Network;
|
import com.imyeyu.network.Network;
|
||||||
import com.imyeyu.spring.TimiSpring;
|
import com.imyeyu.spring.TimiSpring;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
@@ -52,13 +50,11 @@ import java.util.Map;
|
|||||||
public class GaoEventRecordController {
|
public class GaoEventRecordController {
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final RoleChecker roleChecker;
|
|
||||||
private final GaoEventService eventService;
|
private final GaoEventService eventService;
|
||||||
private final AttachmentService attachmentService;
|
private final AttachmentService attachmentService;
|
||||||
private final GaoCustomerService customerService;
|
private final GaoCustomerService customerService;
|
||||||
private final GaoStoreService gaoStoreService;
|
private final GaoStoreScopeService storeScopeService;
|
||||||
private final GaoEventRecordService service;
|
private final GaoEventRecordService service;
|
||||||
private final UserLoginService userLoginService;
|
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@@ -66,6 +62,8 @@ public class GaoEventRecordController {
|
|||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
public GaoEventRecordPageResult list(@RequestBody GaoEventRecordPage page) {
|
public GaoEventRecordPageResult list(@RequestBody GaoEventRecordPage page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
PageResult<GaoEventRecord> pageResult = service.pageByRange(page);
|
PageResult<GaoEventRecord> pageResult = service.pageByRange(page);
|
||||||
GaoEventRecordPageResult result = new GaoEventRecordPageResult();
|
GaoEventRecordPageResult result = new GaoEventRecordPageResult();
|
||||||
result.setTotal(pageResult.getTotal());
|
result.setTotal(pageResult.getTotal());
|
||||||
@@ -81,6 +79,7 @@ public class GaoEventRecordController {
|
|||||||
record.setCustomer(customerMap.get(record.getCustomerId()));
|
record.setCustomer(customerMap.get(record.getCustomerId()));
|
||||||
record.getCustomer().setAttachmentList(attachMap.get(record.getCustomerId()));
|
record.getCustomer().setAttachmentList(attachMap.get(record.getCustomerId()));
|
||||||
}
|
}
|
||||||
|
service.attachSelectedOptionGroupList(result.getList());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -108,22 +107,39 @@ public class GaoEventRecordController {
|
|||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
public GaoEventRecord detail(@RequestParam String id) {
|
public GaoEventRecord detail(@RequestParam String id) {
|
||||||
GaoEventRecord record = service.get(id);
|
GaoEventRecord record = service.get(id);
|
||||||
|
TimiException.required(record, "not found event record");
|
||||||
|
storeScopeService.checkStoreId(record.getStoreId());
|
||||||
record.setCustomer(customerService.get(record.getCustomerId()));
|
record.setCustomer(customerService.get(record.getCustomerId()));
|
||||||
record.getCustomer().setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, record.getCustomerId()));
|
record.getCustomer().setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, record.getCustomerId()));
|
||||||
record.setEvent(eventService.get(record.getEventId()));
|
record.setEvent(eventService.get(record.getEventId()));
|
||||||
|
eventService.attachOptionGroupList(List.of(record.getEvent()));
|
||||||
record.setOperator(userService.get(record.getOperatorUserId()));
|
record.setOperator(userService.get(record.getOperatorUserId()));
|
||||||
|
record.setUpdater(userService.get(record.getUpdatedBy()));
|
||||||
|
if (record.getVerifierUserId() != null) {
|
||||||
|
record.setVerifier(userService.get(record.getVerifierUserId()));
|
||||||
|
}
|
||||||
record.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_EVENT_RECORD, record.getId()));
|
record.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_EVENT_RECORD, record.getId()));
|
||||||
|
service.attachSelectedOptionGroupList(List.of(record));
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_VERIFY)
|
||||||
|
@PostMapping("/verify")
|
||||||
|
public void verify(@RequestParam String id) {
|
||||||
|
GaoEventRecord record = service.get(id);
|
||||||
|
TimiException.required(record, "not found event record");
|
||||||
|
storeScopeService.checkStoreId(record.getStoreId());
|
||||||
|
service.verify(id);
|
||||||
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_CREATE)
|
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_CREATE)
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public void create(@RequestBody GaoEventRecord record) {
|
public void create(@RequestBody GaoEventRecord record) {
|
||||||
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
resolveCreateRecordStore(record);
|
||||||
record.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
|
||||||
}
|
|
||||||
service.create(record);
|
service.create(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,11 +148,8 @@ public class GaoEventRecordController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_CREATE)
|
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_CREATE)
|
||||||
@PostMapping("/create/batch")
|
@PostMapping("/create/batch")
|
||||||
public void createBatch(@RequestBody List<GaoEventRecord> recordList) {
|
public void createBatch(@RequestBody List<GaoEventRecord> recordList) {
|
||||||
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
for (GaoEventRecord record : TimiJava.safeIterable(recordList)) {
|
||||||
String storeId = gaoStoreService.getBelongIdByRequiredLoginUserId();
|
resolveCreateRecordStore(record);
|
||||||
for (GaoEventRecord record : recordList) {
|
|
||||||
record.setStoreId(storeId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
service.createBatch(recordList);
|
service.createBatch(recordList);
|
||||||
}
|
}
|
||||||
@@ -146,11 +159,17 @@ public class GaoEventRecordController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_CREATE)
|
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_CREATE)
|
||||||
@PostMapping("/create/customer")
|
@PostMapping("/create/customer")
|
||||||
public void createWithCustomer(@RequestBody GaoCustomer customer) {
|
public void createWithCustomer(@RequestBody GaoCustomer customer) {
|
||||||
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
TimiException.required(customer, "not found customer");
|
||||||
String storeId = gaoStoreService.getBelongIdByRequiredLoginUserId();
|
if (TimiJava.isNotEmpty(customer.getId())) {
|
||||||
for (GaoEventRecord record : TimiJava.safeIterable(customer.getEventRecordList())) {
|
GaoCustomer dbCustomer = customerService.get(customer.getId());
|
||||||
record.setStoreId(storeId);
|
TimiException.required(dbCustomer, "not found customer");
|
||||||
}
|
storeScopeService.checkStoreId(dbCustomer.getStoreId());
|
||||||
|
customer.setStoreId(dbCustomer.getStoreId());
|
||||||
|
} else {
|
||||||
|
customer.setStoreId(storeScopeService.resolveStoreId(customer.getStoreId()));
|
||||||
|
}
|
||||||
|
for (GaoEventRecord record : TimiJava.safeIterable(customer.getEventRecordList())) {
|
||||||
|
resolveCreateRecordStore(record);
|
||||||
}
|
}
|
||||||
service.createWithCustomer(customer);
|
service.createWithCustomer(customer);
|
||||||
}
|
}
|
||||||
@@ -160,9 +179,12 @@ public class GaoEventRecordController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_UPDATE)
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
public void update(@RequestBody GaoEventRecord record) {
|
public void update(@RequestBody GaoEventRecord record) {
|
||||||
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
TimiException.required(record, "not found event record");
|
||||||
record.setStoreId(gaoStoreService.getBelongIdByRequiredLoginUserId());
|
TimiException.required(record.getId(), "not found event record.id");
|
||||||
}
|
GaoEventRecord dbRecord = service.get(record.getId());
|
||||||
|
TimiException.required(dbRecord, "not found event record");
|
||||||
|
storeScopeService.checkStoreId(dbRecord.getStoreId());
|
||||||
|
record.setStoreId(dbRecord.getStoreId());
|
||||||
service.update(record);
|
service.update(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,6 +193,9 @@ public class GaoEventRecordController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_DELETE)
|
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_DELETE)
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
public void delete(@RequestParam String id) {
|
public void delete(@RequestParam String id) {
|
||||||
|
GaoEventRecord record = service.get(id);
|
||||||
|
TimiException.required(record, "not found event record");
|
||||||
|
storeScopeService.checkStoreId(record.getStoreId());
|
||||||
service.delete(id);
|
service.delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,6 +205,8 @@ public class GaoEventRecordController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_EXPORT)
|
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_EXPORT)
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
public void export(@RequestBody GaoEventRecordPage page) throws IOException {
|
public void export(@RequestBody GaoEventRecordPage page) throws IOException {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
String contentDisposition = Network.getFileDownloadHeader("登记事件记录-%s.xlsx".formatted(Time.serialize.format(Time.now())));
|
String contentDisposition = Network.getFileDownloadHeader("登记事件记录-%s.xlsx".formatted(Time.serialize.format(Time.now())));
|
||||||
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
@@ -193,6 +220,8 @@ public class GaoEventRecordController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
@PostMapping("/rank")
|
@PostMapping("/rank")
|
||||||
public PageResult<GaoCustomerEventRankView> eventRank(@RequestBody GaoEventRecordRankPage page) {
|
public PageResult<GaoCustomerEventRankView> eventRank(@RequestBody GaoEventRecordRankPage page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
PageResult<GaoCustomerEventRankView> result = service.pageRankByRange(page);
|
PageResult<GaoCustomerEventRankView> result = service.pageRankByRange(page);
|
||||||
List<String> customerIdList = result.getList().stream().map(GaoCustomerEventRankView::getCustomerId).distinct().toList();
|
List<String> customerIdList = result.getList().stream().map(GaoCustomerEventRankView::getCustomerId).distinct().toList();
|
||||||
if (customerIdList.isEmpty()) {
|
if (customerIdList.isEmpty()) {
|
||||||
@@ -209,4 +238,22 @@ public class GaoEventRecordController {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/option/stat")
|
||||||
|
public List<GaoEventOptionStatView> optionStat(@RequestBody GaoEventRecordPage page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
return service.optionStatByRange(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resolveCreateRecordStore(GaoEventRecord record) {
|
||||||
|
TimiException.required(record, "not found event record");
|
||||||
|
GaoEvent event = eventService.get(record.getEventId());
|
||||||
|
TimiException.required(event, "not found event");
|
||||||
|
storeScopeService.checkStoreId(event.getStoreId());
|
||||||
|
record.setStoreId(event.getStoreId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,133 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoFundRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoFundRecordService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoOrderPaymentService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoFundRecordPage;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoFundRevokeRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoOrderPaymentRevokeRequest;
|
||||||
|
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.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/// GAO 资金流水接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-31
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/fund/record")
|
||||||
|
public class GaoFundRecordController {
|
||||||
|
|
||||||
|
private final GaoFundRecordService service;
|
||||||
|
private final GaoOrderPaymentService orderPaymentService;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
private final UserService userService;
|
||||||
|
private final UserLoginService userLoginService;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.FUND_RECORD_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
public PageResult<GaoFundRecord> list(@RequestBody GaoFundRecordPage page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
PageResult<GaoFundRecord> result = service.pageByQuery(page);
|
||||||
|
fillTransient(result.getList());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.FUND_RECORD_READ)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
public GaoFundRecord detail(@RequestParam String id) {
|
||||||
|
GaoFundRecord result = service.detail(id);
|
||||||
|
storeScopeService.checkStoreId(result.getStoreId());
|
||||||
|
fillTransient(List.of(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.FUND_RECEIVE_CREATE)
|
||||||
|
@PostMapping("/my-receive/list")
|
||||||
|
public PageResult<GaoFundRecord> listMyReceive(@RequestBody GaoFundRecordPage page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
page.setOperatorUserId(userLoginService.getRequireLoginUserId());
|
||||||
|
page.setOperationType(GaoFundRecord.OperationType.RECEIVE);
|
||||||
|
PageResult<GaoFundRecord> result = service.pageByQuery(page);
|
||||||
|
fillTransient(result.getList());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.FUND_RECEIVE_CREATE)
|
||||||
|
@PostMapping("/my-receive/detail")
|
||||||
|
public GaoFundRecord detailMyReceive(@RequestParam String id) {
|
||||||
|
GaoFundRecord result = service.detail(id);
|
||||||
|
TimiException.requiredTrue(result.getOperationType() == GaoFundRecord.OperationType.RECEIVE, "not found fund receive record");
|
||||||
|
TimiException.requiredTrue(userLoginService.getRequireLoginUserId().equals(result.getOperatorUserId()), "只能读取自己提交的收款");
|
||||||
|
storeScopeService.checkStoreId(result.getStoreId());
|
||||||
|
fillTransient(List.of(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.FUND_REVOKE)
|
||||||
|
@PostMapping("/revoke")
|
||||||
|
public GaoFundRecord revoke(@RequestBody GaoFundRevokeRequest request) {
|
||||||
|
GaoOrderPaymentRevokeRequest orderRequest = new GaoOrderPaymentRevokeRequest();
|
||||||
|
orderRequest.setRequestNo(request.getRequestNo());
|
||||||
|
orderRequest.setFundRecordId(request.getFundRecordId());
|
||||||
|
orderRequest.setOccurredAt(request.getOccurredAt());
|
||||||
|
orderRequest.setReason(request.getReason());
|
||||||
|
orderRequest.setAttachmentList(request.getAttachmentList());
|
||||||
|
orderRequest.setRemark(request.getRemark());
|
||||||
|
GaoFundRecord result = orderPaymentService.revoke(orderRequest);
|
||||||
|
fillTransient(List.of(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillTransient(List<GaoFundRecord> recordList) {
|
||||||
|
if (recordList == null || recordList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> idList = recordList.stream().map(GaoFundRecord::getId).toList();
|
||||||
|
Map<String, List<Attachment>> attachmentMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_FUND_RECORD, idList);
|
||||||
|
List<String> userIdList = recordList.stream()
|
||||||
|
.flatMap(record -> Stream.of(record.getOperatorUserId(), record.getVerifierUserId()))
|
||||||
|
.filter(value -> value != null && !value.isBlank())
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
Map<String, User> userMap = userIdList.isEmpty() ? Map.of() : userService.mapByIdList(userIdList);
|
||||||
|
for (GaoFundRecord record : recordList) {
|
||||||
|
record.setAttachmentList(attachmentMap.getOrDefault(record.getId(), List.of()));
|
||||||
|
record.setOperator(userMap.get(record.getOperatorUserId()));
|
||||||
|
record.setVerifier(userMap.get(record.getVerifierUserId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
|
import com.imyeyu.api.annotation.RequireCorePermission;
|
||||||
|
import com.imyeyu.api.bean.CorePermissionCode;
|
||||||
|
import com.imyeyu.api.bean.PermissionMatchMode;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Notify;
|
||||||
|
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.common.service.NotifyService;
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoUserService;
|
||||||
|
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.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
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 com.imyeyu.utils.Time;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/// GAO 通知接口
|
||||||
|
///
|
||||||
|
/// 这里的通知接收用户必须属于当前操作人的 GAO 用户范围,当前登录用户本人除外。
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-25
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/notify")
|
||||||
|
public class GaoNotifyController {
|
||||||
|
|
||||||
|
private final GaoUserService gaoUserService;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
private final NotifyService notifyService;
|
||||||
|
private final UserLoginService userLoginService;
|
||||||
|
private final UserService userService;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
|
||||||
|
/// 查询可作为通知接收人的 GAO 用户
|
||||||
|
///
|
||||||
|
/// 门店管理范围可以查询全部门店或指定门店,店长只能查询当前门店。
|
||||||
|
///
|
||||||
|
/// @param page 分页参数
|
||||||
|
/// @return 可发送用户分页结果
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
@RequiredToken
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.NOTIFY_CREATE)
|
||||||
|
@RequireGaoPermission(value = {GaoPermissionCode.USER_READ, GaoPermissionCode.STORE_READ}, mode = PermissionMatchMode.ANY)
|
||||||
|
@PostMapping("/recipient/list")
|
||||||
|
public PageResult<GaoUser> recipientList(@RequestBody Page<GaoUser> page) {
|
||||||
|
TimiException.required(page, "未找到分页参数");
|
||||||
|
GaoUser example = TimiJava.defaultIfNull(page.getEqualsExample(), new GaoUser());
|
||||||
|
if (storeScopeService.hasGlobalScope()) {
|
||||||
|
if (TimiJava.isNotEmpty(example.getStoreId())) {
|
||||||
|
storeScopeService.checkStoreId(example.getStoreId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
example.setStoreId(storeScopeService.resolveStoreId(example.getStoreId()));
|
||||||
|
}
|
||||||
|
page.setEqualsExample(example);
|
||||||
|
|
||||||
|
PageResult<GaoUser> result = gaoUserService.pageRecipients(page);
|
||||||
|
fillUser(result.getList());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 创建 GAO 站内通知
|
||||||
|
///
|
||||||
|
/// 只允许发送站内通知,并逐个校验接收用户是否属于当前操作人的门店范围;当前用户可以接收自己发送的通知。
|
||||||
|
///
|
||||||
|
/// @param notify 通知及通知详情
|
||||||
|
/// @return 创建后的通知
|
||||||
|
@RequiredToken
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.NOTIFY_CREATE)
|
||||||
|
@RequireGaoPermission(value = {GaoPermissionCode.USER_READ, GaoPermissionCode.STORE_READ}, mode = PermissionMatchMode.ANY)
|
||||||
|
@PostMapping("/create")
|
||||||
|
public Notify create(@RequestBody Notify notify) {
|
||||||
|
checkRecipientBoundary(notify);
|
||||||
|
notifyService.create(notify);
|
||||||
|
return notify;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 校验通知接收用户边界
|
||||||
|
///
|
||||||
|
/// @param notify 通知
|
||||||
|
private void checkRecipientBoundary(Notify notify) {
|
||||||
|
TimiException.required(notify, "未找到通知");
|
||||||
|
List<NotifyDetail> detailList = notify.getDetailList();
|
||||||
|
TimiException.required(detailList, "未找到通知详情列表");
|
||||||
|
TimiException.requiredTrue(!detailList.isEmpty(), "通知详情列表不能为空");
|
||||||
|
|
||||||
|
Set<String> recipientIdSet = detailList.stream().map(detail -> {
|
||||||
|
TimiException.required(detail, "未找到通知详情");
|
||||||
|
TimiException.requiredTrue(detail.getMsgType() == NotifyDetail.MsgType.INTERNAL, "GAO 通知仅支持站内通知");
|
||||||
|
TimiException.required(detail.getSendTo(), "未找到通知接收用户 ID");
|
||||||
|
if (detail.getSendAt() != null) {
|
||||||
|
TimiException.requiredTrue(Time.now() < detail.getSendAt(), "定时发送时间必须晚于当前时间");
|
||||||
|
}
|
||||||
|
return detail.getSendTo();
|
||||||
|
}).collect(Collectors.toSet());
|
||||||
|
TimiException.requiredTrue(recipientIdSet.size() == detailList.size(), "通知接收用户不能重复");
|
||||||
|
|
||||||
|
String loginUserId = userLoginService.getRequireLoginUserId();
|
||||||
|
Set<String> gaoRecipientIdSet = recipientIdSet.stream()
|
||||||
|
.filter(recipientId -> !loginUserId.equals(recipientId))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
Map<String, GaoUser> gaoUserMap = gaoUserService.mapByUserIdList(gaoRecipientIdSet);
|
||||||
|
TimiException.requiredTrue(gaoUserMap.size() == gaoRecipientIdSet.size(), "包含无效的通知接收用户");
|
||||||
|
for (GaoUser gaoUser : gaoUserMap.values()) {
|
||||||
|
TimiException.requiredTrue(Boolean.TRUE.equals(gaoUser.getEnabled()), "通知接收用户已停用");
|
||||||
|
storeScopeService.checkStoreId(gaoUser.getStoreId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 回填 GAO 用户的核心用户资料
|
||||||
|
///
|
||||||
|
/// @param gaoUserList GAO 用户列表
|
||||||
|
private void fillUser(List<GaoUser> gaoUserList) {
|
||||||
|
if (TimiJava.isEmpty(gaoUserList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> userIdList = gaoUserList.stream().map(GaoUser::getUserId).toList();
|
||||||
|
Map<String, User> userMap = userService.mapByIdList(userIdList);
|
||||||
|
Map<String, List<Attachment>> attachmentMap = attachmentService.mapByBizIdList(
|
||||||
|
Attachment.BizType.USER,
|
||||||
|
userIdList,
|
||||||
|
User.AttachType.AVATAR.toString()
|
||||||
|
);
|
||||||
|
for (GaoUser gaoUser : gaoUserList) {
|
||||||
|
User user = userMap.get(gaoUser.getUserId());
|
||||||
|
if (user == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
user.setAttachmentList(attachmentMap.getOrDefault(user.getId(), List.of()));
|
||||||
|
gaoUser.setUser(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+163
@@ -0,0 +1,163 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoOrderFulfillment;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoOrderFulfillmentService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentActionRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentCreateRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentPage;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentPrepareStockRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentRevokeRequest;
|
||||||
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserService;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/// GAO 统一履约接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-02
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/order/fulfillment")
|
||||||
|
public class GaoOrderFulfillmentController {
|
||||||
|
|
||||||
|
private final GaoOrderFulfillmentService service;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
private final GaoCustomerService customerService;
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.ORDER_FULFILLMENT_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
public PageResult<GaoOrderFulfillment> list(@RequestBody GaoOrderFulfillmentPage page) {
|
||||||
|
TimiException.required(page, "not found fulfillment page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
PageResult<GaoOrderFulfillment> result = service.pageByQuery(page);
|
||||||
|
fillTransient(result.getList());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.ORDER_FULFILLMENT_READ)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
public GaoOrderFulfillment detail(@RequestParam String id) {
|
||||||
|
GaoOrderFulfillment result = service.detail(id);
|
||||||
|
fillTransient(List.of(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.ORDER_FULFILLMENT_CREATE)
|
||||||
|
@PostMapping("/create")
|
||||||
|
public GaoOrderFulfillment create(@RequestBody GaoOrderFulfillmentCreateRequest request) {
|
||||||
|
GaoOrderFulfillment result = service.create(request);
|
||||||
|
fillTransient(List.of(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.ORDER_FULFILLMENT_VERIFY)
|
||||||
|
@PostMapping("/prepare-stock")
|
||||||
|
public GaoOrderFulfillment prepareStock(@RequestBody GaoOrderFulfillmentPrepareStockRequest request) {
|
||||||
|
GaoOrderFulfillment result = service.prepareStock(request);
|
||||||
|
fillTransient(List.of(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.ORDER_FULFILLMENT_VERIFY)
|
||||||
|
@PostMapping("/verify")
|
||||||
|
public GaoOrderFulfillment verify(@RequestBody GaoOrderFulfillmentActionRequest request) {
|
||||||
|
GaoOrderFulfillment result = service.verify(request);
|
||||||
|
fillTransient(List.of(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.ORDER_FULFILLMENT_VERIFY)
|
||||||
|
@PostMapping("/reject")
|
||||||
|
public GaoOrderFulfillment reject(@RequestBody GaoOrderFulfillmentActionRequest request) {
|
||||||
|
GaoOrderFulfillment result = service.reject(request);
|
||||||
|
fillTransient(List.of(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.ORDER_FULFILLMENT_CREATE)
|
||||||
|
@PostMapping("/cancel")
|
||||||
|
public GaoOrderFulfillment cancel(@RequestBody GaoOrderFulfillmentActionRequest request) {
|
||||||
|
GaoOrderFulfillment result = service.cancel(request);
|
||||||
|
fillTransient(List.of(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.ORDER_FULFILLMENT_REVOKE)
|
||||||
|
@PostMapping("/revoke")
|
||||||
|
public GaoOrderFulfillment revoke(@RequestBody GaoOrderFulfillmentRevokeRequest request) {
|
||||||
|
GaoOrderFulfillment result = service.revoke(request);
|
||||||
|
fillTransient(List.of(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillTransient(List<GaoOrderFulfillment> fulfillmentList) {
|
||||||
|
if (fulfillmentList == null || fulfillmentList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> idList = fulfillmentList.stream().map(GaoOrderFulfillment::getId).toList();
|
||||||
|
Map<String, List<Attachment>> attachmentMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_ORDER_FULFILLMENT, idList);
|
||||||
|
List<String> customerIdList = fulfillmentList.stream()
|
||||||
|
.map(GaoOrderFulfillment::getCustomerId)
|
||||||
|
.filter(value -> value != null && !value.isBlank())
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
Map<String, GaoCustomer> customerMap = customerIdList.isEmpty() ? Map.of() : customerService.mapByIdList(customerIdList);
|
||||||
|
Map<String, List<Attachment>> customerAttachmentMap = customerIdList.isEmpty()
|
||||||
|
? Map.of()
|
||||||
|
: attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, customerIdList, GaoCustomer.AttachType.PHOTO.name());
|
||||||
|
List<String> userIdList = fulfillmentList.stream()
|
||||||
|
.flatMap(item -> Stream.of(item.getOperatorUserId(), item.getVerifierUserId()))
|
||||||
|
.filter(value -> value != null && !value.isBlank())
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
Map<String, User> userMap = userIdList.isEmpty() ? Map.of() : userService.mapByIdList(userIdList);
|
||||||
|
for (GaoOrderFulfillment fulfillment : fulfillmentList) {
|
||||||
|
fulfillment.setAttachmentList(attachmentMap.getOrDefault(fulfillment.getId(), List.of()));
|
||||||
|
GaoCustomer customer = customerMap.get(fulfillment.getCustomerId());
|
||||||
|
if (customer != null) {
|
||||||
|
customer.setAttachmentList(customerAttachmentMap.getOrDefault(customer.getId(), List.of()));
|
||||||
|
}
|
||||||
|
fulfillment.setCustomer(customer);
|
||||||
|
fulfillment.setOperator(userMap.get(fulfillment.getOperatorUserId()));
|
||||||
|
fulfillment.setVerifier(userMap.get(fulfillment.getVerifierUserId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPackageConfig;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoPackageConfigItem;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoProductSku;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoEventService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoPackageConfigService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoProductSkuService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoPackageConfigPage;
|
||||||
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserService;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/// GAO 套餐配置接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-31
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/package/config")
|
||||||
|
public class GaoPackageConfigController {
|
||||||
|
|
||||||
|
private final GaoPackageConfigService service;
|
||||||
|
private final GaoEventService eventService;
|
||||||
|
private final GaoProductSkuService skuService;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PACKAGE_CONFIG_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
public PageResult<GaoPackageConfig> list(@RequestBody GaoPackageConfigPage page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
PageResult<GaoPackageConfig> result = service.pageByQuery(page);
|
||||||
|
fillTransient(result.getList(), false);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PACKAGE_CONFIG_READ)
|
||||||
|
@PostMapping("/list/valid")
|
||||||
|
public List<GaoPackageConfig> listValid(@RequestParam String storeId) {
|
||||||
|
List<GaoPackageConfig> result = service.listValid(storeScopeService.resolveStoreId(storeId));
|
||||||
|
fillTransient(result, false);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PACKAGE_CONFIG_READ)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
public GaoPackageConfig detail(@RequestParam String id) {
|
||||||
|
GaoPackageConfig config = service.get(id);
|
||||||
|
TimiException.required(config, "not found package config");
|
||||||
|
storeScopeService.checkStoreId(config.getStoreId());
|
||||||
|
fillTransient(List.of(config), true);
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillTransient(List<GaoPackageConfig> configList, boolean includeProductDetail) {
|
||||||
|
if (configList == null || configList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, List<GaoPackageConfigItem>> itemMap = service.mapItemListByPackageConfigIdList(configList.stream().map(GaoPackageConfig::getId).toList());
|
||||||
|
List<String> updaterIdList = configList.stream().map(GaoPackageConfig::getUpdatedBy).filter(value -> value != null && !value.isBlank()).distinct().toList();
|
||||||
|
Map<String, User> updaterMap = updaterIdList.isEmpty() ? Map.of() : userService.mapByIdList(updaterIdList);
|
||||||
|
for (GaoPackageConfig config : configList) {
|
||||||
|
config.setItemList(itemMap.getOrDefault(config.getId(), List.of()));
|
||||||
|
config.setUpdater(updaterMap.get(config.getUpdatedBy()));
|
||||||
|
}
|
||||||
|
if (includeProductDetail) {
|
||||||
|
fillProductDetails(configList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillProductDetails(List<GaoPackageConfig> configList) {
|
||||||
|
List<String> skuIdList = configList.stream()
|
||||||
|
.flatMap(config -> config.getItemList().stream())
|
||||||
|
.map(GaoPackageConfigItem::getSkuId)
|
||||||
|
.filter(value -> value != null && !value.isBlank())
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
if (skuIdList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, GaoProductSku> skuMap = skuIdList.stream()
|
||||||
|
.collect(java.util.stream.Collectors.toMap(item -> item, skuService::detail));
|
||||||
|
for (GaoPackageConfig config : configList) {
|
||||||
|
for (GaoPackageConfigItem item : config.getItemList()) {
|
||||||
|
item.setSku(skuMap.get(item.getSkuId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PACKAGE_CONFIG_CREATE)
|
||||||
|
@PostMapping("/create")
|
||||||
|
public String create(@RequestBody GaoPackageConfig config) {
|
||||||
|
TimiException.required(config, "not found package config");
|
||||||
|
config.setStoreId(storeScopeService.resolveStoreId(config.getStoreId()));
|
||||||
|
service.create(config);
|
||||||
|
return config.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PACKAGE_CONFIG_UPDATE)
|
||||||
|
@PostMapping("/update")
|
||||||
|
public void update(@RequestBody GaoPackageConfig config) {
|
||||||
|
TimiException.required(config, "not found package config");
|
||||||
|
TimiException.required(config.getId(), "not found packageConfig.id");
|
||||||
|
GaoPackageConfig dbConfig = service.get(config.getId());
|
||||||
|
TimiException.required(dbConfig, "not found package config");
|
||||||
|
storeScopeService.checkStoreId(dbConfig.getStoreId());
|
||||||
|
config.setStoreId(dbConfig.getStoreId());
|
||||||
|
service.update(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PACKAGE_CONFIG_DELETE)
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public void delete(@RequestParam String id) {
|
||||||
|
GaoPackageConfig config = service.get(id);
|
||||||
|
TimiException.required(config, "not found package config");
|
||||||
|
storeScopeService.checkStoreId(config.getStoreId());
|
||||||
|
TimiException.requiredTrue(0 == eventService.countByPackageConfigId(id), "套餐配置已绑定购买事件,不能删除");
|
||||||
|
service.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
+24
-13
@@ -1,17 +1,18 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointAccount;
|
import com.imyeyu.api.modules.gao.entity.GaoPointAccount;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoPointAccountService;
|
import com.imyeyu.api.modules.gao.service.GaoPointAccountService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
import com.imyeyu.api.modules.gao.vo.GaoPointAccountPage;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@@ -25,23 +26,33 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@RequestMapping("/gao/customer/point")
|
@RequestMapping("/gao/customer/point")
|
||||||
public class GaoPointAccountController {
|
public class GaoPointAccountController {
|
||||||
|
|
||||||
private final RoleChecker roleChecker;
|
private final GaoStoreScopeService storeScopeService;
|
||||||
private final GaoStoreService storeService;
|
|
||||||
private final GaoPointAccountService accountService;
|
private final GaoPointAccountService accountService;
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.POINT_ACCOUNT_READ)
|
@RequireGaoPermission(GaoPermissionCode.POINT_ACCOUNT_READ)
|
||||||
@PostMapping("/account/detail")
|
@PostMapping("/account/list")
|
||||||
|
public PageResult<GaoPointAccount> list(@RequestBody GaoPointAccountPage page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
return accountService.pageByQuery(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.POINT_ACCOUNT_READ)
|
||||||
|
@PostMapping("/account/detail/customer")
|
||||||
public GaoPointAccount detail(@RequestParam String customerId, @RequestParam(required = false) String storeId) {
|
public GaoPointAccount detail(@RequestParam String customerId, @RequestParam(required = false) String storeId) {
|
||||||
storeId = resolveStoreId(storeId);
|
storeId = storeScopeService.resolveStoreId(storeId);
|
||||||
return accountService.getByCustomerId(storeId, customerId);
|
return accountService.getByCustomerId(storeId, customerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String resolveStoreId(String requestedStoreId) {
|
@AOPLog
|
||||||
if (roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
@RequestRateLimit
|
||||||
return requestedStoreId;
|
@RequireGaoPermission(GaoPermissionCode.POINT_ACCOUNT_READ)
|
||||||
}
|
@PostMapping("/account/detail")
|
||||||
return storeService.getBelongIdByRequiredLoginUserId();
|
public GaoPointAccount detailById(@RequestParam String id, @RequestParam(required = false) String storeId) {
|
||||||
|
return accountService.getByIdAndStoreId(storeScopeService.resolveStoreId(storeId), id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointLedger;
|
import com.imyeyu.api.modules.gao.entity.GaoPointLedger;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoPointLedgerService;
|
import com.imyeyu.api.modules.gao.service.GaoPointLedgerService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoPointTriggerService;
|
import com.imyeyu.api.modules.gao.service.GaoPointTriggerService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointAdjustRequest;
|
import com.imyeyu.api.modules.gao.vo.GaoPointAdjustRequest;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoPointLedgerPage;
|
import com.imyeyu.api.modules.gao.vo.GaoPointLedgerPage;
|
||||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
@@ -30,8 +27,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@RequestMapping("/gao/customer/point")
|
@RequestMapping("/gao/customer/point")
|
||||||
public class GaoPointLedgerController {
|
public class GaoPointLedgerController {
|
||||||
|
|
||||||
private final RoleChecker roleChecker;
|
private final GaoStoreScopeService storeScopeService;
|
||||||
private final GaoStoreService storeService;
|
|
||||||
private final GaoPointLedgerService ledgerService;
|
private final GaoPointLedgerService ledgerService;
|
||||||
private final GaoPointTriggerService triggerService;
|
private final GaoPointTriggerService triggerService;
|
||||||
|
|
||||||
@@ -41,7 +37,7 @@ public class GaoPointLedgerController {
|
|||||||
@PostMapping("/ledger/list")
|
@PostMapping("/ledger/list")
|
||||||
public PageResult<GaoPointLedger> list(@RequestBody GaoPointLedgerPage page) {
|
public PageResult<GaoPointLedger> list(@RequestBody GaoPointLedgerPage page) {
|
||||||
TimiException.required(page, "not found page");
|
TimiException.required(page, "not found page");
|
||||||
page.setStoreId(resolveStoreId(page.getStoreId()));
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
return ledgerService.pageByQuery(page);
|
return ledgerService.pageByQuery(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,14 +46,7 @@ public class GaoPointLedgerController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.POINT_ADJUST)
|
@RequireGaoPermission(GaoPermissionCode.POINT_ADJUST)
|
||||||
@PostMapping("/adjust")
|
@PostMapping("/adjust")
|
||||||
public void adjust(@RequestBody GaoPointAdjustRequest request) {
|
public void adjust(@RequestBody GaoPointAdjustRequest request) {
|
||||||
request.setStoreId(resolveStoreId(request.getStoreId()));
|
request.setStoreId(storeScopeService.resolveStoreId(request.getStoreId()));
|
||||||
triggerService.adjust(request);
|
triggerService.adjust(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String resolveStoreId(String requestedStoreId) {
|
|
||||||
if (roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
|
||||||
return requestedStoreId;
|
|
||||||
}
|
|
||||||
return storeService.getBelongIdByRequiredLoginUserId();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoPointRule;
|
import com.imyeyu.api.modules.gao.entity.GaoPointRule;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoPointRuleService;
|
import com.imyeyu.api.modules.gao.service.GaoPointRuleService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
@@ -21,6 +18,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/// GAO 客户积分规则接口
|
/// GAO 客户积分规则接口
|
||||||
///
|
///
|
||||||
/// @author Codex
|
/// @author Codex
|
||||||
@@ -30,8 +29,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@RequestMapping("/gao/customer/point")
|
@RequestMapping("/gao/customer/point")
|
||||||
public class GaoPointRuleController {
|
public class GaoPointRuleController {
|
||||||
|
|
||||||
private final RoleChecker roleChecker;
|
private final GaoStoreScopeService storeScopeService;
|
||||||
private final GaoStoreService storeService;
|
|
||||||
private final GaoPointRuleService ruleService;
|
private final GaoPointRuleService ruleService;
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -40,9 +38,9 @@ public class GaoPointRuleController {
|
|||||||
@PostMapping("/rule/list")
|
@PostMapping("/rule/list")
|
||||||
public PageResult<GaoPointRule> list(@RequestBody Page<GaoPointRule> page) {
|
public PageResult<GaoPointRule> list(@RequestBody Page<GaoPointRule> page) {
|
||||||
TimiException.required(page, "not found page");
|
TimiException.required(page, "not found page");
|
||||||
if (!isGlobalManager()) {
|
if (!storeScopeService.hasGlobalScope()) {
|
||||||
GaoPointRule example = TimiJava.defaultIfNull(page.getEqualsExample(), new GaoPointRule());
|
GaoPointRule example = TimiJava.defaultIfNull(page.getEqualsExample(), new GaoPointRule());
|
||||||
example.setStoreId(resolveStoreId(null));
|
example.setStoreId(storeScopeService.resolveStoreId(example.getStoreId()));
|
||||||
page.setEqualsExample(example);
|
page.setEqualsExample(example);
|
||||||
}
|
}
|
||||||
return ruleService.page(page);
|
return ruleService.page(page);
|
||||||
@@ -55,7 +53,7 @@ public class GaoPointRuleController {
|
|||||||
public GaoPointRule detail(@RequestParam String id) {
|
public GaoPointRule detail(@RequestParam String id) {
|
||||||
GaoPointRule rule = ruleService.get(id);
|
GaoPointRule rule = ruleService.get(id);
|
||||||
TimiException.required(rule, "not found point rule");
|
TimiException.required(rule, "not found point rule");
|
||||||
checkStore(rule.getStoreId());
|
storeScopeService.checkStoreId(rule.getStoreId());
|
||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +62,7 @@ public class GaoPointRuleController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.POINT_RULE_CREATE)
|
@RequireGaoPermission(GaoPermissionCode.POINT_RULE_CREATE)
|
||||||
@PostMapping("/rule/create")
|
@PostMapping("/rule/create")
|
||||||
public String create(@RequestBody GaoPointRule rule) {
|
public String create(@RequestBody GaoPointRule rule) {
|
||||||
rule.setStoreId(resolveStoreId(rule.getStoreId()));
|
rule.setStoreId(storeScopeService.resolveStoreId(rule.getStoreId()));
|
||||||
ruleService.create(rule);
|
ruleService.create(rule);
|
||||||
return rule.getId();
|
return rule.getId();
|
||||||
}
|
}
|
||||||
@@ -74,10 +72,23 @@ public class GaoPointRuleController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.POINT_RULE_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.POINT_RULE_UPDATE)
|
||||||
@PostMapping("/rule/update")
|
@PostMapping("/rule/update")
|
||||||
public void update(@RequestBody GaoPointRule rule) {
|
public void update(@RequestBody GaoPointRule rule) {
|
||||||
rule.setStoreId(resolveStoreId(rule.getStoreId()));
|
rule.setStoreId(storeScopeService.resolveStoreId(rule.getStoreId()));
|
||||||
ruleService.update(rule);
|
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)) {
|
||||||
|
storeScopeService.checkStoreId(rule.getStoreId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ruleService.sort(idList);
|
||||||
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.POINT_RULE_DELETE)
|
@RequireGaoPermission(GaoPermissionCode.POINT_RULE_DELETE)
|
||||||
@@ -85,24 +96,7 @@ public class GaoPointRuleController {
|
|||||||
public void delete(@RequestParam String id) {
|
public void delete(@RequestParam String id) {
|
||||||
GaoPointRule rule = ruleService.get(id);
|
GaoPointRule rule = ruleService.get(id);
|
||||||
TimiException.required(rule, "not found point rule");
|
TimiException.required(rule, "not found point rule");
|
||||||
checkStore(rule.getStoreId());
|
storeScopeService.checkStoreId(rule.getStoreId());
|
||||||
ruleService.delete(id);
|
ruleService.delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String resolveStoreId(String requestedStoreId) {
|
|
||||||
if (isGlobalManager()) {
|
|
||||||
return requestedStoreId;
|
|
||||||
}
|
|
||||||
return storeService.getBelongIdByRequiredLoginUserId();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkStore(String storeId) {
|
|
||||||
if (!isGlobalManager()) {
|
|
||||||
TimiException.requiredTrue(resolveStoreId(null).equals(storeId), "无权操作其他门店数据");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isGlobalManager() {
|
|
||||||
return roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,126 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoProductChartService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductCategoryStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductChartReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductFulfillmentDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductFulfillmentRankView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductSalesDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductSalesRankView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductStockHealthView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductStockMovementDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductTypeStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductUnitSalesRankView;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// GAO 产品图表接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-06
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/product/chart")
|
||||||
|
public class GaoProductChartController {
|
||||||
|
|
||||||
|
private final GaoProductChartService service;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
|
||||||
|
/// 查询产品每日销售统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/sales/daily")
|
||||||
|
public List<GaoProductSalesDailyStatView> salesDaily(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.salesDaily(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询产品销售排行
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/sales/rank")
|
||||||
|
public List<GaoProductSalesRankView> salesRank(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.salesRank(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询产品每日履约统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/fulfillment/daily")
|
||||||
|
public List<GaoProductFulfillmentDailyStatView> fulfillmentDaily(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.fulfillmentDaily(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询产品履约进度排行
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/fulfillment/rank")
|
||||||
|
public List<GaoProductFulfillmentRankView> fulfillmentRank(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.fulfillmentRank(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询产品每日库存变动统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/stock/movement/daily")
|
||||||
|
public List<GaoProductStockMovementDailyStatView> stockMovementDaily(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.stockMovementDaily(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询产品库存健康度
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/stock/health")
|
||||||
|
public List<GaoProductStockHealthView> stockHealth(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.stockHealth(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询产品类型统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/structure/type")
|
||||||
|
public List<GaoProductTypeStatView> type(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.type(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询产品分类统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/structure/category")
|
||||||
|
public List<GaoProductCategoryStatView> category(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.category(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询产品销售单位排行
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/sales/unit/rank")
|
||||||
|
public List<GaoProductUnitSalesRankView> unitSalesRank(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.unitSalesRank(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
private GaoProductChartReq normalize(GaoProductChartReq req) {
|
||||||
|
TimiException.required(req, "not found product chart req");
|
||||||
|
req.setStoreId(storeScopeService.resolveStoreId(req.getStoreId()));
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,248 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoProduct;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoProductCategory;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoProductSku;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoProductCategoryService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoProductService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoProductSkuService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoProductSpecService;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoProductSpec;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoProductSpecValue;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductCategoryPage;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductPage;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// GAO 产品库接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-02
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/product")
|
||||||
|
public class GaoProductController {
|
||||||
|
|
||||||
|
private final GaoProductCategoryService categoryService;
|
||||||
|
private final GaoProductService productService;
|
||||||
|
private final GaoProductSkuService skuService;
|
||||||
|
private final GaoProductSpecService specService;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_CATEGORY_READ)
|
||||||
|
@PostMapping("/category/list")
|
||||||
|
public PageResult<GaoProductCategory> categoryList(@RequestBody GaoProductCategoryPage page) {
|
||||||
|
TimiException.required(page, "not found category page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
return categoryService.pageByQuery(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_CATEGORY_CREATE)
|
||||||
|
@PostMapping("/category/create")
|
||||||
|
public String categoryCreate(@RequestBody GaoProductCategory category) {
|
||||||
|
TimiException.required(category, "not found category");
|
||||||
|
category.setStoreId(storeScopeService.resolveStoreId(category.getStoreId()));
|
||||||
|
categoryService.create(category);
|
||||||
|
return category.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_CATEGORY_UPDATE)
|
||||||
|
@PostMapping("/category/update")
|
||||||
|
public void categoryUpdate(@RequestBody GaoProductCategory request) {
|
||||||
|
TimiException.required(request, "not found category");
|
||||||
|
TimiException.required(request.getId(), "not found category.id");
|
||||||
|
GaoProductCategory category = categoryService.get(request.getId());
|
||||||
|
TimiException.required(category, "not found category");
|
||||||
|
storeScopeService.checkStoreId(category.getStoreId());
|
||||||
|
request.setStoreId(category.getStoreId());
|
||||||
|
categoryService.update(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_CATEGORY_UPDATE)
|
||||||
|
@PostMapping("/category/sort")
|
||||||
|
public void categorySort(@RequestBody List<String> idList) {
|
||||||
|
categoryService.sort(idList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_CATEGORY_UPDATE)
|
||||||
|
@PostMapping("/category/disable")
|
||||||
|
public void categoryDisable(@RequestParam String id) {
|
||||||
|
categoryService.disable(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
public PageResult<GaoProduct> list(@RequestBody GaoProductPage page) {
|
||||||
|
TimiException.required(page, "not found product page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
return productService.pageByQuery(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_READ)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
public GaoProduct detail(@RequestParam String id) {
|
||||||
|
GaoProduct result = productService.detail(id);
|
||||||
|
storeScopeService.checkStoreId(result.getStoreId());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_CREATE)
|
||||||
|
@PostMapping("/create")
|
||||||
|
public String create(@RequestBody GaoProduct product) {
|
||||||
|
TimiException.required(product, "not found product");
|
||||||
|
product.setStoreId(storeScopeService.resolveStoreId(product.getStoreId()));
|
||||||
|
productService.create(product);
|
||||||
|
return product.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_UPDATE)
|
||||||
|
@PostMapping("/update")
|
||||||
|
public void update(@RequestBody GaoProduct request) {
|
||||||
|
TimiException.required(request, "not found product");
|
||||||
|
TimiException.required(request.getId(), "not found product.id");
|
||||||
|
GaoProduct product = productService.get(request.getId());
|
||||||
|
TimiException.required(product, "not found product");
|
||||||
|
storeScopeService.checkStoreId(product.getStoreId());
|
||||||
|
request.setStoreId(product.getStoreId());
|
||||||
|
productService.update(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_UPDATE)
|
||||||
|
@PostMapping("/disable")
|
||||||
|
public void disable(@RequestParam String id) {
|
||||||
|
GaoProduct product = productService.get(id);
|
||||||
|
TimiException.required(product, "not found product");
|
||||||
|
storeScopeService.checkStoreId(product.getStoreId());
|
||||||
|
productService.disable(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_READ)
|
||||||
|
@PostMapping("/sku/detail")
|
||||||
|
public GaoProductSku skuDetail(@RequestParam String id) {
|
||||||
|
GaoProductSku result = skuService.detail(id);
|
||||||
|
storeScopeService.checkStoreId(result.getStoreId());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_CREATE)
|
||||||
|
@PostMapping("/sku/create")
|
||||||
|
public String skuCreate(@RequestBody GaoProductSku sku) {
|
||||||
|
TimiException.required(sku, "not found product sku");
|
||||||
|
GaoProduct product = productService.get(sku.getProductId());
|
||||||
|
TimiException.required(product, "not found product");
|
||||||
|
storeScopeService.checkStoreId(product.getStoreId());
|
||||||
|
skuService.create(sku);
|
||||||
|
return sku.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_UPDATE)
|
||||||
|
@PostMapping("/sku/update")
|
||||||
|
public void skuUpdate(@RequestBody GaoProductSku request) {
|
||||||
|
TimiException.required(request, "not found product sku");
|
||||||
|
TimiException.required(request.getId(), "not found product sku.id");
|
||||||
|
GaoProductSku sku = skuService.get(request.getId());
|
||||||
|
TimiException.required(sku, "not found product sku");
|
||||||
|
storeScopeService.checkStoreId(sku.getStoreId());
|
||||||
|
request.setProductId(sku.getProductId());
|
||||||
|
skuService.update(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_UPDATE)
|
||||||
|
@PostMapping("/sku/disable")
|
||||||
|
public void skuDisable(@RequestParam String id) {
|
||||||
|
GaoProductSku sku = skuService.get(id);
|
||||||
|
TimiException.required(sku, "not found product sku");
|
||||||
|
storeScopeService.checkStoreId(sku.getStoreId());
|
||||||
|
skuService.disable(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_READ)
|
||||||
|
@PostMapping("/spec/list")
|
||||||
|
public List<GaoProductSpec> specList(@RequestParam String productId) {
|
||||||
|
GaoProduct product = productService.get(productId);
|
||||||
|
TimiException.required(product, "not found product");
|
||||||
|
storeScopeService.checkStoreId(product.getStoreId());
|
||||||
|
return specService.listByProductId(productId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_UPDATE)
|
||||||
|
@PostMapping("/spec/create")
|
||||||
|
public String specCreate(@RequestBody GaoProductSpec spec) {
|
||||||
|
TimiException.required(spec, "not found product spec");
|
||||||
|
GaoProduct product = productService.get(spec.getProductId());
|
||||||
|
TimiException.required(product, "not found product");
|
||||||
|
storeScopeService.checkStoreId(product.getStoreId());
|
||||||
|
specService.createSpec(spec);
|
||||||
|
return spec.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_UPDATE)
|
||||||
|
@PostMapping("/spec/value/create")
|
||||||
|
public String specValueCreate(@RequestBody GaoProductSpecValue value) {
|
||||||
|
TimiException.required(value, "not found product spec value");
|
||||||
|
String productId = specService.getProductIdBySpecId(value.getSpecId());
|
||||||
|
TimiException.required(productId, "规格项不存在");
|
||||||
|
GaoProduct product = productService.get(productId);
|
||||||
|
TimiException.required(product, "not found product");
|
||||||
|
storeScopeService.checkStoreId(product.getStoreId());
|
||||||
|
specService.createValue(value);
|
||||||
|
return value.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_READ)
|
||||||
|
@PostMapping("/sellable/list")
|
||||||
|
public List<GaoProduct> sellableList(@RequestBody GaoProductPage page) {
|
||||||
|
TimiException.required(page, "not found product page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
return productService.listSellable(page);
|
||||||
|
}
|
||||||
|
}
|
||||||
+106
@@ -0,0 +1,106 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoProductSkuChartService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductChartReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductSkuFulfillmentDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductSkuFulfillmentRankView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductSkuSalesDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductSkuSalesRankView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductSkuStockHealthView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductSkuStockMovementDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductSkuUnitSalesRankView;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// GAO SKU 图表接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-07
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/product/sku/chart")
|
||||||
|
public class GaoProductSkuChartController {
|
||||||
|
|
||||||
|
private final GaoProductSkuChartService service;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
|
||||||
|
/// 查询 SKU 每日销售统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/sales/daily")
|
||||||
|
public List<GaoProductSkuSalesDailyStatView> salesDaily(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.salesDaily(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询 SKU 销售排行
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/sales/rank")
|
||||||
|
public List<GaoProductSkuSalesRankView> salesRank(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.salesRank(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询 SKU 单位销售排行
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/sales/unit/rank")
|
||||||
|
public List<GaoProductSkuUnitSalesRankView> unitSalesRank(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.unitSalesRank(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询 SKU 每日履约统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/fulfillment/daily")
|
||||||
|
public List<GaoProductSkuFulfillmentDailyStatView> fulfillmentDaily(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.fulfillmentDaily(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询 SKU 履约进度排行
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/fulfillment/rank")
|
||||||
|
public List<GaoProductSkuFulfillmentRankView> fulfillmentRank(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.fulfillmentRank(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询 SKU 每日库存变动统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/stock/movement/daily")
|
||||||
|
public List<GaoProductSkuStockMovementDailyStatView> stockMovementDaily(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.stockMovementDaily(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询 SKU 库存健康度
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/stock/health")
|
||||||
|
public List<GaoProductSkuStockHealthView> stockHealth(@RequestBody GaoProductChartReq req) {
|
||||||
|
return service.stockHealth(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
private GaoProductChartReq normalize(GaoProductChartReq req) {
|
||||||
|
TimiException.required(req, "SKU 图表请求不能为空");
|
||||||
|
req.setStoreId(storeScopeService.resolveStoreId(req.getStoreId()));
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoProductStock;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoProductStockRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoProductStockService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoProductStockRecordService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductStockChangeRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductStockManualRevokeRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductStockPage;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductStockProductView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoProductStockRecordPage;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/// GAO 产品库存接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-02
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/product/stock")
|
||||||
|
public class GaoProductStockController {
|
||||||
|
|
||||||
|
private final GaoProductStockService stockService;
|
||||||
|
private final GaoProductStockRecordService recordService;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_STOCK_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
public PageResult<GaoProductStock> list(@RequestBody GaoProductStockPage page) {
|
||||||
|
TimiException.required(page, "not found stock page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
return stockService.pageByQuery(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_STOCK_READ)
|
||||||
|
@PostMapping("/product-list")
|
||||||
|
public PageResult<GaoProductStockProductView> productList(@RequestBody GaoProductStockPage page) {
|
||||||
|
TimiException.required(page, "not found stock product page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
return stockService.pageProductByQuery(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_STOCK_READ)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
public GaoProductStock detail(@RequestParam(required = false) String storeId, @RequestParam String skuId) {
|
||||||
|
return stockService.detail(storeScopeService.resolveStoreId(storeId), skuId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_STOCK_CREATE)
|
||||||
|
@PostMapping("/initial-in")
|
||||||
|
public GaoProductStock initialIn(@RequestBody GaoProductStockChangeRequest request) {
|
||||||
|
return stockService.initialIn(normalize(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_STOCK_CREATE)
|
||||||
|
@PostMapping("/manual-in")
|
||||||
|
public GaoProductStock manualIn(@RequestBody GaoProductStockChangeRequest request) {
|
||||||
|
return stockService.manualIn(normalize(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_STOCK_CREATE)
|
||||||
|
@PostMapping("/manual-out")
|
||||||
|
public GaoProductStock manualOut(@RequestBody GaoProductStockChangeRequest request) {
|
||||||
|
return stockService.manualOut(normalize(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_STOCK_MANUAL_REVOKE)
|
||||||
|
@PostMapping("/manual-revoke")
|
||||||
|
public GaoProductStock manualRevoke(@RequestBody GaoProductStockManualRevokeRequest request) {
|
||||||
|
return stockService.manualRevoke(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_STOCK_CREATE)
|
||||||
|
@PostMapping("/stocktake-gain")
|
||||||
|
public GaoProductStock stocktakeGain(@RequestBody GaoProductStockChangeRequest request) {
|
||||||
|
return stockService.stocktakeGain(normalize(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_STOCK_CREATE)
|
||||||
|
@PostMapping("/stocktake-loss")
|
||||||
|
public GaoProductStock stocktakeLoss(@RequestBody GaoProductStockChangeRequest request) {
|
||||||
|
return stockService.stocktakeLoss(normalize(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_STOCK_READ)
|
||||||
|
@PostMapping("/record/list")
|
||||||
|
public PageResult<GaoProductStockRecord> recordList(@RequestBody GaoProductStockRecordPage page) {
|
||||||
|
TimiException.required(page, "not found stock record page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
return recordService.pageByQuery(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.PRODUCT_STOCK_READ)
|
||||||
|
@PostMapping("/record/detail")
|
||||||
|
public GaoProductStockRecord recordDetail(@RequestParam String id) {
|
||||||
|
GaoProductStockRecord result = recordService.detail(id);
|
||||||
|
storeScopeService.checkStoreId(result.getStoreId());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private GaoProductStockChangeRequest normalize(GaoProductStockChangeRequest request) {
|
||||||
|
TimiException.required(request, "not found stock change request");
|
||||||
|
request.setStoreId(storeScopeService.resolveStoreId(request.getStoreId()));
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
}
|
||||||
+156
@@ -0,0 +1,156 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoSalesOrderChartService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerOrderProductRankView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerOrderRankView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerOrderSkuRankView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerRepeatDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerRepeatIntervalStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoSalesOrderChartReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoSalesOrderCalendarStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoSalesOrderConsumptionDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoSalesOrderDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoSalesOrderPaymentStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoSalesOrderReceivableStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoSalesOrderStatusStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoSalesOrderTypeStatView;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/// GAO 销售订单图表接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-06
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/sales/order/chart")
|
||||||
|
public class GaoSalesOrderChartController {
|
||||||
|
|
||||||
|
private final GaoSalesOrderChartService service;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
|
||||||
|
/// 查询销售订单每日统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/daily")
|
||||||
|
public List<GaoSalesOrderDailyStatView> daily(@RequestBody GaoSalesOrderChartReq req) {
|
||||||
|
return service.daily(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询销售订单类型统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/type")
|
||||||
|
public List<GaoSalesOrderTypeStatView> type(@RequestBody GaoSalesOrderChartReq req) {
|
||||||
|
return service.type(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询销售订单付款状态统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/payment")
|
||||||
|
public List<GaoSalesOrderPaymentStatView> payment(@RequestBody GaoSalesOrderChartReq req) {
|
||||||
|
return service.payment(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询客户订单排行
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/customer/rank")
|
||||||
|
public List<GaoCustomerOrderRankView> customerRank(@RequestBody GaoSalesOrderChartReq req) {
|
||||||
|
return service.customerRank(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询指定客户订单产品排行
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/customer/product/rank")
|
||||||
|
public List<GaoCustomerOrderProductRankView> customerProductRank(@RequestBody GaoSalesOrderChartReq req) {
|
||||||
|
return service.customerProductRank(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询指定客户订单 SKU 排行
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/customer/sku/rank")
|
||||||
|
public List<GaoCustomerOrderSkuRankView> customerSkuRank(@RequestBody GaoSalesOrderChartReq req) {
|
||||||
|
return service.customerSkuRank(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询销售订单状态统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/status")
|
||||||
|
public List<GaoSalesOrderStatusStatView> status(@RequestBody GaoSalesOrderChartReq req) {
|
||||||
|
return service.status(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询销售订单应收统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/receivable")
|
||||||
|
public GaoSalesOrderReceivableStatView receivable(@RequestBody GaoSalesOrderChartReq req) {
|
||||||
|
return service.receivable(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询客户每日有效消费统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/customer/consumption/daily")
|
||||||
|
public List<GaoSalesOrderConsumptionDailyStatView> consumptionDaily(@RequestBody GaoSalesOrderChartReq req) {
|
||||||
|
return service.consumptionDaily(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询客户订单日历统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/customer/calendar")
|
||||||
|
public List<GaoSalesOrderCalendarStatView> calendar(@RequestBody GaoSalesOrderChartReq req) {
|
||||||
|
return service.calendar(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询客户每日复购统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/customer/repeat/daily")
|
||||||
|
public List<GaoCustomerRepeatDailyStatView> repeatDaily(@RequestBody GaoSalesOrderChartReq req) {
|
||||||
|
return service.repeatDaily(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询客户复购间隔统计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/customer/repeat/interval")
|
||||||
|
public List<GaoCustomerRepeatIntervalStatView> repeatInterval(@RequestBody GaoSalesOrderChartReq req) {
|
||||||
|
return service.repeatInterval(normalize(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
private GaoSalesOrderChartReq normalize(GaoSalesOrderChartReq req) {
|
||||||
|
TimiException.required(req, "not found sales order chart req");
|
||||||
|
req.setStoreId(storeScopeService.resolveStoreId(req.getStoreId()));
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.bean.PermissionMatchMode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoFundRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoSalesOrder;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoOrderPaymentService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoSalesOrderService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoDirectProductOrderCreateRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoOrderPaymentActionRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoOrderPaymentNoRefundRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoOrderPaymentReceiveRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoOrderPaymentRefundRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoOrderPaymentRevokeRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoSalesOrderCancelRequest;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoSalesOrderPage;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoSalesOrderUpdateRequest;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/// GAO 销售订单和资金接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-09-02
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/sales/order")
|
||||||
|
public class GaoSalesOrderController {
|
||||||
|
|
||||||
|
private final GaoSalesOrderService service;
|
||||||
|
private final GaoOrderPaymentService paymentService;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.SALES_ORDER_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
public PageResult<GaoSalesOrder> list(@RequestBody GaoSalesOrderPage page) {
|
||||||
|
TimiException.required(page, "not found sales order page");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
return service.pageByQuery(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.SALES_ORDER_READ)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
public GaoSalesOrder detail(@RequestParam String id) {
|
||||||
|
return service.detail(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.SALES_ORDER_CREATE)
|
||||||
|
@PostMapping("/direct-product/create")
|
||||||
|
public GaoSalesOrder createDirectProduct(@RequestBody GaoDirectProductOrderCreateRequest request) {
|
||||||
|
TimiException.required(request, "not found direct product order request");
|
||||||
|
request.setStoreId(storeScopeService.resolveStoreId(request.getStoreId()));
|
||||||
|
return service.createDirectProductOrder(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.SALES_ORDER_UPDATE)
|
||||||
|
@PostMapping("/update")
|
||||||
|
public GaoSalesOrder update(@RequestBody GaoSalesOrderUpdateRequest request) {
|
||||||
|
TimiException.required(request, "not found sales order update request");
|
||||||
|
TimiException.required(request.getId(), "not found sales order.id");
|
||||||
|
return service.updateRemarkAndAttachments(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.SALES_ORDER_CANCEL)
|
||||||
|
@PostMapping("/cancel")
|
||||||
|
public GaoSalesOrder cancel(@RequestBody GaoSalesOrderCancelRequest request) {
|
||||||
|
return service.cancel(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.FUND_RECEIVE_CREATE)
|
||||||
|
@PostMapping("/payment/receive")
|
||||||
|
public GaoFundRecord receive(@RequestBody GaoOrderPaymentReceiveRequest request) {
|
||||||
|
return paymentService.receive(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.FUND_RECEIVE_VERIFY)
|
||||||
|
@PostMapping("/payment/verify")
|
||||||
|
public GaoFundRecord verify(@RequestParam String id) {
|
||||||
|
return paymentService.verify(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.FUND_RECEIVE_VERIFY)
|
||||||
|
@PostMapping("/payment/reject")
|
||||||
|
public GaoFundRecord reject(@RequestBody GaoOrderPaymentActionRequest request) {
|
||||||
|
return paymentService.reject(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(value = {GaoPermissionCode.FUND_RECEIVE_CREATE, GaoPermissionCode.FUND_RECORD_READ}, mode = PermissionMatchMode.ANY)
|
||||||
|
@PostMapping("/payment/cancel")
|
||||||
|
public GaoFundRecord cancelPayment(@RequestBody GaoOrderPaymentActionRequest request) {
|
||||||
|
return paymentService.cancel(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.FUND_REFUND)
|
||||||
|
@PostMapping("/refund")
|
||||||
|
public GaoFundRecord refund(@RequestBody GaoOrderPaymentRefundRequest request) {
|
||||||
|
return paymentService.refund(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.FUND_REFUND)
|
||||||
|
@PostMapping("/refund/confirm-none")
|
||||||
|
public GaoFundRecord confirmNoRefund(@RequestBody GaoOrderPaymentNoRefundRequest request) {
|
||||||
|
return paymentService.confirmNoRefund(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.FUND_REVOKE)
|
||||||
|
@PostMapping("/fund/revoke")
|
||||||
|
public GaoFundRecord revoke(@RequestBody GaoOrderPaymentRevokeRequest request) {
|
||||||
|
return paymentService.revoke(request);
|
||||||
|
}
|
||||||
|
}
|
||||||
+23
-2
@@ -4,6 +4,9 @@ import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
|||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoStoreBusinessDay;
|
import com.imyeyu.api.modules.gao.entity.GaoStoreBusinessDay;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreBusinessDayService;
|
import com.imyeyu.api.modules.gao.service.GaoStoreBusinessDayService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
import com.imyeyu.spring.bean.Page;
|
import com.imyeyu.spring.bean.Page;
|
||||||
@@ -27,12 +30,17 @@ import java.util.List;
|
|||||||
public class GaoStoreBusinessDayController {
|
public class GaoStoreBusinessDayController {
|
||||||
|
|
||||||
private final GaoStoreBusinessDayService service;
|
private final GaoStoreBusinessDayService service;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
public PageResult<GaoStoreBusinessDay> list(@RequestBody Page<GaoStoreBusinessDay> page) {
|
public PageResult<GaoStoreBusinessDay> list(@RequestBody Page<GaoStoreBusinessDay> page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
GaoStoreBusinessDay example = TimiJava.defaultIfNull(page.getEqualsExample(), new GaoStoreBusinessDay());
|
||||||
|
example.setStoreId(storeScopeService.resolveStoreId(example.getStoreId()));
|
||||||
|
page.setEqualsExample(example);
|
||||||
return service.page(page);
|
return service.page(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +49,7 @@ public class GaoStoreBusinessDayController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
||||||
@PostMapping("/calendar")
|
@PostMapping("/calendar")
|
||||||
public List<GaoStoreBusinessDay> calendar(@RequestParam String storeId, @RequestParam Integer beginDateValue, @RequestParam Integer endDateValue) {
|
public List<GaoStoreBusinessDay> calendar(@RequestParam String storeId, @RequestParam Integer beginDateValue, @RequestParam Integer endDateValue) {
|
||||||
return service.listByDateRange(storeId, beginDateValue, endDateValue);
|
return service.listByDateRange(storeScopeService.resolveStoreId(storeId), beginDateValue, endDateValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -49,7 +57,10 @@ public class GaoStoreBusinessDayController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
||||||
@PostMapping("/detail")
|
@PostMapping("/detail")
|
||||||
public GaoStoreBusinessDay detail(@RequestParam String id) {
|
public GaoStoreBusinessDay detail(@RequestParam String id) {
|
||||||
return service.get(id);
|
GaoStoreBusinessDay businessDay = service.get(id);
|
||||||
|
TimiException.required(businessDay, "not found businessDay");
|
||||||
|
storeScopeService.checkStoreId(businessDay.getStoreId());
|
||||||
|
return businessDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -57,6 +68,7 @@ public class GaoStoreBusinessDayController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public String create(@RequestBody GaoStoreBusinessDay businessDay) {
|
public String create(@RequestBody GaoStoreBusinessDay businessDay) {
|
||||||
|
businessDay.setStoreId(storeScopeService.resolveStoreId(businessDay.getStoreId()));
|
||||||
service.create(businessDay);
|
service.create(businessDay);
|
||||||
return businessDay.getId();
|
return businessDay.getId();
|
||||||
}
|
}
|
||||||
@@ -66,6 +78,12 @@ public class GaoStoreBusinessDayController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
public void update(@RequestBody GaoStoreBusinessDay businessDay) {
|
public void update(@RequestBody GaoStoreBusinessDay businessDay) {
|
||||||
|
TimiException.required(businessDay, "not found businessDay");
|
||||||
|
TimiException.required(businessDay.getId(), "not found businessDay.id");
|
||||||
|
GaoStoreBusinessDay dbBusinessDay = service.get(businessDay.getId());
|
||||||
|
TimiException.required(dbBusinessDay, "not found businessDay");
|
||||||
|
storeScopeService.checkStoreId(dbBusinessDay.getStoreId());
|
||||||
|
businessDay.setStoreId(dbBusinessDay.getStoreId());
|
||||||
service.update(businessDay);
|
service.update(businessDay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +92,9 @@ public class GaoStoreBusinessDayController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.STORE_DELETE)
|
@RequireGaoPermission(GaoPermissionCode.STORE_DELETE)
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
public void delete(@RequestParam String id) {
|
public void delete(@RequestParam String id) {
|
||||||
|
GaoStoreBusinessDay businessDay = service.get(id);
|
||||||
|
TimiException.required(businessDay, "not found businessDay");
|
||||||
|
storeScopeService.checkStoreId(businessDay.getStoreId());
|
||||||
service.delete(id);
|
service.delete(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,14 @@ package com.imyeyu.api.modules.gao.controller;
|
|||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreChartService;
|
import com.imyeyu.api.modules.gao.service.GaoStoreChartService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoEventRecordCalendarView;
|
import com.imyeyu.api.modules.gao.vo.GaoEventRecordCalendarView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoEventRecordDailyStatView;
|
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.api.modules.gao.vo.GaoStoreChartReq;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -29,6 +32,7 @@ import java.util.List;
|
|||||||
public class GaoStoreChartController {
|
public class GaoStoreChartController {
|
||||||
|
|
||||||
private final GaoStoreChartService service;
|
private final GaoStoreChartService service;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
|
||||||
/// 查询客户增长趋势
|
/// 查询客户增长趋势
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -36,6 +40,8 @@ public class GaoStoreChartController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
@PostMapping("/customer/daily")
|
@PostMapping("/customer/daily")
|
||||||
public List<GaoCustomerDailyStateView> customerDaily(@RequestBody GaoStoreChartReq req) {
|
public List<GaoCustomerDailyStateView> customerDaily(@RequestBody GaoStoreChartReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
req.setStoreId(storeScopeService.resolveStoreId(req.getStoreId()));
|
||||||
return service.customerDailyTrend(req);
|
return service.customerDailyTrend(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +51,7 @@ public class GaoStoreChartController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
@PostMapping("/customer/gender")
|
@PostMapping("/customer/gender")
|
||||||
public List<GaoCustomerGenderStatView> customerGender(@RequestParam String storeId) {
|
public List<GaoCustomerGenderStatView> customerGender(@RequestParam String storeId) {
|
||||||
return service.customerGender(storeId);
|
return service.customerGender(storeScopeService.resolveStoreId(storeId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 查询登记事件每日统计,可同时支撑登记趋势和事件结构图表
|
/// 查询登记事件每日统计,可同时支撑登记趋势和事件结构图表
|
||||||
@@ -54,15 +60,30 @@ public class GaoStoreChartController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
@PostMapping("/event/record/daily")
|
@PostMapping("/event/record/daily")
|
||||||
public List<GaoEventRecordDailyStatView> eventRecordDaily(@RequestBody GaoStoreChartReq req) {
|
public List<GaoEventRecordDailyStatView> eventRecordDaily(@RequestBody GaoStoreChartReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
req.setStoreId(storeScopeService.resolveStoreId(req.getStoreId()));
|
||||||
return service.eventRecordDailyStat(req);
|
return service.eventRecordDailyStat(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 查询登记事件每日数值合计
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/event/record/number-value/daily")
|
||||||
|
public List<GaoEventRecordNumberValueDailyStatView> eventRecordNumberValueDaily(@RequestBody GaoStoreChartReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
req.setStoreId(storeScopeService.resolveStoreId(req.getStoreId()));
|
||||||
|
return service.eventRecordNumberValueDailyStat(req);
|
||||||
|
}
|
||||||
|
|
||||||
/// 查询登记事件日历记录
|
/// 查询登记事件日历记录
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
@PostMapping("/event/record/calendar")
|
@PostMapping("/event/record/calendar")
|
||||||
public List<GaoEventRecordCalendarView> eventRecordCalendar(@RequestBody GaoStoreChartReq req) {
|
public List<GaoEventRecordCalendarView> eventRecordCalendar(@RequestBody GaoStoreChartReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
req.setStoreId(storeScopeService.resolveStoreId(req.getStoreId()));
|
||||||
return service.eventRecordCalendar(req);
|
return service.eventRecordCalendar(req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoStore;
|
import com.imyeyu.api.modules.gao.entity.GaoStore;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||||
import com.imyeyu.api.modules.user.service.PermissionChecker;
|
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
import com.imyeyu.network.Network;
|
import com.imyeyu.network.Network;
|
||||||
import com.imyeyu.spring.TimiSpring;
|
import com.imyeyu.spring.TimiSpring;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
@@ -37,14 +38,20 @@ import java.util.List;
|
|||||||
public class GaoStoreController {
|
public class GaoStoreController {
|
||||||
|
|
||||||
private final GaoStoreService service;
|
private final GaoStoreService service;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
private final UserLoginService userLoginService;
|
private final UserLoginService userLoginService;
|
||||||
private final PermissionChecker permissionChecker;
|
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
public PageResult<GaoStore> list(@RequestBody Page<GaoStore> page) {
|
public PageResult<GaoStore> list(@RequestBody Page<GaoStore> page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
if (!storeScopeService.hasGlobalScope()) {
|
||||||
|
GaoStore example = TimiJava.defaultIfNull(page.getEqualsExample(), new GaoStore());
|
||||||
|
example.setId(storeScopeService.resolveStoreId(example.getId()));
|
||||||
|
page.setEqualsExample(example);
|
||||||
|
}
|
||||||
return service.page(page);
|
return service.page(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +60,9 @@ public class GaoStoreController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
||||||
@PostMapping("/detail")
|
@PostMapping("/detail")
|
||||||
public GaoStore detail(@RequestParam String id) {
|
public GaoStore detail(@RequestParam String id) {
|
||||||
return service.get(id);
|
GaoStore store = service.get(id);
|
||||||
|
storeScopeService.checkStore(store);
|
||||||
|
return store;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -70,12 +79,13 @@ public class GaoStoreController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
public void update(@RequestBody GaoStore store) {
|
public void update(@RequestBody GaoStore store) {
|
||||||
if (permissionChecker.hasAny(ModuleCode.GAO, GaoPermissionCode.STORE_CREATE.getValue())) {
|
if (storeScopeService.hasGlobalScope()) {
|
||||||
// 门店管理
|
// 门店管理
|
||||||
service.update(store);
|
service.update(store);
|
||||||
} else {
|
} else {
|
||||||
// 店长
|
// 店长
|
||||||
GaoStore dbStore = service.get(store.getId());
|
GaoStore dbStore = service.get(store.getId());
|
||||||
|
storeScopeService.checkStore(dbStore);
|
||||||
dbStore.setName(store.getName());
|
dbStore.setName(store.getName());
|
||||||
dbStore.setTelephone(store.getTelephone());
|
dbStore.setTelephone(store.getTelephone());
|
||||||
dbStore.setAddress(store.getAddress());
|
dbStore.setAddress(store.getAddress());
|
||||||
@@ -98,6 +108,11 @@ public class GaoStoreController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
||||||
@PostMapping("/sort")
|
@PostMapping("/sort")
|
||||||
public void sort(@RequestBody List<String> idList) {
|
public void sort(@RequestBody List<String> idList) {
|
||||||
|
if (!storeScopeService.hasGlobalScope()) {
|
||||||
|
for (String id : TimiJava.safeIterable(idList)) {
|
||||||
|
storeScopeService.checkStore(service.get(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
service.sort(idList);
|
service.sort(idList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +122,12 @@ public class GaoStoreController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.STORE_EXPORT)
|
@RequireGaoPermission(GaoPermissionCode.STORE_EXPORT)
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
public void export(@RequestBody Page<GaoStore> page) throws IOException {
|
public void export(@RequestBody Page<GaoStore> page) throws IOException {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
if (!storeScopeService.hasGlobalScope()) {
|
||||||
|
GaoStore example = TimiJava.defaultIfNull(page.getEqualsExample(), new GaoStore());
|
||||||
|
example.setId(storeScopeService.resolveStoreId(example.getId()));
|
||||||
|
page.setEqualsExample(example);
|
||||||
|
}
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
HttpServletResponse resp = TimiSpring.getResponse();
|
||||||
String contentDisposition = Network.getFileDownloadHeader("门店列表-%s.xlsx".formatted(Time.serialize.format(Time.now())));
|
String contentDisposition = Network.getFileDownloadHeader("门店列表-%s.xlsx".formatted(Time.serialize.format(Time.now())));
|
||||||
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Article;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreDiaryService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoStoreDiaryPage;
|
||||||
|
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.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/// GAO 门店日记接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-31
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/store/diary")
|
||||||
|
public class GaoStoreDiaryController {
|
||||||
|
|
||||||
|
private final GaoStoreDiaryService service;
|
||||||
|
private final GaoStoreScopeService storeScopeService;
|
||||||
|
private final UserLoginService userLoginService;
|
||||||
|
private final UserService userService;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
|
||||||
|
/// 分页查询门店日记
|
||||||
|
///
|
||||||
|
/// @param page 分页查询条件
|
||||||
|
/// @return 门店日记分页结果
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_DIARY_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public PageResult<Article> list(@RequestBody GaoStoreDiaryPage page) {
|
||||||
|
TimiException.required(page, "未找到分页参数");
|
||||||
|
TimiException.required(page.getBeginCreatedAt(), "未找到门店日记开始时间");
|
||||||
|
TimiException.required(page.getEndCreatedAt(), "未找到门店日记结束时间");
|
||||||
|
TimiException.requiredTrue(page.getBeginCreatedAt() < page.getEndCreatedAt(), "门店日记时间范围无效");
|
||||||
|
page.setStoreId(storeScopeService.resolveStoreId(page.getStoreId()));
|
||||||
|
PageResult<Article> result = service.page(page);
|
||||||
|
{
|
||||||
|
List<String> articleIdList = result.getList().stream().map(Article::getId).toList();
|
||||||
|
Map<String, Attachment> attachMap = attachmentService.mapFirstImageByIdList(Attachment.BizType.ARTICLE, articleIdList);
|
||||||
|
for (Article article : result.getList()) {
|
||||||
|
Attachment attachment = attachMap.get(article.getId());
|
||||||
|
article.setAttachmentList(TimiJava.ofList(attachment));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询门店日记详情
|
||||||
|
///
|
||||||
|
/// @param id 日记 ID
|
||||||
|
/// @return 门店日记
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_DIARY_READ)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public Article detail(@RequestParam String id) {
|
||||||
|
Article article = service.get(id);
|
||||||
|
storeScopeService.checkStoreId(article.getBizId());
|
||||||
|
article.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.ARTICLE, article.getId()));
|
||||||
|
if (TimiJava.isNotEmpty(article.getUpdatedBy())) {
|
||||||
|
User updater = userService.get(article.getUpdatedBy());
|
||||||
|
if (updater != null) {
|
||||||
|
updater.setAttachmentList(attachmentService.listByBizId(
|
||||||
|
Attachment.BizType.USER,
|
||||||
|
updater.getId(),
|
||||||
|
User.AttachType.AVATAR.toString()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
article.setUpdater(updater);
|
||||||
|
}
|
||||||
|
return article;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 创建门店日记
|
||||||
|
///
|
||||||
|
/// @param article 门店日记
|
||||||
|
/// @return 日记 ID
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_DIARY_CREATE)
|
||||||
|
@PostMapping("/create")
|
||||||
|
public String create(@RequestBody Article article) {
|
||||||
|
article.setBizId(storeScopeService.resolveStoreId(article.getBizId()));
|
||||||
|
service.create(article, userLoginService.getRequireLoginUserId());
|
||||||
|
return article.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 修改门店日记
|
||||||
|
///
|
||||||
|
/// @param article 门店日记
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_DIARY_UPDATE)
|
||||||
|
@PostMapping("/update")
|
||||||
|
public void update(@RequestBody Article article) {
|
||||||
|
TimiException.required(article, "未找到门店日记");
|
||||||
|
TimiException.required(article.getId(), "未找到门店日记 ID");
|
||||||
|
Article dbArticle = service.get(article.getId());
|
||||||
|
storeScopeService.checkStoreId(dbArticle.getBizId());
|
||||||
|
service.update(article, userLoginService.getRequireLoginUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 删除门店日记
|
||||||
|
///
|
||||||
|
/// @param id 日记 ID
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STORE_DIARY_DELETE)
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public void delete(@RequestParam String id) {
|
||||||
|
Article article = service.get(id);
|
||||||
|
storeScopeService.checkStoreId(article.getBizId());
|
||||||
|
service.delete(article.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user