|
|
@@ -3,12 +3,18 @@ package com.gz.service.statistics.impl;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUnit;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.lang.tree.Tree;
|
|
|
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
|
|
import cn.hutool.core.lang.tree.TreeUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.ReUtil;
|
|
|
+import cn.hutool.core.util.RuntimeUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.gz.common.DataGlobalVariable;
|
|
|
+import com.gz.core.exception.BusinessException;
|
|
|
import com.gz.dto.borrow.ArchiveBorrowDTO;
|
|
|
import com.gz.dto.system.ArchivesTreeDTO;
|
|
|
import com.gz.mapper.borrow.ArchiveBorrowMapper;
|
|
|
@@ -19,12 +25,15 @@ import com.gz.rvo.statistics.ArchiveYearStatisticsRVO;
|
|
|
import com.gz.rvo.statistics.BorrowStatisticsRVO;
|
|
|
import com.gz.service.statistics.SelectStatisticsService;
|
|
|
import com.gz.service.system.ArchivesTreeService;
|
|
|
+import com.gz.service.system.impl.AuthServiceImpl;
|
|
|
import com.gz.utils.JwtUtils;
|
|
|
import com.gz.vo.statistics.StatisticsVO;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.Data;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.mybatis.spring.annotation.MapperScan;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -32,6 +41,8 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.persistence.Id;
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -44,6 +55,7 @@ import java.util.stream.Collectors;
|
|
|
* @author LiuchangLan
|
|
|
* @date 2021/3/8 14:59
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class SelectStatisticsServiceImpl implements SelectStatisticsService {
|
|
|
|
|
|
@@ -59,10 +71,13 @@ public class SelectStatisticsServiceImpl implements SelectStatisticsService {
|
|
|
@Resource
|
|
|
private ArchiveBorrowMapper archiveBorrowMapper;
|
|
|
|
|
|
+ @Value("${upload-file.archive-file-root-directory}")
|
|
|
+ private String baseDir;
|
|
|
+
|
|
|
@Override
|
|
|
public List<ArchiveStatisticsRVO> selectStatisticsByType(StatisticsVO vo) {
|
|
|
String key = String.format(DataGlobalVariable.CACHE_KEY_FOMAT, this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName(), JSONObject.toJSONString(vo));
|
|
|
- if (stringRedisTemplate.hasKey(key)) {
|
|
|
+ if (false) {
|
|
|
return JSONArray.parseArray(stringRedisTemplate.opsForValue().get(key), ArchiveStatisticsRVO.class);
|
|
|
} else {
|
|
|
if (vo.getMl() != null) {
|
|
|
@@ -74,6 +89,59 @@ public class SelectStatisticsServiceImpl implements SelectStatisticsService {
|
|
|
}
|
|
|
// 统计结果
|
|
|
List<ArchiveStatisticsRVO> tree = selectStatisticsMapper.selectArchiveStatistics(vo);
|
|
|
+ //二级分类集合
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ List<ArchivesTreeDTO> archivesTreeDTOS = archivesTreeService.selectByOrder();
|
|
|
+ archivesTreeDTOS.forEach(dto -> {
|
|
|
+ if (dto.getParentId() != -1) {
|
|
|
+ for (ArchivesTreeDTO dt : archivesTreeDTOS) {
|
|
|
+ if (dto.getParentId() == dt.getId()) {
|
|
|
+ list.add(dt.getTitle());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //占用磁盘大小临时存储到map
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ // 档案文件根目录
|
|
|
+ File baseDir = FileUtil.file(this.baseDir);
|
|
|
+ if (FileUtil.exist(baseDir) && FileUtil.isDirectory(baseDir)) {
|
|
|
+ // 全宗号
|
|
|
+ for (File qzh : baseDir.listFiles()) {
|
|
|
+ if (FileUtil.isDirectory(qzh)) {
|
|
|
+ // 年份
|
|
|
+ for (File year : qzh.listFiles()) {
|
|
|
+ if (ObjectUtil.isNotEmpty(year)) {
|
|
|
+ //分类
|
|
|
+ for (File category : year.listFiles()) {
|
|
|
+ if (ObjectUtil.isNotEmpty(category)) {
|
|
|
+ if (list.contains(category.getName())) {
|
|
|
+ //二级分类
|
|
|
+ for (File category2 : category.listFiles()) {
|
|
|
+ if (ObjectUtil.isNotEmpty(category2)) {
|
|
|
+ String s1 = this.getLinuxDirectorySize(category);
|
|
|
+ map.put(category.getName(), s1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String s2 = this.getLinuxDirectorySize(category);
|
|
|
+ map.put(category.getName(), s2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //内存大小赋值
|
|
|
+ for (Map.Entry<String, String> entry : map.entrySet()) {
|
|
|
+ for (ArchiveStatisticsRVO li : tree) {
|
|
|
+ if (li.getTitle().equals(entry.getKey())) {
|
|
|
+ li.setSpace(entry.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //计算总量
|
|
|
tree.forEach(e -> {
|
|
|
if (e.getParentId() == -1) {
|
|
|
for (ArchiveStatisticsRVO node : tree) {
|
|
|
@@ -107,11 +175,54 @@ public class SelectStatisticsServiceImpl implements SelectStatisticsService {
|
|
|
vo.setEndTime(vo.getTime().split(" - ")[1]);
|
|
|
}
|
|
|
List<ArchiveYearStatisticsRVO> archiveYearStatisticsRVOS = selectStatisticsMapper.selectArchiveYearStatistics(vo);
|
|
|
+ // 档案文件根目录
|
|
|
+ File baseDir = FileUtil.file(this.baseDir);
|
|
|
+ log.info("{}{}", baseDir, baseDir.isDirectory());
|
|
|
+ if (FileUtil.exist(baseDir) && FileUtil.isDirectory(baseDir)) {
|
|
|
+ // 全宗号
|
|
|
+ for (File qzh : baseDir.listFiles()) {
|
|
|
+ if (FileUtil.isDirectory(qzh)) {
|
|
|
+ // 年份
|
|
|
+ for (File year : qzh.listFiles()) {
|
|
|
+ if (ObjectUtil.isNotEmpty(year)) {
|
|
|
+ String linuxDirectorySize = this.getLinuxDirectorySize(year);
|
|
|
+ archiveYearStatisticsRVOS.forEach(statisticsRVO -> {
|
|
|
+ if (statisticsRVO.getGdnd().equals(year.getName())) {
|
|
|
+ statisticsRVO.setSpace(linuxDirectorySize);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
stringRedisTemplate.opsForValue().set(key, JSONObject.toJSONString(archiveYearStatisticsRVOS), DataGlobalVariable.CACHE_EXPIRES, DataGlobalVariable.TIME_UNIT);
|
|
|
return archiveYearStatisticsRVOS;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @description 获取Linux文件夹大小
|
|
|
+ * @author ZhangHai
|
|
|
+ * @since 2021/9/15 11:33
|
|
|
+ */
|
|
|
+ private String getLinuxDirectorySize(File file) {
|
|
|
+ if (!file.exists()) {
|
|
|
+ throw new BusinessException(500, "文件见不存在");
|
|
|
+ }
|
|
|
+ if (!file.isDirectory()) {
|
|
|
+ throw new BusinessException(500, "参数非文件见");
|
|
|
+ }
|
|
|
+ // 执行命令Format
|
|
|
+ final String commandFomat = "du -sh {}";
|
|
|
+ // 需要执行的命令
|
|
|
+ final String command = StrUtil.format(commandFomat, file.getAbsoluteFile());
|
|
|
+ log.info("文件夹大小扫描命令执行:{}", command);
|
|
|
+ // 执行命令的结果
|
|
|
+ String commandResult = RuntimeUtil.execForStr(command);
|
|
|
+ return commandResult.substring(0, commandResult.indexOf(" "));
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<BorrowStatisticsRVO> selectBorrowStatistics(StatisticsVO vo) {
|
|
|
String key = String.format(DataGlobalVariable.CACHE_KEY_FOMAT, this.getClass().getName(), Thread.currentThread().getStackTrace()[1].getMethodName(), JSONObject.toJSONString(vo));
|