Commit 46be83ea by java-温文海

油量接口插入

parent 42ea7fdd
...@@ -13,6 +13,6 @@ public class DspReleaseInfoTask { ...@@ -13,6 +13,6 @@ public class DspReleaseInfoTask {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
DspReleaseInfoService.init(); DspReleaseInfoService.init();
DspReleaseInfoService.buildGatewayRequestString(); DspReleaseInfoService.addInfo();
} }
} }
package com.foc.dao; package com.foc.dao;
import com.foc.entity.DspReleaseInfo;
import com.foc.entity.StatisticalEntity; import com.foc.entity.StatisticalEntity;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -67,4 +68,17 @@ public interface StatisticalDao { ...@@ -67,4 +68,17 @@ public interface StatisticalDao {
* @param list * @param list
*/ */
void insertOrUpdateBatch(List<StatisticalEntity> list); void insertOrUpdateBatch(List<StatisticalEntity> list);
/**
* 获取航班号列表
* @return
*/
List<String> getFlightNoList();
/**
* 批量新增或修改
* @param list
*/
void insertDspReleaseInfo(List<DspReleaseInfo> list);
} }
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;
}
package com.foc.service; 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.ApiRequest;
import com.foc.thirdpart.esb.EncodeUtil; import com.foc.thirdpart.esb.EncodeUtil;
import com.foc.thirdpart.esb.HttpClient; import com.foc.thirdpart.esb.HttpClient;
import com.foc.thirdpart.esb.PageParam; import com.foc.thirdpart.esb.PageParam;
import com.foc.thirdpart.esb.nativehttp.HttpClientImpl; import com.foc.thirdpart.esb.nativehttp.HttpClientImpl;
import com.foc.util.DateUtils;
import com.foc.util.PropertiesUtils; import com.foc.util.PropertiesUtils;
import com.foc.util.StringUtils; import com.foc.util.StringUtils;
import com.google.gson.Gson; import com.google.gson.Gson;
...@@ -17,9 +24,9 @@ import org.slf4j.LoggerFactory; ...@@ -17,9 +24,9 @@ import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.util.HashMap; import java.io.UnsupportedEncodingException;
import java.util.Map; import java.security.GeneralSecurityException;
import java.util.Properties; import java.util.*;
/** /**
* @author LEGION * @author LEGION
...@@ -44,34 +51,40 @@ public class DspReleaseInfoService { ...@@ -44,34 +51,40 @@ public class DspReleaseInfoService {
} }
} }
public static void sync() {
} private static List<String> nativeHttpCall() {
private static void nativeHttpCall() {
Properties properties = PropertiesUtils.getProperties(); Properties properties = PropertiesUtils.getProperties();
String gatewayUatUrl = properties.getProperty("esb.security.gateway.uat.url"); String gatewayUatUrl = properties.getProperty("esb.security.gateway.uat.url");
String key = properties.getProperty("esb.security.key"); String key = properties.getProperty("esb.security.key");
if (StringUtils.isEmpty(gatewayUatUrl) || StringUtils.isEmpty(key)) { if (StringUtils.isEmpty(gatewayUatUrl) || StringUtils.isEmpty(key)) {
log.error("获取配置文件中机型的文件"); log.error("获取配置文件中机型的文件");
return; return null;
} }
log.info("**********************************************"); log.info("**********************************************");
log.info("----nativeHttpCall-----"); log.info("----nativeHttpCall-----");
List<String> resultList = new ArrayList<>();
try { try {
HttpClient httpClient = new HttpClientImpl(); HttpClient httpClient = new HttpClientImpl();
Map<String, String> params = buildGatewayRequestString(); List<Map<String, String>> params = buildGatewayRequestString();
String result = httpClient.doPost(gatewayUatUrl, params, for (Map<String, String> s:params
HttpClientImpl.DEFAULT_CHARSET, 60000, 60000); ) {
log.info("nativeHttpCall result=" + result); String result = httpClient.doPost(gatewayUatUrl, s,
log.info("nativeHttpCall decrypt result=" + EncodeUtil.decrypt(result, key)); 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) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
log.info("**********************************************"); 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(); Properties properties = PropertiesUtils.getProperties();
String gatewayUatUrl = properties.getProperty("esb.security.gateway.uat.url"); String gatewayUatUrl = properties.getProperty("esb.security.gateway.uat.url");
String key = properties.getProperty("esb.security.key"); String key = properties.getProperty("esb.security.key");
...@@ -85,49 +98,95 @@ public class DspReleaseInfoService { ...@@ -85,49 +98,95 @@ public class DspReleaseInfoService {
Gson gson = new Gson(); Gson gson = new Gson();
String currentTimeMillisStr = String.valueOf(System.currentTimeMillis()); String currentTimeMillisStr = String.valueOf(System.currentTimeMillis());
/** step1: 参考接口文档 2.4输入参数说明 章节,并组装成json string **/ /** 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();
}
}
}
}
} }
} }
...@@ -104,4 +104,48 @@ ...@@ -104,4 +104,48 @@
, airline_json = values(airline_json) , airline_json = values(airline_json)
, update_date = values(update_date) , update_date = values(update_date)
</insert> </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> </mapper>
\ No newline at end of file
...@@ -64,8 +64,6 @@ ...@@ -64,8 +64,6 @@
<property name="password" value="FOC@2016"/> <property name="password" value="FOC@2016"/>
</dataSource> </dataSource>
</environment> </environment>
</environments> </environments>
<mappers> <mappers>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment