- 添加订单 info
This commit is contained in:
@@ -12,11 +12,28 @@ import java.util.List;
|
||||
*/
|
||||
public interface OrderCommon {
|
||||
|
||||
|
||||
/**
|
||||
* 计算订单金额
|
||||
* 计算总价格
|
||||
*
|
||||
* @param items
|
||||
* @return
|
||||
*/
|
||||
Integer calculatedPrice(List<OrderItemDO> items);
|
||||
|
||||
/**
|
||||
* 计算订单实付金额
|
||||
*
|
||||
* @param items
|
||||
* @return
|
||||
*/
|
||||
Integer calculatedAmount(List<OrderItemDO> items);
|
||||
|
||||
/**
|
||||
* 计算物流金额
|
||||
*
|
||||
* @param items
|
||||
* @return
|
||||
*/
|
||||
Integer calculatedLogisticsPrice(List<OrderItemDO> items);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,18 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
@Component
|
||||
public class OrderCommonImpl implements OrderCommon {
|
||||
|
||||
@Override
|
||||
public Integer calculatedPrice(List<OrderItemDO> items) {
|
||||
if (CollectionUtils.isEmpty(items)) {
|
||||
return 0;
|
||||
}
|
||||
AtomicInteger totalPrice = new AtomicInteger(0);
|
||||
items.forEach(orderItemDO -> {
|
||||
totalPrice.addAndGet(orderItemDO.getPrice() * orderItemDO.getQuantity());
|
||||
});
|
||||
return totalPrice.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer calculatedAmount(List<OrderItemDO> items) {
|
||||
if (CollectionUtils.isEmpty(items)) {
|
||||
@@ -27,4 +39,16 @@ public class OrderCommonImpl implements OrderCommon {
|
||||
});
|
||||
return totalAmount.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer calculatedLogisticsPrice(List<OrderItemDO> items) {
|
||||
if (CollectionUtils.isEmpty(items)) {
|
||||
return 0;
|
||||
}
|
||||
AtomicInteger totalAmount = new AtomicInteger(0);
|
||||
items.forEach(orderItemDO -> {
|
||||
totalAmount.addAndGet(orderItemDO.getLogisticsPrice());
|
||||
});
|
||||
return totalAmount.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.iocoder.mall.order.biz.convert;
|
||||
|
||||
import cn.iocoder.mall.order.api.bo.OrderBO;
|
||||
import cn.iocoder.mall.order.api.bo.OrderInfoBO;
|
||||
import cn.iocoder.mall.order.biz.dataobject.OrderDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
@@ -21,4 +22,7 @@ public interface OrderConvert {
|
||||
|
||||
@Mappings({})
|
||||
List<OrderBO> convertPageBO(List<OrderDO> orderDOList);
|
||||
|
||||
@Mappings({})
|
||||
OrderInfoBO convert(OrderDO orderDO);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.iocoder.mall.order.biz.convert;
|
||||
|
||||
import cn.iocoder.mall.order.api.bo.OrderInfoBO;
|
||||
import cn.iocoder.mall.order.api.bo.OrderLogisticsInfoBO;
|
||||
import cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDetailDO;
|
||||
import org.mapstruct.Mapper;
|
||||
@@ -21,4 +22,7 @@ public interface OrderLogisticsDetailConvert {
|
||||
|
||||
@Mappings({})
|
||||
List<OrderLogisticsInfoBO.LogisticsDetail> convertLogisticsDetail(List<OrderLogisticsDetailDO> orderLogisticsDOList);
|
||||
|
||||
@Mappings({})
|
||||
OrderInfoBO.LogisticsDetail convertLogisticsDetail(OrderLogisticsDetailDO orderLogisticsDetailDO);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.iocoder.mall.order.biz.convert;
|
||||
|
||||
import cn.iocoder.mall.order.api.bo.OrderInfoBO;
|
||||
import cn.iocoder.mall.order.api.bo.OrderRecipientBO;
|
||||
import cn.iocoder.mall.order.api.dto.OrderCreateDTO;
|
||||
import cn.iocoder.mall.order.biz.dataobject.OrderRecipientDO;
|
||||
@@ -32,4 +33,7 @@ public interface OrderRecipientConvert {
|
||||
|
||||
@Mappings({})
|
||||
List<OrderRecipientBO> convert(List<OrderRecipientDO> orderRecipientDOList);
|
||||
|
||||
@Mappings({})
|
||||
OrderInfoBO.Recipient convertOrderInfoRecipient(OrderRecipientDO orderRecipientDO);
|
||||
}
|
||||
|
||||
@@ -43,4 +43,14 @@ public interface OrderLogisticsDetailMapper {
|
||||
List<OrderLogisticsDetailDO> selectByOrderLogisticsIds(
|
||||
@Param("orderLogisticsIds") Collection<Integer> orderLogisticsIds
|
||||
);
|
||||
|
||||
/**
|
||||
* 查询 - 获取最新的物流信息
|
||||
*
|
||||
* @param orderLogisticsIds
|
||||
* @return
|
||||
*/
|
||||
OrderLogisticsDetailDO selectLatest(
|
||||
@Param("orderLogisticsIds") Collection<Integer> orderLogisticsIds
|
||||
);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,14 @@ public class OrderDO extends DeletableDO {
|
||||
* 订单编号
|
||||
*/
|
||||
private String orderNo;
|
||||
/**
|
||||
* 价格(分)
|
||||
*/
|
||||
private Integer price;
|
||||
/**
|
||||
* 物流金额 (分)
|
||||
*/
|
||||
private Integer logisticsPrice;
|
||||
/**
|
||||
* 交易金额
|
||||
*/
|
||||
|
||||
@@ -56,6 +56,10 @@ public class OrderItemDO extends DeletableDO {
|
||||
* 支付金额(实付金额)
|
||||
*/
|
||||
private Integer payAmount;
|
||||
/**
|
||||
* 物流金额 (分)
|
||||
*/
|
||||
private Integer logisticsPrice;
|
||||
|
||||
///
|
||||
/// 时间信息
|
||||
|
||||
@@ -5,7 +5,6 @@ import cn.iocoder.common.framework.util.DateUtil;
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.order.api.OrderLogisticsService;
|
||||
import cn.iocoder.mall.order.api.bo.OrderLogisticsBO;
|
||||
import cn.iocoder.mall.order.api.bo.OrderLogisticsInfoBO;
|
||||
import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum;
|
||||
import cn.iocoder.mall.order.biz.convert.OrderLogisticsConvert;
|
||||
@@ -34,6 +33,7 @@ import java.util.stream.Collectors;
|
||||
* @time 2019-04-12 21:32
|
||||
*/
|
||||
@Service
|
||||
@com.alibaba.dubbo.config.annotation.Service(validation = "true")
|
||||
public class OrderLogisticsServiceImpl implements OrderLogisticsService {
|
||||
|
||||
@Autowired
|
||||
@@ -63,7 +63,9 @@ public class OrderLogisticsServiceImpl implements OrderLogisticsService {
|
||||
|
||||
// 获取物流 信息
|
||||
Set<Integer> orderLogisticsIds = orderItemDOList.stream()
|
||||
.map(o -> o.getOrderLogisticsId()).collect(Collectors.toSet());
|
||||
.filter(o -> o.getOrderLogisticsId() != null)
|
||||
.map(o -> o.getOrderLogisticsId())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
List<OrderLogisticsDO> orderLogisticsDOList = orderLogisticsMapper.selectByIds(orderLogisticsIds);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Date;
|
||||
* @time 2019-03-30 15:35
|
||||
*/
|
||||
@Service
|
||||
@com.alibaba.dubbo.config.annotation.Service(validation = "true")
|
||||
public class OrderReturnServiceImpl implements OrderReturnService {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -12,10 +12,7 @@ import cn.iocoder.mall.order.api.dto.*;
|
||||
import cn.iocoder.mall.order.biz.OrderCommon;
|
||||
import cn.iocoder.mall.order.biz.constants.OrderDeliveryTypeEnum;
|
||||
import cn.iocoder.mall.order.biz.constants.OrderRecipientTypeEnum;
|
||||
import cn.iocoder.mall.order.biz.convert.OrderConvert;
|
||||
import cn.iocoder.mall.order.biz.convert.OrderItemConvert;
|
||||
import cn.iocoder.mall.order.biz.convert.OrderLogisticsConvert;
|
||||
import cn.iocoder.mall.order.biz.convert.OrderRecipientConvert;
|
||||
import cn.iocoder.mall.order.biz.convert.*;
|
||||
import cn.iocoder.mall.order.biz.dao.*;
|
||||
import cn.iocoder.mall.order.biz.dataobject.*;
|
||||
import cn.iocoder.mall.pay.api.PayTransactionService;
|
||||
@@ -55,6 +52,8 @@ public class OrderServiceImpl implements OrderService {
|
||||
@Autowired
|
||||
private OrderLogisticsMapper orderLogisticsMapper;
|
||||
@Autowired
|
||||
private OrderLogisticsDetailMapper orderLogisticsDetailMapper;
|
||||
@Autowired
|
||||
private OrderRecipientMapper orderRecipientMapper;
|
||||
@Autowired
|
||||
private OrderCancelMapper orderCancelMapper;
|
||||
@@ -152,6 +151,41 @@ public class OrderServiceImpl implements OrderService {
|
||||
return CommonResult.success(orderRecipientBO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<OrderInfoBO> info(Integer userId, Integer orderId) {
|
||||
OrderDO orderDO = orderMapper.selectById(orderId);
|
||||
if (orderDO == null) {
|
||||
return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_NOT_EXISTENT.getCode());
|
||||
}
|
||||
|
||||
List<OrderItemDO> itemDOList = orderItemMapper
|
||||
.selectByDeletedAndOrderId(orderId, DeletedStatusEnum.DELETED_NO.getValue());
|
||||
|
||||
Set<Integer> orderLogisticsIds = itemDOList.stream()
|
||||
.filter(o -> o.getOrderLogisticsId() != null)
|
||||
.map(o -> o.getOrderLogisticsId())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 收件人信息
|
||||
OrderRecipientDO orderRecipientDO = orderRecipientMapper.selectByOrderId(orderId);
|
||||
|
||||
// 订单物流信息
|
||||
OrderLogisticsDetailDO orderLogisticsDetailDO = null;
|
||||
if (!CollectionUtils.isEmpty(orderLogisticsIds)) {
|
||||
orderLogisticsDetailDO = orderLogisticsDetailMapper.selectLatest(orderLogisticsIds);
|
||||
}
|
||||
|
||||
// convert 信息
|
||||
OrderInfoBO.LogisticsDetail logisticsDetail
|
||||
= OrderLogisticsDetailConvert.INSTANCE.convertLogisticsDetail(orderLogisticsDetailDO);
|
||||
|
||||
OrderInfoBO.Recipient recipient = OrderRecipientConvert.INSTANCE.convertOrderInfoRecipient(orderRecipientDO);
|
||||
OrderInfoBO orderInfoBO = OrderConvert.INSTANCE.convert(orderDO);
|
||||
orderInfoBO.setRecipient(recipient);
|
||||
orderInfoBO.setLatestLogisticsDetail(logisticsDetail);
|
||||
return CommonResult.success(orderInfoBO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CommonResult<OrderCreateBO> createOrder(OrderCreateDTO orderCreateDTO) {
|
||||
@@ -196,6 +230,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
orderItemDO.setSkuImage(Optional.ofNullable(productSkuDetailBO.getSpu().getPicUrls().get(0)).get());
|
||||
orderItemDO.setSkuName(productSkuDetailBO.getSpu().getName());
|
||||
orderItemDO.setPrice(productSkuDetailBO.getPrice());
|
||||
orderItemDO.setLogisticsPrice(0);
|
||||
|
||||
int payAmount = orderItemDO.getQuantity() * orderItemDO.getPrice();
|
||||
orderItemDO.setPayAmount(payAmount);
|
||||
@@ -206,10 +241,14 @@ public class OrderServiceImpl implements OrderService {
|
||||
// TODO: 2019-04-11 Sin 订单号需要生成规则
|
||||
String orderNo = UUID.randomUUID().toString().replace("-", "").substring(0, 16);
|
||||
Integer totalAmount = orderCommon.calculatedAmount(orderItemDOList);
|
||||
Integer totalPrice = orderCommon.calculatedPrice(orderItemDOList);
|
||||
Integer totalLogisticsPrice = orderCommon.calculatedLogisticsPrice(orderItemDOList);
|
||||
OrderDO orderDO = new OrderDO()
|
||||
.setUserId(userId)
|
||||
.setOrderNo(orderNo)
|
||||
.setPrice(totalPrice)
|
||||
.setPayAmount(totalAmount)
|
||||
.setLogisticsPrice(totalLogisticsPrice)
|
||||
.setClosingTime(null)
|
||||
.setDeliveryTime(null)
|
||||
.setPaymentTime(null)
|
||||
@@ -223,7 +262,9 @@ public class OrderServiceImpl implements OrderService {
|
||||
orderMapper.insert(orderDO);
|
||||
|
||||
// 收件人信息
|
||||
CommonResult<UserAddressBO> userAddressResult = userAddressService.getAddress(userId, orderCreateDTO.getUserAddressId());
|
||||
CommonResult<UserAddressBO> userAddressResult
|
||||
= userAddressService.getAddress(userId, orderCreateDTO.getUserAddressId());
|
||||
|
||||
if (userAddressResult.isError()) {
|
||||
return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_GET_USER_ADDRESS_FAIL.getCode());
|
||||
}
|
||||
@@ -310,9 +351,16 @@ public class OrderServiceImpl implements OrderService {
|
||||
orderItemMapper.updateById(new OrderItemDO().setId(orderItemId).setPayAmount(payAmount));
|
||||
|
||||
// 再重新计算订单金额
|
||||
List<OrderItemDO> orderItemDOList = orderItemMapper.selectByDeletedAndOrderId(orderId, DeletedStatusEnum.DELETED_NO.getValue());
|
||||
Integer orderPayAmount = orderCommon.calculatedAmount(orderItemDOList);
|
||||
orderMapper.updateById(new OrderDO().setId(orderId).setPayAmount(orderPayAmount));
|
||||
List<OrderItemDO> orderItemDOList = orderItemMapper
|
||||
.selectByDeletedAndOrderId(orderId, DeletedStatusEnum.DELETED_NO.getValue());
|
||||
Integer price = orderCommon.calculatedPrice(orderItemDOList);
|
||||
Integer amount = orderCommon.calculatedAmount(orderItemDOList);
|
||||
orderMapper.updateById(
|
||||
new OrderDO()
|
||||
.setId(orderId)
|
||||
.setPrice(price)
|
||||
.setPayAmount(amount)
|
||||
);
|
||||
return CommonResult.success(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,4 +46,19 @@
|
||||
#{orderLogisticsId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<!--
|
||||
查询 - 最新的物流信息
|
||||
-->
|
||||
<select id="selectLatest" resultType="cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDetailDO">
|
||||
SELECT
|
||||
<include refid="FIELDS"/>
|
||||
FROM order_logistics_detail
|
||||
WHERE order_logistics_id IN
|
||||
<foreach collection="orderLogisticsIds" item="orderLogisticsId" separator="," open="(" close=")">
|
||||
#{orderLogisticsId}
|
||||
</foreach>
|
||||
ORDER BY create_time DESC
|
||||
LIMIT 0, 1
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
<mapper namespace="cn.iocoder.mall.order.biz.dao.OrderMapper">
|
||||
|
||||
<sql id="FIELDS">
|
||||
id, user_id, order_no, pay_amount, payment_time,
|
||||
delivery_time, receiver_time, closing_time,
|
||||
id, user_id, order_no, price, pay_amount, logistics_price,
|
||||
payment_time, delivery_time, receiver_time, closing_time,
|
||||
has_return_exchange,
|
||||
status, remark, create_time, update_time, `deleted`
|
||||
</sql>
|
||||
@@ -14,13 +14,13 @@
|
||||
-->
|
||||
<insert id="insert" parameterType="OrderDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
INSERT INTO `order` (
|
||||
user_id, order_no, pay_amount, payment_time,
|
||||
delivery_time, receiver_time, closing_time,
|
||||
user_id, order_no, price, pay_amount, logistics_price,
|
||||
payment_time, delivery_time, receiver_time, closing_time,
|
||||
has_return_exchange,
|
||||
status, remark, create_time, update_time, `deleted`
|
||||
) VALUES (
|
||||
#{userId}, #{orderNo}, #{payAmount}, #{paymentTime},
|
||||
#{deliveryTime}, #{receiverTime}, #{closingTime},
|
||||
#{userId}, #{orderNo}, #{price}, #{payAmount}, #{logisticsPrice},
|
||||
#{paymentTime}, #{deliveryTime}, #{receiverTime}, #{closingTime},
|
||||
#{hasReturnExchange},
|
||||
#{status}, #{remark}, #{createTime}, #{updateTime}, #{deleted}
|
||||
)
|
||||
@@ -34,9 +34,15 @@
|
||||
<if test="orderNo != null">
|
||||
, order_no = #{orderNo}
|
||||
</if>
|
||||
<if test="price != null">
|
||||
, price = #{price}
|
||||
</if>
|
||||
<if test="payAmount != null">
|
||||
, pay_amount = #{payAmount}
|
||||
</if>
|
||||
<if test="logisticsPrice != null">
|
||||
, logistics_price = #{logisticsPrice}
|
||||
</if>
|
||||
|
||||
<if test="paymentTime != null">
|
||||
, payment_time = #{paymentTime}
|
||||
|
||||
Reference in New Issue
Block a user