Commit 46be83ea by java-温文海

油量接口插入

parent 42ea7fdd
......@@ -13,6 +13,6 @@ public class DspReleaseInfoTask {
public static void main(String[] args) throws Exception {
DspReleaseInfoService.init();
DspReleaseInfoService.buildGatewayRequestString();
DspReleaseInfoService.addInfo();
}
}
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);
}
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;
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,
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,16 +98,22 @@ public class DspReleaseInfoService {
Gson gson = new Gson();
String currentTimeMillisStr = String.valueOf(System.currentTimeMillis());
/** step1: 参考接口文档 2.4输入参数说明 章节,并组装成json string **/
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", "JD0132");
apiRequest.getOptions().put("stdTimeStart", "2020-12-08 00:00:00");
apiRequest.getOptions().put("stdTimeEnd", "2020-12-08 23:59:59");
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(10);
pageParam.setPageSize(100);
apiRequest.getOptions().put("pageParam", pageParam);
String apiRequestJson = gson.toJson(apiRequest);
log.info("dubbo interface apiRequestJson=" + apiRequestJson);
......@@ -127,7 +146,47 @@ public class DspReleaseInfoService {
Map<String, String> requstMap = new HashMap<>();
requstMap.put("userName", userAccount);
requstMap.put("requestString", requestString);
return requstMap;
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 @@
, 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
......@@ -64,8 +64,6 @@
<property name="password" value="FOC@2016"/>
</dataSource>
</environment>
</environments>
<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