浏览代码

Merge branch 'release_lutong_bug' into sit

lutong 1 月之前
父节点
当前提交
9979015219

+ 18 - 4
alien-store/src/main/java/shop/alien/store/controller/LifeDiscountCouponStoreFriendController.java

@@ -16,6 +16,7 @@ import shop.alien.store.annotation.TrackEvent;
 import shop.alien.store.service.LifeDiscountCouponStoreFriendService;
 import shop.alien.util.common.TokenInfo;
 import springfox.documentation.annotations.ApiIgnore;
+import org.apache.commons.lang3.StringUtils;
 
 import java.util.List;
 import java.util.Map;
@@ -177,12 +178,25 @@ public class LifeDiscountCouponStoreFriendController {
     }
 
     @ApiOperation("查询赠券规则")
-    @ApiImplicitParams({@ApiImplicitParam(name = "storeId", value = "当前登录店铺id", dataType = "String", paramType = "query", required = true)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "storeId", value = "当前登录店铺id", dataType = "String", paramType = "query", required = true),
+            @ApiImplicitParam(name = "acName", value = "活动名称(模糊查询,可选)", dataType = "String", paramType = "query", required = false),
+            @ApiImplicitParam(name = "status", value = "状态:0-启用,1-禁用(可选)", dataType = "String", paramType = "query", required = false)
     })
     @GetMapping("/getRuleList")
-    public R<List<LifeDiscountCouponFriendRuleVo>> getRuleList(@RequestParam(value = "storeId") String storeId, String acName, String status) {
-        log.info("LifeDiscountCouponStoreFriendController.getRuleList?storeId={},name={},status={}", storeId, acName, status);
-        return R.data(lifeDiscountCouponStoreFriendService.getRuleList(storeId, acName, status));
+    public R<List<LifeDiscountCouponFriendRuleVo>> getRuleList(@RequestParam(value = "storeId") String storeId,
+                                                                @RequestParam(value = "acName", required = false) String acName,
+                                                                @RequestParam(value = "status", required = false) String status) {
+        log.info("LifeDiscountCouponStoreFriendController.getRuleList?storeId={},acName={},status={}", storeId, acName, status);
+        try {
+            if (StringUtils.isEmpty(storeId)) {
+                return R.fail("店铺ID不能为空");
+            }
+            return R.data(lifeDiscountCouponStoreFriendService.getRuleList(storeId, acName, status));
+        } catch (Exception e) {
+            log.error("LifeDiscountCouponStoreFriendController.getRuleList ERROR Msg={}", e.getMessage(), e);
+            return R.fail("查询失败:" + e.getMessage());
+        }
     }
 
     @ApiOperation("查询赠券记录(商户送给商户券)。queryType=1查询我收到的,queryType=2查询我送出的。type=4仅代金券,不传返回全部(优惠券+代金券)。couponType=1仅满减券,couponType=2仅折扣券,不传返回全部优惠券")

+ 28 - 3
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponStoreFriendServiceImpl.java

@@ -30,6 +30,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -568,35 +569,59 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
 
     @Override
     public List<LifeDiscountCouponFriendRuleVo> getRuleList(String storeId, String acName, String status) {
+        // 参数校验
         if (StringUtils.isEmpty(storeId)) {
+            log.warn("getRuleList 参数错误:storeId 不能为空");
             return new ArrayList<>();
         }
+        
+        // 查询规则列表(一个规则可能关联多个优惠券,会返回多条记录)
         List<LifeDiscountCouponFriendRuleVo> ruleList = lifeDiscountCouponFriendRuleDetailMapper.getRuleList(storeId);
         if (ruleList == null) {
             ruleList = new ArrayList<>();
         }
+        
+        // 计算状态:根据结束日期判断活动是否已结束
+        // 状态:0-启用(活动进行中),1-禁用(活动已结束)
         if (ObjectUtils.isNotEmpty(ruleList)) {
             Date now = new Date();
             ruleList.forEach(i -> {
                 if (i.getEndDate() != null) {
+                    // 如果结束日期在当前时间之后,活动进行中(启用)
+                    // 如果结束日期在当前时间之前或等于,活动已结束(禁用)
                     i.setStatus(i.getEndDate().after(now) ? "0" : "1");
                 } else {
-                    i.setStatus(null);
+                    // 如果结束日期为null,视为永久有效,状态为启用
+                    i.setStatus("0");
                 }
             });
         }
+        
+        // 按规则ID分组去重:同一个规则ID只保留第一条记录(避免一个规则关联多个优惠券时重复展示)
+        Map<Integer, LifeDiscountCouponFriendRuleVo> ruleMap = new LinkedHashMap<>();
+        for (LifeDiscountCouponFriendRuleVo rule : ruleList) {
+            if (rule.getId() != null && !ruleMap.containsKey(rule.getId())) {
+                ruleMap.put(rule.getId(), rule);
+            }
+        }
+        ruleList = new ArrayList<>(ruleMap.values());
+        
+        // 根据活动名称过滤(模糊查询)
         if (StringUtils.isNotEmpty(acName)) {
-            String name = acName;
+            String name = acName.trim();
             ruleList = ruleList.stream()
                     .filter(i -> i.getAcName() != null && i.getAcName().contains(name))
                     .collect(Collectors.toList());
         }
+        
+        // 根据状态过滤
         if (StringUtils.isNotEmpty(status)) {
-            String s = status;
+            String s = status.trim();
             ruleList = ruleList.stream()
                     .filter(i -> i.getStatus() != null && i.getStatus().equals(s))
                     .collect(Collectors.toList());
         }
+        
         return ruleList;
     }