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 ...
随机推荐
- 【原创】遇到:Invalid layout of java.lang.String at value 这样的问题,该怎么办呢?
Invalid layout of java.lang.String at value## A fatal error has been detected by the Java Runtime En ...
- java打开windows系统的浏览器
获得百度的数据有两种方式,一种是用Url从流中获得,另一种是直接打开浏览器.文字识别(OCR)后再转码可以快速百度 public static void main(String[] args) thr ...
- HDU 1969 精度二分
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- 深入理解javascript之typeof和instanceof
1.https://blog.csdn.net/mevicky/article/details/50353881 (深入理解javascript之typeof和instanceof)
- 手写DCGAN
//加上了注释,对pytorch又加深了理解import torch as t from torch import nn from torch.autograd import Variable fro ...
- 使用POI导入小数变成浮点数异常
例如 我在Excel中的数据为17.2, 导入到表中就变成了17.1999999或者17.20000001 原因是我用double接收了17.2,然后直接用了String去转换,精度就丢失了. 代 ...
- linux 常用操作以及概念
一.常用操作以及概念 查看LINUX发行版的名称及其版本号的命令: lsb_release -a cat /etc/redhat-release(针对redhat,Fedora) 0.rpm包路径:/ ...
- ansible常用套路(一)
一.SSH互信 1 配置/etc/ansible/hosts 文件 [zabbix_agent] 172.26.4.203 172.26.4.204 172.26.4.205 [zabbix_agen ...
- 201621123006 《Java程序设计》第10周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 本次PTA作业题集异常 1. 常用异常 结合题集题目7-1回答 1.1 自己以前编写的代码中经常出现 ...
- ubuntu16切换hosts软件安装
之前用ubuntu切换hosts以为没有软件可用,直接用cp来替换hosts文件,今天网上搜了一下发现一个软件和window上用的切hosts功能一样,而且可以支持linux,mac,windows. ...