This commit is contained in:
linfso 2024-09-21 20:16:52 +08:00
parent 35d4224dc9
commit 9c68348391
3 changed files with 505 additions and 139 deletions

View File

@ -695,6 +695,199 @@ public class EmisCommonController extends EmisBaseController
return rst;
}
@PostMapping("/notifyTraceBy17track")
public void notifyTraceBy17track(@RequestBody String body){
String lockKey="notifyTraceBy17track";
log.error("notifyTraceBy17track start");
/*
{
"event": "TRACKING_UPDATED",
"data": {
"number": "RR123456789CN",
"carrier": 3011,
"param": "518000",
"tag": "myID",
"track_info": {
"shipping_info": {
"shipper_address": {
"country": "CN",
"state": "GD",
"city": "SHENZHEN",
"street": "HARTFORD CT DISTRIBUTION CENTER",
"postal_code": "518000",
"coordinates": {
"longitude": "114.085947",
"latitude": "22.547"
}
},
"recipient_address": {
"country": "AF",
"state": null,
"city": "KABUL",
"street": null,
"postal_code": null,
"coordinates": {
"longitude": null,
"latitude": null
}
}
},
"latest_status": {
"status": "InfoReceived",
"sub_status": "InfoReceived",
"sub_status_descr": null
},
"latest_event": {
"time_iso": "2022-05-23T22:22:00+08:00",
"time_utc": "2022-05-23T14:22:00Z",
"description": "Shipment information sent to FedEx",
"description_translation": {
"lang": "en",
"description": "Shipment information sent to FedEx"
},
"location": "NJ",
"stage": "InfoReceived",
"address": {
"country": "US",
"state": "NJ",
"city": "MARLTON",
"street": null,
"postal_code": "08053",
"coordinates": {
"longitude": null,
"latitude": null
}
}
},
"time_metrics": {
"days_after_order": 7,
"days_of_transit": 7,
"days_of_transit_done": 7,
"days_after_last_update": 57,
"estimated_delivery_date": {
"source":"Official",
"from": "2022-03-02T18:43:24-06:00",
"to": "2022-03-03T19:43:24-06:00"
}
},
"milestone": [
{
"key_stage": "InfoReceived",
"time_iso": "2022-04-25T22:22:47-05:00",
"time_utc": "2022-04-26T03:22:47Z"
},
{
"key_stage": "PickedUp",
"time_iso": "2022-04-25T16:22:00+08:00",
"time_utc": "2022-04-25T08:22:00Z"
},
{
"key_stage": "Departure",
"time_iso": "2022-05-19T21:40:00+08:00",
"time_utc": "2022-05-19T13:40:00Z"
},
{
"key_stage": "Arrival",
"time_iso": null,
"time_utc": null
},
{
"key_stage": "AvailableForPickup",
"time_iso": null,
"time_utc": null
},
{
"key_stage": "OutForDelivery",
"time_iso": null,
"time_utc": null
},
{
"key_stage": "Delivered",
"time_iso": null,
"time_utc": null
},
{
"key_stage": "Returning",
"time_iso": null,
"time_utc": null
},
{
"key_stage": "Returned",
"time_iso": null,
"time_utc": null
}
],
"misc_info": {
"risk_factor": 0,
"service_type": "FedEx International Priority",
"weight_raw": "1.1 KG",
"weight_kg": "1.1",
"pieces": "1",
"dimensions": "22*20*16 CM",
"customer_number": "2459642000~270434455123~FX",
"reference_number": null,
"local_number": "270434455123",
"local_provider": "Fedex",
"local_key": 100003
},
"tracking": {
"providers_hash": 2067301750,
"providers": [
{
"provider": {
"key": 3011,
"name": "China Post",
"alias": "China Post",
"tel": null,
"homepage": "http://www.17track.net",
"country": "CN"
},
"service_type": "International Priority",
"latest_sync_status": "Success",
"latest_sync_time": "2022-06-09T05:46:31Z",
"events_hash": -227928244,
"events": [
{
"time_iso": "2022-04-29T09:19:00-08:00",
"time_utc": "2022-04-29T17:19:00Z",
"description": "At local FedEx facility",
"description_translation": {
"lang": "en",
"description": "At local FedEx facility"
},
"location": "ANCHORAGE, AK, US",
"stage": "InfoReceived",
"address": {
"country": "US",
"state": "AK",
"city": "ANCHORAGE",
"street": null,
"postal_code": "99502",
"coordinates": {
"longitude": "35.86166",
"latitude": "104.195397"
}
}
}
]
}
]
}
}
}
}
*/
String rst="{\n" +
" \"result\":true,\n" +
" \"returnCode\":\"200\",\n" +
" \"message\":\"成功\"\n" +
" }";
log.error("notifyTraceBy17track end");
}
/**
* 导出进仓单模板
* @param response

View File

@ -2848,9 +2848,9 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
);
if(CollectionUtils.isEmpty(emisQuotePriceList)){
throw new EmisBizError(EmisBizErrorType.CALC_QUOTE_ERROR, "报价未配置");
}
// if(CollectionUtils.isEmpty(emisQuotePriceList)){
// throw new EmisBizError(EmisBizErrorType.CALC_QUOTE_ERROR, "报价未配置");
// }
// 根据表达式计算费用
String calcFeeType = emisWaybill.getCalcFeeType();
@ -2858,163 +2858,165 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
double totalFee = 0.0D;
List<EmisWaybillFeeitem> feeList = new ArrayList<>();
Map<String,Integer> feeTypeMap = new HashMap<>();
for (EmisQuotePrice quoteItem: emisQuotePriceList) {
// 不允许重复
if(feeTypeMap.containsKey(quoteItem.getFeeType())){
continue;
}
if(!CollectionUtils.isEmpty(emisQuotePriceList)) {
for (EmisQuotePrice quoteItem : emisQuotePriceList) {
List<EmisQuoteExpression> exprList = quoteItem.getExprList();
if(CollectionUtils.isEmpty(exprList)){
continue;
}
// 判断是否要计算报关费 只有一般贸易报关需要收取报关费
// 2002-报关费 3-一般报关
if( "2002".equals(quoteItem.getFeeType()) ){
if( !"3".equals(emisWaybill.getCustomsEclaration()) ){
// 不允许重复
if (feeTypeMap.containsKey(quoteItem.getFeeType())) {
continue;
}
}
// 2003-清关费 3-一般贸易清关
if( "2003".equals(quoteItem.getFeeType()) ){
if(!"3".equals(emisWaybill.getCustomsClear())){
List<EmisQuoteExpression> exprList = quoteItem.getExprList();
if (CollectionUtils.isEmpty(exprList)) {
continue;
}
}
EmisWaybillFeeitem feeItem = null;
// 重量计费 , 一口价
if("1".equals(calcFeeType) || "3".equals(calcFeeType)){
for (EmisQuoteExpression exprItem: exprList) {
log.info("计算项目:"+JSONObject.toJSONString(exprItem)+",重量:"+emisWaybill.getSettlementWeight().doubleValue());
if( exprItem.getStartWeight().doubleValue() < emisWaybill.getSettlementWeight().doubleValue()
&& exprItem.getEndWeight().doubleValue() >= emisWaybill.getSettlementWeight().doubleValue()
){
feeItem = new EmisWaybillFeeitem();
feeItem.setFeeCode(quoteItem.getFeeType());
String feeName=DictUtils.getDictLabel("emis_fee_type",quoteItem.getFeeType());
feeItem.setFeeName(feeName);
// 币种
feeItem.setCurrency(quoteItem.getCurrency());
feeItem.setQuoteId(quoteItem.getQuoteId());
feeItem.setExprId(exprItem.getId());
// 最低报价
feeItem.setLeastPrice(quoteItem.getLeastPrice());
String calcExp = exprItem.getCalculateExpression();
feeItem.setCalcExp(calcExp);
feeItem.setAddWeightPrice(BigDecimal.valueOf(exprItem.getAdditionalWeight()));
feeItem.setInitialWeightFee(BigDecimal.valueOf(exprItem.getInitialWeight()));
String calcExprStr=calcExp.replaceAll("w",emisWaybill.getSettlementWeight().toString())
.replaceAll("s",exprItem.getInitialWeight().toString())
.replaceAll("d",exprItem.getAdditionalWeight().toString());
log.info("计算公式:"+calcExprStr+",重量:"+emisWaybill.getSettlementWeight());
double fee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString());
fee=WaybillHelper.calcSettledFee(fee,quoteItem.getPriceType());
// 如果低于最低报价,则使用最低报价来计算
if( fee < quoteItem.getLeastPrice().doubleValue() ){
fee = quoteItem.getLeastPrice().doubleValue();
feeItem.setRemark("must > "+quoteItem.getLeastPrice().doubleValue());
}else{
feeItem.setRemark(feeItem.getCalcExp());
}
feeItem.setFee(BigDecimal.valueOf(fee));
feeItem.setRealFee(BigDecimal.valueOf(fee));
log.info("计算后费用:"+feeItem.getFee());
totalFee=totalFee+fee;
feeItem.setBlAutoGen("1");
// 计算完成后就结束
break;
// 判断是否要计算报关费 只有一般贸易报关需要收取报关费
// 2002-报关费 3-一般报关
if ("2002".equals(quoteItem.getFeeType())) {
if (!"3".equals(emisWaybill.getCustomsEclaration())) {
continue;
}
}
}
// 体积计费
else if("2".equals(calcFeeType)){
for (EmisQuoteExpression exprItem: exprList) {
if(
exprItem.getStartWeight().doubleValue() < emisWaybill.getTotalVolume().doubleValue()
&& exprItem.getEndWeight().doubleValue() >= emisWaybill.getTotalVolume().doubleValue()
){
feeItem = new EmisWaybillFeeitem();
feeItem.setFeeCode(quoteItem.getFeeType());
String feeName=DictUtils.getDictLabel("emis_fee_type",quoteItem.getFeeType());
feeItem.setFeeName(feeName);
// 币种
feeItem.setCurrency(quoteItem.getCurrency());
feeItem.setQuoteId(quoteItem.getQuoteId());
feeItem.setExprId(exprItem.getId());
// 最低报价
feeItem.setLeastPrice(quoteItem.getLeastPrice());
String calcExp = exprItem.getCalculateExpression();
feeItem.setCalcExp(calcExp);
feeItem.setAddWeightPrice(BigDecimal.valueOf(exprItem.getAdditionalWeight()));
feeItem.setInitialWeightFee(BigDecimal.valueOf(exprItem.getInitialWeight()));
String calcExprStr=calcExp.replaceAll("w",emisWaybill.getTotalVolume().toString())
.replaceAll("s",exprItem.getInitialWeight().toString())
.replaceAll("d",exprItem.getAdditionalWeight().toString());
log.info("计算公式:"+calcExprStr+",体积:"+emisWaybill.getTotalVolume());
double fee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString());
fee=WaybillHelper.calcSettledFee(fee,quoteItem.getPriceType());
// 如果低于最低报价,则使用最低报价来计算
if( fee < quoteItem.getLeastPrice().doubleValue() ){
fee = quoteItem.getLeastPrice().doubleValue();
feeItem.setRemark("must > "+quoteItem.getLeastPrice().doubleValue());
}else{
feeItem.setRemark(feeItem.getCalcExp());
}
feeItem.setFee(BigDecimal.valueOf(fee));
feeItem.setRealFee(BigDecimal.valueOf(fee));
log.info("计算后费用:"+feeItem.getFee());
totalFee=totalFee+fee;
feeItem.setBlAutoGen("1");
break;
// 2003-清关费 3-一般贸易清关
if ("2003".equals(quoteItem.getFeeType())) {
if (!"3".equals(emisWaybill.getCustomsClear())) {
continue;
}
}
}
if(feeItem!=null) {
if (feeItem.getFee().compareTo(BigDecimal.ZERO) != 0) {
// 记录类型,用于判断是否重复
feeTypeMap.put(feeItem.getFeeCode(), 1);
EmisWaybillFeeitem feeItem = null;
// 重量计费 , 一口价
if ("1".equals(calcFeeType) || "3".equals(calcFeeType)) {
for (EmisQuoteExpression exprItem : exprList) {
log.info("计算项目:" + JSONObject.toJSONString(exprItem) + ",重量:" + emisWaybill.getSettlementWeight().doubleValue());
if (exprItem.getStartWeight().doubleValue() < emisWaybill.getSettlementWeight().doubleValue()
&& exprItem.getEndWeight().doubleValue() >= emisWaybill.getSettlementWeight().doubleValue()
) {
feeList.add(feeItem);
feeItem = new EmisWaybillFeeitem();
feeItem.setFeeCode(quoteItem.getFeeType());
String feeName = DictUtils.getDictLabel("emis_fee_type", quoteItem.getFeeType());
feeItem.setFeeName(feeName);
// 币种
feeItem.setCurrency(quoteItem.getCurrency());
feeItem.setQuoteId(quoteItem.getQuoteId());
feeItem.setExprId(exprItem.getId());
// 最低报价
feeItem.setLeastPrice(quoteItem.getLeastPrice());
String calcExp = exprItem.getCalculateExpression();
feeItem.setCalcExp(calcExp);
feeItem.setAddWeightPrice(BigDecimal.valueOf(exprItem.getAdditionalWeight()));
feeItem.setInitialWeightFee(BigDecimal.valueOf(exprItem.getInitialWeight()));
String calcExprStr = calcExp.replaceAll("w", emisWaybill.getSettlementWeight().toString())
.replaceAll("s", exprItem.getInitialWeight().toString())
.replaceAll("d", exprItem.getAdditionalWeight().toString());
log.info("计算公式:" + calcExprStr + ",重量:" + emisWaybill.getSettlementWeight());
double fee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString());
fee = WaybillHelper.calcSettledFee(fee, quoteItem.getPriceType());
// 如果低于最低报价,则使用最低报价来计算
if (fee < quoteItem.getLeastPrice().doubleValue()) {
fee = quoteItem.getLeastPrice().doubleValue();
feeItem.setRemark("must > " + quoteItem.getLeastPrice().doubleValue());
} else {
feeItem.setRemark(feeItem.getCalcExp());
}
feeItem.setFee(BigDecimal.valueOf(fee));
feeItem.setRealFee(BigDecimal.valueOf(fee));
log.info("计算后费用:" + feeItem.getFee());
totalFee = totalFee + fee;
feeItem.setBlAutoGen("1");
// 计算完成后就结束
break;
}
}
}
}
// 体积计费
else if ("2".equals(calcFeeType)) {
for (EmisQuoteExpression exprItem : exprList) {
if (
exprItem.getStartWeight().doubleValue() < emisWaybill.getTotalVolume().doubleValue()
&& exprItem.getEndWeight().doubleValue() >= emisWaybill.getTotalVolume().doubleValue()
) {
feeItem = new EmisWaybillFeeitem();
feeItem.setFeeCode(quoteItem.getFeeType());
String feeName = DictUtils.getDictLabel("emis_fee_type", quoteItem.getFeeType());
feeItem.setFeeName(feeName);
// 币种
feeItem.setCurrency(quoteItem.getCurrency());
feeItem.setQuoteId(quoteItem.getQuoteId());
feeItem.setExprId(exprItem.getId());
// 最低报价
feeItem.setLeastPrice(quoteItem.getLeastPrice());
String calcExp = exprItem.getCalculateExpression();
feeItem.setCalcExp(calcExp);
feeItem.setAddWeightPrice(BigDecimal.valueOf(exprItem.getAdditionalWeight()));
feeItem.setInitialWeightFee(BigDecimal.valueOf(exprItem.getInitialWeight()));
String calcExprStr = calcExp.replaceAll("w", emisWaybill.getTotalVolume().toString())
.replaceAll("s", exprItem.getInitialWeight().toString())
.replaceAll("d", exprItem.getAdditionalWeight().toString());
log.info("计算公式:" + calcExprStr + ",体积:" + emisWaybill.getTotalVolume());
double fee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString());
fee = WaybillHelper.calcSettledFee(fee, quoteItem.getPriceType());
// 如果低于最低报价,则使用最低报价来计算
if (fee < quoteItem.getLeastPrice().doubleValue()) {
fee = quoteItem.getLeastPrice().doubleValue();
feeItem.setRemark("must > " + quoteItem.getLeastPrice().doubleValue());
} else {
feeItem.setRemark(feeItem.getCalcExp());
}
feeItem.setFee(BigDecimal.valueOf(fee));
feeItem.setRealFee(BigDecimal.valueOf(fee));
log.info("计算后费用:" + feeItem.getFee());
totalFee = totalFee + fee;
feeItem.setBlAutoGen("1");
break;
}
}
}
if (feeItem != null) {
if (feeItem.getFee().compareTo(BigDecimal.ZERO) != 0) {
// 记录类型,用于判断是否重复
feeTypeMap.put(feeItem.getFeeCode(), 1);
feeList.add(feeItem);
}
}
}
}
// 对非人民币重新进行计算费用总额

View File

@ -0,0 +1,171 @@
package com.xdadan.erp.emis.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xdadan.erp.common.utils.DateUtils;
import com.xdadan.erp.emis.domain.EmisTmsScanRecord;
import com.xdadan.erp.emis.domain.EmisTmsTransferTrace;
import com.xdadan.erp.emis.domain.enumtype.WaybillStatus;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 17Track Api
* 请求头必须添加: "Content-type","application/json”
*/
@SuppressWarnings("all")
@Component
@Slf4j
public class Q17trackHelper {
private static final String QUERY_URL = "https://api.17track.net/track/v2.2/gettrackinfo";
private static final String REGISTER_URL = "https://api.17track.net/track/v2/register";
// 17track Key
private static final String KEY = "F461E71E91CC9CEBD016E2A078E5496D";
/**
* 17track 物流查询
* @param com 快递公司编码
* @param num 快递单号
* @return data
*/
public static String queryTraceInfo(String mainNo, String com,String phone) throws Exception {
Map<String, String> postHeader = new HashMap<>();
postHeader.put("17token",KEY);
JSONArray ydJsonArr = new JSONArray();
JSONObject ydJsonItem = new JSONObject();
ydJsonItem.put("number",mainNo);
ydJsonItem.put("carrier",com);
ydJsonArr.add(ydJsonItem);
String postJsonStr=ydJsonArr.toJSONString();
log.debug("===17track==POST==>{}",postJsonStr);
String allResult=HTTPHelperV3.postJson(QUERY_URL,postHeader,postJsonStr);
log.debug("===17track==REST==>{}",allResult);
return allResult;
}
/**
*
* 订阅
* @param mainNo
* @param com
* @param phone
* @return
* @throws Exception
*
*/
public static String register(String mainNo, String com) {
Map<String, String> postHeader = new HashMap<>();
postHeader.put("17token",KEY);
JSONArray ydJsonArr = new JSONArray();
JSONObject ydJsonItem = new JSONObject();
ydJsonItem.put("number",mainNo);
ydJsonArr.add(ydJsonItem);
String postJsonStr=ydJsonArr.toJSONString();
try {
log.debug("===17track==POST==>{}",postJsonStr);
String restStr=HTTPHelperV3.postJson(REGISTER_URL,postHeader,postJsonStr);
log.debug("===17track==REST==>{}",restStr);
return restStr;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static List<EmisTmsScanRecord> cvtTraceToScanRecord(String billCode,String traceInfo) {
List<EmisTmsScanRecord> recordList= null;
try {
if(!StringUtils.isEmpty(traceInfo)){
JSONObject jsonObject = JSONObject.parseObject(traceInfo);
JSONArray steps=jsonObject.getJSONArray("data");
if(steps!=null && steps.size()>0){
recordList = new ArrayList<>();
for (Object obj:steps) {
JSONObject stepItem = (JSONObject)obj;
EmisTmsScanRecord recordItem = new EmisTmsScanRecord();
recordItem.setBillCode(billCode);
recordItem.setScanDate(DateUtils.parseDate(stepItem.getString("time")));
recordItem.setRemark(stepItem.getString("context"));
recordItem.setScanType("81");
recordList.add(recordItem);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return recordList;
}
public static EmisTmsTransferTrace queryTmsTransferTraceByKd100(EmisTmsTransferTrace emisTmsTransferTrace,String phone) {
String rstStr= null;
try {
emisTmsTransferTrace.setChId("17track");
rstStr = queryTraceInfo(emisTmsTransferTrace.getTransferBillCode(),emisTmsTransferTrace.getTransferExpress(),phone);
JSONObject jsonObject=JSONObject.parseObject(rstStr);
emisTmsTransferTrace.setTraceInfo(rstStr);
/*
快递单当前状态,默认为0在途,1揽收,2疑难,3签收,4退签,5派件,8清关,14拒签等10个基础物流状态,如需要返回高级物流状态,请参考 resultv2 传值
*/
// String state=jsonObject.getString("state");
// if("3".equals(state)){
// emisTmsTransferTrace.setLastWaybillStatus(WaybillStatus.SIGNED.statusCode);
// }
//
// JSONArray steps=jsonObject.getJSONArray("data");
// if(steps!=null && steps.size()>0){
// JSONObject lastObj = steps.getJSONObject(0);
// emisTmsTransferTrace.setLastTraceDate(DateUtils.parseDate(lastObj.getString("time")));
// emisTmsTransferTrace.setRemark(lastObj.getString("context"));
// }
} catch (Exception e) {
e.printStackTrace();
}
return emisTmsTransferTrace;
}
public static void main(String[] args) {
String rst= null;
try {
String str=register("DRK50179785","100702");
System.out.println(str);
String str1=queryTraceInfo("DRK50179785","100702","137");
System.out.println(str1);
} catch (Exception e) {
e.printStackTrace();
}
}
}