|
@@ -1,15 +1,16 @@
|
|
|
package com.ylx.lottery.service.impl;
|
|
package com.ylx.lottery.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.TypeReference;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.ylx.common.exception.ServiceException;
|
|
import com.ylx.common.exception.ServiceException;
|
|
|
import com.ylx.lottery.domain.LotteryCountLog;
|
|
import com.ylx.lottery.domain.LotteryCountLog;
|
|
|
import com.ylx.lottery.domain.dto.LotteryCountDTO;
|
|
import com.ylx.lottery.domain.dto.LotteryCountDTO;
|
|
|
|
|
+import com.ylx.lottery.domain.vo.LotteryActivityVO;
|
|
|
import com.ylx.lottery.domain.vo.LotteryCountResponseVO;
|
|
import com.ylx.lottery.domain.vo.LotteryCountResponseVO;
|
|
|
import com.ylx.lottery.domain.vo.LotteryStatVO;
|
|
import com.ylx.lottery.domain.vo.LotteryStatVO;
|
|
|
import com.ylx.lottery.service.LotteryCountLogService;
|
|
import com.ylx.lottery.service.LotteryCountLogService;
|
|
@@ -18,10 +19,10 @@ import com.ylx.usercenter.domain.dto.UnifiedUserCenterDTO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
@@ -32,6 +33,10 @@ public class LotteryCountServiceImpl implements LotteryCountService {
|
|
|
|
|
|
|
|
// 定义接口路径常量
|
|
// 定义接口路径常量
|
|
|
private static final String LOTTERY_COUNT_ADD_PATH = "/lottery/lotteryUserLotteryCount/batchAdd";
|
|
private static final String LOTTERY_COUNT_ADD_PATH = "/lottery/lotteryUserLotteryCount/batchAdd";
|
|
|
|
|
+ private static final String LOTTERY_ACTIVITY_LIST_PATH = "/lottery/lotteryActivity/queryActivityList";
|
|
|
|
|
+ private static final int SCENE_CODE = 2;
|
|
|
|
|
+ private static final int DEFAULT_TIMEOUT = 5000; // 5秒超时
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
private LotteryCountLogService lotteryCountLogService;
|
|
private LotteryCountLogService lotteryCountLogService;
|
|
|
|
|
|
|
@@ -69,7 +74,7 @@ public class LotteryCountServiceImpl implements LotteryCountService {
|
|
|
String jsonParam = JSON.toJSONString(dtoList);
|
|
String jsonParam = JSON.toJSONString(dtoList);
|
|
|
|
|
|
|
|
// 3. 发送请求
|
|
// 3. 发送请求
|
|
|
- String result = HttpUtil.post(url, jsonParam);
|
|
|
|
|
|
|
+ String result = HttpUtil.post(url, jsonParam, DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
// 4. 校验结果
|
|
// 4. 校验结果
|
|
|
if (StrUtil.isEmpty(result)) {
|
|
if (StrUtil.isEmpty(result)) {
|
|
@@ -77,15 +82,15 @@ public class LotteryCountServiceImpl implements LotteryCountService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 5. 解析结果
|
|
// 5. 解析结果
|
|
|
- LotteryCountResponseVO response = JSON.parseObject(
|
|
|
|
|
|
|
+ LotteryCountResponseVO<String> response = JSON.parseObject(
|
|
|
result,
|
|
result,
|
|
|
- new TypeReference<LotteryCountResponseVO>() {
|
|
|
|
|
|
|
+ new TypeReference<LotteryCountResponseVO<String>>() {
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// 4. 处理业务状态
|
|
// 4. 处理业务状态
|
|
|
if (!response.isSuccess()) {
|
|
if (!response.isSuccess()) {
|
|
|
- log.warn("抽奖次数批量添加接口失败失败: code={}, msg={}", response.getCode(), response.getMessage());
|
|
|
|
|
|
|
+ log.warn("抽奖次数批量添加接口失败失败: code={}, msg={}", response.getCode(), response.getMessage());
|
|
|
throw new ServiceException("远程接口返回失败: " + response.getMessage());
|
|
throw new ServiceException("远程接口返回失败: " + response.getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -101,6 +106,59 @@ public class LotteryCountServiceImpl implements LotteryCountService {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<LotteryActivityVO> queryActivityRules() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 1. 构建请求参数
|
|
|
|
|
+ String url = localLiveBaseUrl + LOTTERY_ACTIVITY_LIST_PATH;
|
|
|
|
|
+ Map<String, Object> params = Collections.singletonMap("scene", SCENE_CODE);
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 发送请求
|
|
|
|
|
+ String resultJson = HttpUtil.get(url, params, DEFAULT_TIMEOUT);
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 校验结果
|
|
|
|
|
+ if (StrUtil.isEmpty(resultJson)) {
|
|
|
|
|
+ throw new RuntimeException("抽奖规则查询接口失败:接口返回空结果");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 解析结果
|
|
|
|
|
+ LotteryCountResponseVO<List<LotteryActivityVO>> response = JSON.parseObject(
|
|
|
|
|
+ resultJson,
|
|
|
|
|
+ new TypeReference<LotteryCountResponseVO<List<LotteryActivityVO>>>() {
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 处理业务状态
|
|
|
|
|
+ if (ObjUtil.isNull(response) || !response.isSuccess()) {
|
|
|
|
|
+ String msg = ObjUtil.isNotNull(response) ? response.getMessage() : "未知错误";
|
|
|
|
|
+ Integer code = ObjUtil.isNotNull(response) ? response.getCode() : -1;
|
|
|
|
|
+
|
|
|
|
|
+ log.warn("抽奖规则查询接口业务失败: code={}, msg={}", code, msg);
|
|
|
|
|
+ throw new ServiceException("远程接口返回失败: " + msg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 获取数据列表
|
|
|
|
|
+ List<LotteryActivityVO> activityList = response.getResult();
|
|
|
|
|
+
|
|
|
|
|
+ if (CollUtil.isEmpty(activityList)) {
|
|
|
|
|
+ log.info("未查询到相关活动数据");
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.info("成功获取抽奖活动列表,数量: {}", activityList.size());
|
|
|
|
|
+
|
|
|
|
|
+ return activityList;
|
|
|
|
|
+
|
|
|
|
|
+ } catch (ServiceException e) {
|
|
|
|
|
+ // 透传业务异常,不要重复包装
|
|
|
|
|
+ throw e;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("抽奖规则查询接口发生系统异常", e);
|
|
|
|
|
+ // 优化点:只抛出消息,不要直接把整个 Exception 对象 toString() 拼接到字符串里
|
|
|
|
|
+ throw new ServiceException("抽奖规则查询接口异常: " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void updateSyncStatus(String userId) {
|
|
private void updateSyncStatus(String userId) {
|
|
|
LambdaUpdateWrapper<LotteryCountLog> updateWrapper = new LambdaUpdateWrapper<>();
|
|
LambdaUpdateWrapper<LotteryCountLog> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
updateWrapper.eq(LotteryCountLog::getUserId, userId)
|
|
updateWrapper.eq(LotteryCountLog::getUserId, userId)
|