Authored by sailing-PC\sailing

add some new

... ... @@ -47,7 +47,7 @@ public class UfoServiceCaller implements ApplicationListener<ContextRefreshedEve
* @param param 方法参数
* @return 返回值
*/
public Object call(String serviceMethod, Object... param) {
public <T> T call(String serviceMethod, Object... param) {
logger.info("call ufo service : {}", serviceMethod);
ServiceMethod sm = serviceMap.get(serviceMethod);
if (sm == null) {
... ... @@ -55,7 +55,7 @@ public class UfoServiceCaller implements ApplicationListener<ContextRefreshedEve
}
try {
return sm.call(param);
return (T)sm.call(param);
} catch (Exception e) {
logger.error("service error : " + serviceMethod, e);
return null;
... ...
... ... @@ -11,17 +11,17 @@ public class SellerOrder {
private Integer uid;
private Byte clientType;
private Integer clientType;
private Byte payment;
private Integer payment;
private BigDecimal income;
private BigDecimal earnestMoney;
private Byte isCancel;
private Integer isCancel;
private Byte status;
private Integer status;
private Integer createTime;
... ... @@ -59,19 +59,19 @@ public class SellerOrder {
this.uid = uid;
}
public Byte getClientType() {
public Integer getClientType() {
return clientType;
}
public void setClientType(Byte clientType) {
public void setClientType(Integer clientType) {
this.clientType = clientType;
}
public Byte getPayment() {
public Integer getPayment() {
return payment;
}
public void setPayment(Byte payment) {
public void setPayment(Integer payment) {
this.payment = payment;
}
... ... @@ -91,19 +91,19 @@ public class SellerOrder {
this.earnestMoney = earnestMoney;
}
public Byte getIsCancel() {
public Integer getIsCancel() {
return isCancel;
}
public void setIsCancel(Byte isCancel) {
public void setIsCancel(Integer isCancel) {
this.isCancel = isCancel;
}
public Byte getStatus() {
public Integer getStatus() {
return status;
}
public void setStatus(Byte status) {
public void setStatus(Integer status) {
this.status = status;
}
... ...
... ... @@ -19,13 +19,13 @@ public class SellerOrderGoods {
private Integer goodsId;
private Short colorId;
private Integer colorId;
private String colorName;
private BigDecimal goodsPrice;
private Byte status;
private Integer status;
private String imageUrl;
... ... @@ -103,11 +103,11 @@ public class SellerOrderGoods {
this.goodsId = goodsId;
}
public Short getColorId() {
public Integer getColorId() {
return colorId;
}
public void setColorId(Short colorId) {
public void setColorId(Integer colorId) {
this.colorId = colorId;
}
... ... @@ -127,11 +127,11 @@ public class SellerOrderGoods {
this.goodsPrice = goodsPrice;
}
public Byte getStatus() {
public Integer getStatus() {
return status;
}
public void setStatus(Byte status) {
public void setStatus(Integer status) {
this.status = status;
}
}
\ No newline at end of file
... ...
package com.yohoufo.order.constants;
/**
* Created by chenchao on 2018/9/17.
*/
public enum SkupStatus {
NOT_AVAILABLE(0,"不可售"), AVAILABLE(1, "可售");
private int code;
private String desc;
SkupStatus(int code,String desc){
this.code = code;
this.desc = desc;
}
public int getCode() {
return code;
}
public String getDesc() {
return desc;
}
}
... ...
... ... @@ -5,6 +5,7 @@ import com.yoho.core.rest.client.hystrix.AsyncFuture;
import com.yohobuy.ufo.model.order.bo.PlatformFee;
import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.http.URLHolder;
import com.yohoufo.common.utils.BigDecimalHelper;
... ... @@ -14,6 +15,7 @@ import com.yohoufo.order.model.dto.PlatformFeeDto;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.service.handler.SellerOrderComputeHandler;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.product.response.StorageDataResp;
import com.yohoufo.product.response.StorageLeastPriceResp;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
... ... @@ -38,22 +40,32 @@ public class SellerOrderService {
private ServiceCaller serviceCaller;
@Autowired
private UfoServiceCaller ufoServiceCaller;
@Autowired
private URLHolder urlHolder;
@Autowired
private SellerOrderComputeHandler computeHandler;
@Autowired
private OrderCodeGenerator orderCodeGenerator;
@Autowired
private SkupService skupService;
public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException {
log.info("in computePublishPrd, req {}", req);
//
String baseUrl = urlHolder.getUrl();
String apiParam = "?method=ufo.product.storage.leastprice";
String fullUrl = baseUrl + apiParam;
Object params = new Object();
AsyncFuture<StorageLeastPriceResp.StorageLeastPrice> future = serviceCaller.post("product.getFloorPrice", fullUrl, params,
StorageLeastPriceResp.StorageLeastPrice.class, null);
StorageLeastPriceResp.StorageLeastPrice resp = future.get();
Integer storageId = req.getStorageId();
if (storageId <=0 ){
log.warn("in computePublishPrd storageId illegal , req {}", req);
throw new GatewayException(400, "storageId 错误");
}
StorageLeastPriceResp.StorageLeastPrice resp = ufoServiceCaller.call("ufo.product.storage.leastprice", storageId);
BigDecimal leastPrice;
if (Objects.isNull(resp) || Objects.isNull(leastPrice = resp.getLeastPrice()) || leastPrice.doubleValue() == 0D){
throw new GatewayException(501, "暂无商品");
... ... @@ -84,20 +96,27 @@ public class SellerOrderService {
return buildSoldPrdComputeBo(prdPrice);
}
public Long publishPrd(SellerOrderComputeReq req){
//TODO step 1: rpc get product detail by storage id
public Long publishPrd(SellerOrderComputeReq req) throws GatewayException {
Integer storageId = req.getStorageId();
if (storageId <=0 ){
log.warn("in computePublishPrd storageId illegal , req {}", req);
throw new GatewayException(400, "storageId 错误");
}
//step 1: rpc get product detail by storage id
//ufo.product.storage.data
StorageDataResp prdResp = ufoServiceCaller.call("ufo.product.storage.data", storageId);
StorageDataResp.StorageData storageData = prdResp.getProduct_info();
//getProductDetail()
//TODO step 2: generate skup ,action :set price status(unsaleable)
//createSkup()
//step 2: generate skup ,action :set price status(unsaleable)
if (Objects.isNull(storageData)){
log.warn("in computePublishPrd storageId not exist in prd , req {}", req);
throw new GatewayException(400, "商品不存在");
}
int skup = skupService.addSkup(storageData);
//TODO step 2: create order, set status(not pay)
//TODO generate a new real code
long orderCode = new OrderCodeGenerator(){
@Override
public long generate() {
return new Random(10000000).nextLong();
}
}.generate();
long orderCode = orderCodeGenerator.generate();
//createOrder()
return orderCode;
}
... ... @@ -132,7 +151,7 @@ public class SellerOrderService {
String bankTransferFeeStr = formatFee(bankTransferfee);
SoldPrdComputeBo computeBo = SoldPrdComputeBo.builder()
.earnestMoney(earnestMoneyStr)
//.bankTransferFee(bankTransferFeeStr) 编译问题先注释
.bankTransferFee(bankTransferFeeStr)
.platformFee(platformFeeWrapper)
.income(incomeStr)
.build();
... ...
package com.yohoufo.order.service;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.constants.SkupStatus;
import com.yohoufo.product.model.GoodsSize;
import com.yohoufo.product.response.StorageDataResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by chenchao on 2018/9/17.
*/
@Service
public class SkupService {
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
public int addSkup(StorageDataResp.StorageData storageData){
GoodsSize goodsSize = storageData.getSizeList().get(0);
SellerOrderGoods sellerOrderGoods = new SellerOrderGoods();
sellerOrderGoods.setSizeId(goodsSize.getSizeId());
sellerOrderGoods.setStatus(SkupStatus.NOT_AVAILABLE.getCode());
sellerOrderGoodsMapper.insertSelective(sellerOrderGoods);
return sellerOrderGoods.getId();
}
}
... ...