|
@ -1,7 +1,19 @@
|
|
|
package com.yihu.wlyy.service.app.express;
|
|
|
|
|
|
import com.yihu.wlyy.entity.dict.DmExpressagePriceEntity;
|
|
|
import com.yihu.wlyy.entity.organization.Hospital;
|
|
|
import com.yihu.wlyy.entity.patient.prescription.Prescription;
|
|
|
import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressage;
|
|
|
import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressageLog;
|
|
|
import com.yihu.wlyy.entity.patient.prescription.PrescriptionLog;
|
|
|
import com.yihu.wlyy.repository.dict.DmExpressagePriceDao;
|
|
|
import com.yihu.wlyy.repository.organization.HospitalDao;
|
|
|
import com.yihu.wlyy.repository.prescription.PrescriptionDao;
|
|
|
import com.yihu.wlyy.repository.prescription.PrescriptionExpressageDao;
|
|
|
import com.yihu.wlyy.repository.prescription.PrescriptionExpressageLogDao;
|
|
|
import com.yihu.wlyy.repository.prescription.PrescriptionLogDao;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
|
import com.yihu.wlyy.util.HttpClientUtil;
|
|
|
import com.yihu.wlyy.util.SFUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@ -10,14 +22,18 @@ import org.apache.http.message.BasicNameValuePair;
|
|
|
import org.dom4j.Document;
|
|
|
import org.dom4j.DocumentHelper;
|
|
|
import org.dom4j.Element;
|
|
|
import org.dom4j.dom.DOMDocument;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.TransactionDefinition;
|
|
|
import org.springframework.transaction.TransactionStatus;
|
|
|
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
/**
|
|
@ -44,10 +60,82 @@ public class SFExpressService extends BaseService {
|
|
|
@Autowired
|
|
|
private HttpClientUtil HttpClientUtil;
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private SFUtils SFUtils;
|
|
|
|
|
|
@Autowired
|
|
|
private JpaTransactionManager transactionManager;
|
|
|
|
|
|
@Autowired
|
|
|
private PrescriptionLogDao prescriptionLogDao;
|
|
|
|
|
|
@Autowired
|
|
|
private PrescriptionDao prescriptionDao;
|
|
|
|
|
|
@Autowired
|
|
|
private DmExpressagePriceDao dmExpressagePriceDao;
|
|
|
|
|
|
@Autowired
|
|
|
private PrescriptionExpressageLogDao prescriptionExpressageLogDao;
|
|
|
|
|
|
@Autowired
|
|
|
private PrescriptionExpressageDao prescriptionExpressageDao;
|
|
|
|
|
|
@Autowired
|
|
|
private HospitalDao hospitalDao;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 组装请求参数,发送请求
|
|
|
* @param xml
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
private String SFExpressPost(String xml)throws Exception{
|
|
|
String verifyCode = SFUtils.verifyCodeSFXmlStr(xml,sf_check_word);
|
|
|
List<NameValuePair> params = new ArrayList<>();
|
|
|
params.add(new BasicNameValuePair("xml", xml));
|
|
|
params.add(new BasicNameValuePair("verifyCode", verifyCode));
|
|
|
String re = HttpClientUtil.post(sf_url, params, "UTF-8");
|
|
|
return re;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 校验返回的xml报文
|
|
|
* @param responseXml
|
|
|
* @param title
|
|
|
*/
|
|
|
private void verificationResponXml(String responseXml,String title) throws Exception {
|
|
|
String error = "";
|
|
|
if (StringUtils.isBlank(responseXml)) {
|
|
|
// 如果返回的XML报文为空,请求也算失败
|
|
|
//保存http日志
|
|
|
error = title + ",返回的XML为空!";
|
|
|
logger.info(error);
|
|
|
throw new Exception(error);
|
|
|
}else{
|
|
|
// 报错的报文示例<Response service="ScopeService"><Head>ERR</Head><ERROR code="8014">校验码错误 </ERROR></Response>
|
|
|
Document doc = DocumentHelper.parseText(responseXml);
|
|
|
String headvalue = doc.selectSingleNode("/Response/Head").getText();
|
|
|
if(StringUtils.isNotBlank(headvalue) && "ERR".equals(headvalue)){
|
|
|
//错误代码
|
|
|
String errorCode = "";
|
|
|
//错误代对应的文字
|
|
|
String errorMessage = doc.selectSingleNode("/Response/ERROR").getText();
|
|
|
Document error_doc = doc.selectSingleNode("/Response/ERROR").getDocument();
|
|
|
Element root = error_doc.getRootElement();
|
|
|
List<?> child = root.elements();
|
|
|
for (Object o : child){
|
|
|
Element e = (Element) o;
|
|
|
errorCode = e.attributeValue("code");
|
|
|
}
|
|
|
error = title+","+errorCode+","+errorMessage;
|
|
|
logger.info(error);
|
|
|
throw new Exception(error);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查询派送地址是否属于顺丰的派送范围
|
|
@ -95,10 +183,17 @@ public class SFExpressService extends BaseService {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public PrescriptionExpressage postSFOrderService(PrescriptionExpressage sfexpress_obj) throws Exception {
|
|
|
String xml = SFUtils.postSFOrderService(sfexpress_obj,sf_code);
|
|
|
|
|
|
//获取医生所处的医院详细地址,作为寄件人地址
|
|
|
Prescription prescription = prescriptionDao.findByCode(sfexpress_obj.getPrescriptionCode());
|
|
|
Hospital hospital = hospitalDao.findByCode(prescription.getHospital());
|
|
|
|
|
|
String xml = SFUtils.postSFOrderService(sfexpress_obj,hospital,sf_code);
|
|
|
String re = this.SFExpressPost(xml);
|
|
|
|
|
|
//xml验证
|
|
|
verificationResponXml(re,"向顺丰快递下订单失败!");
|
|
|
|
|
|
Document doc = DocumentHelper.parseText(re);
|
|
|
String headvalue = doc.selectSingleNode("/Response/Head").getText();
|
|
|
if(StringUtils.isNotBlank(headvalue) && "OK".equals(headvalue)) {
|
|
@ -120,62 +215,356 @@ public class SFExpressService extends BaseService {
|
|
|
logger.info("顺丰快递下订单失败:派送地址不可派送,处方编号:"+sfexpress_obj.getPrescriptionCode());
|
|
|
throw new Exception("顺丰快递下订单失败:派送地址不可派送");
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isBlank(mailno)){
|
|
|
logger.info("顺丰快递下订单失败:未获取到快递单号!"+sfexpress_obj.getPrescriptionCode());
|
|
|
throw new Exception("顺丰快递下订单失败:未获取到快递单号!");
|
|
|
}
|
|
|
sfexpress_obj.setMailno(mailno);
|
|
|
}
|
|
|
return sfexpress_obj;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 组装请求参数,发送请求
|
|
|
* 调用顺丰接口获取物流路由日志,与本地匹配,进行增量修改,并返回完整日志列表
|
|
|
* @param prescription
|
|
|
* @param sfexpress_obj
|
|
|
* @param sfexpresslogList
|
|
|
* @return
|
|
|
*/
|
|
|
public List<PrescriptionExpressageLog> getRoutInfos(Prescription prescription, PrescriptionExpressage sfexpress_obj, List<PrescriptionExpressageLog> sfexpresslogList) throws Exception {
|
|
|
String xml = SFUtils.getRoutInfos(sfexpress_obj,sf_code);
|
|
|
String re = this.SFExpressPost(xml);
|
|
|
//xml验证
|
|
|
verificationResponXml(re,"查询顺丰快递路由信息失败!");
|
|
|
Document doc = DocumentHelper.parseText(re);
|
|
|
String headvalue = doc.selectSingleNode("/Response/Head").getText();
|
|
|
if(StringUtils.isNotBlank(headvalue) && "OK".equals(headvalue)) {
|
|
|
|
|
|
}
|
|
|
List<Document> redocs = doc.selectNodes("/Response/Body/RouteResponse");
|
|
|
|
|
|
String mailno = "";
|
|
|
for (Document routdoc : redocs) {
|
|
|
Element root = routdoc.getRootElement();
|
|
|
List<?> child = root.elements();
|
|
|
for (Object o : child) {
|
|
|
Element e = (Element) o;
|
|
|
mailno = e.attributeValue("mailno");
|
|
|
//判断快递单号不为空,且和我们本地的一致
|
|
|
if(StringUtils.isNotBlank(mailno) &&
|
|
|
sfexpress_obj.getMailno().equals(mailno)){
|
|
|
|
|
|
//解析报文,结合本地数据返回最终的日志结果
|
|
|
return this.xmltologlist(e,sfexpresslogList,sfexpress_obj);
|
|
|
}else{
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
private List<PrescriptionExpressageLog> xmltologlist(Element e, List<PrescriptionExpressageLog> sfexpresslogList, PrescriptionExpressage sfexpress_obj)throws Exception{
|
|
|
|
|
|
//获取本地所有路由信息的时间集
|
|
|
Set<String> routAcceptTimeSet = new HashSet<>();
|
|
|
for (PrescriptionExpressageLog log: sfexpresslogList) {
|
|
|
routAcceptTimeSet.add(DateUtil.dateToStrLong(log.getAcceptTime()));
|
|
|
}
|
|
|
|
|
|
List<?> child = e.elements();
|
|
|
|
|
|
List<PrescriptionExpressageLog> newroutinfolist = new ArrayList<>();
|
|
|
|
|
|
//用于判断新节点是否包含了"已收件"的节点
|
|
|
boolean isContainEndRoutInfo = false;
|
|
|
|
|
|
for (Object o : child) {
|
|
|
Element routinfoe = (Element) o;
|
|
|
String accept_time = routinfoe.attributeValue("accept_time");
|
|
|
String accept_address = routinfoe.attributeValue("accept_address");
|
|
|
String accept_remark = routinfoe.attributeValue("remark");
|
|
|
String opcode = routinfoe.attributeValue("opcode");
|
|
|
|
|
|
//和时间集作比对,过滤已存在的
|
|
|
if(!routAcceptTimeSet.contains(accept_time)){
|
|
|
PrescriptionExpressageLog newlogobj = new PrescriptionExpressageLog();
|
|
|
newlogobj.setAcceptTime(DateUtil.strToDate(accept_time));
|
|
|
newlogobj.setAcceptAddress(accept_address);
|
|
|
newlogobj.setAcceptRemark(accept_remark);
|
|
|
newlogobj.setOpCode(opcode);
|
|
|
newlogobj.setCode(UUID.randomUUID().toString().replace("-",""));
|
|
|
newlogobj.setPrescriptionCode(sfexpress_obj.getPrescriptionCode());
|
|
|
newlogobj.setExpressageCode(sfexpress_obj.getExpressageCode());
|
|
|
newlogobj.setCreateTime(new Date());
|
|
|
newroutinfolist.add(newlogobj);
|
|
|
sfexpresslogList.add(newlogobj);
|
|
|
//accept_remark为"已收件",代表派送结束
|
|
|
if("已收件".equals(accept_remark)){
|
|
|
isContainEndRoutInfo = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
|
|
|
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别,开启新事务
|
|
|
TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态
|
|
|
try {
|
|
|
|
|
|
//如果有新增的路由信息,则添加到数据库
|
|
|
if(!newroutinfolist.isEmpty()){
|
|
|
prescriptionExpressageLogDao.save(newroutinfolist);
|
|
|
}
|
|
|
|
|
|
//如果路由信息节点包含了"已收件"节点,这修改处方派送状态为完成,增加物流派送日志为完成
|
|
|
if(isContainEndRoutInfo){
|
|
|
//修改处方状态为完成
|
|
|
prescriptionDao.updateStatus(sfexpress_obj.getPrescriptionCode(), PrescriptionLog.PrescriptionLogStatus.finish.getValue());
|
|
|
|
|
|
//保存配送成功的日志
|
|
|
PrescriptionLog prescriptionLog = new PrescriptionLog();
|
|
|
prescriptionLog.setPrescriptionCode(sfexpress_obj.getPrescriptionCode());
|
|
|
prescriptionLog.setCode(UUID.randomUUID().toString());
|
|
|
prescriptionLog.setType(PrescriptionLog.PrescriptionLogType.sf.getValue());
|
|
|
prescriptionLog.setCreateTime(new Date());
|
|
|
prescriptionLog.setFlag(1);
|
|
|
prescriptionLog.setStatus(PrescriptionLog.PrescriptionLogStatus.finish.getValue());
|
|
|
prescriptionLogDao.save(prescriptionLog);
|
|
|
}
|
|
|
|
|
|
//事务提交
|
|
|
transactionManager.commit(status);
|
|
|
} catch (Exception ex) {
|
|
|
//报错事务回滚
|
|
|
transactionManager.rollback(status);
|
|
|
}
|
|
|
|
|
|
|
|
|
return sfexpresslogList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 解析顺丰推送过来的路由信息,和本地数据匹配并进行增量更新)
|
|
|
* @param xml
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
private String SFExpressPost(String xml)throws Exception{
|
|
|
String verifyCode = SFUtils.verifyCodeSFXmlStr(xml,sf_check_word);
|
|
|
List<NameValuePair> params = new ArrayList<>();
|
|
|
params.add(new BasicNameValuePair("xml", xml));
|
|
|
params.add(new BasicNameValuePair("verifyCode", verifyCode));
|
|
|
String re = HttpClientUtil.post(sf_url, params, "UTF-8");
|
|
|
return re;
|
|
|
public void SFRoutePushService(String xml) throws Exception{
|
|
|
Document doc = DocumentHelper.parseText(xml);
|
|
|
Document bodydoc = doc.selectSingleNode("/Request/Body").getDocument();
|
|
|
Element root = bodydoc.getRootElement();
|
|
|
if (root.element("WaybillRoute") != null) //包含WaybillRoute节点
|
|
|
{
|
|
|
root = root.element("WaybillRoute");
|
|
|
}
|
|
|
List<?> child = root.elements();
|
|
|
|
|
|
Map<String,List<PrescriptionExpressageLog>> wayroutlsit = new HashMap<>();
|
|
|
for (Object o : child) {
|
|
|
Element routinfoe = (Element) o;
|
|
|
PrescriptionExpressageLog sflog = new PrescriptionExpressageLog();
|
|
|
String accept_time = routinfoe.attributeValue("acceptTime");
|
|
|
String accept_address = routinfoe.attributeValue("acceptAddress");
|
|
|
String accept_remark = routinfoe.attributeValue("remark");
|
|
|
String opcode = routinfoe.attributeValue("opCode");
|
|
|
String mailno = routinfoe.attributeValue("mailno");
|
|
|
String orderid = routinfoe.attributeValue("orderid");
|
|
|
|
|
|
sflog.setAcceptTime(DateUtil.strToDate(accept_time));
|
|
|
sflog.setAcceptAddress(accept_address);
|
|
|
sflog.setAcceptRemark(accept_remark);
|
|
|
sflog.setOpCode(opcode);
|
|
|
sflog.setExpressageCode(orderid);
|
|
|
sflog.setCode(UUID.randomUUID().toString());
|
|
|
if(wayroutlsit.keySet().contains(mailno)){
|
|
|
wayroutlsit.get(mailno).add(sflog);
|
|
|
}else{
|
|
|
List<PrescriptionExpressageLog> newsflogs = new ArrayList<>();
|
|
|
newsflogs.add(sflog);
|
|
|
wayroutlsit.put(mailno,newsflogs);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(!wayroutlsit.keySet().isEmpty()){
|
|
|
for (String mailno:wayroutlsit.keySet()) {
|
|
|
List<PrescriptionExpressageLog> pushSFLogs = wayroutlsit.get(mailno);
|
|
|
//同一个快递单号的执行一个事务操作
|
|
|
this.saveSFPushRoutInfos(mailno,pushSFLogs);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 校验返回的xml报文
|
|
|
* @param responseXml
|
|
|
* @param title
|
|
|
* 同一个快递单号的执行一个事务操作
|
|
|
* @param mailno
|
|
|
* @param pushSFLogs
|
|
|
*/
|
|
|
private void verificationResponXml(String responseXml,String title) throws Exception {
|
|
|
String error = "";
|
|
|
if (StringUtils.isBlank(responseXml)) {
|
|
|
// 如果返回的XML报文为空,请求也算失败
|
|
|
//保存http日志
|
|
|
error = title + ",返回的XML为空!";
|
|
|
logger.info(error);
|
|
|
// logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,logService.archiveType);
|
|
|
throw new Exception(error);
|
|
|
public void saveSFPushRoutInfos(String mailno,List<PrescriptionExpressageLog> pushSFLogs){
|
|
|
|
|
|
//根据快递单号获取处方配送详细信息
|
|
|
PrescriptionExpressage sfexpress = prescriptionExpressageDao.findByPrescriptionExpressMailno(mailno);
|
|
|
//根据快递单号获取本地的路由信息
|
|
|
List<PrescriptionExpressageLog> localroutinfos = prescriptionExpressageLogDao.findByPrescriptionCode(sfexpress.getPrescriptionCode());
|
|
|
//需要增量更新到本地的路由信息集合
|
|
|
List<PrescriptionExpressageLog> newroutinfolist = new ArrayList<>();
|
|
|
|
|
|
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
|
|
|
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事务隔离级别,开启新事务
|
|
|
TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态
|
|
|
try {
|
|
|
|
|
|
//用于判断新节点是否包含了"已收件"的节点
|
|
|
boolean isContainEndRoutInfo = false;
|
|
|
|
|
|
//获取本地所有路由信息的时间集
|
|
|
Set<String> routAcceptTimeSet = new HashSet<>();
|
|
|
for (PrescriptionExpressageLog log: localroutinfos) {
|
|
|
routAcceptTimeSet.add(DateUtil.dateToStrLong(log.getAcceptTime()));
|
|
|
}
|
|
|
|
|
|
for (PrescriptionExpressageLog pushlog: pushSFLogs) {
|
|
|
|
|
|
//判断是否有已收件的路由节点
|
|
|
if("已收件".equals(pushlog.getAcceptRemark())){
|
|
|
isContainEndRoutInfo = true;
|
|
|
}
|
|
|
|
|
|
if(routAcceptTimeSet.contains(DateUtil.dateToStrLong(pushlog.getAcceptTime()))){
|
|
|
continue;
|
|
|
}else{
|
|
|
pushlog.setPrescriptionCode(sfexpress.getPrescriptionCode());
|
|
|
newroutinfolist.add(pushlog);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//如果有新增的路由信息,则添加到数据库
|
|
|
if(!newroutinfolist.isEmpty()){
|
|
|
prescriptionExpressageLogDao.save(newroutinfolist);
|
|
|
}
|
|
|
|
|
|
//如果路由信息节点包含了"已收件"节点,则修改处方状态为完成,增加物流派送日志为完成
|
|
|
if(isContainEndRoutInfo){
|
|
|
//修改处方状态为完成
|
|
|
prescriptionDao.updateStatus(sfexpress.getPrescriptionCode(), PrescriptionLog.PrescriptionLogStatus.finish.getValue());
|
|
|
|
|
|
//保存配送成功的日志
|
|
|
PrescriptionLog prescriptionLog = new PrescriptionLog();
|
|
|
prescriptionLog.setPrescriptionCode(sfexpress.getPrescriptionCode());
|
|
|
prescriptionLog.setCode(UUID.randomUUID().toString());
|
|
|
prescriptionLog.setType(PrescriptionLog.PrescriptionLogType.sf.getValue());
|
|
|
prescriptionLog.setCreateTime(new Date());
|
|
|
prescriptionLog.setFlag(1);
|
|
|
prescriptionLog.setStatus(PrescriptionLog.PrescriptionLogStatus.finish.getValue());
|
|
|
prescriptionLogDao.save(prescriptionLog);
|
|
|
}
|
|
|
//事务提交
|
|
|
transactionManager.commit(status);
|
|
|
} catch (Exception ex) {
|
|
|
//报错事务回滚
|
|
|
transactionManager.rollback(status);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据收寄地址获取快递费用
|
|
|
* @param d_province 省份名称
|
|
|
* @param d_city 城市名称
|
|
|
* @return
|
|
|
*/
|
|
|
public DmExpressagePriceEntity getSFExpressPrice(String d_province, String d_city) throws Exception{
|
|
|
String end_address_name = "";
|
|
|
|
|
|
if("厦门市".equals(d_city)){
|
|
|
end_address_name = "同城";
|
|
|
}else{
|
|
|
// <Response service="ScopeService"><Head>ERR</Head><ERROR code="8014">校验码错误 </ERROR></Response>
|
|
|
Document doc = DocumentHelper.parseText(responseXml);
|
|
|
if("福建省".equals(d_province)){
|
|
|
end_address_name = "省内";
|
|
|
}else{
|
|
|
end_address_name = d_city;
|
|
|
}
|
|
|
}
|
|
|
DmExpressagePriceEntity sfprice = dmExpressagePriceDao.getExprePriceEntityByCodeAndEndAdressName("shunfeng",end_address_name);
|
|
|
return sfprice;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据处方快递订单号判断是否下单成功
|
|
|
* 如果下单成功,保存处方物流记录,保存配送日志
|
|
|
* @param sfexpress_obj
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public boolean sfOrderSearchService(PrescriptionExpressage sfexpress_obj) throws Exception{
|
|
|
|
|
|
boolean go_on = false;
|
|
|
|
|
|
String xml = SFUtils.sfOrderSearchService(sfexpress_obj.getCode(),sf_code);
|
|
|
String re = this.SFExpressPost(xml);
|
|
|
|
|
|
try {
|
|
|
//xml验证
|
|
|
verificationResponXml(re,"订单处理失败!");
|
|
|
|
|
|
Document doc = DocumentHelper.parseText(re);
|
|
|
String headvalue = doc.selectSingleNode("/Response/Head").getText();
|
|
|
if(StringUtils.isNotBlank(headvalue) && "ERR".equals(headvalue)){
|
|
|
//错误代码
|
|
|
String errorCode = "";
|
|
|
if(StringUtils.isNotBlank(headvalue) && "OK".equals(headvalue)) {
|
|
|
//是否能派送:1:人工确认;2:可收派;3:不可以收派
|
|
|
String filter_result = "";
|
|
|
String orderid = "";//业务订单号
|
|
|
String mailno = "";//顺丰运单号
|
|
|
|
|
|
//错误代对应的文字
|
|
|
String errorMessage = doc.selectSingleNode("/Response/ERROR").getText();
|
|
|
Document error_doc = doc.selectSingleNode("/Response/ERROR").getDocument();
|
|
|
Element root = error_doc.getRootElement();
|
|
|
Document redoc = doc.selectSingleNode("/Response/Body/Orderresponse").getDocument();
|
|
|
Element root = redoc.getRootElement();
|
|
|
List<?> child = root.elements();
|
|
|
for (Object o : child){
|
|
|
for (Object o : child) {
|
|
|
Element e = (Element) o;
|
|
|
errorCode = e.attributeValue("code");
|
|
|
filter_result = e.attributeValue("filter_result");
|
|
|
orderid = e.attributeValue("orderid");
|
|
|
mailno = e.attributeValue("mailno");
|
|
|
}
|
|
|
error = title+","+errorCode+","+errorMessage;
|
|
|
logger.info(error);
|
|
|
throw new Exception(error);
|
|
|
|
|
|
if(StringUtils.isBlank(mailno)){
|
|
|
logger.info("顺丰快递下订单失败:未获取到快递单号!"+sfexpress_obj.getPrescriptionCode());
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isNotBlank(filter_result) && "3".equals(filter_result)){
|
|
|
logger.info("顺丰快递下订单失败:派送地址不可派送,处方编号:"+sfexpress_obj.getPrescriptionCode());
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
sfexpress_obj.setMailno(mailno);
|
|
|
}
|
|
|
|
|
|
//如果成功获取到快递单号,则保存处方物流记录,保存配送日志
|
|
|
|
|
|
//保存处方物流记录
|
|
|
prescriptionExpressageDao.save(sfexpress_obj);
|
|
|
|
|
|
//保存配送日志
|
|
|
PrescriptionLog prescriptionLog = new PrescriptionLog();
|
|
|
prescriptionLog.setPrescriptionCode(sfexpress_obj.getPrescriptionCode());
|
|
|
prescriptionLog.setCode(UUID.randomUUID().toString());
|
|
|
prescriptionLog.setType(PrescriptionLog.PrescriptionLogType.sf.getValue());
|
|
|
prescriptionLog.setCreateTime(new Date());
|
|
|
prescriptionLog.setFlag(1);
|
|
|
prescriptionLog.setStatus(PrescriptionLog.PrescriptionLogStatus.expressageing.getValue());
|
|
|
prescriptionLogDao.save(prescriptionLog);
|
|
|
|
|
|
|
|
|
}catch (Exception ex){
|
|
|
logger.info("顺丰快递下订单失败:派送地址不可派送,处方编号:"+sfexpress_obj.getPrescriptionCode());
|
|
|
//如果订单处理失败,则可以继续下单
|
|
|
go_on = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return go_on;
|
|
|
|
|
|
}
|
|
|
}
|