licailing 5 лет назад
Родитель
Сommit
22bcc135b2

+ 5 - 4
src/main/java/com/izouma/jiashanxia/dto/StatisticDTO.java

@@ -5,14 +5,15 @@ import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
-import java.time.LocalDateTime;
+import java.math.BigDecimal;
+import java.time.LocalDate;
 
 @Data
 @AllArgsConstructor
 @NoArgsConstructor
 @Builder
 public class StatisticDTO {
-    private Long          dayOrder;
-    private Long          dayFee;
-    private LocalDateTime dateTime;
+    private Long       dayOrder;
+    private BigDecimal dayFee;
+    private LocalDate  date;
 }

+ 4 - 0
src/main/java/com/izouma/jiashanxia/repo/WxFeeRepo.java

@@ -5,9 +5,13 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Query;
 
 import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.List;
 
 public interface WxFeeRepo extends JpaRepository<WxFee, String> {
 
     @Query(nativeQuery = true, value = "SELECT SUM(amount) FROM wx_fee WHERE is_refund=false")
     BigDecimal sumByAmount();
+
+    List<WxFee> findAllByCreatedAtBetween(LocalDateTime createdAt, LocalDateTime createdAt2);
 }

+ 29 - 2
src/main/java/com/izouma/jiashanxia/service/StatisticService.java

@@ -1,5 +1,7 @@
 package com.izouma.jiashanxia.service;
 
+import com.izouma.jiashanxia.domain.OrderInfo;
+import com.izouma.jiashanxia.domain.WxFee;
 import com.izouma.jiashanxia.dto.StatisticDTO;
 import com.izouma.jiashanxia.enums.OrderInfoStatus;
 import com.izouma.jiashanxia.repo.CompanyRepo;
@@ -10,6 +12,8 @@ import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -43,9 +47,32 @@ public class StatisticService {
     /*
     每日订单折线图
      */
-    public List<StatisticDTO> dayData(Long day) {
+    public List<StatisticDTO> dayData(Integer day) {
         List<StatisticDTO> dtos = new ArrayList<>();
-        return null;
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime start = LocalDateTime.of(now.toLocalDate().minusDays(day - 1), LocalTime.MIN);
+        List<OrderInfo> orderInfos = orderInfoRepo.findAllByPaidAtBetweenAndStatus(start, now, OrderInfoStatus.PAID);
+        List<WxFee> wxFees = wxFeeRepo.findAllByCreatedAtBetween(start, now);
 
+        while (day > 0) {
+            LocalDateTime end = start.plusDays(1);
+            LocalDateTime finalStart = start;
+            long order = orderInfos.stream()
+                    .filter(orderInfo -> !finalStart.isAfter(orderInfo.getPaidAt()) && end.isAfter(orderInfo.getPaidAt()))
+                    .count();
+            BigDecimal fee = wxFees.stream()
+                    .filter(wxFee -> !finalStart.isAfter(wxFee.getCreatedAt()) && end.isAfter(wxFee.getCreatedAt()))
+                    .map(WxFee::getAmount)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+            dtos.add(StatisticDTO.builder()
+                    .date(finalStart.toLocalDate())
+                    .dayOrder(order)
+                    .dayFee(fee)
+                    .build());
+            day--;
+            start = end;
+        }
+        return dtos;
     }
 }

+ 2 - 2
src/main/resources/application.yaml

@@ -64,8 +64,8 @@ wx:
         msg_format: JSON
     pay:
         appId: wxde386c1d6f9fc0c8
-        mchId: 1529090291
-        mchKey: uDusnGcUqYyWqsBdmvuioxDhtgZErwtu
+        mchId: 1604487424
+        mchKey: SGZSquBjfa8Apt5WkLu5knNUXq8MgGD2
         subAppId: #服务商模式下的子商户公众账号ID
         subMchId: #服务商模式下的子商户号
         keyPath: classpath:/cert/apiclient_cert.p12

+ 7 - 5
src/main/vue/src/views/Dashboard.vue

@@ -42,11 +42,13 @@ export default {
     data() {
         return {
             layout: [
-                { x: 0, y: 0, w: 6, h: 4, i: '0', name: 'UserWidget' },
-                { x: 6, y: 0, w: 6, h: 4, i: '1', name: 'UserWidget' },
-                { x: 0, y: 4, w: 6, h: 6, i: '2', name: 'BarChartWidget' },
-                { x: 0, y: 10, w: 6, h: 6, i: '3', name: 'LineChartWidget' },
-                { x: 6, y: 4, w: 6, h: 12, i: '4', name: 'PieChartWidget' }
+                { x: 0, y: 0, w: 3, h: 4, i: '0', name: 'UserWidget' },
+                { x: 3, y: 0, w: 3, h: 4, i: '1', name: 'UserWidget' },
+                { x: 6, y: 0, w: 3, h: 4, i: '2', name: 'UserWidget' },
+                { x: 9, y: 0, w: 3, h: 4, i: '3', name: 'UserWidget' },
+                { x: 0, y: 4, w: 6, h: 6, i: '4', name: 'BarChartWidget' },
+                { x: 0, y: 10, w: 6, h: 6, i: '5', name: 'LineChartWidget' },
+                { x: 6, y: 4, w: 6, h: 12, i: '6', name: 'PieChartWidget' }
             ],
             editable: false
         };

+ 23 - 0
src/test/java/com/izouma/jiashanxia/service/StatisticServiceTest.java

@@ -0,0 +1,23 @@
+package com.izouma.jiashanxia.service;
+
+import com.izouma.jiashanxia.dto.StatisticDTO;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.List;
+
+@SpringBootTest
+@RunWith(SpringRunner.class)
+public class StatisticServiceTest {
+    @Autowired
+    private StatisticService statisticService;
+
+    @Test
+    public void dayData() {
+        List<StatisticDTO> dtos = statisticService.dayData(7);
+        dtos.forEach(System.out::println);
+    }
+}