Authored by sailing-PC\sailing

update

... ... @@ -3,6 +3,7 @@ package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.BuyerOrder;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
... ... @@ -36,4 +37,8 @@ public interface BuyerOrderMapper {
@Param("offset")Integer offset, @Param("limit")Integer limit);
int updateByPrimaryKey(BuyerOrder record);
int updateBatchByOrderCodes(@Param("orderCodes")Collection<Long> orderCodes,@Param("status")Integer status,
@Param("updateTime")Integer updateTime);
}
\ No newline at end of file
... ...
... ... @@ -19,7 +19,8 @@ public class SellerOrder {
private BigDecimal earnestMoney;
private Integer isCancel;
private Integer isDel;
private Integer status;
... ... @@ -91,13 +92,6 @@ public class SellerOrder {
this.earnestMoney = earnestMoney;
}
public Integer getIsCancel() {
return isCancel;
}
public void setIsCancel(Integer isCancel) {
this.isCancel = isCancel;
}
public Integer getStatus() {
return status;
... ... @@ -122,4 +116,12 @@ public class SellerOrder {
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
public Integer getIsDel() {
return isDel;
}
public void setIsDel(Integer isDel) {
this.isDel = isDel;
}
}
\ No newline at end of file
... ...
... ... @@ -289,6 +289,17 @@
</update>
<update id="updateBatchByOrderCodes" parameterType="com.yohoufo.dal.order.model.BuyerOrder">
update buyer_order
set
status = #{status,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER}
where order_code IN
<foreach collection="orderCodes" item="orderCode" open="(" separator="," close=")">
#{orderCode,jdbcType=BIGINT}
</foreach>
</update>
<sql id="sql_where_4_select_SellerUidStatus">
seller_uid = #{sellerUid,jdbcType=INTEGER}
and seller_order_status = 1
... ...
... ... @@ -10,13 +10,13 @@
<result column="payment" jdbcType="TINYINT" property="payment" />
<result column="income" jdbcType="DECIMAL" property="income" />
<result column="earnest_money" jdbcType="DECIMAL" property="earnestMoney" />
<result column="is_cancel" jdbcType="TINYINT" property="isCancel" />
<result column="is_del" jdbcType="TINYINT" property="isDel" />
<result column="status" jdbcType="TINYINT" property="status" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
<result column="update_time" jdbcType="INTEGER" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
id, order_code, skup, uid, client_type, payment, income, earnest_money, is_cancel,
id, order_code, skup, uid, client_type, payment, income, earnest_money, is_del,
status, create_time, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
... ... @@ -72,11 +72,11 @@
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SellerOrder" useGeneratedKeys="true">
insert into seller_order (order_code, skup, uid,
client_type, payment, income,
earnest_money, is_cancel, status,
earnest_money, is_del, status,
create_time, update_time)
values (#{orderCode,jdbcType=BIGINT}, #{skup,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER},
#{clientType,jdbcType=TINYINT}, #{payment,jdbcType=TINYINT}, #{income,jdbcType=DECIMAL},
#{earnestMoney,jdbcType=DECIMAL}, #{isCancel,jdbcType=TINYINT}, #{status,jdbcType=TINYINT},
#{earnestMoney,jdbcType=DECIMAL}, #{isDel,jdbcType=TINYINT}, #{status,jdbcType=TINYINT},
#{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SellerOrder" useGeneratedKeys="true">
... ... @@ -103,8 +103,8 @@
<if test="earnestMoney != null">
earnest_money,
</if>
<if test="isCancel != null">
is_cancel,
<if test="isDel != null">
is_del,
</if>
<if test="status != null">
status,
... ... @@ -138,8 +138,8 @@
<if test="earnestMoney != null">
#{earnestMoney,jdbcType=DECIMAL},
</if>
<if test="isCancel != null">
#{isCancel,jdbcType=TINYINT},
<if test="isDel != null">
#{isDel,jdbcType=TINYINT},
</if>
<if test="status != null">
#{status,jdbcType=TINYINT},
... ... @@ -176,8 +176,8 @@
<if test="earnestMoney != null">
earnest_money = #{earnestMoney,jdbcType=DECIMAL},
</if>
<if test="isCancel != null">
is_cancel = #{isCancel,jdbcType=TINYINT},
<if test="isDel != null">
is_del = #{isDel,jdbcType=TINYINT},
</if>
<if test="status != null">
status = #{status,jdbcType=TINYINT},
... ... @@ -200,7 +200,7 @@
payment = #{payment,jdbcType=TINYINT},
income = #{income,jdbcType=DECIMAL},
earnest_money = #{earnestMoney,jdbcType=DECIMAL},
is_cancel = #{isCancel,jdbcType=TINYINT},
is_del = #{isDel,jdbcType=TINYINT},
status = #{status,jdbcType=TINYINT},
create_time = #{createTime,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER}
... ...
package com.yohoufo.order.common;
/**
* Created by chenchao on 2018/9/25.
*/
public enum DelStatus {
NOT_DEL(0),
IS_DEL(1);
private int code;
DelStatus(int code){
this.code = code;
}
public int getCode() {
return code;
}
}
... ...
... ... @@ -75,8 +75,7 @@ public class SellerOrderController {
}
@Autowired
private SellerOrderCancelService sellerOrderCancelService;
@RequestMapping(params = "method=ufo.sellerOrder.cancel")
... ... @@ -89,7 +88,25 @@ public class SellerOrderController {
.orderCode(orderCode)
.build();
logger.info("in ufo.sellerOrder.cancel, req {}", req);
boolean result = sellerOrderCancelService.cancel(req);
boolean result = sellerOrderService.cancel(req);
String msg = "取消成功";
if(!result){
msg = "取消失败";
}
return new ApiResponse.ApiResponseBuilder().data(result).code(200).message(msg).build();
}
@RequestMapping(params = "method=ufo.sellerOrder.delete")
@ResponseBody
public ApiResponse delete(@RequestParam(name = "uid", required = true)int uid,
@RequestParam(name = "order_code", required = true)long orderCode
) throws GatewayException {
SellerOrderCancelReq req = SellerOrderCancelReq.builder()
.uid(uid)
.orderCode(orderCode)
.build();
logger.info("in ufo.sellerOrder.cancel, req {}", req);
boolean result = sellerOrderService.delete(req);
String msg = "取消成功";
if(!result){
msg = "取消失败";
... ...
... ... @@ -6,13 +6,16 @@ import com.yohobuy.ufo.model.order.req.SellerOrderCancelReq;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.order.common.CancelType;
import com.yohoufo.order.common.OrderStatus;
import com.yohoufo.order.common.SellerOrderStatus;
import com.yohoufo.order.event.OrderCancelEvent;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.mq.TopicConstants;
import com.yohoufo.order.mq.producer.TradeMqSender;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.impl.visitor.AutoCancelCase;
import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase;
import com.yohoufo.order.service.impl.visitor.UserCancelCase;
... ... @@ -25,6 +28,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* Created by chenchao on 2018/9/17.
... ... @@ -43,18 +47,10 @@ public class SellerOrderCancelService {
@Autowired
private TradeMqSender tradeMqSender;
public boolean cancel(SellerOrderCancelReq req){
logger.info("seller self cancel order,req {}", req);
int uid = req.getUid();
long orderCode = req.getOrderCode();
@Autowired
private IPaymentService paymentService;
if (uid <= 0 || orderCode <= 0L){
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
int result = doCancel(uid, orderCode);
return result > 0;
}
public void cancel(UserCancelCase cancelCase){
logger.info("in cancel UserCancelCase {}", cancelCase);
... ... @@ -64,10 +60,8 @@ public class SellerOrderCancelService {
//未支付时
//支付完成,没有买家下单
//支付完成,有买家下单
doCancel(uid, orderCode);
}
... ... @@ -80,34 +74,94 @@ public class SellerOrderCancelService {
if (Objects.isNull(status)){
return result;
}
Integer targetStatus = null;
//target seller Order Status
Integer targetSOStatus;
//未支付时
if (SellerOrderStatus.WAITING_PAY.getCode() == status){
targetStatus = SellerOrderStatus.SELf_CANCEL_PAY.getCode();
targetSOStatus = SellerOrderStatus.SELf_CANCEL_PAY.getCode();
doCancelBeforeBuyAction(uid, orderCode, targetSOStatus);
}
if (SellerOrderStatus.HAS_PAYED.getCode() == status){
List<Integer> sellerCanCancelStatus = Arrays.asList(OrderStatus.HAS_PAYED.getCode());
buyerOrderMapper.selectCntBySellerUidStatus(uid, sellerCanCancelStatus);
targetStatus = SellerOrderStatus.SELf_CANCEL_PAY.getCode();
if (SellerOrderStatus.HAS_PAYED.getCode() == status){
doCancelAfterBuyAction(uid, orderCode);
}
if (Objects.nonNull(targetStatus)){
SellerOrder target = new SellerOrder();
target.setOrderCode(orderCode);
target.setUid(uid);
target.setStatus(targetStatus);
return result;
}
private int doCancelBeforeBuyAction(int uid, long orderCode, Integer targetSOStatus){
SellerOrder target = new SellerOrder();
target.setOrderCode(orderCode);
target.setUid(uid);
target.setStatus(targetSOStatus);
return doCancelBeforeBuyAction(target);
}
private int doCancelBeforeBuyAction(SellerOrder target){
int result = 0;
int uid = target.getUid();
long orderCode = target.getOrderCode();
Integer targetSOStatus = target.getStatus();
//update seller order
if (Objects.nonNull(targetSOStatus)){
target.setUpdateTime(DateUtil.getCurrentTimeSecond());
result = sellerOrderMapper.updateByOrderCode(target);
result += sellerOrderMapper.updateByOrderCode(target);
//refund earnestMoney
double earnestMoney = target.getEarnestMoney().doubleValue();
PaymentRequest refundReq = PaymentRequest.builder().uid(uid).orderCode(orderCode)
.refundAmount(earnestMoney).build();
paymentService.refund(refundReq);
}
return result;
}
private int doCancelAfterBuyAction(int sellerUid, long orderCode){
int result = 0;
List<Integer> sellerCanCancelStatus;
int canCancelCnt = 0;
//target Buyer Order Status
Integer targetBOStatus;
//查询买家订单,状态是支付成功的
sellerCanCancelStatus = Arrays.asList(OrderStatus.HAS_PAYED.getCode());
canCancelCnt = buyerOrderMapper.selectCntBySellerUidStatus(sellerUid, sellerCanCancelStatus);
Integer targetSOStatus = SellerOrderStatus.SELF_CANCEL_COMPENSATE.getCode();
if (canCancelCnt == 0){
//支付完成,没有买家下单
result = doCancelBeforeBuyAction(sellerUid, orderCode, targetSOStatus);
return result;
}
targetBOStatus = OrderStatus.SELLER_CANCEL_AFTER_PAY.getCode();
List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListBySellerUidStatus(sellerUid, sellerCanCancelStatus, 0, canCancelCnt);
List<Long> orderCodes = buyerOrderList.parallelStream().map(BuyerOrder::getOrderCode).collect(Collectors.toList());
if (orderCodes.size() > 1){
throw new ServiceException(ServiceError.ERP_ORDER_CANCEL_FAILED);
}
//actions of buyer order and related
//update buyer Order
result += buyerOrderMapper.updateBatchByOrderCodes(orderCodes, targetBOStatus, DateUtil.getCurrentTimeSecond());
//TODO 分赃(分账)
SellerOrder target = new SellerOrder();
target.setOrderCode(orderCode);
target.setUid(sellerUid);
target.setStatus(targetSOStatus);
target.setUpdateTime(DateUtil.getCurrentTimeSecond());
result += sellerOrderMapper.updateByOrderCode(target);
//TODO sync skup
return result;
}
public void cancel(AutoCancelCase autoCancelCase){
logger.info("in cancel autoCancelCase {}", autoCancelCase);
OrderCancelEvent event = autoCancelCase.getOrderCancelEvent();
... ...
... ... @@ -4,6 +4,7 @@ import com.yoho.core.dal.datasource.annotation.Database;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.order.common.DelStatus;
import com.yohoufo.order.common.SellerOrderStatus;
import com.yohoufo.order.constants.SellerOrderCancelStatus;
import com.yohoufo.order.model.SellerOrderContext;
... ... @@ -29,7 +30,7 @@ public class SellerOrderCreateService {
condition.setOrderCode(context.getOrderCode());
condition.setUid(context.getUid());
condition.setSkup(context.getSoldProduct().getSkup());
condition.setIsCancel(SellerOrderCancelStatus.NO.getCode());
condition.setIsDel(DelStatus.NOT_DEL.getCode());
condition.setCreateTime(currentTiem);
condition.setStatus(SellerOrderStatus.WAITING_PAY.getCode());
condition.setEarnestMoney(context.getSellerOrderComputeResult().getEarnestMoney());
... ...
package com.yohoufo.order.service.impl;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.response.UserAddressRspBO;
import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
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.exception.GatewayException;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.order.common.CancelType;
import com.yohoufo.order.common.OrderCodeType;
import com.yohoufo.order.common.SkupStatus;
import com.yohoufo.order.common.TabType;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.order.common.*;
import com.yohoufo.order.convert.AddressInfoConvertor;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.event.EventHandlerContainer;
... ... @@ -27,9 +31,11 @@ import com.yohoufo.order.service.IOrderDetailService;
import com.yohoufo.order.service.IOrderListService;
import com.yohoufo.order.service.handler.SellerOrderComputeHandler;
import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
import com.yohoufo.order.service.impl.visitor.UserCancelCase;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.product.model.GoodsSize;
import com.yohoufo.product.response.StorageDataResp;
import lombok.extern.slf4j.Slf4j;
... ... @@ -51,7 +57,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
private SellerOrderMapper sellerOrderMapper;
@Autowired
private SellerOrderComputeHandler computeHandler;
... ... @@ -78,6 +83,14 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
private EventHandlerContainer eventHandlerContainer;
@Autowired
private SellerOrderCancelService sellerOrderCancelService;
@Autowired
private BuyerOrderMapper buyerOrderMapper;
public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException {
log.info("in computePublishPrd, req {}", req);
... ... @@ -175,6 +188,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
}
private GoodsInfo getProductDetail(SellerOrderContext context){
int uid = context.getUid();
int storageId = context.getStorageId();
... ... @@ -259,6 +273,73 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
}
public boolean cancel(SellerOrderCancelReq req){
log.info("seller self cancel order,req {}", req);
int uid = req.getUid();
long orderCode = req.getOrderCode();
if (uid <= 0 || orderCode <= 0L){
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
OrderCancelEvent event = OrderCancelEvent.builder().uid(uid)
.orderCode(orderCode).actorType(TabType.SELL).build();
UserCancelCase userCancelCase = new UserCancelCase(event);
userCancelCase.accept(sellerOrderCancelService);
return true;
}
public boolean delete(SellerOrderCancelReq req){
log.info("seller self cancel order,req {}", req);
int uid = req.getUid();
long orderCode = req.getOrderCode();
if (uid <= 0 || orderCode <= 0L){
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
//根据ordercode区分卖家 买家
CodeMeta codeMeta = orderCodeGenerator.expId(orderCode);
if (Objects.isNull(codeMeta)){
log.warn("seller delete orderCode illegal, req {}", req);
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
if(OrderCodeType.SELLER_TYPE.getType() == codeMeta.getType()){
SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid);
//todo 判断状态后更新
SellerOrder target = new SellerOrder();
target.setId(sellerOrder.getId());
target.setIsDel(DelStatus.IS_DEL.getCode());
target.setUpdateTime(DateUtil.getCurrentTimeSecond());
int row = sellerOrderMapper.updateByPrimaryKeySelective(target);
return row > 0;
}
if(OrderCodeType.BUYER_TYPE.getType() == codeMeta.getType()){
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
//todo 判断状态后更新
BuyerOrder target = new BuyerOrder();
target.setId(buyerOrder.getId());
target.setSellerOrderStatus(DelStatus.IS_DEL.getCode());
target.setUpdateTime(DateUtil.getCurrentTimeSecond());
buyerOrderMapper.updateByPrimaryKeySelective(target);
}
return true;
}
/**
* 查物流详情
* 只查卖家自己填的物流单
... ...
... ... @@ -8,10 +8,7 @@ import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.ClientType;
import com.yohoufo.order.common.OrderStatus;
import com.yohoufo.order.common.SellerOrderStatus;
import com.yohoufo.order.common.SkupStatus;
import com.yohoufo.order.common.*;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.model.dto.OrderBuilder;
import com.yohoufo.order.service.ISubmitOrderService;
... ... @@ -165,6 +162,7 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
buyerOrder.setCreateTime(now);
buyerOrder.setUpdateTime(now);
buyerOrder.setStatus(OrderStatus.WAITING_PAY.getCode());
buyerOrder.setBuyerOrderStatus(DelStatus.NOT_DEL.getCode());
buyerOrderMapper.insert(buyerOrder);
}
... ...
... ... @@ -38,17 +38,17 @@ public class SellerOrderCancelHandler implements IEventHandler<OrderCancelEvent>
switch (cancelType){
case SELF_BEFORE_PAY:
UserCancelCase ucCase = new UserCancelCase(event);
sellerOrderCancelService.cancel(ucCase);
ucCase.accept(sellerOrderCancelService);
break;
case TIME_OUT:
AutoCancelCase autoCancelCase = new AutoCancelCase(event);
sellerOrderCancelService.cancel(autoCancelCase);
autoCancelCase.accept(sellerOrderCancelService);
break;
case ERP_OFFSHELVE:
OffShelveCancelCase offShelveCancelCase = new OffShelveCancelCase(event);
sellerOrderCancelService.cancel(offShelveCancelCase);
offShelveCancelCase.accept(sellerOrderCancelService);
break;
}
... ...