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 ...
随机推荐
- Rails 5 Test Prescriptions 第9章 Testing-JavaScript: Integration Testing,❌挂一个问题webpacker::helper
使用Capybara进行JS的集成测试 谈论驱动 让测试通过 Webpack in Development Mode Js设计 是用户在网页上有好的体验的重要因素. 尽管如此,许多网页不测试JS. 部 ...
- Coderforce 560B-Gerald is into Art
题目大意:给了三个矩形的长和宽,问第一个能否把其他两个装在内部,要求内部之间不重叠,不出界(可重边)? 题目分析:这道题...考虑不够全面导致比赛时没有出来...当时,就是觉得自己的代码很完美,不可能 ...
- 自定义jQuery的animate动画
//擦除效果 jQuery.extend(jQuery.easing, { easeOutBack : function(x, t, b, c, d, s) { s = s || 1.3; retur ...
- Xcode6中手动添加Precompile Prefix Header
Xcode5中创建一个工程的时候,系统会自动创建一个以以工程名为名字的pch(Precompile Prefix Header)文件,开发的过程中可以将广泛使用的头文件以及宏包含在该文件下,编译器就会 ...
- Java虚拟机体系结构分析
下图是JAVA虚拟机的结构图: 每个Java虚拟机都有一个类装载子系统,它根据给定的全限定名来装入类型(类或接口).同样,每个Java虚拟机都有一个执行引擎,它负责执行那些包含在被装载类的方法中的指令 ...
- L173
Technical problems temporarily blocked some US and European users having access to their accounts an ...
- Openlayers4中地图的导出
概述: 本文讲述Openlayers4中地图的导出,包括调用天地图切片跨域.Geoserver11 WMS跨域等. 效果: 导出图片 页面展示 实现代码: document.getElementByI ...
- python实践报错:SyntaxError: Non-ASCII character
报错: File "C:\001myWorkspace\001myWork\workspace2\MyFirstPython\src\demo4\demo4-2.py", line ...
- Qt SD卡 文件系统挂载、文件预览
/********************************************************************************** * Qt SD卡 文件系统挂载. ...
- linux 下的php_gd2.dll
今天写验证码时,发现要配置php.ini,单不知在哪儿,用下面的办法可以解决. <?php phpinfo(); ?> 用vim搜索字符串时,发现一个命令特别好用 /字符串 就可以搜索到字 ...