Merge pull request #78 from LQYBill/feat/clearLogisticChannelName

Feat/clear logistic channel name
pull/8040/head
Qiuyi LI 2024-06-03 09:57:23 +02:00 committed by GitHub
commit 070573ca6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 165 additions and 12 deletions

View File

@ -0,0 +1,15 @@
package org.jeecg.modules.business.domain.api.mabang.dochangeorder;
import org.jeecg.modules.business.domain.api.mabang.Request;
public class ClearLogisticRequest extends Request {
public ClearLogisticRequest(ClearLogisticRequestBody body) {
super(body);
}
@Override
public ClearLogisticResponse send() {
String jsonString = rawSend().getBody();
return ClearLogisticResponse.parse(jsonString);
}
}

View File

@ -0,0 +1,34 @@
package org.jeecg.modules.business.domain.api.mabang.dochangeorder;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.jeecg.modules.business.domain.api.mabang.RequestBody;
@Data
public class ClearLogisticRequestBody implements RequestBody {
private String platformOrderId;
public ClearLogisticRequestBody(String platformOrderId) {
this.platformOrderId = platformOrderId;
}
@Override
public String api() {
return "order-do-order-logistics";
}
@Override
public JSONObject parameters() {
JSONObject json = new JSONObject();
putNonNull(json, "platformOrderId", platformOrderId);
putNonNull(json, "type", 1);
return json;
}
private <E> void putNonNull(JSONObject json, String key, E value) {
if (value != null) {
json.put(key, value);
}
}
}

View File

@ -0,0 +1,23 @@
package org.jeecg.modules.business.domain.api.mabang.dochangeorder;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.modules.business.domain.api.mabang.Response;
public class ClearLogisticResponse extends Response {
private ClearLogisticResponse(Code status) {
super(status);
}
public static ClearLogisticResponse parse(String json) {
JSONObject jsonObject = JSON.parseObject(json);
String code = jsonObject.getString("code");
if (code.equals("200")) {
return new ClearLogisticResponse(Code.SUCCESS);
} else {
return new ClearLogisticResponse(Code.ERROR);
}
}
}

View File

@ -10,6 +10,7 @@ import org.jeecg.modules.business.domain.api.mabang.dochangeorder.ChangeOrderReq
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.ChangeOrderRequestBody;
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.ChangeOrderResponse;
import org.jeecg.modules.business.domain.api.mabang.getorderlist.*;
import org.jeecg.modules.business.entity.PlatformOrder;
import org.jeecg.modules.business.service.IPlatformOrderService;
import org.quartz.Job;
import org.quartz.JobDataMap;
@ -87,7 +88,8 @@ public class AddPortraitTubeJob implements Job {
throw new RuntimeException("EndDateTime must be strictly greater than StartDateTime !");
}
List<String> platformOrderIds = platformOrderService.fetchUninvoicedOrdersForShops(startDateTime, endDateTime, shops);
List<PlatformOrder> platformOrders = platformOrderService.fetchUninvoicedOrdersForShops(startDateTime, endDateTime, shops);
List<String> platformOrderIds = platformOrders.stream().map(PlatformOrder::getPlatformOrderId).collect(Collectors.toList());
List<List<String>> platformOrderIdLists = Lists.partition(platformOrderIds, 10);
List<OrderListRequestBody> requests = new ArrayList<>();

View File

@ -0,0 +1,62 @@
package org.jeecg.modules.business.domain.job;
import lombok.extern.slf4j.Slf4j;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.*;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
@Slf4j
public class ClearLogisticChannelJob implements Job {
private static final Integer DEFAULT_NUMBER_OF_THREADS = 10;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap jobDataMap = context.getMergedJobDataMap();
String parameter = ((String) jobDataMap.get("parameter"));
List<String> platformOrderIds = new ArrayList<>();
if (parameter != null) {
try {
JSONObject jsonObject = new JSONObject(parameter);
if (!jsonObject.isNull("platformOrderIds")) {
JSONArray orderIds = jsonObject.getJSONArray("platformOrderIds");
if(orderIds == null) {
throw new RuntimeException("Empty parameter");
}
for(int i = 0; i < orderIds.length(); i++) {
platformOrderIds.add(orderIds.get(i).toString());
}
}
else {
throw new RuntimeException("platformOrderIds parameter is mandatory.");
}
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
ExecutorService executor = Executors.newFixedThreadPool(DEFAULT_NUMBER_OF_THREADS);
List<CompletableFuture<Boolean>> clearLogisticFutures = platformOrderIds.stream()
.map(orderId -> CompletableFuture.supplyAsync(() -> {
ClearLogisticRequestBody body = new ClearLogisticRequestBody(orderId);
ClearLogisticRequest request = new ClearLogisticRequest(body);
ClearLogisticResponse response = request.send();
return response.success();
}, executor))
.collect(Collectors.toList());
List<Boolean> clearResults = clearLogisticFutures.stream().map(CompletableFuture::join).collect(Collectors.toList());
long clearSuccessCount = clearResults.stream().filter(b -> b).count();
log.info("{}/{} logistic channel names cleared successfully.", clearSuccessCount, platformOrderIds.size());
}
}

View File

@ -6,10 +6,9 @@ import org.apache.commons.lang3.tuple.Pair;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.ChangeOrderResponse;
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.RemoveSkuRequest;
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.RemoveSkuRequestBody;
import org.jeecg.modules.business.domain.api.mabang.dochangeorder.*;
import org.jeecg.modules.business.domain.api.mabang.getorderlist.*;
import org.jeecg.modules.business.entity.PlatformOrder;
import org.jeecg.modules.business.service.IPlatformOrderService;
import org.quartz.Job;
import org.quartz.JobDataMap;
@ -81,7 +80,8 @@ public class RemoveVirtualProductJob implements Job {
throw new RuntimeException("EndDateTime must be strictly greater than StartDateTime !");
}
List<String> platformOrderIds = platformOrderService.fetchUninvoicedOrdersForShops(startDateTime, endDateTime, shops);
List<PlatformOrder> platformOrders = platformOrderService.fetchUninvoicedOrdersForShops(startDateTime, endDateTime, shops);
List<String> platformOrderIds = platformOrders.stream().map(PlatformOrder::getPlatformOrderId).collect(Collectors.toList());
List<List<String>> platformOrderIdLists = Lists.partition(platformOrderIds, 10);
List<OrderListRequestBody> requests = new ArrayList<>();
@ -112,6 +112,7 @@ public class RemoveVirtualProductJob implements Job {
log.info("{}/{} mabang orders have been retrieved.", mabangOrders.size(), platformOrderIds.size());
log.info("Constructing virtual SKU removal requests");
List<Order> ordersWithLogistic = new ArrayList<>();
List<RemoveSkuRequestBody> removeSkuRequests = new ArrayList<>();
Set<String> shopErpCodes = virtualSkusByShop.keySet();
for (Order mabangOrder : mabangOrders) {
@ -126,6 +127,9 @@ public class RemoveVirtualProductJob implements Job {
}
}
if (!virtualSkuToRemove.isEmpty()) {
if(!mabangOrder.getLogisticChannelName().isEmpty()) {
ordersWithLogistic.add(mabangOrder);
}
RemoveSkuRequestBody removeSkuRequestBody = new RemoveSkuRequestBody(mabangOrder.getPlatformOrderId(),
virtualSkuToRemove);
removeSkuRequests.add(removeSkuRequestBody);
@ -134,6 +138,19 @@ public class RemoveVirtualProductJob implements Job {
}
log.info("{} virtual SKU removal requests to be sent to MabangAPI", removeSkuRequests.size());
// First we delete the logistic channel names, otherwise we can't delete virtual skus
List<CompletableFuture<Boolean>> clearLogisticFutures = ordersWithLogistic.stream()
.map(orderWithLogistic -> CompletableFuture.supplyAsync(() -> {
ClearLogisticRequestBody body = new ClearLogisticRequestBody(orderWithLogistic.getPlatformOrderId());
ClearLogisticRequest request = new ClearLogisticRequest(body);
ClearLogisticResponse response = request.send();
return response.success();
}, executor))
.collect(Collectors.toList());
List<Boolean> logisticResults = clearLogisticFutures.stream().map(CompletableFuture::join).collect(Collectors.toList());
long logisticClearSuccessCount = logisticResults.stream().filter(b -> b).count();
log.info("{}/{} logistic channel names cleared successfully.", logisticClearSuccessCount, ordersWithLogistic.size());
List<CompletableFuture<Boolean>> removeSkuFutures = removeSkuRequests.stream()
.map(removeSkuRequestBody -> CompletableFuture.supplyAsync(() -> {
boolean success = false;

View File

@ -161,7 +161,7 @@ public interface PlatformOrderMapper extends BaseMapper<PlatformOrder> {
List<String> fetchBillCodesOfParcelsWithoutTrace(@Param("startDate") Date startDate, @Param("endDate") Date endDate,
@Param("transporters") List<String> transporters);
List<String> fetchUninvoicedOrdersForShops(@Param("startDateTime") LocalDateTime startDateTime,
List<PlatformOrder> fetchUninvoicedOrdersForShops(@Param("startDateTime") LocalDateTime startDateTime,
@Param("endDateTime") LocalDateTime endDateTime,
@Param("shops") List<String> shops);

View File

@ -404,8 +404,8 @@
AND internal_tracking_number IS NOT NULL;
</select>
<select id="fetchUninvoicedOrdersForShops" resultType="java.lang.String">
SELECT platform_order_id
<select id="fetchUninvoicedOrdersForShops" resultType="org.jeecg.modules.business.entity.PlatformOrder">
SELECT platform_order_id, logistic_channel_name
FROM platform_order po join shop s ON po.shop_id = s.id
WHERE erp_code IN
<foreach

View File

@ -129,7 +129,7 @@ public interface IPlatformOrderService extends IService<PlatformOrder> {
List<String> fetchBillCodesOfParcelsWithoutTrace(Date startDate, Date endDate, List<String> transporters);
List<String> fetchUninvoicedOrdersForShops(LocalDateTime startDate, LocalDateTime endDate, List<String> shops);
List<PlatformOrder> fetchUninvoicedOrdersForShops(LocalDateTime startDate, LocalDateTime endDate, List<String> shops);
/**
* Fetch platformOrderId of shipped AND invoiced orders, from startDatetime to endDatetime, excluding orders from

View File

@ -369,7 +369,7 @@ public class PlatformOrderServiceImpl extends ServiceImpl<PlatformOrderMapper, P
}
@Override
public List<String> fetchUninvoicedOrdersForShops(LocalDateTime startDate, LocalDateTime endDate, List<String> shops) {
public List<PlatformOrder> fetchUninvoicedOrdersForShops(LocalDateTime startDate, LocalDateTime endDate, List<String> shops) {
return platformOrderMap.fetchUninvoicedOrdersForShops(startDate, endDate, shops);
}

View File

@ -12,6 +12,6 @@
<td style="padding:10px 0;"><b>Client :</b> ${invoiceEntity}</td>
</tr>
<tr>
<td style="padding:10px 0;"><b>Numéro de facture :</b> <a href="http://app.wia-sourcing.com/business/admin/shippingInvoice/Invoice?invoice=${invoiceNumber}"> ${invoiceNumber} </a></td>
<td style="padding:10px 0;"><b>Numéro de facture :</b> <a href="http://app.wia-sourcing.com/business/admin/invoice/Invoice?invoice=${invoiceNumber}"> ${invoiceNumber} </a></td>
</tr>
<#include "../components/footer.ftl">

View File

@ -12,6 +12,6 @@
<td style="padding:10px 0;"><b>Client :</b> ${invoiceEntity}</td>
</tr>
<tr>
<td style="padding:10px 0;"><b>Numéro de facture :</b> <a href="http://app.wia-sourcing.com/business/admin/shippingInvoice/Invoice?invoice=${invoiceNumber}"> ${invoiceNumber} </a></td>
<td style="padding:10px 0;"><b>Numéro de facture :</b> <a href="http://app.wia-sourcing.com/business/admin/invoice/Invoice?invoice=${invoiceNumber}"> ${invoiceNumber} </a></td>
</tr>
<#include "components/footer.ftl">