Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
ocrCloudPlatForm
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ocr-cloud-platform
ocrCloudPlatForm
Commits
1a470204
Commit
1a470204
authored
Dec 28, 2023
by
黄明步
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改文件下载
parent
9cf8b1c5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
170 additions
and
237 deletions
+170
-237
src/main/java/com/gxmailu/ocrCloudPlatform/controller/RetransmissionController.java
+10
-132
src/main/java/com/gxmailu/ocrCloudPlatform/entity/TmpRecordByTrigger.java
+17
-0
src/main/java/com/gxmailu/ocrCloudPlatform/mapper/TmpRecordByTriggerMapper.java
+13
-0
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/MessageServiceImpl.java
+10
-5
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/RetransmissionService.java
+120
-100
No files found.
src/main/java/com/gxmailu/ocrCloudPlatform/controller/RetransmissionController.java
View file @
1a470204
package
com
.
gxmailu
.
ocrCloudPlatform
.
controller
;
package
com
.
gxmailu
.
ocrCloudPlatform
.
controller
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.core.util.ObjUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecord
;
import
com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll
;
import
com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecord1Mapper
;
import
com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecord1Mapper
;
import
com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecordAllMapper
;
import
com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecordAllMapper
;
import
com.gxmailu.ocrCloudPlatform.service.impl.ElasticSearchService
;
import
com.gxmailu.ocrCloudPlatform.service.impl.ElasticSearchService
;
import
com.gxmailu.ocrCloudPlatform.service.impl.RetransmissionService
;
import
com.gxmailu.ocrCloudPlatform.service.impl.RetransmissionService
;
import
com.gxmailu.ocrCloudPlatform.vo.OcrResult
;
import
com.gxmailu.ocrCloudPlatform.vo.OcrResult
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Objects
;
/**
/**
* 接口转发控制器
* 接口转发控制器
...
@@ -49,114 +31,6 @@ public class RetransmissionController {
...
@@ -49,114 +31,6 @@ public class RetransmissionController {
@Autowired
@Autowired
private
AppAbilityRecordAllMapper
recordAllMapper
;
private
AppAbilityRecordAllMapper
recordAllMapper
;
@GetMapping
(
"/test"
)
public
void
test
(
HttpServletResponse
response
)
throws
IOException
{
OcrResult
result
=
rec
();
JSONObject
info
=
JSONUtil
.
parseObj
(
result
.
getData
());
Long
id
=
info
.
getLong
(
"sid"
);
AppAbilityRecordAll
appAbilityRecordAll
=
elasticSearchService
.
getDocumentById
(
id
.
toString
());
if
(
ObjUtil
.
isNull
(
appAbilityRecordAll
))
{
System
.
out
.
println
(
"从es中获取的数据为空"
);
appAbilityRecordAll
=
recordAllMapper
.
selectById
(
id
);
if
(
ObjUtil
.
isNull
(
appAbilityRecordAll
))
{
System
.
out
.
println
(
"查询数据库也为空"
);
}
else
{
System
.
out
.
println
(
appAbilityRecordAll
);
}
}
else
{
System
.
out
.
println
(
"从es中取到数据:"
+
appAbilityRecordAll
);
String
serverIp
=
appAbilityRecordAll
.
getServerIp
();
String
dstUrl
=
appAbilityRecordAll
.
getDstUrl
();
String
pdf
=
appAbilityRecordAll
.
getPdf
();
// 构建MinIO文件的URL
String
fileUrl
=
"http://"
+
serverIp
+
":9000/"
+
dstUrl
+
"/"
+
pdf
;
try
{
byte
[]
bytes
=
HttpUtil
.
downloadBytes
(
fileUrl
);
response
.
getOutputStream
().
write
(
bytes
);
}
catch
(
IOException
e
)
{
// 处理异常
e
.
printStackTrace
();
}
}
}
private
OcrResult
rec
()
{
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"fileId"
,
IdUtil
.
fastSimpleUUID
());
File
tempFile
=
new
File
(
"C:\\Users\\Windows11\\Desktop\\ll\\0239.jpg"
);
paramMap
.
put
(
"file"
,
tempFile
);
String
ocrApi
=
"http://127.0.0.1:18082"
;
// 设置开始时间
long
startTime
=
System
.
currentTimeMillis
();
String
res
=
HttpRequest
.
post
(
ocrApi
+
"/ofs/api/sync/v1/ft/1001"
)
.
header
(
"Authorization"
,
"AppId aj32jafj-l948-0034-zn6k-6dqymid9le32"
)
.
header
(
"X-Timestamp"
,
"1685889614304"
)
.
header
(
"X-Checksum"
,
"d57ed307c05f1088a3216f2031a9b11c"
)
.
form
(
paramMap
).
execute
().
body
();
// 设置结束时间
long
endTime
=
System
.
currentTimeMillis
();
// Assert.hasText(res, "请求接口返回为空");
if
(
StringUtils
.
isEmpty
(
res
))
{
// return new OcrResult("-1", "请求失败", null, null);
}
// FileUtil.del(tempFile);
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
saveToAppAbilityRecordAll
(
result
,
"127.0.0.1"
);
return
result
;
}
@Async
(
"dataPersistThreadPoolTaskExecutor"
)
public
void
saveToAppAbilityRecordAll
(
OcrResult
result
,
String
serverIp
)
{
try
{
if
(
Objects
.
equals
(
result
.
getCode
(),
"000000"
))
{
log
.
info
(
"调用成功,开始持久化存储..."
);
JSONObject
info
=
JSONUtil
.
parseObj
(
result
.
getData
());
Long
id
=
info
.
getLong
(
"sid"
);
handleRecord
(
record1Mapper
,
id
,
"127.0.0.1"
,
serverIp
);
}
else
{
log
.
error
(
"请求OCR接口错误{}"
,
result
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"数据{}保存发生异常!"
,
result
,
e
);
}
}
private
<
T
extends
AppAbilityRecord
>
void
handleRecord
(
BaseMapper
<
T
>
mapper
,
Long
id
,
String
clientIP
,
String
serverIp
)
{
T
record
=
mapper
.
selectById
(
id
);
if
(
ObjUtil
.
isNull
(
record
))
{
return
;
}
record
.
setIp
(
clientIP
);
log
.
info
(
"修改id:{}的真实客户端请求ip结果:{}"
,
id
,
mapper
.
updateById
(
record
));
AppAbilityRecordAll
recordAll
=
recordAllMapper
.
selectById
(
id
);
if
(
recordAll
==
null
)
{
recordAll
=
new
AppAbilityRecordAll
();
BeanUtils
.
copyProperties
(
record
,
recordAll
,
AppAbilityRecordAll
.
class
);
recordAll
.
setCreatedTime
(
DateUtil
.
date
());
recordAll
.
setUpdatedTime
(
DateUtil
.
date
());
if
(
StrUtil
.
isEmpty
(
recordAll
.
getServerIp
()))
{
recordAll
.
setServerIp
(
serverIp
);
}
log
.
info
(
"添加id:{} 的数据到recordAll持久化保存结果:{}"
,
recordAll
.
getId
(),
recordAllMapper
.
insert
(
recordAll
));
}
else
{
AppAbilityRecordAll
newRecordAll
=
new
AppAbilityRecordAll
();
BeanUtils
.
copyProperties
(
record
,
newRecordAll
,
AppAbilityRecordAll
.
class
);
newRecordAll
.
setUpdatedTime
(
DateUtil
.
date
());
if
(
StrUtil
.
isEmpty
(
newRecordAll
.
getServerIp
()))
{
newRecordAll
.
setServerIp
(
serverIp
);
}
log
.
info
(
"修改recordAll中id:{} 的数据结果:{}"
,
newRecordAll
.
getId
(),
recordAllMapper
.
updateById
(
newRecordAll
));
}
}
@GetMapping
(
"/ofs/api/sync/getClientOcrTask"
)
@GetMapping
(
"/ofs/api/sync/getClientOcrTask"
)
public
OcrResult
getClientOcrTask
()
{
public
OcrResult
getClientOcrTask
()
{
return
this
.
retransmissionService
.
getClientOcrTask
();
return
this
.
retransmissionService
.
getClientOcrTask
();
...
@@ -177,22 +51,26 @@ public class RetransmissionController {
...
@@ -177,22 +51,26 @@ public class RetransmissionController {
@PostMapping
(
"/ofs/api/sync/v1/pdf"
)
@PostMapping
(
"/ofs/api/sync/v1/pdf"
)
public
void
downloadDoubleDeckPdf
(
@RequestBody
JSONObject
body
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
public
void
downloadDoubleDeckPdf
(
@RequestBody
JSONObject
body
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
retransmissionService
.
downloadDoubleDeckPdf
(
body
,
request
,
response
);
// retransmissionService.downloadDoubleDeckPdf(body, request, response);
retransmissionService
.
downloadPdfNew
(
body
,
response
);
}
}
@PostMapping
(
"/ofs/api/sync/v1/ft/pdf"
)
@PostMapping
(
"/ofs/api/sync/v1/ft/pdf"
)
public
void
downloadDoubleDeckPdfByFt
(
@RequestBody
JSONObject
body
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
public
void
downloadDoubleDeckPdfByFt
(
@RequestBody
JSONObject
body
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
retransmissionService
.
downloadDoubleDeckPdf
(
body
,
request
,
response
);
// retransmissionService.downloadDoubleDeckPdf(body, request, response);
retransmissionService
.
downloadPdfNew
(
body
,
response
);
}
}
@PostMapping
(
"/ofs/api/sync/v1/o
df
"
)
@PostMapping
(
"/ofs/api/sync/v1/o
fd
"
)
public
void
downloadDoubleDeckOfd
(
@RequestBody
JSONObject
body
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
public
void
downloadDoubleDeckOfd
(
@RequestBody
JSONObject
body
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
retransmissionService
.
downloadDoubleDeckOfd
(
body
,
request
,
response
);
// retransmissionService.downloadDoubleDeckOfd(body, request, response);
retransmissionService
.
downloadOfdNew
(
body
,
response
);
}
}
@PostMapping
(
"/ofs/api/sync/v1/ft/o
df
"
)
@PostMapping
(
"/ofs/api/sync/v1/ft/o
fd
"
)
public
void
downloadDoubleDeckOfdByFt
(
@RequestBody
JSONObject
body
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
public
void
downloadDoubleDeckOfdByFt
(
@RequestBody
JSONObject
body
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
retransmissionService
.
downloadDoubleDeckOfd
(
body
,
request
,
response
);
// retransmissionService.downloadDoubleDeckOfd(body, request, response);
retransmissionService
.
downloadOfdNew
(
body
,
response
);
}
}
@PostMapping
(
"/ofs/api/sync/v1/ft/1001"
)
@PostMapping
(
"/ofs/api/sync/v1/ft/1001"
)
...
...
src/main/java/com/gxmailu/ocrCloudPlatform/entity/TmpRecordByTrigger.java
0 → 100644
View file @
1a470204
package
com
.
gxmailu
.
ocrCloudPlatform
.
entity
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
java.io.Serializable
;
/**
* 应用调用能力记录临时中间表
*
* @author Hmb
* @since 2023/12/22 16:44
*/
@TableName
(
"tmp_record_by_trigger"
)
public
class
TmpRecordByTrigger
extends
AppAbilityRecord
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
}
src/main/java/com/gxmailu/ocrCloudPlatform/mapper/TmpRecordByTriggerMapper.java
0 → 100644
View file @
1a470204
package
com
.
gxmailu
.
ocrCloudPlatform
.
mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.gxmailu.ocrCloudPlatform.entity.TmpRecordByTrigger
;
import
org.springframework.stereotype.Repository
;
/**
* @author Hmb
* @since 2023/12/22 16:45
*/
@Repository
public
interface
TmpRecordByTriggerMapper
extends
BaseMapper
<
TmpRecordByTrigger
>
{
}
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/MessageServiceImpl.java
View file @
1a470204
package
com
.
gxmailu
.
ocrCloudPlatform
.
service
.
impl
;
package
com
.
gxmailu
.
ocrCloudPlatform
.
service
.
impl
;
import
cn.hutool.core.codec.Base64
;
import
cn.hutool.core.codec.Base64
;
import
cn.hutool.core.date.DateTime
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.http.HttpException
;
import
cn.hutool.http.HttpException
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpRequest
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
...
@@ -24,8 +26,10 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
...
@@ -24,8 +26,10 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.*
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Objects
;
@Service
@Service
@Slf4j
@Slf4j
...
@@ -144,9 +148,10 @@ public class MessageServiceImpl implements MessageService {
...
@@ -144,9 +148,10 @@ public class MessageServiceImpl implements MessageService {
String
title
=
alerts
.
getJSONObject
(
"labels"
).
getString
(
"alertname"
);
String
title
=
alerts
.
getJSONObject
(
"labels"
).
getString
(
"alertname"
);
String
body
=
alerts
.
getJSONObject
(
"annotations"
).
getString
(
"summary"
);
String
body
=
alerts
.
getJSONObject
(
"annotations"
).
getString
(
"summary"
);
String
dateStr
=
alerts
.
getString
(
"startsAt"
);
String
dateStr
=
alerts
.
getString
(
"startsAt"
);
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
);
// SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
df
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"UTC"
));
// df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date
date
=
df
.
parse
(
dateStr
);
// Date date = df.parse(dateStr);
DateTime
date
=
DateUtil
.
parse
(
dateStr
);
Message
dto
=
new
Message
();
Message
dto
=
new
Message
();
dto
.
setTitle
(
title
);
dto
.
setTitle
(
title
);
dto
.
setBody
(
body
);
dto
.
setBody
(
body
);
...
...
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/RetransmissionService.java
View file @
1a470204
package
com
.
gxmailu
.
ocrCloudPlatform
.
service
.
impl
;
package
com
.
gxmailu
.
ocrCloudPlatform
.
service
.
impl
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.io.IoUtil
;
import
cn.hutool.core.io.IoUtil
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.core.util.ObjUtil
;
import
cn.hutool.core.util.ObjUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.extra.servlet.ServletUtil
;
import
cn.hutool.extra.servlet.ServletUtil
;
...
@@ -20,6 +22,7 @@ import com.gxmailu.ocrCloudPlatform.config.DistributedRedisLock;
...
@@ -20,6 +22,7 @@ import com.gxmailu.ocrCloudPlatform.config.DistributedRedisLock;
import
com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecord
;
import
com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecord
;
import
com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll
;
import
com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll
;
import
com.gxmailu.ocrCloudPlatform.entity.ServerInfo
;
import
com.gxmailu.ocrCloudPlatform.entity.ServerInfo
;
import
com.gxmailu.ocrCloudPlatform.entity.TmpRecordByTrigger
;
import
com.gxmailu.ocrCloudPlatform.mapper.*
;
import
com.gxmailu.ocrCloudPlatform.mapper.*
;
import
com.gxmailu.ocrCloudPlatform.service.ServerInfoService
;
import
com.gxmailu.ocrCloudPlatform.service.ServerInfoService
;
import
com.gxmailu.ocrCloudPlatform.vo.OcrResult
;
import
com.gxmailu.ocrCloudPlatform.vo.OcrResult
;
...
@@ -38,6 +41,7 @@ import javax.servlet.http.HttpServletRequest;
...
@@ -38,6 +41,7 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicInteger
;
...
@@ -70,6 +74,8 @@ public class RetransmissionService {
...
@@ -70,6 +74,8 @@ public class RetransmissionService {
private
AppAbilityRecord9Mapper
record9Mapper
;
private
AppAbilityRecord9Mapper
record9Mapper
;
@Autowired
@Autowired
private
AppAbilityRecordAllMapper
recordAllMapper
;
private
AppAbilityRecordAllMapper
recordAllMapper
;
@Autowired
private
TmpRecordByTriggerMapper
tmpRecordByTriggerMapper
;
@Autowired
@Autowired
private
ServerInfoMapper
serverInfoMapper
;
private
ServerInfoMapper
serverInfoMapper
;
...
@@ -164,9 +170,9 @@ public class RetransmissionService {
...
@@ -164,9 +170,9 @@ public class RetransmissionService {
public
OcrResult
commonRecognition
(
String
code
,
String
fileId
,
MultipartFile
file
,
Boolean
createOfd
,
HttpServletRequest
request
)
{
public
OcrResult
commonRecognition
(
String
code
,
String
fileId
,
MultipartFile
file
,
Boolean
createOfd
,
HttpServletRequest
request
)
{
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"fileId"
,
fileId
);
paramMap
.
put
(
"fileId"
,
fileId
);
// 不能直接传 MultipartFile,另存一份临时文件,请求完毕后删除。
String
tempSaveDir
=
tempDir
+
File
.
separator
+
IdUtil
.
fastSimpleUUID
()
+
"_"
+
System
.
currentTimeMillis
();
// File tempFile = new File("C:\\Users\\Administrator\\Desktop\\test", System.currentTimeMillis() +"_"+ file.getOriginalFilename()
);
FileUtil
.
mkdir
(
tempSaveDir
);
File
tempFile
=
new
File
(
temp
Dir
,
System
.
currentTimeMillis
()
+
"_"
+
FileUtil
.
getName
(
file
.
getOriginalFilename
(
)));
File
tempFile
=
new
File
(
temp
SaveDir
,
Objects
.
requireNonNull
(
FileUtil
.
getName
(
file
.
getOriginalFilename
()
)));
try
{
try
{
file
.
transferTo
(
tempFile
);
file
.
transferTo
(
tempFile
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
@@ -174,13 +180,11 @@ public class RetransmissionService {
...
@@ -174,13 +180,11 @@ public class RetransmissionService {
}
}
paramMap
.
put
(
"file"
,
tempFile
);
paramMap
.
put
(
"file"
,
tempFile
);
paramMap
.
put
(
"createOfd"
,
createOfd
);
paramMap
.
put
(
"createOfd"
,
createOfd
);
// ServerInfo ocrServerAddress = getOcrServerAddress();
ServerInfo
ocrServerAddress
=
getServerAddressByRequestCount
();
ServerInfo
ocrServerAddress
=
getServerAddressByRequestCount
();
if
(
ocrServerAddress
==
null
)
{
if
(
ocrServerAddress
==
null
)
{
return
OcrResult
.
error
(
"OCR云平台未配置服务器信息"
);
return
OcrResult
.
error
(
"OCR云平台未配置服务器信息"
);
}
}
// setOcrTask(ocrServerAddress.getIp());
// setActiveServer(ocrServerAddress.getIp());
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
1
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
1
);
String
ocrApi
=
"http://"
+
ocrServerAddress
.
getIp
()
+
":"
+
ocrServerAddress
.
getOcrPort
();
String
ocrApi
=
"http://"
+
ocrServerAddress
.
getIp
()
+
":"
+
ocrServerAddress
.
getOcrPort
();
...
@@ -196,16 +200,15 @@ public class RetransmissionService {
...
@@ -196,16 +200,15 @@ public class RetransmissionService {
// 记录请求结束时间
// 记录请求结束时间
long
endTime
=
System
.
currentTimeMillis
();
long
endTime
=
System
.
currentTimeMillis
();
// Assert.hasText(res, "请求接口返回为空");
if
(
StringUtils
.
isEmpty
(
res
))
{
if
(
StringUtils
.
isEmpty
(
res
))
{
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
null
,
ocrServerAddress
,
request
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
null
,
ocrServerAddress
,
request
);
return
new
OcrResult
(
"007500"
,
"识别失败,请重试"
,
null
,
DateUtil
.
date
());
return
new
OcrResult
(
"007500"
,
"识别失败,请重试"
,
null
,
DateUtil
.
date
());
}
}
FileUtil
.
del
(
temp
File
);
FileUtil
.
del
(
temp
SaveDir
);
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
());
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
()
,
fileId
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
return
result
;
return
result
;
}
}
...
@@ -213,9 +216,9 @@ public class RetransmissionService {
...
@@ -213,9 +216,9 @@ public class RetransmissionService {
public
OcrResult
commonRecognitionV2
(
String
code
,
String
fileId
,
MultipartFile
file
,
Boolean
createOfd
,
HttpServletRequest
request
)
{
public
OcrResult
commonRecognitionV2
(
String
code
,
String
fileId
,
MultipartFile
file
,
Boolean
createOfd
,
HttpServletRequest
request
)
{
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"fileId"
,
fileId
);
paramMap
.
put
(
"fileId"
,
fileId
);
// 不能直接传 MultipartFile,另存一份临时文件,请求完毕后删除。
String
tempSaveDir
=
tempDir
+
File
.
separator
+
IdUtil
.
fastSimpleUUID
()
+
"_"
+
System
.
currentTimeMillis
();
// File tempFile = new File("C:\\Users\\Administrator\\Desktop\\test", System.currentTimeMillis() +"_"+ file.getOriginalFilename()
);
FileUtil
.
mkdir
(
tempSaveDir
);
File
tempFile
=
new
File
(
temp
Dir
,
System
.
currentTimeMillis
()
+
"_"
+
FileUtil
.
getName
(
file
.
getOriginalFilename
(
)));
File
tempFile
=
new
File
(
temp
SaveDir
,
Objects
.
requireNonNull
(
FileUtil
.
getName
(
file
.
getOriginalFilename
()
)));
try
{
try
{
file
.
transferTo
(
tempFile
);
file
.
transferTo
(
tempFile
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
@@ -247,11 +250,11 @@ public class RetransmissionService {
...
@@ -247,11 +250,11 @@ public class RetransmissionService {
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
null
,
ocrServerAddress
,
request
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
null
,
ocrServerAddress
,
request
);
return
new
OcrResult
(
"007500"
,
"识别失败,请重试"
,
null
,
DateUtil
.
date
());
return
new
OcrResult
(
"007500"
,
"识别失败,请重试"
,
null
,
DateUtil
.
date
());
}
}
FileUtil
.
del
(
temp
File
);
FileUtil
.
del
(
temp
SaveDir
);
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
());
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
()
,
fileId
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
return
result
;
return
result
;
}
}
...
@@ -288,36 +291,47 @@ public class RetransmissionService {
...
@@ -288,36 +291,47 @@ public class RetransmissionService {
}
}
public
void
downloadPdfNew
(
JSONObject
body
,
HttpServletResponse
response
)
{
public
void
downloadPdfNew
(
JSONObject
body
,
HttpServletResponse
response
)
{
Long
id
=
body
.
getLong
(
"sid"
);
try
{
try
{
Thread
.
sleep
(
50
);
if
(
id
==
null
)
{
JSONObject
info
=
JSONUtil
.
parseObj
(
body
);
log
.
error
(
"请求体中缺少 'sid' 字段,无法进行后续处理"
);
Long
id
=
info
.
getLong
(
"sid"
);
return
;
}
AppAbilityRecordAll
appAbilityRecordAll
=
elasticSearchService
.
getDocumentById
(
id
.
toString
());
AppAbilityRecordAll
appAbilityRecordAll
=
elasticSearchService
.
getDocumentById
(
id
.
toString
());
if
(
ObjUtil
.
isNull
(
appAbilityRecordAll
))
{
// 如果 appAbilityRecordAll 为空,或者相关字段为空,则直接查询数据库
log
.
error
(
"从es中获取文件数据为空"
);
if
(
appAbilityRecordAll
==
null
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getServerIp
())
// 兜底方案直接查询数据库
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getDstUrl
())
appAbilityRecordAll
=
recordAllMapper
.
selectById
(
id
);
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getPdf
()))
{
if
(
ObjUtil
.
isNull
(
appAbilityRecordAll
))
{
TmpRecordByTrigger
tmpRecordByTrigger
=
tmpRecordByTriggerMapper
.
selectById
(
id
);
log
.
error
(
"从数据库中获取文件数据为空"
);
if
(
tmpRecordByTrigger
==
null
)
{
log
.
error
(
"从查询不到ID为 {} 的文件数据"
,
id
);
return
;
return
;
}
}
appAbilityRecordAll
=
new
AppAbilityRecordAll
();
BeanUtil
.
copyProperties
(
tmpRecordByTriggerMapper
.
selectById
(
id
),
appAbilityRecordAll
);
}
}
if
(
ObjUtil
.
isNotNull
(
appAbilityRecordAll
))
{
String
serverIp
=
appAbilityRecordAll
.
getServerIp
();
String
dstUrl
=
appAbilityRecordAll
.
getDstUrl
();
String
objName
=
appAbilityRecordAll
.
getPdf
();
if
(
StrUtil
.
isBlank
(
serverIp
)
||
StrUtil
.
isBlank
(
dstUrl
)
||
StrUtil
.
isBlank
(
objName
))
{
log
.
error
(
"获取到数据内容不全,无法拼接URL下载文件"
);
return
;
}
// 构建MinIO文件的URL
String
fileUrl
=
"http://"
+
serverIp
+
":9000/"
+
dstUrl
+
"/"
+
objName
;
byte
[]
bytes
=
HttpUtil
.
downloadBytes
(
fileUrl
);
// 如果再次查询后结果仍为空,中止下载处理
response
.
getOutputStream
().
write
(
bytes
);
if
(
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getServerIp
())
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getDstUrl
())
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getPdf
()))
{
log
.
error
(
"无法获取ID为 {} 的完整文件信息,中止下载处理"
,
id
);
return
;
}
// 构建MinIO文件的URL
String
serverIp
=
appAbilityRecordAll
.
getServerIp
();
String
dstUrl
=
appAbilityRecordAll
.
getDstUrl
();
String
objName
=
appAbilityRecordAll
.
getPdf
();
String
fileUrl
=
StrUtil
.
format
(
"http://{}:9000/{}/{}"
,
serverIp
,
dstUrl
,
objName
);
byte
[]
bytes
=
HttpUtil
.
downloadBytes
(
fileUrl
);
try
(
OutputStream
outputStream
=
response
.
getOutputStream
())
{
outputStream
.
write
(
bytes
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"
OCR云平台接口异常"
,
e
);
log
.
error
(
"
在处理ID为 {} 的PDF下载过程中发生异常"
,
id
,
e
);
returnError
(
response
,
500
,
"OCR云平台接口异常"
);
returnError
(
response
,
500
,
"OCR云平台接口异常"
);
}
}
}
}
...
@@ -349,38 +363,48 @@ public class RetransmissionService {
...
@@ -349,38 +363,48 @@ public class RetransmissionService {
}
}
}
}
public
void
downloadOfdNew
(
JSONObject
body
,
HttpServletResponse
response
)
{
public
void
downloadOfdNew
(
JSONObject
body
,
HttpServletResponse
response
)
{
Long
id
=
body
.
getLong
(
"sid"
);
try
{
try
{
Thread
.
sleep
(
50
);
if
(
id
==
null
)
{
JSONObject
info
=
JSONUtil
.
parseObj
(
body
);
log
.
error
(
"请求体中缺少 'sid' 字段,无法进行后续处理"
);
Long
id
=
info
.
getLong
(
"sid"
);
return
;
}
AppAbilityRecordAll
appAbilityRecordAll
=
elasticSearchService
.
getDocumentById
(
id
.
toString
());
AppAbilityRecordAll
appAbilityRecordAll
=
elasticSearchService
.
getDocumentById
(
id
.
toString
());
if
(
ObjUtil
.
isNull
(
appAbilityRecordAll
))
{
// 如果 appAbilityRecordAll 为空,或者相关字段为空,再次查询数据库
log
.
error
(
"从es中获取文件数据为空"
);
if
(
appAbilityRecordAll
==
null
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getServerIp
())
// 兜底方案直接查询数据库
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getDstUrl
())
appAbilityRecordAll
=
recordAllMapper
.
selectById
(
id
);
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getPdf
()))
{
if
(
ObjUtil
.
isNull
(
appAbilityRecordAll
))
{
TmpRecordByTrigger
tmpRecordByTrigger
=
tmpRecordByTriggerMapper
.
selectById
(
id
);
log
.
error
(
"从数据库中获取文件数据为空"
);
if
(
tmpRecordByTrigger
==
null
)
{
log
.
error
(
"从数据库中无法获取ID为 {} 的文件数据"
,
id
);
return
;
return
;
}
}
BeanUtil
.
copyProperties
(
tmpRecordByTriggerMapper
.
selectById
(
id
),
appAbilityRecordAll
);
}
}
if
(
ObjUtil
.
isNotNull
(
appAbilityRecordAll
))
{
String
serverIp
=
appAbilityRecordAll
.
getServerIp
();
String
dstUrl
=
appAbilityRecordAll
.
getDstUrl
();
String
objName
=
appAbilityRecordAll
.
getPdf
();
if
(
StrUtil
.
isBlank
(
serverIp
)
||
StrUtil
.
isBlank
(
dstUrl
)
||
StrUtil
.
isBlank
(
objName
))
{
log
.
error
(
"获取到数据内容不全,无法拼接URL下载文件"
);
return
;
}
objName
=
objName
.
substring
(
0
,
objName
.
lastIndexOf
(
"."
))
+
".ofd"
;
// 构建MinIO文件的URL
String
fileUrl
=
"http://"
+
serverIp
+
":9000/"
+
dstUrl
+
"/"
+
objName
;
byte
[]
bytes
=
HttpUtil
.
downloadBytes
(
fileUrl
);
// 如果再次查询后结果仍为空,中止下载处理
response
.
getOutputStream
().
write
(
bytes
);
if
(
appAbilityRecordAll
==
null
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getServerIp
())
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getDstUrl
())
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getPdf
()))
{
log
.
error
(
"无法获取ID为 {} 的完整文件信息,中止下载处理"
,
id
);
return
;
}
// 构建MinIO文件的URL
String
serverIp
=
appAbilityRecordAll
.
getServerIp
();
String
dstUrl
=
appAbilityRecordAll
.
getDstUrl
();
String
objName
=
appAbilityRecordAll
.
getPdf
().
substring
(
0
,
appAbilityRecordAll
.
getPdf
().
lastIndexOf
(
"."
))
+
".ofd"
;
String
fileUrl
=
StrUtil
.
format
(
"http://{}:9000/{}/{}"
,
serverIp
,
dstUrl
,
objName
);
byte
[]
bytes
=
HttpUtil
.
downloadBytes
(
fileUrl
);
try
(
OutputStream
outputStream
=
response
.
getOutputStream
())
{
outputStream
.
write
(
bytes
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"
OCR云平台接口异常"
,
e
);
log
.
error
(
"
在处理ID为 {} 的PDF下载过程中发生异常"
,
id
,
e
);
returnError
(
response
,
500
,
"OCR云平台接口异常"
);
returnError
(
response
,
500
,
"OCR云平台接口异常"
);
}
}
}
}
...
@@ -388,20 +412,20 @@ public class RetransmissionService {
...
@@ -388,20 +412,20 @@ public class RetransmissionService {
public
OcrResult
fullTextRecognition
(
String
fileId
,
MultipartFile
file
,
HttpServletRequest
request
)
{
public
OcrResult
fullTextRecognition
(
String
fileId
,
MultipartFile
file
,
HttpServletRequest
request
)
{
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"fileId"
,
fileId
);
paramMap
.
put
(
"fileId"
,
fileId
);
File
tempFile
=
new
File
(
tempDir
,
System
.
currentTimeMillis
()
+
"_"
+
FileUtil
.
getName
(
file
.
getOriginalFilename
()));
String
tempSaveDir
=
tempDir
+
File
.
separator
+
IdUtil
.
fastSimpleUUID
()
+
"_"
+
System
.
currentTimeMillis
();
FileUtil
.
mkdir
(
tempSaveDir
);
File
tempFile
=
new
File
(
tempSaveDir
,
Objects
.
requireNonNull
(
FileUtil
.
getName
(
file
.
getOriginalFilename
())));
try
{
try
{
file
.
transferTo
(
tempFile
);
file
.
transferTo
(
tempFile
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
return
OcrResult
.
error
(
"异常!"
+
e
);
return
OcrResult
.
error
(
"异常!"
+
e
);
}
}
paramMap
.
put
(
"file"
,
tempFile
);
paramMap
.
put
(
"file"
,
tempFile
);
// ServerInfo ocrServerAddress = getOcrServerAddress();
ServerInfo
ocrServerAddress
=
getServerAddressByRequestCount
();
ServerInfo
ocrServerAddress
=
getServerAddressByRequestCount
();
if
(
ocrServerAddress
==
null
)
{
if
(
ocrServerAddress
==
null
)
{
return
OcrResult
.
error
(
"OCR云平台未配置服务器信息"
);
return
OcrResult
.
error
(
"OCR云平台未配置服务器信息"
);
}
}
// setOcrTask(ocrServerAddress.getIp());
// setActiveServer(ocrServerAddress.getIp());
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
1
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
1
);
String
ocrApi
=
"http://"
+
ocrServerAddress
.
getIp
()
+
":"
+
ocrServerAddress
.
getOcrPort
();
String
ocrApi
=
"http://"
+
ocrServerAddress
.
getIp
()
+
":"
+
ocrServerAddress
.
getOcrPort
();
...
@@ -417,16 +441,15 @@ public class RetransmissionService {
...
@@ -417,16 +441,15 @@ public class RetransmissionService {
// 设置结束时间
// 设置结束时间
long
endTime
=
System
.
currentTimeMillis
();
long
endTime
=
System
.
currentTimeMillis
();
// Assert.hasText(res, "请求接口返回为空");
if
(
StringUtils
.
isEmpty
(
res
))
{
if
(
StringUtils
.
isEmpty
(
res
))
{
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
null
,
ocrServerAddress
,
request
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
null
,
ocrServerAddress
,
request
);
return
new
OcrResult
(
"007500"
,
"识别失败,请重试"
,
null
,
DateUtil
.
date
());
return
new
OcrResult
(
"007500"
,
"识别失败,请重试"
,
null
,
DateUtil
.
date
());
}
}
FileUtil
.
del
(
temp
File
);
FileUtil
.
del
(
temp
SaveDir
);
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
());
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
()
,
fileId
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
return
result
;
return
result
;
}
}
...
@@ -434,20 +457,20 @@ public class RetransmissionService {
...
@@ -434,20 +457,20 @@ public class RetransmissionService {
public
OcrResult
fullTextRecognitionV2
(
String
fileId
,
MultipartFile
file
,
HttpServletRequest
request
)
{
public
OcrResult
fullTextRecognitionV2
(
String
fileId
,
MultipartFile
file
,
HttpServletRequest
request
)
{
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"fileId"
,
fileId
);
paramMap
.
put
(
"fileId"
,
fileId
);
File
tempFile
=
new
File
(
tempDir
,
System
.
currentTimeMillis
()
+
"_"
+
FileUtil
.
getName
(
file
.
getOriginalFilename
()));
String
tempSaveDir
=
tempDir
+
File
.
separator
+
IdUtil
.
fastSimpleUUID
()
+
"_"
+
System
.
currentTimeMillis
();
FileUtil
.
mkdir
(
tempSaveDir
);
File
tempFile
=
new
File
(
tempSaveDir
,
Objects
.
requireNonNull
(
FileUtil
.
getName
(
file
.
getOriginalFilename
())));
try
{
try
{
file
.
transferTo
(
tempFile
);
file
.
transferTo
(
tempFile
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
return
OcrResult
.
error
(
"异常!"
+
e
);
return
OcrResult
.
error
(
"异常!"
+
e
);
}
}
paramMap
.
put
(
"file"
,
tempFile
);
paramMap
.
put
(
"file"
,
tempFile
);
// ServerInfo ocrServerAddress = getOcrServerAddress();
ServerInfo
ocrServerAddress
=
getServerAddressByRequestCount
();
ServerInfo
ocrServerAddress
=
getServerAddressByRequestCount
();
if
(
ocrServerAddress
==
null
)
{
if
(
ocrServerAddress
==
null
)
{
return
OcrResult
.
error
(
"OCR云平台未配置服务器信息"
);
return
OcrResult
.
error
(
"OCR云平台未配置服务器信息"
);
}
}
// setOcrTask(ocrServerAddress.getIp());
// setActiveServer(ocrServerAddress.getIp());
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
1
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
1
);
String
ocrApi
=
"http://"
+
ocrServerAddress
.
getIp
()
+
":"
+
ocrServerAddress
.
getOcrPort
();
String
ocrApi
=
"http://"
+
ocrServerAddress
.
getIp
()
+
":"
+
ocrServerAddress
.
getOcrPort
();
...
@@ -463,16 +486,15 @@ public class RetransmissionService {
...
@@ -463,16 +486,15 @@ public class RetransmissionService {
// 设置结束时间
// 设置结束时间
long
endTime
=
System
.
currentTimeMillis
();
long
endTime
=
System
.
currentTimeMillis
();
// Assert.hasText(res, "请求接口返回为空");
if
(
StringUtils
.
isEmpty
(
res
))
{
if
(
StringUtils
.
isEmpty
(
res
))
{
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
null
,
ocrServerAddress
,
request
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
null
,
ocrServerAddress
,
request
);
return
new
OcrResult
(
"007500"
,
"识别失败,请重试"
,
null
,
DateUtil
.
date
());
return
new
OcrResult
(
"007500"
,
"识别失败,请重试"
,
null
,
DateUtil
.
date
());
}
}
FileUtil
.
del
(
temp
File
);
FileUtil
.
del
(
temp
SaveDir
);
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
());
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
()
,
fileId
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
return
result
;
return
result
;
}
}
...
@@ -480,20 +502,20 @@ public class RetransmissionService {
...
@@ -480,20 +502,20 @@ public class RetransmissionService {
public
OcrResult
cardRecognition
(
Integer
code
,
String
fileId
,
MultipartFile
file
,
HttpServletRequest
request
)
{
public
OcrResult
cardRecognition
(
Integer
code
,
String
fileId
,
MultipartFile
file
,
HttpServletRequest
request
)
{
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"fileId"
,
fileId
);
paramMap
.
put
(
"fileId"
,
fileId
);
File
tempFile
=
new
File
(
tempDir
,
System
.
currentTimeMillis
()
+
"_"
+
FileUtil
.
getName
(
file
.
getOriginalFilename
()));
String
tempSaveDir
=
tempDir
+
File
.
separator
+
IdUtil
.
fastSimpleUUID
()
+
"_"
+
System
.
currentTimeMillis
();
FileUtil
.
mkdir
(
tempSaveDir
);
File
tempFile
=
new
File
(
tempSaveDir
,
Objects
.
requireNonNull
(
FileUtil
.
getName
(
file
.
getOriginalFilename
())));
try
{
try
{
file
.
transferTo
(
tempFile
);
file
.
transferTo
(
tempFile
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
return
OcrResult
.
error
(
"异常!"
+
e
);
return
OcrResult
.
error
(
"异常!"
+
e
);
}
}
paramMap
.
put
(
"file"
,
tempFile
);
paramMap
.
put
(
"file"
,
tempFile
);
// ServerInfo ocrServerAddress = getOcrServerAddress();
ServerInfo
ocrServerAddress
=
getServerAddressByRequestCount
();
ServerInfo
ocrServerAddress
=
getServerAddressByRequestCount
();
if
(
ocrServerAddress
==
null
)
{
if
(
ocrServerAddress
==
null
)
{
return
OcrResult
.
error
(
"OCR云平台未配置服务器信息"
);
return
OcrResult
.
error
(
"OCR云平台未配置服务器信息"
);
}
}
// setOcrTask(ocrServerAddress.getIp());
// setActiveServer(ocrServerAddress.getIp());
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
1
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
1
);
String
ocrApi
=
"http://"
+
ocrServerAddress
.
getIp
()
+
":"
+
ocrServerAddress
.
getOcrPort
();
String
ocrApi
=
"http://"
+
ocrServerAddress
.
getIp
()
+
":"
+
ocrServerAddress
.
getOcrPort
();
...
@@ -508,16 +530,15 @@ public class RetransmissionService {
...
@@ -508,16 +530,15 @@ public class RetransmissionService {
// 设置结束时间
// 设置结束时间
long
endTime
=
System
.
currentTimeMillis
();
long
endTime
=
System
.
currentTimeMillis
();
// Assert.hasText(res, "请求接口返回为空");
if
(
StringUtils
.
isEmpty
(
res
))
{
if
(
StringUtils
.
isEmpty
(
res
))
{
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
null
,
ocrServerAddress
,
request
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
null
,
ocrServerAddress
,
request
);
return
new
OcrResult
(
"007500"
,
"识别失败,请重试"
,
null
,
DateUtil
.
date
());
return
new
OcrResult
(
"007500"
,
"识别失败,请重试"
,
null
,
DateUtil
.
date
());
}
}
FileUtil
.
del
(
temp
File
);
FileUtil
.
del
(
temp
SaveDir
);
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
());
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
()
,
fileId
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
return
result
;
return
result
;
}
}
...
@@ -531,13 +552,11 @@ public class RetransmissionService {
...
@@ -531,13 +552,11 @@ public class RetransmissionService {
body
.
set
(
"name"
,
name
);
body
.
set
(
"name"
,
name
);
body
.
set
(
"callback_url"
,
callback_url
);
body
.
set
(
"callback_url"
,
callback_url
);
body
.
set
(
"need_pdf"
,
need_pdf
);
body
.
set
(
"need_pdf"
,
need_pdf
);
// ServerInfo ocrServerAddress = getOcrServerAddress();
ServerInfo
ocrServerAddress
=
getServerAddressByRequestCount
();
ServerInfo
ocrServerAddress
=
getServerAddressByRequestCount
();
if
(
ocrServerAddress
==
null
)
{
if
(
ocrServerAddress
==
null
)
{
return
OcrResult
.
error
(
"OCR云平台未配置服务器信息"
);
return
OcrResult
.
error
(
"OCR云平台未配置服务器信息"
);
}
}
// setOcrTask(ocrServerAddress.getIp());
// setActiveServer(ocrServerAddress.getIp());
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
1
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
1
);
String
ocrApi
=
"http://"
+
ocrServerAddress
.
getIp
()
+
":"
+
ocrServerAddress
.
getOcrPort
();
String
ocrApi
=
"http://"
+
ocrServerAddress
.
getIp
()
+
":"
+
ocrServerAddress
.
getOcrPort
();
...
@@ -553,7 +572,6 @@ public class RetransmissionService {
...
@@ -553,7 +572,6 @@ public class RetransmissionService {
// 设置结束时间
// 设置结束时间
long
endTime
=
System
.
currentTimeMillis
();
long
endTime
=
System
.
currentTimeMillis
();
// Assert.hasText(res, "请求接口返回为空");
if
(
StringUtils
.
isEmpty
(
res
))
{
if
(
StringUtils
.
isEmpty
(
res
))
{
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
null
,
ocrServerAddress
,
request
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
null
,
ocrServerAddress
,
request
);
return
new
OcrResult
(
"007500"
,
"识别失败,请重试"
,
null
,
DateUtil
.
date
());
return
new
OcrResult
(
"007500"
,
"识别失败,请重试"
,
null
,
DateUtil
.
date
());
...
@@ -562,7 +580,7 @@ public class RetransmissionService {
...
@@ -562,7 +580,7 @@ public class RetransmissionService {
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
());
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
()
,
id
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
return
result
;
return
result
;
}
}
...
@@ -570,20 +588,21 @@ public class RetransmissionService {
...
@@ -570,20 +588,21 @@ public class RetransmissionService {
public
OcrResult
formatRestoration
(
String
fileId
,
MultipartFile
file
,
HttpServletRequest
request
)
{
public
OcrResult
formatRestoration
(
String
fileId
,
MultipartFile
file
,
HttpServletRequest
request
)
{
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"fileId"
,
fileId
);
paramMap
.
put
(
"fileId"
,
fileId
);
File
tempFile
=
new
File
(
tempDir
,
System
.
currentTimeMillis
()
+
"_"
+
FileUtil
.
getName
(
file
.
getOriginalFilename
()));
String
tempSaveDir
=
tempDir
+
File
.
separator
+
IdUtil
.
fastSimpleUUID
()
+
"_"
+
System
.
currentTimeMillis
();
FileUtil
.
mkdir
(
tempSaveDir
);
File
tempFile
=
new
File
(
tempSaveDir
,
Objects
.
requireNonNull
(
FileUtil
.
getName
(
file
.
getOriginalFilename
())));
try
{
try
{
file
.
transferTo
(
tempFile
);
file
.
transferTo
(
tempFile
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
return
OcrResult
.
error
(
"异常!"
+
e
);
return
OcrResult
.
error
(
"异常!"
+
e
);
}
}
paramMap
.
put
(
"file"
,
tempFile
);
paramMap
.
put
(
"file"
,
tempFile
);
// ServerInfo ocrServerAddress = getOcrServerAddress();
ServerInfo
ocrServerAddress
=
getServerAddressByRequestCount
();
ServerInfo
ocrServerAddress
=
getServerAddressByRequestCount
();
if
(
ocrServerAddress
==
null
)
{
if
(
ocrServerAddress
==
null
)
{
return
OcrResult
.
error
(
"OCR云平台未配置服务器信息"
);
return
OcrResult
.
error
(
"OCR云平台未配置服务器信息"
);
}
}
// setOcrTask(ocrServerAddress.getIp());
// setActiveServer(ocrServerAddress.getIp());
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
1
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
1
);
String
ocrApi
=
"http://"
+
ocrServerAddress
.
getIp
()
+
":"
+
ocrServerAddress
.
getOcrPort
();
String
ocrApi
=
"http://"
+
ocrServerAddress
.
getIp
()
+
":"
+
ocrServerAddress
.
getOcrPort
();
...
@@ -602,13 +621,12 @@ public class RetransmissionService {
...
@@ -602,13 +621,12 @@ public class RetransmissionService {
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
null
,
ocrServerAddress
,
request
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
null
,
ocrServerAddress
,
request
);
return
new
OcrResult
(
"007500"
,
"识别失败,请重试"
,
null
,
DateUtil
.
date
());
return
new
OcrResult
(
"007500"
,
"识别失败,请重试"
,
null
,
DateUtil
.
date
());
}
}
FileUtil
.
del
(
temp
File
);
FileUtil
.
del
(
temp
SaveDir
);
// Assert.hasText(res, "请求接口返回为空");
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
());
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
()
,
fileId
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
return
result
;
return
result
;
}
}
...
@@ -617,7 +635,9 @@ public class RetransmissionService {
...
@@ -617,7 +635,9 @@ public class RetransmissionService {
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"fileId"
,
fileId
);
paramMap
.
put
(
"fileId"
,
fileId
);
paramMap
.
put
(
"dstFileType"
,
dstFileType
);
paramMap
.
put
(
"dstFileType"
,
dstFileType
);
File
tempFile
=
new
File
(
tempDir
,
System
.
currentTimeMillis
()
+
"_"
+
srcFile
.
getOriginalFilename
());
String
tempSaveDir
=
tempDir
+
File
.
separator
+
IdUtil
.
fastSimpleUUID
()
+
"_"
+
System
.
currentTimeMillis
();
FileUtil
.
mkdir
(
tempSaveDir
);
File
tempFile
=
new
File
(
tempSaveDir
,
Objects
.
requireNonNull
(
FileUtil
.
getName
(
srcFile
.
getOriginalFilename
())));
try
{
try
{
srcFile
.
transferTo
(
tempFile
);
srcFile
.
transferTo
(
tempFile
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
@@ -648,7 +668,7 @@ public class RetransmissionService {
...
@@ -648,7 +668,7 @@ public class RetransmissionService {
response
.
setHeader
(
entry
.
getKey
(),
entry
.
getValue
().
get
(
0
));
response
.
setHeader
(
entry
.
getKey
(),
entry
.
getValue
().
get
(
0
));
}
}
}
}
FileUtil
.
del
(
temp
File
);
FileUtil
.
del
(
temp
SaveDir
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
// 赋值body
// 赋值body
IoUtil
.
copy
(
httpResponse
.
bodyStream
(),
response
.
getOutputStream
());
IoUtil
.
copy
(
httpResponse
.
bodyStream
(),
response
.
getOutputStream
());
...
@@ -660,11 +680,11 @@ public class RetransmissionService {
...
@@ -660,11 +680,11 @@ public class RetransmissionService {
}
}
@Async
(
"dataPersistThreadPoolTaskExecutor"
)
@Async
(
"dataPersistThreadPoolTaskExecutor"
)
public
void
saveToAppAbilityRecordAll
(
OcrResult
result
,
HttpServletRequest
request
,
String
serverIp
)
{
public
void
saveToAppAbilityRecordAll
(
OcrResult
result
,
HttpServletRequest
request
,
String
serverIp
,
String
fileId
)
{
try
{
try
{
String
clientIP
=
ServletUtil
.
getClientIP
(
request
);
String
clientIP
=
ServletUtil
.
getClientIP
(
request
);
if
(
Objects
.
equals
(
result
.
getCode
(),
"000000"
))
{
if
(
Objects
.
equals
(
result
.
getCode
(),
"000000"
))
{
log
.
info
(
"调用成功,开始持久化存储..."
);
//
log.info("调用成功,开始持久化存储...");
JSONObject
info
=
JSONUtil
.
parseObj
(
result
.
getData
());
JSONObject
info
=
JSONUtil
.
parseObj
(
result
.
getData
());
Long
id
=
info
.
getLong
(
"sid"
);
Long
id
=
info
.
getLong
(
"sid"
);
...
@@ -678,7 +698,7 @@ public class RetransmissionService {
...
@@ -678,7 +698,7 @@ public class RetransmissionService {
handleRecord
(
record8Mapper
,
id
,
clientIP
,
serverIp
);
handleRecord
(
record8Mapper
,
id
,
clientIP
,
serverIp
);
handleRecord
(
record9Mapper
,
id
,
clientIP
,
serverIp
);
handleRecord
(
record9Mapper
,
id
,
clientIP
,
serverIp
);
}
else
{
}
else
{
log
.
error
(
"请求OCR接口错误{}
"
,
result
);
log
.
error
(
"请求OCR接口错误{}
, fileId={}"
,
result
,
fileId
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"数据{}保存发生异常!"
,
result
,
e
);
log
.
error
(
"数据{}保存发生异常!"
,
result
,
e
);
...
@@ -691,7 +711,7 @@ public class RetransmissionService {
...
@@ -691,7 +711,7 @@ public class RetransmissionService {
return
;
return
;
}
}
record
.
setIp
(
clientIP
);
record
.
setIp
(
clientIP
);
log
.
info
(
"修改id:{}的真实客户端请求ip结果:{}"
,
id
,
mapper
.
updateById
(
record
));
//
log.info("修改id:{}的真实客户端请求ip结果:{}", id, mapper.updateById(record));
AppAbilityRecordAll
recordAll
=
recordAllMapper
.
selectById
(
id
);
AppAbilityRecordAll
recordAll
=
recordAllMapper
.
selectById
(
id
);
if
(
recordAll
==
null
)
{
if
(
recordAll
==
null
)
{
recordAll
=
new
AppAbilityRecordAll
();
recordAll
=
new
AppAbilityRecordAll
();
...
@@ -701,7 +721,7 @@ public class RetransmissionService {
...
@@ -701,7 +721,7 @@ public class RetransmissionService {
if
(
StrUtil
.
isEmpty
(
recordAll
.
getServerIp
()))
{
if
(
StrUtil
.
isEmpty
(
recordAll
.
getServerIp
()))
{
recordAll
.
setServerIp
(
serverIp
);
recordAll
.
setServerIp
(
serverIp
);
}
}
log
.
info
(
"添加id:{} 的数据到recordAll持久化保存结果:{}"
,
recordAll
.
getId
(),
recordAllMapper
.
insert
(
recordAll
));
//
log.info("添加id:{} 的数据到recordAll持久化保存结果:{}", recordAll.getId(), recordAllMapper.insert(recordAll));
}
else
{
}
else
{
AppAbilityRecordAll
newRecordAll
=
new
AppAbilityRecordAll
();
AppAbilityRecordAll
newRecordAll
=
new
AppAbilityRecordAll
();
BeanUtils
.
copyProperties
(
record
,
newRecordAll
,
AppAbilityRecordAll
.
class
);
BeanUtils
.
copyProperties
(
record
,
newRecordAll
,
AppAbilityRecordAll
.
class
);
...
@@ -709,7 +729,7 @@ public class RetransmissionService {
...
@@ -709,7 +729,7 @@ public class RetransmissionService {
if
(
StrUtil
.
isEmpty
(
newRecordAll
.
getServerIp
()))
{
if
(
StrUtil
.
isEmpty
(
newRecordAll
.
getServerIp
()))
{
newRecordAll
.
setServerIp
(
serverIp
);
newRecordAll
.
setServerIp
(
serverIp
);
}
}
log
.
info
(
"修改recordAll中id:{} 的数据结果:{}"
,
newRecordAll
.
getId
(),
recordAllMapper
.
updateById
(
newRecordAll
));
//
log.info("修改recordAll中id:{} 的数据结果:{}", newRecordAll.getId(), recordAllMapper.updateById(newRecordAll));
}
}
}
}
...
...
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