Refactor HLJob to make it possible to change request URL

pull/6221/head
Qiuyi LI 2023-11-21 15:22:01 +01:00
parent 0419db4f72
commit 09bcd7938c
2 changed files with 7 additions and 4 deletions

View File

@ -21,12 +21,13 @@ import java.util.List;
*/ */
@Slf4j @Slf4j
public class HLRequest { 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 static final RequestConfig REQUEST_CONFIG = RequestConfig.custom().build();
private final String url;
private final List<String> billCodes; private final List<String> billCodes;
public HLRequest(List<String> billCodes) { public HLRequest(String url, List<String> billCodes) {
this.url = url;
this.billCodes = billCodes; this.billCodes = billCodes;
} }
@ -40,7 +41,7 @@ public class HLRequest {
while (attempts++ < 5) { while (attempts++ < 5) {
try { try {
HttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(REQUEST_CONFIG).build(); HttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(REQUEST_CONFIG).build();
HttpPost request = new HttpPost(URL); HttpPost request = new HttpPost(url);
// adding the form data // adding the form data
request.setEntity(new UrlEncodedFormEntity(generateFormData(), "UTF-8")); request.setEntity(new UrlEncodedFormEntity(generateFormData(), "UTF-8"));

View File

@ -35,6 +35,8 @@ public class HLJob implements Job {
@Autowired @Autowired
private IPlatformOrderService platformOrderService; private IPlatformOrderService platformOrderService;
private final static String URL = "http://www.antugj.com:8082/selectTrack.htm";
private static final Integer DEFAULT_NUMBER_OF_DAYS = 15; private static final Integer DEFAULT_NUMBER_OF_DAYS = 15;
private static final Integer DEFAULT_MAXIMUM_NUMBER_OF_PARCELS_PER_TRANSACTION = 800; private static final Integer DEFAULT_MAXIMUM_NUMBER_OF_PARCELS_PER_TRANSACTION = 800;
private static final List<String> DEFAULT_TRANSPORTERS = Arrays.asList("法国专线普货"); private static final List<String> DEFAULT_TRANSPORTERS = Arrays.asList("法国专线普货");
@ -91,7 +93,7 @@ public class HLJob implements Job {
List<HLResponseItem> parcelTraces = new ArrayList<>(); List<HLResponseItem> parcelTraces = new ArrayList<>();
List<HLRequest> hlRequests = new ArrayList<>(); List<HLRequest> hlRequests = new ArrayList<>();
billCodeLists.forEach(billcodeList -> { billCodeLists.forEach(billcodeList -> {
HLRequest hlRequest = new HLRequest(billcodeList); HLRequest hlRequest = new HLRequest(URL, billcodeList);
hlRequests.add(hlRequest); hlRequests.add(hlRequest);
}); });
List<Boolean> results = new ArrayList<>(); List<Boolean> results = new ArrayList<>();