|
@@ -3,23 +3,19 @@ package com.yohoufo.order.service.deposit; |
|
@@ -3,23 +3,19 @@ package com.yohoufo.order.service.deposit; |
3
|
import com.google.common.collect.Lists;
|
3
|
import com.google.common.collect.Lists;
|
4
|
import com.yoho.error.ServiceError;
|
4
|
import com.yoho.error.ServiceError;
|
5
|
import com.yoho.error.exception.ServiceException;
|
5
|
import com.yoho.error.exception.ServiceException;
|
|
|
6
|
+import com.yohobuy.ufo.model.order.bo.DepositDetailBo;
|
6
|
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
|
7
|
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
|
7
|
import com.yohobuy.ufo.model.order.common.OrderCodeType;
|
8
|
import com.yohobuy.ufo.model.order.common.OrderCodeType;
|
8
|
import com.yohobuy.ufo.model.order.constants.DepositEventTypeEnum;
|
9
|
import com.yohobuy.ufo.model.order.constants.DepositEventTypeEnum;
|
9
|
import com.yohobuy.ufo.model.order.constants.OrderConstant;
|
10
|
import com.yohobuy.ufo.model.order.constants.OrderConstant;
|
|
|
11
|
+import com.yohobuy.ufo.model.order.constants.StorageDepositStatusEnum;
|
10
|
import com.yohobuy.ufo.model.order.req.DepositOrderComputeReq;
|
12
|
import com.yohobuy.ufo.model.order.req.DepositOrderComputeReq;
|
11
|
import com.yohobuy.ufo.model.order.resp.DepositOrderComputeResp;
|
13
|
import com.yohobuy.ufo.model.order.resp.DepositOrderComputeResp;
|
12
|
import com.yohobuy.ufo.model.order.vo.AddressInfo;
|
14
|
import com.yohobuy.ufo.model.order.vo.AddressInfo;
|
13
|
import com.yohoufo.common.exception.UfoServiceException;
|
15
|
import com.yohoufo.common.exception.UfoServiceException;
|
14
|
import com.yohoufo.common.utils.StringUtil;
|
16
|
import com.yohoufo.common.utils.StringUtil;
|
15
|
-import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
|
|
|
16
|
-import com.yohoufo.dal.order.DepositOrderMapper;
|
|
|
17
|
-import com.yohoufo.dal.order.SellerOrderGoodsMapper;
|
|
|
18
|
-import com.yohoufo.dal.order.StorageDepositMapper;
|
|
|
19
|
-import com.yohoufo.dal.order.model.BuyerOrderGoods;
|
|
|
20
|
-import com.yohoufo.dal.order.model.DepositOrder;
|
|
|
21
|
-import com.yohoufo.dal.order.model.SellerOrderGoods;
|
|
|
22
|
-import com.yohoufo.dal.order.model.StorageDeposit;
|
17
|
+import com.yohoufo.dal.order.*;
|
|
|
18
|
+import com.yohoufo.dal.order.model.*;
|
23
|
import com.yohoufo.order.convert.GoodsInfoConvertor;
|
19
|
import com.yohoufo.order.convert.GoodsInfoConvertor;
|
24
|
import com.yohoufo.order.model.response.OrderSubmitResponse;
|
20
|
import com.yohoufo.order.model.response.OrderSubmitResponse;
|
25
|
import com.yohoufo.order.service.DepositService;
|
21
|
import com.yohoufo.order.service.DepositService;
|
|
@@ -33,6 +29,7 @@ import org.springframework.stereotype.Service; |
|
@@ -33,6 +29,7 @@ import org.springframework.stereotype.Service; |
33
|
|
29
|
|
34
|
import java.math.BigDecimal;
|
30
|
import java.math.BigDecimal;
|
35
|
import java.util.List;
|
31
|
import java.util.List;
|
|
|
32
|
+import java.util.Objects;
|
36
|
|
33
|
|
37
|
/**
|
34
|
/**
|
38
|
* Created by li.ma on 2019/7/9.
|
35
|
* Created by li.ma on 2019/7/9.
|
|
@@ -51,7 +48,7 @@ public class DepositOrderService { |
|
@@ -51,7 +48,7 @@ public class DepositOrderService { |
51
|
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
|
48
|
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
|
52
|
|
49
|
|
53
|
@Autowired
|
50
|
@Autowired
|
54
|
- private BuyerOrderGoodsMapper buyerOrderGoodsMapper;
|
51
|
+ private BuyerOrderMapper buyerOrderMapper;
|
55
|
|
52
|
|
56
|
@Autowired
|
53
|
@Autowired
|
57
|
private IBuyerOrderMetaService buyerOrderMetaService;
|
54
|
private IBuyerOrderMetaService buyerOrderMetaService;
|
|
@@ -68,42 +65,42 @@ public class DepositOrderService { |
|
@@ -68,42 +65,42 @@ public class DepositOrderService { |
68
|
* @return
|
65
|
* @return
|
69
|
*/
|
66
|
*/
|
70
|
public DepositOrderComputeResp computePublishPrd(DepositOrderComputeReq req) {
|
67
|
public DepositOrderComputeResp computePublishPrd(DepositOrderComputeReq req) {
|
71
|
- StorageDeposit storageDeposit = checkStorageDeposit(req); // 不存在的时候有异常
|
68
|
+ StorageDeposit storageDeposit = checkStorageDeposit(req,
|
|
|
69
|
+ Lists.newArrayList(StorageDepositStatusEnum.HAS_IN.getCode())); // 不存在的时候有异常
|
72
|
|
70
|
|
73
|
int depositRemainDay = depositService.getRemainDay(req.getUid(), req.getDepositCode()); // 还可存放多久 单位天
|
71
|
int depositRemainDay = depositService.getRemainDay(req.getUid(), req.getDepositCode()); // 还可存放多久 单位天
|
74
|
|
72
|
|
75
|
Integer skup = storageDeposit.getSkup();
|
73
|
Integer skup = storageDeposit.getSkup();
|
76
|
Long orderCode = storageDeposit.getOrderCode();
|
74
|
Long orderCode = storageDeposit.getOrderCode();
|
77
|
|
75
|
|
78
|
- SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
|
|
|
79
|
- GoodsInfo goodsInfo = null;
|
|
|
80
|
- if (null != sellerOrderGoods) {
|
|
|
81
|
- goodsInfo = GoodsInfoConvertor.SellerOrderGoods2GoodsInfo(sellerOrderGoods);
|
|
|
82
|
- }
|
|
|
83
|
- List<BuyerOrderGoods> buyerOrderGoodses = buyerOrderGoodsMapper.selectBySkups(Lists.newArrayList(skup));
|
|
|
84
|
- DepositOrderComputeResp.PriceInfo priceInfo = getFeeInfo(orderCode);
|
|
|
85
|
- if (CollectionUtils.isNotEmpty(buyerOrderGoodses)) {
|
|
|
86
|
- priceInfo.setGoodPrice(buyerOrderGoodses.get(0).getGoodsAmount());
|
|
|
87
|
- }
|
76
|
+ GoodsInfo goodsInfo = getGoodsInfo(skup); // 查询购买商品的详细信息
|
|
|
77
|
+
|
|
|
78
|
+
|
|
|
79
|
+ DepositOrderComputeResp.PriceInfo priceInfo = getFeeInfo(orderCode, req.getAddress_id()); // 获取各种费用
|
88
|
|
80
|
|
89
|
- AddressInfo addressInfo = buyerOrderMetaService.getAddressInfo(req.getUid(), orderCode);
|
81
|
+ setBuyerPrice(orderCode, priceInfo); // 设置入手价
|
|
|
82
|
+
|
|
|
83
|
+ AddressInfo addressInfo = buyerOrderMetaService.getHiddenAddressInfo(req.getUid(), orderCode);
|
90
|
|
84
|
|
91
|
return DepositOrderComputeResp.builder().depositRemainDay(getReplacedContent(DepositOrderComputeResp.DEPOSITREMAINDAY_TIP, depositRemainDay))
|
85
|
return DepositOrderComputeResp.builder().depositRemainDay(getReplacedContent(DepositOrderComputeResp.DEPOSITREMAINDAY_TIP, depositRemainDay))
|
92
|
.userAddress(addressInfo).priceInfo(priceInfo).goodsInfo(goodsInfo).build();
|
86
|
.userAddress(addressInfo).priceInfo(priceInfo).goodsInfo(goodsInfo).build();
|
93
|
}
|
87
|
}
|
94
|
|
88
|
|
95
|
|
89
|
|
|
|
90
|
+
|
|
|
91
|
+
|
96
|
public OrderSubmitResponse publishDepositOrder(DepositOrderComputeReq req) {
|
92
|
public OrderSubmitResponse publishDepositOrder(DepositOrderComputeReq req) {
|
97
|
Integer uid = req.getUid();
|
93
|
Integer uid = req.getUid();
|
98
|
if (uid == null || uid <= 0){
|
94
|
if (uid == null || uid <= 0){
|
99
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
95
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
100
|
}
|
96
|
}
|
101
|
- checkStorageDeposit(req);
|
97
|
+ StorageDeposit storageDeposit = checkStorageDeposit(req,
|
|
|
98
|
+ Lists.newArrayList(StorageDepositStatusEnum.HAS_IN.getCode())); //查看在库状态的库存
|
102
|
|
99
|
|
103
|
long orderCode = orderCodeGenerator.generate(OrderCodeType.STORAGE_MANAGEMENT);
|
100
|
long orderCode = orderCodeGenerator.generate(OrderCodeType.STORAGE_MANAGEMENT);
|
104
|
|
101
|
|
105
|
int now = (int) (System.currentTimeMillis()/1000);
|
102
|
int now = (int) (System.currentTimeMillis()/1000);
|
106
|
- DepositOrderComputeResp.PriceInfo priceInfo = getFeeInfo(orderCode);
|
103
|
+ DepositOrderComputeResp.PriceInfo priceInfo = getFeeInfo(orderCode, req.getAddress_id());
|
107
|
|
104
|
|
108
|
DepositOrder depositOrder = DepositOrder.builder().uid(uid).amount(priceInfo.getAmount())
|
105
|
DepositOrder depositOrder = DepositOrder.builder().uid(uid).amount(priceInfo.getAmount())
|
109
|
.contractFee(priceInfo.getContractFee())
|
106
|
.contractFee(priceInfo.getContractFee())
|
|
@@ -111,6 +108,9 @@ public class DepositOrderService { |
|
@@ -111,6 +108,9 @@ public class DepositOrderService { |
111
|
.createTime(now).depositCode(req.getDepositCode())
|
108
|
.createTime(now).depositCode(req.getDepositCode())
|
112
|
.eventType(DepositEventTypeEnum.DEPOSIT_RECALL_FEE.getCode()).orderCode(orderCode).payment(0).status(0).updateTime(now).build();
|
109
|
.eventType(DepositEventTypeEnum.DEPOSIT_RECALL_FEE.getCode()).orderCode(orderCode).payment(0).status(0).updateTime(now).build();
|
113
|
|
110
|
|
|
|
111
|
+ // TODO 创建召回地址
|
|
|
112
|
+ storageDeposit.getOrderCode();
|
|
|
113
|
+
|
114
|
LOG.info("enter publishDepositOrder begin save depositOrder {} ",depositOrder);
|
114
|
LOG.info("enter publishDepositOrder begin save depositOrder {} ",depositOrder);
|
115
|
int num = depositOrderMapper.insert(depositOrder); // 生成订单数据,insert db
|
115
|
int num = depositOrderMapper.insert(depositOrder); // 生成订单数据,insert db
|
116
|
LOG.info("enter publishDepositOrder end save depositOrder {} ,num {}",depositOrder, num);
|
116
|
LOG.info("enter publishDepositOrder end save depositOrder {} ,num {}",depositOrder, num);
|
|
@@ -118,18 +118,83 @@ public class DepositOrderService { |
|
@@ -118,18 +118,83 @@ public class DepositOrderService { |
118
|
return OrderSubmitResponse.builder().orderCode(orderCode).paymentStatus(OrderConstant.N_STR).build();
|
118
|
return OrderSubmitResponse.builder().orderCode(orderCode).paymentStatus(OrderConstant.N_STR).build();
|
119
|
}
|
119
|
}
|
120
|
|
120
|
|
121
|
- private StorageDeposit checkStorageDeposit(DepositOrderComputeReq req) {
|
|
|
122
|
- StorageDeposit storageDeposit = storageDepositMapper.selectByDepositCode(req.getUid(), req.getDepositCode());
|
|
|
123
|
- if (null == storageDeposit || null == storageDeposit.getSkup() || null == storageDeposit.getOrderCode()) {
|
|
|
124
|
- LOG.warn("storageDepositMapper.selectByDepositCode not exist, req is {}", req);
|
|
|
125
|
- throw new UfoServiceException(400, "在库状态的库存不存在");
|
121
|
+
|
|
|
122
|
+
|
|
|
123
|
+ public void updateByOrderCode(DepositOrder order) {
|
|
|
124
|
+ depositOrderMapper.updatePayment(order);
|
126
|
}
|
125
|
}
|
127
|
|
126
|
|
128
|
- return storageDeposit;
|
127
|
+ public DepositOrder selectByOrderCodeUid(long orderCode, int uid) {
|
|
|
128
|
+ return depositOrderMapper.selectByOrderCode(orderCode);
|
|
|
129
|
+ }
|
|
|
130
|
+
|
|
|
131
|
+ public int updateStatusByOrderCode(DepositOrder order) {
|
|
|
132
|
+ return depositOrderMapper.updateStatusByOrderCode(order);
|
|
|
133
|
+ }
|
|
|
134
|
+
|
|
|
135
|
+ public DepositOrder selectByOrderCode(Long orderCode) {
|
|
|
136
|
+ return depositOrderMapper.selectByOrderCode(orderCode);
|
|
|
137
|
+ }
|
|
|
138
|
+
|
|
|
139
|
+ /**
|
|
|
140
|
+ * 查询召回订单详情
|
|
|
141
|
+ * @param req
|
|
|
142
|
+ * @return
|
|
|
143
|
+ */
|
|
|
144
|
+ public DepositOrderComputeResp depositOrderInfo(DepositOrderComputeReq req) {
|
|
|
145
|
+ StorageDeposit storageDeposit = checkStorageDeposit(req,
|
|
|
146
|
+ Lists.newArrayList(StorageDepositStatusEnum.WAITING_QUERY.getCode(), StorageDepositStatusEnum.WAITING_OUT.getCode())); // 不存在的时候有异常
|
|
|
147
|
+
|
|
|
148
|
+ DepositDetailBo depositDetailBo = depositService.convert(storageDeposit);
|
|
|
149
|
+
|
|
|
150
|
+ AddressInfo addressInfo = buyerOrderMetaService.getHiddenAddressInfo(req.getUid(), storageDeposit.getOrderCode());
|
|
|
151
|
+
|
|
|
152
|
+ GoodsInfo goodsInfo = getGoodsInfo(storageDeposit.getSkup()); // 查询购买商品的详细信息
|
|
|
153
|
+
|
|
|
154
|
+ DepositOrderComputeResp.PriceInfo priceInfo = getOrderFeeInfo(req.getDepositCode()); // 获取各种费用
|
|
|
155
|
+
|
|
|
156
|
+ setBuyerPrice(storageDeposit.getOrderCode(), priceInfo); // 设置入手价
|
|
|
157
|
+
|
|
|
158
|
+ return DepositOrderComputeResp.builder().userAddress(addressInfo).priceInfo(priceInfo).goodsInfo(goodsInfo).depositDetailBo(depositDetailBo).build();
|
|
|
159
|
+ }
|
|
|
160
|
+
|
|
|
161
|
+ /**
|
|
|
162
|
+ * 查询召回订单的各种详情
|
|
|
163
|
+ * @param depositCode
|
|
|
164
|
+ * @return
|
|
|
165
|
+ */
|
|
|
166
|
+ private DepositOrderComputeResp.PriceInfo getOrderFeeInfo(String depositCode) {
|
|
|
167
|
+ DepositOrderComputeResp.PriceInfo priceInfo = DepositOrderComputeResp.PriceInfo.builder().build();
|
|
|
168
|
+
|
|
|
169
|
+ DepositOrder depositOrder = depositOrderMapper.selectByDepositCode(depositCode, DepositEventTypeEnum.DEPOSIT_RECALL_FEE.getCode()); // 自动到期之后寄回的,没有订单
|
|
|
170
|
+ if (Objects.isNull(depositOrder)) {
|
|
|
171
|
+ return DepositOrderComputeResp.PriceInfo.builder().build();
|
|
|
172
|
+ }
|
|
|
173
|
+
|
|
|
174
|
+ return DepositOrderComputeResp.PriceInfo.builder().amount(depositOrder.getAmount())
|
|
|
175
|
+ .contractFee(depositOrder.getContractFee())
|
|
|
176
|
+ .shipFee(depositOrder.getShipFee()).build();
|
|
|
177
|
+ }
|
|
|
178
|
+
|
|
|
179
|
+
|
|
|
180
|
+ private void setBuyerPrice(Long orderCode, DepositOrderComputeResp.PriceInfo priceInfo) {
|
|
|
181
|
+ BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
|
|
|
182
|
+ if (!Objects.isNull(buyerOrder)) {
|
|
|
183
|
+ priceInfo.setGoodPrice(buyerOrder.getAmount());
|
|
|
184
|
+ }
|
|
|
185
|
+ }
|
|
|
186
|
+
|
|
|
187
|
+ private GoodsInfo getGoodsInfo(Integer skup) {
|
|
|
188
|
+ SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
|
|
|
189
|
+ GoodsInfo goodsInfo = null;
|
|
|
190
|
+ if (null != sellerOrderGoods) {
|
|
|
191
|
+ goodsInfo = GoodsInfoConvertor.SellerOrderGoods2GoodsInfo(sellerOrderGoods);
|
|
|
192
|
+ }
|
|
|
193
|
+ return goodsInfo;
|
129
|
}
|
194
|
}
|
130
|
|
195
|
|
131
|
// 查询召回所需要的费用
|
196
|
// 查询召回所需要的费用
|
132
|
- private DepositOrderComputeResp.PriceInfo getFeeInfo(Long orderCode) {
|
197
|
+ private DepositOrderComputeResp.PriceInfo getFeeInfo(Long orderCode, String addressId) {
|
133
|
BigDecimal contractFee = new BigDecimal(15); // 违约金
|
198
|
BigDecimal contractFee = new BigDecimal(15); // 违约金
|
134
|
BigDecimal shipFee = new BigDecimal(15); // 运费
|
199
|
BigDecimal shipFee = new BigDecimal(15); // 运费
|
135
|
BigDecimal amount = contractFee.add(shipFee);
|
200
|
BigDecimal amount = contractFee.add(shipFee);
|
|
@@ -141,19 +206,13 @@ public class DepositOrderService { |
|
@@ -141,19 +206,13 @@ public class DepositOrderService { |
141
|
return StringUtil.getReplacedContent(content, params);
|
206
|
return StringUtil.getReplacedContent(content, params);
|
142
|
}
|
207
|
}
|
143
|
|
208
|
|
144
|
- public void updateByOrderCode(DepositOrder order) {
|
|
|
145
|
- depositOrderMapper.updatePayment(order);
|
|
|
146
|
- }
|
|
|
147
|
-
|
|
|
148
|
- public DepositOrder selectByOrderCodeUid(long orderCode, int uid) {
|
|
|
149
|
- return null;
|
|
|
150
|
- }
|
|
|
151
|
-
|
|
|
152
|
- public int updateStatusByOrderCode(DepositOrder order) {
|
|
|
153
|
- return depositOrderMapper.updateStatusByOrderCode(order);
|
209
|
+ private StorageDeposit checkStorageDeposit(DepositOrderComputeReq req, List<Integer> statusList) {
|
|
|
210
|
+ StorageDeposit storageDeposit = storageDepositMapper.selectByDepositCode(req.getUid(), req.getDepositCode(), statusList);
|
|
|
211
|
+ if (null == storageDeposit || null == storageDeposit.getSkup() || null == storageDeposit.getOrderCode()) {
|
|
|
212
|
+ LOG.warn("storageDepositMapper.selectByDepositCode not exist, req is {}", req);
|
|
|
213
|
+ throw new UfoServiceException(400, "在库状态的库存不存在");
|
154
|
}
|
214
|
}
|
155
|
|
215
|
|
156
|
- public DepositOrder selectByOrderCode(Long orderCode) {
|
|
|
157
|
- return depositOrderMapper.selectByOrderCode(orderCode);
|
216
|
+ return storageDeposit;
|
158
|
}
|
217
|
}
|
159
|
} |
218
|
} |