- 添加订单 items 查询api

This commit is contained in:
sin 2019-04-05 14:27:10 +08:00
parent 8418641731
commit fb60682c44
12 changed files with 113 additions and 22 deletions

View File

@ -2,6 +2,7 @@ package cn.iocoder.mall.order.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.order.api.OrderService;
import cn.iocoder.mall.order.api.bo.OrderItemBO;
import cn.iocoder.mall.order.api.bo.OrderPageBO;
import cn.iocoder.mall.order.api.dto.*;
import cn.iocoder.mall.order.application.convert.OrderConvertAPP;
@ -15,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 订单API(admins)
*
@ -36,6 +39,12 @@ public class AdminsOrderController {
return orderService.getOrderPage(orderQueryDTO);
}
@GetMapping("order_items")
@ApiOperation("订单列表")
public CommonResult<List<OrderItemBO>> getOrderItems(@RequestParam("orderId") Integer orderId) {
return orderService.getOrderItems(orderId);
}
@PutMapping("update_remark")
@ApiOperation("更新-更新订单备注")
public CommonResult updateRemark(@RequestParam("orderId") Integer orderId,

View File

@ -2,9 +2,12 @@ package cn.iocoder.mall.order.api;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.order.api.bo.OrderCreateBO;
import cn.iocoder.mall.order.api.bo.OrderItemBO;
import cn.iocoder.mall.order.api.bo.OrderPageBO;
import cn.iocoder.mall.order.api.dto.*;
import java.util.List;
/**
* 订单 service
*
@ -21,6 +24,14 @@ public interface OrderService {
*/
CommonResult<OrderPageBO> getOrderPage(OrderQueryDTO orderQueryDTO);
/**
* 获取订单items
*
* @param orderId
* @return
*/
CommonResult<List<OrderItemBO>> getOrderItems(Integer orderId);
/**
* 订单 - 创建
*
@ -119,4 +130,5 @@ public interface OrderService {
* mq 更新 status
*/
CommonResult listenerExchangeGoods();
}

View File

@ -15,7 +15,8 @@ public enum OrderErrorCodeEnum {
ORDER_GET_SKU_FAIL(1008000001, "获取商品失败!"),
ORDER_GET_SKU_NOT_EXISTENT(1008000002, "获取的商品不存在!"),
ORDER_PAY_AMOUNT_NOT_NEGATIVE(1008000003, "支付金额不能为负数!"),
ORDER_STATUS_NOT_CANCEL(1008000004, "订单状态不能取消"),
ORDER_STATUS_NOT_CANCEL(1008000004, "订单状态不能取消!"),
ORDER_DELIVERY_INCORRECT_DATA(1008000005, "订单发货数据不正确!"),
// order item
ORDER_ITEM_ONLY_ONE(1008000004, "订单Item只有一个!"),

View File

@ -24,6 +24,9 @@ public interface OrderItemConvert {
@Mappings({})
OrderItemDO convert(OrderItemUpdateDTO orderItemUpdateDTO);
@Mappings({})
List<OrderItemBO> convertOrderItemBO(List<OrderItemDO> orderItemDOList);
@Mappings({})
List<OrderItemDO> convert(List<OrderCreateItemDTO> orderCreateItemDTOList);

View File

@ -2,6 +2,7 @@ package cn.iocoder.mall.order.biz.convert;
import cn.iocoder.mall.order.api.bo.OrderLogisticsBO;
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 org.mapstruct.Mapper;
@ -22,7 +23,7 @@ public interface OrderLogisticsConvert {
OrderLogisticsConvert INSTANCE = Mappers.getMapper(OrderLogisticsConvert.class);
@Mappings({})
OrderLogisticsDO convert(OrderCreateDTO orderCreateDTO);
OrderLogisticsDO convert(OrderDeliveryDTO orderDelivery);
@Mappings({})
OrderLogisticsDO convert(OrderLogisticsUpdateDTO orderLogisticsDTO);

View File

@ -48,6 +48,14 @@ public interface OrderItemMapper {
OrderItemDO orderItemDO
);
/**
* 获取 - 根据 ids 查询
*
* @param ids
* @return
*/
List<OrderItemDO> selectByIds(Collection<Integer> ids);
/**
* 查询 - 根据 orderIds status
*

View File

@ -20,10 +20,6 @@ public class OrderDO extends DeletableDO {
* 用户编号
*/
private Integer userId;
/**
* 物流id
*/
private Integer orderLogisticsId;
/**
* 订单编号
*/
@ -85,7 +81,6 @@ public class OrderDO extends DeletableDO {
return "OrderDO{" +
"id=" + id +
", userId=" + userId +
", orderLogisticsId=" + orderLogisticsId +
", orderNo='" + orderNo + '\'' +
", payAmount=" + payAmount +
", paymentTime=" + paymentTime +
@ -116,15 +111,6 @@ public class OrderDO extends DeletableDO {
return this;
}
public Integer getOrderLogisticsId() {
return orderLogisticsId;
}
public OrderDO setOrderLogisticsId(Integer orderLogisticsId) {
this.orderLogisticsId = orderLogisticsId;
return this;
}
public String getOrderNo() {
return orderNo;
}

View File

@ -48,6 +48,10 @@ public class OrderItemDO extends DeletableDO {
* 支付金额实付金额
*/
private Integer payAmount;
/**
* 物流id
*/
private Integer orderLogisticsId;
///
/// 时间信息
@ -99,11 +103,12 @@ public class OrderItemDO extends DeletableDO {
", orderId=" + orderId +
", orderNo='" + orderNo + '\'' +
", skuId=" + skuId +
", skuName=" + skuName +
", skuImage=" + skuImage +
", skuName='" + skuName + '\'' +
", skuImage='" + skuImage + '\'' +
", quantity=" + quantity +
", price=" + price +
", payAmount=" + payAmount +
", orderLogisticsId=" + orderLogisticsId +
", paymentTime=" + paymentTime +
", deliveryTime=" + deliveryTime +
", receiverTime=" + receiverTime +
@ -194,6 +199,15 @@ public class OrderItemDO extends DeletableDO {
return this;
}
public Integer getOrderLogisticsId() {
return orderLogisticsId;
}
public OrderItemDO setOrderLogisticsId(Integer orderLogisticsId) {
this.orderLogisticsId = orderLogisticsId;
return this;
}
public Date getPaymentTime() {
return paymentTime;
}

View File

@ -34,6 +34,10 @@ public class OrderLogisticsDO extends BaseDO {
* 收件详细地址
*/
private String address;
/**
* 物流 (字典)
*/
private Integer logistics;
/**
* 物流编号
*/
@ -48,6 +52,7 @@ public class OrderLogisticsDO extends BaseDO {
", name='" + name + '\'' +
", mobile='" + mobile + '\'' +
", address='" + address + '\'' +
", logistics=" + logistics +
", logisticsNo='" + logisticsNo + '\'' +
'}';
}
@ -106,6 +111,15 @@ public class OrderLogisticsDO extends BaseDO {
return this;
}
public Integer getLogistics() {
return logistics;
}
public OrderLogisticsDO setLogistics(Integer logistics) {
this.logistics = logistics;
return this;
}
public String getLogisticsNo() {
return logisticsNo;
}

View File

@ -105,6 +105,19 @@ public class OrderServiceImpl implements OrderService {
);
}
@Override
public CommonResult<List<OrderItemBO>> getOrderItems(Integer orderId) {
if (orderMapper.selectById(orderId) == null) {
return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_NOT_EXISTENT.getCode());
}
List<OrderItemDO> orderItemDOList = orderItemMapper
.selectByOrderIdAndDeleted(orderId, DeletedStatusEnum.DELETED_NO.getValue());
List<OrderItemBO> orderItemBOList = OrderItemConvert.INSTANCE.convertOrderItemBO(orderItemDOList);
return CommonResult.success(orderItemBOList);
}
@Override
@Transactional
public CommonResult<OrderCreateBO> createOrder(Integer userId, OrderCreateDTO orderCreateDTO) {
@ -132,7 +145,6 @@ public class OrderServiceImpl implements OrderService {
// order
OrderDO orderDO = new OrderDO()
.setUserId(userId)
.setOrderLogisticsId(null)
.setOrderNo(UUID.randomUUID().toString().replace("-", ""))
.setPayAmount(-1) // 先设置一个默认值金额在下面计算
.setClosingTime(null)
@ -265,8 +277,25 @@ public class OrderServiceImpl implements OrderService {
}
@Override
@Transactional
public CommonResult orderDelivery(OrderDeliveryDTO orderDelivery) {
return null;
List<Integer> orderItemIds = orderDelivery.getOrderItemIds();
List<OrderItemDO> orderItemDOList = orderItemMapper.selectByIds(orderItemIds);
if (orderItemDOList.size() != orderItemIds.size()) {
return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_DELIVERY_INCORRECT_DATA.getCode());
}
// 保存物流信息
OrderLogisticsDO orderLogisticsDO = OrderLogisticsConvert.INSTANCE.convert(orderDelivery);
orderLogisticsDO
.setCreateTime(new Date())
.setUpdateTime(null);
orderLogisticsMapper.insert(orderLogisticsDO);
// 关联订单item 物流信息
orderItemMapper.updateByIds(orderItemIds, new OrderItemDO().setOrderLogisticsId(orderLogisticsDO.getId()));
return CommonResult.success(null);
}
@Override

View File

@ -115,6 +115,19 @@
WHERE order_id = #{orderId}
</update>
<!--
获取 - 根据 ids 查询
-->
<select id="selectByIds" resultType="cn.iocoder.mall.order.biz.dataobject.OrderItemDO">
SELECT
<include refid="FIELDS" />
FROM order_item
WHERE `id` IN
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</select>
<!--
查询 - 根据 orderId 下的 item
-->

View File

@ -3,8 +3,9 @@
<mapper namespace="cn.iocoder.mall.order.biz.dao.OrderMapper">
<sql id="FIELDS">
id, user_id, order_logistics_id, order_no, pay_amount, payment_time,
delivery_time, receiver_time, closing_time, has_return_exchange,
id, user_id, order_no, pay_amount, payment_time,
delivery_time, receiver_time, closing_time,
has_return_exchange,
status, remark, create_time, update_time, `deleted`
</sql>