-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wangqi
committed
Nov 12, 2024
1 parent
42ca066
commit 38036d3
Showing
26 changed files
with
646 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...p-framework/src/main/java/cn/sliew/carp/module/http/sync/framework/model/AbstractJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cn.sliew.carp.module.http.sync.framework.model; | ||
|
||
import cn.sliew.carp.module.http.sync.framework.model.internal.ProcessResult; | ||
import cn.sliew.carp.module.http.sync.framework.model.internal.SimpleJobContext; | ||
import cn.sliew.milky.common.exception.Rethrower; | ||
import cn.sliew.milky.common.util.JacksonUtil; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.pekko.Done; | ||
import org.apache.pekko.NotUsed; | ||
import org.apache.pekko.actor.typed.ActorSystem; | ||
import org.apache.pekko.actor.typed.SpawnProtocol; | ||
import org.apache.pekko.japi.Pair; | ||
import org.apache.pekko.stream.*; | ||
import org.apache.pekko.stream.javadsl.*; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@Slf4j | ||
public abstract class AbstractJob implements Job { | ||
|
||
protected ActorSystem<SpawnProtocol.Command> actorSystem; | ||
|
||
public AbstractJob(ActorSystem<SpawnProtocol.Command> actorSystem) { | ||
this.actorSystem = actorSystem; | ||
} | ||
|
||
@Override | ||
public void process(String param) { | ||
doExecute(param); | ||
} | ||
|
||
protected void doExecute(Object param) { | ||
SimpleJobContext context = buildJobContext(); | ||
JobProcessor processor = buildJobProcessor(context); | ||
RootTask rootTask = buildRootTask(param); | ||
|
||
Source<SubTask, UniqueKillSwitch> source = Source.single(rootTask) | ||
.mapConcat(root -> processor.map(root)) | ||
.viaMat(KillSwitches.single(), Keep.right()); | ||
|
||
Flow<SubTask, ProcessResult, NotUsed> process = Flow.<SubTask>create() | ||
.map(subTask -> processor.process(subTask)).mapAsync(1, future -> future); | ||
|
||
Flow<SubTask, ProcessResult, NotUsed> subTasks = | ||
Flow.fromGraph( | ||
GraphDSL.create( | ||
b -> { | ||
int concurrency = context.getSubTaskParallelism(); | ||
UniformFanOutShape<SubTask, SubTask> partition = | ||
b.add(Partition.create(concurrency, subTask -> Math.toIntExact(subTask.getIdentifier()) % concurrency)); | ||
UniformFanInShape<ProcessResult, ProcessResult> merge = | ||
b.add(MergeSequence.create(concurrency, result -> result.getSubTask().getIdentifier())); | ||
|
||
for (int i = 0; i < concurrency; i++) { | ||
b.from(partition.out(i)) | ||
.via(b.add(process.async())) | ||
.viaFanIn(merge); | ||
} | ||
|
||
return FlowShape.of(partition.in(), merge.out()); | ||
})); | ||
|
||
Pair<UniqueKillSwitch, CompletionStage<Done>> pair = source.via(subTasks) | ||
.log(getJobName()) | ||
.toMat(Sink.foreach(result -> processor.reduce(result)), Keep.both()) | ||
.run(actorSystem); | ||
UniqueKillSwitch killSwitch = pair.first(); | ||
try { | ||
pair.second().toCompletableFuture().get(1, TimeUnit.HOURS); | ||
} catch (Exception e) { | ||
log.error("job 执行异常, job: {}, param: {}", getJobName(), JacksonUtil.toJsonString(param)); | ||
killSwitch.abort(e); | ||
Rethrower.throwAs(e); | ||
} | ||
} | ||
|
||
public abstract String getJobName(); | ||
|
||
protected abstract SimpleJobContext buildJobContext(); | ||
|
||
protected JobProcessor buildJobProcessor(SimpleJobContext context) { | ||
return new DefaultJobProcessor(context); | ||
} | ||
|
||
protected abstract RootTask buildRootTask(Object param); | ||
} |
24 changes: 24 additions & 0 deletions
24
...dule-http-framework/src/main/java/cn/sliew/carp/module/http/sync/framework/model/Job.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cn.sliew.carp.module.http.sync.framework.model; | ||
|
||
public interface Job { | ||
|
||
void process(String param); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...tp-job/src/main/java/cn/sliew/carp/module/http/sync/job/config/HttpSyncOpenAPIConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cn.sliew.carp.module.http.sync.job.config; | ||
|
||
import org.springdoc.core.models.GroupedOpenApi; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class HttpSyncOpenAPIConfig { | ||
|
||
@Bean | ||
public GroupedOpenApi carpHttpSyncModuleOpenApi() { | ||
return GroupedOpenApi.builder().group("Http同步模块") | ||
.pathsToMatch("/api/carp/http-sync/**") | ||
.packagesToScan("cn.sliew.carp.module.http.sync").build(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...ob/src/main/java/cn/sliew/carp/module/http/sync/job/controller/job/CarpJstController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cn.sliew.carp.module.http.sync.job.controller.job; | ||
|
||
import cn.sliew.carp.framework.common.security.annotations.AnonymousAccess; | ||
import cn.sliew.carp.framework.web.response.ApiResponseWrapper; | ||
import cn.sliew.carp.module.http.sync.job.jst.order.JstOrderJob; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@AnonymousAccess | ||
@RestController | ||
@ApiResponseWrapper | ||
@RequestMapping("/api/carp/http-sync/job/jst") | ||
@Tag(name = "Http同步管理-聚水潭") | ||
public class CarpJstController { | ||
|
||
@Autowired | ||
private JstOrderJob jstOrderJob; | ||
|
||
@GetMapping("jstOrderJob") | ||
@Operation(summary = "订单", description = "订单") | ||
public void jstOrderJob(@RequestParam("param") String param) { | ||
jstOrderJob.process(param); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...carp-module-http-job/src/main/java/cn/sliew/carp/module/http/sync/job/enums/JobGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cn.sliew.carp.module.http.sync.job.enums; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum JobGroup { | ||
|
||
JST("jst", "聚水潭"), | ||
; | ||
|
||
private String group; | ||
private String desc; | ||
|
||
JobGroup(String group, String desc) { | ||
this.group = group; | ||
this.desc = desc; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
.../carp-module-http-job/src/main/java/cn/sliew/carp/module/http/sync/job/enums/JobType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cn.sliew.carp.module.http.sync.job.enums; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum JobType { | ||
|
||
NORMAL("normal", "普通任务"), | ||
; | ||
|
||
private String type; | ||
private String desc; | ||
|
||
JobType(String type, String desc) { | ||
this.type = type; | ||
this.desc = desc; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...rp-module-http-job/src/main/java/cn/sliew/carp/module/http/sync/job/enums/JstApiEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cn.sliew.carp.module.http.sync.job.enums; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum JstApiEnum { | ||
|
||
SHOPS_QUERY("shops.query", "店铺查询"), | ||
WMS_PARTNER_QUERY("wms.partner.query", "仓库查询"), | ||
CATEGORY_QUERY("category.query", "商品类目查询"), | ||
LOGISTIC_QUERY("logistic.query", "发货信息查询"), | ||
COMBINE_SKU_QUERY("combine.sku.query", "组合商品查询"), | ||
INVENTORY_COUNT_QUERY("inventory.count.query", "库存盘点查询"), | ||
INVENTORY_QUERY("inventory.query", "库存查询"), | ||
PACK_QUERY("pack.query", "箱及仓位库存查询-按照修改时间查询"), | ||
MALL_ITEM_QUERY("mall.item.query", "普通商品查询(按款查询)"), | ||
PURCHASEIN_QUERY("purchasein.query", "采购入库查询"), | ||
PURCHASEOUT_QUERY("purchaseout.query", "采购退货查询"), | ||
PURCHASE_QUERY("purchase.query", "采购单查询"), | ||
SKUMAP_QUERY("skumap.query", "商品映射查询"), | ||
SKU_QUERY("sku.query", "普通商品资料查询(按sku查询)"), | ||
SUPPLIER_QUERY("supplier.query", "供应商查询"), | ||
AFTERSALE_RECEIVED_QUERY("aftersale.received.query", "实际收货查询"), | ||
ALLOCATE_QUERY("allocate.query", "调拨单查询"), | ||
ORDER_ACTION_QUERY("order.action.query", "订单操作日志查询"), | ||
OTHER_INOUT_QUERY("other.inout.query", "其它出入库查询"), | ||
JUSHUITAN_INOUT_WATER_QUERY("jushuitan.inout.water.query", "进出仓流水"), | ||
JUSHUITAN_TRACKINFO_QUERY("jushuitan.trackinfo.query", "通过唯一码查询物流日志"), | ||
|
||
ORDERS_SINGLE_QUERY("orders.single.query", "订单查询"), | ||
REFUND_SINGLE_QUERY("refund.single.query", "退货退款查询"), | ||
ORDERS_OUT_SIMPLE_QUERY("orders.out.simple.query", "销售出库查询"), | ||
|
||
ORDERS_HISTORY_QUERY("orders.history.query", "历史订单查询"), | ||
REFUND_HISTORY_QUERY("refund.history.query", "历史退货退款查询"), | ||
JUSHUITAN_SALEOUT_HISTORY_QUERY("jushuitan.saleout.history.query", "历史销售出库单查询"), | ||
|
||
JUSHUITAN_ORDER_LIST_QUERY("jushuitan.order.list.query", "聚水潭奇门云订单"), | ||
JUSHUITAN_REFUND_LIST_QUERY("jushuitan.refund.list.query", "聚水潭奇门云售后"), | ||
JUSHUITAN_SALEOUT_LIST_QUERY("jushuitan.saleout.list.query", "聚水潭奇门云销售出库"), | ||
; | ||
|
||
private String api; | ||
private String desc; | ||
|
||
JstApiEnum(String api, String desc) { | ||
this.api = api; | ||
this.desc = desc; | ||
} | ||
} |
Oops, something went wrong.