|
|
@@ -115,6 +115,16 @@ public class OperationalActivityServiceImpl implements OperationalActivityServic
|
|
|
String authorization = "Bearer " + accessToken;
|
|
|
|
|
|
JsonNode auditParam = dto.getAuditParam();
|
|
|
+ // 如果 auditParam 是字符串,先解析为 JsonNode
|
|
|
+ if (auditParam != null && auditParam.isTextual()) {
|
|
|
+ try {
|
|
|
+ auditParam = objectMapper.readTree(auditParam.asText());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("解析 auditParam JSON 字符串失败: {}", auditParam.asText(), e);
|
|
|
+ auditParam = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
String auditText = (auditParam != null && auditParam.has("text")) ? auditParam.get("text").asText() : "";
|
|
|
JsonNode imagesNode = (auditParam != null) ? auditParam.get("image_urls") : null;
|
|
|
|
|
|
@@ -127,15 +137,35 @@ public class OperationalActivityServiceImpl implements OperationalActivityServic
|
|
|
// 调用同步审核工具类
|
|
|
AiContentModerationUtil.AuditResult auditResult = aiContentModerationUtil.auditContent(auditText, imageUrls);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ // 审核通过,根据活动时间自动设置状态
|
|
|
+ Date currentTime = new Date();
|
|
|
+ Date startTime = activity.getStartTime();
|
|
|
+ Date endTime = activity.getEndTime();
|
|
|
+
|
|
|
+ int status;
|
|
|
+ if (currentTime.before(startTime)) {
|
|
|
+ // 当前时间在活动开始时间之前,设置为未开始
|
|
|
+ status = 2;
|
|
|
+ } else if (currentTime.compareTo(startTime) >= 0 && currentTime.compareTo(endTime) <= 0) {
|
|
|
+ // 当前时间在活动时间之间,设置为进行中
|
|
|
+ status = 5;
|
|
|
+ } else {
|
|
|
+ // 当前时间在活动结束时间之后,设置为已结束
|
|
|
+ status = 7;
|
|
|
+ }
|
|
|
+ activity.setStatus(status);
|
|
|
+
|
|
|
// 如果审核不通过,记录原因并提前结束
|
|
|
if (!auditResult.isPassed()) {
|
|
|
log.warn("AI内容审核未通过: {}", auditResult.getFailureReason());
|
|
|
failureReasonHolder.set(auditResult.getFailureReason());
|
|
|
- return 2; // 返回2表示审核失败
|
|
|
+ activity.setApprovalComments(auditResult.getFailureReason());
|
|
|
+ activity.setStatus(3);
|
|
|
+// return 2; // 返回2表示审核失败
|
|
|
}
|
|
|
-
|
|
|
- // 审核通过,执行入库操作(状态设为8:待生成海报)
|
|
|
- activity.setStatus(8);
|
|
|
+
|
|
|
result = activityMapper.insert(activity);
|
|
|
// 使用用户描述和页面输入框其他信息,让AI生成海报图片。
|
|
|
if (dto.getUploadImgType() == 2) {
|
|
|
@@ -231,7 +261,112 @@ public class OperationalActivityServiceImpl implements OperationalActivityServic
|
|
|
|
|
|
StoreOperationalActivity activity = new StoreOperationalActivity();
|
|
|
BeanUtils.copyProperties(dto, activity);
|
|
|
- Integer result = activityMapper.updateById(activity);
|
|
|
+ Integer result =0;
|
|
|
+ try {
|
|
|
+ String accessToken = getToken();
|
|
|
+ if (accessToken == null || accessToken.isEmpty()) {
|
|
|
+ log.error("获取AI服务access_token失败,无法生成促销图片");
|
|
|
+ } else {
|
|
|
+ // AI登录成功
|
|
|
+ // 先调用AI进行运营名称和图片的审核,同步调用
|
|
|
+ String authorization = "Bearer " + accessToken;
|
|
|
+
|
|
|
+ JsonNode auditParam = dto.getAuditParam();
|
|
|
+ // 如果 auditParam 是字符串,先解析为 JsonNode
|
|
|
+ if (auditParam != null && auditParam.isTextual()) {
|
|
|
+ try {
|
|
|
+ auditParam = objectMapper.readTree(auditParam.asText());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("解析 auditParam JSON 字符串失败: {}", auditParam.asText(), e);
|
|
|
+ auditParam = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String auditText = (auditParam != null && auditParam.has("text")) ? auditParam.get("text").asText() : "";
|
|
|
+ JsonNode imagesNode = (auditParam != null) ? auditParam.get("image_urls") : null;
|
|
|
+
|
|
|
+ List<String> imageUrls = (imagesNode != null && imagesNode.isArray())
|
|
|
+ ? StreamSupport.stream(imagesNode.spliterator(), false)
|
|
|
+ .map(JsonNode::asText)
|
|
|
+ .collect(Collectors.toList())
|
|
|
+ : new ArrayList<>();
|
|
|
+
|
|
|
+ // 调用同步审核工具类
|
|
|
+ AiContentModerationUtil.AuditResult auditResult = aiContentModerationUtil.auditContent(auditText, imageUrls);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 审核通过,根据活动时间自动设置状态
|
|
|
+ Date currentTime = new Date();
|
|
|
+ Date startTime = activity.getStartTime();
|
|
|
+ Date endTime = activity.getEndTime();
|
|
|
+
|
|
|
+ int status;
|
|
|
+ if (currentTime.before(startTime)) {
|
|
|
+ // 当前时间在活动开始时间之前,设置为未开始
|
|
|
+ status = 2;
|
|
|
+ } else if (currentTime.compareTo(startTime) >= 0 && currentTime.compareTo(endTime) <= 0) {
|
|
|
+ // 当前时间在活动时间之间,设置为进行中
|
|
|
+ status = 5;
|
|
|
+ } else {
|
|
|
+ // 当前时间在活动结束时间之后,设置为已结束
|
|
|
+ status = 7;
|
|
|
+ }
|
|
|
+ activity.setStatus(status);
|
|
|
+
|
|
|
+ // 如果审核不通过,记录原因并提前结束
|
|
|
+ if (!auditResult.isPassed()) {
|
|
|
+ log.warn("AI内容审核未通过: {}", auditResult.getFailureReason());
|
|
|
+ failureReasonHolder.set(auditResult.getFailureReason());
|
|
|
+ activity.setApprovalComments(auditResult.getFailureReason());
|
|
|
+ activity.setStatus(3);
|
|
|
+// return 2; // 返回2表示审核失败
|
|
|
+ }
|
|
|
+
|
|
|
+ result = activityMapper.updateById(activity);
|
|
|
+ // 使用用户描述和页面输入框其他信息,让AI生成海报图片。
|
|
|
+ if (dto.getUploadImgType() == 2) {
|
|
|
+ // 格式化输入AI参数
|
|
|
+ ObjectNode requestBody = objectMapper.createObjectNode();
|
|
|
+ String filled = String.format(
|
|
|
+ tpl,
|
|
|
+ dto.getActivityName(),
|
|
|
+ dto.getStartTime(),
|
|
|
+ dto.getEndTime(),
|
|
|
+ dto.getParticipationLimit(),
|
|
|
+ dto.getActivityRule(),
|
|
|
+ dto.getCouponQuantity(),
|
|
|
+ dto.getImgDescribe()
|
|
|
+ );
|
|
|
+ requestBody.put("text", filled);
|
|
|
+ JsonNode imgResponse = alienAIFeign.generatePromotionImage(authorization, requestBody);
|
|
|
+ // 解析响应
|
|
|
+ if (imgResponse.has("data")) {
|
|
|
+ JsonNode data = imgResponse.get("data");
|
|
|
+ // 提取横向图(banner_image)的图片URL
|
|
|
+ if (data.has("banner_image")) {
|
|
|
+ JsonNode bannerImage = data.get("banner_image");
|
|
|
+ if (bannerImage.has("image_url") && !bannerImage.get("image_url").isNull()) {
|
|
|
+ String bannerImageUrl = bannerImage.get("image_url").asText();
|
|
|
+ dto.getActivityTitleImg().setImgUrl(bannerImageUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 提取竖向图(vertical_image)的图片URL
|
|
|
+ if (data.has("vertical_image")) {
|
|
|
+ JsonNode verticalImage = data.get("vertical_image");
|
|
|
+ if (verticalImage.has("image_url") && !verticalImage.get("image_url").isNull()) {
|
|
|
+ String verticalImageUrl = verticalImage.get("image_url").asText();
|
|
|
+ dto.getActivityDetailImg().setImgUrl(verticalImageUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // AI调用失败,也可以添加数据
|
|
|
+ log.error("调用AI服务生成促销图片失败", e);
|
|
|
+ }
|
|
|
+// result = activityMapper.updateById(activity);
|
|
|
|
|
|
// 添加
|
|
|
if (result > 0) {
|
|
|
@@ -342,7 +477,7 @@ public class OperationalActivityServiceImpl implements OperationalActivityServic
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public IPage<StoreOperationalActivityVO> queryActivityList(Integer storeId, Integer status, String activityName, Integer pageNum, Integer pageSize) {
|
|
|
+ public IPage<StoreOperationalActivityVO> queryActivityList(Integer storeId, Integer status,String activityType, String activityName, Integer pageNum, Integer pageSize) {
|
|
|
log.info("OperationalActivityServiceImpl.queryActivityList: storeId={}, status={}, activityName={}, pageNum={}, pageSize={}",
|
|
|
storeId, status, activityName, pageNum, pageSize);
|
|
|
|
|
|
@@ -350,6 +485,7 @@ public class OperationalActivityServiceImpl implements OperationalActivityServic
|
|
|
wrapper.eq(storeId != null, StoreOperationalActivity::getStoreId, storeId);
|
|
|
wrapper.like(activityName != null && activityName != "", StoreOperationalActivity::getActivityName, activityName);
|
|
|
wrapper.eq(status != null, StoreOperationalActivity::getStatus, status);
|
|
|
+ wrapper.eq(activityType != null, StoreOperationalActivity::getActivityType, activityType);
|
|
|
|
|
|
IPage<StoreOperationalActivity> list = activityMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
|
|
|
|
|
|
@@ -377,7 +513,13 @@ public class OperationalActivityServiceImpl implements OperationalActivityServic
|
|
|
vo.setStatusName("已结束");
|
|
|
}
|
|
|
|
|
|
- vo.setCouponName(lifeDiscountCouponMapper.selectById(activity.getCouponId()).getName());
|
|
|
+ // 设置优惠券名称(判空处理)
|
|
|
+ if (activity.getCouponId() != null) {
|
|
|
+ LifeDiscountCoupon coupon = lifeDiscountCouponMapper.selectById(activity.getCouponId());
|
|
|
+ if (coupon != null) {
|
|
|
+ vo.setCouponName(coupon.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
voRecords.add(vo);
|
|
|
}
|