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
eac46d03
Commit
eac46d03
authored
Nov 06, 2020
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
8cb03b92
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
76 deletions
+100
-76
PriceTask.java
src/main/java/com/egolm/pds/schedule/PriceTask.java
+0
-74
ProductsTask.java
src/main/java/com/egolm/pds/schedule/ProductsTask.java
+6
-1
EmailService.java
...ain/java/com/egolm/pds/schedule/service/EmailService.java
+60
-0
ThrowableUtil.java
src/main/java/com/egolm/pds/utils/ThrowableUtil.java
+23
-0
application-dev.yml
src/main/resources/application-dev.yml
+11
-1
No files found.
src/main/java/com/egolm/pds/schedule/PriceTask.java
deleted
100644 → 0
View file @
8cb03b92
package
com
.
egolm
.
pds
.
schedule
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.egolm.common.DateUtil
;
import
com.egolm.pds.config.HttpUtil
;
//@Component
public
class
PriceTask
{
private
static
final
Log
log
=
LogFactory
.
getLog
(
PriceTask
.
class
);
@Value
(
"${pds.auth_key}"
)
private
String
authKey
;
@Value
(
"${pds.auth_value}"
)
private
String
authValue
;
@Value
(
"${pds.url_query}"
)
private
String
urlQuery
;
@Scheduled
(
cron
=
"${pds.cron.price_download}"
)
public
void
execute
()
{
log
.
debug
(
DateUtil
.
format
(
new
Date
())
+
" PdsProductsUpdateTask RUN"
);
boolean
boo
=
true
;
int
loopCount
=
0
;
while
(
boo
)
{
boo
=
executeUpdateTask
()
>
0
&&
loopCount
++
<
10
;
}
}
private
int
executeUpdateTask
()
{
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
headers
.
put
(
authKey
,
authValue
);
String
responseBody
=
HttpUtil
.
get
(
urlQuery
,
headers
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
responseBody
);
JSONArray
jsonArray
=
jsonObject
.
getJSONArray
(
"data"
);
if
(
jsonArray
!=
null
)
{
for
(
int
i
=
0
;
i
<
jsonArray
.
size
();
i
++)
{
JSONObject
priceObject
=
jsonArray
.
getJSONObject
(
i
);
String
barcode
=
priceObject
.
getString
(
"barcode"
);
Integer
contract_id
=
priceObject
.
getInteger
(
"contract_id"
);
String
effective_date
=
priceObject
.
getString
(
"effective_date"
);
String
effective_end_date
=
priceObject
.
getString
(
"effective_end_date"
);
String
new_buying_price_with_tax
=
priceObject
.
getString
(
"new_buying_price_with_tax"
);
String
new_selling_price_with_tax
=
priceObject
.
getString
(
"new_selling_price_with_tax"
);
String
price_change_type
=
priceObject
.
getString
(
"price_change_type"
);
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"barcode"
,
barcode
);
map
.
put
(
"contract_id"
,
contract_id
);
map
.
put
(
"effective_date"
,
effective_date
);
map
.
put
(
"effective_end_date"
,
effective_end_date
);
map
.
put
(
"new_buying_price_with_tax"
,
new_buying_price_with_tax
);
map
.
put
(
"new_selling_price_with_tax"
,
new_selling_price_with_tax
);
map
.
put
(
"price_change_type"
,
price_change_type
);
log
.
debug
(
JSON
.
toJSONString
(
map
));
}
}
return
jsonArray
==
null
?
0
:
jsonArray
.
size
();
}
}
src/main/java/com/egolm/pds/schedule/ProductsTask.java
View file @
eac46d03
...
...
@@ -16,6 +16,7 @@ import com.alibaba.fastjson.JSONArray;
import
com.alibaba.fastjson.JSONObject
;
import
com.egolm.common.DateUtil
;
import
com.egolm.pds.config.HttpUtil
;
import
com.egolm.pds.schedule.service.EmailService
;
import
com.egolm.pds.schedule.service.PdsService
;
@Component
...
...
@@ -25,6 +26,9 @@ public class ProductsTask {
@Autowired
private
PdsService
pdsService
;
@Autowired
private
EmailService
emailService
;
@Value
(
"${pds.auth_key}"
)
private
String
authKey
;
...
...
@@ -100,8 +104,9 @@ public class ProductsTask {
productMap
.
put
(
"dLastUpdateTime"
,
new
Date
());
try
{
pdsService
.
savePdsProduct
(
transactionId
,
productMap
);;
}
catch
(
Exception
e
)
{
}
catch
(
Throwable
e
)
{
log
.
error
(
""
,
e
);
emailService
.
appendToQueue
(
"PDS TASK ERROR"
,
productJsonObject
.
toJSONString
(),
e
);
}
}
}
...
...
src/main/java/com/egolm/pds/schedule/service/EmailService.java
0 → 100644
View file @
eac46d03
package
com
.
egolm
.
pds
.
schedule
.
service
;
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.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
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
;
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
)
{
StringBuffer
stackString
=
ThrowableUtil
.
toStackString
(
e
);
EmailObject
emailObject
=
new
EmailObject
();
emailObject
.
subject
=
subject
;
emailObject
.
content
=
content
+
"\r\n"
+
stackString
.
toString
();
queue
.
add
(
emailObject
);
}
@Scheduled
(
initialDelay
=
5000
,
fixedRate
=
Long
.
MAX_VALUE
)
private
void
exec
()
{
while
(
true
)
{
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
()]));
}
catch
(
Throwable
e
)
{
log
.
error
(
""
,
e
);
if
(
obj
!=
null
)
{
queue
.
add
(
obj
);
}
}
}
}
private
static
class
EmailObject
{
String
subject
;
String
content
;
}
}
src/main/java/com/egolm/pds/utils/ThrowableUtil.java
0 → 100644
View file @
eac46d03
package
com
.
egolm
.
pds
.
utils
;
public
class
ThrowableUtil
{
public
static
StringBuffer
toStackString
(
Throwable
ex
)
{
StringBuffer
stack
=
new
StringBuffer
();
if
(
ex
!=
null
)
{
stack
.
append
(
ex
.
getClass
().
getName
()).
append
(
": "
).
append
(
ex
.
getMessage
()).
append
(
System
.
lineSeparator
());
StackTraceElement
[]
elms
=
ex
.
getStackTrace
();
for
(
StackTraceElement
elm
:
elms
)
{
stack
.
append
(
"\t"
).
append
(
elm
.
getClassName
()).
append
(
"."
).
append
(
elm
.
getMethodName
()).
append
(
"("
).
append
(
elm
.
getFileName
()).
append
(
" "
).
append
(
elm
.
getLineNumber
()).
append
(
")\n"
);
}
if
(
ex
.
getCause
()
!=
null
)
{
stack
.
append
(
"\n\n"
).
append
(
"Cause By: \n"
).
append
(
toStackString
(
ex
.
getCause
()));
}
for
(
Throwable
e
:
ex
.
getSuppressed
())
{
stack
.
append
(
"\n\n"
).
append
(
"Suppressed By: \n"
).
append
(
toStackString
(
e
));
}
}
return
stack
;
}
}
src/main/resources/application-dev.yml
View file @
eac46d03
...
...
@@ -28,4 +28,14 @@ pds:
url_update
:
https://pztafj5g87.execute-api.ap-southeast-1.amazonaws.com/test/sunshine/confirm
price
:
url_query
:
https://pztafj5g87.execute-api.ap-southeast-1.amazonaws.com/test/sunshine/price_changes
url_update
:
https://pztafj5g87.execute-api.ap-southeast-1.amazonaws.com/test/sunshine/confirm
\ No newline at end of file
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
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