- 添加发货功能

pull/1/head
sin 2019-04-05 17:51:37 +08:00
parent 8b11176353
commit 10807b0c6f
11 changed files with 229 additions and 117 deletions

View File

@ -7,12 +7,13 @@ import cn.iocoder.mall.order.api.bo.OrderPageBO;
import cn.iocoder.mall.order.api.bo.OrderRecipientBO;
import cn.iocoder.mall.order.api.dto.*;
import cn.iocoder.mall.order.application.convert.OrderConvertAPP;
import cn.iocoder.mall.order.application.vo.OrderItemUpdateVO;
import cn.iocoder.mall.order.application.vo.OrderLogisticsVO;
import cn.iocoder.mall.order.application.vo.OrderPageQueryVO;
import cn.iocoder.mall.order.application.convert.OrderDeliveryConvert;
import cn.iocoder.mall.order.application.po.OrderDeliverPO;
import cn.iocoder.mall.order.application.po.OrderItemUpdatePO;
import cn.iocoder.mall.order.application.po.OrderLogisticsPO;
import cn.iocoder.mall.order.application.po.OrderPageQueryPO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -35,7 +36,7 @@ public class AdminsOrderController {
@GetMapping("page")
@ApiOperation("订单列表")
public CommonResult<OrderPageBO> getOrderPage(@Validated OrderPageQueryVO orderPageQueryVO) {
public CommonResult<OrderPageBO> getOrderPage(@Validated OrderPageQueryPO orderPageQueryVO) {
OrderQueryDTO orderQueryDTO = OrderConvertAPP.INSTANCE.convertPageBO(orderPageQueryVO);
return orderService.getOrderPage(orderQueryDTO);
}
@ -52,6 +53,12 @@ public class AdminsOrderController {
return orderService.getOrderRecipientBO(orderId);
}
@PostMapping("order_deliver")
@ApiOperation("订单发货")
public CommonResult<OrderRecipientBO> orderDeliver(@RequestBody @Validated OrderDeliverPO orderDeliverPO) {
return orderService.orderDelivery(OrderDeliveryConvert.INSTANCE.convert(orderDeliverPO));
}
@PutMapping("update_remark")
@ApiOperation("更新-更新订单备注")
public CommonResult updateRemark(@RequestParam("orderId") Integer orderId,
@ -78,14 +85,14 @@ public class AdminsOrderController {
@PutMapping("order_item/update")
@ApiOperation("更新-订单item")
public CommonResult updateOrderItem(@RequestBody @Validated OrderItemUpdateVO orderItemUpdateVO) {
public CommonResult updateOrderItem(@RequestBody @Validated OrderItemUpdatePO orderItemUpdateVO) {
OrderItemUpdateDTO dto = OrderConvertAPP.INSTANCE.convertPageBO(orderItemUpdateVO);
return orderService.updateOrderItem(dto);
}
@PutMapping("logistics/update")
@ApiOperation("更新-订单物流")
public CommonResult updateLogistics(@RequestBody @Validated OrderLogisticsVO orderLogisticsVO) {
public CommonResult updateLogistics(@RequestBody @Validated OrderLogisticsPO orderLogisticsVO) {
OrderLogisticsUpdateDTO dto = OrderConvertAPP.INSTANCE.convertPageBO(orderLogisticsVO);
return orderService.updateLogistics(dto);
}

View File

@ -3,9 +3,9 @@ package cn.iocoder.mall.order.application.convert;
import cn.iocoder.mall.order.api.dto.OrderItemUpdateDTO;
import cn.iocoder.mall.order.api.dto.OrderLogisticsUpdateDTO;
import cn.iocoder.mall.order.api.dto.OrderQueryDTO;
import cn.iocoder.mall.order.application.vo.OrderItemUpdateVO;
import cn.iocoder.mall.order.application.vo.OrderLogisticsVO;
import cn.iocoder.mall.order.application.vo.OrderPageQueryVO;
import cn.iocoder.mall.order.application.po.OrderItemUpdatePO;
import cn.iocoder.mall.order.application.po.OrderPageQueryPO;
import cn.iocoder.mall.order.application.po.OrderLogisticsPO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@ -24,11 +24,11 @@ public interface OrderConvertAPP {
OrderConvertAPP INSTANCE = Mappers.getMapper(OrderConvertAPP.class);
@Mappings({})
OrderQueryDTO convertPageBO(OrderPageQueryVO orderPageQueryVO);
OrderQueryDTO convertPageBO(OrderPageQueryPO orderPageQueryVO);
@Mappings({})
OrderLogisticsUpdateDTO convertPageBO(OrderLogisticsVO orderLogisticsVO);
OrderLogisticsUpdateDTO convertPageBO(OrderLogisticsPO orderLogisticsVO);
@Mappings({})
OrderItemUpdateDTO convertPageBO(OrderItemUpdateVO orderItemUpdateVO);
OrderItemUpdateDTO convertPageBO(OrderItemUpdatePO orderItemUpdateVO);
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.mall.order.application.convert;
import cn.iocoder.mall.order.api.dto.OrderDeliveryDTO;
import cn.iocoder.mall.order.application.po.OrderDeliverPO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
/**
* @author Sin
* @time 2019-04-05 17:00
*/
@Mapper
public interface OrderDeliveryConvert {
OrderDeliveryConvert INSTANCE = Mappers.getMapper(OrderDeliveryConvert.class);
@Mappings({})
OrderDeliveryDTO convert(OrderDeliverPO orderDeliverPO);
}

View File

@ -0,0 +1,89 @@
package cn.iocoder.mall.order.application.po;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
*
*
* @author Sin
* @time 2019-04-05 16:55
*/
@ApiModel(description = "订单发货PO")
public class OrderDeliverPO implements Serializable {
/**
*
*/
@ApiModelProperty("订单id")
@NotNull(message = "orderId不能为空")
private Integer orderId;
/**
* ()
*/
@ApiModelProperty("物流商家")
@NotNull(message = "必须选择商家")
private Integer logistics;
/**
*
*/
@ApiModelProperty("物流单号")
@NotNull(message = "没有物流单号")
private String logisticsNo;
/**
* items
*/
@ApiModelProperty("订单items")
@NotNull(message = "没有选择发货的商品")
private List<Integer> orderItemIds;
@Override
public String toString() {
return "OrderDeliverPO{" +
"orderId=" + orderId +
", logistics=" + logistics +
", logisticsNo='" + logisticsNo + '\'' +
", orderItemIds=" + orderItemIds +
'}';
}
public Integer getOrderId() {
return orderId;
}
public OrderDeliverPO setOrderId(Integer orderId) {
this.orderId = orderId;
return this;
}
public Integer getLogistics() {
return logistics;
}
public OrderDeliverPO setLogistics(Integer logistics) {
this.logistics = logistics;
return this;
}
public String getLogisticsNo() {
return logisticsNo;
}
public OrderDeliverPO setLogisticsNo(String logisticsNo) {
this.logisticsNo = logisticsNo;
return this;
}
public List<Integer> getOrderItemIds() {
return orderItemIds;
}
public OrderDeliverPO setOrderItemIds(List<Integer> orderItemIds) {
this.orderItemIds = orderItemIds;
return this;
}
}

View File

@ -12,21 +12,9 @@ import java.util.List;
public class OrderDeliveryDTO implements Serializable {
/**
*
* id
*/
private String areaNo;
/**
*
*/
private String name;
/**
*
*/
private String mobile;
/**
*
*/
private String address;
private Integer orderId;
/**
* ()
*/
@ -46,50 +34,20 @@ public class OrderDeliveryDTO implements Serializable {
@Override
public String toString() {
return "OrderDeliverGoodsDTO{" +
"areaNo='" + areaNo + '\'' +
", name='" + name + '\'' +
", mobile='" + mobile + '\'' +
", address='" + address + '\'' +
return "OrderDeliveryDTO{" +
"orderId=" + orderId +
", logistics=" + logistics +
", logisticsNo='" + logisticsNo + '\'' +
", orderItemIds=" + orderItemIds +
'}';
}
public String getAreaNo() {
return areaNo;
public Integer getOrderId() {
return orderId;
}
public OrderDeliveryDTO setAreaNo(String areaNo) {
this.areaNo = areaNo;
return this;
}
public String getName() {
return name;
}
public OrderDeliveryDTO setName(String name) {
this.name = name;
return this;
}
public String getMobile() {
return mobile;
}
public OrderDeliveryDTO setMobile(String mobile) {
this.mobile = mobile;
return this;
}
public String getAddress() {
return address;
}
public OrderDeliveryDTO setAddress(String address) {
this.address = address;
public OrderDeliveryDTO setOrderId(Integer orderId) {
this.orderId = orderId;
return this;
}

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>