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
46be83ea
Commit
46be83ea
authored
Dec 10, 2020
by
java-温文海
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
油量接口插入
parent
42ea7fdd
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
220 additions
and
60 deletions
+220
-60
DspReleaseInfoTask.java
src/main/java/com/foc/DspReleaseInfoTask.java
+1
-1
StatisticalDao.java
src/main/java/com/foc/dao/StatisticalDao.java
+14
-0
DspReleaseInfo.java
src/main/java/com/foc/entity/DspReleaseInfo.java
+44
-0
DspReleaseInfoService.java
src/main/java/com/foc/service/DspReleaseInfoService.java
+116
-57
StatisticalMapper.xml
src/main/resources/mapper/StatisticalMapper.xml
+45
-0
mybatis-config.xml
src/main/resources/mybatis-config.xml
+0
-2
No files found.
src/main/java/com/foc/DspReleaseInfoTask.java
View file @
46be83ea
...
...
@@ -13,6 +13,6 @@ public class DspReleaseInfoTask {
public
static
void
main
(
String
[]
args
)
throws
Exception
{
DspReleaseInfoService
.
init
();
DspReleaseInfoService
.
buildGatewayRequestString
();
DspReleaseInfoService
.
addInfo
();
}
}
src/main/java/com/foc/dao/StatisticalDao.java
View file @
46be83ea
package
com
.
foc
.
dao
;
import
com.foc.entity.DspReleaseInfo
;
import
com.foc.entity.StatisticalEntity
;
import
org.apache.ibatis.annotations.Param
;
...
...
@@ -67,4 +68,17 @@ public interface StatisticalDao {
* @param list
*/
void
insertOrUpdateBatch
(
List
<
StatisticalEntity
>
list
);
/**
* 获取航班号列表
* @return
*/
List
<
String
>
getFlightNoList
();
/**
* 批量新增或修改
* @param list
*/
void
insertDspReleaseInfo
(
List
<
DspReleaseInfo
>
list
);
}
src/main/java/com/foc/entity/DspReleaseInfo.java
0 → 100644
View file @
46be83ea
package
com
.
foc
.
entity
;
import
lombok.Data
;
import
java.util.Date
;
/**
*
* @Author wenwh
* @Date 14:43 2020/12/10
**/
@Data
public
class
DspReleaseInfo
{
private
String
sendTime
;
private
String
flightNo
;
private
String
std
;
private
String
acNo
;
private
String
depIataId
;
private
String
arrIataId
;
private
String
totalOil
;
private
String
dispatcherName
;
private
String
extraOilFuelReason
;
private
String
eET
;
private
String
weightUnit
;
private
String
updateTime
;
private
String
createDate
;
private
String
updateDate
;
private
String
delFlag
;
}
src/main/java/com/foc/service/DspReleaseInfoService.java
View file @
46be83ea
package
com
.
foc
.
service
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.foc.dao.StatisticalDao
;
import
com.foc.entity.DspReleaseInfo
;
import
com.foc.entity.ResultMsg
;
import
com.foc.thirdpart.esb.ApiRequest
;
import
com.foc.thirdpart.esb.EncodeUtil
;
import
com.foc.thirdpart.esb.HttpClient
;
import
com.foc.thirdpart.esb.PageParam
;
import
com.foc.thirdpart.esb.nativehttp.HttpClientImpl
;
import
com.foc.util.DateUtils
;
import
com.foc.util.PropertiesUtils
;
import
com.foc.util.StringUtils
;
import
com.google.gson.Gson
;
...
...
@@ -17,9 +24,9 @@ import org.slf4j.LoggerFactory;
import
java.io.IOException
;
import
java.io.Reader
;
import
java.
util.HashMap
;
import
java.
util.Map
;
import
java.util.
Properties
;
import
java.
io.UnsupportedEncodingException
;
import
java.
security.GeneralSecurityException
;
import
java.util.
*
;
/**
* @author LEGION
...
...
@@ -44,34 +51,40 @@ public class DspReleaseInfoService {
}
}
public
static
void
sync
()
{
}
private
static
void
nativeHttpCall
()
{
private
static
List
<
String
>
nativeHttpCall
()
{
Properties
properties
=
PropertiesUtils
.
getProperties
();
String
gatewayUatUrl
=
properties
.
getProperty
(
"esb.security.gateway.uat.url"
);
String
key
=
properties
.
getProperty
(
"esb.security.key"
);
if
(
StringUtils
.
isEmpty
(
gatewayUatUrl
)
||
StringUtils
.
isEmpty
(
key
))
{
log
.
error
(
"获取配置文件中机型的文件"
);
return
;
return
null
;
}
log
.
info
(
"**********************************************"
);
log
.
info
(
"----nativeHttpCall-----"
);
List
<
String
>
resultList
=
new
ArrayList
<>();
try
{
HttpClient
httpClient
=
new
HttpClientImpl
();
Map
<
String
,
String
>
params
=
buildGatewayRequestString
();
String
result
=
httpClient
.
doPost
(
gatewayUatUrl
,
params
,
HttpClientImpl
.
DEFAULT_CHARSET
,
60000
,
60000
);
log
.
info
(
"nativeHttpCall result="
+
result
);
log
.
info
(
"nativeHttpCall decrypt result="
+
EncodeUtil
.
decrypt
(
result
,
key
));
List
<
Map
<
String
,
String
>>
params
=
buildGatewayRequestString
();
for
(
Map
<
String
,
String
>
s:
params
)
{
String
result
=
httpClient
.
doPost
(
gatewayUatUrl
,
s
,
HttpClientImpl
.
DEFAULT_CHARSET
,
60000
,
60000
);
resultList
.
add
(
result
);
log
.
info
(
"nativeHttpCall result="
+
result
);
log
.
info
(
"nativeHttpCall decrypt result="
+
EncodeUtil
.
decrypt
(
result
,
key
));
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
log
.
info
(
"**********************************************"
);
return
resultList
;
}
public
static
Map
<
String
,
String
>
buildGatewayRequestString
()
throws
Exception
{
public
static
List
<
Map
<
String
,
String
>
>
buildGatewayRequestString
()
throws
Exception
{
Properties
properties
=
PropertiesUtils
.
getProperties
();
String
gatewayUatUrl
=
properties
.
getProperty
(
"esb.security.gateway.uat.url"
);
String
key
=
properties
.
getProperty
(
"esb.security.key"
);
...
...
@@ -85,49 +98,95 @@ public class DspReleaseInfoService {
Gson
gson
=
new
Gson
();
String
currentTimeMillisStr
=
String
.
valueOf
(
System
.
currentTimeMillis
());
/** step1: 参考接口文档 2.4输入参数说明 章节,并组装成json string **/
ApiRequest
apiRequest
=
new
ApiRequest
();
apiRequest
.
getOptions
().
put
(
"flightNos"
,
"JD0132"
);
apiRequest
.
getOptions
().
put
(
"stdTimeStart"
,
"2020-12-08 00:00:00"
);
apiRequest
.
getOptions
().
put
(
"stdTimeEnd"
,
"2020-12-08 23:59:59"
);
//分页参数
PageParam
pageParam
=
new
PageParam
();
//从第一页开始
pageParam
.
setPageIndex
(
1
);
//每次查询10条记录
pageParam
.
setPageSize
(
10
);
apiRequest
.
getOptions
().
put
(
"pageParam"
,
pageParam
);
String
apiRequestJson
=
gson
.
toJson
(
apiRequest
);
log
.
info
(
"dubbo interface apiRequestJson="
+
apiRequestJson
);
/** step2: 构建 gateway 接口 signature 参数**/
String
signature
=
EncodeUtil
.
generateToken
(
userAccount
,
key
,
apiRequestJson
,
currentTimeMillisStr
);
log
.
info
(
"signature="
+
signature
);
/** step3: 构建外网网关接口参数 **/
Map
<
String
,
String
>
gatewayParam
=
new
HashMap
<>();
//dubbo 接口参数,json 格式
gatewayParam
.
put
(
"inParams"
,
apiRequestJson
);
//接口文档中的 2.1 包名与类名
gatewayParam
.
put
(
"packageName"
,
"com.hnair.opcnet.api.ods.dsp.GetDspReleaseApi"
);
//接口文档中的 2.2 方法名
gatewayParam
.
put
(
"methodName"
,
"getDspReleaseInfoByPage"
);
//hna-esb-security.xml 文件中的password
gatewayParam
.
put
(
"password"
,
password
);
//step2 的签名串
gatewayParam
.
put
(
"signature"
,
signature
);
//当前时间string 串
gatewayParam
.
put
(
"time"
,
currentTimeMillisStr
);
String
gatewayParamStr
=
gson
.
toJson
(
gatewayParam
);
log
.
info
(
"gatewayParamStr="
+
gatewayParamStr
);
//step3 对gatewayParamStr 进行加密,key 来自hna-esb-security.xml 文件中的key
String
requestString
=
EncodeUtil
.
encrypt
(
gatewayParamStr
,
key
);
log
.
info
(
"requestString encrypt="
+
requestString
);
Map
<
String
,
String
>
requstMap
=
new
HashMap
<>();
requstMap
.
put
(
"userName"
,
userAccount
);
requstMap
.
put
(
"requestString"
,
requestString
);
return
requstMap
;
List
<
Map
<
String
,
String
>>
maps
=
new
ArrayList
<>();
StatisticalDao
dao
=
session
.
getMapper
(
StatisticalDao
.
class
);
List
<
String
>
flightNoList
=
dao
.
getFlightNoList
();
for
(
String
s:
flightNoList
)
{
ApiRequest
apiRequest
=
new
ApiRequest
();
apiRequest
.
getOptions
().
put
(
"flightNos"
,
s
);
apiRequest
.
getOptions
().
put
(
"stdTimeStart"
,
"2020-12-09 00:00:00"
);
apiRequest
.
getOptions
().
put
(
"stdTimeEnd"
,
"2020-12-09 23:59:59"
);
//分页参数
PageParam
pageParam
=
new
PageParam
();
//从第一页开始
pageParam
.
setPageIndex
(
1
);
//每次查询10条记录
pageParam
.
setPageSize
(
100
);
apiRequest
.
getOptions
().
put
(
"pageParam"
,
pageParam
);
String
apiRequestJson
=
gson
.
toJson
(
apiRequest
);
log
.
info
(
"dubbo interface apiRequestJson="
+
apiRequestJson
);
/** step2: 构建 gateway 接口 signature 参数**/
String
signature
=
EncodeUtil
.
generateToken
(
userAccount
,
key
,
apiRequestJson
,
currentTimeMillisStr
);
log
.
info
(
"signature="
+
signature
);
/** step3: 构建外网网关接口参数 **/
Map
<
String
,
String
>
gatewayParam
=
new
HashMap
<>();
//dubbo 接口参数,json 格式
gatewayParam
.
put
(
"inParams"
,
apiRequestJson
);
//接口文档中的 2.1 包名与类名
gatewayParam
.
put
(
"packageName"
,
"com.hnair.opcnet.api.ods.dsp.GetDspReleaseApi"
);
//接口文档中的 2.2 方法名
gatewayParam
.
put
(
"methodName"
,
"getDspReleaseInfoByPage"
);
//hna-esb-security.xml 文件中的password
gatewayParam
.
put
(
"password"
,
password
);
//step2 的签名串
gatewayParam
.
put
(
"signature"
,
signature
);
//当前时间string 串
gatewayParam
.
put
(
"time"
,
currentTimeMillisStr
);
String
gatewayParamStr
=
gson
.
toJson
(
gatewayParam
);
log
.
info
(
"gatewayParamStr="
+
gatewayParamStr
);
//step3 对gatewayParamStr 进行加密,key 来自hna-esb-security.xml 文件中的key
String
requestString
=
EncodeUtil
.
encrypt
(
gatewayParamStr
,
key
);
log
.
info
(
"requestString encrypt="
+
requestString
);
Map
<
String
,
String
>
requstMap
=
new
HashMap
<>();
requstMap
.
put
(
"userName"
,
userAccount
);
requstMap
.
put
(
"requestString"
,
requestString
);
maps
.
add
(
requstMap
);
}
return
maps
;
}
public
static
void
addInfo
()
throws
GeneralSecurityException
,
UnsupportedEncodingException
{
Properties
properties
=
PropertiesUtils
.
getProperties
();
String
key
=
properties
.
getProperty
(
"esb.security.key"
);
StatisticalDao
dao
=
session
.
getMapper
(
StatisticalDao
.
class
);
List
<
String
>
resultList
=
nativeHttpCall
();
for
(
String
result:
resultList
)
{
String
response
=
EncodeUtil
.
decrypt
(
result
,
key
);
System
.
out
.
println
(
response
);
//转成jsonObject
JSONObject
jsonObject
=
JSON
.
parseObject
(
response
);
//取出jsonObject中的data
String
resultJson
=
jsonObject
.
getString
(
"result"
);
System
.
out
.
println
(
resultJson
);
JSONObject
resultJsonObject
=
JSON
.
parseObject
(
resultJson
);
ResultMsg
resultMsg
=
JSONObject
.
toJavaObject
(
resultJsonObject
,
ResultMsg
.
class
);
if
(
Objects
.
nonNull
(
resultMsg
)){
if
(
"0"
.
equals
(
resultMsg
.
getResultCode
())){
//取出jsonObject中的data
String
data
=
jsonObject
.
getString
(
"data"
);
System
.
out
.
println
(
data
);
List
<
DspReleaseInfo
>
dspReleaseInfoList
=
JSON
.
parseArray
(
data
,
DspReleaseInfo
.
class
);
if
(
Objects
.
nonNull
(
dspReleaseInfoList
)){
for
(
DspReleaseInfo
ss:
dspReleaseInfoList
)
{
ss
.
setDelFlag
(
"0"
);
}
//调添加接口
dao
.
insertDspReleaseInfo
(
dspReleaseInfoList
);
session
.
commit
();
}
}
}
}
}
}
src/main/resources/mapper/StatisticalMapper.xml
View file @
46be83ea
...
...
@@ -104,4 +104,48 @@
, airline_json = values(airline_json)
, update_date = values(update_date)
</insert>
<select
id=
"getFlightNoList"
resultType=
"String"
>
SELECT
ffd.flight_no
FROM
foc_flight_dynamics ffd
WHERE
ffd.datop_chn = date_sub( curdate(), INTERVAL 1 DAY )
AND ffd.`status` != 'CNL'
AND ffd.ata_chn IS NOT NULL
GROUP BY
ffd.flight_no
</select>
<insert
id=
"insertDspReleaseInfo"
parameterType=
"java.util.List"
>
INSERT INTO foc_flight_dynamics_sta ( send_time, flight_no, std, ac_no, dep_iata_id, arr_iata_id, total_oil, dispatcher_name, extra_oil_fuel_reason, e_e_t, weight_unit, update_time,create_date,update_date, del_flag )
VALUES
<foreach
collection=
"list"
item=
"item"
index=
"index"
separator=
","
>
(
#{item.sendTime}
, #{item.flightNo}
, #{item.std}
, #{item.acNo}
, #{item.depIataId}
, #{item.arrIataId}
, #{item.totalOil}
, #{item.dispatcherName}
, #{item.extraOilFuelReason}
, #{item.eET}
, #{item.weightUnit}
, #{item.updateTime}
, #{item.createDate}
, #{item.updateDate}
, #{item.delFlag}
)
</foreach>
ON DUPLICATE KEY UPDATE
send_time = values(send_time)
, total_oil = values(total_oil)
, extra_oil_fuel_reason = values(extra_oil_fuel_reason)
, e_e_t = values(e_e_t)
, update_date = values(update_date)
</insert>
</mapper>
\ No newline at end of file
src/main/resources/mybatis-config.xml
View file @
46be83ea
...
...
@@ -64,8 +64,6 @@
<property
name=
"password"
value=
"FOC@2016"
/>
</dataSource>
</environment>
</environments>
<mappers>
...
...
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