Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
sap-service
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
曲欣亮
sap-service
Commits
60544650
Commit
60544650
authored
Aug 12, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
dc8d3e69
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
65 deletions
+101
-65
SI011ACTUALSALESSyncOutServiceTask.java
...ES_SyncOutService/SI011ACTUALSALESSyncOutServiceTask.java
+2
-2
CommonService.java
src/main/java/com/egolm/sso/services/CommonService.java
+99
-63
No files found.
src/main/java/com/egolm/sso/clients/SI_011_ACTUAL_SALES_SyncOutService/SI011ACTUALSALESSyncOutServiceTask.java
View file @
60544650
...
...
@@ -68,7 +68,7 @@ public class SI011ACTUALSALESSyncOutServiceTask {
}
private
void
sendData
(
SI011ACTUALSALESSyncOut
SI011ACTUALSALESSyncOut
)
{
Page
page
=
new
Page
(
1L
,
1000L
,
new
String
[]
{
"DIS_CODE"
,
"
TRACE
_NO"
});
Page
page
=
new
Page
(
1L
,
1000L
,
new
String
[]
{
"DIS_CODE"
,
"
SALES
_NO"
});
String
sql
=
"SELECT * FROM t_dis_sales WHERE SEND_STATUS = 'N'"
;
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<
Map
<
String
,
Object
>>();
List
<
Map
<
String
,
Object
>>
tmp
=
null
;
...
...
@@ -78,7 +78,7 @@ public class SI011ACTUALSALESSyncOutServiceTask {
list
.
addAll
(
tmp
);
page
.
toNextPage
();
}
while
(
tmp
!=
null
&&
tmp
.
size
()
>
0
);
Map
<
String
,
List
<
Map
<
String
,
Object
>>>
datas
=
CollectionUtil
.
toGroupList
(
list
,
"DIS_CODE"
,
"
TRACE
_NO"
);
Map
<
String
,
List
<
Map
<
String
,
Object
>>>
datas
=
CollectionUtil
.
toGroupList
(
list
,
"DIS_CODE"
,
"
SALES
_NO"
);
for
(
List
<
Map
<
String
,
Object
>>
vList
:
datas
.
values
())
{
try
{
this
.
sendData
(
SI011ACTUALSALESSyncOut
,
vList
);
...
...
src/main/java/com/egolm/sso/services/CommonService.java
View file @
60544650
package
com
.
egolm
.
sso
.
services
;
import
java.sql.CallableStatement
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.sql.Types
;
import
java.text.MessageFormat
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
...
...
@@ -8,13 +12,15 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
org.bouncycastle.util.encoders.Base64
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.config.ConfigurableBeanFactory
;
import
org.springframework.context.annotation.Scope
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.dao.DuplicateKeyException
;
import
org.springframework.dao.EmptyResultDataAccessException
;
import
org.springframework.jdbc.core.CallableStatementCallback
;
import
org.springframework.jdbc.core.CallableStatementCreator
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
...
...
@@ -29,55 +35,76 @@ import com.egolm.sso.util.SqlUtil.Sql;
import
com.egolm.sso.util.StringUtil
;
@Service
@Scope
(
value
=
ConfigurableBeanFactory
.
SCOPE_SINGLETON
)
@Scope
(
value
=
ConfigurableBeanFactory
.
SCOPE_SINGLETON
)
public
class
CommonService
{
@Autowired
private
JdbcTemplate
jdbcTemplate
;
@Value
(
"${systemId}"
)
private
String
systemId
;
@Value
(
"${dataTracking.appId}"
)
private
String
appId
;
@Value
(
"${dataTracking.appSecret}"
)
private
String
appSecret
;
@Value
(
"${dataTracking.username}"
)
private
String
username
;
@Value
(
"${dataTracking.baseUrl}"
)
private
String
baseUrl
;
@Value
(
"${dataTracking.uri.token}"
)
private
String
tokenUri
;
@Value
(
"${dataTracking.uri.insertOrderTracking}"
)
private
String
insertOrderTrackingUri
;
@Value
(
"${dataTracking.isOpen}"
)
private
boolean
isOpen
;
public
Long
getNextval
(
String
sName
)
{
return
getNextvalBySql
(
sName
);
}
public
Long
getNextvalByProc
(
String
sName
)
{
return
this
.
jdbcTemplate
.
execute
(
new
CallableStatementCreator
()
{
public
CallableStatement
createCallableStatement
(
Connection
connection
)
throws
SQLException
{
String
storedProc
=
"{call getNextval(?, ?)}"
;
CallableStatement
cs
=
connection
.
prepareCall
(
storedProc
);
cs
.
setString
(
1
,
sName
);
cs
.
registerOutParameter
(
2
,
Types
.
BIGINT
);
return
cs
;
}
},
new
CallableStatementCallback
<
Long
>()
{
public
Long
doInCallableStatement
(
CallableStatement
cs
)
throws
SQLException
,
DataAccessException
{
cs
.
execute
();
return
cs
.
getLong
(
2
);
}
});
}
@Transactional
(
propagation
=
Propagation
.
NOT_SUPPORTED
)
public
synchronized
Long
getNextva
l
(
String
sName
)
{
public
Long
getNextvalBySq
l
(
String
sName
)
{
try
{
Map
<
String
,
Object
>
seqMap
=
jdbcTemplate
.
queryForMap
(
"select * from x_sequence where name = ?"
,
sName
);
Integer
id
=
(
Integer
)
seqMap
.
get
(
"id"
);
Long
step
=
(
Long
)
seqMap
.
get
(
"step"
);
Long
max
=
(
Long
)
seqMap
.
get
(
"max"
);
Long
min
=
(
Long
)
seqMap
.
get
(
"min"
);
Long
value
=
(
Long
)
seqMap
.
get
(
"value"
);
Integer
id
=
(
Integer
)
seqMap
.
get
(
"id"
);
Long
step
=
(
Long
)
seqMap
.
get
(
"step"
);
Long
max
=
(
Long
)
seqMap
.
get
(
"max"
);
Long
min
=
(
Long
)
seqMap
.
get
(
"min"
);
Long
value
=
(
Long
)
seqMap
.
get
(
"value"
);
Long
nextValue
=
value
+
step
;
if
(
value
>
max
||
value
<
min
)
{
if
(
value
>
max
||
value
<
min
)
{
throw
new
XRException
(
MessageFormat
.
format
(
"序列已超出许可范围[{0}]"
,
sName
));
}
else
{
String
sql
=
"update x_sequence set value = ? where id = ? and value < ?"
;
int
count
=
jdbcTemplate
.
update
(
sql
,
nextValue
,
id
,
nextValue
);
if
(
count
==
1
)
{
if
(
count
==
1
)
{
return
value
;
}
else
if
(
count
==
0
)
{
}
else
if
(
count
==
0
)
{
return
this
.
getNextval
(
sName
);
}
else
{
throw
new
XRException
(
MessageFormat
.
format
(
"序列错误[{0}]"
,
sName
));
...
...
@@ -93,21 +120,25 @@ public class CommonService {
}
}
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
Long
.
MAX_VALUE
);
}
public
String
getNextBatch
(
Date
day
,
String
sPrefix
,
String
sName
)
{
String
dateString
=
DateUtil
.
formatDate
(
day
,
"yyyyMMdd"
);
sName
=
sPrefix
+
"_"
+
sName
+
"_"
+
dateString
;
return
dateString
+
"-"
+
this
.
getNextval
(
sName
);
}
public
String
limitByMysql
(
String
sql
,
Page
page
)
{
long
start
=
(
page
.
getIndex
()
-
1
)
*
page
.
getLimit
();
long
limit
=
page
.
getLimit
();
String
limitKeys
=
StringUtil
.
join
(
", as_limit."
,
" order by as_limit."
,
""
,
""
,
page
.
getLimitKey
());
return
"select as_limit.* from ("
+
sql
+
") as_limit"
+
limitKeys
+
" limit "
+
start
+
", "
+
limit
;
}
@Transactional
(
propagation
=
Propagation
.
NOT_SUPPORTED
)
@Transactional
(
propagation
=
Propagation
.
NOT_SUPPORTED
)
public
void
saveApiAccessLog
(
String
METHOD
,
String
ADDRESS
,
String
RESULT
)
{
Date
now
=
new
Date
();
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
...
...
@@ -123,15 +154,16 @@ public class CommonService {
Object
[]
objs
=
sqlObj
.
getArgs
();
jdbcTemplate
.
update
(
sql
,
objs
);
}
@Value
(
"${dataTracking.tokenExpireMinute}"
)
private
Long
tokenExpireMinute
;
private
static
String
token
;
private
static
Date
tokenCreateTime
;
public
String
getToken
()
{
Date
now
=
new
Date
();
if
(
token
!=
null
&&
tokenCreateTime
!=
null
&&
(
tokenCreateTime
.
getTime
()
+
((
tokenExpireMinute
-
2
)*
60L
*
1000L
))
>
now
.
getTime
())
{
if
(
token
!=
null
&&
tokenCreateTime
!=
null
&&
(
tokenCreateTime
.
getTime
()
+
((
tokenExpireMinute
-
2
)
*
60L
*
1000L
))
>
now
.
getTime
())
{
return
token
;
}
String
requestUrl
=
baseUrl
+
tokenUri
;
...
...
@@ -142,7 +174,7 @@ public class CommonService {
String
resultText
=
HttpUtil
.
post
(
requestUrl
,
parameters
,
null
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
resultText
);
Boolean
isSuccess
=
jsonObject
.
getBoolean
(
"success"
);
if
(
isSuccess
!=
null
&&
isSuccess
)
{
if
(
isSuccess
!=
null
&&
isSuccess
)
{
tokenCreateTime
=
now
;
token
=
jsonObject
.
getString
(
"token"
);
return
token
;
...
...
@@ -150,13 +182,14 @@ public class CommonService {
throw
new
TrackingTokenException
(
jsonObject
.
getString
(
"message"
));
}
}
public
String
saveOrderTracking
(
String
traceNo
,
String
orderType
,
String
orderNo
,
String
disCode
,
String
action
,
String
result
,
String
message
,
String
errorMessage
)
{
if
(
isOpen
)
{
public
String
saveOrderTracking
(
String
traceNo
,
String
orderType
,
String
orderNo
,
String
disCode
,
String
action
,
String
result
,
String
message
,
String
errorMessage
)
{
if
(
isOpen
)
{
String
requestUrl
=
baseUrl
+
insertOrderTrackingUri
;
String
token
=
this
.
getToken
();
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
headers
.
put
(
"Authorization"
,
"Bearer "
+
token
);
headers
.
put
(
"Authorization"
,
"Bearer "
+
token
);
Map
<
String
,
Object
>
parameters
=
new
HashMap
<
String
,
Object
>();
parameters
.
put
(
"traceNo"
,
traceNo
);
parameters
.
put
(
"orderType"
,
orderType
);
...
...
@@ -170,20 +203,16 @@ public class CommonService {
}
return
null
;
}
public
static
class
TrackingTokenException
extends
RuntimeException
{
private
static
final
long
serialVersionUID
=
1L
;
public
TrackingTokenException
(
String
msg
)
{
super
(
msg
);
}
}
public
static
void
main
(
String
[]
args
)
{
String
string
=
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlSWRzIjpbIjM1YmY2NmI4LWQ2NzQtNDNkNy1iNjc3LTc0N2QwMWJhNDZiMyJdLCJ1c2VyX25hbWUiOiJ0cmFuY2UiLCJzY29wZSI6WyJDTElFTlQiXSwiZXhwaXJhdGlvbiI6MTU2NTAwODQ2ODA2NCwiZXhwIjoxNTY1MDA4NDY4LCJhdXRob3JpdGllcyI6WyJ0cmFuY2UiXSwianRpIjoiNGFmMjlhZTItZWJhYy00ZTg5LWExZDAtODUyYWEwZDhkNWM2IiwiY2xpZW50X2lkIjoicGMifQ.cCaEDqpB-yZQp-zmjYAv2igS1IdsjZVd-OT0EOfvdt4"
;
System
.
out
.
println
(
new
String
(
Base64
.
decode
(
string
)));
}
public
static
class
Page
implements
java
.
io
.
Serializable
{
public
static
class
Page
implements
java
.
io
.
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -191,41 +220,45 @@ public class CommonService {
* 分页页数
*/
protected
Long
index
=
1L
;
/**
* 分页大小,即每页数据显示条数
*/
protected
Long
limit
=
50L
;
/**
* 数据总条数
*/
protected
Long
total
=
0L
;
protected
String
[]
limitKey
;
public
Page
()
{}
public
Page
()
{
}
public
Page
(
String
...
limitKey
)
{
this
.
limitKey
=
limitKey
;
}
/**
* 构造函数
* @param index 分页查询的页索引
* @param limit 每页显示的条数
*
* @param index
* 分页查询的页索引
* @param limit
* 每页显示的条数
*/
public
Page
(
Long
index
,
Long
limit
)
{
this
.
index
=
index
;
this
.
limit
=
limit
;
}
public
Page
(
Long
index
,
Long
limit
,
String
...
limitKey
)
{
this
.
index
=
index
;
this
.
limit
=
limit
;
this
.
limitKey
=
limitKey
;
}
public
Long
getIndex
()
{
Long
pageTotal
=
getPageTotal
();
if
(
index
>
pageTotal
&&
pageTotal
!=
null
&&
pageTotal
!=
0
)
{
...
...
@@ -233,7 +266,7 @@ public class CommonService {
}
return
index
;
}
public
Page
toNextPage
()
{
this
.
index
+=
1
;
return
this
;
...
...
@@ -254,35 +287,38 @@ public class CommonService {
public
Long
getTotal
()
{
return
total
;
}
public
void
setTotal
(
Long
total
)
{
this
.
total
=
total
;
}
/**
* 计算总分页页数
*
* @return
*/
public
Long
getPageTotal
()
{
return
total
%
limit
==
0
?
(
total
/
limit
)
:
(
total
/
limit
+
1
);
return
total
%
limit
==
0
?
(
total
/
limit
)
:
(
total
/
limit
+
1
);
}
/**
* 计算分页查询开始行的行标
*
* @return 分页查询开始行标
*/
public
Long
getFirstRowNumber
()
{
return
((
index
-
1
)
*
limit
)
+
1
;
}
/**
* 计算分页查询结束行的行标
*
* @return 分页查询结束行标
*/
public
Long
getLastRowNumber
()
{
return
index
*
limit
;
}
public
Long
[]
getPageIndexs
()
{
Long
lastIndex
=
this
.
getPageTotal
();
List
<
Long
>
list
=
new
ArrayList
<
Long
>();
...
...
@@ -290,17 +326,17 @@ public class CommonService {
Long
i
=
1L
;
Long
prefPage
=
index
;
Long
nextPage
=
index
;
do
{
do
{
prefPage
=
index
-
i
;
nextPage
=
index
+
i
;
if
(
prefPage
>=
1
)
{
if
(
prefPage
>=
1
)
{
list
.
add
(
0
,
prefPage
);
}
if
(
nextPage
<=
lastIndex
)
{
if
(
nextPage
<=
lastIndex
)
{
list
.
add
(
nextPage
);
}
i
++;
}
while
(
list
.
size
()
<
6
&&
(
prefPage
>=
1
||
nextPage
<=
lastIndex
));
}
while
(
list
.
size
()
<
6
&&
(
prefPage
>=
1
||
nextPage
<=
lastIndex
));
return
list
.
toArray
(
new
Long
[
list
.
size
()]);
}
...
...
@@ -309,7 +345,7 @@ public class CommonService {
}
public
void
setLimitKey
(
String
...
limitKey
)
{
if
(
this
.
limitKey
==
null
)
{
if
(
this
.
limitKey
==
null
)
{
this
.
limitKey
=
limitKey
;
}
else
{
List
<
String
>
strs
=
new
ArrayList
<
String
>();
...
...
@@ -318,7 +354,7 @@ public class CommonService {
this
.
limitKey
=
strs
.
toArray
(
new
String
[
strs
.
size
()]);
}
}
}
}
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