Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zhj-report
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
data-spider
zhj-report
Commits
d37a3632
Commit
d37a3632
authored
Nov 04, 2019
by
董建华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
数据上报
parent
94234edd
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
458 additions
and
154 deletions
+458
-154
QgException.java
src/main/java/com/QgException.java
+46
-0
ReportController.java
src/main/java/com/controller/ReportController.java
+161
-0
ReportService.java
src/main/java/com/service/report/ReportService.java
+7
-3
IReportServiceImpl.java
...main/java/com/service/report/impl/IReportServiceImpl.java
+182
-133
ReportTimer.java
src/main/java/com/timer/ReportTimer.java
+37
-16
DingTalk.java
src/main/java/com/util/DingTalk.java
+20
-0
Utils.java
src/main/java/com/util/Utils.java
+5
-2
No files found.
src/main/java/com/QgException.java
0 → 100644
View file @
d37a3632
package
com
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
/**
* @author :dongjianhua
* @date :Created in 2019/11/4 10:38
* @description:异常类
* @modified By:
* @version: 1.0
*/
public
class
QgException
extends
RuntimeException
{
//提醒标题
public
String
alarm
;
//堆栈信息 或者报错信息
public
String
message
;
public
QgException
(
String
exMsg
)
{
alarm
=
exMsg
;
}
public
QgException
(
String
exMsg
,
String
message
)
{
alarm
=
exMsg
;
this
.
message
=
message
;
}
public
QgException
(
String
exMsg
,
Exception
e
)
{
super
(
e
);
alarm
=
exMsg
;
message
=
getStackTrace
(
e
);
}
public
static
String
getStackTrace
(
Throwable
t
)
{
StringWriter
sw
=
new
StringWriter
();
PrintWriter
pw
=
new
PrintWriter
(
sw
);
try
{
t
.
printStackTrace
(
pw
);
return
sw
.
toString
();
}
finally
{
pw
.
close
();
}
}
}
src/main/java/com/controller/ReportController.java
0 → 100644
View file @
d37a3632
package
com
.
controller
;
import
com.QgException
;
import
com.alibaba.fastjson.JSONArray
;
import
com.emums.BusinessType
;
import
com.emums.InfoType
;
import
com.entity.FileEntry
;
import
com.service.report.ReportService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author :dongjianhua
* @date :Created in 2019/11/4 15:30
* @description:数据上报控制器
* @modified By:
* @version: 1.0
*/
@Slf4j
@RestController
@RequestMapping
(
"report"
)
public
class
ReportController
{
@Autowired
private
ReportService
reportService
;
@RequestMapping
(
"/upDataByJson"
)
public
Map
<
String
,
Object
>
upDataByJson
(
String
json
,
String
type
)
{
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
List
<
Map
<
String
,
Object
>>
maps
=
(
List
<
Map
<
String
,
Object
>>)
JSONArray
.
parse
(
json
);
BusinessType
[]
values
=
BusinessType
.
values
();
BusinessType
btype
=
null
;
for
(
BusinessType
value
:
values
)
{
if
(
value
.
getCode
().
equals
(
type
))
{
btype
=
value
;
break
;
}
}
try
{
FileEntry
fileEntry
=
reportService
.
creatZipFile
(
maps
,
InfoType
.
CREDIT_FINANCING_INFO
,
btype
);
reportService
.
reportData
(
fileEntry
);
}
catch
(
QgException
e
)
{
log
.
error
(
"数据上报失败: {} ,e: {}"
,
e
.
alarm
,
e
);
result
.
put
(
"msg"
,
"上报失败,"
+
e
.
alarm
);
return
result
;
}
catch
(
Exception
e
)
{
log
.
error
(
"数据上报失败,系统异常 ,e: {}"
,
e
);
result
.
put
(
"msg"
,
"上报失败,系统异常"
);
return
result
;
}
result
.
put
(
"msg"
,
"上报成功"
);
return
result
;
}
@RequestMapping
(
"/dowloadFile"
)
public
void
dowloadFile
(
String
filePath
,
HttpServletResponse
response
)
throws
Exception
{
File
file
=
new
File
(
getPath
(
filePath
));
if
(!
file
.
exists
())
{
throw
new
Exception
(
"文件不存在"
);
}
FileInputStream
in
=
null
;
ServletOutputStream
outputStream
=
null
;
try
{
String
fileName
=
new
String
(
file
.
getName
().
getBytes
(
"gbk"
),
"iso-8859-1"
);
// 设置response的编码方式
response
.
setContentType
(
"application/x-msdownload"
);
// 设置附加文件名
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
fileName
);
in
=
new
FileInputStream
(
file
);
outputStream
=
response
.
getOutputStream
();
byte
[]
bytes
=
new
byte
[
512
];
int
len
=
0
;
while
((
len
=
in
.
read
(
bytes
))
!=
-
1
)
{
outputStream
.
write
(
bytes
,
0
,
len
);
}
outputStream
.
flush
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
in
!=
null
)
{
in
.
close
();
}
if
(
outputStream
!=
null
)
{
outputStream
.
close
();
}
}
catch
(
Exception
e
)
{
log
.
error
(
"下载文件出错,e: {} "
,
e
);
}
}
}
@RequestMapping
(
"/quaryReportedStatus"
)
public
Map
<
String
,
Object
>
searchMap
(
FileEntry
fileEntry
)
{
fileEntry
.
setFilePath
(
getPath
(
fileEntry
.
getFilePath
()));
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
try
{
reportService
.
quaryReportedStatus
(
fileEntry
);
}
catch
(
QgException
e
)
{
log
.
error
(
"查询上报状态失败,e: {} "
,
e
);
result
.
put
(
"msg"
,
e
.
alarm
);
return
result
;
}
catch
(
Exception
e
)
{
log
.
error
(
"查询上报状态异常,e: {} "
,
e
);
result
.
put
(
"msg"
,
"查询上报状态异常"
);
return
result
;
}
result
.
put
(
"msg"
,
"查询成功"
);
return
result
;
}
@RequestMapping
(
"/upDataByFile"
)
public
Map
<
String
,
Object
>
upDataByFile
(
@RequestParam
(
"file"
)
MultipartFile
file
,
String
type
)
{
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
BusinessType
[]
values
=
BusinessType
.
values
();
BusinessType
btype
=
null
;
for
(
BusinessType
value
:
values
)
{
if
(
value
.
getCode
().
equals
(
type
))
{
btype
=
value
;
break
;
}
}
try
{
FileEntry
fileEntry
=
reportService
.
creatZipFileByFile
(
file
,
InfoType
.
CREDIT_FINANCING_INFO
,
btype
);
reportService
.
reportData
(
fileEntry
);
}
catch
(
QgException
e
)
{
log
.
error
(
"数据上报失败: {} ,e: {}"
,
e
.
alarm
,
e
);
result
.
put
(
"msg"
,
"上报失败,"
+
e
.
alarm
);
return
result
;
}
catch
(
Exception
e
)
{
log
.
error
(
"数据上报失败,系统异常 ,e: {}"
,
e
);
result
.
put
(
"msg"
,
"上报失败,系统异常"
);
return
result
;
}
result
.
put
(
"msg"
,
"上报成功"
);
return
result
;
}
public
String
getPath
(
String
old
){
String
[]
split
=
old
.
split
(
"-"
);
StringBuffer
sb
=
new
StringBuffer
();
for
(
String
str
:
split
)
{
sb
.
append
(
str
).
append
(
File
.
separator
);
}
return
sb
.
substring
(
0
,
sb
.
length
()
-
1
);
}
}
src/main/java/com/service/report/ReportService.java
View file @
d37a3632
package
com
.
service
.
report
;
import
com.QgException
;
import
com.emums.BusinessType
;
import
com.emums.InfoType
;
import
com.entity.FileEntry
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.util.List
;
import
java.util.Map
;
public
interface
ReportService
{
FileEntry
creatZipFile
(
List
<
Map
<
String
,
Object
>>
dataList
,
InfoType
infoType
,
BusinessType
businessType
);
FileEntry
creatZipFile
(
List
<
Map
<
String
,
Object
>>
dataList
,
InfoType
infoType
,
BusinessType
businessType
)
throws
QgException
;
FileEntry
creatZipFileByFile
(
MultipartFile
file
,
InfoType
infoType
,
BusinessType
businessType
)
throws
QgException
;
Map
<
String
,
Object
>
reportData
(
FileEntry
fileEntry
)
;
void
reportData
(
FileEntry
fileEntry
)
throws
QgException
;
void
quaryReportedStatus
();
Map
<
String
,
Object
>
quaryReportedStatus
(
FileEntry
fileEntry
)
;
void
quaryReportedStatus
(
FileEntry
fileEntry
)
throws
QgException
;
//上报日放款数据
void
reportLoanDayData
();
...
...
src/main/java/com/service/report/impl/IReportServiceImpl.java
View file @
d37a3632
This diff is collapsed.
Click to expand it.
src/main/java/com/timer/ReportTimer.java
View file @
d37a3632
...
...
@@ -26,6 +26,8 @@ public class ReportTimer {
private
static
boolean
isRun
=
false
;
private
static
boolean
dayReportIsRunning
=
false
;
private
static
boolean
monReportIsRunning
=
false
;
@PostConstruct
public
void
init
()
{
...
...
@@ -34,32 +36,51 @@ public class ReportTimer {
isRun
=
true
;
}
}
//每天凌晨2点
@Scheduled
(
cron
=
"0 0 2 * * ? *"
)
void
reportDayData
(){
if
(!
isRun
){
return
;
@Scheduled
(
cron
=
"0 0 2 * * ?"
)
void
reportDayData
()
{
if
(!
isRun
)
{
return
;
}
dayReportIsRunning
=
true
;
try
{
//上报日放款数据
reportService
.
reportLoanDayData
();
//上报日还款数据
reportService
.
reportRepayDayData
();
//上报日逾期数据
reportService
.
reportOverDayData
();
}
finally
{
dayReportIsRunning
=
false
;
}
//上报日放款数据
reportService
.
reportLoanDayData
();
//上报日还款数据
reportService
.
reportRepayDayData
();
//上报日逾期数据
reportService
.
reportOverDayData
();
}
//每月1次
@Scheduled
(
cron
=
"0 0 3 1 1/1 ?"
)
void
reportMonthData
(){
if
(!
isRun
){
return
;
void
reportMonthData
()
{
if
(!
isRun
)
{
return
;
}
monReportIsRunning
=
true
;
try
{
//上报月逾期数据
reportService
.
reportOverMonthData
();
}
finally
{
monReportIsRunning
=
false
;
}
//上报月逾期数据
reportService
.
reportOverMonthData
();
}
//一小时一次
@Scheduled
(
fixedDelay
=
1000
*
60
*
60
)
public
void
quaryReportedStatus
()
{
if
(!
isRun
){
if
(!
isRun
)
{
return
;
}
if
(
monReportIsRunning
||
dayReportIsRunning
){
return
;
}
reportService
.
quaryReportedStatus
();
...
...
src/main/java/com/util/DingTalk.java
View file @
d37a3632
package
com
.
util
;
import
com.QgException
;
import
com.service.http.IHttpService
;
import
com.sun.jersey.api.client.ClientResponse
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -57,4 +58,23 @@ public class DingTalk {
String
resp
=
iHttpService
.
post
(
talkUri
,
param
);
log
.
info
(
"测试钉钉报警接口结果!resp:{}"
,
resp
);
}
@Async
public
void
talk
(
String
msgTitle
,
QgException
e
)
{
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"webhook"
,
webHook
);
param
.
put
(
"alarmLevel"
,
"Warn"
);
param
.
put
(
"msgTitle"
,
"数据上报:"
+
msgTitle
);
param
.
put
(
"msgContent"
,
exceptionToString
(
e
));
// param.put("toUsers", "15542661376,18612632691");
String
resp
=
iHttpService
.
post
(
talkUri
,
param
);
log
.
info
(
"测试钉钉报警接口结果!resp:{}"
,
resp
);
}
public
String
exceptionToString
(
QgException
e
)
{
return
new
StringBuffer
()
.
append
(
e
.
alarm
)
.
append
(
":"
)
.
append
(
e
.
message
==
null
?
""
:
(
e
.
message
.
length
()
>
500
?
e
.
message
.
substring
(
0
,
499
)
:
e
.
message
)).
toString
();
}
}
src/main/java/com/util/Utils.java
View file @
d37a3632
package
com
.
util
;
import
com.QgException
;
import
com.cfcc.jaf.crypto.CryptoUtil
;
import
com.cfcc.jaf.crypto.sm.SMUtil
;
import
com.config.ReportConfig
;
...
...
@@ -79,7 +80,7 @@ public class Utils {
/**
* 字符串转md5
*
* @param
psw
* @param
* @return
*/
public
String
string2Md5
(
String
string
)
{
...
...
@@ -141,7 +142,6 @@ public class Utils {
// 公钥2
byte
[]
puby
=
CryptoUtil
.
toByteArray
(
reportConfig
.
getYPubKey
());
ECPoint
pubKey
=
SMUtil
.
createECPoint
(
pubx
,
puby
);
;
//需要加密文件
File
file
=
new
File
(
sourceFile
);
//把文件变成直接数组
...
...
@@ -156,6 +156,7 @@ public class Utils {
CryptoUtil
.
writeFile
(
b2
,
file2
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
QgException
(
"zip转enc失败"
,
e
);
}
return
file2
;
}
...
...
@@ -190,6 +191,7 @@ public class Utils {
CryptoUtil
.
writeFile
(
prb2
,
file3
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
QgException
(
"国密解密 env转zip异常"
,
e
);
}
return
file3
;
}
...
...
@@ -210,6 +212,7 @@ public class Utils {
encodeBase64String
=
Base64
.
encodeBase64String
(
buffer
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
throw
new
QgException
(
"读取file 转为base64字符串异常"
,
e
);
}
return
encodeBase64String
;
}
...
...
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