mirror of https://github.com/jeecgboot/jeecg-boot
Add HL API models
parent
aed2406c81
commit
4de3ed4429
|
@ -0,0 +1,140 @@
|
||||||
|
package org.jeecg.modules.business.domain.api.hualei;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import static org.jeecg.modules.business.domain.api.ScanType.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Data
|
||||||
|
public class HLParcelTraceDetail {
|
||||||
|
|
||||||
|
@JSONField(deserialize = false)
|
||||||
|
private String parcelId;
|
||||||
|
|
||||||
|
@JsonProperty("track_date")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.S")
|
||||||
|
private String scanTime;
|
||||||
|
|
||||||
|
private String scanType;
|
||||||
|
|
||||||
|
@JsonProperty("track_kind")
|
||||||
|
private String trackKind;
|
||||||
|
|
||||||
|
@JsonProperty("track_content")
|
||||||
|
private String descriptionCn;
|
||||||
|
|
||||||
|
private String descriptionEn;
|
||||||
|
|
||||||
|
@JsonProperty("track_location")
|
||||||
|
private String location;
|
||||||
|
|
||||||
|
private static final String ARRIVAL_AT_RECEPTION_CN = "到达收货点";
|
||||||
|
private static final String ARRIVAL_AT_RECEPTION = "Parcel has been handed to logistics company";
|
||||||
|
private static final String DELIVERED = "Package delivered";
|
||||||
|
private static final String ARRIVAL_LOCAL_DELIVERY = "Arrived at local delivery center";
|
||||||
|
private static final String OUT_FOR_DELIVERY = "Out for delivery";
|
||||||
|
private static final String LOCAL_DELIVERY_RECEPTION = "Received by local delivery company";
|
||||||
|
private static final String DEPART_CUSTOMS = "Departed from customs";
|
||||||
|
private static final String AWAITING_TRANSIT_TO_FINAL_DELIVERY_OFFICE = "Awaiting for transit to final delivery office";
|
||||||
|
private static final String DEPARTED_FROM_TRANSIT_COUNTRY = "Departed from transit country/region";
|
||||||
|
private static final String LEAVING_TRANSIT_COUNTRY = "Leaving transit country/region";
|
||||||
|
private static final String IMPORT_CUSTOMS_CLEARANCE_COMPLETE = "Import customs clearance complete";
|
||||||
|
private static final String IMPORT_CUSTOMS_CLEARANCE_STARTED = "Import customs clearance started";
|
||||||
|
private static final String ARRIVAL_IN_TRANSIT_COUNTRY = "Arrived in transit country/region";
|
||||||
|
private static final String HANDED_TO_LINEHAUL = "Handed over from linehaul office";
|
||||||
|
private static final String ARRIVAL_LINEHAUL = "Arrived at linehaul office";
|
||||||
|
private static final String DEPARTED_FROM_ORIGIN = "Departed from departure country/region";
|
||||||
|
private static final String LEAVING_FROM_ORIGIN = "Leaving from departure country/region";
|
||||||
|
private static final String EXPORT_CUSTOMS_CLEARANCE_COMPLETE = "Export customs clearance complete";
|
||||||
|
private static final String EXPORT_CUSTOMS_CLEARANCE_START = "Export customs clearance started";
|
||||||
|
private static final String TRANSPORT_HUB_ARRIVAL = "Arrived at departure transport hub";
|
||||||
|
private static final String SORTING_CENTER_DEPARTURE = "[Fenggang Town] Departed from sorting center";
|
||||||
|
private static final String SORTING_CENTER_PROCESSING = "[Fenggang Town] Processing at sorting center";
|
||||||
|
private static final String ORDER_RECEIVED = "货物电子信息已经收到";
|
||||||
|
private static final String ORDER_RECEIVED_EN = "Order received by logistics company";
|
||||||
|
|
||||||
|
|
||||||
|
public HLParcelTraceDetail() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public HLParcelTraceDetail(String parcelId, String scanTime, String scanType, String trackKind,
|
||||||
|
String descriptionCn, String descriptionEn, String location) {
|
||||||
|
this.parcelId = parcelId;
|
||||||
|
this.scanTime = scanTime;
|
||||||
|
this.scanType = scanType;
|
||||||
|
this.trackKind = trackKind;
|
||||||
|
this.descriptionCn = descriptionCn;
|
||||||
|
this.descriptionEn = descriptionEn;
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set parcel ID, and write the scan type into the trace according to description
|
||||||
|
* @param parcelId Parcel ID to which the trace belongs to
|
||||||
|
*/
|
||||||
|
public void parcelTraceProcess(String parcelId) {
|
||||||
|
setParcelId(parcelId);
|
||||||
|
switch (descriptionCn) {
|
||||||
|
case DELIVERED:
|
||||||
|
setScanType(END_DELIVERED.getDesc());
|
||||||
|
break;
|
||||||
|
case ARRIVAL_LOCAL_DELIVERY:
|
||||||
|
setScanType(END_ARRIVED.getDesc());
|
||||||
|
break;
|
||||||
|
case OUT_FOR_DELIVERY:
|
||||||
|
setScanType(END_DELIVERY.getDesc());
|
||||||
|
break;
|
||||||
|
case LOCAL_DELIVERY_RECEPTION:
|
||||||
|
setScanType(END_RECEIVED.getDesc());
|
||||||
|
break;
|
||||||
|
case DEPART_CUSTOMS:
|
||||||
|
case IMPORT_CUSTOMS_CLEARANCE_COMPLETE:
|
||||||
|
setScanType(CUSTOMS_CLEARANCE_COMPLETED.getDesc());
|
||||||
|
break;
|
||||||
|
case AWAITING_TRANSIT_TO_FINAL_DELIVERY_OFFICE:
|
||||||
|
setScanType(END_SEND.getDesc());
|
||||||
|
break;
|
||||||
|
case DEPARTED_FROM_TRANSIT_COUNTRY:
|
||||||
|
case LEAVING_TRANSIT_COUNTRY:
|
||||||
|
case ARRIVAL_IN_TRANSIT_COUNTRY:
|
||||||
|
setScanType(FLIGHT_ARRIVED.getDesc());
|
||||||
|
break;
|
||||||
|
case IMPORT_CUSTOMS_CLEARANCE_STARTED:
|
||||||
|
setScanType(CUSTOMS_CLEARANCE.getDesc());
|
||||||
|
break;
|
||||||
|
case HANDED_TO_LINEHAUL:
|
||||||
|
setScanType(FLIGHT_DEPARTURE.getDesc());
|
||||||
|
break;
|
||||||
|
case ARRIVAL_LINEHAUL:
|
||||||
|
case DEPARTED_FROM_ORIGIN:
|
||||||
|
case LEAVING_FROM_ORIGIN:
|
||||||
|
setScanType(FLIGHT_PREPARING.getDesc());
|
||||||
|
break;
|
||||||
|
case EXPORT_CUSTOMS_CLEARANCE_COMPLETE:
|
||||||
|
setScanType(EXPORT_CUSTOMS_DECLARATION_COMPLETED.getDesc());
|
||||||
|
break;
|
||||||
|
case EXPORT_CUSTOMS_CLEARANCE_START:
|
||||||
|
setScanType(EXPORT_CUSTOMS_DECLARATION.getDesc());
|
||||||
|
break;
|
||||||
|
case TRANSPORT_HUB_ARRIVAL:
|
||||||
|
case SORTING_CENTER_DEPARTURE:
|
||||||
|
setScanType(FACILITY_DEPARTURE.getDesc());
|
||||||
|
break;
|
||||||
|
case SORTING_CENTER_PROCESSING:
|
||||||
|
setScanType(FACILITY_ARRIVED.getDesc());
|
||||||
|
break;
|
||||||
|
case ORDER_RECEIVED:
|
||||||
|
setDescriptionEn(ORDER_RECEIVED_EN);
|
||||||
|
setScanType(ORDER_PLACED.getDesc());
|
||||||
|
break;
|
||||||
|
case ARRIVAL_AT_RECEPTION_CN:
|
||||||
|
setDescriptionEn(ARRIVAL_AT_RECEPTION);
|
||||||
|
setScanType(BAGGING.getDesc());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package org.jeecg.modules.business.domain.api.hualei;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.NameValuePair;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.config.RequestConfig;
|
||||||
|
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class contains some key information and necessary procedures
|
||||||
|
* to send a request body to mabang API, for example target URL,
|
||||||
|
* correspondent HTTP method, procedure to generate authorization.
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class HLRequest {
|
||||||
|
private final static String URL = "http://www.antugj.com:8082/selectTrack.htm";
|
||||||
|
private static final RequestConfig REQUEST_CONFIG = RequestConfig.custom().build();
|
||||||
|
|
||||||
|
private final List<String> billCodes;
|
||||||
|
|
||||||
|
public HLRequest(List<String> billCodes) {
|
||||||
|
this.billCodes = billCodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sent request to the mabang API with a request body.
|
||||||
|
*
|
||||||
|
* @return the response
|
||||||
|
*/
|
||||||
|
public HttpResponse send() {
|
||||||
|
int attempts = 0;
|
||||||
|
while (attempts++ < 5) {
|
||||||
|
try {
|
||||||
|
HttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(REQUEST_CONFIG).build();
|
||||||
|
HttpPost request = new HttpPost(URL);
|
||||||
|
|
||||||
|
// adding the form data
|
||||||
|
request.setEntity(new UrlEncodedFormEntity(generateFormData(), "UTF-8"));
|
||||||
|
return httpClient.execute(request);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Request failed on attempt n°" + attempts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert body's json parameters to json string with the necessary extra parameter to
|
||||||
|
* send request.
|
||||||
|
*
|
||||||
|
* @return json string
|
||||||
|
*/
|
||||||
|
private List<NameValuePair> generateFormData() {
|
||||||
|
List<NameValuePair> pairs = new ArrayList<>();
|
||||||
|
String billCodesWithComas = String.join(",", billCodes);
|
||||||
|
pairs.add(new BasicNameValuePair("documentCode", billCodesWithComas));
|
||||||
|
return pairs;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package org.jeecg.modules.business.domain.api.hualei;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.modules.business.domain.api.jt.JTResponseItem;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Data
|
||||||
|
public class HLResponse {
|
||||||
|
|
||||||
|
@JsonProperty("ack")
|
||||||
|
private Boolean acknowledgment;
|
||||||
|
|
||||||
|
@JsonProperty("data")
|
||||||
|
private List<HLResponseItem> responseItems;
|
||||||
|
|
||||||
|
public HLResponse(Boolean acknowledgment, List<HLResponseItem> responseItems) {
|
||||||
|
this.acknowledgment = acknowledgment;
|
||||||
|
this.responseItems = responseItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HLResponse() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package org.jeecg.modules.business.domain.api.hualei;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Data
|
||||||
|
@TableName("parcel")
|
||||||
|
public class HLResponseItem {
|
||||||
|
|
||||||
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
|
private String id = IdWorker.getIdStr();
|
||||||
|
|
||||||
|
@JsonProperty("trackingNumber")
|
||||||
|
private String trackingNumber;
|
||||||
|
|
||||||
|
@JsonProperty("consigneeCountry")
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
@JsonProperty("productKindName")
|
||||||
|
private String productCode;
|
||||||
|
|
||||||
|
@JsonProperty("business_seqinvoicecode")
|
||||||
|
private String billCode;
|
||||||
|
|
||||||
|
@JsonProperty("referenceNumber")
|
||||||
|
private String orderNumber;
|
||||||
|
|
||||||
|
@JsonProperty("trackDetails")
|
||||||
|
private List<HLParcelTraceDetail> tracesList;
|
||||||
|
|
||||||
|
public HLResponseItem(String id, String trackingNumber, String country, String productCode, String billCode,
|
||||||
|
String orderNumber, List<HLParcelTraceDetail> tracesList) {
|
||||||
|
this.id = id;
|
||||||
|
this.trackingNumber = trackingNumber;
|
||||||
|
this.country = country;
|
||||||
|
this.productCode = productCode;
|
||||||
|
this.billCode = billCode;
|
||||||
|
this.orderNumber = orderNumber;
|
||||||
|
this.tracesList = tracesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HLResponseItem() {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue