Authored by sailing-PC\sailing

optimize code

... ... @@ -28,7 +28,30 @@ public enum ButtonShow {
bo = new ButtonShowBo(name(), code, value);
}
ButtonShow(String code,String value, String confirmTips) {
this.code = code;
this.value = value;
bo = new ButtonShowBo(name(), code, value, confirmTips);
}
public ButtonShowBo getBo() {
return bo;
}
public ButtonShowBo getBo(CancelType cancelType) {
switch (cancelType){
case SELF_BEFORE_PAY:
bo.setConfirmTips("您确定不卖此商品吗?");
break;
case PLAY_SELF:
bo.setConfirmTips("您确定不卖此商品么?取消后保证金将原路退换至您的支付宝账户");
break;
case PLAY_BUYER:
bo.setConfirmTips("您确定不卖此商品么?取消后保证金将作为赔偿金打入买家账户");
break;
}
return bo;
}
}
... ...
... ... @@ -19,7 +19,9 @@ public enum CancelType {
/**
* 买家下单后取消售卖
*/
PLAY_BUYER(SellerOrderStatus.PLAY_SELF),
PLAY_BUYER(SellerOrderStatus.PLAY_BUYER),
PLAY_SELF(SellerOrderStatus.PLAY_SELF),
/**
* yoho下架
*/
... ...
... ... @@ -38,7 +38,7 @@ public enum OrderStatus {
"待发货",
Arrays.asList(ButtonShow.NOT_SOLD, ButtonShow.DELIVER_GOODS),
Arrays.asList(ButtonShow.NOT_SOLD, ButtonShow.DELIVER_GOODS),
OrderDetailDesc.Seller.BUYER_HAS_PAID
OrderDetailDesc.Seller.BUYER_HAS_PAID, CancelType.PLAY_BUYER
)
}),
... ... @@ -265,6 +265,7 @@ public enum OrderStatus {
*/
String detailDesc;
public Node(String statusStr,
List<ButtonShow> listButtons,
List<ButtonShow> detailButtons,
... ... @@ -278,5 +279,19 @@ public enum OrderStatus {
};
this.detailDesc = detailDesc;
}
public Node(String statusStr,
List<ButtonShow> listButtons,
List<ButtonShow> detailButtons,
String detailDesc, CancelType cancelType) {
this.statusStr = statusStr;
if (listButtons != null && !listButtons.isEmpty()){
this.listButtons = listButtons.parallelStream().map(buttonShow -> buttonShow.getBo(cancelType)).collect(Collectors.toList());
}
if (detailButtons !=null && !detailButtons.isEmpty()){
this.detailButtons = detailButtons.parallelStream().map(buttonShow -> buttonShow.getBo(cancelType)).collect(Collectors.toList());
};
this.detailDesc = detailDesc;
}
}
}
... ...
... ... @@ -18,8 +18,8 @@ public enum SkupStatus {
*/
CAN_SELL(1, "出售中",
new Node(
Arrays.asList(ButtonShow.NOT_SOLD.getBo(), ButtonShow.SHOW_DETAIL.getBo()),
Arrays.asList(ButtonShow.NOT_SOLD.getBo()),
Arrays.asList(ButtonShow.NOT_SOLD.getBo(CancelType.PLAY_SELF), ButtonShow.SHOW_DETAIL.getBo()),
Arrays.asList(ButtonShow.NOT_SOLD.getBo(CancelType.PLAY_SELF)),
OrderDetailDesc.Seller.PAY_FINISH,
OrderDetailDesc.PaymentTips.AUTO_RETURN_SELLER
)
... ... @@ -29,8 +29,8 @@ public enum SkupStatus {
*/
CAN_NOT_SELL(0,"待付保证金",
new Node(
Arrays.asList(ButtonShow.NOT_SOLD.getBo(), ButtonShow.PAY_EARNESTMONEY.getBo()),
Arrays.asList(ButtonShow.NOT_SOLD.getBo(), ButtonShow.PAY_EARNESTMONEY.getBo()),
Arrays.asList(ButtonShow.NOT_SOLD.getBo(CancelType.SELF_BEFORE_PAY), ButtonShow.PAY_EARNESTMONEY.getBo()),
Arrays.asList(ButtonShow.NOT_SOLD.getBo(CancelType.SELF_BEFORE_PAY), ButtonShow.PAY_EARNESTMONEY.getBo()),
OrderDetailDesc.Seller.WAIT_PAY,
OrderDetailDesc.PaymentTips.AUTO_RETURN_SELLER
)
... ...
... ... @@ -16,5 +16,12 @@ public class ButtonShowBo {
String code;
String text;
String confirmTips;
public ButtonShowBo(String name, String code, String text) {
this.name = name;
this.code = code;
this.text = text;
}
}
... ...
... ... @@ -8,6 +8,8 @@ import com.yohobuy.ufo.model.order.req.SellerOrderCancelReq;
import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.utils.AddressUtil;
import com.yohoufo.common.utils.DateUtil;
... ... @@ -176,7 +178,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
//step 2: generate skup ,action :set price status(unsaleable)
if (Objects.isNull(goodsInfo)){
log.warn("in computePublishPrd storageId not exist in prd , uid {}, storageId {}", uid, storageId);
throw new GatewayException(400, "商品不存在");
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
}
context.setSoldProduct(goodsInfo);
checkPrice(storageId, goodsInfo.getPrice(), true);
... ... @@ -191,18 +193,26 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
long orderCode = orderCodeGenerator.generate(OrderCodeType.SELLER_TYPE);
if (orderCode <= 0L){
log.warn("in publishPrd storageId not exist in prd , uid {}, storageId {}", uid, storageId);
throw new GatewayException(501, "保证金订单生成失败");
throw new ServiceException(ServiceError.EARNESTMONEY_ORDER_CREATE_FAIL);
}
context.setOrderCode(orderCode);
//submit all as atomic operation, use transaction of DB
//all include : 1. skup, 2. order , 3. 寄回地址
orderSubmitHandler.submit(context);
try{
orderSubmitHandler.submit(context);
}catch (Exception ex){
String content = "用户"+ uid + "发布商品"+storageId + "失败";
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("sellerOrder.create", "create", content);
EventBusPublisher.publishEvent(smsAlarmEvent);
log.warn("in publishPrd create order fail , uid {}, storageId {}", uid, storageId);
throw new ServiceException(ServiceError.EARNESTMONEY_ORDER_CREATE_FAIL);
}
boolean syncPrdFlag = productProxyService.syncSkup(context.getSellerOrderGoods(), SkupStatus.CAN_NOT_SELL);
log.info("publish finish, syncPrdFlag {}, req {}, orderCode {}", syncPrdFlag, req, orderCode);
//发布支付超时取消消息
pushAutoCancelEvent(context);
//TODO 发消息
// 发消息
OrderSubmitResp resp = OrderSubmitResp.builder().orderCode(orderCode).productId(goodsInfo.getProductId()).build();
return resp;
}
... ...