Authored by chenchao

continue implement

package com.yohoufo.order.controller;
import com.google.common.collect.Lists;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.model.response.OrderSummaryResp;
import com.yohoufo.order.service.IBuyerOrderService;
import com.yohoufo.order.service.IShoppingService;
import com.yohoufo.order.service.impl.SellerOrderViewService;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class OrderStatisticController {
private Logger logger = LoggerUtils.getBuyerOrderLogger();
@Autowired
private SellerOrderViewService sellerOrderViewService;
@Autowired
private IBuyerOrderService ibuyerOrderService;
/**
* 我的出售记录数,买入记录数
* 准备逐步弃用 from version 6.9.12
* @return
*/
@Deprecated
@RequestMapping(value = "/shopping", params = "method=ufo.order.summary")
public ApiResponse summary(@RequestParam(name = "uid") int uid,
@RequestParam(name = "client_type", required = false) String clientType){
logger.info("in ufo.order.summary, uid {}, clientType is {}", uid, clientType);
OrderSummaryResp orderSummaryResp1 = sellerOrderViewService.selectOrderNumByUid(uid);
OrderSummaryResp orderSummaryResp2 = ibuyerOrderService.selectOrderNumByUid(uid);
return new ApiResponse.ApiResponseBuilder().code(200).data(Lists.newArrayList(orderSummaryResp1, orderSummaryResp2)).message("查询成功").build();
}
@RequestMapping(params = "method=ufo.seller.orderSummary")
public ApiResponse sellerOrderSummary(@RequestParam(name = "uid") int uid,
@RequestParam(name = "client_type", required = false) String clientType){
logger.info("in ufo.seller.orderSummary, uid {}, clientType is {}", uid, clientType);
List<OrderSummaryResp> orderSummaryResps = sellerOrderViewService.getOrderCntListByUid(uid);
return new ApiResponse.ApiResponseBuilder().code(200).data(orderSummaryResps).message("查询成功").build();
}
}
... ...
package com.yohoufo.order.controller;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.constants.ActivityTypeEnum;
import com.yohoufo.order.annotation.BlackUserType;
import com.yohoufo.order.common.BlackTypeEnum;
import com.yohoufo.order.constants.ActivityTypeEnum;
import com.yohoufo.order.constants.CouponConstants;
import com.yohoufo.order.model.request.ShoppingRequest;
import com.yohoufo.order.model.response.*;
import com.yohoufo.order.service.IBuyerOrderService;
import com.yohoufo.order.service.IShoppingService;
import com.yohoufo.order.service.impl.SellerOrderViewService;
import com.yohoufo.order.utils.CouponCodeUtils;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/shopping")
... ... @@ -27,15 +26,7 @@ public class ShoppingController {
private Logger logger = LoggerUtils.getBuyerOrderLogger();
@Autowired
IShoppingService buyerOrderService;
@Autowired
private SellerOrderViewService sellerOrderViewService;
@Autowired
IBuyerOrderService ibuyerOrderService;
private IShoppingService buyerOrderService;
/**
* 结算
... ... @@ -170,22 +161,7 @@ public class ShoppingController {
return new ApiResponse.ApiResponseBuilder().code(200).data(submitResponse).message("提交订单SUCCESS").build();
}
/**
* 我的出售记录数,买入记录数
* @return
*/
@RequestMapping(params = "method=ufo.order.summary")
public ApiResponse summary(@RequestParam(name = "uid") int uid,
@RequestParam(name = "client_type", required = false) String clientType){
logger.info("in ufo.order.summary, uid {}, clientType is {}", uid, clientType);
OrderSummaryResp orderSummaryResp1 = sellerOrderViewService.selectOrderNumByUid(uid);
OrderSummaryResp orderSummaryResp2 = ibuyerOrderService.selectOrderNumByUid(uid);
return new ApiResponse.ApiResponseBuilder().code(200).data(Lists.newArrayList(orderSummaryResp1, orderSummaryResp2)).message("查询成功").build();
}
/**
... ...
package com.yohoufo.order.model.response;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Created by li.ma on 2018/9/27.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OrderSummaryResp {
@JSONField(name = "actor")
private String actor;
private Integer listType;
@JSONField(name = "sum")
private Integer sum;
public OrderSummaryResp() {
}
public OrderSummaryResp(String actor, Integer sum) {
this.actor = actor;
this.sum = sum;
}
public String getActor() {
return actor;
}
public void setActor(String actor) {
this.actor = actor;
}
public Integer getSum() {
return sum;
}
public void setSum(Integer sum) {
this.sum = sum;
}
}
... ...
... ... @@ -43,6 +43,7 @@ public class BuyerOrderAssistant {
@Data
public static class DepositSkuCheckNode{
private String depositCode;
private StorageDeposit psd;
private boolean existDepositGoods;
}
... ... @@ -77,6 +78,7 @@ public class BuyerOrderAssistant {
dsNode.setPsd(psd);
}
dsNode.setExistDepositGoods(existDepositGoods);
dsNode.setDepositCode(depositCode);
return dsNode;
}
... ... @@ -85,4 +87,7 @@ public class BuyerOrderAssistant {
Integer pboa = pbo.getAttributes();
return BuyerOrderUtils.isInstockDeposit(skupType, pboa);
}
}
... ...
... ... @@ -3,6 +3,7 @@ package com.yohoufo.order.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Joiner;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.yoho.core.common.helpers.ImagesHelper;
import com.yoho.core.rabbitmq.YhProducer;
... ... @@ -31,7 +32,6 @@ import com.yohoufo.common.utils.UserInfoHiddenHelper;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.ExpressForMqSend;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.constants.SellerConfig;
import com.yohoufo.order.event.BuyerOrderSellerDeliveryCheckEvent;
import com.yohoufo.order.event.ErpBuyerOrderEvent;
... ... @@ -171,6 +171,9 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
@Autowired
private SkupService skupService;
@Autowired
private ProductProxyService productProxyService;
/**
* 这个方法请尽量保持单一原则
... ... @@ -303,22 +306,27 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
if(existDepositGoods){
//set depot num
depotNum = DepotType.NJ.getCode();
//bind deposit code 2 buyer order
buyerOrderMetaService.saveDepositCode(depositCode, buyerUid, orderCode);
//生成内部使用的物流单号
wayBillCode = new StringBuilder()
.append(orderCode)
.append("_")
.append(depositCode).toString();
//TODO skup 下架
StorageDeposit psd = dscNode.getPsd();
//TODO 寄存商品 出库准备
}
//香港卖家不能售卖现货 在业务规则上天然互斥
if (isHKLargeSettlementSuper(sellerUid)) {
depotNum = DepotType.HK.getCode();
}
updateOrderCnt = processBuyerOrder(preparedData, expressCompanyId, expressType, wayBillCode, depotNum);
if (updateOrderCnt>0){
try {
processOrderDeliverByDepositGoods(preparedData, dscNode);
}catch (Exception ex){
LOGGER.warn("deliverToDepot processOrderDeliverByDepositGoods fail ,req {} error {}",
req, Throwables.getStackTraceAsString(ex));
}
}
break;
case GOODS_SERVICE:
... ... @@ -364,6 +372,31 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
LOGGER.info("deliverToDepot update buyer order status, orderCode {} result {} ", orderCode, updateOrderCnt);
}
private void processOrderDeliverByDepositGoods(BuyerOrderAssistant.PreparedData preparedData,
BuyerOrderAssistant.DepositSkuCheckNode dscNode){
if (!dscNode.isExistDepositGoods()){
return;
}
BuyerOrder buyerOrder = preparedData.getBuyerOrder();
Integer buyerUid = buyerOrder.getUid();
Long orderCode = buyerOrder.getOrderCode();
String depositCode = dscNode.getDepositCode();
//bind deposit code 2 buyer order
buyerOrderMetaService.saveDepositCode(depositCode, buyerUid, orderCode);
//TODO skup 下架
StorageDeposit psd = dscNode.getPsd();
Integer skup;
Integer productId;
if (Objects.nonNull(skup = psd.getNewSkup())){
// 减库存
productProxyService.subtractStorage(productId=psd.getProductId(), skup);
//
skupService.saleOut(skup);
}
//TODO 寄存商品 出库准备
}
@Override
public void returnBackCauseOfBuyerCancelAfterSellerSendOut(Integer sellerUid, Integer expressCompanyId, Long orderCode, String wayBillCode, Integer depotNum, String sellerMobile, boolean unSureFlag) {
Integer expressType = EnumExpressType.EXPRESS_TYPE_REBACK.getCode();
... ...
... ... @@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
... ... @@ -108,7 +109,7 @@ public class SellerOrderViewService {
if (cnt == null) {
//todo add cache
Integer num = sellerOrderGoodsMapper.selectCntByUidStatusList(uid, Arrays.asList(SkupStatus.CAN_SELL.getCode()));
List<SellerOrderListType> types = Arrays.asList(SellerOrderListType.WAITING_SEND, SellerOrderListType.WAITING_PAY);
List<SellerOrderListType> types = Arrays.asList(SellerOrderListType.SEND_OUT, SellerOrderListType.WAITING_PAY);
List<Integer> statusList = types.parallelStream().flatMap(solt -> solt.getStatus().parallelStream()).collect(Collectors.toList());
Integer buyerOrderNum = buyerOrderMapper.selectCntBySellerUid(uid, statusList);
logger.info("in seller order count uid {}, num {}, buyerOrderNum {}", uid, num, buyerOrderNum);
... ... @@ -129,6 +130,34 @@ public class SellerOrderViewService {
return new OrderSummaryResp("sell", cnt);
}
public List<OrderSummaryResp> getOrderCntListByUid(int uid) {
List<OrderSummaryResp> list = new ArrayList<>(8);
final String actor = TabType.SELL.getValue();
SellerOrderListType insale = SellerOrderListType.IN_SALE;
//TODO add cache
int num = sellerOrderGoodsMapper.selectCntByUidStatusList(uid, Arrays.asList(SkupStatus.CAN_SELL.getCode()));
OrderSummaryResp sellerGoodsSummary = new OrderSummaryResp(actor, insale.getType(), num);
list.add(sellerGoodsSummary);
//
List<SellerOrderListType> types = Arrays.asList(SellerOrderListType.WAITING_PAY,
SellerOrderListType.SEND_OUT,
SellerOrderListType.ORDER_SUCCESS,
SellerOrderListType.ORDER_FAILED);
for(SellerOrderListType solt : types) {
List<Integer> statusList = solt.getStatus();
int buyerOrderNum = buyerOrderMapper.selectCntBySellerUid(uid, statusList);
logger.info("in seller order count uid {}, num {}, buyerOrderNum {}", uid, num, buyerOrderNum);
//
OrderSummaryResp osResp = new OrderSummaryResp();
osResp.setActor(actor);
osResp.setSum(buyerOrderNum);
osResp.setListType(solt.getType());
list.add(osResp);
}
return list;
}
public OrderCntResp getOrderCnt(OrderRequest orderRequest, SellerOrderListType listType){
logger.info("in seller getOrderCnt req {} listType {}", orderRequest, listType);
int cnt ;
... ...
... ... @@ -22,6 +22,7 @@ import com.yohoufo.order.model.dto.BuyerOrderSubmitResult;
import com.yohoufo.order.model.dto.OrderBuilder;
import com.yohoufo.order.service.ISubmitOrderService;
import com.yohoufo.order.service.proxy.*;
import com.yohoufo.order.service.seller.SkupService;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
... ... @@ -153,6 +154,9 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
@Autowired
private OrderStatusFlowService orderStatusFlowService;
@Autowired
private SkupService skupService;
/**
* 创建订单
* @param orderBuilder
... ... @@ -339,11 +343,7 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
private int updSellerOrderGoods(OrderBuilder orderBuilder) {
int skup;
int uid = orderBuilder.getUid();
SellerOrderGoods condition = new SellerOrderGoods();
condition.setId(skup = orderBuilder.getSkup());
condition.setExceptStatus(SkupStatus.CAN_SELL.getCode());
condition.setStatus(SkupStatus.SELL_OUT.getCode());
int num = sellerOrderGoodsMapper.updateStatusBySkpu(condition);
int num = skupService.saleOut(skup= orderBuilder.getSkup());
if (num == 0 ){
logger.warn("in buyer create order fail on update skup status , uid {} skup {}", uid, skup);
throw new ServiceException(ServiceError.ORDER_SKUP_CANNOT_SELL);
... ...
package com.yohoufo.order.service.seller;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.GoodsSize;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.common.SkupStatus;
... ... @@ -9,6 +11,7 @@ import com.yohobuy.ufo.model.response.StorageDataResp;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.convert.GoodsInfoConvertor;
import com.yohoufo.order.model.dto.OrderBuilder;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.seller.support.SkupTypeCodeSupport;
import com.yohoufo.order.utils.LoggerUtils;
... ... @@ -139,4 +142,15 @@ public class SkupService {
productProxyService.setDepotNum(skup,depotNum);
return result;
}
@Transactional(propagation = Propagation.REQUIRED)
@Database(ForceMaster=true, DataSource="ufo_order")
public int saleOut(int skup) {
SellerOrderGoods condition = new SellerOrderGoods();
condition.setId(skup);
condition.setExceptStatus(SkupStatus.CAN_SELL.getCode());
condition.setStatus(SkupStatus.SELL_OUT.getCode());
int num = sellerOrderGoodsMapper.updateStatusBySkpu(condition);
return num;
}
}
... ...