|
@@ -9,7 +9,7 @@ import cn.rankin.data.api.trade.dto.OrderSearchDTO;
|
|
|
import cn.rankin.data.api.trade.dto.UserOrderDTO;
|
|
|
import cn.rankin.data.api.trade.dto.OrderGoodsDTO;
|
|
|
import cn.rankin.data.api.trade.entity.OrderGoods;
|
|
|
-import cn.rankin.data.api.trade.entity.UserOrder;
|
|
|
+import cn.rankin.data.api.trade.entity.Order;
|
|
|
import cn.rankin.tradeservice.code.TradeServiceAPICode;
|
|
|
import cn.rankin.tradeservice.repository.OrderRepository;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -36,17 +36,8 @@ public class OrderService {
|
|
|
private OrderGoodsService orderGoodsService;
|
|
|
|
|
|
@Transactional
|
|
|
- public APIResult<Boolean> pay(String orderId, OrderStatusEnum status) {
|
|
|
- Integer count = 0;
|
|
|
- if (status.equals(OrderStatusEnum.PAYOK)) {
|
|
|
- count = orderRepository.pay(orderId);
|
|
|
- }else if (status.equals(OrderStatusEnum.SEND)) {
|
|
|
- count = orderRepository.send(orderId);
|
|
|
- }else if (status.equals(OrderStatusEnum.RECEIVED)) {
|
|
|
- count = orderRepository.received(orderId);
|
|
|
- }else if (status.equals(OrderStatusEnum.COMPLETE)) {
|
|
|
- count = orderRepository.complete(orderId);
|
|
|
- }
|
|
|
+ public APIResult<Boolean> ok(String orderId) {
|
|
|
+ Integer count = orderRepository.pay(orderId);
|
|
|
if (count > 0) {
|
|
|
return APIResult.ok();
|
|
|
}
|
|
@@ -63,38 +54,38 @@ public class OrderService {
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
- public APIResult<UserOrder> create(UserOrderDTO userOrderDTO) {
|
|
|
- UserOrder userOrder = convert(userOrderDTO);
|
|
|
- userOrder.setStatus(OrderStatusEnum.UNPAID);
|
|
|
- userOrder = orderRepository.saveAndFlush(userOrder);
|
|
|
- String orderId = userOrder.getId();
|
|
|
+ public APIResult<Order> create(UserOrderDTO userOrderDTO) {
|
|
|
+ Order order = convert(userOrderDTO);
|
|
|
+ order.setStatus(OrderStatusEnum.UNPAID);
|
|
|
+ order = orderRepository.saveAndFlush(order);
|
|
|
+ String orderId = order.getId();
|
|
|
List<OrderGoodsDTO> orderGoodsDTOList = userOrderDTO.getGoods();
|
|
|
orderGoodsService.createRelation(orderId, orderGoodsDTOList);
|
|
|
List<OrderGoods> orderGoodsList = orderGoodsService.findByOrderId(orderId);
|
|
|
- userOrder.setGoods(orderGoodsList);
|
|
|
- return APIResult.ok(userOrder);
|
|
|
+ order.setGoods(orderGoodsList);
|
|
|
+ return APIResult.ok(order);
|
|
|
}
|
|
|
|
|
|
- public APIResult<UserOrder> getOrder(String orderId) {
|
|
|
- UserOrder userOrder = orderRepository.find(orderId);
|
|
|
- if (userOrder == null) {
|
|
|
+ public APIResult<Order> getOrder(String orderId) {
|
|
|
+ Order order = orderRepository.find(orderId);
|
|
|
+ if (order == null) {
|
|
|
return APIResult.error(TradeServiceAPICode.NOT_EXISTS);
|
|
|
}
|
|
|
|
|
|
List<OrderGoods> orderGoodsList = orderGoodsService.findByOrderId(orderId);
|
|
|
- userOrder.setGoods(orderGoodsList);
|
|
|
- return APIResult.ok(userOrder);
|
|
|
+ order.setGoods(orderGoodsList);
|
|
|
+ return APIResult.ok(order);
|
|
|
}
|
|
|
|
|
|
- public APIResult<List<UserOrder>> findPayList(Integer limit) {
|
|
|
- List<UserOrder> userOrderList = orderRepository.findPayList(limit);
|
|
|
- if (CollectionUtils.isEmpty(userOrderList)) {
|
|
|
- return APIResult.ok(userOrderList);
|
|
|
+ public APIResult<List<Order>> findPayList(Integer limit) {
|
|
|
+ List<Order> orderList = orderRepository.findPayList(limit);
|
|
|
+ if (CollectionUtils.isEmpty(orderList)) {
|
|
|
+ return APIResult.ok(orderList);
|
|
|
}
|
|
|
|
|
|
List<String> orderIdList = new ArrayList<>();
|
|
|
- for (UserOrder userOrder : userOrderList) {
|
|
|
- orderIdList.add(userOrder.getId());
|
|
|
+ for (Order order : orderList) {
|
|
|
+ orderIdList.add(order.getId());
|
|
|
}
|
|
|
|
|
|
List<OrderGoods> orderGoodsList = orderGoodsService.findByOrderIds(orderIdList);
|
|
@@ -111,25 +102,25 @@ public class OrderService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- for (UserOrder userOrder : userOrderList) {
|
|
|
- String orderId = userOrder.getId();
|
|
|
+ for (Order order : orderList) {
|
|
|
+ String orderId = order.getId();
|
|
|
List<OrderGoods> tmpList = orderGoodsMap.get(orderId);
|
|
|
- userOrder.setGoods(tmpList);
|
|
|
+ order.setGoods(tmpList);
|
|
|
}
|
|
|
|
|
|
- return APIResult.ok(userOrderList);
|
|
|
+ return APIResult.ok(orderList);
|
|
|
}
|
|
|
|
|
|
- public APIResult<Page<UserOrder>> search(OrderSearchDTO searchDTO) {
|
|
|
- Specification<UserOrder> specification = new Specification<UserOrder>() {
|
|
|
+ public APIResult<Page<Order>> search(OrderSearchDTO searchDTO) {
|
|
|
+ Specification<Order> specification = new Specification<Order>() {
|
|
|
@Override
|
|
|
- public Predicate toPredicate(Root<UserOrder> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
+ public Predicate toPredicate(Root<Order> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
return OrderService.this.toPredicate(root, query, cb, searchDTO);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
Long count = orderRepository.count(specification);
|
|
|
- Page<UserOrder> page = new Page<>(count, searchDTO.getPageNo(), searchDTO.getPageSize());
|
|
|
+ Page<Order> page = new Page<>(count, searchDTO.getPageNo(), searchDTO.getPageSize());
|
|
|
|
|
|
Long start = page.getStart();
|
|
|
if (count == 0) {
|
|
@@ -138,13 +129,13 @@ public class OrderService {
|
|
|
|
|
|
LinkedHashMap<String, BaseOrderEnum> sort = new LinkedHashMap<>();
|
|
|
sort.put("gmtModified", BaseOrderEnum.DESC);
|
|
|
- List<UserOrder> userOrderList = orderRepository.find(specification, start, page.getPageSize(), JpaSortUtil.sort(sort));
|
|
|
- page.setList(userOrderList);
|
|
|
+ List<Order> orderList = orderRepository.find(specification, start, page.getPageSize(), JpaSortUtil.sort(sort));
|
|
|
+ page.setList(orderList);
|
|
|
|
|
|
return APIResult.ok(page);
|
|
|
}
|
|
|
|
|
|
- public Predicate toPredicate(Root<UserOrder> root, CriteriaQuery<?> query, CriteriaBuilder cb, OrderSearchDTO searchDTO) {
|
|
|
+ public Predicate toPredicate(Root<Order> root, CriteriaQuery<?> query, CriteriaBuilder cb, OrderSearchDTO searchDTO) {
|
|
|
// 存放查询条件
|
|
|
List<Predicate> list = new ArrayList<Predicate>();
|
|
|
Predicate tmp = null;
|