Commit 7eb7cb82 authored by 张辰's avatar 张辰

rank log 定时移除

parent 37ea56f1
...@@ -9,7 +9,7 @@ public enum FileTypeEnum { ...@@ -9,7 +9,7 @@ public enum FileTypeEnum {
IMAGE(1,"图片类型"),QUERY_IDOLS(2,"查询关注"); IMAGE(1,"图片类型"),QUERY_IDOLS(2,"查询关注");
public static final HashSet<String> imageTypeSet = SetUtils.hashSet("jpg", "jpeg", "png"); public static final HashSet<String> ossTypeSet = SetUtils.hashSet("jpg", "jpeg", "png", "txt");
private Integer code; private Integer code;
private String type; private String type;
......
...@@ -8,7 +8,6 @@ import com.tanpu.common.util.JsonUtil; ...@@ -8,7 +8,6 @@ import com.tanpu.common.util.JsonUtil;
import com.tanpu.common.uuid.UuidGenHelper; import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.CommunityConstant; import com.tanpu.community.api.CommunityConstant;
import com.tanpu.community.api.enums.FileTypeEnum; import com.tanpu.community.api.enums.FileTypeEnum;
import com.tanpu.community.api.enums.OssRelType;
import com.tanpu.community.dao.entity.community.FileRecordEntity; import com.tanpu.community.dao.entity.community.FileRecordEntity;
import com.tanpu.community.dao.mapper.community.FileRecordMapper; import com.tanpu.community.dao.mapper.community.FileRecordMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -67,43 +66,34 @@ public class OSSFileService { ...@@ -67,43 +66,34 @@ public class OSSFileService {
public FileRecordEntity uploadFile(byte[] data, String fileName, String fileSuffix, String dirPrefix) { public FileRecordEntity uploadFile(byte[] data, String fileName, String fileSuffix, String dirPrefix) {
String[] arr = StringUtils.split(fileName, "."); String[] arr = StringUtils.split(fileName, ".");
String suffix = arr[arr.length - 1]; String suffix = arr[arr.length - 1];
if (FileTypeEnum.imageTypeSet.contains(suffix)) { //上传
//上传 String id = uuidGenHelper.getUuidStr();
String id = uuidGenHelper.getUuidStr(); String key = CommunityConstant.OSS_PREFIX_FOLDER + dirPrefix + id + "." + suffix;
String key = CommunityConstant.OSS_PREFIX_FOLDER + dirPrefix + id + "." + suffix; ossHelper.writeFile(bucketName, key, data, fileSuffix);
ossHelper.writeFile(bucketName, key, data, fileSuffix);
//落库
//落库 FileRecordEntity record = new FileRecordEntity();
FileRecordEntity record = new FileRecordEntity(); record.setFileId(uuidGenHelper.getUuidStr());
record.setFileId(uuidGenHelper.getUuidStr()); record.setDeleteTag(BizStatus.DeleteTag.tag_init);
record.setDeleteTag(BizStatus.DeleteTag.tag_init); record.setFileOssKey(key);
record.setFileOssKey(key); record.setFileName(fileName);
record.setFileName(fileName); record.setFileId(id);
record.setFileId(id); record.setPreviewUrl(ossHelper.getPreSignedUrl(bucketName, key));
record.setPreviewUrl(ossHelper.getPreSignedUrl(bucketName, key)); record.setFileType(FileTypeEnum.IMAGE.getCode());
record.setFileType(FileTypeEnum.IMAGE.getCode()); HashMap<String, Integer> attr = getStringIntegerHashMap(data);
HashMap<String, Integer> attr = getStringIntegerHashMap(data); record.setExtInfo(JsonUtil.toJson(attr));
record.setExtInfo(JsonUtil.toJson(attr));
fileRecordMapper.insert(record);
fileRecordMapper.insert(record);
return record;
return record;
}else {
throw new BizException("文件格式暂不支持:"+suffix);
}
} }
public void uploadFileNoRecord(byte[] data, String fileName, String fileSuffix, String dirPrefix) { public void uploadFileNoRecord(byte[] data, String fileName, String fileSuffix, String dirPrefix) {
String[] arr = StringUtils.split(fileName, "."); String[] arr = StringUtils.split(fileName, ".");
String suffix = arr[arr.length - 1]; String suffix = arr[arr.length - 1];
if (FileTypeEnum.imageTypeSet.contains(suffix)) { //上传
//上传 String key = CommunityConstant.OSS_PREFIX_FOLDER + dirPrefix + suffix;
String id = uuidGenHelper.getUuidStr(); ossHelper.writeFile(bucketName, key, data, fileSuffix);
String key = CommunityConstant.OSS_PREFIX_FOLDER + dirPrefix + id + "." + suffix;
ossHelper.writeFile(bucketName, key, data, fileSuffix);
}else {
throw new BizException("文件格式暂不支持:"+suffix);
}
} }
private HashMap<String, Integer> getStringIntegerHashMap(byte[] data) { private HashMap<String, Integer> getStringIntegerHashMap(byte[] data) {
......
...@@ -101,7 +101,7 @@ public class RankLogService { ...@@ -101,7 +101,7 @@ public class RankLogService {
int idx = 0; int idx = 0;
while (true) { while (true) {
List<RankLogEntity> logs = rankLogMapper.selectByTypeLimit(type.getCode(), 50); List<RankLogEntity> logs = rankLogMapper.selectByTypeLimit(type.getCode(), 50);
if (logs.isEmpty() || logs.get(0).getCreateTime().isAfter(t)) { if (logs.isEmpty() || logs.get(0).getRankTime().isAfter(t)) {
break; break;
} }
...@@ -109,7 +109,7 @@ public class RankLogService { ...@@ -109,7 +109,7 @@ public class RankLogService {
String fileName = "ranklog_" + type.getCode() + "_" + t.format(DateTimeFormatter.BASIC_ISO_DATE) + "_" + idx; String fileName = "ranklog_" + type.getCode() + "_" + t.format(DateTimeFormatter.BASIC_ISO_DATE) + "_" + idx;
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
IOUtils.writeLines(logs.stream().map(JSON::toJSONString).collect(Collectors.toList()), null, os); IOUtils.writeLines(logs.stream().map(JSON::toJSONString).collect(Collectors.toList()), null, os);
ossFileService.uploadFileNoRecord(os.toByteArray(), fileName, "txt", "rankLog/"); ossFileService.uploadFileNoRecord(os.toByteArray(), fileName, ".txt", "rankLog/");
Thread.sleep(1000); Thread.sleep(1000);
} catch (Exception e) { } catch (Exception e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment