Selaa lähdekoodia

广场舞大赛活动

xgb 1 kuukausi sitten
vanhempi
commit
356ca0e6ad

+ 2 - 75
fs-service/src/main/java/com/fs/activity/domain/AccActivity.java

@@ -91,79 +91,6 @@ public class AccActivity extends BaseEntity {
      */
     private Date updatedAt;
 
-    @Override
-    public boolean equals(Object that) {
-        if (this == that) {
-            return true;
-        }
-        if (that == null) {
-            return false;
-        }
-        if (getClass() != that.getClass()) {
-            return false;
-        }
-        AccActivity other = (AccActivity) that;
-        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
-            && (this.getTitle() == null ? other.getTitle() == null : this.getTitle().equals(other.getTitle()))
-            && (this.getCoverUrl() == null ? other.getCoverUrl() == null : this.getCoverUrl().equals(other.getCoverUrl()))
-            && (this.getDescription() == null ? other.getDescription() == null : this.getDescription().equals(other.getDescription()))
-            && (this.getRegistrationStartTime() == null ? other.getRegistrationStartTime() == null : this.getRegistrationStartTime().equals(other.getRegistrationStartTime()))
-            && (this.getRegistrationEndTime() == null ? other.getRegistrationEndTime() == null : this.getRegistrationEndTime().equals(other.getRegistrationEndTime()))
-            && (this.getActivityStartTime() == null ? other.getActivityStartTime() == null : this.getActivityStartTime().equals(other.getActivityStartTime()))
-            && (this.getActivityEndTime() == null ? other.getActivityEndTime() == null : this.getActivityEndTime().equals(other.getActivityEndTime()))
-            && (this.getLocation() == null ? other.getLocation() == null : this.getLocation().equals(other.getLocation()))
-            && (this.getRules() == null ? other.getRules() == null : this.getRules().equals(other.getRules()))
-            && (this.getAwards() == null ? other.getAwards() == null : this.getAwards().equals(other.getAwards()))
-            && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
-            && (this.getCreatedBy() == null ? other.getCreatedBy() == null : this.getCreatedBy().equals(other.getCreatedBy()))
-            && (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()))
-            && (this.getUpdatedAt() == null ? other.getUpdatedAt() == null : this.getUpdatedAt().equals(other.getUpdatedAt()));
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
-        result = prime * result + ((getTitle() == null) ? 0 : getTitle().hashCode());
-        result = prime * result + ((getCoverUrl() == null) ? 0 : getCoverUrl().hashCode());
-        result = prime * result + ((getDescription() == null) ? 0 : getDescription().hashCode());
-        result = prime * result + ((getRegistrationStartTime() == null) ? 0 : getRegistrationStartTime().hashCode());
-        result = prime * result + ((getRegistrationEndTime() == null) ? 0 : getRegistrationEndTime().hashCode());
-        result = prime * result + ((getActivityStartTime() == null) ? 0 : getActivityStartTime().hashCode());
-        result = prime * result + ((getActivityEndTime() == null) ? 0 : getActivityEndTime().hashCode());
-        result = prime * result + ((getLocation() == null) ? 0 : getLocation().hashCode());
-        result = prime * result + ((getRules() == null) ? 0 : getRules().hashCode());
-        result = prime * result + ((getAwards() == null) ? 0 : getAwards().hashCode());
-        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
-        result = prime * result + ((getCreatedBy() == null) ? 0 : getCreatedBy().hashCode());
-        result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
-        result = prime * result + ((getUpdatedAt() == null) ? 0 : getUpdatedAt().hashCode());
-        return result;
-    }
-
-    @Override
-    public String toString() {
-        StringBuilder sb = new StringBuilder();
-        sb.append(getClass().getSimpleName());
-        sb.append(" [");
-        sb.append("Hash = ").append(hashCode());
-        sb.append(", id=").append(id);
-        sb.append(", title=").append(title);
-        sb.append(", coverUrl=").append(coverUrl);
-        sb.append(", description=").append(description);
-        sb.append(", registrationStartTime=").append(registrationStartTime);
-        sb.append(", registrationEndTime=").append(registrationEndTime);
-        sb.append(", activityStartTime=").append(activityStartTime);
-        sb.append(", activityEndTime=").append(activityEndTime);
-        sb.append(", location=").append(location);
-        sb.append(", rules=").append(rules);
-        sb.append(", awards=").append(awards);
-        sb.append(", status=").append(status);
-        sb.append(", createdBy=").append(createdBy);
-        sb.append(", createdAt=").append(createdAt);
-        sb.append(", updatedAt=").append(updatedAt);
-        sb.append("]");
-        return sb.toString();
-    }
+    // 是否展示
+    private Boolean isShow;
 }

+ 19 - 0
fs-service/src/main/java/com/fs/activity/param/AccVoteResponse.java

@@ -0,0 +1,19 @@
+package com.fs.activity.param;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * 投票数
+ */
+@Data
+public class AccVoteResponse {
+
+    // 今日当前投票数
+    private Integer todayCurrVoteCount;
+
+    // 今日最大投票数
+    private Integer todayMaxCount;
+
+}

+ 4 - 0
fs-service/src/main/java/com/fs/activity/service/AccActivityService.java

@@ -65,4 +65,8 @@ public interface AccActivityService extends IService<AccActivity> {
 
 
     R checkActivityStatus(Long activityId);
+
+    AccActivity selectAccActivityByIdAndUserId(Long activityId, Long userId);
+
+    R updateActivityShow(Long activityId, long userId);
 }

+ 2 - 1
fs-service/src/main/java/com/fs/activity/service/AccWorkService.java

@@ -1,6 +1,5 @@
 package com.fs.activity.service;
 
-import com.fs.activity.domain.AccVoteRecord;
 import com.fs.activity.domain.AccWork;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fs.activity.param.AccVoteRecordRequest;
@@ -74,4 +73,6 @@ public interface AccWorkService extends IService<AccWork> {
     R castVote(AccVoteRecordRequest accWorkRecord);
 
     R getWorkList(AccWorkRequest request);
+
+    R getVoteCont(Long userId, Long activityId);
 }

+ 58 - 0
fs-service/src/main/java/com/fs/activity/service/impl/AccActivityServiceImpl.java

@@ -5,9 +5,14 @@ import com.fs.activity.domain.AccActivity;
 import com.fs.activity.service.AccActivityService;
 import com.fs.activity.mapper.AccActivityMapper;
 import com.fs.common.core.domain.R;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 /**
 * @author Administrator
@@ -18,6 +23,14 @@ import java.util.List;
 public class AccActivityServiceImpl extends ServiceImpl<AccActivityMapper, AccActivity>
     implements AccActivityService{
 
+
+    private static final String ACTIVITY_CACHE_KEY = "activity:";
+
+    private static final String ACTIVITY_SHOW_KEY = "activity:show:";
+
+    @Autowired
+    private RedisTemplate redisTemplate;
+
     /**
      * 查询活动
      *
@@ -135,6 +148,51 @@ public class AccActivityServiceImpl extends ServiceImpl<AccActivityMapper, AccAc
         return R.ok();
     }
 
+    /**
+     * @Description: 查询用户
+     * @Param:
+     * @Return:
+     * @Author xgb
+     * @Date 2026/3/11 11:19
+     */
+
+    @Override
+    public AccActivity selectAccActivityByIdAndUserId(Long activityId, Long userId) {
+
+        LocalDate today = LocalDate.now();
+        String todayStr = today.format(DateTimeFormatter.ISO_DATE);
+        String showKey = ACTIVITY_SHOW_KEY + activityId+ ":" + userId + ":" + todayStr;
+        Boolean isShow = !redisTemplate.hasKey(showKey);
+
+        // 先从缓存读取
+        String cacheKey = ACTIVITY_CACHE_KEY + activityId;
+        AccActivity accActivity = (AccActivity) redisTemplate.opsForValue().get(cacheKey);
+        if (accActivity != null) {
+            accActivity.setIsShow(isShow);
+            return accActivity;
+        }
+
+        // 缓存中没有,查询数据库
+        accActivity = baseMapper.selectAccActivityById(activityId);
+        if (accActivity != null) {
+            // 放入缓存,有效期 1 天
+            redisTemplate.opsForValue().set(cacheKey, accActivity, 1, TimeUnit.DAYS);
+        }
+        accActivity.setIsShow( isShow);
+
+        return accActivity;
+    }
+
+    @Override
+    public R updateActivityShow(Long activityId, long userId) {
+        LocalDate today = LocalDate.now();
+        String todayStr = today.format(DateTimeFormatter.ISO_DATE);
+        String cacheKey = ACTIVITY_SHOW_KEY + activityId+ ":" + userId + ":" + todayStr;
+        redisTemplate.opsForValue().set(cacheKey, true,1, TimeUnit.DAYS);
+
+        return R.ok();
+    }
+
 
 }
 

+ 23 - 4
fs-service/src/main/java/com/fs/activity/service/impl/AccWorkServiceImpl.java

@@ -1,7 +1,6 @@
 package com.fs.activity.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.activity.domain.AccVoteRecord;
@@ -9,15 +8,13 @@ import com.fs.activity.domain.AccWork;
 import com.fs.activity.mapper.AccVoteRecordMapper;
 import com.fs.activity.param.AccVoteRecordRequest;
 import com.fs.activity.param.AccVoteRecordResponse;
+import com.fs.activity.param.AccVoteResponse;
 import com.fs.activity.param.AccWorkRequest;
 import com.fs.activity.service.AccActivityService;
 import com.fs.activity.service.AccWorkService;
 import com.fs.activity.mapper.AccWorkMapper;
-import com.fs.common.constant.FsConstants;
 import com.fs.common.core.domain.R;
-import com.fs.common.core.redis.RedisCache;
 import com.fs.common.exception.ServiceException;
-import com.fs.common.exception.base.BusinessException;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
@@ -321,6 +318,28 @@ public class AccWorkServiceImpl extends ServiceImpl<AccWorkMapper, AccWork>
 
         return R.ok().put("data",new PageInfo<>(accWorks));
     }
+
+    /**
+     * @Description: 获取投票数
+     * @Param:
+     * @Return:
+     * @Author xgb
+     * @Date 2026/3/11 10:47
+     */
+    @Override
+    public R getVoteCont(Long userId, Long activityId) {
+        LocalDate today = LocalDate.now();
+        String todayStr = today.format(DateTimeFormatter.ISO_DATE);
+        String dailyLimitKey = DAILY_VOTE_LIMIT + activityId +":"+ userId + ":" + todayStr;
+        Integer count = (Integer) redisTemplate.opsForValue().get(dailyLimitKey);
+        if (count == null) {
+            count=0;
+        }
+        AccVoteResponse response=new AccVoteResponse();
+        response.setTodayMaxCount(MAX_VOTES_PER_DAY);
+        response.setTodayCurrVoteCount(count);
+        return R.ok().put("data",response);
+    }
 }
 
 

+ 29 - 1
fs-user-app/src/main/java/com/fs/app/controller/app/AccActivityController.java

@@ -60,8 +60,22 @@ public class AccActivityController extends AppBaseController
      * @Date 2026/3/6 15:18
      */
     @GetMapping("/getActivityInfo")
+    @Login
     public R getActivityInfo(Long activityId){
-        return R.ok().put("data",accActivityService.selectAccActivityById(activityId));
+        return R.ok().put("data",accActivityService.selectAccActivityByIdAndUserId(activityId,Long.parseLong(getUserId())));
+    }
+
+    /**
+     * @Description: 今天关闭展示活动弹窗
+     * @Param:
+     * @Return:
+     * @Author xgb
+     * @Date 2026/3/11 11:41
+     */
+    @GetMapping("/updateActivityShow")
+    @Login
+    public R updateActivityShow(Long activityId){
+        return accActivityService.updateActivityShow(activityId,Long.parseLong(getUserId()));
     }
 
 
@@ -178,6 +192,20 @@ public class AccActivityController extends AppBaseController
         return accWorkService.getWorkList(request);
     }
 
+    /**
+     * @Description: 获取用户投票数
+     * @Param:
+     * @Return:
+     * @Author xgb
+     * @Date 2026/3/11 10:39
+     */
+    @GetMapping("/getVoteCont")
+    @Login
+    public R getVoteCont(Long activityId){
+        return accWorkService.getVoteCont(Long.parseLong(getUserId()),activityId);
+    }
+
+