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
b05c24c1
Commit
b05c24c1
authored
Aug 18, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图片审核结果记录
parent
9b11bd9b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
52 deletions
+63
-52
CommunityConstant.java
.../main/java/com/tanpu/community/api/CommunityConstant.java
+5
-0
CallBackController.java
...va/com/tanpu/community/controller/CallBackController.java
+6
-4
FileRecordEntity.java
...anpu/community/dao/entity/community/FileRecordEntity.java
+12
-1
FileManager.java
...rc/main/java/com/tanpu/community/manager/FileManager.java
+30
-38
BatchFeignCallService.java
...va/com/tanpu/community/service/BatchFeignCallService.java
+9
-9
FileRecordEntityMapper.xml
...ain/resources/mapper/community/FileRecordEntityMapper.xml
+1
-0
No files found.
community-api/src/main/java/com/tanpu/community/api/CommunityConstant.java
View file @
b05c24c1
...
...
@@ -23,6 +23,11 @@ public final class CommunityConstant {
//图片压缩比例:50%
public
static
final
String
OSS_RESIZE_RATIO
=
"?x-oss-process=image/resize,p_50"
;
// 图片审核不通过的替换默认图片
public
static
final
String
OSS_CHECK_FAIL_DEFAULT
=
"https://tamp-sit.oss-cn-shanghai.aliyuncs.com/community/pic/default/check_fail.png"
;
public
static
final
Integer
OSS_CHECK_FAIL_DEFAULT_WIDTH
=
1035
;
public
static
final
Integer
OSS_CHECK_FAIL_DEFAULT_HEIGHT
=
1115
;
public
static
final
String
THEME_PREFIX
=
"NEW_THEME_"
;
public
static
final
String
OLD_FILE_UPLOAD_URL
=
"http://tp-fatools-svc/fatools/h5/rest/common/uploadSingleFile"
;
...
...
community-service/src/main/java/com/tanpu/community/controller/CallBackController.java
View file @
b05c24c1
...
...
@@ -29,25 +29,27 @@ public class CallBackController {
* 阿里云图片审核回调接口
* 回调时间:6秒以内
* 文档地址:https://help.aliyun.com/document_detail/129946.html?spm=a2c4g.11186623.6.562.19a05f3aNkd2Oo#table-s9e-grd-408
*
* @param checksum
* @param content
* @return
*/
@ApiOperation
(
"oss图片审核回调"
)
@PostMapping
(
value
=
"/picCheck/callback"
)
public
String
picCheck
(
String
checksum
,
String
content
)
{
public
String
picCheck
(
String
checksum
,
String
content
)
{
log
.
info
(
"checksum:{}"
,
checksum
);
Map
<
String
,
Object
>
response
=
JsonUtil
.
toMap
(
content
);
String
fileKey
=
(
String
)
response
.
get
(
"object"
);
boolean
freezed
=
(
boolean
)
response
.
get
(
"freezed"
);
HashMap
<
String
,
Object
>
scanResult
=
(
HashMap
<
String
,
Object
>)
response
.
get
(
"scanResult"
);
HashMap
<
String
,
Object
>
scanResult
=
(
HashMap
<
String
,
Object
>)
response
.
get
(
"scanResult"
);
String
taskId
=
(
String
)
scanResult
.
get
(
"taskId"
);
fileManager
.
updateCheckResult
(
fileKey
,
freezed
,
taskId
);
String
resultLog
=
JsonUtil
.
toJson
(
scanResult
.
get
(
"results"
));
fileManager
.
updateCheckResult
(
fileKey
,
freezed
,
taskId
,
resultLog
);
return
"success"
;
}
@ApiOperation
(
"oss图片审核
回调
"
)
@ApiOperation
(
"oss图片审核
结果查询
"
)
@PostMapping
(
value
=
"/picCheck/queryTask"
)
public
CommonResp
<
JSONArray
>
queryTask
(
@RequestParam
String
taskId
)
{
...
...
community-service/src/main/java/com/tanpu/community/dao/entity/community/FileRecordEntity.java
View file @
b05c24c1
...
...
@@ -62,10 +62,12 @@ public class FileRecordEntity implements Serializable {
@ApiModelProperty
(
value
=
"阿里云校验任务id(用于同步查询结果)"
)
private
String
checkTaskId
;
@ApiModelProperty
(
value
=
"审核结果记录"
)
private
String
checkResultLog
;
public
String
getUrl
(){
return
getPreviewUrl
().
substring
(
0
,
getPreviewUrl
().
indexOf
(
"?"
));
}
public
Long
getId
()
{
return
id
;
}
...
...
@@ -162,6 +164,14 @@ public class FileRecordEntity implements Serializable {
this
.
checkTaskId
=
checkTaskId
;
}
public
String
getCheckResultLog
()
{
return
checkResultLog
;
}
public
void
setCheckResultLog
(
String
checkResultLog
)
{
this
.
checkResultLog
=
checkResultLog
;
}
@Override
public
String
toString
()
{
return
"FileRecordEntity{"
+
...
...
@@ -177,6 +187,7 @@ public class FileRecordEntity implements Serializable {
", extInfo="
+
extInfo
+
", checkStatus="
+
checkStatus
+
", checkTaskId="
+
checkTaskId
+
", checkResultLog="
+
checkResultLog
+
"}"
;
}
}
community-service/src/main/java/com/tanpu/community/manager/FileManager.java
View file @
b05c24c1
...
...
@@ -5,8 +5,6 @@ import com.alibaba.fastjson.JSONArray;
import
com.alibaba.fastjson.JSONObject
;
import
com.aliyuncs.DefaultAcsClient
;
import
com.aliyuncs.IAcsClient
;
import
com.aliyuncs.exceptions.ClientException
;
import
com.aliyuncs.exceptions.ServerException
;
import
com.aliyuncs.green.model.v20180509.ImageAsyncScanResultsRequest
;
import
com.aliyuncs.http.FormatType
;
import
com.aliyuncs.http.HttpResponse
;
...
...
@@ -75,27 +73,28 @@ public class FileManager {
.
collect
(
Collectors
.
toMap
(
FileRecordEntity:
:
getFileId
,
FileRecordEntity:
:
getUrl
));
}
public
void
updateCheckResult
(
String
fileKey
,
boolean
check
,
String
taskId
)
{
public
void
updateCheckResult
(
String
fileKey
,
boolean
check
,
String
taskId
,
String
resultLog
)
{
FileRecordEntity
fileRecordEntity
=
ossFileService
.
queryByOssKey
(
fileKey
);
if
(
fileRecordEntity
==
null
)
{
throw
new
BizException
(
"图片未找到:"
+
fileKey
);
if
(
fileRecordEntity
==
null
)
{
throw
new
BizException
(
"图片未找到:"
+
fileKey
);
}
if
(
check
){
if
(
check
)
{
// 审核失败
fileRecordEntity
.
setCheckStatus
(
2
);
}
else
{
}
else
{
// 审核通过
fileRecordEntity
.
setCheckStatus
(
1
);
}
fileRecordEntity
.
setCheckTaskId
(
taskId
);
fileRecordEntity
.
setCheckResultLog
(
resultLog
);
ossFileService
.
update
(
fileRecordEntity
);
}
// 同步查询,使用taskId,且1/24小时内才能查询
public
JSONArray
queryTask
(
String
taskId
)
throws
Exception
{
IClientProfile
profile
=
DefaultProfile
.
getProfile
(
"cn-shanghai"
,
"LTAIAKEzVydP0Q9P"
,
"59V9ke9txaIFzWxHFKTb1eoOOpmKpJ"
);
IClientProfile
profile
=
DefaultProfile
.
getProfile
(
"cn-shanghai"
,
"LTAIAKEzVydP0Q9P"
,
"59V9ke9txaIFzWxHFKTb1eoOOpmKpJ"
);
DefaultProfile
.
addEndpoint
(
"cn-shanghai"
,
"cn-shanghai"
,
"Green"
,
"green.cn-shanghai.aliyuncs.com"
);
IAcsClient
client
=
new
DefaultAcsClient
(
profile
);
...
...
@@ -119,41 +118,34 @@ public class FileManager {
imageAsyncScanResultsRequest
.
setConnectTimeout
(
3000
);
imageAsyncScanResultsRequest
.
setReadTimeout
(
6000
);
try
{
HttpResponse
httpResponse
=
client
.
doAction
(
imageAsyncScanResultsRequest
);
if
(
httpResponse
.
isSuccess
()){
JSONObject
scrResponse
=
JSON
.
parseObject
(
new
String
(
httpResponse
.
getHttpContent
(),
"UTF-8"
));
System
.
out
.
println
(
JSON
.
toJSONString
(
scrResponse
,
true
));
if
(
200
==
scrResponse
.
getInteger
(
"code"
))
{
JSONArray
taskResults
=
scrResponse
.
getJSONArray
(
"data"
);
for
(
Object
taskResult
:
taskResults
)
{
if
(
200
==
((
JSONObject
)
taskResult
).
getInteger
(
"code"
)){
JSONArray
sceneResults
=
((
JSONObject
)
taskResult
).
getJSONArray
(
"results"
);
for
(
Object
sceneResult
:
sceneResults
)
{
String
scene
=
((
JSONObject
)
sceneResult
).
getString
(
"scene"
);
String
suggestion
=
((
JSONObject
)
sceneResult
).
getString
(
"suggestion"
);
// 根据scene和suggestion做相关的处理。
// 根据不同的suggestion结果做业务上的不同处理。例如,将违规数据删除等。
}
return
sceneResults
;
}
else
{
throw
new
BizException
(
"task process fail:"
+
((
JSONObject
)
taskResult
).
getInteger
(
"code"
));
HttpResponse
httpResponse
=
client
.
doAction
(
imageAsyncScanResultsRequest
);
if
(
httpResponse
.
isSuccess
())
{
JSONObject
scrResponse
=
JSON
.
parseObject
(
new
String
(
httpResponse
.
getHttpContent
(),
"UTF-8"
));
System
.
out
.
println
(
JSON
.
toJSONString
(
scrResponse
,
true
));
if
(
200
==
scrResponse
.
getInteger
(
"code"
))
{
JSONArray
taskResults
=
scrResponse
.
getJSONArray
(
"data"
);
for
(
Object
taskResult
:
taskResults
)
{
if
(
200
==
((
JSONObject
)
taskResult
).
getInteger
(
"code"
))
{
JSONArray
sceneResults
=
((
JSONObject
)
taskResult
).
getJSONArray
(
"results"
);
for
(
Object
sceneResult
:
sceneResults
)
{
String
scene
=
((
JSONObject
)
sceneResult
).
getString
(
"scene"
);
String
suggestion
=
((
JSONObject
)
sceneResult
).
getString
(
"suggestion"
);
// 根据scene和suggestion做相关的处理。
// 根据不同的suggestion结果做业务上的不同处理。例如,将违规数据删除等。
}
return
sceneResults
;
}
else
{
throw
new
BizException
(
"task process fail:"
+
((
JSONObject
)
taskResult
).
getInteger
(
"code"
));
}
}
else
{
throw
new
BizException
(
"detect not success. code:"
+
scrResponse
.
getInteger
(
"code"
));
}
}
else
{
throw
new
BizException
(
"response not success. status:"
+
httpResponse
.
getStatus
(
));
}
else
{
throw
new
BizException
(
"detect not success. code:"
+
scrResponse
.
getInteger
(
"code"
));
}
}
catch
(
ServerException
e
)
{
e
.
printStackTrace
();
}
catch
(
ClientException
e
)
{
e
.
printStackTrace
();
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
else
{
throw
new
BizException
(
"response not success. status:"
+
httpResponse
.
getStatus
());
}
return
null
;
}
}
community-service/src/main/java/com/tanpu/community/service/BatchFeignCallService.java
View file @
b05c24c1
...
...
@@ -442,10 +442,10 @@ public class BatchFeignCallService {
.
build
();
// 图片审核屏蔽
if
(
FileChechStatusEnum
.
FAILED
.
getCode
().
equals
(
imgEntity
.
getCheckStatus
())){
imagesDTO
.
setRemark
(
"https://tamp-sit.oss-cn-shanghai.aliyuncs.com/community/pic/default/check_fail.png"
);
imagesDTO
.
setResizeUrl
(
"https://tamp-sit.oss-cn-shanghai.aliyuncs.com/community/pic/default/check_fail.png?x-oss-process=image/resize,p_50"
);
imagesDTO
.
setImgWidth
(
1035
);
imagesDTO
.
setImgHeight
(
1115
);
imagesDTO
.
setRemark
(
CommunityConstant
.
OSS_CHECK_FAIL_DEFAULT
);
imagesDTO
.
setResizeUrl
(
CommunityConstant
.
OSS_CHECK_FAIL_DEFAULT
+
CommunityConstant
.
OSS_RESIZE_RATIO
);
imagesDTO
.
setImgWidth
(
CommunityConstant
.
OSS_CHECK_FAIL_DEFAULT_WIDTH
);
imagesDTO
.
setImgHeight
(
CommunityConstant
.
OSS_CHECK_FAIL_DEFAULT_HEIGHT
);
}
themeContent
.
setImgList
(
Collections
.
singletonList
(
imagesDTO
));
}
...
...
@@ -457,12 +457,12 @@ public class BatchFeignCallService {
if
(
imgUrlMap
.
containsKey
(
imagesDTO
.
getRelId
()))
{
FileRecordEntity
imgEntity
=
imgUrlMap
.
get
(
imagesDTO
.
getRelId
());
// 图片审核不通过,替换为默认图片
// 图片审核不通过,替换为默认图片
todo 配置移除
if
(
FileChechStatusEnum
.
FAILED
.
getCode
().
equals
(
imgEntity
.
getCheckStatus
())){
imagesDTO
.
setRemark
(
"https://tamp-sit.oss-cn-shanghai.aliyuncs.com/community/pic/default/check_fail.png"
);
imagesDTO
.
setResizeUrl
(
"https://tamp-sit.oss-cn-shanghai.aliyuncs.com/community/pic/default/check_fail.png?x-oss-process=image/resize,p_50"
);
imagesDTO
.
setImgWidth
(
1035
);
imagesDTO
.
setImgHeight
(
1115
);
imagesDTO
.
setRemark
(
CommunityConstant
.
OSS_CHECK_FAIL_DEFAULT
);
imagesDTO
.
setResizeUrl
(
CommunityConstant
.
OSS_CHECK_FAIL_DEFAULT
+
CommunityConstant
.
OSS_RESIZE_RATIO
);
imagesDTO
.
setImgWidth
(
CommunityConstant
.
OSS_CHECK_FAIL_DEFAULT_WIDTH
);
imagesDTO
.
setImgHeight
(
CommunityConstant
.
OSS_CHECK_FAIL_DEFAULT_HEIGHT
);
}
else
{
imagesDTO
.
setRemark
(
imgEntity
.
getUrl
());
imagesDTO
.
setResizeUrl
(
imgEntity
.
getUrl
()
+
CommunityConstant
.
OSS_RESIZE_RATIO
);
...
...
community-service/src/main/resources/mapper/community/FileRecordEntityMapper.xml
View file @
b05c24c1
...
...
@@ -16,6 +16,7 @@
<result
column=
"ext_info"
property=
"extInfo"
/>
<result
column=
"check_status"
property=
"checkStatus"
/>
<result
column=
"check_task_id"
property=
"checkTaskId"
/>
<result
column=
"check_result_log"
property=
"checkResultLog"
/>
</resultMap>
</mapper>
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