|
|
@@ -16,19 +16,27 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import shop.alien.entity.store.LifeDiscountCoupon;
|
|
|
+import shop.alien.entity.store.LifeNotice;
|
|
|
import shop.alien.entity.store.StoreImg;
|
|
|
+import shop.alien.entity.store.StoreUser;
|
|
|
+import shop.alien.entity.store.vo.WebSocketVo;
|
|
|
import shop.alien.entity.storePlatform.StoreOperationalActivity;
|
|
|
import shop.alien.entity.storePlatform.StoreOperationalActivitySignup;
|
|
|
import shop.alien.entity.storePlatform.vo.StoreOperationalActivityDTO;
|
|
|
import shop.alien.entity.storePlatform.vo.StoreOperationalActivityVO;
|
|
|
import shop.alien.mapper.LifeDiscountCouponMapper;
|
|
|
+import shop.alien.mapper.LifeNoticeMapper;
|
|
|
import shop.alien.mapper.StoreImgMapper;
|
|
|
+import shop.alien.mapper.StoreUserMapper;
|
|
|
import shop.alien.mapper.storePlantform.StoreOperationalActivityMapper;
|
|
|
import shop.alien.mapper.storePlantform.StoreOperationalActivitySignupMapper;
|
|
|
import shop.alien.storeplatform.feign.AlienAIFeign;
|
|
|
+import shop.alien.storeplatform.feign.AlienStoreFeign;
|
|
|
import shop.alien.storeplatform.service.OperationalActivityService;
|
|
|
import shop.alien.storeplatform.util.AiContentModerationUtil;
|
|
|
+import shop.alien.util.common.Constants;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
@@ -65,8 +73,14 @@ public class OperationalActivityServiceImpl implements OperationalActivityServic
|
|
|
|
|
|
private final StoreOperationalActivitySignupMapper signupMapper;
|
|
|
|
|
|
+ private final StoreUserMapper storeUserMapper;
|
|
|
+
|
|
|
+ private final LifeNoticeMapper lifeNoticeMapper;
|
|
|
+
|
|
|
private final AlienAIFeign alienAIFeign;
|
|
|
|
|
|
+ private final AlienStoreFeign alienStoreFeign;
|
|
|
+
|
|
|
private final RedissonClient redissonClient;
|
|
|
|
|
|
private final AiContentModerationUtil aiContentModerationUtil;
|
|
|
@@ -143,6 +157,7 @@ public class OperationalActivityServiceImpl implements OperationalActivityServic
|
|
|
|
|
|
// 审核结束后,设置审核时间
|
|
|
Date auditTime = new Date();
|
|
|
+ activity.setAuditStatus(auditResult.isPassed() ? 1 : 2);
|
|
|
activity.setAuditTime(auditTime);
|
|
|
|
|
|
// 审核通过,根据活动时间自动设置状态
|
|
|
@@ -173,6 +188,15 @@ public class OperationalActivityServiceImpl implements OperationalActivityServic
|
|
|
}
|
|
|
|
|
|
result = activityMapper.insert(activity);
|
|
|
+
|
|
|
+ // AI审核后向商户发送通知
|
|
|
+ if (result > 0) {
|
|
|
+ try {
|
|
|
+ sendActivityAuditNotice(activity, auditResult.isPassed(), auditResult.getFailureReason());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送活动审核通知失败,activityId={}, error={}", activity.getId(), e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
// 使用用户描述和页面输入框其他信息,让AI生成海报图片。
|
|
|
if (dto.getUploadImgType() == 2) {
|
|
|
// 格式化输入AI参数
|
|
|
@@ -612,5 +636,83 @@ public class OperationalActivityServiceImpl implements OperationalActivityServic
|
|
|
|
|
|
return activityMapper.updateById(activity);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送活动审核通知给商户
|
|
|
+ *
|
|
|
+ * @param activity 活动信息
|
|
|
+ * @param approved 是否通过:true-通过,false-拒绝
|
|
|
+ * @param rejectReason 拒绝原因(审核不通过时)
|
|
|
+ */
|
|
|
+ private void sendActivityAuditNotice(StoreOperationalActivity activity, boolean approved, String rejectReason) {
|
|
|
+ log.info("OperationalActivityServiceImpl.sendActivityAuditNotice: activityId={}, approved={}",
|
|
|
+ activity.getId(), approved);
|
|
|
+
|
|
|
+ if (activity.getStoreId() == null) {
|
|
|
+ log.warn("活动商户ID为空,无法发送通知,activityId={}", activity.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询商户用户信息(获取手机号)
|
|
|
+ LambdaQueryWrapper<StoreUser> userWrapper = new LambdaQueryWrapper<>();
|
|
|
+ userWrapper.eq(StoreUser::getStoreId, activity.getStoreId())
|
|
|
+ .eq(StoreUser::getDeleteFlag, 0)
|
|
|
+ .last("LIMIT 1");
|
|
|
+ StoreUser storeUser = storeUserMapper.selectOne(userWrapper);
|
|
|
+ if (storeUser == null || storeUser.getPhone() == null) {
|
|
|
+ log.warn("商户用户信息不存在或手机号为空,无法发送通知,storeId={}", activity.getStoreId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String phone = storeUser.getPhone();
|
|
|
+ String receiverId = "store_" + phone;
|
|
|
+
|
|
|
+ // 构建通知内容
|
|
|
+ String message;
|
|
|
+ if (approved) {
|
|
|
+ // 审核成功
|
|
|
+ message = "您创建的活动已审核通过,快去查看吧";
|
|
|
+ } else {
|
|
|
+ // 审核拒绝
|
|
|
+ message = "您创建的活动经审核未通过,拒绝原因:" + (rejectReason != null ? rejectReason : "") + ",请重新提交审核";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建通知对象
|
|
|
+ JSONObject contextJson = new JSONObject();
|
|
|
+ contextJson.put("activityId", activity.getId());
|
|
|
+ contextJson.put("activityName", activity.getActivityName());
|
|
|
+ contextJson.put("status", approved ? "通过" : "拒绝");
|
|
|
+ contextJson.put("message", message);
|
|
|
+
|
|
|
+ LifeNotice lifeNotice = new LifeNotice();
|
|
|
+ lifeNotice.setSenderId("system");
|
|
|
+ lifeNotice.setReceiverId(receiverId);
|
|
|
+ lifeNotice.setBusinessId(activity.getId());
|
|
|
+ lifeNotice.setTitle("活动审核通知");
|
|
|
+ lifeNotice.setContext(contextJson.toJSONString());
|
|
|
+ lifeNotice.setNoticeType(Constants.Notice.SYSTEM_NOTICE); // 系统通知
|
|
|
+ lifeNotice.setIsRead(0);
|
|
|
+
|
|
|
+ // 保存通知到数据库
|
|
|
+ lifeNoticeMapper.insert(lifeNotice);
|
|
|
+
|
|
|
+ // 通过WebSocket发送实时通知
|
|
|
+ try {
|
|
|
+ WebSocketVo webSocketVo = new WebSocketVo();
|
|
|
+ webSocketVo.setSenderId("system");
|
|
|
+ webSocketVo.setReceiverId(receiverId);
|
|
|
+ webSocketVo.setCategory("notice");
|
|
|
+ webSocketVo.setNoticeType("1");
|
|
|
+ webSocketVo.setIsRead(0);
|
|
|
+ webSocketVo.setText(JSONObject.toJSONString(lifeNotice));
|
|
|
+
|
|
|
+ alienStoreFeign.sendMsgToClientByPhoneId(receiverId, JSONObject.toJSONString(webSocketVo));
|
|
|
+ log.info("活动审核通知发送成功,activityId={}, receiverId={}, approved={}",
|
|
|
+ activity.getId(), receiverId, approved);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送WebSocket通知失败,activityId={}, receiverId={}, error={}",
|
|
|
+ activity.getId(), receiverId, e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|