Merge pull request #81 from LQYBill/shopify_sync_opti

Shopify sync opti
pull/8040/head
Qiuyi LI 2024-06-03 10:16:02 +02:00 committed by GitHub
commit afc8e31800
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 41 additions and 8 deletions

View File

@ -12,7 +12,7 @@ public class GetFulfillmentRequestBody extends ShopifyRequestBody {
public GetFulfillmentRequestBody(String sitePrefix, String platformOrderId, String shopToken) {
super(sitePrefix, shopToken);
this.platformOrderId = platformOrderId;
this.platformOrderId = platformOrderId.split("_")[0];
}
public GetFulfillmentRequestBody(PlatformOrderShopSync platformOrderShopSync) {

View File

@ -16,10 +16,7 @@ import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -83,7 +80,7 @@ public class ShopifySyncJob implements Job {
GetFulfillmentRequest getFulfillmentRequest = new GetFulfillmentRequest(body);
String responseStr = getFulfillmentRequest.rawSend().getBody();
FulfillmentOrdersResponse response = mapper.readValue(responseStr, FulfillmentOrdersResponse.class);
fulfillmentOrders.add(response.getFulfillmentOrders().get(0));
fulfillmentOrders.addAll(response.getFulfillmentOrders());
success = true;
} catch (RuntimeException e) {
log.error("Error communicating with ShopifyAPI", e);
@ -109,6 +106,7 @@ public class ShopifySyncJob implements Job {
}
log.info("{} fulfillment creation requests to be sent to ShopifyAPI", createFulfillmentRequests.size());
Set<String> syncedPlatformOrderIds = new HashSet<>();
List<CompletableFuture<Boolean>> fulfillmentCreationFutures = createFulfillmentRequests.stream()
.map(changeOrderRequestBody -> CompletableFuture.supplyAsync(() -> {
boolean success = false;
@ -117,6 +115,9 @@ public class ShopifySyncJob implements Job {
String responseStr = createFulfillmentRequest.rawSend().getBody();
FulfillmentCreationResponse response = mapper.readValue(responseStr, FulfillmentCreationResponse.class);
success = response.getFulfillment().isSuccess();
if (success) {
syncedPlatformOrderIds.add(response.getFulfillment().getOrderId());
}
} catch (RuntimeException e) {
log.error("Error communicating with ShopifyAPI", e);
} catch (JsonProcessingException e) {
@ -128,5 +129,10 @@ public class ShopifySyncJob implements Job {
results = fulfillmentCreationFutures.stream().map(CompletableFuture::join).collect(Collectors.toList());
nbSuccesses = results.stream().filter(b -> b).count();
log.info("{}/{} fulfillment creation requests have succeeded.", nbSuccesses, createFulfillmentRequests.size());
if (!syncedPlatformOrderIds.isEmpty()) {
platformOrderService.updateShopifySynced(syncedPlatformOrderIds);
log.info("Those orders have been marked as shopify synced : {} ", syncedPlatformOrderIds);
}
}
}

View File

@ -18,8 +18,8 @@ import java.util.Date;
/**
* @Description:
* @Author: jeecg-boot
* @Date: 2024-01-25
* @Version: V1.8
* @Date: 2024-05-30
* @Version: V1.9
*/
@ApiModel(value = "platform_order对象", description = "平台订单表")
@Data
@ -252,4 +252,11 @@ public class PlatformOrder implements Serializable {
@Excel(name = "个人税号", width = 15)
@ApiModelProperty(value = "个人税号")
private java.lang.String taxNumber;
/**
* Shopify(1=0=)
*/
@Excel(name = "Shopify平台已同步(1=已同步0=未同步)", width = 15, dicCode = "yn")
@Dict(dicCode = "yn")
@ApiModelProperty(value = "Shopify平台已同步(1=已同步0=未同步)")
private java.lang.String shopifySynced;
}

View File

@ -13,6 +13,7 @@ import org.jeecg.modules.business.vo.clientPlatformOrder.section.OrderQuantity;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -224,4 +225,6 @@ public interface PlatformOrderMapper extends BaseMapper<PlatformOrder> {
void anonymizePersonalData(@Param("period") int indirectClientAnonymizationPeriod);
List<PlatformOrderOption> ordersByShop(@Param("shopID") String shopID);
void updateShopifySynced(@Param("platformOrderIds") Collection<String> platformOrderIds);
}

View File

@ -463,6 +463,7 @@
#{shop}
</foreach>
AND ready_for_shopify_sync = 1
AND shopify_synced = 0
AND erp_status = 3
ORDER BY shipping_time;
</select>
@ -898,4 +899,13 @@
WHERE shop_id = #{shopID}
AND erp_status IN (1,2,3)
</select>
<update id="updateShopifySynced">
UPDATE platform_order
SET shopify_synced = 1
WHERE platform_order_id IN
<foreach collection="platformOrderIds" separator="," open="(" close=")" index="index" item="platformOrderId">
#{platformOrderId}
</foreach>
</update>
</mapper>

View File

@ -248,4 +248,6 @@ public interface IPlatformOrderService extends IService<PlatformOrder> {
void anonymizePersonalData(int indirectClientAnonymizationPeriod);
List<PlatformOrderOption> ordersByShop(String shopID);
void updateShopifySynced(Collection<String> platformOrderIds);
}

View File

@ -501,4 +501,9 @@ public class PlatformOrderServiceImpl extends ServiceImpl<PlatformOrderMapper, P
public List<PlatformOrderOption> ordersByShop(String shopID) {
return platformOrderMap.ordersByShop(shopID);
}
@Override
public void updateShopifySynced(Collection<String> platformOrderIds) {
platformOrderMap.updateShopifySynced(platformOrderIds);
}
}