|
@@ -7,6 +7,16 @@ import com.caimei.model.ResponseJson;
|
|
import com.caimei.model.po.*;
|
|
import com.caimei.model.po.*;
|
|
import com.caimei.model.vo.*;
|
|
import com.caimei.model.vo.*;
|
|
import com.caimei.service.auth.*;
|
|
import com.caimei.service.auth.*;
|
|
|
|
+import com.google.gson.Gson;
|
|
|
|
+import com.kuaidi100.sdk.api.AutoNum;
|
|
|
|
+import com.kuaidi100.sdk.api.QueryTrack;
|
|
|
|
+import com.kuaidi100.sdk.core.IBaseClient;
|
|
|
|
+import com.kuaidi100.sdk.pojo.HttpResult;
|
|
|
|
+import com.kuaidi100.sdk.request.AutoNumReq;
|
|
|
|
+import com.kuaidi100.sdk.request.QueryTrackParam;
|
|
|
|
+import com.kuaidi100.sdk.request.QueryTrackReq;
|
|
|
|
+import com.kuaidi100.sdk.response.QueryTrackResp;
|
|
|
|
+import com.kuaidi100.sdk.utils.SignUtils;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -24,6 +34,10 @@ import java.util.*;
|
|
@Slf4j
|
|
@Slf4j
|
|
@Service
|
|
@Service
|
|
public class LogisticsServiceImpl implements LogisticsService {
|
|
public class LogisticsServiceImpl implements LogisticsService {
|
|
|
|
+ /** 快递100授权KEY */
|
|
|
|
+ private static final String LOGISTICS_KEY = "bEZlgVkW1438";
|
|
|
|
+ /** 快递100企业版授权码 */
|
|
|
|
+ private static final String LOGISTICS_CUSTOMER = "1414E0E533E3311FBA5E633C10F78306";
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private LogisticsMapper logisticsMapper;
|
|
private LogisticsMapper logisticsMapper;
|
|
@@ -34,6 +48,9 @@ public class LogisticsServiceImpl implements LogisticsService {
|
|
@Value("${caimei.imageDomain}")
|
|
@Value("${caimei.imageDomain}")
|
|
private String imageDomain;
|
|
private String imageDomain;
|
|
|
|
|
|
|
|
+ @Value("${spring.profiles.active}")
|
|
|
|
+ private String active;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public ResponseJson sendCertificate(Integer authId, Integer companyId, String logisticsNumber, JSONArray imageList, String remarks, String mobile) {
|
|
public ResponseJson sendCertificate(Integer authId, Integer companyId, String logisticsNumber, JSONArray imageList, String remarks, String mobile) {
|
|
List<LogisticsCompanyVo> logisticsCompanyList = logisticsMapper.getLogisticsCompanyList(companyId);
|
|
List<LogisticsCompanyVo> logisticsCompanyList = logisticsMapper.getLogisticsCompanyList(companyId);
|
|
@@ -68,10 +85,19 @@ public class LogisticsServiceImpl implements LogisticsService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public ResponseJson certificateLogistics(Integer authId) {
|
|
public ResponseJson certificateLogistics(Integer authId) {
|
|
|
|
+ System.out.println(active);
|
|
List<CertificateLogisticsVo> certificateLogisticsList = logisticsMapper.getCertificateLogistics(authId);
|
|
List<CertificateLogisticsVo> certificateLogisticsList = logisticsMapper.getCertificateLogistics(authId);
|
|
|
|
+ CertificateLogisticsVo Logistics=null;
|
|
CertificateLogisticsVo certificateLogistics=null;
|
|
CertificateLogisticsVo certificateLogistics=null;
|
|
if(null!=certificateLogisticsList && certificateLogisticsList.size()>0){
|
|
if(null!=certificateLogisticsList && certificateLogisticsList.size()>0){
|
|
- certificateLogistics=certificateLogisticsList.get(0);
|
|
|
|
|
|
+ Logistics=certificateLogisticsList.get(0);
|
|
|
|
+ //手动更新物流追踪信息
|
|
|
|
+ updateLogistics(Logistics.getId(),Logistics.getLogisticsNumber(),Logistics.getCompanyCode(),Logistics.getOrderID(),Logistics.getMobile());
|
|
|
|
+ }
|
|
|
|
+ //修改后重新获取
|
|
|
|
+ List<CertificateLogisticsVo> LogisticsList = logisticsMapper.getCertificateLogistics(authId);
|
|
|
|
+ if(null!=LogisticsList && LogisticsList.size()>0){
|
|
|
|
+ certificateLogistics=LogisticsList.get(0);
|
|
}
|
|
}
|
|
if (null != certificateLogistics) {
|
|
if (null != certificateLogistics) {
|
|
String remarksImage = certificateLogistics.getRemarksImage();
|
|
String remarksImage = certificateLogistics.getRemarksImage();
|
|
@@ -94,6 +120,138 @@ public class LogisticsServiceImpl implements LogisticsService {
|
|
return ResponseJson.success(certificateLogistics);
|
|
return ResponseJson.success(certificateLogistics);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 更新物流追踪信息
|
|
|
|
+ * @param logisticsNumber 快递单号
|
|
|
|
+ * @param company 快递公司编码
|
|
|
|
+ * @param orderId 订单id
|
|
|
|
+ */
|
|
|
|
+ public void updateLogistics(Integer id,String logisticsNumber,String company,Long orderId,String mo){
|
|
|
|
+ //正式环境才去读取物流信息
|
|
|
|
+ if("prod".equals(active)){
|
|
|
|
+ CertificateLogisticsVo logistics=new CertificateLogisticsVo();
|
|
|
|
+ logistics.setId(id);
|
|
|
|
+ boolean updateFlag = false;
|
|
|
|
+ Date current = new Date();
|
|
|
|
+ if (logisticsNumber.length() >= 8) {
|
|
|
|
+ ResponseJson<QueryTrackResp> result = getLogisticsByNumber(logisticsNumber, company, "");
|
|
|
|
+ if (result.getCode() == -2) {
|
|
|
|
+ // 顺丰速运需要提供收/寄件人的电话号码查询
|
|
|
|
+ String mobile;
|
|
|
|
+ if (null != orderId) {
|
|
|
|
+ mobile = logisticsMapper.getLogisticsPhoneByOrderId(orderId);
|
|
|
|
+ }else {
|
|
|
|
+ mobile = mo;
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(mobile)) {
|
|
|
|
+ result = getLogisticsByNumber(logisticsNumber, company, mobile);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (result.getCode() == 0) {
|
|
|
|
+ // 查询成功
|
|
|
|
+ QueryTrackResp queryTrackResp = result.getData();
|
|
|
|
+ String state = queryTrackResp.getState();
|
|
|
|
+ String companyCode = queryTrackResp.getCom();
|
|
|
|
+ String info = new Gson().toJson(queryTrackResp.getData());
|
|
|
|
+ if (StringUtils.isNotEmpty(state) && StringUtils.isNotEmpty(info)) {
|
|
|
|
+ logistics.setState(Integer.valueOf(state));
|
|
|
|
+ logistics.setCompanyCode(companyCode);
|
|
|
|
+ logistics.setInfo(info);
|
|
|
|
+ logistics.setUpdateDate(current);
|
|
|
|
+ updateFlag = true;
|
|
|
|
+ }
|
|
|
|
+ if ("400".equals(queryTrackResp.getReturnCode())) {
|
|
|
|
+ logistics.setState(-1);
|
|
|
|
+ String errInfo = "[{\"time\":\"" + current + "\",\"context\":\"" + queryTrackResp.getMessage() + "\",\"ftime\":\" + new Date() + \"}]";
|
|
|
|
+ logistics.setInfo(errInfo);
|
|
|
|
+ logistics.setUpdateDate(current);
|
|
|
|
+ updateFlag = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ logistics.setState(-1);
|
|
|
|
+ String errInfo = "[{\"time\":\"" + current + "\",\"context\":\"运单号错误!\",\"ftime\":\"" + current + "\"}]";
|
|
|
|
+ logistics.setInfo(errInfo);
|
|
|
|
+ logistics.setUpdateDate(current);
|
|
|
|
+ updateFlag = true;
|
|
|
|
+ }
|
|
|
|
+ if (updateFlag) {
|
|
|
|
+ // 更新数据库物流信息
|
|
|
|
+ logisticsMapper.updateLogistics(logistics);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 智能获取物流信息
|
|
|
|
+ *
|
|
|
|
+ * @param number 快递单号
|
|
|
|
+ * @param companyCode 快递公司的编码
|
|
|
|
+ * @param mobile 收/寄件人的电话号码(顺丰必填)
|
|
|
|
+ */
|
|
|
|
+ public ResponseJson<QueryTrackResp> getLogisticsByNumber(String number, String companyCode, String mobile) {
|
|
|
|
+ if (StringUtils.isEmpty(number)) {
|
|
|
|
+ return ResponseJson.error("参数错误:快递单号不能为空!", null);
|
|
|
|
+ }
|
|
|
|
+ // 智能获取物流公司代码
|
|
|
|
+ AutoNumReq autoNumReq = new AutoNumReq();
|
|
|
|
+ autoNumReq.setKey(LOGISTICS_KEY);
|
|
|
|
+ autoNumReq.setNum(number);
|
|
|
|
+ AutoNum baseClient = new AutoNum();
|
|
|
|
+ try {
|
|
|
|
+ String firstComByNum = baseClient.getFirstComByNum(autoNumReq);
|
|
|
|
+ if (StringUtils.isEmpty(firstComByNum) && StringUtils.isNotEmpty(companyCode)) {
|
|
|
|
+ firstComByNum = companyCode;
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(firstComByNum)) {
|
|
|
|
+ // 顺丰需要提供手机号
|
|
|
|
+ if ("shunfeng".equals(firstComByNum) && StringUtils.isEmpty(mobile)){
|
|
|
|
+ return ResponseJson.error(-2, "顺丰速运需要提供收/寄件人的电话号码查询,请提供后重试", null);
|
|
|
|
+ }
|
|
|
|
+ // 根据快递单号获取物流信息
|
|
|
|
+ return queryLogistics(number, mobile, firstComByNum);
|
|
|
|
+ }
|
|
|
|
+ return ResponseJson.error("未能识别物流公司,请提供正确的快递单号后重试!", null);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("智能获取物流公司代码,错误信息:", e);
|
|
|
|
+ return ResponseJson.error("智能获取物流公司出错,请提供物流公司代码后重试!", null);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 根据快递单号获取物流信息
|
|
|
|
+ *
|
|
|
|
+ * @param number 快递单号
|
|
|
|
+ * @param companyCode 快递公司的编码
|
|
|
|
+ * @param mobile 收/寄件人的电话号码(顺丰必填)
|
|
|
|
+ */
|
|
|
|
+ private ResponseJson<QueryTrackResp> queryLogistics(String number, String mobile, String companyCode) {
|
|
|
|
+ // 设置参数信息
|
|
|
|
+ QueryTrackParam queryTrackParam = new QueryTrackParam();
|
|
|
|
+ queryTrackParam.setCom(companyCode);
|
|
|
|
+ queryTrackParam.setNum(number);
|
|
|
|
+ if (StringUtils.isNotEmpty(mobile)) {
|
|
|
|
+ queryTrackParam.setPhone(mobile);
|
|
|
|
+ }
|
|
|
|
+ String param = new Gson().toJson(queryTrackParam);
|
|
|
|
+ // 设置请求信息
|
|
|
|
+ QueryTrackReq queryTrackReq = new QueryTrackReq();
|
|
|
|
+ queryTrackReq.setParam(param);
|
|
|
|
+ queryTrackReq.setCustomer(LOGISTICS_CUSTOMER);
|
|
|
|
+ queryTrackReq.setSign(SignUtils.querySign(param , LOGISTICS_KEY, LOGISTICS_CUSTOMER));
|
|
|
|
+
|
|
|
|
+ IBaseClient baseClient = new QueryTrack();
|
|
|
|
+ try {
|
|
|
|
+ HttpResult httpResult = baseClient.execute(queryTrackReq);
|
|
|
|
+ if (httpResult.getStatus() == 200 && StringUtils.isNotBlank(httpResult.getBody())) {
|
|
|
|
+ QueryTrackResp queryTrackResp = (new Gson()).fromJson(httpResult.getBody(), QueryTrackResp.class);
|
|
|
|
+ log.info(">> 获取物流信息:"+number+" >> " + new Gson().toJson(queryTrackResp));
|
|
|
|
+ return ResponseJson.success(queryTrackResp);
|
|
|
|
+ }
|
|
|
|
+ return ResponseJson.error(httpResult.toString(), null);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("获取物流信息,错误信息:", e);
|
|
|
|
+ return ResponseJson.error("获取物流信息错误"+e.toString(), null);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
@Override
|
|
@Override
|
|
public ResponseJson getLogisticsCompany() {
|
|
public ResponseJson getLogisticsCompany() {
|
|
List<LogisticsCompanyVo> logisticsCompanyList = logisticsMapper.getLogisticsCompanyList(null);
|
|
List<LogisticsCompanyVo> logisticsCompanyList = logisticsMapper.getLogisticsCompanyList(null);
|