Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
customer-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QG
customer-service
Commits
23fbc1ba
Commit
23fbc1ba
authored
Mar 05, 2022
by
吴琼
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xiugai
parent
343364b4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
3 deletions
+57
-3
TransactionReceiptRecordRest.java
...uantgroup/customer/rest/TransactionReceiptRecordRest.java
+2
-0
ITransactionReceiptRecordService.java
...up/customer/service/ITransactionReceiptRecordService.java
+2
-0
TransactionReceiptRecordServiceImpl.java
...mer/service/impl/TransactionReceiptRecordServiceImpl.java
+53
-3
No files found.
src/main/java/cn/quantgroup/customer/rest/TransactionReceiptRecordRest.java
View file @
23fbc1ba
...
...
@@ -61,6 +61,7 @@ public class TransactionReceiptRecordRest {
try
{
return
transactionReceiptRecordService
.
importTransactionReceiptRecord
(
file
);
}
catch
(
Exception
e
){
transactionReceiptRecordService
.
deleteRedis
(
"importTransactionReceiptRecord"
);
return
JsonResult
.
buildErrorStateResult
(
e
.
getMessage
());
}
}
...
...
@@ -90,6 +91,7 @@ public class TransactionReceiptRecordRest {
try
{
return
transactionReceiptRecordService
.
exportZipFile
(
request
,
response
);
}
catch
(
Exception
e
){
transactionReceiptRecordService
.
deleteRedis
(
"exportZipFile"
);
return
JsonResult
.
buildErrorStateResult
(
"导出文件出现错误"
);
}
...
...
src/main/java/cn/quantgroup/customer/service/ITransactionReceiptRecordService.java
View file @
23fbc1ba
...
...
@@ -24,4 +24,6 @@ public interface ITransactionReceiptRecordService {
void
generatePDF
(
TransactionReceiptVO
transactionReceiptVO
,
String
filePath
);
void
deleteRedis
(
String
str
);
}
src/main/java/cn/quantgroup/customer/service/impl/TransactionReceiptRecordServiceImpl.java
View file @
23fbc1ba
...
...
@@ -43,6 +43,7 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
sun.misc.IOUtils
;
...
...
@@ -100,6 +101,9 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
@Value
(
"${customer.transaction.local.file.limit}"
)
private
int
limit
;
@Autowired
private
RedisTemplate
<
String
,
Object
>
redisTemplate
;
@Override
public
JsonResult
<
Page
<
TransactionReceiptRecordVO
>>
findRecordsByQuery
(
TransactionReceiptRecordQuery
query
)
{
...
...
@@ -112,12 +116,11 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
}
if
(
StringUtils
.
isNotEmpty
(
query
.
getImportStatus
()))
{
predicates
.
add
(
criteriaBuilder
.
equal
(
root
.
get
(
"importStatus"
),
query
.
getImportStatus
()));
}
else
{
predicates
.
add
(
criteriaBuilder
.
equal
(
root
.
get
(
"importStatus"
),
1
));
}
if
(
StringUtils
.
isNotEmpty
(
query
.
getExportStatus
()))
{
predicates
.
add
(
criteriaBuilder
.
equal
(
root
.
get
(
"exportStatus"
),
query
.
getExportStatus
()));
}
else
{
predicates
.
add
(
criteriaBuilder
.
equal
(
root
.
get
(
"exportStatus"
),
1
));
}
// 设置查询条件
criteriaQuery
.
where
(
criteriaBuilder
.
and
(
predicates
.
toArray
(
new
Predicate
[
predicates
.
size
()])));
...
...
@@ -146,9 +149,37 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
}
}
/**
*校验是否有其他人在导入、导出
*/
private
String
checkRedis
(
String
str
){
log
.
info
(
"redis add TransactionReceiptRecordServiceImpl."
+
str
+
".userId"
,
redisTemplate
);
String
obj
=
(
String
)
redisTemplate
.
opsForValue
().
get
(
"TransactionReceiptRecordServiceImpl."
+
str
+
".userId"
);
if
(
StringUtils
.
isBlank
(
obj
)){
redisTemplate
.
opsForValue
().
set
(
"TransactionReceiptRecordServiceImpl."
+
str
+
"..userId"
,
str
);
return
""
;
}
return
obj
;
}
/**
* 删除redis中的值
*/
public
void
deleteRedis
(
String
str
){
log
.
info
(
"redis delete TransactionReceiptRecordServiceImpl."
+
str
+
".userId"
,
redisTemplate
);
String
obj
=
(
String
)
redisTemplate
.
opsForValue
().
get
(
"TransactionReceiptRecordServiceImpl."
+
str
+
".userId"
);
if
(
StringUtils
.
isNotBlank
(
obj
)){
redisTemplate
.
opsForValue
().
set
(
"TransactionReceiptRecordServiceImpl."
+
str
+
"..userId"
,
""
);
}
}
@Override
@Transactional
public
JsonResult
importTransactionReceiptRecord
(
MultipartFile
file
)
throws
RuntimeException
{
String
str
=
checkRedis
(
"importTransactionReceiptRecord"
);
if
(
StringUtils
.
isNotBlank
(
str
)){
throw
new
RuntimeException
(
"只能一个人导入,当前有其他人正在导入,请稍后重试"
);
}
log
.
info
(
"[TransactionReceiptRecordServiceImpl importTransactionReceiptRecord] end,query={} "
,
file
);
//查询未导出数据最大批次号
Integer
maxBatchNo
=
transactionReceiptRecordRepo
.
findMaxBatchNo
(
0
);
...
...
@@ -163,12 +194,15 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
try
{
readList
=
read
(
file
.
getOriginalFilename
(),
file
.
getInputStream
());
if
(
CollectionUtils
.
isEmpty
(
readList
)){
deleteRedis
(
"importTransactionReceiptRecord"
);
throw
new
RuntimeException
(
"文件中没有数据"
);
}
if
(
readList
!=
null
&&
readList
.
size
()
>
fileSize
){
deleteRedis
(
"importTransactionReceiptRecord"
);
throw
new
RuntimeException
(
"文件太大,最多可以读取"
+
fileSize
+
"条数据!"
);
}
}
catch
(
IOException
e
)
{
deleteRedis
(
"importTransactionReceiptRecord"
);
throw
new
RuntimeException
(
"读取数据异常"
);
}
long
end
=
System
.
currentTimeMillis
();
...
...
@@ -187,6 +221,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
List
<
TransactionReceiptRecord
>
records
=
transactionReceiptRecordRepo
.
selectRecordsByOrderNo
(
record
.
getOrderNo
(),
record
.
getUserId
(),
record
.
getUserName
());
if
(
CollectionUtils
.
isNotEmpty
(
records
)){
deleteRedis
(
"importTransactionReceiptRecord"
);
throw
new
RuntimeException
(
"存在userid为"
+
record
.
getUserId
()+
",姓名为"
+
record
.
getUserName
()+
",交易单号为"
+
record
.
getOrderNo
()+
"数据还未导出,不能再次导入"
);
}
//保存时如果有其中一项为空则默认为导入失败,其他则默认初始状态
...
...
@@ -208,6 +243,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
log
.
info
(
"TransactionReceiptRecordServiceImpl importTransactionReceiptRecord save end"
);
return
updateTransactionRecordsStatus
();
}
deleteRedis
(
"importTransactionReceiptRecord"
);
return
JsonResult
.
buildErrorStateResult
(
"未读取到数据或读取失败"
);
}
...
...
@@ -284,12 +320,17 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
//导出zip压缩包文件
@Transactional
public
JsonResult
exportZipFile
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
RuntimeException
{
String
str
=
checkRedis
(
"exportZipFile"
);
if
(
StringUtils
.
isNotBlank
(
str
)){
throw
new
RuntimeException
(
"只能一个人导出,当前有其他人正在导出,请稍后重试"
);
}
//调用电商接口获取对应数据
log
.
info
(
"[TransactionReceiptRecordServiceImpl.exportZipFile begin]"
);
//查询需要导出的数据-导入成功的数据,但未导出成功的数据
List
<
TransactionReceiptRecord
>
transactionReceiptRecordList
=
transactionReceiptRecordRepo
.
selectRecordsByImportStatusAndExportStatus
(
1
,
limit
);
log
.
info
(
"[TransactionReceiptRecordServiceImpl.exportZipFile transactionReceiptRecordList] 可导出数据为:"
,
transactionReceiptRecordList
.
size
());
if
(
CollectionUtils
.
isEmpty
(
transactionReceiptRecordList
)){
deleteRedis
(
"exportZipFile"
);
return
JsonResult
.
buildErrorStateResult
(
"没有可以导出得数据"
);
}
//查询导入成功数据的导出的最大批次号
...
...
@@ -326,6 +367,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
log
.
info
(
"调用kdsp查询订单接口返回结果,result:"
,
result
);
//转换成json 对象
if
(
StringUtils
.
isBlank
(
result
)){
deleteRedis
(
"exportZipFile"
);
throw
new
RuntimeException
(
"未查询到订单数据"
);
}
JSONObject
json
=
JSONObject
.
parseObject
(
result
);
...
...
@@ -372,6 +414,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
filePathList
.
add
(
map
);
}
}
catch
(
Exception
e
)
{
deleteRedis
(
"exportZipFile"
);
log
.
error
(
"[TransactionReceiptRecordServiceImpl][exportZipFile] 网络通讯异常,userId:{},ex:{}"
,
ExceptionUtils
.
getStackTrace
(
e
));
return
JsonResult
.
buildErrorStateResult
(
e
.
getMessage
());
}
...
...
@@ -381,6 +424,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
log
.
info
(
"[TransactionReceiptRecordServiceImpl.kdspOperationUrl 调用kdsp-op 接口end]"
,
System
.
currentTimeMillis
());
//调用签章接口
if
(
filePathList
.
isEmpty
()){
deleteRedis
(
"exportZipFile"
);
throw
new
RuntimeException
(
"没有可以导出的数据"
);
}
log
.
info
(
"contractUrl /contract/batch/sign 调用签章接口"
);
...
...
@@ -394,6 +438,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
String
jsonResult
=
json
.
getString
(
"data"
);
String
businessCode
=
json
.
getString
(
"businessCode"
);
if
(!
"0000"
.
equals
(
businessCode
)){
deleteRedis
(
"exportZipFile"
);
throw
new
RuntimeException
(
"签章失败!"
);
}
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
jsonResult
);
...
...
@@ -420,6 +465,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
}
}
else
{
sftpUtil
.
logout
();
deleteRedis
(
"exportZipFile"
);
throw
new
RuntimeException
(
"签章失败!"
);
}
//更新数据
...
...
@@ -456,6 +502,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
deleteDirectory
(
deleteFile1
);
return
JsonResult
.
buildSuccessResult
(
"ok"
,
map
);
}
catch
(
Exception
e
)
{
deleteRedis
(
"exportZipFile"
);
throw
new
RuntimeException
(
"文件转换失败"
);
}
}
...
...
@@ -593,6 +640,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
JSONObject
kJson
=
JSONObject
.
parseObject
(
kResult
);
String
businessCode
=
kJson
.
getString
(
"businessCode"
);
if
(!
"0000"
.
equals
(
businessCode
)){
deleteRedis
(
"importTransactionReceiptRecord"
);
throw
new
RuntimeException
(
"调用电商接口报错"
);
}
log
.
error
(
"TransactionReceiptRecordServiceImpl updateTransactionRecordsStatus 调用商城接口 end"
);
...
...
@@ -616,6 +664,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
failList
.
add
(
record
);
}
}
catch
(
Exception
e
){
deleteRedis
(
"importTransactionReceiptRecord"
);
throw
new
RuntimeException
(
"调用接口报错"
);
}
}
...
...
@@ -628,6 +677,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
}
log
.
error
(
"TransactionReceiptRecordServiceImpl updateTransactionRecordsStatus 校验更新数据 end"
);
}
deleteRedis
(
"importTransactionReceiptRecord"
);
return
JsonResult
.
buildSuccessResult
(
"数据导入成功"
,
null
);
}
...
...
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