|
|
@@ -1,3 +1,4 @@
|
|
|
+/*
|
|
|
package shop.alien.store.aspect;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
@@ -13,13 +14,17 @@ import shop.alien.entity.store.StorePrice;
|
|
|
import shop.alien.entity.store.dto.CuisineComboDto;
|
|
|
import shop.alien.store.util.ai.AiContentModerationUtil;
|
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.StringJoiner;
|
|
|
|
|
|
+*/
|
|
|
/**
|
|
|
* AI 审核切面:拦截美食与通用价目新增/修改接口
|
|
|
- */
|
|
|
+ *//*
|
|
|
+
|
|
|
@Slf4j
|
|
|
@Aspect
|
|
|
@Component
|
|
|
@@ -29,9 +34,11 @@ public class AiAuditAspect {
|
|
|
|
|
|
private final AiContentModerationUtil aiContentModerationUtil;
|
|
|
|
|
|
- /**
|
|
|
+ */
|
|
|
+/**
|
|
|
* 仅拦截美食新增/修改与通用价目新增/修改接口
|
|
|
- */
|
|
|
+ *//*
|
|
|
+
|
|
|
@Pointcut(
|
|
|
"execution(* shop.alien.store.controller.StoreCuisineController.addCuisineCombo(..))"
|
|
|
+ " || execution(* shop.alien.store.controller.StoreCuisineController.updateCuisineCombo(..))"
|
|
|
@@ -41,14 +48,16 @@ public class AiAuditAspect {
|
|
|
// pointcut definition
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ */
|
|
|
+/**
|
|
|
* 环绕通知:组合请求参数,获取AI token,并设置审核状态
|
|
|
- */
|
|
|
+ *//*
|
|
|
+
|
|
|
@Around("aiAuditPointcut()")
|
|
|
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
Object[] args = joinPoint.getArgs();
|
|
|
|
|
|
- String payload = JSON.toJSONString(args);
|
|
|
+ String payload = extractFieldValues(args);
|
|
|
log.info("AI审核切面拦截方法: {}, payload={}", joinPoint.getSignature().toShortString(), payload);
|
|
|
|
|
|
List<String> imageUrls = extractImageUrls(args);
|
|
|
@@ -62,9 +71,11 @@ public class AiAuditAspect {
|
|
|
return joinPoint.proceed(args);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ */
|
|
|
+/**
|
|
|
* AI审核调用:使用文本审核(图片列表暂为空)
|
|
|
- */
|
|
|
+ *//*
|
|
|
+
|
|
|
private boolean performAiAudit(String payload, List<String> imageUrls, Object[] args) {
|
|
|
try {
|
|
|
// token 目前仅预留,如后续需要可添加到header或payload
|
|
|
@@ -88,9 +99,11 @@ public class AiAuditAspect {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ */
|
|
|
+/**
|
|
|
将审核结果写入入参的status字段(通过=1,不通过=2)
|
|
|
- */
|
|
|
+ *//*
|
|
|
+
|
|
|
private void applyStatus(Object[] args, boolean passed) {
|
|
|
int status = passed ? 1 : 2;
|
|
|
for (Object arg : args) {
|
|
|
@@ -105,9 +118,11 @@ public class AiAuditAspect {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ */
|
|
|
+/**
|
|
|
* 将审核失败原因写入入参
|
|
|
- */
|
|
|
+ *//*
|
|
|
+
|
|
|
private void applyFailureReason(Object[] args, String reason) {
|
|
|
String safeReason = reason != null ? reason : "审核未通过";
|
|
|
for (Object arg : args) {
|
|
|
@@ -122,9 +137,40 @@ public class AiAuditAspect {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ */
|
|
|
+/**
|
|
|
+ * 通过反射提取所有参数对象的字段值,用空格拼接成纯文本
|
|
|
+ *//*
|
|
|
+
|
|
|
+ private String extractFieldValues(Object[] args) {
|
|
|
+ StringJoiner joiner = new StringJoiner(" ");
|
|
|
+ for (Object arg : args) {
|
|
|
+ if (arg == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (Field field : arg.getClass().getDeclaredFields()) {
|
|
|
+ field.setAccessible(true);
|
|
|
+ try {
|
|
|
+ Object value = field.get(arg);
|
|
|
+ if (value != null) {
|
|
|
+ String str = String.valueOf(value);
|
|
|
+ if (!str.isEmpty()) {
|
|
|
+ joiner.add(str);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ // skip
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return joiner.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ */
|
|
|
+/**
|
|
|
* 从入参中提取图片URL列表;images字段为JSON字符串数组
|
|
|
- */
|
|
|
+ *//*
|
|
|
+
|
|
|
private List<String> extractImageUrls(Object[] args) {
|
|
|
for (Object arg : args) {
|
|
|
if (arg instanceof CuisineComboDto) {
|
|
|
@@ -153,3 +199,4 @@ public class AiAuditAspect {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+*/
|