Jelajahi Sumber

bugfix: UV && DAU

ggbocoder 2 tahun lalu
induk
melakukan
0c39c22978

+ 14 - 8
README.md

@@ -1,16 +1,21 @@
 # FdroidRepository
 ## 主要功能
 
-- 基于邮件激活的注册方式
-- 基于MD5加密与加盐的密码存储方式
+- 基于邮件激活的注册方式 done
+- 基于MD5加密与加盐的密码存储方式 done 
 - 登录功能包括随机验证码的验证
-- 登录状态检查,为游客和已登录用户展示不同界面与功能
-- 不同用户的权限控制和网站数据统计(UV、DAU)
-- 管理员可以查看网站数据统计和网站监控信息
+- 登录状态检查,为游客和已登录用户展示不同界面与功能 done
+- 不同用户的权限控制和网站数据统计(UV、DAU) doing
+- 管理员可以查看网站数据统计和网站监控信息 
 - 用户上传头像
-- 发布帖子、评论帖子、热帖排行、发送私信与敏感词过滤等功能
-- 点赞、关注与系统通知功能
+- 发布帖子、评论帖子、热帖排行、发送私信与敏感词过滤等功能 done
+- 点赞、关注与系统通知功能 done
 - 全局搜索帖子信息的功能
+- 上传和下载apk
+- 爬取Fdroid的APP图标和信息介绍
+- 提供实时的热门app榜单
+- 构建fdroid app构建流水线
+- 开发者配置riscv的app构建文件,实现负载均衡模块,执行构建流水线,实时展示构建日志,kafka异步发送邮件通知构建完成
 
 ## 核心功能实现
 
@@ -21,6 +26,7 @@
 - 使用Kafka作为消息队列,实现系统通知和解耦
 
 ## TODO
+- 爬取Fdroid的APP图标和信息介绍
 - 使用布隆过滤器屏蔽拉黑的ip下载应用
 - 使用Redis实现一致性哈希算法,使用Redis的ZSet实现用户综合评分
 - 使用kafka收集用户下载app量,使用kafka解耦构建流水线,当流水线构建完毕时通过kafka将消息通知到邮箱
@@ -28,7 +34,7 @@
 - 加快下载速度,断点续传
 - Redis的HyperLogLog存储每日UV、Bitmap存储DAU,实现网站数据统计
 - 使用Elasticsearch + IK分词插件实现全局搜索功能
-- 使用分布式定时任务Quartz定时计算帖子分数,实现热帖排行
+- 使用分布式定时任务Quartz定时计算或者XXL-job计算APP热度,实现热门APP排行
 - Caffeine本地缓存 + Redis分布式缓存的多级缓存,提高服务器性能
 
 ## 评论点赞设计

+ 24 - 0
src/main/java/cn/seecoder/fdroidrepository/Controller/DataController.java

@@ -0,0 +1,24 @@
+package cn.seecoder.fdroidrepository.Controller;
+
+
+import cn.seecoder.fdroidrepository.Service.ServiceImpl.DateService;
+import cn.seecoder.fdroidrepository.result.SingleResult;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PostMapping;
+
+import java.util.Date;
+import java.util.Map;
+
+@Controller
+public class DataController {
+    @Autowired
+    private DateService dateService;
+
+
+    @PostMapping("/data/uv")
+    public SingleResult<Map> getUV(@DateTimeFormat(pattern = "yyyy-MM-dd") Date start, @DateTimeFormat(pattern = "yyyy-MM-dd")Date end){
+
+    })
+}

+ 58 - 0
src/main/java/cn/seecoder/fdroidrepository/Service/ServiceImpl/DateService.java

@@ -0,0 +1,58 @@
+package cn.seecoder.fdroidrepository.Service.ServiceImpl;
+
+
+import cn.seecoder.fdroidrepository.utils.RedisUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Service;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+@Service
+public class DateService {
+    @Autowired
+    private RedisTemplate redisTemplate;
+
+    private SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
+
+    public void recordUV(String ip){
+        String redisKey = RedisUtil.getUVKey(df.format(new Date()));
+        redisTemplate.opsForHyperLogLog().add(redisKey,ip);
+    }
+
+    public long calculateUV(Date start,Date end) {
+        if(start==null||end==null){
+            throw new IllegalStateException("params can not be null!");
+        }
+        List<String> keyList = new ArrayList<>();
+        Calendar calendar=Calendar.getInstance();
+        calendar.setTime(start);
+        while (!calendar.getTime().after(end)){
+            String key = RedisUtil.getUVKey(df.format(calendar.getTime()));
+            keyList.add(key);
+            calendar.add(Calendar.DATE,1);
+        }
+        String redisKey = RedisUtil.getUVKey(df.format(start),df.format(end));
+        redisTemplate.opsForHyperLogLog().union(redisKey,keyList.toArray());
+        return redisTemplate.opsForHyperLogLog().size(redisKey);
+    }
+
+    public void recordDAU(int userId){
+        String redisKey = RedisUtil.getDAUKey(df.format(new Date()));
+        redisTemplate.opsForValue().setBit(redisKey,userId,true);
+    }
+
+    public long calculateDAU(Date start ,Date end){
+        if(start==null||end==null){
+            throw new IllegalStateException("params can not be null!");
+        }
+
+
+    }
+}
+
+

+ 15 - 0
src/main/java/cn/seecoder/fdroidrepository/config/WebMvcConfig.java

@@ -0,0 +1,15 @@
+package cn.seecoder.fdroidrepository.config;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+public class WebMvcConfig implements WebMvcConfigurer {
+
+    @Autowired
+    private DataInterceptor dataInterceptor;
+
+
+}

+ 12 - 0
src/main/java/cn/seecoder/fdroidrepository/utils/RedisUtil.java

@@ -14,4 +14,16 @@ public class RedisUtil {
     public static String getFollowerKey(String userId){
         return "followers"+REDIS_SPLIT_KEY+userId;
     }
+
+    public static String getUVKey(String time){
+        return "uv"+REDIS_SPLIT_KEY+time;
+    }
+
+    public static String getUVKey(String start,String end){
+        return "uv"+REDIS_SPLIT_KEY+start+REDIS_SPLIT_KEY+end;
+    }
+
+    public static String getDAUKey(String time){
+        return "dau"+REDIS_SPLIT_KEY+time;
+    }
 }