From 67157345fe1878681e39ec186ef37ff6b3b5c1fc Mon Sep 17 00:00:00 2001
From: luodangjia <luodangjia>
Date: 星期六, 03 八月 2024 18:07:00 +0800
Subject: [PATCH] 8.3

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java |   70 +++++++++++++++++++++++++++++------
 1 files changed, 58 insertions(+), 12 deletions(-)

diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
index c07ae66..3e416ab 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
@@ -4,7 +4,9 @@
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.common.core.constant.Constants;
 import com.ruoyi.common.core.constant.OrderConstants;
+import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.utils.GaoDeMapUtil;
+import com.ruoyi.common.core.vo.AddressDto;
 import com.ruoyi.common.core.vo.Path;
 import com.ruoyi.order.entity.ChangeDispatch;
 import com.ruoyi.order.entity.Order;
@@ -13,16 +15,20 @@
 import com.ruoyi.order.service.ChangeDispatchService;
 import com.ruoyi.order.service.OrderService;
 import com.ruoyi.order.vo.*;
+import com.ruoyi.user.api.feignClient.UserClient;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.Month;
 import java.time.Year;
 import java.time.temporal.TemporalAdjusters;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Objects;
 
@@ -40,6 +46,8 @@
 
     @Resource
     private ChangeDispatchService changeDispatchService;
+    @Resource
+    private UserClient userClient;
 
     @Override
     public OrderResultVO orderCountHome(OrderCountRequest orderCount) {
@@ -51,15 +59,32 @@
         List<OrderQueryVO> list;
         // 根据查询类型查询订单信息
         if (OrderConstants.YEAR.equals(countType)) {
-            list = baseMapper.orderCountByYear(cityList, orderState, startTime, endTime);
+            list = baseMapper.orderCountByYear(cityList, orderState);
         } else if (OrderConstants.MONTH.equals(countType)) {
-            list = baseMapper.orderCountByMonth(cityList, orderState, startTime, endTime);
+            list = baseMapper.orderCountByMonth(cityList, orderState);
         } else if (OrderConstants.WEEK.equals(countType)) {
-            list = baseMapper.orderCountByWeek(cityList, orderState, startTime, endTime);
+            list = baseMapper.orderCountByWeek(cityList, orderState);
         } else if (OrderConstants.TODAY.equals(countType)) {
-            list = baseMapper.orderCountByToday(cityList, orderState, startTime, endTime);
+            list = baseMapper.orderCountByToday(cityList, orderState);
         } else {
-            list = new ArrayList<>();
+            try {
+                startTime = startTime + " 00:00:00";
+                endTime = endTime + " 00:00:00";
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                Date date1 = sdf.parse(startTime);
+                Date date2 = sdf.parse(endTime);
+                long diffInMillis = date2.getTime() - date1.getTime();
+                long diffInDays = diffInMillis / (24 * 60 * 60 * 1000);
+                if (diffInDays > Constants.YEAR_DAY) {
+                    list = baseMapper.orderCountByTimeRangeYear(cityList, startTime, endTime, orderState);
+                } else if (diffInDays > Constants.THIRTY) {
+                    list = baseMapper.orderCountByTimeRangeMonth(cityList, startTime, endTime, orderState);
+                } else {
+                    list = baseMapper.orderCountByTimeRange(cityList, startTime, endTime, orderState);
+                }
+            } catch (ParseException e) {
+                list = new ArrayList<>();
+            }
         }
         // 计算订单总额及总订单数量
         BigDecimal totalMoney;
@@ -73,7 +98,10 @@
             orderNumber = list.stream().filter(order -> order.getNumber() != null)
                     .mapToInt(OrderQueryVO::getNumber).sum();
         }
-        return new OrderResultVO(totalMoney, orderNumber, list);
+        return new
+
+                OrderResultVO(totalMoney, orderNumber, list);
+
     }
 
     @Override
@@ -108,8 +136,8 @@
 
 
     @Override
-    public Page<OrderCountVO> orderCount(String name, String phone, Page<OrderCountVO> page) {
-        return baseMapper.orderCount(name, phone, page);
+    public Page<OrderCountVO> orderCount(String name, String phone, List<String> cityList, Page<OrderCountVO> page) {
+        return baseMapper.orderCount(name, phone, cityList, page);
     }
 
     @Override
@@ -136,7 +164,7 @@
             } else if (Constants.FOUR.equals(state)) {
                 canceled++;
             }
-            if (order.getIsReinvest() != null && order.getIsReinvest() == 1) {
+            if (order.getState().equals(Constants.SIX)) {
                 reInvestment++;
             }
         }
@@ -222,6 +250,9 @@
 
     @Override
     public Boolean placeOrder(UserOrderRequest userOrderRequest) {
+
+        R<AddressDto> cityCode = userClient.getCityCode(userOrderRequest.getAddressId());
+
         // 下单参数
         String orderNumber = userOrderRequest.getOrderNumber();
         Integer serveId = userOrderRequest.getServeId();
@@ -246,7 +277,7 @@
         order.setUserId(userId);
         order.setReservationName(reservationName);
         order.setReservationPhone(reservationPhone);
-        order.setReservationAddress(address);
+        order.setReservationAddress(address+cityCode.getData().getName());
         order.setTime(time);
         order.setReservationRemark(reservationRemark);
         order.setOrderMoney(defaultPrice.add(new BigDecimal(String.valueOf(subsidy))));
@@ -257,11 +288,23 @@
         order.setIsWithdrawal(Constants.ZERO);
         order.setSubsidy(subsidy);
         order.setAddress(addressDetail);
+        order.setIsEvaluate(Constants.ZERO);
+
+        order.setCity(cityCode.getData().getCity());
+        order.setCityCode(cityCode.getData().getCityCode());
         return this.save(order);
     }
 
+
     @Override
     public String orderEstimate(UserOrderRequest userOrderRequest) {
+        R<AddressDto> cityCode = userClient.getCityCode(userOrderRequest.getAddressId());
+        R<BigDecimal> servePrice = userClient.getServePrice(userOrderRequest.getServeId(), cityCode.getData().getCityCode());
+        if (servePrice.getData()!=null){
+            userOrderRequest.setDefaultPrice(servePrice.getData());
+        }
+
+
         // 下单参数
         String orderNumber = userOrderRequest.getOrderNumber();
         Integer serveId = userOrderRequest.getServeId();
@@ -284,12 +327,13 @@
         order.setServeName(serveName);
         order.setServePrice(defaultPrice);
         order.setUserId(userId);
+        order.setIsEvaluate(Constants.ZERO);
         order.setReservationName(reservationName);
         order.setReservationPhone(reservationPhone);
         if (null == userOrderRequest.getAddressId()) {
-            order.setReservationAddress(addressDetail);
+            order.setReservationAddress(addressDetail+cityCode.getData().getName());
         } else {
-            order.setReservationAddress(address);
+            order.setReservationAddress(address+cityCode.getData().getName());
         }
         order.setTime(time);
         order.setReservationRemark(reservationRemark);
@@ -305,6 +349,8 @@
         order.setIsWithdrawal(Constants.ZERO);
         order.setSubsidy(subsidy);
         order.setAddress(addressDetail);
+        order.setCity(cityCode.getData().getCity());
+        order.setCityCode(cityCode.getData().getCityCode());
         this.save(order);
         return String.valueOf(order.getId());
     }

--
Gitblit v1.7.1