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 @@
...
@@ -45,7 +45,6 @@
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<groupId>
com.alibaba
</groupId>
...
...
src/main/java/com/egolm/pds/schedule/ProductsTask.java
View file @
06acd152
...
@@ -106,7 +106,7 @@ public class ProductsTask {
...
@@ -106,7 +106,7 @@ public class ProductsTask {
pdsService
.
savePdsProduct
(
transactionId
,
productMap
);;
pdsService
.
savePdsProduct
(
transactionId
,
productMap
);;
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
log
.
error
(
""
,
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
;
package
com
.
egolm
.
pds
.
schedule
.
service
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
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.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
com.egolm.common.DateUtil
;
import
com.egolm.common.MailUtil
;
import
com.egolm.common.MailUtil
;
import
com.egolm.pds.utils.ThrowableUtil
;
import
com.egolm.pds.utils.ThrowableUtil
;
@Component
@Component
public
class
EmailService
{
public
class
EmailService
{
@Value
(
"${mail.to}"
)
private
List
<
String
>
to
;
@Autowired
@Value
(
"${mail.host}"
)
private
String
host
;
private
MailConfig
config
;
@Value
(
"${mail.port}"
)
private
Integer
port
;
@Value
(
"${mail.from}"
)
private
String
from
;
@Value
(
"${mail.username}"
)
private
String
username
;
@Value
(
"${mail.password}"
)
private
String
password
;
private
static
final
Log
log
=
LogFactory
.
getLog
(
EmailService
.
class
);
private
static
final
Log
log
=
LogFactory
.
getLog
(
EmailService
.
class
);
private
static
final
LinkedBlockingQueue
<
EmailObject
>
queue
=
new
LinkedBlockingQueue
<
EmailObject
>();
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
);
StringBuffer
stackString
=
ThrowableUtil
.
toStackString
(
e
);
String
timeString
=
DateUtil
.
format
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
);
EmailObject
emailObject
=
new
EmailObject
();
EmailObject
emailObject
=
new
EmailObject
();
emailObject
.
subject
=
subject
;
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
);
queue
.
add
(
emailObject
);
}
}
...
@@ -39,9 +37,7 @@ public class EmailService {
...
@@ -39,9 +37,7 @@ public class EmailService {
EmailObject
obj
=
null
;
EmailObject
obj
=
null
;
try
{
try
{
obj
=
queue
.
take
();
obj
=
queue
.
take
();
String
subject
=
obj
.
subject
;
this
.
sendForsync
(
obj
.
subject
,
obj
.
content
);
String
content
=
obj
.
content
;
MailUtil
.
sendBySmtps
(
host
,
port
,
username
,
password
,
from
,
subject
,
content
,
null
,
to
.
toArray
(
new
String
[
to
.
size
()]));
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
log
.
error
(
""
,
e
);
log
.
error
(
""
,
e
);
if
(
obj
!=
null
)
{
if
(
obj
!=
null
)
{
...
@@ -51,6 +47,16 @@ public class EmailService {
...
@@ -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
{
private
static
class
EmailObject
{
String
subject
;
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:
...
@@ -31,9 +31,7 @@ pds:
url_update
:
https://pztafj5g87.execute-api.ap-southeast-1.amazonaws.com/test/sunshine/confirm
url_update
:
https://pztafj5g87.execute-api.ap-southeast-1.amazonaws.com/test/sunshine/confirm
mail
:
mail
:
to
:
to
:
-
customerservice@powere2e.net
-
qu.xinliang@linkfern.com
-
hanxu@linkfern.com
-
qiu.zhihua@linkfern.com
from
:
customerservice@powere2e.net
from
:
customerservice@powere2e.net
host
:
mail.powere2e.net
host
:
mail.powere2e.net
port
:
587
port
:
587
...
...
src/main/resources/application-pro.yml
View file @
06acd152
...
@@ -29,4 +29,13 @@ pds:
...
@@ -29,4 +29,13 @@ pds:
price
:
price
:
url_query
:
https://api.goodsmaster.com/sunshine/price_changes
url_query
:
https://api.goodsmaster.com/sunshine/price_changes
url_update
:
https://api.goodsmaster.com/sunshine/price_changes/confirm
url_update
:
https://api.goodsmaster.com/sunshine/price_changes/confirm
mail
:
\ No newline at end of file
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