Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
pdstask
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
pdstask
Commits
06acd152
Commit
06acd152
authored
Nov 06, 2020
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
eac46d03
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
113 additions
and
19 deletions
+113
-19
pom.xml
pom.xml
+0
-1
ProductsTask.java
src/main/java/com/egolm/pds/schedule/ProductsTask.java
+1
-1
EmailService.java
...ain/java/com/egolm/pds/schedule/service/EmailService.java
+19
-13
EmailServiceTest.java
...java/com/egolm/pds/schedule/service/EmailServiceTest.java
+29
-0
MailConfig.java
src/main/java/com/egolm/pds/schedule/service/MailConfig.java
+53
-0
application-dev.yml
src/main/resources/application-dev.yml
+1
-3
application-pro.yml
src/main/resources/application-pro.yml
+10
-1
No files found.
pom.xml
View file @
06acd152
...
...
@@ -45,7 +45,6 @@
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
...
...
src/main/java/com/egolm/pds/schedule/ProductsTask.java
View file @
06acd152
...
...
@@ -106,7 +106,7 @@ public class ProductsTask {
pdsService
.
savePdsProduct
(
transactionId
,
productMap
);;
}
catch
(
Throwable
e
)
{
log
.
error
(
""
,
e
);
emailService
.
appendToQueue
(
"PDS TASK ERROR"
,
productJsonObject
.
toJSONString
(),
e
);
emailService
.
sendForasync
(
"PDS TASK ERROR"
,
productJsonObject
.
toJSONString
(),
e
);
}
}
}
...
...
src/main/java/com/egolm/pds/schedule/service/EmailService.java
View file @
06acd152
package
com
.
egolm
.
pds
.
schedule
.
service
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.factory.annotation.
Value
;
import
org.springframework.beans.factory.annotation.
Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
com.egolm.common.DateUtil
;
import
com.egolm.common.MailUtil
;
import
com.egolm.pds.utils.ThrowableUtil
;
@Component
public
class
EmailService
{
@Value
(
"${mail.to}"
)
private
List
<
String
>
to
;
@Value
(
"${mail.host}"
)
private
String
host
;
@Value
(
"${mail.port}"
)
private
Integer
port
;
@Value
(
"${mail.from}"
)
private
String
from
;
@Value
(
"${mail.username}"
)
private
String
username
;
@Value
(
"${mail.password}"
)
private
String
password
;
@Autowired
private
MailConfig
config
;
private
static
final
Log
log
=
LogFactory
.
getLog
(
EmailService
.
class
);
private
static
final
LinkedBlockingQueue
<
EmailObject
>
queue
=
new
LinkedBlockingQueue
<
EmailObject
>();
public
void
appendToQueue
(
String
subject
,
String
content
,
Throwable
e
)
{
public
void
sendForasync
(
String
subject
,
String
content
,
Throwable
e
)
{
StringBuffer
stackString
=
ThrowableUtil
.
toStackString
(
e
);
String
timeString
=
DateUtil
.
format
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
);
EmailObject
emailObject
=
new
EmailObject
();
emailObject
.
subject
=
subject
;
emailObject
.
content
=
content
+
"\r\n"
+
stackString
.
toString
();
emailObject
.
content
=
timeString
+
"\r\n"
+
subject
+
"\r\n"
+
content
+
"\r\n"
+
stackString
.
toString
();
queue
.
add
(
emailObject
);
}
...
...
@@ -39,9 +37,7 @@ public class EmailService {
EmailObject
obj
=
null
;
try
{
obj
=
queue
.
take
();
String
subject
=
obj
.
subject
;
String
content
=
obj
.
content
;
MailUtil
.
sendBySmtps
(
host
,
port
,
username
,
password
,
from
,
subject
,
content
,
null
,
to
.
toArray
(
new
String
[
to
.
size
()]));
this
.
sendForsync
(
obj
.
subject
,
obj
.
content
);
}
catch
(
Throwable
e
)
{
log
.
error
(
""
,
e
);
if
(
obj
!=
null
)
{
...
...
@@ -51,6 +47,16 @@ public class EmailService {
}
}
public
void
sendForsync
(
String
subject
,
String
content
)
{
String
host
=
config
.
getHost
();
Integer
port
=
config
.
getPort
();
String
username
=
config
.
getUsername
();
String
password
=
config
.
getPassword
();
String
from
=
config
.
getFrom
();
List
<
String
>
to
=
config
.
getTo
();
MailUtil
.
sendBySmtp
(
host
,
port
,
true
,
username
,
password
,
from
,
subject
,
content
,
null
,
to
.
toArray
(
new
String
[
to
.
size
()]));
}
private
static
class
EmailObject
{
String
subject
;
...
...
src/main/java/com/egolm/pds/schedule/service/EmailServiceTest.java
0 → 100644
View file @
06acd152
package
com
.
egolm
.
pds
.
schedule
.
service
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
com.egolm.pds.PDSApplication
;
@ActiveProfiles
(
"dev"
)
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
PDSApplication
.
class
)
public
class
EmailServiceTest
{
@Autowired
private
EmailService
service
;
@Test
public
void
sendEmailTest
()
{
try
{
service
.
sendForsync
(
"测试邮件"
,
"测试邮件"
);
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
}
}
}
src/main/java/com/egolm/pds/schedule/service/MailConfig.java
0 → 100644
View file @
06acd152
package
com
.
egolm
.
pds
.
schedule
.
service
;
import
java.util.List
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.stereotype.Component
;
@Component
@ConfigurationProperties
(
prefix
=
"mail"
)
public
class
MailConfig
{
private
List
<
String
>
to
;
private
String
host
;
private
Integer
port
;
private
String
from
;
private
String
username
;
private
String
password
;
public
List
<
String
>
getTo
()
{
return
to
;
}
public
String
getHost
()
{
return
host
;
}
public
Integer
getPort
()
{
return
port
;
}
public
String
getFrom
()
{
return
from
;
}
public
String
getUsername
()
{
return
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setTo
(
List
<
String
>
to
)
{
this
.
to
=
to
;
}
public
void
setHost
(
String
host
)
{
this
.
host
=
host
;
}
public
void
setPort
(
Integer
port
)
{
this
.
port
=
port
;
}
public
void
setFrom
(
String
from
)
{
this
.
from
=
from
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
}
src/main/resources/application-dev.yml
View file @
06acd152
...
...
@@ -31,9 +31,7 @@ pds:
url_update
:
https://pztafj5g87.execute-api.ap-southeast-1.amazonaws.com/test/sunshine/confirm
mail
:
to
:
-
customerservice@powere2e.net
-
hanxu@linkfern.com
-
qiu.zhihua@linkfern.com
-
qu.xinliang@linkfern.com
from
:
customerservice@powere2e.net
host
:
mail.powere2e.net
port
:
587
...
...
src/main/resources/application-pro.yml
View file @
06acd152
...
...
@@ -29,4 +29,13 @@ pds:
price
:
url_query
:
https://api.goodsmaster.com/sunshine/price_changes
url_update
:
https://api.goodsmaster.com/sunshine/price_changes/confirm
\ No newline at end of file
mail
:
to
:
-
customerservice@powere2e.net
-
hanxu@linkfern.com
-
qiu.zhihua@linkfern.com
from
:
customerservice@powere2e.net
host
:
mail.powere2e.net
port
:
587
username
:
customerservice@powere2e.net
password
:
CSpowere2e/.
\ No newline at end of file
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