mirror of https://github.com/jeecgboot/jeecg-boot
feature : new Mabang Job to retrieve orders.
parent
cdf5ce3cb6
commit
28ec71f50a
|
@ -33,8 +33,9 @@ public class OrderListRawStream implements NetworkDataStream<OrderListResponse>
|
||||||
if (currentResponse.getDataCount() == 0) {
|
if (currentResponse.getDataCount() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
began = true;
|
toSend.setCursor(currentResponse.getNextCursor());
|
||||||
toSend.nextPage();
|
toSend.nextPage();
|
||||||
|
began = true;
|
||||||
return currentResponse;
|
return currentResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,8 +50,8 @@ public class OrderListRawStream implements NetworkDataStream<OrderListResponse>
|
||||||
throw new IllegalStateException("Calling hasNext before begin");
|
throw new IllegalStateException("Calling hasNext before begin");
|
||||||
}
|
}
|
||||||
// still has page left, true
|
// still has page left, true
|
||||||
if (toSend.getPage() <= currentResponse.getTotalPage()) {
|
if (currentResponse.getHasNext()) {
|
||||||
log.info("page: {}/{}, has next", toSend.getPage(), currentResponse.getTotalPage());
|
log.info("page: {}, has next", toSend.getPage());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// no page left, false
|
// no page left, false
|
||||||
|
@ -72,6 +73,7 @@ public class OrderListRawStream implements NetworkDataStream<OrderListResponse>
|
||||||
|
|
||||||
log.info("Sending request for page {}.", toSend.getPage());
|
log.info("Sending request for page {}.", toSend.getPage());
|
||||||
this.currentResponse = new OrderListRequest(toSend).send();
|
this.currentResponse = new OrderListRequest(toSend).send();
|
||||||
|
toSend.setCursor(currentResponse.getNextCursor());
|
||||||
toSend.nextPage();
|
toSend.nextPage();
|
||||||
return this.currentResponse;
|
return this.currentResponse;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,13 @@ public class OrderListRequestBody implements RequestBody {
|
||||||
private LocalDateTime endDate;
|
private LocalDateTime endDate;
|
||||||
// 1.Normal 2.Abnormal 3.All
|
// 1.Normal 2.Abnormal 3.All
|
||||||
private final static String CAN_SEND = "3";
|
private final static String CAN_SEND = "3";
|
||||||
|
private String cursor = "";
|
||||||
private Integer page = 1;
|
private Integer page = 1;
|
||||||
|
private boolean hasNext = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String api() {
|
public String api() {
|
||||||
return "order-get-order-list";
|
return "order-get-order-list-new";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,19 +37,29 @@ public class OrderListRequestBody implements RequestBody {
|
||||||
putNonNull(json, datetimeType.text() + "End", endDate, formatter::format);
|
putNonNull(json, datetimeType.text() + "End", endDate, formatter::format);
|
||||||
}
|
}
|
||||||
putNonNull(json, "canSend", CAN_SEND);
|
putNonNull(json, "canSend", CAN_SEND);
|
||||||
putNonNull(json, "page", page);
|
putNonNull(json, "cursor", cursor);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nextPage() {
|
String getCursor() {
|
||||||
setPage(this.page + 1);
|
return cursor;
|
||||||
|
}
|
||||||
|
void setCursor(String cursor) {
|
||||||
|
this.cursor = cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getPage() {
|
int getPage() {
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
void setPage(int page) {
|
||||||
|
this.page = page;
|
||||||
|
}
|
||||||
|
void nextPage() {
|
||||||
|
this.page += 1;
|
||||||
|
}
|
||||||
|
boolean getHasNext() { return hasNext; }
|
||||||
|
void setHasNext(boolean hasNext) {
|
||||||
|
this.hasNext = hasNext;
|
||||||
|
}
|
||||||
public OrderListRequestBody setStatus(OrderStatus status) {
|
public OrderListRequestBody setStatus(OrderStatus status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
return this;
|
return this;
|
||||||
|
@ -73,8 +85,8 @@ public class OrderListRequestBody implements RequestBody {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderListRequestBody setPage(int page) {
|
public OrderListRequestBody setPage(String cursor) {
|
||||||
this.page = page;
|
this.cursor = cursor;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,25 @@ import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jeecg.modules.business.domain.api.mabang.Response;
|
import org.jeecg.modules.business.domain.api.mabang.Response;
|
||||||
|
|
||||||
|
import static cn.hutool.core.util.StrUtil.trim;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Immutable object
|
* Immutable object
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class OrderListResponse extends Response {
|
public class OrderListResponse extends Response {
|
||||||
/**
|
/**
|
||||||
* total page number
|
* Response message
|
||||||
*/
|
*/
|
||||||
private final int pageCount;
|
private String message;
|
||||||
|
/**
|
||||||
|
* Has next page
|
||||||
|
*/
|
||||||
|
private boolean hasNext;
|
||||||
|
/**
|
||||||
|
* 下一页页码(加密串)
|
||||||
|
*/
|
||||||
|
private String nextCursor;
|
||||||
/**
|
/**
|
||||||
* Total data number
|
* Total data number
|
||||||
*/
|
*/
|
||||||
|
@ -25,9 +35,11 @@ public class OrderListResponse extends Response {
|
||||||
|
|
||||||
private final JSONObject rawData;
|
private final JSONObject rawData;
|
||||||
|
|
||||||
OrderListResponse(Code code, int pageCount, int dataCount, JSONArray data, JSONObject rawData) {
|
OrderListResponse(Code code, String message, String hasNext, String nextCursor, int dataCount, JSONArray data, JSONObject rawData) {
|
||||||
super(code);
|
super(code);
|
||||||
this.pageCount = pageCount;
|
setMessage(message);
|
||||||
|
setHasNext(hasNext);
|
||||||
|
setNextCursor(nextCursor);
|
||||||
this.dataCount = dataCount;
|
this.dataCount = dataCount;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.rawData = rawData;
|
this.rawData = rawData;
|
||||||
|
@ -44,19 +56,37 @@ public class OrderListResponse extends Response {
|
||||||
public static OrderListResponse parse(JSONObject json) throws OrderListRequestErrorException {
|
public static OrderListResponse parse(JSONObject json) throws OrderListRequestErrorException {
|
||||||
log.debug("Constructing a response by json.");
|
log.debug("Constructing a response by json.");
|
||||||
String code = json.getString("code");
|
String code = json.getString("code");
|
||||||
|
String message = json.getString("message");
|
||||||
if (code.equals(Code.ERROR.value))
|
if (code.equals(Code.ERROR.value))
|
||||||
throw new OrderListRequestErrorException(json.getString("message"));
|
throw new OrderListRequestErrorException(message);
|
||||||
|
|
||||||
JSONObject data = json.getJSONObject("data");
|
JSONObject data = json.getJSONObject("data");
|
||||||
int pageCount = Integer.parseInt(data.getString("pageCount"));
|
String hasNext = data.getString("hasNext");
|
||||||
int dataCount = Integer.parseInt(data.getString("dataCount"));
|
String nextCursor = data.getString("nextCursor");
|
||||||
|
int dataCount = Integer.parseInt(data.getString("total"));
|
||||||
JSONArray realData = data.getJSONArray("data");
|
JSONArray realData = data.getJSONArray("data");
|
||||||
log.info("Constructed response: data contained {}, total page {}, total data {}", realData.size(), pageCount, dataCount);
|
log.info("Constructed response: data contained {}, total data {}", realData.size(), dataCount);
|
||||||
return new OrderListResponse(Code.SUCCESS, pageCount, dataCount, realData, json);
|
return new OrderListResponse(Code.SUCCESS, message, hasNext, nextCursor, dataCount, realData, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTotalPage() {
|
public String getMessage() {
|
||||||
return pageCount;
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = trim(message);
|
||||||
|
}
|
||||||
|
public boolean getHasNext() {
|
||||||
|
return hasNext;
|
||||||
|
}
|
||||||
|
public void setHasNext(String hasNext) {
|
||||||
|
this.hasNext = hasNext.equals("true");
|
||||||
|
}
|
||||||
|
public String getNextCursor() {
|
||||||
|
return this.nextCursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNextCursor(String nextCursor) {
|
||||||
|
this.nextCursor = nextCursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONArray getData() {
|
public JSONArray getData() {
|
||||||
|
@ -74,7 +104,6 @@ public class OrderListResponse extends Response {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "OrderListResponse{" +
|
return "OrderListResponse{" +
|
||||||
"pageCount=" + pageCount +
|
|
||||||
", dataCount=" + dataCount +
|
", dataCount=" + dataCount +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,10 +74,10 @@ public class RetrieveOrderListJob implements Job {
|
||||||
|
|
||||||
// sent request for newly paid orders
|
// sent request for newly paid orders
|
||||||
OrderListRequestBody body = new OrderListRequestBody();
|
OrderListRequestBody body = new OrderListRequestBody();
|
||||||
body.setDatetimeType(DateType.PAID)
|
body.setDatetimeType(DateType.PAID);
|
||||||
.setStartDate(begin)
|
body.setStartDate(begin);
|
||||||
.setEndDate(end)
|
body.setEndDate(end);
|
||||||
.setStatus(OrderStatus.AllUnshipped);
|
body.setStatus(OrderStatus.AllUnshipped);
|
||||||
OrderListRawStream rawStream = new OrderListRawStream(body);
|
OrderListRawStream rawStream = new OrderListRawStream(body);
|
||||||
// get data in json array format
|
// get data in json array format
|
||||||
List<OrderListResponse> rawStreamAll = rawStream.all();
|
List<OrderListResponse> rawStreamAll = rawStream.all();
|
||||||
|
@ -118,11 +118,10 @@ public class RetrieveOrderListJob implements Job {
|
||||||
|
|
||||||
// Query orders that updated in a certain duration of time in the past.
|
// Query orders that updated in a certain duration of time in the past.
|
||||||
OrderListRequestBody updatedOrderBody = new OrderListRequestBody();
|
OrderListRequestBody updatedOrderBody = new OrderListRequestBody();
|
||||||
updatedOrderBody
|
updatedOrderBody.setStartDate(begin);
|
||||||
.setStartDate(begin)
|
updatedOrderBody.setEndDate(end);
|
||||||
.setEndDate(end)
|
updatedOrderBody.setDatetimeType(DateType.UPDATE);
|
||||||
.setDatetimeType(DateType.UPDATE)
|
updatedOrderBody.setStatus(OrderStatus.Pending);
|
||||||
.setStatus(OrderStatus.Pending);
|
|
||||||
|
|
||||||
OrderListRawStream rawStream = new OrderListRawStream(updatedOrderBody);
|
OrderListRawStream rawStream = new OrderListRawStream(updatedOrderBody);
|
||||||
OrderListStream stream = new OrderListStream(rawStream);
|
OrderListStream stream = new OrderListStream(rawStream);
|
||||||
|
|
Loading…
Reference in New Issue