Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
task3.0
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
首航-临时账号
task3.0
Commits
239a824a
Commit
239a824a
authored
Sep 23, 2019
by
zt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改
parent
e6487870
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
221 additions
and
39 deletions
+221
-39
DbSoundsMonitorTask.java
src/main/java/com/foc/DbSoundsMonitorTask.java
+3
-25
SoundsMaxIdDao.java
src/main/java/com/foc/dao/SoundsMaxIdDao.java
+42
-0
FocSmsEmailRecord.java
src/main/java/com/foc/entity/FocSmsEmailRecord.java
+36
-0
SoundMonitorService.java
src/main/java/com/foc/service/SoundMonitorService.java
+114
-13
SoundsMaxIdMapper.xml
src/main/resources/mapper/SoundsMaxIdMapper.xml
+25
-0
mybatis-config.xml
src/main/resources/mybatis-config.xml
+1
-1
No files found.
src/main/java/com/foc/DbSoundsMonitorTask.java
View file @
239a824a
...
@@ -11,10 +11,7 @@ import com.foc.util.PropertiesUtils;
...
@@ -11,10 +11,7 @@ import com.foc.util.PropertiesUtils;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
java.time.Instant
;
import
java.time.Instant
;
import
java.time.ZoneId
;
import
java.util.Date
;
import
java.util.Properties
;
import
java.util.Properties
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
...
@@ -51,34 +48,15 @@ public class DbSoundsMonitorTask {
...
@@ -51,34 +48,15 @@ public class DbSoundsMonitorTask {
String
aicc
=
properties
.
getProperty
(
"aicc"
);
String
aicc
=
properties
.
getProperty
(
"aicc"
);
String
aicp
=
properties
.
getProperty
(
"aicp"
);
String
aicp
=
properties
.
getProperty
(
"aicp"
);
String
resultCode
=
properties
.
getProperty
(
"resultCode"
);
String
resultCode
=
properties
.
getProperty
(
"resultCode"
);
String
mobile
=
properties
.
getProperty
(
"mobile"
);
//查看定时任务最后同步时间
//查看定时任务最后同步时间
SoundMonitorService
.
init
();
SoundMonitorService
.
init
();
boolean
i
=
SoundMonitorService
.
test
();
boolean
i
=
SoundMonitorService
.
test
();
if
(!
i
){
if
(!
i
){
log
.
info
(
"没有异常!"
);
log
.
info
(
"没有异常!"
);
}
}
//发送短信
//发送邮件和短信
AccessInfo
accessInfo
=
new
AccessInfo
();
SoundMonitorService
.
SendEmailAndSms
(
aicc
,
aicp
,
resultCode
,
mobile
);
accessInfo
.
setAicc
(
aicc
);
accessInfo
.
setAicp
(
aicp
);
//发送短信
String
result
=
Sms
.
sendSms
(
accessInfo
,
properties
.
getProperty
(
"mobile"
),
"预警:智能首航录音记录显示异常,请处理。"
);
//发送邮件
String
emailResult
=
Email
.
sendEmail
(
"录音记录预警"
,
"智能首航录音记录显示异常,请处理。"
);
EmailResult
emailResult1
=
JSON
.
parseObject
(
emailResult
,
EmailResult
.
class
);
//当前时间
Instant
now
=
Instant
.
now
().
plusMillis
(
TimeUnit
.
HOURS
.
toMillis
(
8
));
if
(
emailResult1
.
getResult
().
getResultCode
().
equals
(
resultCode
)){
log
.
info
(
"邮件发送成功,Time:{},result:{}"
,
now
,
result
);
}
else
{
log
.
info
(
"邮件发送失败,Time:{},result:{}"
,
now
,
result
);
}
SmsResult
rootEntity
=
JSON
.
parseObject
(
result
,
SmsResult
.
class
);
if
(
rootEntity
.
getResult
().
getResultCode
().
equals
(
resultCode
)){
log
.
info
(
"短信发送成功,Time:{},result:{}"
,
now
,
result
);
}
else
{
log
.
info
(
"短信发送失败,Time:{},result:{}"
,
now
,
result
);
}
}
}
}
}
src/main/java/com/foc/dao/SoundsMaxIdDao.java
View file @
239a824a
package
com
.
foc
.
dao
;
package
com
.
foc
.
dao
;
import
com.foc.entity.FocSmsEmailRecord
;
import
com.foc.entity.SoundInfo
;
import
com.foc.entity.SoundInfo
;
import
com.foc.entity.SoundsMaxId
;
import
com.foc.entity.SoundsMaxId
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
...
@@ -27,4 +28,45 @@ public interface SoundsMaxIdDao {
...
@@ -27,4 +28,45 @@ public interface SoundsMaxIdDao {
*/
*/
List
<
SoundInfo
>
getInfo
(
@Param
(
"date"
)
String
date
);
List
<
SoundInfo
>
getInfo
(
@Param
(
"date"
)
String
date
);
/**
* 新增巡检记录
*
* @param focSmsEmailRecord
*/
void
insertFocRecord
(
FocSmsEmailRecord
focSmsEmailRecord
);
/**
* 已经发送过短信
*
* @return
*/
FocSmsEmailRecord
selectFocSendSmsRecord
();
/**
* 已经发送过邮件
*
* @return
*/
FocSmsEmailRecord
selectFocSendEmailRecord
();
/**
* 根据创建时间获取最新的一条数据
*
* @return
*/
FocSmsEmailRecord
selectLatestOne
();
/**
* 更新短信状态
*
* @param focSmsEmailRecord
*/
void
updateSms
(
FocSmsEmailRecord
focSmsEmailRecord
);
/**
* 更新邮件状态
*
* @param focSmsEmailRecord
*/
void
updateEmail
(
FocSmsEmailRecord
focSmsEmailRecord
);
}
}
src/main/java/com/foc/entity/FocSmsEmailRecord.java
0 → 100644
View file @
239a824a
package
com
.
foc
.
entity
;
import
lombok.Data
;
import
java.util.Date
;
/**
* 发送短信邮件记录
*
* @author zangtao
* @create 2019 - 09 -23 15:08
*/
@Data
public
class
FocSmsEmailRecord
{
private
Integer
id
;
private
String
description
;
private
Date
createTime
;
private
Short
monitorState
;
private
Short
emailSendStatus
;
private
Date
emailSendTime
;
private
String
emailErrorLog
;
private
Short
smsSendStatus
;
private
String
smsErrorLog
;
private
Date
smsSendTime
;
}
src/main/java/com/foc/service/SoundMonitorService.java
View file @
239a824a
package
com
.
foc
.
service
;
package
com
.
foc
.
service
;
import
com.alibaba.fastjson.JSON
;
import
com.foc.dao.SoundsMaxIdDao
;
import
com.foc.dao.SoundsMaxIdDao
;
import
com.foc.entity.SoundInfo
;
import
com.foc.entity.*
;
import
com.foc.entity.SoundsMaxId
;
import
com.foc.util.DateUtils
;
import
com.foc.util.DateUtils
;
import
com.foc.util.PropertiesUtils
;
import
com.foc.util.PropertiesUtils
;
import
com.foc.util.StringUtils
;
import
com.foc.util.StringUtils
;
...
@@ -15,11 +15,14 @@ import org.slf4j.LoggerFactory;
...
@@ -15,11 +15,14 @@ import org.slf4j.LoggerFactory;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.Reader
;
import
java.io.Reader
;
import
java.text.SimpleDateFormat
;
import
java.time.Instant
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Properties
;
import
java.util.Properties
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* @Author: lisu
* @Author: lisu
...
@@ -45,45 +48,143 @@ public class SoundMonitorService {
...
@@ -45,45 +48,143 @@ public class SoundMonitorService {
log
.
error
(
"连接数据库异常"
);
log
.
error
(
"连接数据库异常"
);
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
// finally {
// //session.close();
// }
}
}
public
static
boolean
test
()
{
/**
* 判断是否要巡检
*
* @return
*/
public
static
boolean
test
()
{
Properties
properties
=
PropertiesUtils
.
getProperties
();
Properties
properties
=
PropertiesUtils
.
getProperties
();
String
interval
=
properties
.
getProperty
(
"interval"
);
String
interval
=
properties
.
getProperty
(
"interval"
);
SoundsMaxIdDao
soundsMaxIdDao
=
session
.
getMapper
(
SoundsMaxIdDao
.
class
);
SoundsMaxIdDao
soundsMaxIdDao
=
session
.
getMapper
(
SoundsMaxIdDao
.
class
);
SoundsMaxId
maxId
=
soundsMaxIdDao
.
getMaxId
();
SoundsMaxId
maxId
=
soundsMaxIdDao
.
getMaxId
();
String
updateTime
=
maxId
.
getUpdateDate
();
String
updateTime
=
maxId
.
getUpdateDate
();
log
.
info
(
"当前系统时间:"
+
new
Date
());
Date
date
=
new
Date
();
log
.
info
(
"当前系统时间:{}"
,
date
);
FocSmsEmailRecord
focSmsEmailRecord
=
new
FocSmsEmailRecord
();
focSmsEmailRecord
.
setCreateTime
(
date
);
//比较时间,如果相差20分钟没有执行
//比较时间,如果相差20分钟没有执行
DateTimeFormatter
df
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
DateTimeFormatter
df
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
LocalDateTime
ldt
=
LocalDateTime
.
parse
(
updateTime
,
df
);
LocalDateTime
ldt
=
LocalDateTime
.
parse
(
updateTime
,
df
);
if
(
DateUtils
.
until
(
ldt
)
>
Long
.
parseLong
(
interval
)){
if
(
DateUtils
.
until
(
ldt
)
>
Long
.
parseLong
(
interval
)){
log
.
info
(
"更新时间异常,与最新时间间隔大于20分钟,updateTime:{}"
,
updateTime
)
;
log
.
info
(
"更新时间异常,与最新时间间隔大于20分钟,updateTime:{}"
,
updateTime
);
focSmsEmailRecord
.
setDescription
(
"更新时间异常,与最新时间间隔大于20分钟,updateTime为"
+
updateTime
);
focSmsEmailRecord
.
setMonitorState
((
short
)
1
);
soundsMaxIdDao
.
insertFocRecord
(
focSmsEmailRecord
);
session
.
commit
();
return
true
;
return
true
;
}
}
List
<
SoundInfo
>
list
=
soundsMaxIdDao
.
getInfo
(
updateTime
);
List
<
SoundInfo
>
list
=
soundsMaxIdDao
.
getInfo
(
updateTime
);
if
(
list
==
null
&&
list
.
size
()
<
1
){
if
(
list
==
null
&&
list
.
size
()
<
1
){
log
.
info
(
"查询不到记录"
);
log
.
info
(
"查询不到记录"
);
focSmsEmailRecord
.
setDescription
(
"查询不到记录"
);
focSmsEmailRecord
.
setMonitorState
((
short
)
0
);
soundsMaxIdDao
.
insertFocRecord
(
focSmsEmailRecord
);
session
.
commit
();
return
false
;
return
false
;
}
}
for
(
SoundInfo
soundInfo
:
list
){
for
(
SoundInfo
soundInfo
:
list
){
//成功且没有url的
//成功且没有url的
if
(
StringUtils
.
isEmpty
(
soundInfo
.
getDownloadUrl
()
)
){
if
(
StringUtils
.
isEmpty
(
soundInfo
.
getDownloadUrl
()
)
){
log
.
info
(
new
Date
()+
"该条记录无url:"
+
soundInfo
.
toString
());
log
.
info
(
"{}该条记录无url:{}"
,
date
,
soundInfo
.
toString
());
focSmsEmailRecord
.
setDescription
(
"该条记录无url"
+
soundInfo
.
toString
());
focSmsEmailRecord
.
setMonitorState
((
short
)
1
);
soundsMaxIdDao
.
insertFocRecord
(
focSmsEmailRecord
);
session
.
commit
();
return
true
;
return
true
;
}
}
}
}
log
.
info
(
"全部成功"
);
log
.
info
(
"全部成功"
);
focSmsEmailRecord
.
setDescription
(
"全部成功"
);
focSmsEmailRecord
.
setMonitorState
((
short
)
0
);
soundsMaxIdDao
.
insertFocRecord
(
focSmsEmailRecord
);
session
.
commit
();
return
false
;
return
false
;
}
public
static
void
SendEmailAndSms
(
String
aicc
,
String
aicp
,
String
resultCode
,
String
mobile
)
{
SoundsMaxIdDao
soundsMaxIdDao
=
session
.
getMapper
(
SoundsMaxIdDao
.
class
);
AccessInfo
accessInfo
=
new
AccessInfo
();
accessInfo
.
setAicc
(
aicc
);
accessInfo
.
setAicp
(
aicp
);
//当前时间
Instant
now
=
Instant
.
now
().
plusMillis
(
TimeUnit
.
HOURS
.
toMillis
(
8
));
Date
date
=
new
Date
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
//判断是否要发送短信 间隔一小时
FocSmsEmailRecord
focSendSmsRecord
=
soundsMaxIdDao
.
selectFocSendSmsRecord
();
FocSmsEmailRecord
focSendEmailRecord
=
soundsMaxIdDao
.
selectFocSendEmailRecord
();
FocSmsEmailRecord
focSmsEmailRecord
=
soundsMaxIdDao
.
selectLatestOne
();
Date
currentTime
=
focSmsEmailRecord
.
getCreateTime
();
boolean
smsFlag
;
Date
smsSendTime
=
focSendSmsRecord
.
getSmsSendTime
();
if
(
smsSendTime
==
null
){
smsFlag
=
true
;
}
else
{
//判断是否超过了一小时
long
second
=
currentTime
.
getTime
()-
smsSendTime
.
getTime
()/
1000
;
if
(
second
/
360
<
1
){
smsFlag
=
true
;
}
else
{
smsFlag
=
false
;
}
}
if
(
smsFlag
){
//发送短信
String
smsResult
=
Sms
.
sendSms
(
accessInfo
,
mobile
,
"预警:智能首航录音记录显示异常,请处理。"
);
SmsResult
rootEntity
=
JSON
.
parseObject
(
smsResult
,
SmsResult
.
class
);
if
(
rootEntity
.
getResult
().
getResultCode
().
equals
(
resultCode
)){
log
.
info
(
"短信发送成功,Time:{},result:{}"
,
now
,
smsResult
);
focSmsEmailRecord
.
setSmsSendTime
(
date
);
focSmsEmailRecord
.
setSmsSendStatus
((
short
)
1
);
focSmsEmailRecord
.
setSmsErrorLog
(
smsResult
);
soundsMaxIdDao
.
updateSms
(
focSmsEmailRecord
);
session
.
commit
();
}
else
{
log
.
info
(
"短信发送失败,Time:{},result:{}"
,
now
,
smsResult
);
focSmsEmailRecord
.
setSmsSendStatus
((
short
)
0
);
focSmsEmailRecord
.
setSmsErrorLog
(
smsResult
);
soundsMaxIdDao
.
updateSms
(
focSmsEmailRecord
);
session
.
commit
();
}
}
}
boolean
emailFlag
;
Date
emailSendTime
=
focSendEmailRecord
.
getEmailSendTime
();
if
(
emailSendTime
==
null
){
emailFlag
=
true
;
}
else
{
//判断是否超过了一小时
long
emailSecond
=
currentTime
.
getTime
()-
emailSendTime
.
getTime
()/
1000
;
if
(
emailSecond
/
360
<
1
){
emailFlag
=
true
;
}
else
{
emailFlag
=
false
;
}
}
if
(
emailFlag
){
//发送邮件
String
emailResult
=
Email
.
sendEmail
(
"录音记录预警"
,
"智能首航录音记录显示异常,请处理。"
);
EmailResult
emailResult1
=
JSON
.
parseObject
(
emailResult
,
EmailResult
.
class
);
if
(
emailResult1
.
getResult
().
getResultCode
().
equals
(
resultCode
)){
log
.
info
(
"邮件发送成功,Time:{},result:{}"
,
now
,
emailResult
);
focSmsEmailRecord
.
setEmailSendTime
(
date
);
focSmsEmailRecord
.
setEmailSendStatus
((
short
)
1
);
focSmsEmailRecord
.
setSmsErrorLog
(
emailResult
);
soundsMaxIdDao
.
updateEmail
(
focSmsEmailRecord
);
session
.
commit
();
}
else
{
log
.
info
(
"邮件发送失败,Time:{},result:{}"
,
now
,
emailResult
);
focSmsEmailRecord
.
setEmailSendStatus
((
short
)
0
);
focSmsEmailRecord
.
setSmsErrorLog
(
emailResult
);
soundsMaxIdDao
.
updateEmail
(
focSmsEmailRecord
);
session
.
commit
();
}
}
}
}
}
src/main/resources/mapper/SoundsMaxIdMapper.xml
View file @
239a824a
...
@@ -32,5 +32,29 @@
...
@@ -32,5 +32,29 @@
LIMIT 20
LIMIT 20
</select>
</select>
<insert
id=
"insertFocRecord"
parameterType=
"com.foc.entity.FocSmsEmailRecord"
>
insert into foc_sms_email_record(create_time,description,monitor_state) values (#{createTime},#{description},#{monitorState})
</insert>
<select
id=
"selectFocSendSmsRecord"
resultType=
"com.foc.entity.FocSmsEmailRecord"
>
select id ,create_time,monitor_state,sms_send_time,sms_send_status from foc_sms_email_record where 1 = 1 order by sms_send_time desc limit 1
</select>
<select
id=
"selectFocSendEmailRecord"
resultType=
"com.foc.entity.FocSmsEmailRecord"
>
select id ,create_time,monitor_state,email_send_status,email_send_time from foc_sms_email_record where 1 = 1 order by email_send_time desc limit 1
</select>
<select
id=
"selectLatestOne"
resultType=
"com.foc.entity.FocSmsEmailRecord"
>
select id,create_time,monitor_state from foc_sms_email_record where 1 = 1 order by create_time desc limit 1
</select>
<update
id=
"updateSms"
parameterType=
"com.foc.entity.FocSmsEmailRecord"
>
update foc_sms_email_record set sms_send_status = #{smsSendStatus},sms_error_log = #{smsErrorLog},
sms_send_time = #{smsSendTime} where id = #{id}
</update>
<update
id=
"updateEmail"
parameterType=
"com.foc.entity.FocSmsEmailRecord"
>
update foc_sms_email_record set email_send_status = #{emailSendStatus},email_error_log = #{emailErrorLog},
email_send_time = #{emailSendTime} where id = #{id}
</update>
</mapper>
</mapper>
\ No newline at end of file
src/main/resources/mybatis-config.xml
View file @
239a824a
...
@@ -46,7 +46,7 @@
...
@@ -46,7 +46,7 @@
<!-- 配置数据库连接信息 -->
<!-- 配置数据库连接信息 -->
<dataSource
type=
"POOLED"
>
<dataSource
type=
"POOLED"
>
<property
name=
"driver"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"driver"
value=
"com.mysql.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://106.75.97.50:3306/jd_foc"
/>
<property
name=
"url"
value=
"jdbc:mysql://106.75.97.50:3306/jd_foc
?useUnicode=true&characterEncoding=utf-8
"
/>
<!--<property name="url" value="jdbc:mysql://mysql_server:3306/foc?useUnicode=true&characterEncoding=utf-8"/>-->
<!--<property name="url" value="jdbc:mysql://mysql_server:3306/foc?useUnicode=true&characterEncoding=utf-8"/>-->
<property
name=
"username"
value=
"focuser"
/>
<property
name=
"username"
value=
"focuser"
/>
<property
name=
"password"
value=
"FOC@2016"
/>
<property
name=
"password"
value=
"FOC@2016"
/>
...
...
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