feat : (WIP) sku temp build

pull/8040/head
Gauthier LO 2024-12-20 17:16:42 +01:00
parent 08528696c7
commit e2cfbf031f
3 changed files with 174 additions and 1 deletions

View File

@ -0,0 +1,123 @@
package org.jeecg.modules.business.domain.api.mabang.doSearchSkuListNew;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.business.domain.api.mabang.getorderlist.NetworkDataStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
/**
* This class provide stream of order.
*/
@Slf4j
public class UnpairedSkuListStream implements NetworkDataStream<SkuData> {
private final NetworkDataStream<SkuListResponse> rawStream;
private List<SkuData> skus;
private int index;
private boolean began;
/**
* Flag of current data is already empty,
* either currentOrders is null or currentIndex arrives at the end.
* In both case, we should call next() of the rawStream.
*/
private boolean empty;
public UnpairedSkuListStream(NetworkDataStream<SkuListResponse> rawStream) {
this.rawStream = rawStream;
skus = null;
this.index = 0;
this.empty = true;
this.began = false;
}
@Override
public List<SkuData> all() {
SkuData firstElement = attempt();
if (firstElement == null) {
return Collections.emptyList();
}
ArrayList<SkuData> res = new ArrayList<>();
if (firstElement.getStatus().equals(SkuStatus.AutomaticallyCreated)) {
res.add(firstElement);
}
while (hasNext()) {
SkuData nextSku = next();
if(nextSku.getStatus().equals(SkuStatus.AutomaticallyCreated)) {
res.add(nextSku);
}
}
return res;
}
@Override
public SkuData attempt() {
began = true;
log.info("Attempting for the first request");
SkuListResponse response = rawStream.attempt();
if (response == null) {
log.info("No response");
return null;
}
if (response.getData().isEmpty()) {
log.info("Response with empty data");
return null;
}
skus = response.getData().toJavaList(SkuData.class);
log.info("Raw response: {}", response.getData());
index = 1;
log.info("Returned the first element");
empty = index >= skus.size();
return skus.get(0);
}
@Override
public boolean hasNext() {
// the first time
if (!began) {
throw new IllegalStateException("Calling hasNext before begin");
}
// Current data is not yet empty
if (index < skus.size()) {
log.debug("Current order list is not empty yet");
return true;
}
/* Current data is empty */
this.empty = true;
log.debug("Current order list is already empty,");
// and raw stream is empty too.
if (!rawStream.hasNext()) {
log.debug("and source stream is empty too, hasNext: false");
return false;
}
// but raw stream not empty.
else {
log.debug("but source stream still has data, hasNext: true");
return true;
}
}
@Override
public SkuData next() {
if (!hasNext()) {
throw new NoSuchElementException("Stream is empty!");
}
if (empty) {
skus = this.rawStream.next().getData().toJavaList(SkuData.class);
empty = false;
index = 0;
}
log.debug("Return data at {}", index);
SkuData res = skus.get(index);
index++;
return res;
}
}

View File

@ -0,0 +1,50 @@
package org.jeecg.modules.business.domain.job;
import lombok.extern.slf4j.Slf4j;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.jeecg.modules.business.domain.api.mabang.doSearchSkuListNew.*;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Component
public class MabangUnpairedSkuJob implements Job {
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap jobDataMap = context.getMergedJobDataMap();
List<String> skuList = new ArrayList<>();
String parameter = ((String) jobDataMap.get("parameter"));
if (parameter != null) {
try {
JSONObject jsonObject = new JSONObject(parameter);
if (!jsonObject.isNull("skus")) {
for (int i = 0; i < jsonObject.getJSONArray("skus").length(); i++) {
skuList.add(jsonObject.getJSONArray("skus").getString(i));
}
}
} catch (JSONException e) {
log.error("Error while parsing parameter as JSON, falling back to default parameters.");
}
}
if(skuList.isEmpty()) {
log.error("No skus provided, exiting job.");
return;
}
SkuListRequestBody body = new SkuListRequestBody();
body.setStockSkuList(String.join(",", skuList));
SkuListRawStream rawStream = new SkuListRawStream(body);
UnpairedSkuListStream stream = new UnpairedSkuListStream(rawStream);
List<SkuData> skusFromMabang = stream.all();
// System.out.println("skus from mabang : " + skusFromMabang);
}
}

View File

@ -107,7 +107,7 @@
JOIN client c ON s.owner_id = c.id
JOIN client_category cc ON c.client_category_id = cc.id
WHERE po.erp_status IN (1,2)
AND cc.name = 'self-service'
AND cc.name IN ('self-service', 'confirmed')
AND po.order_time &gt;= #{start}
ORDER BY po.order_time
),