ソースを参照

1、调整分页

yys 3 週間 前
コミット
b4100dac83

+ 4 - 1
fs-service/src/main/java/com/fs/live/param/CouponPO.java

@@ -1,9 +1,12 @@
 package com.fs.live.param;
 
+import com.fs.common.param.BaseQueryParam;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
 
 @Data
-public class CouponPO {
+@EqualsAndHashCode(callSuper = true)
+public class CouponPO extends BaseQueryParam {
 
     /**
      * 直播间id

+ 8 - 25
fs-service/src/main/java/com/fs/live/service/impl/LiveCouponServiceImpl.java

@@ -4,8 +4,9 @@ import java.util.*;
 import java.util.stream.Collectors;
 
 import cn.hutool.core.util.ObjectUtil;
-import cn.hutool.json.JSONUtil;
 import com.fs.common.constant.LiveKeysConstant;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
 import com.fs.common.utils.DateUtils;
@@ -300,24 +301,6 @@ public class LiveCouponServiceImpl implements ILiveCouponService
             return R.error("优惠券配置不存在!");
         }
 
-        // 判断是否为无门槛优惠券(type=2)
-        boolean isNoThresholdCoupon = liveCoupon.getType() != null && liveCoupon.getType() == 2L;
-
-        if (!isNoThresholdCoupon) {
-            // 普通优惠券:检查是否已领取
-            Object o = redisCache.hashGet(String.format(LiveKeysConstant.LIVE_HOME_PAGE_CONFIG_COUPON, coupon.getLiveId(), coupon.getCouponIssueId()), String.valueOf(coupon.getUserId()));
-            if (ObjectUtil.isNotEmpty(o)) {
-                return R.error("您已经领取过优惠券了!");
-            }
-        } else {
-            // 无门槛优惠券:检查领取次数是否超过限制
-            int receivedCount = liveCouponIssueUserMapper.countUserReceivedCoupon(coupon.getUserId(), issue.getId());
-            Integer limitCount = liveCoupon.getLimitReceiveCount() != null ? liveCoupon.getLimitReceiveCount() : 1;
-            if (receivedCount >= limitCount) {
-                return R.error("您已达到该优惠券的领取次数上限!");
-            }
-        }
-
         Long decrement = redisCache.decrement(String.format(LiveKeysConstant.LIVE_COUPON_NUM , coupon.getCouponIssueId()));
 
         if (decrement < 0L) {
@@ -369,11 +352,6 @@ public class LiveCouponServiceImpl implements ILiveCouponService
         }
 
 
-        // 对于非无门槛优惠券,记录到Redis(防止重复领取)
-        if (!isNoThresholdCoupon) {
-            redisCache.hashPut(String.format(LiveKeysConstant.LIVE_HOME_PAGE_CONFIG_COUPON, coupon.getLiveId(), coupon.getCouponIssueId()), String.valueOf(coupon.getUserId()), JSONUtil.toJsonStr(record));
-        }
-
         return R.ok("恭喜您抢到优惠券");
     }
 
@@ -390,9 +368,14 @@ public class LiveCouponServiceImpl implements ILiveCouponService
 
     @Override
     public R userCouponDetailList(CouponPO coupon) {
+        int pageNum = coupon.getPageNum() != null ? coupon.getPageNum()
+                : (coupon.getPage() != null ? coupon.getPage() : 1);
+        int pageSize = coupon.getPageSize() != null ? coupon.getPageSize() : 10;
+        PageHelper.startPage(pageNum, pageSize);
         List<LiveCouponUserDetailVo> list = liveCouponUserService.selectLiveCouponUserDetailList(coupon);
         list.forEach(this::fillCouponStatusName);
-        return R.ok().put("data", list);
+        PageInfo<LiveCouponUserDetailVo> pageInfo = new PageInfo<>(list);
+        return R.ok().put("data", pageInfo);
     }
 
     @Override

+ 45 - 11
fs-service/src/main/java/com/fs/live/service/impl/LiveServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
@@ -770,10 +771,9 @@ public class LiveServiceImpl implements ILiveService
         if (live.getIsShow() != 1) {
             return R.error("您未拥有直播权限");
         }
-        SysConfig sysConfig = sysConfigService.selectConfigByConfigKey("living.config");
-        Map<String, String> livingConfigMap = JSON.parseObject(sysConfig.getConfigValue(), Map.class);
+        Map<String, String> livingConfigMap = getLivingConfigMap(live.getCompanyId());
         if (livingConfigMap == null || livingConfigMap.isEmpty()) {
-            return R.error("缺失直播配置");
+            return R.error("缺失直播配置,请在系统参数中完善 living.config");
         }
         String rtmpPushUrl = generateRtmpPushUrl(livingConfigMap.get("domain"), livingConfigMap.get("app"), liveId.toString());
         String hlvPlayUrl = generateHlvPlayUrl(livingConfigMap.get("http"), livingConfigMap.get("app"), liveId.toString());
@@ -994,15 +994,10 @@ public class LiveServiceImpl implements ILiveService
             return R.error("您没有权限操作此直播间");
         }
 
-        SysConfig sysConfig = sysConfigService.selectConfigByConfigKey("living.config");
-        if (sysConfig == null || StringUtils.isEmpty(sysConfig.getConfigValue())) {
-            log.error("直播配置不存在或为空, liveId: {}", live.getLiveId());
-            return R.error("直播配置不存在,请联系管理员配置");
-        }
-        Map<String, String> livingConfigMap = JSON.parseObject(sysConfig.getConfigValue(), Map.class);
+        Map<String, String> livingConfigMap = getLivingConfigMap(exist.getCompanyId());
         if (livingConfigMap == null || livingConfigMap.isEmpty()) {
-            log.error("直播配置解析失败, liveId: {}, configValue: {}", live.getLiveId(), sysConfig.getConfigValue());
-            return R.error("直播配置解析失败");
+            log.error("直播配置不存在或为空, liveId: {}", live.getLiveId());
+            return R.error("直播配置不存在或为空,请在系统参数中完善 living.config");
         }
         if (StringUtils.isEmpty(livingConfigMap.get("domain")) || StringUtils.isEmpty(livingConfigMap.get("app"))) {
             log.error("直播配置缺少必要参数, liveId: {}, configMap: {}", live.getLiveId(), livingConfigMap);
@@ -1558,6 +1553,45 @@ public class LiveServiceImpl implements ILiveService
     }
 
 
+    private Map<String, String> getLivingConfigMap(Long companyId) {
+        SysConfig sysConfig = sysConfigService.selectConfigByConfigKey("living.config");
+        if (sysConfig == null || StringUtils.isEmpty(sysConfig.getConfigValue())) {
+            return null;
+        }
+        return resolveLivingConfigMap(sysConfig.getConfigValue(), companyId);
+    }
+
+    @SuppressWarnings("unchecked")
+    private Map<String, String> resolveLivingConfigMap(String configValue, Long companyId) {
+        String trimmed = configValue.trim();
+        try {
+            if (trimmed.startsWith("[")) {
+                JSONArray configArray = JSON.parseArray(trimmed);
+                if (configArray == null || configArray.isEmpty()) {
+                    return null;
+                }
+                if (companyId != null) {
+                    for (int i = 0; i < configArray.size(); i++) {
+                        JSONObject item = configArray.getJSONObject(i);
+                        if (item != null && companyId.equals(item.getLong("companyId"))) {
+                            return item.toJavaObject(Map.class);
+                        }
+                    }
+                }
+                JSONObject first = configArray.getJSONObject(0);
+                return first == null ? null : first.toJavaObject(Map.class);
+            }
+            if (trimmed.startsWith("{")) {
+                return JSON.parseObject(trimmed, Map.class);
+            }
+            log.warn("living.config 格式不支持: {}", trimmed);
+            return null;
+        } catch (Exception e) {
+            log.error("解析 living.config 失败, configValue: {}", configValue, e);
+            return null;
+        }
+    }
+
     public static String generateRtmpPushUrl(String domain, String app, String liveId) {
         Date now = new Date();
         now.setTime(now.getTime() + 24 * 3600 * 1000);

+ 0 - 1
fs-user-app/src/main/java/com/fs/app/facade/impl/LiveFacadeServiceImpl.java

@@ -233,7 +233,6 @@ public class LiveFacadeServiceImpl extends BaseController implements LiveFacadeS
     }
 
     @Override
-    @DistributeLock(keyExpression = "#coupon.couponIssueId +'_'+#coupon.userId", scene = "coupon_claim", waitTime = 1000, errorMsg = "优惠券领取失败")
     public R couponClaim(CouponPO coupon) {
         return iLiveCouponService.claimCoupon(coupon);
     }