Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
7eb7cb82
Commit
7eb7cb82
authored
Aug 06, 2021
by
张辰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rank log 定时移除
parent
37ea56f1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
36 deletions
+26
-36
FileTypeEnum.java
...main/java/com/tanpu/community/api/enums/FileTypeEnum.java
+1
-1
OSSFileService.java
...main/java/com/tanpu/community/service/OSSFileService.java
+23
-33
RankLogService.java
...main/java/com/tanpu/community/service/RankLogService.java
+2
-2
No files found.
community-api/src/main/java/com/tanpu/community/api/enums/FileTypeEnum.java
View file @
7eb7cb82
...
@@ -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
;
...
...
community-service/src/main/java/com/tanpu/community/service/OSSFileService.java
View file @
7eb7cb82
...
@@ -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
)
{
...
...
community-service/src/main/java/com/tanpu/community/service/RankLogService.java
View file @
7eb7cb82
...
@@ -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
).
get
Create
Time
().
isAfter
(
t
))
{
if
(
logs
.
isEmpty
()
||
logs
.
get
(
0
).
get
Rank
Time
().
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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment