Air21
handler
package com.icil.edi.ws.milestoneService.handler; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import com.icil.edi.dao.common.dao.EdiHistoryDAO;
import com.icil.edi.ws.common.utils.ObjectUtils;
import com.icil.edi.ws.common.utils.PropertiesUtils;
import com.icil.edi.ws.milestoneService.Air21MileStoneBean.Air21MileStoneStatus;
import com.icil.edi.ws.milestoneService.Air21MileStoneBean.Packages;
import com.icil.edi.ws.milestoneService.Air21MileStoneBean.Scan_detail;
import com.icil.edi.ws.milestoneService.Air21MileStoneBean.Shipment_tracking;
import com.icil.edi.ws.milestoneService.constant.MilestoneConstant;
import com.icil.sofs.dao.edi.dao.OrderStatusDAO;
import com.icil.sofs.dao.edi.model.OrderStatusDO;
import com.icil.sofs.dao.global.decode.dao.LocationDAO;
import com.icil.sofs.dao.global.decode.model.LocationDO; /**
*
* @ClassName: Air21OrderStatusConverter
* @Description:convert Air21 order status to table OrderStatus
* @author: Sea
* @date: 15 Jun 2018 7:24:58 PM
*
* @Copyright: 2018 ICIL. All rights reserved.
*/
@Component("air21OrderStatusHandler")
public class Air21OrderStatusHandler {
/********************************
* 1.convert bean
*
* 2.if status is DDL or DL1 ,update edi_history isOverMileStone="true"
*
* 3.delete old milestone info
*
* 4.save new milestone to orderstatus table
***************************************/
@Autowired
private EdiHistoryDAO ediHistoryDAO; @Autowired
private LocationDAO LocationDAO; @Autowired
private OrderStatusDAO OrderStatusDAO; private static final Logger LOGGER = LoggerFactory.getLogger(Air21OrderStatusHandler.class); @Transactional
public void handerStatus(List<Air21MileStoneStatus> mileStoneStatusList) { LOGGER.info("Enter into the method Air21OrderStatusHandler-->handerStatus() "); ArrayList<OrderStatusDO> orderStatusDOs = new ArrayList<OrderStatusDO>();
Properties prorperties = PropertiesUtils
.getProperties(MilestoneConstant.AIR21_MILESTONE_STATUS__MAPPING_PROPERTIES); for (Air21MileStoneStatus air21MileStoneStatus : mileStoneStatusList) {
if(air21MileStoneStatus==null){continue;}
Shipment_tracking shipment_tracking = air21MileStoneStatus.getShipment_tracking();
Packages packages = shipment_tracking.getPackages();
if(packages==null){continue;}
// reference_number is orderNo
String reference_number = packages.getReference_number();
// user to query edi_history
String orderNoJson = "";
if (reference_number != null&&) {
orderNoJson = ObjectUtils.map2Json("orderNo", reference_number); List<Scan_detail> scan_details = packages.getScan_details();
/*************
* start convert bean
***************/
for (Scan_detail scan_detail : scan_details) {
OrderStatusDO orderStatusDO = new OrderStatusDO();
orderStatusDO.setDataSource(MilestoneConstant.Air21);
if (scan_detail != null) {
String statusCode = prorperties.getProperty(scan_detail.getScan_code());
statusCode = statusCode.trim();
orderStatusDO.setStatus(statusCode);
orderStatusDO.setReferenceNo(reference_number);
// if the shipment has delivered ,update the edi_history
// respnse_summary "isOver"
if (statusCode.equalsIgnoreCase("DDL") || statusCode.equalsIgnoreCase("DL1")) {
ediHistoryDAO.updateResponseSummaryIsOverMileStoneByCourierBillNo("true", orderNoJson);
} String post_date = scan_detail.getPost_date();// 07/04/2013
String post_time = scan_detail.getPost_time(); // 11:28
// LUCENA CITY
String post_location = scan_detail.getPost_location();
// shipment is on Ari21 vehicle for delivery
String status = scan_detail.getStatus(); SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm");
Date actionDateLoc = format.parse(post_date + post_time);
orderStatusDO.setActionDateLoc(actionDateLoc);// 2018-02-10_04:45:00 /**
* TODO :timeZone
*/
// queryActionDateTz(post_location,actionDateLoc,orderStatusDO);
orderStatusDO.setActionDateGMT(actionDateLoc);
orderStatusDO.setCompletedDateLoc(actionDateLoc);
orderStatusDO.setCompletedDateTz("GMT+7");
orderStatusDO.setOtherInfo(status);
orderStatusDO.setActionPlace1(post_location);
orderStatusDOs.add(orderStatusDO);
}
}
// delete the old mileStone records from Air21 before new
// records into AFSA2 DB.
// query the records which dataSource is Air21 String sql = "select OrderStatusDO from OrderStatusDO OrderStatusDO where OrderStatusDO.orderNo='"
+ reference_number + "' and OrderStatusDO.dataSource='Air21'";
List<OrderStatusDO> oldMileStoneList = OrderStatusDAO.queryByJPQL(sql);
if (!oldMileStoneList.isEmpty()) {
OrderStatusDAO.delete(oldMileStoneList);
} // save the new mileStone info to database
try {
if (orderStatusDOs != null && orderStatusDOs.size() > ) {
LOGGER.info("Start to insert new records to OrderStatus which from Air21");
Date startInsertDate = new Date();
OrderStatusDAO.insert(orderStatusDOs, false);
Date endInsertDate = new Date();
ediCheckpointHistoryService.saveCheckpoint(startInsertDate, endInsertDate,
CheckpointConstant.CONNECT_DB, , CheckpointConstant.SAVE_TO_DB);
LOGGER.info("End of insert records to OrderStatus");
//clear the list of orderStatusDOs
orderStatusDOs.clear();
} } catch (Exception e) {
e.printStackTrace();
LOGGER.error("OrderStatusHandler.saveMileStoneRecord() occurred exception,the error is "
+ e.getMessage());
ediCheckpointHistoryService.saveCheckpoint(new Date(), new Date(), CheckpointConstant.CONNECT_DB, ,
CheckpointConstant.SAVE_TO_DB);
String subject = "Save data to DB failed";
String content = "query milestone from aftership in OrderStatusHandler.saveMileStoneRecord() occurred exception ";
EmailUtils.sendExceptionEmailNotify(subject, content, e); } } } // return orderStatusDOs; } private void queryActionDateTz(String post_location, Date date, OrderStatusDO orderStatusDO) {
String fTimeZone = "";
Map criteriaMap = new HashMap<String, String>();
criteriaMap.put("location", post_location);
List<LocationDO> locationDOlist = (List<LocationDO>) LocationDAO.query(criteriaMap);
if (!locationDOlist.isEmpty()) {
fTimeZone = locationDOlist.get().getTimezone();
} else {
fTimeZone = "US/Pacific";
} /***/
String strTimeZone = date.substring(date.lastIndexOf("T") + );
String lastTimeZone = "";
if ("".equals(strTimeZone)) {
lastTimeZone = getTimeZone(checkpoint);
if (lastTimeZone == null || "".equals(lastTimeZone)) {
lastTimeZone = fTimeZone;
}
} else {
lastTimeZone = "GMT" + strTimeZone;
}
orderStatusDO.setActionDateTz(lastTimeZone);
Date actionDateGMT = DateUtils.getGMTDate(date, lastTimeZone, MilestoneConstant.TDate_Time_Format);
orderStatusDO.setActionDateGMT(actionDateGMT);
orderStatusDO.setCompletedDateLoc(actionDateLoc);
orderStatusDO.setCompletedDateTz(lastTimeZone); /****/
} }
impl
package com.icil.edi.ws.milestoneService.impl; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List; import org.apache.xmlbeans.impl.jam.internal.elements.VoidClassImpl;
import org.glassfish.jersey.message.MessageBodyWorkers;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.XML;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import com.google.gson.Gson;
import com.icil.edi.dao.common.dao.EdiHistoryDAO;
import com.icil.edi.dao.common.exception.DAOExceptionHandler;
import com.icil.edi.dao.common.model.EdiHistoryDO;
import com.icil.edi.ws.common.constant.EdiServiceConstant;
import com.icil.edi.ws.common.utils.EmailUtils;
import com.icil.edi.ws.common.utils.PropertiesUtils;
import com.icil.edi.ws.common.utils.TypeAndPartyUtils;
import com.icil.edi.ws.common.utils.URLHttpUtils;
import com.icil.edi.ws.milestoneService.Air21MileStoneBean.Air21MileStoneStatus;
import com.icil.edi.ws.milestoneService.constant.MilestoneConstant;
import com.icil.edi.ws.milestoneService.handler.Air21OrderStatusHandler; import javassist.expr.NewArray; /**
*
* @ClassName: Air21QueryMileStoneServiceImpl
* @Description:the logic of Air21 query milestone
* @author: Sea
* @param <E>
* @date: 15 June 2018 12:06:28 PM
*
* @Copyright: 2018 ICIL. All rights reserved.
*/
@Service
public class Air21QueryMileStoneServiceImpl<E> { /***********************************************************************
* 1.create logger
*
* 1.1 do some prepare work
*
* 2.get data source form database
*
* 2.1.save edi_checkpoint history edi_history and save request data to
* server 2.2 collect edi_batchindo data
*
* 3.send courierbillNo to Air21 and get milestone 3.1 here need to try 3
* time
*
* 4.parse response
*
* 5.convert response_data_xml to bean
*
* 6.delete old milestone according to courierBillNo
*
* 7.save new milestone 7.1 here need time zone mapping
*
* 8.update edi_history filed response_summary isOverMileStone:true if
* status is DDl or Dl1 8.1 update edi_history 8.2 save response data to
* local 8.3 save batch_info .checkpoint history
*
***********************************************************************/
@Autowired
private EdiHistoryDAO ediHistoryDAO; @Autowired
private Air21OrderStatusHandler air21OrderStatusHandler; private static final Logger LOGGER = LoggerFactory.getLogger(Air21QueryMileStoneServiceImpl.class); public void queryMileStone() {
// 1 .create logger
// addTypeAndPartyToMDC(String party,String type)
TypeAndPartyUtils.addTypeAndPartyToMDC("EDI", MilestoneConstant.AS_QUERY_MILESTONE); /*
* *******************************************************************
* 2.get data source form database 2.1.save edi_checkpoint history
* edi_history and save request data to server 2.2 collect edi_batchindo
* data
******************************************************************/
LinkedList<String> air21QueryMileStoneDataSource = getAir21QueryMileStoneDataSource();
if (air21QueryMileStoneDataSource != null && air21QueryMileStoneDataSource.size() > ) { /*******************************
* 3.send courierbillNo to Air21 and get milestone 3.1 here need to
* try 3 time
********************************/ String AirQueryMileStone_Url = (String) PropertiesUtils.getProperties(EdiServiceConstant.WEBSERVICE_URL,
MilestoneConstant.AIR210QUERYMILESTONE_URL); /**
* 4 start query milestone ####
*/
Gson gson = new Gson();
ArrayList<Air21MileStoneStatus> mileStoneStatusList = new ArrayList<Air21MileStoneStatus>();
for (String ref_Number : air21QueryMileStoneDataSource) {
String response = sendRequest(AirQueryMileStone_Url + "&c=" + ref_Number);
/*********************************
* 4.parse response 5.convert response_data_xml to bean
*********************************/
if (response == null) {
// TODO:here need add some record
continue;
} /**
* TODO: jsonrespnse XML.toJSONObject(response);
* aa= jsonrespnse.getkey("shipment_tracking");
* bb=new JSONObject(aa);
* if(bb.get("reference_number")!=null){continue;}
*/ // TODO: here need save response data to server .update
// edi_history edi_checkpoint // response is_Xml here : 1. parse it to _json 2. parse to bean
// 3.collect air21MileStoneStatus
try {
String responseStr = XML.toJSONObject(response).toString();
Air21MileStoneStatus air21MileStoneStatus = gson.fromJson(responseStr, Air21MileStoneStatus.class);
mileStoneStatusList.add(air21MileStoneStatus);
} catch (JSONException e) {
LOGGER.info("response xml convert to json exceptoin ");
e.printStackTrace();
} } // end query milestone /*****************************************************
* 5 .convert bean 6.delete old milestone according to courierBillNo
* 7.save new milestone 7.1 here need time zone mapping 7.2 parse
* response result ":1.if status is DDL or DL1 ,update edi_history
* isOverMileStone="true"
***************************************************/ air21OrderStatusHandler.handerStatus(mileStoneStatusList);
} } private String sendRequest(String url) {
LOGGER.info("start invoke Air21 get milestone ");
String response = URLHttpUtils.getURLRequest(url, null);
if (response == null) {
LOGGER.info("connect Air21 exception , start second connect it ");
response = URLHttpUtils.getURLRequest(url, null);
if (response == null) {
LOGGER.info("connect Air21 exception , start third times connect it ");
response = URLHttpUtils.getURLRequest(url, null);
String subject = "Query milestone from Air21 Failed";
String content = "query milestone from Air21 failed,connect Air21 exception,plase check the net ";
EmailUtils.sendExceptionEmailNotify(subject, content, null);
}
} return response;
} private LinkedList<String> getAir21QueryMileStoneDataSource() {
// get data source from database
List<String> air21QueryMileStoneDataSource = null;
try {
air21QueryMileStoneDataSource = ediHistoryDAO.findAir21QueryMileStoneDataSource();
} catch (Exception e) {
DAOExceptionHandler.handle(e);
} // convert to only courierBillNo data list
LinkedList<String> air21DataSource = new LinkedList<String>();
for (String dataSource : air21QueryMileStoneDataSource) {
try {
JSONArray data = new JSONArray(dataSource);
String dataStr = data.get().toString();
JSONObject dataJson = new JSONObject(dataStr);
String orderNo = dataJson.get("orderNo").toString();
air21DataSource.add(orderNo);
} catch (Exception exception) {
exception.printStackTrace();
LOGGER.info("dataSource is exception");
}
}
return air21DataSource;
} }
Air21的更多相关文章
- 数据库中查询json 样式的值的sql语句
参考:http://www.lnmp.cn/mysql-57-new-features-json.html 方式一: 可以查到json中的Key:value SELECT * FROM EDI.edi ...
随机推荐
- 豆知识扩展:HTML<meta> tag
豆知识: HTML<meta> tag Metadata 是关于数据的信息. The <meta> tag provides metadata关于网页.Metadat不会显示在 ...
- IOS-详解KVO底层实现
一.KVO (Key-Value Observing) KVO 是 Objective-C 对观察者模式(Observer Pattern)的实现.也是 Cocoa Binding 的基础.当被观察对 ...
- Mysql5.7的gtid主从半同步复制和组复制
(一)gtid主从半同步复制 一.半同步复制原理 mysql默认的复制是异步的,主库在执行完客户端提交的事务后会立即将结果返回给客户端,并不关心从库是否已经接收并处理,这样就会有一个问题,主库如果cr ...
- cuteftp不能连接虚拟机的解决方法
使用cuteftp在PC和虚拟机之间传送文件 工具/原料 PC机中装有cuteftp软件和虚拟机 注意事项 首先要确保虚拟机中的ftp软件已安装,如未安装可以用如下命令安装 sudo apt-get ...
- NAT 穿透
/********************************************************************************* * NAT 穿透 * 说明: * ...
- streamsets Executors 说明
执行程序阶段在收到事件时触发任务.执行者不会写入或存储事件. 将执行程序用作事件流中数据流触发器的一部分,以执行事件驱动的与管道相关的任务,例如在目标关闭时移动完全写入的文件. 可以使用的execut ...
- 第01章-欢迎学习VTK
[译者:这个系列教程是以Kitware公司出版的<VTK User's Guide -11th edition>一书作的中文翻译(出版时间2010年,ISBN: 978-1-930934- ...
- Spring中FactoryBean与BeanFactory的区别
版本:spring-framework-4.1 一概述 BeanFactory 与 FactoryBean的区别, 两个名字很像,面试中也经常遇到,所以容易搞混,现从源码以及示例两方面来分析. 二.源 ...
- DNS中NS和SOA区别
ns 授權很簡單… 假設你註冊的 domain 叫 abc.com ,而你有 ns1 與 ns2 兩台 server . 那,你必需從 .com 的權威伺服器授權給你,其設定或類似如此: $ORIGI ...
- poj1015陪审团——DP+路径记录
题目:http://poj.org/problem?id=1015 DP的第一维是选了几个人,第二维是当前D与P的差值,而值存的是当前D与P的和: 技巧1:通过平移避免负角标,即代码中的fix: 技巧 ...