mirror of https://github.com/jeecgboot/jeecg-boot
commit
afc8e31800
|
@ -12,7 +12,7 @@ public class GetFulfillmentRequestBody extends ShopifyRequestBody {
|
||||||
|
|
||||||
public GetFulfillmentRequestBody(String sitePrefix, String platformOrderId, String shopToken) {
|
public GetFulfillmentRequestBody(String sitePrefix, String platformOrderId, String shopToken) {
|
||||||
super(sitePrefix, shopToken);
|
super(sitePrefix, shopToken);
|
||||||
this.platformOrderId = platformOrderId;
|
this.platformOrderId = platformOrderId.split("_")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetFulfillmentRequestBody(PlatformOrderShopSync platformOrderShopSync) {
|
public GetFulfillmentRequestBody(PlatformOrderShopSync platformOrderShopSync) {
|
||||||
|
|
|
@ -16,10 +16,7 @@ import org.quartz.JobExecutionContext;
|
||||||
import org.quartz.JobExecutionException;
|
import org.quartz.JobExecutionException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
@ -83,7 +80,7 @@ public class ShopifySyncJob implements Job {
|
||||||
GetFulfillmentRequest getFulfillmentRequest = new GetFulfillmentRequest(body);
|
GetFulfillmentRequest getFulfillmentRequest = new GetFulfillmentRequest(body);
|
||||||
String responseStr = getFulfillmentRequest.rawSend().getBody();
|
String responseStr = getFulfillmentRequest.rawSend().getBody();
|
||||||
FulfillmentOrdersResponse response = mapper.readValue(responseStr, FulfillmentOrdersResponse.class);
|
FulfillmentOrdersResponse response = mapper.readValue(responseStr, FulfillmentOrdersResponse.class);
|
||||||
fulfillmentOrders.add(response.getFulfillmentOrders().get(0));
|
fulfillmentOrders.addAll(response.getFulfillmentOrders());
|
||||||
success = true;
|
success = true;
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
log.error("Error communicating with ShopifyAPI", 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());
|
log.info("{} fulfillment creation requests to be sent to ShopifyAPI", createFulfillmentRequests.size());
|
||||||
|
|
||||||
|
Set<String> syncedPlatformOrderIds = new HashSet<>();
|
||||||
List<CompletableFuture<Boolean>> fulfillmentCreationFutures = createFulfillmentRequests.stream()
|
List<CompletableFuture<Boolean>> fulfillmentCreationFutures = createFulfillmentRequests.stream()
|
||||||
.map(changeOrderRequestBody -> CompletableFuture.supplyAsync(() -> {
|
.map(changeOrderRequestBody -> CompletableFuture.supplyAsync(() -> {
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
@ -117,6 +115,9 @@ public class ShopifySyncJob implements Job {
|
||||||
String responseStr = createFulfillmentRequest.rawSend().getBody();
|
String responseStr = createFulfillmentRequest.rawSend().getBody();
|
||||||
FulfillmentCreationResponse response = mapper.readValue(responseStr, FulfillmentCreationResponse.class);
|
FulfillmentCreationResponse response = mapper.readValue(responseStr, FulfillmentCreationResponse.class);
|
||||||
success = response.getFulfillment().isSuccess();
|
success = response.getFulfillment().isSuccess();
|
||||||
|
if (success) {
|
||||||
|
syncedPlatformOrderIds.add(response.getFulfillment().getOrderId());
|
||||||
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
log.error("Error communicating with ShopifyAPI", e);
|
log.error("Error communicating with ShopifyAPI", e);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
|
@ -128,5 +129,10 @@ public class ShopifySyncJob implements Job {
|
||||||
results = fulfillmentCreationFutures.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
results = fulfillmentCreationFutures.stream().map(CompletableFuture::join).collect(Collectors.toList());
|
||||||
nbSuccesses = results.stream().filter(b -> b).count();
|
nbSuccesses = results.stream().filter(b -> b).count();
|
||||||
log.info("{}/{} fulfillment creation requests have succeeded.", nbSuccesses, createFulfillmentRequests.size());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,8 @@ import java.util.Date;
|
||||||
/**
|
/**
|
||||||
* @Description: 平台订单表
|
* @Description: 平台订单表
|
||||||
* @Author: jeecg-boot
|
* @Author: jeecg-boot
|
||||||
* @Date: 2024-01-25
|
* @Date: 2024-05-30
|
||||||
* @Version: V1.8
|
* @Version: V1.9
|
||||||
*/
|
*/
|
||||||
@ApiModel(value = "platform_order对象", description = "平台订单表")
|
@ApiModel(value = "platform_order对象", description = "平台订单表")
|
||||||
@Data
|
@Data
|
||||||
|
@ -252,4 +252,11 @@ public class PlatformOrder implements Serializable {
|
||||||
@Excel(name = "个人税号", width = 15)
|
@Excel(name = "个人税号", width = 15)
|
||||||
@ApiModelProperty(value = "个人税号")
|
@ApiModelProperty(value = "个人税号")
|
||||||
private java.lang.String taxNumber;
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.jeecg.modules.business.vo.clientPlatformOrder.section.OrderQuantity;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -224,4 +225,6 @@ public interface PlatformOrderMapper extends BaseMapper<PlatformOrder> {
|
||||||
void anonymizePersonalData(@Param("period") int indirectClientAnonymizationPeriod);
|
void anonymizePersonalData(@Param("period") int indirectClientAnonymizationPeriod);
|
||||||
|
|
||||||
List<PlatformOrderOption> ordersByShop(@Param("shopID") String shopID);
|
List<PlatformOrderOption> ordersByShop(@Param("shopID") String shopID);
|
||||||
|
|
||||||
|
void updateShopifySynced(@Param("platformOrderIds") Collection<String> platformOrderIds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -463,6 +463,7 @@
|
||||||
#{shop}
|
#{shop}
|
||||||
</foreach>
|
</foreach>
|
||||||
AND ready_for_shopify_sync = 1
|
AND ready_for_shopify_sync = 1
|
||||||
|
AND shopify_synced = 0
|
||||||
AND erp_status = 3
|
AND erp_status = 3
|
||||||
ORDER BY shipping_time;
|
ORDER BY shipping_time;
|
||||||
</select>
|
</select>
|
||||||
|
@ -898,4 +899,13 @@
|
||||||
WHERE shop_id = #{shopID}
|
WHERE shop_id = #{shopID}
|
||||||
AND erp_status IN (1,2,3)
|
AND erp_status IN (1,2,3)
|
||||||
</select>
|
</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>
|
</mapper>
|
||||||
|
|
|
@ -248,4 +248,6 @@ public interface IPlatformOrderService extends IService<PlatformOrder> {
|
||||||
void anonymizePersonalData(int indirectClientAnonymizationPeriod);
|
void anonymizePersonalData(int indirectClientAnonymizationPeriod);
|
||||||
|
|
||||||
List<PlatformOrderOption> ordersByShop(String shopID);
|
List<PlatformOrderOption> ordersByShop(String shopID);
|
||||||
|
|
||||||
|
void updateShopifySynced(Collection<String> platformOrderIds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -501,4 +501,9 @@ public class PlatformOrderServiceImpl extends ServiceImpl<PlatformOrderMapper, P
|
||||||
public List<PlatformOrderOption> ordersByShop(String shopID) {
|
public List<PlatformOrderOption> ordersByShop(String shopID) {
|
||||||
return platformOrderMap.ordersByShop(shopID);
|
return platformOrderMap.ordersByShop(shopID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateShopifySynced(Collection<String> platformOrderIds) {
|
||||||
|
platformOrderMap.updateShopifySynced(platformOrderIds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue