Skip to content

Commit 89da6f1

Browse files
authored
新增电子面单服务骨架与基础数据模型
1 parent ba02374 commit 89da6f1

26 files changed

Lines changed: 622 additions & 0 deletions
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package me.chanjar.weixin.channel.api;
2+
3+
import java.util.List;
4+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
5+
import me.chanjar.weixin.channel.bean.ewaybill.AccountInfoResponse;
6+
import me.chanjar.weixin.channel.bean.ewaybill.AddSubOrderRequest;
7+
import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderRequest;
8+
import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderResponse;
9+
import me.chanjar.weixin.channel.bean.ewaybill.DeliveryListResponse;
10+
import me.chanjar.weixin.channel.bean.ewaybill.OrderDetailResponse;
11+
import me.chanjar.weixin.channel.bean.ewaybill.PreCreateRequest;
12+
import me.chanjar.weixin.channel.bean.ewaybill.PreCreateResponse;
13+
import me.chanjar.weixin.channel.bean.ewaybill.PrintContentResponse;
14+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateConfigResponse;
15+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateCreateRequest;
16+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateIdResponse;
17+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateInfoResponse;
18+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateUpdateRequest;
19+
import me.chanjar.weixin.common.error.WxErrorException;
20+
21+
/**
22+
* 视频号小店电子面单服务接口
23+
*
24+
* @author GitHub Copilot
25+
*/
26+
public interface WxChannelEwaybillService {
27+
28+
TemplateConfigResponse getTemplateConfig() throws WxErrorException;
29+
30+
TemplateIdResponse createTemplate(TemplateCreateRequest req) throws WxErrorException;
31+
32+
WxChannelBaseResponse deleteTemplate(String templateId) throws WxErrorException;
33+
34+
WxChannelBaseResponse updateTemplate(TemplateUpdateRequest req) throws WxErrorException;
35+
36+
TemplateInfoResponse getTemplate(String templateId) throws WxErrorException;
37+
38+
TemplateInfoResponse getTemplateById(String templateId) throws WxErrorException;
39+
40+
AccountInfoResponse getAccount() throws WxErrorException;
41+
42+
DeliveryListResponse getDeliveryList() throws WxErrorException;
43+
44+
PreCreateResponse preCreateOrder(PreCreateRequest req) throws WxErrorException;
45+
46+
CreateOrderResponse createOrder(CreateOrderRequest req) throws WxErrorException;
47+
48+
WxChannelBaseResponse addSubOrder(AddSubOrderRequest req) throws WxErrorException;
49+
50+
WxChannelBaseResponse cancelOrder(String waybillId) throws WxErrorException;
51+
52+
OrderDetailResponse getOrder(String waybillId) throws WxErrorException;
53+
54+
PrintContentResponse getPrintContent(String waybillId) throws WxErrorException;
55+
56+
WxChannelBaseResponse printOrder(String waybillId) throws WxErrorException;
57+
58+
WxChannelBaseResponse batchPrintOrder(List<String> waybillIds) throws WxErrorException;
59+
}
60+

weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,11 @@ public interface WxChannelService extends BaseWxChannelService {
182182
*/
183183
WxChannelLiveDashboardService getLiveDashboardService();
184184

185+
/**
186+
* 电子面单服务
187+
*
188+
* @return 电子面单服务
189+
*/
190+
WxChannelEwaybillService getEwaybillService();
191+
185192
}

weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/BaseWxChannelServiceImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public abstract class BaseWxChannelServiceImpl<H, P> implements WxChannelService
6060
private WxChannelVipService vipService = null;
6161
private WxChannelCompassFinderService compassFinderService = null;
6262
private WxChannelLiveDashboardService liveDashboardService = null;
63+
private WxChannelEwaybillService ewaybillService = null;
6364

6465
protected WxChannelConfig config;
6566
private int retrySleepMillis = 1000;
@@ -473,4 +474,12 @@ public synchronized WxChannelLiveDashboardService getLiveDashboardService() {
473474
return liveDashboardService;
474475
}
475476

477+
@Override
478+
public synchronized WxChannelEwaybillService getEwaybillService() {
479+
if (ewaybillService == null) {
480+
ewaybillService = new WxChannelEwaybillServiceImpl(this);
481+
}
482+
return ewaybillService;
483+
}
484+
476485
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
package me.chanjar.weixin.channel.api.impl;
2+
3+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.ADD_SUB_ORDER_URL;
4+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.BATCH_PRINT_ORDER_URL;
5+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.CANCEL_ORDER_URL;
6+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.CREATE_ORDER_URL;
7+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.CREATE_TEMPLATE_URL;
8+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.DELETE_TEMPLATE_URL;
9+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_ACCOUNT_URL;
10+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_DELIVERY_LIST_URL;
11+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_ORDER_URL;
12+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_PRINT_CONTENT_URL;
13+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_TEMPLATE_BY_ID_URL;
14+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_TEMPLATE_CONFIG_URL;
15+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_TEMPLATE_URL;
16+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.PRE_CREATE_ORDER_URL;
17+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.PRINT_ORDER_URL;
18+
import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.UPDATE_TEMPLATE_URL;
19+
20+
import java.util.List;
21+
import me.chanjar.weixin.channel.api.WxChannelEwaybillService;
22+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
23+
import me.chanjar.weixin.channel.bean.ewaybill.AccountInfoResponse;
24+
import me.chanjar.weixin.channel.bean.ewaybill.AddSubOrderRequest;
25+
import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderRequest;
26+
import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderResponse;
27+
import me.chanjar.weixin.channel.bean.ewaybill.DeliveryListResponse;
28+
import me.chanjar.weixin.channel.bean.ewaybill.OrderDetailResponse;
29+
import me.chanjar.weixin.channel.bean.ewaybill.PreCreateRequest;
30+
import me.chanjar.weixin.channel.bean.ewaybill.PreCreateResponse;
31+
import me.chanjar.weixin.channel.bean.ewaybill.PrintContentResponse;
32+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateConfigResponse;
33+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateCreateRequest;
34+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateIdParam;
35+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateIdResponse;
36+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateInfoResponse;
37+
import me.chanjar.weixin.channel.bean.ewaybill.TemplateUpdateRequest;
38+
import me.chanjar.weixin.channel.bean.ewaybill.WaybillIdParam;
39+
import me.chanjar.weixin.channel.bean.ewaybill.WaybillIdsParam;
40+
import me.chanjar.weixin.channel.util.ResponseUtils;
41+
import me.chanjar.weixin.common.error.WxErrorException;
42+
43+
/**
44+
* 视频号小店电子面单服务实现。
45+
*
46+
* @author GitHub Copilot
47+
*/
48+
public class WxChannelEwaybillServiceImpl implements WxChannelEwaybillService {
49+
50+
/** 微信商店服务 */
51+
private final BaseWxChannelServiceImpl<?, ?> shopService;
52+
53+
public WxChannelEwaybillServiceImpl(BaseWxChannelServiceImpl<?, ?> shopService) {
54+
this.shopService = shopService;
55+
}
56+
57+
@Override
58+
public TemplateConfigResponse getTemplateConfig() throws WxErrorException {
59+
String resJson = shopService.post(GET_TEMPLATE_CONFIG_URL, "{}");
60+
return ResponseUtils.decode(resJson, TemplateConfigResponse.class);
61+
}
62+
63+
@Override
64+
public TemplateIdResponse createTemplate(TemplateCreateRequest req) throws WxErrorException {
65+
String resJson = shopService.post(CREATE_TEMPLATE_URL, req);
66+
return ResponseUtils.decode(resJson, TemplateIdResponse.class);
67+
}
68+
69+
@Override
70+
public WxChannelBaseResponse deleteTemplate(String templateId) throws WxErrorException {
71+
String resJson = shopService.post(DELETE_TEMPLATE_URL, new TemplateIdParam(templateId));
72+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
73+
}
74+
75+
@Override
76+
public WxChannelBaseResponse updateTemplate(TemplateUpdateRequest req) throws WxErrorException {
77+
String resJson = shopService.post(UPDATE_TEMPLATE_URL, req);
78+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
79+
}
80+
81+
@Override
82+
public TemplateInfoResponse getTemplate(String templateId) throws WxErrorException {
83+
String resJson = shopService.post(GET_TEMPLATE_URL, new TemplateIdParam(templateId));
84+
return ResponseUtils.decode(resJson, TemplateInfoResponse.class);
85+
}
86+
87+
@Override
88+
public TemplateInfoResponse getTemplateById(String templateId) throws WxErrorException {
89+
String resJson = shopService.post(GET_TEMPLATE_BY_ID_URL, new TemplateIdParam(templateId));
90+
return ResponseUtils.decode(resJson, TemplateInfoResponse.class);
91+
}
92+
93+
@Override
94+
public AccountInfoResponse getAccount() throws WxErrorException {
95+
String resJson = shopService.post(GET_ACCOUNT_URL, "{}");
96+
return ResponseUtils.decode(resJson, AccountInfoResponse.class);
97+
}
98+
99+
@Override
100+
public DeliveryListResponse getDeliveryList() throws WxErrorException {
101+
String resJson = shopService.post(GET_DELIVERY_LIST_URL, "{}");
102+
return ResponseUtils.decode(resJson, DeliveryListResponse.class);
103+
}
104+
105+
@Override
106+
public PreCreateResponse preCreateOrder(PreCreateRequest req) throws WxErrorException {
107+
String resJson = shopService.post(PRE_CREATE_ORDER_URL, req);
108+
return ResponseUtils.decode(resJson, PreCreateResponse.class);
109+
}
110+
111+
@Override
112+
public CreateOrderResponse createOrder(CreateOrderRequest req) throws WxErrorException {
113+
String resJson = shopService.post(CREATE_ORDER_URL, req);
114+
return ResponseUtils.decode(resJson, CreateOrderResponse.class);
115+
}
116+
117+
@Override
118+
public WxChannelBaseResponse addSubOrder(AddSubOrderRequest req) throws WxErrorException {
119+
String resJson = shopService.post(ADD_SUB_ORDER_URL, req);
120+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
121+
}
122+
123+
@Override
124+
public WxChannelBaseResponse cancelOrder(String waybillId) throws WxErrorException {
125+
String resJson = shopService.post(CANCEL_ORDER_URL, new WaybillIdParam(waybillId));
126+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
127+
}
128+
129+
@Override
130+
public OrderDetailResponse getOrder(String waybillId) throws WxErrorException {
131+
String resJson = shopService.post(GET_ORDER_URL, new WaybillIdParam(waybillId));
132+
return ResponseUtils.decode(resJson, OrderDetailResponse.class);
133+
}
134+
135+
@Override
136+
public PrintContentResponse getPrintContent(String waybillId) throws WxErrorException {
137+
String resJson = shopService.post(GET_PRINT_CONTENT_URL, new WaybillIdParam(waybillId));
138+
return ResponseUtils.decode(resJson, PrintContentResponse.class);
139+
}
140+
141+
@Override
142+
public WxChannelBaseResponse printOrder(String waybillId) throws WxErrorException {
143+
String resJson = shopService.post(PRINT_ORDER_URL, new WaybillIdParam(waybillId));
144+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
145+
}
146+
147+
@Override
148+
public WxChannelBaseResponse batchPrintOrder(List<String> waybillIds) throws WxErrorException {
149+
String resJson = shopService.post(BATCH_PRINT_ORDER_URL, new WaybillIdsParam(waybillIds));
150+
return ResponseUtils.decode(resJson, WxChannelBaseResponse.class);
151+
}
152+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package me.chanjar.weixin.channel.bean.ewaybill;
2+
3+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
4+
import com.fasterxml.jackson.annotation.JsonAnySetter;
5+
import java.io.Serializable;
6+
import java.util.LinkedHashMap;
7+
import java.util.Map;
8+
import lombok.Data;
9+
import lombok.NoArgsConstructor;
10+
11+
/**
12+
* 电子面单通用请求参数容器。
13+
*
14+
* <p>字段按官方文档动态透传,避免非官方字段定义。</p>
15+
*
16+
* @author GitHub Copilot
17+
*/
18+
@Data
19+
@NoArgsConstructor
20+
public abstract class AbstractEwaybillRequest implements Serializable {
21+
22+
private static final long serialVersionUID = 4213577159985597237L;
23+
24+
private Map<String, Object> params = new LinkedHashMap<>();
25+
26+
@JsonAnySetter
27+
public void addParam(String key, Object value) {
28+
params.put(key, value);
29+
}
30+
31+
@JsonAnyGetter
32+
public Map<String, Object> anyParams() {
33+
return params;
34+
}
35+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package me.chanjar.weixin.channel.bean.ewaybill;
2+
3+
import com.fasterxml.jackson.annotation.JsonAnySetter;
4+
import java.util.LinkedHashMap;
5+
import java.util.Map;
6+
import lombok.Data;
7+
import lombok.EqualsAndHashCode;
8+
import lombok.NoArgsConstructor;
9+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
10+
11+
/**
12+
* 电子面单通用响应参数容器。
13+
*
14+
* <p>未显式声明字段将保存到 extra 字段,便于兼容官方接口变更。</p>
15+
*
16+
* @author GitHub Copilot
17+
*/
18+
@Data
19+
@NoArgsConstructor
20+
@EqualsAndHashCode(callSuper = true)
21+
public abstract class AbstractEwaybillResponse extends WxChannelBaseResponse {
22+
23+
private static final long serialVersionUID = -2460196179063989718L;
24+
25+
private Map<String, Object> extra = new LinkedHashMap<>();
26+
27+
@JsonAnySetter
28+
public void addExtra(String key, Object value) {
29+
extra.put(key, value);
30+
}
31+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package me.chanjar.weixin.channel.bean.ewaybill;
2+
3+
/**
4+
* 电子面单网点/账号信息响应。
5+
*
6+
* @author GitHub Copilot
7+
*/
8+
public class AccountInfoResponse extends AbstractEwaybillResponse {
9+
private static final long serialVersionUID = 5682783958522805959L;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package me.chanjar.weixin.channel.bean.ewaybill;
2+
3+
/**
4+
* 电子面单子件追加请求。
5+
*
6+
* @author GitHub Copilot
7+
*/
8+
public class AddSubOrderRequest extends AbstractEwaybillRequest {
9+
private static final long serialVersionUID = 4250200603210217269L;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package me.chanjar.weixin.channel.bean.ewaybill;
2+
3+
/**
4+
* 电子面单取号请求。
5+
*
6+
* @author GitHub Copilot
7+
*/
8+
public class CreateOrderRequest extends AbstractEwaybillRequest {
9+
private static final long serialVersionUID = 2521225918646916853L;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package me.chanjar.weixin.channel.bean.ewaybill;
2+
3+
/**
4+
* 电子面单取号响应。
5+
*
6+
* @author GitHub Copilot
7+
*/
8+
public class CreateOrderResponse extends AbstractEwaybillResponse {
9+
private static final long serialVersionUID = 9115454170108519187L;
10+
}

0 commit comments

Comments
 (0)