|
@@ -3,7 +3,7 @@ package cn.rankin.tradeservice.service;
|
|
|
import cn.rankin.common.utils.api.model.APIResult;
|
|
|
import cn.rankin.common.utils.api.page.Page;
|
|
|
import cn.rankin.common.utils.enums.BaseOrderEnum;
|
|
|
-import cn.rankin.common.utils.enums.OrderDetailStatusEnum;
|
|
|
+import cn.rankin.common.utils.enums.OrderStatusEnum;
|
|
|
import cn.rankin.common.utils.util.JpaSortUtil;
|
|
|
import cn.rankin.data.api.trade.dto.OrderDetailSearchDTO;
|
|
|
import cn.rankin.data.api.trade.entity.OrderDetail;
|
|
@@ -11,9 +11,12 @@ import cn.rankin.data.api.trade.entity.OrderGoods;
|
|
|
import cn.rankin.tradeservice.code.TradeServiceAPICode;
|
|
|
import cn.rankin.tradeservice.repository.OrderDetailRepository;
|
|
|
import cn.rankin.tradeservice.repository.OrderGoodsRepository;
|
|
|
+import cn.rankin.tradeservice.repository.OrderRepository;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
@@ -26,6 +29,7 @@ import java.util.Date;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class OrderDetailService {
|
|
|
|
|
@@ -35,6 +39,55 @@ public class OrderDetailService {
|
|
|
@Autowired
|
|
|
private OrderGoodsRepository orderGoodsRepository;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OrderRepository orderRepository;
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public APIResult<Boolean> send(String detailId) {
|
|
|
+ OrderDetail orderDetail = orderDetailRepository.find(detailId);
|
|
|
+ if (orderDetail == null) {
|
|
|
+ return APIResult.error(TradeServiceAPICode.NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer count = orderDetailRepository.send(detailId);
|
|
|
+ if (count == 0) {
|
|
|
+ log.error("update detail order send status error");
|
|
|
+ return APIResult.error(TradeServiceAPICode.UPDATE_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ String orderId = orderDetail.getOrderId();
|
|
|
+ Integer another = orderRepository.send(orderId);
|
|
|
+ if (another == 0) {
|
|
|
+ log.error("update order send status error");
|
|
|
+ return APIResult.error(TradeServiceAPICode.UPDATE_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ return APIResult.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public APIResult<Boolean> receive(String detailId) {
|
|
|
+ OrderDetail orderDetail = orderDetailRepository.find(detailId);
|
|
|
+ if (orderDetail == null) {
|
|
|
+ return APIResult.error(TradeServiceAPICode.NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer count = orderDetailRepository.receive(detailId);
|
|
|
+ if (count == 0) {
|
|
|
+ log.error("update detail order receive status error");
|
|
|
+ return APIResult.error(TradeServiceAPICode.UPDATE_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ String orderId = orderDetail.getOrderId();
|
|
|
+ Integer another = orderRepository.receive(orderId);
|
|
|
+ if (another == 0) {
|
|
|
+ log.error("update order receive status error");
|
|
|
+ return APIResult.error(TradeServiceAPICode.UPDATE_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ return APIResult.ok();
|
|
|
+ }
|
|
|
+
|
|
|
public APIResult<OrderDetail> getOrder(String detailId) {
|
|
|
OrderDetail orderDetail = orderDetailRepository.find(detailId);
|
|
|
if (orderDetail == null) {
|
|
@@ -87,7 +140,13 @@ public class OrderDetailService {
|
|
|
list.add(tmp);
|
|
|
}
|
|
|
|
|
|
- OrderDetailStatusEnum status = searchDTO.getStatus();
|
|
|
+ String cpId = searchDTO.getCpId();
|
|
|
+ if (!StringUtils.isEmpty(cpId)) {
|
|
|
+ tmp = cb.equal(root.get("cpId"), cpId);
|
|
|
+ list.add(tmp);
|
|
|
+ }
|
|
|
+
|
|
|
+ OrderStatusEnum status = searchDTO.getStatus();
|
|
|
if (status != null) {
|
|
|
tmp = cb.equal(root.get("orderStatus"), status);
|
|
|
list.add(tmp);
|