Authored by chenchao

implement service logic

package com.yohoufo.dal.order.model;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class AppraiseOrder {
private Integer id;
... ... @@ -17,7 +20,7 @@ public class AppraiseOrder {
private BigDecimal shipFee;
private Byte status;
private Integer status;
private Integer createTime;
... ... @@ -26,100 +29,4 @@ public class AppraiseOrder {
private Byte isDel;
private String channelNo;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public Long getOrderCode() {
return orderCode;
}
public void setOrderCode(Long orderCode) {
this.orderCode = orderCode;
}
public Byte getClientType() {
return clientType;
}
public void setClientType(Byte clientType) {
this.clientType = clientType;
}
public Byte getPayment() {
return payment;
}
public void setPayment(Byte payment) {
this.payment = payment;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public BigDecimal getShipFee() {
return shipFee;
}
public void setShipFee(BigDecimal shipFee) {
this.shipFee = shipFee;
}
public Byte getStatus() {
return status;
}
public void setStatus(Byte status) {
this.status = status;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
public Byte getIsDel() {
return isDel;
}
public void setIsDel(Byte isDel) {
this.isDel = isDel;
}
public String getChannelNo() {
return channelNo;
}
public void setChannelNo(String channelNo) {
this.channelNo = channelNo == null ? null : channelNo.trim();
}
}
\ No newline at end of file
... ...
... ... @@ -4,9 +4,15 @@ import com.yohobuy.ufo.model.order.req.AppraiseOrderComputeReq;
import com.yohobuy.ufo.model.order.req.AppraiseOrderDetailReq;
import com.yohobuy.ufo.model.order.req.AppraiseOrderListReq;
import com.yohobuy.ufo.model.order.req.AppraiseOrderSubmitReq;
import com.yohobuy.ufo.model.order.resp.AppraiseOrderComputeResp;
import com.yohobuy.ufo.model.order.resp.AppraiseOrderDetailResp;
import com.yohobuy.ufo.model.order.resp.AppraiseOrderListResp;
import com.yohobuy.ufo.model.order.resp.AppraiseOrderSubmitResp;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.service.impl.AppraiseOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
... ... @@ -16,6 +22,9 @@ public class AppraiseOrderController {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private AppraiseOrderService appraiseOrderService;
/**
* 商品付费鉴定费用计算
* @param uid
... ... @@ -30,11 +39,10 @@ public class AppraiseOrderController {
.productId(productId)
.build();
logger.info("in ufo.appriseOrder.compute req {}", req);
AppraiseOrderComputeResp resp = appraiseOrderService.compute(req);
return new ApiResponse.ApiResponseBuilder()
.code(200)
.data(null)
.data(resp)
.message("鉴定计算成功")
.build();
}
... ... @@ -47,10 +55,10 @@ public class AppraiseOrderController {
AppraiseOrderSubmitReq req = AppraiseOrderSubmitReq.builder()
.uid(uid).productId(productId).addressId(addressId).build();
logger.info("in ufo.appriseOrder.submit req {}", req);
AppraiseOrderSubmitResp resp = appraiseOrderService.submit(req);
return new ApiResponse.ApiResponseBuilder()
.code(200)
.data(null)
.data(resp)
.message("鉴定订单提交成功")
.build();
}
... ... @@ -70,10 +78,10 @@ public class AppraiseOrderController {
.uid(uid).limit(limit).page(page).build();
logger.info("in ufo.appriseOrder.list req {}", req);
AppraiseOrderListResp resp = appraiseOrderService.getOrderList(req);
return new ApiResponse.ApiResponseBuilder()
.code(200)
.data(null)
.data(resp)
.message("鉴定订单列表查询成功")
.build();
}
... ... @@ -84,10 +92,10 @@ public class AppraiseOrderController {
@RequestParam(name = "orderCode")long orderCode){
AppraiseOrderDetailReq req = AppraiseOrderDetailReq.builder().uid(uid).orderCode(orderCode).build();
logger.info("in ufo.appriseOrder.detail req {}", req);
AppraiseOrderDetailResp resp = appraiseOrderService.getOrderDetail(req);
return new ApiResponse.ApiResponseBuilder()
.code(200)
.data(null)
.data(resp)
.message("鉴定订单详情查询成功")
.build();
}
... ...
package com.yohoufo.order.model.dto;
import com.yohobuy.ufo.model.order.bo.AppraiseOrderGoodsBo;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AppraiseOrderContext {
private int uid;
private long orderCode;
private int productId;
/**
* 鉴定费
*/
private BigDecimal fee;
private AppraiseOrderGoodsBo goodsBo;
/**
* 寄回地址
*/
private AddressInfo backAddress;
private AddressInfo backHiddenAddress;
}
... ...
package com.yohoufo.order.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.yohobuy.ufo.model.order.bo.AppraiseOrderGoodsBo;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.dal.order.AppraiseOrderGoodsMapper;
import com.yohoufo.dal.order.AppraiseOrderMapper;
import com.yohoufo.dal.order.BuyerOrderMetaMapper;
import com.yohoufo.dal.order.model.AppraiseOrder;
import com.yohoufo.dal.order.model.AppraiseOrderGoods;
import com.yohoufo.dal.order.model.BuyerOrderMeta;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.model.dto.AppraiseOrderContext;
import com.yohoufo.order.utils.LoggerUtils;
import lombok.Builder;
import lombok.Data;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class AppraiseOrderCreateService {
private final Logger logger = LoggerUtils.getBuyerOrderLogger();
@Autowired
private AppraiseOrderMapper appraiseOrderMapper;
@Autowired
private AppraiseOrderGoodsMapper appraiseOrderGoodsMapper;
@Autowired
private BuyerOrderMetaMapper buyerOrderMetaMapper;
@Builder
@Data
static class SubmitResult{
AppraiseOrder appraiseOrder;
AppraiseOrderGoods appraiseOrderGoods;
}
public SubmitResult create(AppraiseOrderContext ctx){
logger.info("in AppraiseOrderCreateService create, ");
int uid = ctx.getUid();
long orderCode = ctx.getOrderCode();
logger.info("in AppraiseOrderCreateService create, uid {} orderCode {} prdId {}",
uid, orderCode, ctx.getProductId());
//
AppraiseOrder pao = new AppraiseOrder();
pao.setOrderCode(orderCode);
pao.setAmount(ctx.getFee());
//TODO
pao.setStatus(0);
appraiseOrderMapper.insertSelective(pao);
//
AppraiseOrderGoodsBo aogb = ctx.getGoodsBo();
AppraiseOrderGoods paog = new AppraiseOrderGoods();
paog.setOrderCode(orderCode);
paog.setProductId(aogb.getProductId());
paog.setProductName(aogb.getProductName());
paog.setProductCode(aogb.getProductCode());
appraiseOrderGoodsMapper.insertSelective(paog);
//meta
AddressInfo noHiddenBackAddress = ctx.getBackAddress(),
hiddenBackAddress = ctx.getBackHiddenAddress();
final String key = MetaKey.BUYER_DELIVERY_ADDRESS,
hiiden_key = MetaKey.BUYER_DELIVERY_HIDDEN_ADDRESS;
BuyerOrderMeta noHiddenAddressMeta=new BuyerOrderMeta();
noHiddenAddressMeta.setUid(uid);
noHiddenAddressMeta.setOrderCode(orderCode);
noHiddenAddressMeta.setMetaKey(key);
noHiddenAddressMeta.setMetaValue(JSONObject.toJSONString(noHiddenBackAddress));
//hidden address
BuyerOrderMeta hiddenAddressMeta=new BuyerOrderMeta();
hiddenAddressMeta.setUid(uid);
hiddenAddressMeta.setOrderCode(orderCode);
hiddenAddressMeta.setMetaKey(hiiden_key);
hiddenAddressMeta.setMetaValue(JSONObject.toJSONString(hiddenBackAddress));
List<BuyerOrderMeta> boms = new ArrayList<>(2);
boms.add(noHiddenAddressMeta);
boms.add(hiddenAddressMeta);
buyerOrderMetaMapper.insertBatch(boms);
return SubmitResult.builder().appraiseOrder(pao).appraiseOrderGoods(paog).build();
}
}
... ...
package com.yohoufo.order.service.impl;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.AppraiseOrderGoodsBo;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.order.req.AppraiseOrderComputeReq;
import com.yohobuy.ufo.model.order.req.AppraiseOrderDetailReq;
import com.yohobuy.ufo.model.order.req.AppraiseOrderListReq;
import com.yohobuy.ufo.model.order.req.AppraiseOrderSubmitReq;
import com.yohobuy.ufo.model.order.resp.AppraiseOrderComputeResp;
import com.yohobuy.ufo.model.order.resp.AppraiseOrderDetailResp;
import com.yohobuy.ufo.model.order.resp.AppraiseOrderListResp;
import com.yohobuy.ufo.model.order.resp.AppraiseOrderSubmitResp;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.AddressUtil;
import com.yohoufo.dal.order.AppraiseOrderGoodsMapper;
import com.yohoufo.dal.order.AppraiseOrderMapper;
import com.yohoufo.order.model.dto.AppraiseOrderContext;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.utils.AddressHelper;
import com.yohoufo.order.utils.LoggerUtils;
import lombok.Builder;
import lombok.Data;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
... ... @@ -10,8 +34,127 @@ public class AppraiseOrderService {
private final Logger logger = LoggerUtils.getBuyerOrderLogger();
@Autowired
private AppraiseOrderMapper appraiseOrderMapper;
@Autowired
private AppraiseOrderGoodsMapper appraiseOrderGoodsMapper;
@Autowired
private UserProxyService userProxyService;
@Autowired
private AppraiseOrderCreateService appraiseOrderCreateService;
@Autowired
OrderCodeGenerator orderCodeGenerator;
public AppraiseOrderComputeResp compute(AppraiseOrderComputeReq req){
logger.info("in AppraiseOrderService.compute req {}", req);
int uid = req.getUid();
if (uid<=0){
throw new UfoServiceException(400, "uid错误");
}
int productId = req.getProductId();
if (productId <= 0){
throw new UfoServiceException(400, "商品ID错误");
}
double fee = 15D;
return AppraiseOrderComputeResp.builder().fee(String.valueOf(fee)).build();
}
public AppraiseOrderSubmitResp submit(AppraiseOrderSubmitReq req){
//1. check
PreparedNode pn = checkAndAcquire(req);
// 生成订单号
long orderCode = orderCodeGenerator.generate(OrderCodeType.BUYER_TYPE);
logger.info("AppraiseOrder.submit req {} ,generate new orderCode:{}", req, orderCode);
AppraiseOrderGoodsBo aog = new AppraiseOrderGoodsBo();
//TODO dependency product service support produce data
AppraiseOrderContext aoc = AppraiseOrderContext.builder()
.orderCode(orderCode)
.uid(pn.getUid())
.productId(pn.getProductId())
.backAddress(pn.getNoHiddenBackAddress())
.backHiddenAddress(pn.getHiddenBackAddress())
.goodsBo(aog)
.build();
//2 persistent key info
//2.1 appraise order
//2.2 appraise order goods
//2.3 address
AppraiseOrderCreateService.SubmitResult submitResult = appraiseOrderCreateService.create(aoc);
//todo notice by async
AppraiseOrderSubmitResp aosr = new AppraiseOrderSubmitResp();
aosr.setOrderCode(orderCode);
return aosr;
}
@Data
@Builder
private static class PreparedNode{
int uid;
int productId;
AddressInfo hiddenBackAddress;
AddressInfo noHiddenBackAddress;
}
private PreparedNode checkAndAcquire(AppraiseOrderSubmitReq req){
int uid = req.getUid();
if (uid<=0){
throw new UfoServiceException(400, "uid错误");
}
int productId = req.getProductId();
if (productId <= 0){
throw new UfoServiceException(400, "商品ID错误");
}
int addressId = AddressUtil.getDecryptStr(req.getAddressId());
if (addressId < 0){
logger.warn("submit appraise order addressId invalidate, uid {}, productId {}, addressId {}",
uid, productId, req.getAddressId());
throw new ServiceException(ServiceError.ORDER_ADDRESSID_INVALIDATE);
}
//the address of send back 2 seller
AddressInfo hiddenBackAddress = userProxyService.getHiddenAddressInfo(uid, addressId);
AddressInfo noHiddenBackAddress = userProxyService.getAddressInfoNotHidden(uid, addressId);
if(AddressHelper.isNeedUpdate(noHiddenBackAddress)){
logger.warn("submit appraise order addressId need update, uid {}, appraise {}, addressId {}",
uid, productId, addressId);
throw new ServiceException(ServiceError.ORDER_ADDRESS_NEED_UPDATE);
}
return PreparedNode.builder()
.uid(uid)
.productId(productId)
.hiddenBackAddress(hiddenBackAddress)
.noHiddenBackAddress(noHiddenBackAddress)
.build();
}
public AppraiseOrderListResp getOrderList(AppraiseOrderListReq req){
return null;
}
public AppraiseOrderDetailResp getOrderDetail(AppraiseOrderDetailReq req){
return null;
}
}
... ...