Merge branch 'dev'
Showing
6 changed files
with
173 additions
and
91 deletions
1 | +package com.yohoufo.order.common; | ||
2 | + | ||
3 | +import java.util.Arrays; | ||
4 | +import java.util.List; | ||
5 | + | ||
6 | +/** | ||
7 | + * Created by chenchao on 2018/9/27. | ||
8 | + */ | ||
9 | +public class ActionStatusHold { | ||
10 | + | ||
11 | + | ||
12 | + public static List<Integer> getSellerCanCancelStatus(){ | ||
13 | + List<Integer> sellerCanCancelStatus; | ||
14 | + sellerCanCancelStatus = Arrays.asList(SellerOrderStatus.WAITING_PAY.getCode(), | ||
15 | + SellerOrderStatus.HAS_PAYED.getCode()); | ||
16 | + | ||
17 | + return sellerCanCancelStatus; | ||
18 | + } | ||
19 | +} |
1 | package com.yohoufo.order.common; | 1 | package com.yohoufo.order.common; |
2 | 2 | ||
3 | +import java.util.HashMap; | ||
4 | +import java.util.Map; | ||
5 | + | ||
3 | public enum OrderCodeType { | 6 | public enum OrderCodeType { |
4 | 7 | ||
5 | SELLER_TYPE(0L), | 8 | SELLER_TYPE(0L), |
@@ -22,11 +25,22 @@ public enum OrderCodeType { | @@ -22,11 +25,22 @@ public enum OrderCodeType { | ||
22 | * @return | 25 | * @return |
23 | */ | 26 | */ |
24 | public static boolean isExistOrderCodeType(long code){ | 27 | public static boolean isExistOrderCodeType(long code){ |
28 | + | ||
29 | + return cache.containsKey(code); | ||
30 | + } | ||
31 | + | ||
32 | + | ||
33 | + public static OrderCodeType getOrderCodeType(long type){ | ||
34 | + return cache.get(type); | ||
35 | + } | ||
36 | + | ||
37 | + | ||
38 | + private static Map<Long, OrderCodeType> cache; | ||
39 | + static { | ||
40 | + cache = new HashMap<>(); | ||
25 | for(OrderCodeType v : values()){ | 41 | for(OrderCodeType v : values()){ |
26 | - if(v.type == code){ | ||
27 | - return true; | ||
28 | - } | 42 | + |
43 | + cache.put(v.type, v); | ||
29 | } | 44 | } |
30 | - return false; | ||
31 | } | 45 | } |
32 | } | 46 | } |
@@ -16,26 +16,27 @@ public interface IExpressInfoService { | @@ -16,26 +16,27 @@ public interface IExpressInfoService { | ||
16 | * @param orderCode 订单号 | 16 | * @param orderCode 订单号 |
17 | * @param wayBillCode 快递单号 | 17 | * @param wayBillCode 快递单号 |
18 | */ | 18 | */ |
19 | - void deliverToDepot(Integer uid,Integer expressCompanyId, Long orderCode, String wayBillCode); | 19 | + void deliverToDepot(Integer sellerUid,Integer expressCompanyId, Long orderCode, String wayBillCode); |
20 | 20 | ||
21 | 21 | ||
22 | /** | 22 | /** |
23 | * 商品鉴定不通过,鉴定中心寄回商品给卖家 | 23 | * 商品鉴定不通过,鉴定中心寄回商品给卖家 |
24 | - * | 24 | + * @param sellerUid 卖家uid |
25 | * @param expressCompanyId 快递公司id | 25 | * @param expressCompanyId 快递公司id |
26 | * @param orderCode 订单号 | 26 | * @param orderCode 订单号 |
27 | * @param wayBillCode 快递单号 | 27 | * @param wayBillCode 快递单号 |
28 | */ | 28 | */ |
29 | - void appraiseFail(Integer expressCompanyId, Long orderCode, String wayBillCode); | 29 | + void appraiseFail(Integer sellerUid,Integer expressCompanyId, Long orderCode, String wayBillCode); |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * 商品鉴定通过,鉴定中心发货给买家 | 32 | * 商品鉴定通过,鉴定中心发货给买家 |
33 | * | 33 | * |
34 | + * @param uid 买家id | ||
34 | * @param expressCompanyId 快递公司id | 35 | * @param expressCompanyId 快递公司id |
35 | * @param orderCode 订单号 | 36 | * @param orderCode 订单号 |
36 | * @param wayBillCode 快递单号 | 37 | * @param wayBillCode 快递单号 |
37 | */ | 38 | */ |
38 | - void appraiseSuccess(Integer expressCompanyId, Long orderCode, String wayBillCode); | 39 | + void appraiseSuccess(Integer uid,Integer expressCompanyId, Long orderCode, String wayBillCode); |
39 | 40 | ||
40 | /** | 41 | /** |
41 | * 根据订单号查询快递信息 | 42 | * 根据订单号查询快递信息 |
1 | package com.yohoufo.order.service.impl; | 1 | package com.yohoufo.order.service.impl; |
2 | 2 | ||
3 | +import com.yoho.error.ServiceError; | ||
4 | +import com.yoho.error.exception.ServiceException; | ||
5 | +import com.yohoufo.common.utils.DateUtil; | ||
6 | +import com.yohoufo.dal.order.BuyerOrderMapper; | ||
7 | +import com.yohoufo.dal.order.model.BuyerOrder; | ||
8 | +import com.yohoufo.order.common.OrderStatus; | ||
3 | import com.yohoufo.order.service.IExpressInfoService; | 9 | import com.yohoufo.order.service.IExpressInfoService; |
10 | +import org.slf4j.Logger; | ||
11 | +import org.slf4j.LoggerFactory; | ||
4 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
5 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
6 | 14 | ||
@@ -10,23 +18,55 @@ import org.springframework.stereotype.Service; | @@ -10,23 +18,55 @@ import org.springframework.stereotype.Service; | ||
10 | @Service | 18 | @Service |
11 | public class AppraiseService { | 19 | public class AppraiseService { |
12 | 20 | ||
21 | + private static final Logger LOGGER = LoggerFactory.getLogger(AppraiseService.class); | ||
13 | 22 | ||
14 | @Autowired | 23 | @Autowired |
15 | private IExpressInfoService expressInfoService; | 24 | private IExpressInfoService expressInfoService; |
16 | 25 | ||
26 | + @Autowired | ||
27 | + private BuyerOrderMapper buyerOrderMapper; | ||
28 | + | ||
17 | public boolean appraiseSuccess(Integer expressCompanyId, Long orderCode, String wayBillCode){ | 29 | public boolean appraiseSuccess(Integer expressCompanyId, Long orderCode, String wayBillCode){ |
30 | + BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode); | ||
31 | + | ||
32 | + if (buyerOrder == null){ | ||
33 | + LOGGER.warn("appraiseSuccess getOrderInfo order not exist, orderCode is {}", orderCode); | ||
34 | + throw new ServiceException(ServiceError.ORDER_NULL); | ||
35 | + } | ||
36 | + | ||
37 | + //记录物流信息 | ||
38 | + expressInfoService.appraiseSuccess(buyerOrder.getUid(),expressCompanyId, orderCode, wayBillCode); | ||
39 | + | ||
40 | + // 更新买家订单状态 | ||
41 | + buyerOrder.setStatus(OrderStatus.WAITING_RECEIVE.getCode()); | ||
42 | + buyerOrder.setUpdateTime(DateUtil.getCurrentTimeSecond()); | ||
43 | + LOGGER.info("appraiseSuccess update buyer order {} ", buyerOrder); | ||
44 | + buyerOrderMapper.updateByPrimaryKeySelective(buyerOrder); | ||
18 | 45 | ||
19 | - expressInfoService.appraiseSuccess(expressCompanyId, orderCode, wayBillCode); | ||
20 | //TODO 更新卖家订单状态,退款给卖家(仅退一次) | 46 | //TODO 更新卖家订单状态,退款给卖家(仅退一次) |
21 | - return false; | 47 | + |
48 | + return true; | ||
22 | } | 49 | } |
23 | 50 | ||
51 | + public boolean appraiseFail(Integer expressCompanyId, Long orderCode, String wayBillCode){ | ||
52 | + BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode); | ||
24 | 53 | ||
54 | + if (buyerOrder == null){ | ||
55 | + LOGGER.warn("appraiseFail getOrderInfo order not exist, orderCode is {}", orderCode); | ||
56 | + throw new ServiceException(ServiceError.ORDER_NULL); | ||
57 | + } | ||
58 | + | ||
59 | + //更新物流信息 | ||
60 | + expressInfoService.appraiseFail(buyerOrder.getSellerUid(),expressCompanyId, orderCode, wayBillCode); | ||
61 | + | ||
62 | + // 更新买家订单状态 | ||
63 | + buyerOrder.setStatus(OrderStatus.CHECKING_FAKE.getCode()); | ||
64 | + buyerOrder.setUpdateTime(DateUtil.getCurrentTimeSecond()); | ||
65 | + LOGGER.info("appraiseFail update buyer order {} ", buyerOrder); | ||
66 | + buyerOrderMapper.updateByPrimaryKeySelective(buyerOrder); | ||
25 | 67 | ||
26 | - public boolean appraiseFail(Integer expressCompanyId, Long orderCode, String wayBillCode){ | ||
27 | - expressInfoService.appraiseFail(expressCompanyId, orderCode, wayBillCode); | ||
28 | //TODO 更新卖家订单状态,买家订单状态;开始分账 | 68 | //TODO 更新卖家订单状态,买家订单状态;开始分账 |
29 | 69 | ||
30 | - return false; | 70 | + return true; |
31 | } | 71 | } |
32 | } | 72 | } |
@@ -64,20 +64,20 @@ public class ExpressInfoServiceImpl implements IExpressInfoService { | @@ -64,20 +64,20 @@ public class ExpressInfoServiceImpl implements IExpressInfoService { | ||
64 | 64 | ||
65 | /** | 65 | /** |
66 | * | 66 | * |
67 | - * @param uid 卖家的uid | 67 | + * @param sellerUid 卖家的uid |
68 | * @param expressCompanyId 快递公司id | 68 | * @param expressCompanyId 快递公司id |
69 | * @param orderCode 订单号 :一定是买家订单编号 | 69 | * @param orderCode 订单号 :一定是买家订单编号 |
70 | * @param wayBillCode 快递单号 | 70 | * @param wayBillCode 快递单号 |
71 | */ | 71 | */ |
72 | @Override | 72 | @Override |
73 | - public void deliverToDepot(Integer uid,Integer expressCompanyId, Long orderCode, String wayBillCode) { | 73 | + public void deliverToDepot(Integer sellerUid,Integer expressCompanyId, Long orderCode, String wayBillCode) { |
74 | //保存物流信息+更新订单状态; | 74 | //保存物流信息+更新订单状态; |
75 | //本阶段的物流类型和订单状态 | 75 | //本阶段的物流类型和订单状态 |
76 | OrderStatus orderStatus=OrderStatus.SELLER_SEND_OUT; | 76 | OrderStatus orderStatus=OrderStatus.SELLER_SEND_OUT; |
77 | Integer expressType = ExpressInfoConstant.EXPRESS_TYPE_1; | 77 | Integer expressType = ExpressInfoConstant.EXPRESS_TYPE_1; |
78 | 78 | ||
79 | - LOGGER.info("deliverToDepot saveExpressAndUpdateBuyerOrderStatus uid={} ,expressCompanyId = {}, orderCode = {}, wayBillCode = {} " + | ||
80 | - ",expressType = {} ,orderStatus = {}", new Object[]{uid ,expressCompanyId, orderCode, wayBillCode,expressType,orderStatus}); | 79 | + LOGGER.info("deliverToDepot saveExpressAndUpdateBuyerOrderStatus sellerUid={} ,expressCompanyId = {}, orderCode = {}, wayBillCode = {} " + |
80 | + ",expressType = {} ,orderStatus = {}", new Object[]{sellerUid ,expressCompanyId, orderCode, wayBillCode,expressType,orderStatus}); | ||
81 | BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode); | 81 | BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode); |
82 | 82 | ||
83 | if (buyerOrder == null){ | 83 | if (buyerOrder == null){ |
@@ -85,85 +85,53 @@ public class ExpressInfoServiceImpl implements IExpressInfoService { | @@ -85,85 +85,53 @@ public class ExpressInfoServiceImpl implements IExpressInfoService { | ||
85 | throw new ServiceException(ServiceError.ORDER_NULL); | 85 | throw new ServiceException(ServiceError.ORDER_NULL); |
86 | } | 86 | } |
87 | 87 | ||
88 | - //卖家的uid | ||
89 | - if(uid.intValue()!=buyerOrder.getSellerUid().intValue()){ | 88 | + /* //卖家的uid |
89 | + if(sellerUid.intValue()!=buyerOrder.getSellerUid().intValue()){ | ||
90 | LOGGER.warn("deliverToDepot saveExpressAndUpdateBuyerOrderStatus uid {} not equal buyer order sellerUid {}",uid, buyerOrder.getSellerUid()); | 90 | LOGGER.warn("deliverToDepot saveExpressAndUpdateBuyerOrderStatus uid {} not equal buyer order sellerUid {}",uid, buyerOrder.getSellerUid()); |
91 | throw new ServiceException(400,"参数错误,传入的卖家uid与订单卖家uid不一致"); | 91 | throw new ServiceException(400,"参数错误,传入的卖家uid与订单卖家uid不一致"); |
92 | - } | ||
93 | - | ||
94 | - Integer dealUid=buyerOrder.getSellerUid(); | 92 | + }*/ |
95 | 93 | ||
96 | // 保存订单物流信息 | 94 | // 保存订单物流信息 |
97 | - saveExpress(dealUid,expressCompanyId,orderCode,wayBillCode,expressType); | 95 | + saveExpress(sellerUid,expressCompanyId,orderCode,wayBillCode,expressType); |
96 | + | ||
97 | + // 发送mq获取物流信息 | ||
98 | + sendExpressMQ(sellerUid,expressCompanyId,orderCode,wayBillCode); | ||
99 | + LOGGER.info("deliverToDepot end ! send express to erp "); | ||
98 | 100 | ||
99 | // 更新买家订单状态 | 101 | // 更新买家订单状态 |
100 | buyerOrder.setStatus(orderStatus.getCode()); | 102 | buyerOrder.setStatus(orderStatus.getCode()); |
101 | buyerOrder.setUpdateTime(DateUtil.getCurrentTimeSecond()); | 103 | buyerOrder.setUpdateTime(DateUtil.getCurrentTimeSecond()); |
102 | LOGGER.info("deliverToDepot update buyer order {} ", buyerOrder); | 104 | LOGGER.info("deliverToDepot update buyer order {} ", buyerOrder); |
103 | buyerOrderMapper.updateByPrimaryKeySelective(buyerOrder); | 105 | buyerOrderMapper.updateByPrimaryKeySelective(buyerOrder); |
104 | - | ||
105 | - // 发送mq获取物流信息 | ||
106 | - sendExpressMQ(dealUid,expressCompanyId,orderCode,wayBillCode); | ||
107 | - LOGGER.info("deliverToDepot end ! send express to erp "); | ||
108 | } | 106 | } |
109 | 107 | ||
110 | @Override | 108 | @Override |
111 | - public void appraiseFail(Integer expressCompanyId, Long orderCode, String wayBillCode) { | ||
112 | - OrderStatus orderStatus=OrderStatus.CHECKING_FAKE; | 109 | + public void appraiseFail(Integer sellerUid ,Integer expressCompanyId, Long orderCode, String wayBillCode) { |
113 | Integer expressType = ExpressInfoConstant.EXPRESS_TYPE_3; | 110 | Integer expressType = ExpressInfoConstant.EXPRESS_TYPE_3; |
114 | 111 | ||
115 | LOGGER.info("appraiseFail expressCompanyId = {}, orderCode = {}, wayBillCode = {} " + | 112 | LOGGER.info("appraiseFail expressCompanyId = {}, orderCode = {}, wayBillCode = {} " + |
116 | - ",expressType = {} ,orderStatus = {}", new Object[]{expressCompanyId, orderCode, wayBillCode,expressType,orderStatus}); | ||
117 | - BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode); | ||
118 | - | ||
119 | - if (buyerOrder == null){ | ||
120 | - LOGGER.warn("appraiseFail getOrderInfo order not exist, orderCode is {}", orderCode); | ||
121 | - throw new ServiceException(ServiceError.ORDER_NULL); | ||
122 | - } | ||
123 | - | ||
124 | - Integer dealUid=buyerOrder.getSellerUid(); | 113 | + ",expressType = {}", new Object[]{expressCompanyId, orderCode, wayBillCode,expressType}); |
125 | 114 | ||
126 | // 保存订单物流信息 | 115 | // 保存订单物流信息 |
127 | - saveExpress(dealUid,expressCompanyId,orderCode,wayBillCode,expressType); | ||
128 | - | ||
129 | - // 更新买家订单状态 | ||
130 | - buyerOrder.setStatus(orderStatus.getCode()); | ||
131 | - buyerOrder.setUpdateTime(DateUtil.getCurrentTimeSecond()); | ||
132 | - LOGGER.info("appraiseFail update buyer order {} ", buyerOrder); | ||
133 | - buyerOrderMapper.updateByPrimaryKeySelective(buyerOrder); | 116 | + saveExpress(sellerUid,expressCompanyId,orderCode,wayBillCode,expressType); |
134 | 117 | ||
135 | // 发送mq获取物流信息 | 118 | // 发送mq获取物流信息 |
136 | - sendExpressMQ(dealUid,expressCompanyId,orderCode,wayBillCode); | 119 | + sendExpressMQ(sellerUid,expressCompanyId,orderCode,wayBillCode); |
137 | LOGGER.info("appraiseFail end ! send express to erp "); | 120 | LOGGER.info("appraiseFail end ! send express to erp "); |
138 | } | 121 | } |
139 | 122 | ||
140 | @Override | 123 | @Override |
141 | - public void appraiseSuccess(Integer expressCompanyId, Long orderCode, String wayBillCode) { | ||
142 | - OrderStatus orderStatus=OrderStatus.WAITING_RECEIVE; | 124 | + public void appraiseSuccess(Integer uid,Integer expressCompanyId, Long orderCode, String wayBillCode) { |
143 | Integer expressType = ExpressInfoConstant.EXPRESS_TYPE_2; | 125 | Integer expressType = ExpressInfoConstant.EXPRESS_TYPE_2; |
144 | 126 | ||
145 | LOGGER.info("appraiseSuccess expressCompanyId = {}, orderCode = {}, wayBillCode = {} " + | 127 | LOGGER.info("appraiseSuccess expressCompanyId = {}, orderCode = {}, wayBillCode = {} " + |
146 | - ",expressType = {} ,orderStatus = {}", new Object[]{expressCompanyId, orderCode, wayBillCode,expressType,orderStatus}); | ||
147 | - BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode); | ||
148 | - | ||
149 | - if (buyerOrder == null){ | ||
150 | - LOGGER.warn("appraiseSuccess getOrderInfo order not exist, orderCode is {}", orderCode); | ||
151 | - throw new ServiceException(ServiceError.ORDER_NULL); | ||
152 | - } | ||
153 | - | ||
154 | - Integer dealUid=buyerOrder.getUid(); | 128 | + ",expressType = {} ", new Object[]{expressCompanyId, orderCode, wayBillCode,expressType}); |
155 | 129 | ||
156 | // 保存订单物流信息 | 130 | // 保存订单物流信息 |
157 | - saveExpress(dealUid,expressCompanyId,orderCode,wayBillCode,expressType); | ||
158 | - | ||
159 | - // 更新买家订单状态 | ||
160 | - buyerOrder.setStatus(orderStatus.getCode()); | ||
161 | - buyerOrder.setUpdateTime(DateUtil.getCurrentTimeSecond()); | ||
162 | - LOGGER.info("appraiseSuccess update buyer order {} ", buyerOrder); | ||
163 | - buyerOrderMapper.updateByPrimaryKeySelective(buyerOrder); | 131 | + saveExpress(uid,expressCompanyId,orderCode,wayBillCode,expressType); |
164 | 132 | ||
165 | // 发送mq获取物流信息 | 133 | // 发送mq获取物流信息 |
166 | - sendExpressMQ(dealUid,expressCompanyId,orderCode,wayBillCode); | 134 | + sendExpressMQ(uid,expressCompanyId,orderCode,wayBillCode); |
167 | LOGGER.info("appraiseSuccess end ! send express to erp "); | 135 | LOGGER.info("appraiseSuccess end ! send express to erp "); |
168 | } | 136 | } |
169 | 137 |
@@ -3,12 +3,16 @@ package com.yohoufo.order.service.impl; | @@ -3,12 +3,16 @@ package com.yohoufo.order.service.impl; | ||
3 | import com.yoho.error.ServiceError; | 3 | import com.yoho.error.ServiceError; |
4 | import com.yoho.error.exception.ServiceException; | 4 | import com.yoho.error.exception.ServiceException; |
5 | import com.yohoufo.common.utils.DateUtil; | 5 | import com.yohoufo.common.utils.DateUtil; |
6 | +import com.yohoufo.dal.order.BuyerOrderGoodsMapper; | ||
6 | import com.yohoufo.dal.order.BuyerOrderMapper; | 7 | import com.yohoufo.dal.order.BuyerOrderMapper; |
7 | import com.yohoufo.dal.order.SellerOrderGoodsMapper; | 8 | import com.yohoufo.dal.order.SellerOrderGoodsMapper; |
8 | import com.yohoufo.dal.order.SellerOrderMapper; | 9 | import com.yohoufo.dal.order.SellerOrderMapper; |
9 | import com.yohoufo.dal.order.model.BuyerOrder; | 10 | import com.yohoufo.dal.order.model.BuyerOrder; |
11 | +import com.yohoufo.dal.order.model.BuyerOrderGoods; | ||
10 | import com.yohoufo.dal.order.model.SellerOrder; | 12 | import com.yohoufo.dal.order.model.SellerOrder; |
11 | import com.yohoufo.dal.order.model.SellerOrderGoods; | 13 | import com.yohoufo.dal.order.model.SellerOrderGoods; |
14 | +import com.yohoufo.order.common.ActionStatusHold; | ||
15 | +import com.yohoufo.order.common.OrderCodeType; | ||
12 | import com.yohoufo.order.common.OrderStatus; | 16 | import com.yohoufo.order.common.OrderStatus; |
13 | import com.yohoufo.order.common.SellerOrderStatus; | 17 | import com.yohoufo.order.common.SellerOrderStatus; |
14 | import com.yohoufo.order.event.ErpCancelSellerOrderEvent; | 18 | import com.yohoufo.order.event.ErpCancelSellerOrderEvent; |
@@ -21,6 +25,8 @@ import com.yohoufo.order.service.impl.visitor.AutoCancelCase; | @@ -21,6 +25,8 @@ import com.yohoufo.order.service.impl.visitor.AutoCancelCase; | ||
21 | import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase; | 25 | import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase; |
22 | import com.yohoufo.order.service.impl.visitor.UserCancelCase; | 26 | import com.yohoufo.order.service.impl.visitor.UserCancelCase; |
23 | import com.yohoufo.order.service.proxy.ProductProxyService; | 27 | import com.yohoufo.order.service.proxy.ProductProxyService; |
28 | +import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; | ||
29 | +import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; | ||
24 | import org.slf4j.Logger; | 30 | import org.slf4j.Logger; |
25 | import org.slf4j.LoggerFactory; | 31 | import org.slf4j.LoggerFactory; |
26 | import org.springframework.beans.factory.annotation.Autowired; | 32 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -56,8 +62,14 @@ public class SellerOrderCancelService { | @@ -56,8 +62,14 @@ public class SellerOrderCancelService { | ||
56 | private SellerOrderGoodsMapper sellerOrderGoodsMapper; | 62 | private SellerOrderGoodsMapper sellerOrderGoodsMapper; |
57 | 63 | ||
58 | @Autowired | 64 | @Autowired |
65 | + private BuyerOrderGoodsMapper buyerOrderGoodsMapper; | ||
66 | + | ||
67 | + @Autowired | ||
59 | private ProductProxyService productProxyService; | 68 | private ProductProxyService productProxyService; |
60 | 69 | ||
70 | + @Autowired | ||
71 | + private OrderCodeGenerator orderCodeGenerator; | ||
72 | + | ||
61 | /** | 73 | /** |
62 | * TODO 如何控制好并发,必须控制不能重复转账 退款 | 74 | * TODO 如何控制好并发,必须控制不能重复转账 退款 |
63 | * 使用乐观锁,带着查询到的状态且符合条件时再去更新 | 75 | * 使用乐观锁,带着查询到的状态且符合条件时再去更新 |
@@ -68,26 +80,51 @@ public class SellerOrderCancelService { | @@ -68,26 +80,51 @@ public class SellerOrderCancelService { | ||
68 | OrderCancelEvent event = (OrderCancelEvent)cancelCase.getEvent(); | 80 | OrderCancelEvent event = (OrderCancelEvent)cancelCase.getEvent(); |
69 | int uid = event.getUid(); | 81 | int uid = event.getUid(); |
70 | long orderCode = event.getOrderCode(); | 82 | long orderCode = event.getOrderCode(); |
71 | - | 83 | + CodeMeta codeMeta = orderCodeGenerator.expId(orderCode); |
84 | + if (Objects.isNull(codeMeta)){ | ||
85 | + logger.warn("seller cancel orderCode illegal, req {}", event); | ||
86 | + throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY); | ||
87 | + } | ||
88 | + OrderCodeType actor = OrderCodeType.getOrderCodeType(codeMeta.getType()); | ||
89 | + logger.info("in cancel uid {},orderCode {}, actor {}", uid, orderCode, actor); | ||
72 | //case 1: 未支付时 | 90 | //case 1: 未支付时 |
73 | //case 2: 支付完成,没有买家下单 | 91 | //case 2: 支付完成,没有买家下单 |
74 | //case 3: 支付完成,有买家下单 | 92 | //case 3: 支付完成,有买家下单 |
75 | - cancel(uid, orderCode); | 93 | + cancel(uid, orderCode, actor); |
76 | } | 94 | } |
77 | 95 | ||
78 | 96 | ||
79 | - public int cancel(int uid, long orderCode){ | 97 | + public int cancel(int uid, long orderCode, OrderCodeType actor){ |
80 | int result = 0; | 98 | int result = 0; |
81 | - SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid); | 99 | + SellerOrder sellerOrder = null; |
100 | + | ||
101 | + if (OrderCodeType.SELLER_TYPE.equals(actor)){ | ||
102 | + sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid); | ||
103 | + } | ||
104 | + | ||
105 | + BuyerOrder buyerOrder = null; | ||
106 | + if (OrderCodeType.BUYER_TYPE.equals(actor)){ | ||
107 | + buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode); | ||
108 | + BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(), orderCode); | ||
109 | + sellerOrder = sellerOrderMapper.selectBySkup(buyerOrderGoods.getSkup()); | ||
110 | + } | ||
82 | 111 | ||
83 | if (Objects.isNull(sellerOrder)){ | 112 | if (Objects.isNull(sellerOrder)){ |
84 | return result; | 113 | return result; |
85 | } | 114 | } |
115 | + | ||
86 | Integer status = Optional.ofNullable(sellerOrder).map(SellerOrder::getStatus).orElse(null); | 116 | Integer status = Optional.ofNullable(sellerOrder).map(SellerOrder::getStatus).orElse(null); |
117 | + logger.info("in seller cancel, uid {}, orderCode {}, SellerOrder status {}", uid, orderCode, status); | ||
87 | if (Objects.isNull(status)){ | 118 | if (Objects.isNull(status)){ |
88 | return result; | 119 | return result; |
89 | } | 120 | } |
90 | - logger.info("in seller cancel, uid {}, orderCode {}, SellerOrder status {}", uid, orderCode, status); | 121 | + List<Integer> sellerCanCancelStatus = ActionStatusHold.getSellerCanCancelStatus(); |
122 | + if (!sellerCanCancelStatus.contains(status)){ | ||
123 | + logger.warn("seller cancel can not execute in this status, uid {} orderCode {}, status {}", uid, orderCode, status); | ||
124 | + throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY); | ||
125 | + } | ||
126 | + //TODO check BuyerOrder | ||
127 | + | ||
91 | //target seller Order Status | 128 | //target seller Order Status |
92 | SellerOrderStatus targetSOStatus; | 129 | SellerOrderStatus targetSOStatus; |
93 | //case 1: 未支付时 | 130 | //case 1: 未支付时 |
@@ -99,7 +136,7 @@ public class SellerOrderCancelService { | @@ -99,7 +136,7 @@ public class SellerOrderCancelService { | ||
99 | //case 2: 支付完成,没有买家下单 | 136 | //case 2: 支付完成,没有买家下单 |
100 | //case 3: 支付完成,有买家下单 | 137 | //case 3: 支付完成,有买家下单 |
101 | if (SellerOrderStatus.HAS_PAYED.getCode() == status){ | 138 | if (SellerOrderStatus.HAS_PAYED.getCode() == status){ |
102 | - result = cancelAfterPayAction(sellerOrder); | 139 | + result = cancelAfterPayAction(sellerOrder, buyerOrder); |
103 | } | 140 | } |
104 | 141 | ||
105 | return result; | 142 | return result; |
@@ -203,8 +240,7 @@ public class SellerOrderCancelService { | @@ -203,8 +240,7 @@ public class SellerOrderCancelService { | ||
203 | return result; | 240 | return result; |
204 | } | 241 | } |
205 | 242 | ||
206 | - private int cancelAfterPayExistBuyAction(SellerOrder sellerOrder,List<Integer> sellerCanCancelStatus, | ||
207 | - int buyOrderCnt){ | 243 | + private int cancelAfterPayExistBuyAction(SellerOrder sellerOrder, BuyerOrder buyerOrder){ |
208 | /** | 244 | /** |
209 | * case 3: 支付完成,有买家下单 | 245 | * case 3: 支付完成,有买家下单 |
210 | * actions as blow: | 246 | * actions as blow: |
@@ -213,30 +249,31 @@ public class SellerOrderCancelService { | @@ -213,30 +249,31 @@ public class SellerOrderCancelService { | ||
213 | * 3. sellerOrderGoods | 249 | * 3. sellerOrderGoods |
214 | * 4. 瓜分保证金 | 250 | * 4. 瓜分保证金 |
215 | */ | 251 | */ |
216 | - final int sellerUid = sellerOrder.getUid(); | ||
217 | - final long orderCode = sellerOrder.getOrderCode(); | ||
218 | - logger.info("in seller cancel After Pay while Exist Buy Action, uid {}, orderCode {}", | ||
219 | - sellerUid, orderCode); | 252 | + final int sellerUid = sellerOrder.getUid(), buyerUid = buyerOrder.getUid(); |
253 | + final long sellerOrderCode = sellerOrder.getOrderCode(), buyerOrderCode = buyerOrder.getOrderCode(); | ||
254 | + | ||
255 | + logger.info("in seller cancel After Pay while Exist Buy Action, uid {}, orderCode {}, buyerOrderCode {}", | ||
256 | + sellerUid, sellerOrderCode, buyerOrderCode); | ||
220 | int result = 0; | 257 | int result = 0; |
221 | - List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListBySellerUidStatus(sellerUid, sellerCanCancelStatus, 0, buyOrderCnt); | ||
222 | - List<Long> orderCodes = buyerOrderList.parallelStream().map(BuyerOrder::getOrderCode).collect(Collectors.toList()); | ||
223 | 258 | ||
224 | - if (orderCodes.size() > 1){ | ||
225 | - throw new ServiceException(ServiceError.ERP_ORDER_CANCEL_FAILED); | ||
226 | - } | ||
227 | //actions of buyer order and related | 259 | //actions of buyer order and related |
228 | //update buyer Order | 260 | //update buyer Order |
229 | //target Buyer Order Status | 261 | //target Buyer Order Status |
230 | Integer targetBOStatus; | 262 | Integer targetBOStatus; |
231 | targetBOStatus = OrderStatus.SELLER_CANCEL_AFTER_PAY.getCode(); | 263 | targetBOStatus = OrderStatus.SELLER_CANCEL_AFTER_PAY.getCode(); |
232 | - result += buyerOrderMapper.updateBatchByOrderCodes(orderCodes, targetBOStatus, DateUtil.getCurrentTimeSecond()); | 264 | + BuyerOrder tbo = new BuyerOrder(); |
265 | + tbo.setUid(buyerUid); | ||
266 | + tbo.setOrderCode(buyerOrderCode); | ||
267 | + tbo.setStatus(targetBOStatus); | ||
268 | + tbo.setUpdateTime(DateUtil.getCurrentTimeSecond()); | ||
269 | + result += buyerOrderMapper.updateByOrderCode(tbo); | ||
233 | 270 | ||
234 | 271 | ||
235 | //update seller order | 272 | //update seller order |
236 | SellerOrderStatus targetSOStatus; | 273 | SellerOrderStatus targetSOStatus; |
237 | targetSOStatus = SellerOrderStatus.PLAY_BUYER; | 274 | targetSOStatus = SellerOrderStatus.PLAY_BUYER; |
238 | SellerOrder target = new SellerOrder(); | 275 | SellerOrder target = new SellerOrder(); |
239 | - target.setOrderCode(orderCode); | 276 | + target.setOrderCode(sellerOrderCode); |
240 | target.setUid(sellerUid); | 277 | target.setUid(sellerUid); |
241 | target.setStatus(targetSOStatus.getCode()); | 278 | target.setStatus(targetSOStatus.getCode()); |
242 | target.setUpdateTime(DateUtil.getCurrentTimeSecond()); | 279 | target.setUpdateTime(DateUtil.getCurrentTimeSecond()); |
@@ -249,20 +286,18 @@ public class SellerOrderCancelService { | @@ -249,20 +286,18 @@ public class SellerOrderCancelService { | ||
249 | return result; | 286 | return result; |
250 | } | 287 | } |
251 | 288 | ||
252 | - private int cancelAfterPayAction(SellerOrder sellerOrder){ | 289 | + private int cancelAfterPayAction(SellerOrder sellerOrder, BuyerOrder buyerOrder){ |
253 | 290 | ||
254 | final int sellerUid = sellerOrder.getUid(); | 291 | final int sellerUid = sellerOrder.getUid(); |
255 | final long orderCode = sellerOrder.getOrderCode(); | 292 | final long orderCode = sellerOrder.getOrderCode(); |
256 | logger.info("in seller cancel After Buy Action, uid {}, orderCode {}", | 293 | logger.info("in seller cancel After Buy Action, uid {}, orderCode {}", |
257 | sellerUid, orderCode); | 294 | sellerUid, orderCode); |
258 | int result = 0; | 295 | int result = 0; |
259 | - List<Integer> sellerCanCancelStatus; | ||
260 | - int buyOrderCnt; | 296 | + |
297 | + int buyOrderCnt = buyerOrder== null ? 0 : 1; | ||
298 | + | ||
261 | 299 | ||
262 | 300 | ||
263 | - //查询买家订单,状态是支付成功的 | ||
264 | - sellerCanCancelStatus = Arrays.asList(OrderStatus.HAS_PAYED.getCode()); | ||
265 | - buyOrderCnt = buyerOrderMapper.selectCntBySellerUidStatus(sellerUid, sellerCanCancelStatus); | ||
266 | if (buyOrderCnt == 0){ | 301 | if (buyOrderCnt == 0){ |
267 | /**case 2: 支付完成,没有买家下单 | 302 | /**case 2: 支付完成,没有买家下单 |
268 | * actions as blow: | 303 | * actions as blow: |
@@ -281,10 +316,15 @@ public class SellerOrderCancelService { | @@ -281,10 +316,15 @@ public class SellerOrderCancelService { | ||
281 | * 3. sellerOrderGoods | 316 | * 3. sellerOrderGoods |
282 | * 4. 瓜分保证金 | 317 | * 4. 瓜分保证金 |
283 | */ | 318 | */ |
284 | - result = cancelAfterPayExistBuyAction(sellerOrder, sellerCanCancelStatus, buyOrderCnt); | 319 | + //查询买家订单,状态是支付成功的 |
320 | + | ||
321 | + result = cancelAfterPayExistBuyAction(sellerOrder, buyerOrder); | ||
285 | return result; | 322 | return result; |
286 | } | 323 | } |
287 | 324 | ||
325 | + | ||
326 | + | ||
327 | + | ||
288 | /** | 328 | /** |
289 | * | 329 | * |
290 | * @param autoCancelCase | 330 | * @param autoCancelCase |
-
Please register or login to post a comment