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
4cd6f2dd
Commit
4cd6f2dd
authored
Aug 18, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图片审核 结果查询
parent
f62f2c48
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
75 deletions
+99
-75
CallBackController.java
...va/com/tanpu/community/controller/CallBackController.java
+15
-0
FileRecordEntity.java
...anpu/community/dao/entity/community/FileRecordEntity.java
+5
-0
FileManager.java
...rc/main/java/com/tanpu/community/manager/FileManager.java
+79
-0
OSSFileService.java
...main/java/com/tanpu/community/service/OSSFileService.java
+0
-75
No files found.
community-service/src/main/java/com/tanpu/community/controller/CallBackController.java
View file @
4cd6f2dd
package
com
.
tanpu
.
community
.
controller
;
import
com.alibaba.fastjson.JSONArray
;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.community.manager.FileManager
;
import
io.swagger.annotations.ApiOperation
;
...
...
@@ -7,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.Date
;
...
...
@@ -43,6 +47,17 @@ public class CallBackController {
return
"success"
;
}
@ApiOperation
(
"oss图片审核回调"
)
@PostMapping
(
value
=
"/picCheck/queryTask"
)
public
CommonResp
<
JSONArray
>
queryTask
(
@RequestParam
String
taskId
)
{
try
{
return
CommonResp
.
success
(
fileManager
.
queryTask
(
taskId
));
}
catch
(
Exception
e
)
{
throw
new
BizException
(
"queryTask请求失败"
);
}
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
new
Date
());
}
...
...
community-service/src/main/java/com/tanpu/community/dao/entity/community/FileRecordEntity.java
View file @
4cd6f2dd
...
...
@@ -3,6 +3,7 @@ package com.tanpu.community.dao.entity.community;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.tanpu.community.api.enums.FileChechStatusEnum
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
...
...
@@ -63,6 +64,10 @@ public class FileRecordEntity implements Serializable {
private
String
checkTaskId
;
public
String
getUrl
(){
if
(
FileChechStatusEnum
.
NOT_PASS
.
getCode
().
equals
(
checkStatus
)){
// 审核不通过,返回默认图片
return
"https://tamp-sit.oss-cn-shanghai.aliyuncs.com/community/pic/default/not_exist.jpg"
;
}
return
getPreviewUrl
().
substring
(
0
,
getPreviewUrl
().
indexOf
(
"?"
));
}
...
...
community-service/src/main/java/com/tanpu/community/manager/FileManager.java
View file @
4cd6f2dd
package
com
.
tanpu
.
community
.
manager
;
import
com.alibaba.fastjson.JSON
;
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
;
import
com.aliyuncs.http.MethodType
;
import
com.aliyuncs.http.ProtocolType
;
import
com.aliyuncs.profile.DefaultProfile
;
import
com.aliyuncs.profile.IClientProfile
;
import
com.tanpu.common.constant.ErrorCodeConstant
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.community.api.beans.resp.FileUploadResp
;
...
...
@@ -14,6 +28,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
...
...
@@ -77,4 +92,68 @@ public class FileManager {
ossFileService
.
update
(
fileRecordEntity
);
}
// 同步查询,使用taskId,且1/24小时内才能查询
public
JSONArray
queryTask
(
String
taskId
)
throws
Exception
{
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
);
ImageAsyncScanResultsRequest
imageAsyncScanResultsRequest
=
new
ImageAsyncScanResultsRequest
();
// 指定API返回格式。
imageAsyncScanResultsRequest
.
setAcceptFormat
(
FormatType
.
JSON
);
// 指定请求方法。
imageAsyncScanResultsRequest
.
setMethod
(
MethodType
.
POST
);
imageAsyncScanResultsRequest
.
setEncoding
(
"utf-8"
);
// 支持HTTP和HTTPS。
imageAsyncScanResultsRequest
.
setProtocol
(
ProtocolType
.
HTTP
);
List
<
String
>
taskIds
=
new
ArrayList
<
String
>();
taskIds
.
add
(
taskId
);
imageAsyncScanResultsRequest
.
setHttpContent
(
JSON
.
toJSONString
(
taskIds
).
getBytes
(
"UTF-8"
),
"UTF-8"
,
FormatType
.
JSON
);
/**
* 请务必设置超时时间。
*/
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"
));
}
}
}
else
{
throw
new
BizException
(
"detect not success. code:"
+
scrResponse
.
getInteger
(
"code"
));
}
}
else
{
throw
new
BizException
(
"response not success. status:"
+
httpResponse
.
getStatus
());
}
}
catch
(
ServerException
e
)
{
e
.
printStackTrace
();
}
catch
(
ClientException
e
)
{
e
.
printStackTrace
();
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
return
null
;
}
}
community-service/src/main/java/com/tanpu/community/service/OSSFileService.java
View file @
4cd6f2dd
package
com
.
tanpu
.
community
.
service
;
import
com.alibaba.fastjson.JSON
;
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
;
import
com.aliyuncs.http.MethodType
;
import
com.aliyuncs.http.ProtocolType
;
import
com.aliyuncs.profile.DefaultProfile
;
import
com.aliyuncs.profile.IClientProfile
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.tanpu.common.constant.BizStatus
;
import
com.tanpu.common.util.AliyunOSSHelper
;
...
...
@@ -35,7 +21,6 @@ import javax.annotation.Resource;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayInputStream
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -134,67 +119,7 @@ public class OSSFileService {
.
in
(
FileRecordEntity:
:
getFileId
,
fileIds
));
}
// 同步查询,使用taskId,且1/24小时内才能查询
public
static
void
main
(
String
[]
args
)
throws
Exception
{
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
);
ImageAsyncScanResultsRequest
imageAsyncScanResultsRequest
=
new
ImageAsyncScanResultsRequest
();
// 指定API返回格式。
imageAsyncScanResultsRequest
.
setAcceptFormat
(
FormatType
.
JSON
);
// 指定请求方法。
imageAsyncScanResultsRequest
.
setMethod
(
MethodType
.
POST
);
imageAsyncScanResultsRequest
.
setEncoding
(
"utf-8"
);
// 支持HTTP和HTTPS。
imageAsyncScanResultsRequest
.
setProtocol
(
ProtocolType
.
HTTP
);
List
<
String
>
taskIds
=
new
ArrayList
<
String
>();
taskIds
.
add
(
"img5B0C6GGD4uq41U3aPy6qpD-1uRam9"
);
imageAsyncScanResultsRequest
.
setHttpContent
(
JSON
.
toJSONString
(
taskIds
).
getBytes
(
"UTF-8"
),
"UTF-8"
,
FormatType
.
JSON
);
/**
* 请务必设置超时时间。
*/
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结果做业务上的不同处理。例如,将违规数据删除等。
}
}
else
{
System
.
out
.
println
(
"task process fail:"
+
((
JSONObject
)
taskResult
).
getInteger
(
"code"
));
}
}
}
else
{
System
.
out
.
println
(
"detect not success. code:"
+
scrResponse
.
getInteger
(
"code"
));
}
}
else
{
System
.
out
.
println
(
"response not success. status:"
+
httpResponse
.
getStatus
());
}
}
catch
(
ServerException
e
)
{
e
.
printStackTrace
();
}
catch
(
ClientException
e
)
{
e
.
printStackTrace
();
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
}
public
FileRecordEntity
queryByOssKey
(
String
fileKey
)
{
...
...
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