|
|
@@ -4,13 +4,15 @@ import cn.hutool.core.date.DatePattern;
|
|
4
|
4
|
import cn.hutool.core.date.DateUtil;
|
|
5
|
5
|
import cn.hutool.core.util.XmlUtil;
|
|
6
|
6
|
import cn.hutool.crypto.digest.DigestUtil;
|
|
|
7
|
+import cn.lili.common.enums.JGS20Unit;
|
|
|
8
|
+import cn.lili.common.exception.ServiceException;
|
|
|
9
|
+import cn.lili.common.exception.UnitIllegalException;
|
|
7
|
10
|
import cn.lili.modules.goods.entity.dos.Goods;
|
|
8
|
11
|
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
|
|
9
|
12
|
import cn.lili.modules.goods.service.GoodsService;
|
|
10
|
13
|
import cn.lili.modules.order.customs.CustomPayload;
|
|
11
|
14
|
import cn.lili.modules.order.customs.CustomsExchange;
|
|
12
|
15
|
import cn.lili.modules.order.order.entity.dos.OrderItem;
|
|
13
|
|
-import cn.lili.modules.order.order.entity.vo.OrderDetailVO;
|
|
14
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
15
|
17
|
import org.springframework.stereotype.Component;
|
|
16
|
18
|
import org.w3c.dom.Document;
|
|
|
@@ -20,12 +22,12 @@ import java.time.LocalDateTime;
|
|
20
|
22
|
import java.util.*;
|
|
21
|
23
|
import java.util.stream.Collectors;
|
|
22
|
24
|
|
|
|
25
|
+import static cn.lili.common.enums.ResultCode.ORDER_CUSTOMS_ERROR;
|
|
|
26
|
+
|
|
23
|
27
|
@Component
|
|
24
|
28
|
public class JiangyinServiceReqConverter implements CustomsReqConverter{
|
|
25
|
29
|
/** 报文前缀 */
|
|
26
|
30
|
private static final String CEB_PREFIX = "ceb:";
|
|
27
|
|
- private static final String DS_PREFIX = "ds:";
|
|
28
|
|
-
|
|
29
|
31
|
|
|
30
|
32
|
private final GoodsService goodsService;
|
|
31
|
33
|
|
|
|
@@ -35,22 +37,16 @@ public class JiangyinServiceReqConverter implements CustomsReqConverter{
|
|
35
|
37
|
}
|
|
36
|
38
|
|
|
37
|
39
|
@Override
|
|
38
|
|
- public String toReq(OrderDetailVO order, CustomPayload payload) {
|
|
39
|
|
- final String guid = UUID.randomUUID().toString();
|
|
40
|
|
- System.out.println(guid);;
|
|
41
|
|
- CustomsExchange exchange = new CustomsExchange(guid, order);
|
|
|
40
|
+ public String toReq(CustomsExchange exchange, CustomPayload payload) {
|
|
42
|
41
|
// map解析
|
|
43
|
|
- Map<String, Object> m = orderToMap(order, payload);
|
|
|
42
|
+ Map<String, Object> m = orderToMap(exchange, payload);
|
|
44
|
43
|
Document ceb = XmlUtil.mapToXml(m, "ceb:CEB303Message");
|
|
45
|
44
|
// 添加首个Node的属性
|
|
46
|
45
|
Element element = ceb.getDocumentElement();
|
|
47
|
|
- element.setAttribute("guid", "311af125-6fed-4603-8c5d-49b1fa4b4b9b");
|
|
|
46
|
+ element.setAttribute("guid", exchange.getGuid());
|
|
48
|
47
|
element.setAttribute("version", "1.0");
|
|
49
|
48
|
element.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
|
|
50
|
49
|
element.setAttribute("xmlns:ceb", "http://www.chinaport.gov.cn/ceb");
|
|
51
|
|
- //
|
|
52
|
|
- Element signature = (Element)element.getLastChild();
|
|
53
|
|
- signature.setAttribute("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#");
|
|
54
|
50
|
ceb.setXmlStandalone(true);
|
|
55
|
51
|
// 转String
|
|
56
|
52
|
return XmlUtil.toStr(ceb);
|
|
|
@@ -66,23 +62,28 @@ public class JiangyinServiceReqConverter implements CustomsReqConverter{
|
|
66
|
62
|
throw new RuntimeException("gen sign failed.");
|
|
67
|
63
|
}
|
|
68
|
64
|
|
|
|
65
|
+ @Override
|
|
|
66
|
+ public boolean checkSuccess(String resStr) {
|
|
|
67
|
+ Map<String, Object> map = XmlUtil.xmlToMap(resStr);
|
|
|
68
|
+ return Optional
|
|
|
69
|
+ .ofNullable(map.get("success"))
|
|
|
70
|
+ .map(String::valueOf)
|
|
|
71
|
+ .filter("true"::equalsIgnoreCase)
|
|
|
72
|
+ .isPresent();
|
|
|
73
|
+ }
|
|
|
74
|
+
|
|
69
|
75
|
/**
|
|
70
|
76
|
* 根据订单详情生成符合报文格式的Map
|
|
71
|
|
- * @param order 订单详情
|
|
|
77
|
+ * @param exchange 交换数据(业务)
|
|
72
|
78
|
* @param payload 存根(企业凭证相关)
|
|
73
|
79
|
* @return 符合报文格式的Map
|
|
74
|
80
|
*/
|
|
75
|
|
- private Map<String, Object> orderToMap(OrderDetailVO order, CustomPayload payload){
|
|
76
|
|
- final String guid = UUID.randomUUID().toString();
|
|
77
|
|
- System.out.println(guid);;
|
|
78
|
|
- CustomsExchange exchange = new CustomsExchange(guid, order);
|
|
79
|
|
-
|
|
|
81
|
+ private Map<String, Object> orderToMap(CustomsExchange exchange, CustomPayload payload){
|
|
80
|
82
|
Map<String, Object> reqMap = new HashMap<>();
|
|
81
|
83
|
// 1. ceb:order
|
|
82
|
84
|
reqMap.put(CEB_PREFIX + "Order", order(exchange, payload));
|
|
83
|
85
|
// 2. ceb:baseTransfer
|
|
84
|
86
|
reqMap.put(CEB_PREFIX + "BaseTransfer", baseTransfer(payload));
|
|
85
|
|
-
|
|
86
|
87
|
return reqMap;
|
|
87
|
88
|
}
|
|
88
|
89
|
|
|
|
@@ -98,76 +99,80 @@ public class JiangyinServiceReqConverter implements CustomsReqConverter{
|
|
98
|
99
|
List<Map<String, Object>> orderList = new ArrayList<>(0);
|
|
99
|
100
|
Optional.ofNullable(exchange.getOrderDetailVO().getOrderItems()).ifPresent(items -> {
|
|
100
|
101
|
// 批量获取商品信息
|
|
101
|
|
- String ids = items.stream().map(OrderItem::getGoodsId).collect(Collectors.joining());
|
|
|
102
|
+ String ids = items.stream().map(OrderItem::getGoodsId).collect(Collectors.joining(","));
|
|
102
|
103
|
GoodsSearchParams params = new GoodsSearchParams();
|
|
103
|
104
|
params.setId(ids);
|
|
104
|
105
|
Map<String, String> id2Unit = goodsService.queryListByParams(params).stream()
|
|
105
|
106
|
.collect(Collectors.toMap(Goods::getId, Goods::getGoodsUnit));
|
|
106
|
|
- for (int i = 0; i < items.size(); i++) {
|
|
107
|
|
- OrderItem item = items.get(i);
|
|
108
|
|
- Map<String, Object> itemMap = new HashMap<>();
|
|
109
|
|
- Map<String, Object> orderHead = new HashMap<>(32);
|
|
110
|
|
- // 1. 表头
|
|
111
|
|
- // 电商平台名称
|
|
112
|
|
- orderHead.put(CEB_PREFIX + "ebpName", "速贸云");
|
|
113
|
|
- // 电商平台代码
|
|
114
|
|
- orderHead.put(CEB_PREFIX + "ebpCode", "无");
|
|
115
|
|
- // 电商企业名称
|
|
116
|
|
- orderHead.put(CEB_PREFIX + "ebcName", payload.copName);
|
|
117
|
|
- // 电商企业代码 (电商企业的海关注册登记编号)
|
|
118
|
|
- orderHead.put(CEB_PREFIX + "ebcCode", payload.copCode);
|
|
119
|
|
- // 系统唯一序号
|
|
120
|
|
- orderHead.put(CEB_PREFIX + "guid", exchange.getGuid());
|
|
121
|
|
- // 业务状态 (1 - 暂存, 2 - 报送)默认为2
|
|
122
|
|
- orderHead.put(CEB_PREFIX + "appStatus", "2");
|
|
123
|
|
- // 商品价格 (商品实际价格,含非现金抵扣金额)
|
|
124
|
|
- orderHead.put(CEB_PREFIX + "goodsValue", String.valueOf(item.getFlowPrice()));
|
|
125
|
|
- // 企业报送类型 (1 - 新增, 2 - 变更, 3 - 删除)默认为1
|
|
126
|
|
- orderHead.put(CEB_PREFIX + "appType", "2");
|
|
127
|
|
- // 运杂费(不包含在商品价格中的运杂费,无则填写0)
|
|
128
|
|
- orderHead.put(CEB_PREFIX + "freight", "0");
|
|
129
|
|
- // 订单类型 (I - 进口, E - 9610出口, B - 9710出口, W - 9810出口)
|
|
130
|
|
- orderHead.put(CEB_PREFIX + "orderType", "B");
|
|
131
|
|
- // 订单编号 (交易平台订单编号,长度不能超过60位)
|
|
132
|
|
- orderHead.put(CEB_PREFIX + "orderNo", exchange.getOrderDetailVO().getOrder().getSn());
|
|
133
|
|
- // 企业报送时间(格式YYYYMMDDhhmmss)
|
|
134
|
|
- orderHead.put(CEB_PREFIX + "appTime", timeStr);
|
|
135
|
|
- // 币制 (限定为人民币 - 142)
|
|
136
|
|
- orderHead.put(CEB_PREFIX + "currency", "142");
|
|
137
|
|
- // 备注
|
|
138
|
|
- orderHead.put(CEB_PREFIX + "note", "");
|
|
139
|
|
-
|
|
140
|
|
- Map<String, Object> orderLists = new HashMap<>(32);
|
|
141
|
|
- // 2. 表体
|
|
142
|
|
- // 商品序号(从1开始递增序号)
|
|
143
|
|
- orderLists.put(CEB_PREFIX + "gnum", i + 1);
|
|
144
|
|
- // 企业商品货号(SKU编号,最长30位)
|
|
145
|
|
- orderLists.put(CEB_PREFIX + "itemNo", item.getSkuId());
|
|
146
|
|
- // 企业商品名称(中文名称)
|
|
147
|
|
- orderLists.put(CEB_PREFIX + "itemName", item.getGoodsName());
|
|
148
|
|
- // 企业商品描述
|
|
149
|
|
- orderLists.put(CEB_PREFIX + "itemDescribe", item.getGoodsName());
|
|
150
|
|
- // 商品条形码 (非必填)
|
|
151
|
|
- orderLists.put(CEB_PREFIX + "barCode", "");
|
|
152
|
|
- // 单位
|
|
153
|
|
- // TODO 单位映射 必填
|
|
154
|
|
- orderLists.put(CEB_PREFIX + "unit", id2Unit.get(item.getGoodsId()));
|
|
155
|
|
- // 币制 (限定为人民币 - 142)
|
|
156
|
|
- orderLists.put(CEB_PREFIX + "currency", "142");
|
|
157
|
|
- // 数量
|
|
158
|
|
- orderLists.put(CEB_PREFIX + "qty", item.getNum());
|
|
159
|
|
- // 单价
|
|
160
|
|
- orderLists.put(CEB_PREFIX + "price", item.getGoodsPrice());
|
|
161
|
|
- // 商品价格 (商品实际价格,含非现金抵扣金额)
|
|
162
|
|
- orderLists.put(CEB_PREFIX + "totalPrice", String.valueOf(item.getFlowPrice()));
|
|
163
|
|
- // 备注
|
|
164
|
|
- orderLists.put(CEB_PREFIX + "note", "");
|
|
165
|
|
-
|
|
166
|
|
- // 放入订单列表
|
|
167
|
|
- itemMap.put(CEB_PREFIX + "OrderHead", orderHead);
|
|
168
|
|
- itemMap.put(CEB_PREFIX + "OrderList", orderLists);
|
|
169
|
|
- orderList.add(itemMap);
|
|
170
|
|
- }
|
|
|
107
|
+ for (int i = 0; i < items.size(); i++) {
|
|
|
108
|
+ OrderItem item = items.get(i);
|
|
|
109
|
+ try {
|
|
|
110
|
+ Map<String, Object> itemMap = new HashMap<>();
|
|
|
111
|
+ Map<String, Object> orderHead = new HashMap<>(32);
|
|
|
112
|
+ // 1. 表头
|
|
|
113
|
+ // 电商平台名称
|
|
|
114
|
+ orderHead.put(CEB_PREFIX + "ebpName", "速贸云");
|
|
|
115
|
+ // 电商平台代码
|
|
|
116
|
+ orderHead.put(CEB_PREFIX + "ebpCode", "无");
|
|
|
117
|
+ // 电商企业名称
|
|
|
118
|
+ orderHead.put(CEB_PREFIX + "ebcName", payload.copName);
|
|
|
119
|
+ // 电商企业代码 (电商企业的海关注册登记编号)
|
|
|
120
|
+ orderHead.put(CEB_PREFIX + "ebcCode", payload.copCode);
|
|
|
121
|
+ // 系统唯一序号
|
|
|
122
|
+ orderHead.put(CEB_PREFIX + "guid", exchange.getGuid());
|
|
|
123
|
+ // 业务状态 (1 - 暂存, 2 - 报送)默认为2
|
|
|
124
|
+ orderHead.put(CEB_PREFIX + "appStatus", "1");
|
|
|
125
|
+ // 商品价格 (商品实际价格,含非现金抵扣金额)
|
|
|
126
|
+ orderHead.put(CEB_PREFIX + "goodsValue", String.valueOf(item.getFlowPrice()));
|
|
|
127
|
+ // 企业报送类型 (1 - 新增, 2 - 变更, 3 - 删除)默认为1
|
|
|
128
|
+ orderHead.put(CEB_PREFIX + "appType", "1");
|
|
|
129
|
+ // 运杂费(不包含在商品价格中的运杂费,无则填写0)
|
|
|
130
|
+ orderHead.put(CEB_PREFIX + "freight", "0");
|
|
|
131
|
+ // 订单类型 (I - 进口, E - 9610出口, B - 9710出口, W - 9810出口)
|
|
|
132
|
+ orderHead.put(CEB_PREFIX + "orderType", "B");
|
|
|
133
|
+ // 订单编号 (交易平台订单编号,长度不能超过60位)
|
|
|
134
|
+ orderHead.put(CEB_PREFIX + "orderNo", exchange.getOrderDetailVO().getOrder().getSn());
|
|
|
135
|
+ // 企业报送时间(格式YYYYMMDDhhmmss)
|
|
|
136
|
+ orderHead.put(CEB_PREFIX + "appTime", timeStr);
|
|
|
137
|
+ // 币制 (限定为人民币 - 142)
|
|
|
138
|
+ orderHead.put(CEB_PREFIX + "currency", "142");
|
|
|
139
|
+ // 备注
|
|
|
140
|
+ orderHead.put(CEB_PREFIX + "note", "");
|
|
|
141
|
+
|
|
|
142
|
+ Map<String, Object> orderLists = new HashMap<>(32);
|
|
|
143
|
+ // 2. 表体
|
|
|
144
|
+ // 商品序号(从1开始递增序号)
|
|
|
145
|
+ orderLists.put(CEB_PREFIX + "gnum", i + 1);
|
|
|
146
|
+ // 企业商品货号(SKU编号,最长30位)
|
|
|
147
|
+ orderLists.put(CEB_PREFIX + "itemNo", item.getSkuId());
|
|
|
148
|
+ // 企业商品名称(中文名称)
|
|
|
149
|
+ orderLists.put(CEB_PREFIX + "itemName", item.getGoodsName());
|
|
|
150
|
+ // 企业商品描述
|
|
|
151
|
+ orderLists.put(CEB_PREFIX + "itemDescribe", item.getGoodsName());
|
|
|
152
|
+ // 商品条形码 (非必填)
|
|
|
153
|
+ orderLists.put(CEB_PREFIX + "barCode", "");
|
|
|
154
|
+ // 单位
|
|
|
155
|
+ String cnName = id2Unit.get(item.getGoodsId());
|
|
|
156
|
+ orderLists.put(CEB_PREFIX + "unit", JGS20Unit.ofCnName(cnName).code);
|
|
|
157
|
+ // 币制 (限定为人民币 - 142)
|
|
|
158
|
+ orderLists.put(CEB_PREFIX + "currency", "142");
|
|
|
159
|
+ // 数量
|
|
|
160
|
+ orderLists.put(CEB_PREFIX + "qty", item.getNum());
|
|
|
161
|
+ // 单价
|
|
|
162
|
+ orderLists.put(CEB_PREFIX + "price", item.getGoodsPrice());
|
|
|
163
|
+ // 商品价格 (商品实际价格,含非现金抵扣金额)
|
|
|
164
|
+ orderLists.put(CEB_PREFIX + "totalPrice", String.valueOf(item.getFlowPrice()));
|
|
|
165
|
+ // 备注
|
|
|
166
|
+ orderLists.put(CEB_PREFIX + "note", "");
|
|
|
167
|
+
|
|
|
168
|
+ // 放入订单列表
|
|
|
169
|
+ itemMap.put(CEB_PREFIX + "OrderHead", orderHead);
|
|
|
170
|
+ itemMap.put(CEB_PREFIX + "OrderList", orderLists);
|
|
|
171
|
+ orderList.add(itemMap);
|
|
|
172
|
+ } catch (UnitIllegalException e) {
|
|
|
173
|
+ throw new ServiceException(ORDER_CUSTOMS_ERROR, String.format("商品[%s]", item.getGoodsName()) + e.getMsg());
|
|
|
174
|
+ }
|
|
|
175
|
+ }
|
|
171
|
176
|
});
|
|
172
|
177
|
|
|
173
|
178
|
return orderList;
|
|
|
@@ -188,7 +193,6 @@ public class JiangyinServiceReqConverter implements CustomsReqConverter{
|
|
188
|
193
|
// 报文传输模式
|
|
189
|
194
|
transfer.put(CEB_PREFIX + "dxpMode", "DXP");
|
|
190
|
195
|
// 报文传输编号
|
|
191
|
|
- // TODO 待平台方确认
|
|
192
|
196
|
transfer.put(CEB_PREFIX + "dxpId", payload.dxpId);
|
|
193
|
197
|
// 备注
|
|
194
|
198
|
transfer.put(CEB_PREFIX + "note", "");
|