Sfoglia il codice sorgente

添加报表功能, 加入定时器

wuweihao 2 anni fa
parent
commit
7f5e8a3ac4

+ 2 - 0
720yun_fd_manage/gis_application/src/main/java/com/gis/GisApplication.java

@@ -2,7 +2,9 @@ package com.gis;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
+@EnableScheduling
 @SpringBootApplication
 public class GisApplication {
 

+ 41 - 0
720yun_fd_manage/gis_domain/src/main/java/com/gis/domain/entity/ReportEntity.java

@@ -0,0 +1,41 @@
+package com.gis.domain.entity;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import java.io.Serializable;
+import java.time.LocalDate;
+
+/**
+ * 作品表
+ */
+@Data
+@Entity
+@Table(name = "tb_report")
+public class ReportEntity extends BaseEntity implements Serializable {
+
+    private static final long serialVersionUID = 220679941563701980L;
+    @ApiModelProperty(value = "类型: work:作品 | user:用户 | volume:容量")
+    private String type;
+
+    @ApiModelProperty(value = "日期")
+    private LocalDate day;
+
+    @ApiModelProperty(value = "全景作品数量-pano")
+    private Integer pano;
+
+    @ApiModelProperty(value = "全景作品数量-4dkk")
+    private Integer age;
+
+    @ApiModelProperty(value = "全景作品数量-mix")
+    private Integer mix;
+
+    @ApiModelProperty(value = "全景作品数量-mix")
+    private Integer total;
+
+
+
+
+}

+ 3 - 29
720yun_fd_manage/gis_domain/src/main/java/com/gis/domain/entity/WorkEntity.java

@@ -39,26 +39,6 @@ public class WorkEntity extends BaseStrEntity implements Serializable {
     @ApiModelProperty(value = "作品密码, 默认0:不需要密码")
     private String password;
 
-//    @ApiModelProperty(value = "PC端提示语")
-//    private String pcIcon;
-//
-//    @ApiModelProperty(value = "移动端提示语")
-//    private String appIcon;
-//
-//    @ApiModelProperty(value = "提醒开关:0:不提醒, 1:提醒")
-//    private Integer isRemind;
-//
-//    @ApiModelProperty(value = "提醒时间,单位秒")
-//    private Integer remindTime;
-
-//    @ApiModelProperty(value = "自定义logo")
-//    private String logo;
-
-//    @ApiModelProperty(value = "显示logo, 0:关,1:开")
-//    private Integer isLogo;
-//
-//    @ApiModelProperty(value = "自动巡游, 0:关,1:开")
-//    private Integer isAuto;
 
     @ApiModelProperty(value = "二维码")
     private String qrCode;
@@ -66,9 +46,6 @@ public class WorkEntity extends BaseStrEntity implements Serializable {
     @ApiModelProperty(value = "分享地址(二维码扫描后地址)")
     private String share;
 
-//    @ApiModelProperty(value = "初始场景id(场景id)")
-//    private String sceneIndex;
-
     @ApiModelProperty(value = "是否有密码,0:没有, 1:有")
     private Integer isPassword;
 
@@ -76,12 +53,9 @@ public class WorkEntity extends BaseStrEntity implements Serializable {
     @ApiModelProperty(value = "场景码")
     private String sceneCodes;
 
-/**********************************************************/
-//    @ApiModelProperty(value = "someData OSS路径")
-//    private String ossSomeData;
+    @ApiModelProperty(value = "作品类型:pano:全是全景图 | 4dkk: 全是四维看看 : mix:混合(pano+4dkk), 通过sceneCodes判断")
+    private String type;
+
 
-    /** 用来关联删除素材时使用*/
-//    @ApiModelProperty(value = "场景码")
-//    private String scenes;
 
 }

+ 3 - 0
720yun_fd_manage/gis_mapper/src/main/java/com/gis/mapper/FodderMapper.java

@@ -44,4 +44,7 @@ public interface FodderMapper extends IBaseMapper<FodderEntity, Long> {
 
     @SelectProvider(type = BaseProvider.class, method = "selectSql")
     List<String> getListStr(String strSql);
+
+    @Select("select sum(file_size) from tb_fodder where is_delete=0")
+    String countSize();
 }

+ 14 - 0
720yun_fd_manage/gis_mapper/src/main/java/com/gis/mapper/ReportMapper.java

@@ -0,0 +1,14 @@
+package com.gis.mapper;
+
+
+import com.gis.domain.entity.ReportEntity;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Component;
+
+
+@Component
+@Mapper
+public interface ReportMapper extends IBaseMapper<ReportEntity, Long> {
+
+
+}

+ 2 - 0
720yun_fd_manage/gis_service/src/main/java/com/gis/service/FodderService.java

@@ -43,4 +43,6 @@ public interface FodderService extends IBaseService<FodderEntity, Long> {
     void updateDirId(Long parentId, String fodderIds);
 
     List<String> getSceneCodeByParentIds(String dirs);
+
+    Integer getVolume(String unit);
 }

+ 14 - 0
720yun_fd_manage/gis_service/src/main/java/com/gis/service/ReportService.java

@@ -0,0 +1,14 @@
+package com.gis.service;
+
+import com.gis.common.util.Result;
+import com.gis.domain.dto.DirDto;
+import com.gis.domain.dto.DirMoveDto;
+import com.gis.domain.entity.DirEntity;
+import com.gis.domain.entity.ReportEntity;
+
+/**
+ * Created by owen on 2022/12/1 0001 15:22
+ */
+public interface ReportService extends IBaseService<ReportEntity, Long>{
+
+}

+ 43 - 24
720yun_fd_manage/gis_service/src/main/java/com/gis/service/impl/FodderServiceImpl.java

@@ -25,6 +25,7 @@ import com.gis.service.WorkService;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.junit.Test;
 import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -33,6 +34,8 @@ import org.springframework.web.multipart.MultipartFile;
 import tk.mybatis.mapper.entity.Condition;
 
 import javax.transaction.Transactional;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
 
 
@@ -370,30 +373,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
         return Result.success(size);
     }
 
-//    @Override
-//    public Result listAndDir(FodderPageDto param) {
-//
-//        // 目录数据
-//        List<FodderEntity> dirs = findDirAndConvertEntity(param);
-//
-//        startPage(param);
-//
-//        List<FodderEntity> list = myMapperFindAll(param);
-//        list.addAll(0, dirs); // 加到队列最前面
-//
-////        page.addAll(list);
-////        Page<FodderEntity> page = PageHelper.startPage(param.getPageNum(), param.getPageSize());
-//
-//
-//
-//        PageInfo<FodderEntity> pageInfo = new PageInfo<>(list);
-//        log.info("size:{}, dirSize:{}", pageInfo.getSize(), dirs.size());
-//        pageInfo.setPageSize(pageInfo.getSize() + dirs.size());
-//
-//
-//
-//        return Result.success(pageInfo);
-//    }
+
 
 
     @Override
@@ -482,6 +462,45 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
     }
 
 
+    /**
+     * 获取素材占用空容量
+     * @param unit 默认KB
+     * @return
+     */
+    @Override
+    public Integer getVolume(String unit) {
+        String volume = entityMapper.countSize();
+        BigDecimal decimal = new BigDecimal(volume);
+        if ("KB".equals(unit) || StrUtil.isBlank(unit)){
+            log.info("KB: {}", volume);
+        } else if ("MB".equals(unit)){
+            decimal = decimal.divide(new BigDecimal("1024"),  BigDecimal.ROUND_HALF_UP);
+            log.info("MB: {}", decimal.toString());
+        } else if ("GB".equals(unit)){
+            decimal = decimal.divide(new BigDecimal("1024"),  BigDecimal.ROUND_HALF_UP);
+            log.info("GB: {}", decimal);
+        }
+        return Integer.valueOf(decimal.toString());
+    }
+
+    @Test
+    public void testVolume(){
+        String volume = "10250";
+        String unit = "GB";
+        BigDecimal decimal = new BigDecimal(volume);
+        if ("KB".equals(unit) || StrUtil.isBlank(unit)){
+            log.info("KB: {}", volume);
+        } else if ("MB".equals(unit)){
+            decimal = decimal.divide(new BigDecimal("1024"),  BigDecimal.ROUND_HALF_UP);
+            log.info("MB: {}", decimal.toString());
+        } else if ("GB".equals(unit)){
+            decimal = decimal.divide(new BigDecimal("1024"),  BigDecimal.ROUND_HALF_UP);
+            log.info("GB: {}", decimal);
+        }
+
+    }
+
+
     private List<FodderEntity> myMapperFindAll(FodderPageDto param){
         StringBuilder builder = new StringBuilder();
         builder.append("select a.*, b.name as dirName from tb_fodder a left join tb_dir b on b.id=a.dir_id where a.is_delete=0");

+ 37 - 0
720yun_fd_manage/gis_service/src/main/java/com/gis/service/impl/ReportServiceImpl.java

@@ -0,0 +1,37 @@
+package com.gis.service.impl;
+
+import com.gis.domain.entity.ReportEntity;
+import com.gis.mapper.IBaseMapper;
+import com.gis.mapper.ReportMapper;
+import com.gis.service.FodderService;
+import com.gis.service.ReportService;
+import com.gis.service.WorkService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+
+/**
+ * Created by owen on 2022/12/1 0001 15:23
+ */
+@Slf4j
+@Service
+public class ReportServiceImpl extends IBaseServiceImpl<ReportEntity, Long> implements ReportService {
+
+    @Autowired
+    ReportMapper entityMapper;
+
+    @Autowired
+    FodderService fodderService;
+
+    @Autowired
+    WorkService workService;
+
+    @Override
+    public IBaseMapper<ReportEntity, Long> getBaseMapper() {
+        return this.entityMapper;
+    }
+
+
+
+}

+ 36 - 1
720yun_fd_manage/gis_service/src/main/java/com/gis/service/impl/WorkServiceImpl.java

@@ -380,7 +380,11 @@ public class WorkServiceImpl extends IBaseStrServiceImpl<WorkEntity, String> imp
         }
 
         String scenes = someDataJson.getString("scenes");
-        entity.setSceneCodes(getSceneCodes(scenes));
+        String sceneCodes = getSceneCodes(scenes);
+        entity.setSceneCodes(sceneCodes);
+        // 2022-12-19 作品类型
+        String type = getTypeBySceneCodes(sceneCodes);
+        entity.setType(type);
         // 更新logoQrCode
         Boolean logoChange = someDataJson.getBoolean("logoChange");
         String logoUrl = someDataJson.getString("logo");
@@ -422,6 +426,37 @@ public class WorkServiceImpl extends IBaseStrServiceImpl<WorkEntity, String> imp
     }
 
     /**
+     * 2022-12-19
+     * 获取作品类型
+     * @param sceneCodes 场景码集合
+     * @return
+     */
+    private String getTypeBySceneCodes(String sceneCodes){
+        String type = "0"; // 默认值
+        if (StrUtil.isBlank(sceneCodes)){
+            return type;
+        }
+        List<String> list = StrUtil.splitTrim(sceneCodes, ",");
+        boolean isPano = false;
+        boolean is4dkk = false;
+        for (String s : list) {
+            if (s.startsWith("fd720_")){
+                type = "pano";
+                isPano = true;
+            } else {
+                type = "4dkk";
+                is4dkk = true;
+            }
+        }
+        if (isPano && is4dkk){ // 同时满足:mix:混合类型
+            type = "mix";
+        }
+        log.info("当前作品类型为:{}", type);
+        return type;
+
+    }
+
+    /**
      * 场景码字符串转list
      * @param param
      * @return

+ 142 - 0
720yun_fd_manage/gis_service/src/main/java/com/gis/task/VisitTask.java

@@ -0,0 +1,142 @@
+package com.gis.task;
+
+import cn.hutool.core.util.StrUtil;
+import com.gis.common.util.RedisUtil;
+import com.gis.domain.entity.ReportEntity;
+import com.gis.service.FodderService;
+import com.gis.service.ReportService;
+import com.gis.service.WorkService;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDate;
+import java.util.List;
+
+/**
+ * Created by owen on 2022/11/9 0009 16:42
+ * 定时器
+ */
+@Slf4j
+@Component
+public class VisitTask {
+
+    @Autowired
+    RedisUtil redisUtil;
+
+    @Autowired
+    ReportService reportService;
+
+    @Autowired
+    WorkService workService;
+
+    @Autowired
+    FodderService fodderService;
+
+    /**
+     * 需要在启动类加入注解
+     * 每天24点检查未开始的活动
+     * 每天24点执行一次  @Scheduled(cron=" 0 0 0 * * ? ") @Scheduled(cron=" * 1  * * ? ")
+     *
+     * Scheduled(cron=" 10 0/5 * * * ? ")   //每五分钟执行一次
+     * Scheduled(cron = "0 0 3 * * ?") 每天凌晨三点
+     */
+    @Scheduled(cron = "0 0 2 * * ?")
+    public void task() {
+
+        log.warn("每天02:00开始执行定时任务:redis访问量数据同步到数据库");
+        try {
+
+            // 当前时间的前一天
+            LocalDate yesterday = LocalDate.now().plusDays(-1);
+            // 更新容量到数据库
+            addVolume(yesterday);
+
+            log.warn("执行完成定时任务:redis访问量数据同步到数据库");
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+    }
+
+
+//    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);
+//            }
+//        }
+//
+//    }
+
+    /**
+     * 保存当天的素材容量
+     * @param today
+     */
+    private void addVolume(LocalDate today){
+
+        Integer volume = fodderService.getVolume("GB");
+        ReportEntity entity = new ReportEntity();
+        entity.setType("volume");
+        entity.setTotal(volume); // 容量是GB
+        entity.setDay(today);
+        reportService.save(entity);
+        log.info("保存容量完成, 当前容量:{} GB", volume);
+
+    }
+
+    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);
+
+    }
+
+    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;
+    }
+
+    @Test
+    public void test(){
+        String a = "1";
+        String[] split = a.split(",");
+        System.out.println();
+    }
+}