- 添加发货功能

This commit is contained in:
sin
2019-04-05 17:51:37 +08:00
parent 8b11176353
commit 10807b0c6f
11 changed files with 229 additions and 117 deletions

View File

@@ -5,6 +5,7 @@ import cn.iocoder.mall.order.api.dto.OrderCreateDTO;
import cn.iocoder.mall.order.api.dto.OrderDeliveryDTO;
import cn.iocoder.mall.order.api.dto.OrderLogisticsUpdateDTO;
import cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDO;
import cn.iocoder.mall.order.biz.dataobject.OrderRecipientDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@@ -28,6 +29,9 @@ public interface OrderLogisticsConvert {
@Mappings({})
OrderLogisticsDO convert(OrderLogisticsUpdateDTO orderLogisticsDTO);
@Mappings({})
OrderLogisticsDO convert(OrderRecipientDO orderRecipientDO);
@Mappings({})
List<OrderLogisticsBO> convertOrderLogisticsBO(List<OrderLogisticsDO> orderLogisticsDOList);
}

View File

@@ -29,7 +29,7 @@ public interface OrderItemMapper {
*
* @param orderItemDO
*/
void updateById(OrderItemDO orderItemDO);
void updateById(@Param("orderItemDO") OrderItemDO orderItemDO);
/**
* 更新 - 根据 orderId
@@ -45,7 +45,7 @@ public interface OrderItemMapper {
*/
void updateByIds(
@Param("ids") List<Integer> ids,
OrderItemDO orderItemDO
@Param("orderItemDO") OrderItemDO orderItemDO
);
/**
@@ -54,7 +54,7 @@ public interface OrderItemMapper {
* @param ids
* @return
*/
List<OrderItemDO> selectByIds(Collection<Integer> ids);
List<OrderItemDO> selectByIds(@Param("ids") Collection<Integer> ids);
/**
* 查询 - 根据 orderIds 和 status

View File

@@ -295,21 +295,55 @@ public class OrderServiceImpl implements OrderService {
@Transactional
public CommonResult orderDelivery(OrderDeliveryDTO orderDelivery) {
List<Integer> orderItemIds = orderDelivery.getOrderItemIds();
List<OrderItemDO> orderItemDOList = orderItemMapper.selectByIds(orderItemIds);
if (orderItemDOList.size() != orderItemIds.size()) {
// 获取所有订单 items
List<OrderItemDO> allOrderItems = orderItemMapper
.selectByOrderIdAndDeleted(orderDelivery.getOrderId(), DeletedStatusEnum.DELETED_NO.getValue());
// 当前需要发货订单,检查 id 和 status
List<OrderItemDO> needDeliveryOrderItems = allOrderItems.stream()
.filter(orderItemDO -> orderItemIds.contains(orderItemDO.getId())
&& OrderStatusEnum.WAIT_SHIPMENT.getValue() == orderItemDO.getStatus())
.collect(Collectors.toList());
List<OrderItemDO> deliveredOrderItems = allOrderItems.stream()
.filter(orderItemDO -> OrderStatusEnum.WAIT_SHIPMENT.getValue() == orderItemDO.getStatus())
.collect(Collectors.toList());
// 发货订单,检查
if (needDeliveryOrderItems.size() != orderItemIds.size()) {
return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_DELIVERY_INCORRECT_DATA.getCode());
}
OrderRecipientDO orderRecipientDO = orderRecipientMapper.selectByOrderId(orderDelivery.getOrderId());
OrderLogisticsDO orderLogisticsDO = OrderLogisticsConvert.INSTANCE.convert(orderRecipientDO);
// 保存物流信息
OrderLogisticsDO orderLogisticsDO = OrderLogisticsConvert.INSTANCE.convert(orderDelivery);
orderLogisticsDO
.setLogisticsNo(orderDelivery.getLogisticsNo())
.setLogistics(orderDelivery.getLogistics())
.setCreateTime(new Date())
.setUpdateTime(null);
orderLogisticsMapper.insert(orderLogisticsDO);
// 关联订单item 和 物流信息
orderItemMapper.updateByIds(orderItemIds, new OrderItemDO().setOrderLogisticsId(orderLogisticsDO.getId()));
orderItemMapper.updateByIds(
orderItemIds,
new OrderItemDO()
.setOrderLogisticsId(orderLogisticsDO.getId())
.setStatus(OrderStatusEnum.ALREADY_SHIPMENT.getValue())
);
// 子订单是否全部发货,如果发完,就更新 order
if (deliveredOrderItems.size() <= 0) {
orderMapper.updateById(
new OrderDO()
.setId(orderDelivery.getOrderId())
.setStatus(OrderStatusEnum.ALREADY_SHIPMENT.getValue())
);
}
return CommonResult.success(null);
}

View File

@@ -29,61 +29,64 @@
-->
<sql id="updateFieldSql" >
<set>
<if test="orderId != null">
, order_id = #{orderId}
<if test="orderItemDO.orderId != null">
, order_id = #{orderItemDO.orderId}
</if>
<if test="orderNo != null">
, order_no = #{orderNo}
<if test="orderItemDO.orderNo != null">
, order_no = #{orderItemDO.orderNo}
</if>
<if test="skuId != null">
, sku_id = #{skuId}
<if test="orderItemDO.orderLogisticsId != null">
, order_logistics_id = #{orderItemDO.orderLogisticsId}
</if>
<if test="skuName != null">
, sku_name = #{skuName}
<if test="orderItemDO.skuId != null">
, sku_id = #{orderItemDO.skuId}
</if>
<if test="skuImage != null">
, sku_image = #{skuImage}
<if test="orderItemDO.skuName != null">
, sku_name = #{orderItemDO.skuName}
</if>
<if test="quantity != null">
, quantity = #{quantity}
<if test="orderItemDO.skuImage != null">
, sku_image = #{orderItemDO.skuImage}
</if>
<if test="price != null">
, price = #{price}
<if test="orderItemDO.quantity != null">
, quantity = #{orderItemDO.quantity}
</if>
<if test="payAmount != null">
, pay_amount = #{payAmount}
<if test="orderItemDO.price != null">
, price = #{orderItemDO.price}
</if>
<if test="orderItemDO.payAmount != null">
, pay_amount = #{orderItemDO.payAmount}
</if>
<if test="paymentTime != null">
, payment_time = #{paymentTime}
<if test="orderItemDO.paymentTime != null">
, payment_time = #{orderItemDO.paymentTime}
</if>
<if test="deliveryTime != null">
, delivery_time = #{deliveryTime}
<if test="orderItemDO.deliveryTime != null">
, delivery_time = #{orderItemDO.deliveryTime}
</if>
<if test="receiverTime != null">
, receiver_time = #{receiverTime}
<if test="orderItemDO.receiverTime != null">
, receiver_time = #{orderItemDO.receiverTime}
</if>
<if test="closingTime != null">
, closing_time = #{closingTime}
<if test="orderItemDO.closingTime != null">
, closing_time = #{orderItemDO.closingTime}
</if>
<if test="hasReturnExchange != null">
, has_return_exchange = #{hasReturnExchange}
<if test="orderItemDO.hasReturnExchange != null">
, has_return_exchange = #{orderItemDO.hasReturnExchange}
</if>
<if test="status != null">
, status = #{status}
<if test="orderItemDO.status != null">
, status = #{orderItemDO.status}
</if>
<if test="deliveryType != null">
, delivery_type = #{deliveryType}
<if test="orderItemDO.deliveryType != null">
, delivery_type = #{orderItemDO.deliveryType}
</if>
<if test="deleted != null">
, `deleted` = #{deleted}
<if test="orderItemDO.deleted != null">
, `deleted` = #{orderItemDO.deleted}
</if>
<if test="createTime != null">
, create_time = #{createTime}
<if test="orderItemDO.createTime != null">
, create_time = #{orderItemDO.createTime}
</if>
<if test="updateTime != null">
, update_time = #{updateTime}
<if test="orderItemDO.updateTime != null">
, update_time = #{orderItemDO.updateTime}
</if>
</set>
</sql>
@@ -94,7 +97,7 @@
<update id="updateById" parameterType="OrderDO">
UPDATE `order_item`
<include refid="updateFieldSql" />
WHERE id = #{id}
WHERE id = #{orderItemDO.id}
</update>
<!--

View File

@@ -11,10 +11,10 @@
-->
<insert id="insert" parameterType="OrderLogisticsDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
INSERT INTO `order_logistics` (
area_no, `name`, mobile, address, logistics_no, create_time, update_time
area_no, `name`, mobile, address, logistics, logistics_no, create_time, update_time
) VALUES (
#{areaNo}, #{name}, #{mobile}, #{address},
#{logisticsNo}, #{createTime}, #{updateTime}
#{logistics}, #{logisticsNo}, #{createTime}, #{updateTime}
)
</insert>
@@ -35,6 +35,9 @@
<if test="address != null">
, address = #{address}
</if>
<if test="logistics != null">
, logistics = #{logistics}
</if>
<if test="logisticsNo != null">
, logistics_no = #{logisticsNo}
</if>

View File

@@ -14,12 +14,12 @@
-->
<insert id="insert" parameterType="OrderDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
INSERT INTO `order` (
user_id, order_logistics_id, order_no, price, payment_time,
user_id, order_no, price, payment_time,
delivery_time, receiver_time, closing_time,
has_return_exchange, status, remark,
create_time, update_time, `deleted`
) VALUES (
#{orderLogisticsId}, #{userId}, #{orderNo}, #{price}, #{paymentTime},
#{userId}, #{orderNo}, #{price}, #{paymentTime},
#{deliveryTime}, #{receiverTime}, #{closingTime},
#{hasReturnExchange}, #{status}, #{remark},
#{createTime}, #{updateTime}, #{deleted}
@@ -31,9 +31,6 @@
-->
<sql id="updateFieldSql" >
<set>
<if test="orderLogisticsId != null">
, order_logistics_id = #{orderLogisticsId}
</if>
<if test="orderNo != null">
, order_no = #{orderNo}
</if>
@@ -110,9 +107,6 @@
<if test="orderNo != null">
AND `order_no` = #{orderNo}
</if>
<if test="orderLogisticsId != null">
AND `order_logistics_id` = #{orderLogisticsId}
</if>
<if test="hasReturnExchange != null">
AND `has_return_exchange` = #{hasReturnExchange}
</if>