|
@@ -1,8 +1,10 @@
|
|
package com.gis.task;
|
|
package com.gis.task;
|
|
|
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
|
+import com.gis.common.constant.RedisConstant;
|
|
import com.gis.common.util.RedisUtil;
|
|
import com.gis.common.util.RedisUtil;
|
|
import com.gis.domain.entity.ReportEntity;
|
|
import com.gis.domain.entity.ReportEntity;
|
|
|
|
+import com.gis.oss.util.FileUtils;
|
|
import com.gis.service.FodderService;
|
|
import com.gis.service.FodderService;
|
|
import com.gis.service.ReportService;
|
|
import com.gis.service.ReportService;
|
|
import com.gis.service.WorkService;
|
|
import com.gis.service.WorkService;
|
|
@@ -13,7 +15,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Created by owen on 2022/11/9 0009 16:42
|
|
* Created by owen on 2022/11/9 0009 16:42
|
|
@@ -35,6 +37,7 @@ public class VisitTask {
|
|
@Autowired
|
|
@Autowired
|
|
FodderService fodderService;
|
|
FodderService fodderService;
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 需要在启动类加入注解
|
|
* 需要在启动类加入注解
|
|
* 每天24点检查未开始的活动
|
|
* 每天24点检查未开始的活动
|
|
@@ -52,7 +55,15 @@ public class VisitTask {
|
|
// 当前时间的前一天
|
|
// 当前时间的前一天
|
|
LocalDate yesterday = LocalDate.now().plusDays(-1);
|
|
LocalDate yesterday = LocalDate.now().plusDays(-1);
|
|
// 更新容量到数据库
|
|
// 更新容量到数据库
|
|
|
|
+ allVolume(yesterday);
|
|
|
|
+ // 更新登陆趋势
|
|
|
|
+ allUser(yesterday);
|
|
|
|
+ // 更新作品信息
|
|
|
|
+ allWork(yesterday);
|
|
|
|
+
|
|
|
|
+ // 新增部分
|
|
addVolume(yesterday);
|
|
addVolume(yesterday);
|
|
|
|
+ addWork(yesterday);
|
|
|
|
|
|
log.warn("执行完成定时任务:redis访问量数据同步到数据库");
|
|
log.warn("执行完成定时任务:redis访问量数据同步到数据库");
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -62,77 +73,115 @@ public class VisitTask {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-// private void visitUpdateToDb(){
|
|
|
|
-// // 当前时间的前一天
|
|
|
|
-// String yesterday = LocalDate.now().plusDays(-1).toString();
|
|
|
|
-//
|
|
|
|
-// List<ProjectEntity> list = projectService.list();
|
|
|
|
-// // String key = now + "_" + type + "_" + projectId + "_" + moduleType;
|
|
|
|
-// VisitEntity visitEntity = null;
|
|
|
|
-// // 每个项目
|
|
|
|
-// for (ProjectEntity entity : list) {
|
|
|
|
-// Long projectId = entity.getId();
|
|
|
|
-// String visitType = entity.getVisitType();
|
|
|
|
-// if (StrUtil.isBlank(visitType)){
|
|
|
|
-// log.error("项目visitType为空结束本次循环, 项目id : {}", projectId);
|
|
|
|
-// continue;
|
|
|
|
-// }
|
|
|
|
-// String[] split = visitType.split(",");
|
|
|
|
-// // 每个类型
|
|
|
|
-// for (String type : split) {
|
|
|
|
-// String visitKey = yesterday + "_visit_" + projectId + "_" + type;
|
|
|
|
-// visitEntity = new VisitEntity();
|
|
|
|
-// visitEntity.setToday(yesterday);
|
|
|
|
-// visitEntity.setModuleType(type);
|
|
|
|
-// visitEntity.setPcsVisit(getRedisValue(visitKey));
|
|
|
|
-// visitEntity.setProjectId(projectId);
|
|
|
|
-// // visitEntity.setPcsStar(pcsStar);
|
|
|
|
-//
|
|
|
|
-// visitService.save(visitEntity);
|
|
|
|
-//
|
|
|
|
-// // 删除过期key
|
|
|
|
-// redisUtil.delete(visitKey);
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
|
|
+
|
|
|
|
+ private void addVolume(LocalDate today) {
|
|
|
|
+ int volume = fodderService.getTodaySize(today, "GB");
|
|
|
|
+ ReportEntity entity = new ReportEntity();
|
|
|
|
+ entity.setType("volume");
|
|
|
|
+ entity.setTotal(volume); // 容量是GB
|
|
|
|
+ entity.setDay(today);
|
|
|
|
+ entity.setInfoType("add");
|
|
|
|
+ reportService.save(entity);
|
|
|
|
+ log.info("保存容量完成, 当前容量:{} GB", volume);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存当天登陆用户数据
|
|
|
|
+ * @param today
|
|
|
|
+ */
|
|
|
|
+ private void allUser(LocalDate today) {
|
|
|
|
+ String key = RedisConstant.REPORT_USER + today;
|
|
|
|
+ Integer count = (Integer)redisUtil.get(key);
|
|
|
|
+ if (count == null){
|
|
|
|
+ count = 0;
|
|
|
|
+ log.error("当天用户登录次数:{} 请检查数据是否正确", count);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ReportEntity entity = new ReportEntity();
|
|
|
|
+ entity.setType("user");
|
|
|
|
+ entity.setTotal(count); // 容量是GB
|
|
|
|
+ entity.setDay(today);
|
|
|
|
+ reportService.save(entity);
|
|
|
|
+ log.info("保存用户上线数据完成, 当前数量:{} ", count);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 保存当天的素材容量
|
|
* 保存当天的素材容量
|
|
* @param today
|
|
* @param today
|
|
*/
|
|
*/
|
|
- private void addVolume(LocalDate today){
|
|
|
|
|
|
+ private void allVolume(LocalDate today){
|
|
|
|
|
|
Integer volume = fodderService.getVolume("GB");
|
|
Integer volume = fodderService.getVolume("GB");
|
|
ReportEntity entity = new ReportEntity();
|
|
ReportEntity entity = new ReportEntity();
|
|
entity.setType("volume");
|
|
entity.setType("volume");
|
|
entity.setTotal(volume); // 容量是GB
|
|
entity.setTotal(volume); // 容量是GB
|
|
entity.setDay(today);
|
|
entity.setDay(today);
|
|
|
|
+ entity.setInfoType("all");
|
|
reportService.save(entity);
|
|
reportService.save(entity);
|
|
log.info("保存容量完成, 当前容量:{} GB", volume);
|
|
log.info("保存容量完成, 当前容量:{} GB", volume);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 保存当天的作品数量
|
|
|
|
+ * @param today
|
|
|
|
+ */
|
|
|
|
+ private void allWork(LocalDate today){
|
|
|
|
+
|
|
|
|
+ Map res = workService.countByType(null);
|
|
|
|
+ Integer mix = convert((Integer)res.get("mix")) ;
|
|
|
|
+ Integer age = convert((Integer)res.get("4dkk")) ;
|
|
|
|
+ Integer pano = convert((Integer)res.get("pano")) ;
|
|
|
|
+
|
|
|
|
+ ReportEntity entity = new ReportEntity();
|
|
|
|
+ entity.setType("work");
|
|
|
|
+ entity.setAge(age);
|
|
|
|
+ entity.setMix(mix);
|
|
|
|
+ entity.setPano(pano);
|
|
|
|
+ int total = mix + age + pano;
|
|
|
|
+ entity.setTotal(total); // 容量是GB
|
|
|
|
+ entity.setDay(today);
|
|
|
|
+ entity.setInfoType("all");
|
|
|
|
+ reportService.save(entity);
|
|
|
|
+ log.info("保存作品完成, 当前作品数量:{} ", total);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
private void addWork(LocalDate today){
|
|
private void addWork(LocalDate today){
|
|
|
|
|
|
-// workService.countByType();
|
|
|
|
-// ReportEntity entity = new ReportEntity();
|
|
|
|
-// entity.setType("work");
|
|
|
|
-// entity.setTotal(volume); // 容量是GB
|
|
|
|
-// entity.setDay(today);
|
|
|
|
-// reportService.save(entity);
|
|
|
|
-// log.info("保存容量完成, 当前容量:{} GB", volume);
|
|
|
|
|
|
+ Map res = workService.countByType(today);
|
|
|
|
+ Integer mix = convert((Integer)res.get("mix")) ;
|
|
|
|
+ Integer age = convert((Integer)res.get("4dkk")) ;
|
|
|
|
+ Integer pano = convert((Integer)res.get("pano")) ;
|
|
|
|
+
|
|
|
|
+ ReportEntity entity = new ReportEntity();
|
|
|
|
+ entity.setType("work");
|
|
|
|
+ entity.setAge(age);
|
|
|
|
+ entity.setMix(mix);
|
|
|
|
+ entity.setPano(pano);
|
|
|
|
+ int total = mix + age + pano;
|
|
|
|
+ entity.setTotal(total); // 容量是GB
|
|
|
|
+ entity.setDay(today);
|
|
|
|
+ entity.setInfoType("add");
|
|
|
|
+ reportService.save(entity);
|
|
|
|
+ log.info("保存作品完成, 当前作品数量:{} ", total);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private int getRedisValue(String key){
|
|
|
|
- log.info("redis key: {}", key);
|
|
|
|
- Integer pcsVisit = (Integer)redisUtil.get(key);
|
|
|
|
- pcsVisit = pcsVisit == null ? 0 : pcsVisit;
|
|
|
|
- log.info("{} 的数据:{}", key, pcsVisit);
|
|
|
|
- return pcsVisit;
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private Integer convert(Integer num){
|
|
|
|
+ return num == null ? 0 : num;
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void test(){
|
|
public void test(){
|
|
String a = "1";
|
|
String a = "1";
|