|
|
@@ -1,13 +1,17 @@
|
|
|
package shop.alien.store.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import shop.alien.entity.store.LifeDiscountCoupon;
|
|
|
+import shop.alien.entity.store.LifeNotice;
|
|
|
import shop.alien.entity.store.StoreImg;
|
|
|
import shop.alien.entity.store.StoreInfo;
|
|
|
+import shop.alien.entity.store.StoreUser;
|
|
|
+import shop.alien.entity.store.vo.WebSocketVo;
|
|
|
import shop.alien.entity.storePlatform.StoreOperationalActivity;
|
|
|
import shop.alien.entity.storePlatform.StoreOperationalActivityAchievement;
|
|
|
import shop.alien.entity.storePlatform.StoreOperationalActivitySignup;
|
|
|
@@ -15,14 +19,18 @@ import shop.alien.entity.storePlatform.vo.StoreOperationalActivityDetailVo;
|
|
|
import shop.alien.entity.storePlatform.vo.StoreOperationalActivityMySignupVo;
|
|
|
import shop.alien.entity.storePlatform.vo.StoreOperationalActivitySignupCheckVo;
|
|
|
import shop.alien.mapper.LifeDiscountCouponMapper;
|
|
|
+import shop.alien.mapper.LifeNoticeMapper;
|
|
|
import shop.alien.mapper.StoreImgMapper;
|
|
|
import shop.alien.mapper.StoreInfoMapper;
|
|
|
+import shop.alien.mapper.StoreUserMapper;
|
|
|
import shop.alien.mapper.storePlantform.StoreOperationalActivityAchievementMapper;
|
|
|
import shop.alien.mapper.storePlantform.StoreOperationalActivityMapper;
|
|
|
import shop.alien.mapper.storePlantform.StoreOperationalActivitySignupMapper;
|
|
|
import shop.alien.store.config.BaseRedisService;
|
|
|
+import shop.alien.store.config.WebSocketProcess;
|
|
|
import shop.alien.store.dto.StoreOperationalActivitySignupDto;
|
|
|
import shop.alien.store.service.StoreOperationalActivityService;
|
|
|
+import shop.alien.util.common.Constants;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
@@ -48,6 +56,9 @@ public class StoreOperationalActivityServiceImpl implements StoreOperationalActi
|
|
|
private final StoreInfoMapper storeInfoMapper;
|
|
|
private final StoreOperationalActivitySignupMapper signupMapper;
|
|
|
private final BaseRedisService baseRedisService;
|
|
|
+ private final LifeNoticeMapper lifeNoticeMapper;
|
|
|
+ private final StoreUserMapper storeUserMapper;
|
|
|
+ private final WebSocketProcess webSocketProcess;
|
|
|
|
|
|
@Override
|
|
|
public StoreOperationalActivityDetailVo getActivityDetail(Integer id, Integer userId) {
|
|
|
@@ -260,7 +271,18 @@ public class StoreOperationalActivityServiceImpl implements StoreOperationalActi
|
|
|
signup.setSignupTime(new Date());
|
|
|
signup.setDeleteFlag(0);
|
|
|
signup.setCreatedUserId(dto.getUserId());
|
|
|
- return signupMapper.insert(signup) > 0;
|
|
|
+ boolean result = signupMapper.insert(signup) > 0;
|
|
|
+
|
|
|
+ // 报名成功后给商家发送通知
|
|
|
+ if (result) {
|
|
|
+ try {
|
|
|
+ sendSignupNoticeToStore(signup.getId(), activity);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送活动报名通知失败,signupId={}, error={}", signup.getId(), e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
} finally {
|
|
|
baseRedisService.unlock(lockKey, lockVal);
|
|
|
}
|
|
|
@@ -495,4 +517,77 @@ public class StoreOperationalActivityServiceImpl implements StoreOperationalActi
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送活动报名通知给商家
|
|
|
+ *
|
|
|
+ * @param signupId 报名ID
|
|
|
+ * @param activity 活动信息
|
|
|
+ */
|
|
|
+ private void sendSignupNoticeToStore(Integer signupId, StoreOperationalActivity activity) {
|
|
|
+ log.info("StoreOperationalActivityServiceImpl.sendSignupNoticeToStore: signupId={}, activityId={}", signupId, activity.getId());
|
|
|
+
|
|
|
+ if (activity.getStoreId() == null) {
|
|
|
+ log.warn("活动商户ID为空,无法发送通知,activityId={}", activity.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询商户信息
|
|
|
+ StoreInfo storeInfo = storeInfoMapper.selectById(activity.getStoreId());
|
|
|
+ if (storeInfo == null) {
|
|
|
+ log.warn("商户信息不存在,无法发送通知,storeId={}", activity.getStoreId());
|
|
|
+ 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 = "您的活动收到了一条新的报名";
|
|
|
+
|
|
|
+ JSONObject contextJson = new JSONObject();
|
|
|
+ contextJson.put("signupId", signupId);
|
|
|
+ contextJson.put("activityId", activity.getId());
|
|
|
+ contextJson.put("activityName", activity.getActivityName());
|
|
|
+ contextJson.put("message", message);
|
|
|
+
|
|
|
+ LifeNotice lifeNotice = new LifeNotice();
|
|
|
+ lifeNotice.setSenderId("system");
|
|
|
+ lifeNotice.setReceiverId(receiverId);
|
|
|
+ lifeNotice.setBusinessId(signupId);
|
|
|
+ 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));
|
|
|
+
|
|
|
+ webSocketProcess.sendMessage(receiverId, JSONObject.toJSONString(webSocketVo));
|
|
|
+ log.info("活动报名通知发送成功,signupId={}, receiverId={}", signupId, receiverId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送WebSocket通知失败,signupId={}, receiverId={}, error={}", signupId, receiverId, e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|