Browse Source

Merge branch 'dev' of xiongzhu/raex_back into master

panhui 4 years ago
parent
commit
0747e813f9

+ 5 - 2
src/main/java/com/izouma/nineth/repo/OrderRepo.java

@@ -46,7 +46,10 @@ public interface OrderRepo extends JpaRepository<Order, Long>, JpaSpecificationE
 
     List<Order> findAllByStatus(OrderStatus status);
 
-    List<Order> findAllByPayTimeBetween(LocalDateTime start, LocalDateTime end);
-
     List<Order> findAllByPayTimeIsAfter(LocalDateTime payTime);
+
+    @Query(nativeQuery = true, value = "select user_id, sum(price) total from raex.order_info " +
+            "where (status = 'FINISH' or status = 'PROCESSING') " +
+            "group by user_id order by sum(price) desc limit 50")
+    List<Object[]> sumPrice();
 }

+ 6 - 0
src/main/java/com/izouma/nineth/repo/TokenHistoryRepo.java

@@ -9,8 +9,10 @@ import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 
 import javax.transaction.Transactional;
+import java.time.LocalDateTime;
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 
 public interface TokenHistoryRepo extends JpaRepository<TokenHistory, Long>, JpaSpecificationExecutor<TokenHistory> {
     List<TokenHistory> findByTokenIdOrderByCreatedAtDesc(String tokenId);
@@ -38,4 +40,8 @@ public interface TokenHistoryRepo extends JpaRepository<TokenHistory, Long>, Jpa
     List<TokenHistory> findError();
 
     List<TokenHistory> findByOperationAndPriceNull(String oper);
+
+    @Query(nativeQuery = true, value = "select to_user_id , to_user, sum(price) total from token_history " +
+            "where created_at between ?1 and ?2 group by to_user_id order by sum(price) desc limit ?3")
+    List<Map<String, Object>> sumPrice(LocalDateTime start, LocalDateTime end, int size);
 }

+ 12 - 4
src/main/java/com/izouma/nineth/service/StatisticService.java

@@ -1,24 +1,24 @@
 package com.izouma.nineth.service;
 
 import cn.hutool.core.collection.CollUtil;
+import com.alibaba.fastjson.JSONObject;
 import com.izouma.nineth.domain.Order;
 import com.izouma.nineth.domain.User;
 import com.izouma.nineth.enums.AuthorityName;
 import com.izouma.nineth.enums.CollectionSource;
 import com.izouma.nineth.enums.OrderStatus;
 import com.izouma.nineth.repo.OrderRepo;
+import com.izouma.nineth.repo.TokenHistoryRepo;
 import com.izouma.nineth.repo.UserRepo;
 import com.izouma.nineth.security.Authority;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
-import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -28,8 +28,9 @@ import java.util.stream.Collectors;
 @AllArgsConstructor
 public class StatisticService {
 
-    private UserRepo  userRepo;
-    private OrderRepo orderRepo;
+    private UserRepo         userRepo;
+    private OrderRepo        orderRepo;
+    private TokenHistoryRepo tokenHistoryRepo;
 
     public Map<String, Object> total() {
         Map<String, Object> total = new HashMap<>();
@@ -114,4 +115,11 @@ public class StatisticService {
         trend.put("transfer", transfer);
         return trend;
     }
+
+    public String top(int year, int month, int size) {
+        LocalDateTime start = LocalDateTime.of(year, month, 1, 0, 0, 0);
+        LocalDateTime end = start.plusMonths(1).minusSeconds(1);
+        List<Map<String, Object>> maps = tokenHistoryRepo.sumPrice(start, end, size);
+        return JSONObject.toJSONString(maps);
+    }
 }

+ 5 - 0
src/main/java/com/izouma/nineth/web/StatisticController.java

@@ -34,4 +34,9 @@ public class StatisticController {
     public Map<String, Map<String, BigDecimal>> orderPriceTrend(int day) {
         return statisticService.orderPriceTrend(day);
     }
+
+    @GetMapping("/top")
+    public String top(int year, int month) {
+        return statisticService.top(year, month, 50);
+    }
 }

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

@@ -38,6 +38,7 @@ import PriceWidget from '../widgets/PriceWidget';
 import LineChartWidget from '../widgets/LineChartWidget';
 import BarChartWidget from '../widgets/BarChartWidget';
 import PieChartWidget from '../widgets/PieChartWidget';
+import TopWidget from '../widgets/TopWidget'
 
 export default {
     created() {},
@@ -48,7 +49,8 @@ export default {
                 { x: 0, y: 0, w: 3, h: 4, i: '2', name: 'PriceWidget' },
                 { x: 3, y: 0, w: 3, h: 4, i: '1', name: 'NumWidget' },
                 // { x: 0, y: 12, w: 6, h: 6, i: '4', name: 'BarChartWidget' },
-                { x: 0, y: 4, w: 6, h: 12, i: '6', name: 'PieChartWidget' }
+                { x: 0, y: 4, w: 6, h: 12, i: '6', name: 'PieChartWidget' },
+                { x: 0, y: 20, w: 12, h: 10, i: '6', name: 'TopWidget' }
             ],
             editable: false,
             info: {}
@@ -73,7 +75,8 @@ export default {
         PriceWidget,
         LineChartWidget,
         BarChartWidget,
-        PieChartWidget
+        PieChartWidget,
+        TopWidget
     }
 };
 </script>

+ 156 - 0
src/main/vue/src/widgets/TopWidget.vue

@@ -0,0 +1,156 @@
+<template>
+    <widget-card :bodyStyle="bodyStyle">
+        <template #header>
+            <div class="header">
+                <span>Top50</span>
+                <el-select
+                    style="width: 120px;"
+                    size="mini"
+                    v-model="value"
+                    @change="changeSelect"
+                    placeholder="请选择"
+                >
+                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
+                    </el-option>
+                </el-select>
+            </div>
+        </template>
+        <div class="list">
+            <div class="empty" v-if="list.length === 0">
+                暂无记录
+            </div>
+            <router-link
+                :to="{
+                    path: '/minterEdit',
+                    query: {
+                        id: item.to_user_id
+                    }
+                }"
+                class="card"
+                v-for="(item, index) in list"
+                :key="index"
+            >
+                <div class="no">NO.{{ index + 1 }}</div>
+                <div class="content">
+                    <div class="text1">{{ item.to_user }}</div>
+                    <div class="text2">{{ item.total }}元</div>
+                </div>
+            </router-link>
+        </div>
+    </widget-card>
+</template>
+<script>
+import { format, parse, addMonths } from 'date-fns';
+import WidgetCard from './WidgetCard';
+
+export default {
+    data() {
+        return {
+            bodyStyle: {
+                overflow: 'auto'
+            },
+            value: '',
+            options: [],
+            list: []
+        };
+    },
+    components: {
+        WidgetCard
+    },
+    mounted() {
+        let options = [];
+        this.value = format(new Date(), 'yyyy-MM');
+        for (let i = 0; i < 7; i++) {
+            options.push({
+                label: format(addMonths(new Date(), 0 - i), 'yyyy-MM'),
+                value: format(addMonths(new Date(), 0 - i), 'yyyy-MM')
+            });
+        }
+        this.options = options;
+
+        this.changeSelect();
+    },
+    methods: {
+        changeSelect() {
+            this.$nextTick(() => {
+                this.$http
+                    .get('/statistic/top', {
+                        year: format(parse(this.value, 'yyyy-MM', new Date()), 'yyyy'),
+                        month: format(parse(this.value, 'yyyy-MM', new Date()), 'M')
+                    })
+                    .then(res => {
+                        this.list = res;
+                    });
+            });
+        }
+    }
+};
+</script>
+<style lang="less" scoped>
+.header {
+    display: flex;
+    justify-content: space-between;
+    align-items: center;
+}
+
+/deep/.el-card {
+    overflow: hidden;
+}
+
+.list {
+    display: flex;
+    flex-wrap: wrap;
+    .card {
+        display: flex;
+        align-items: center;
+        padding: 25px 25px;
+        border-radius: 4px;
+        cursor: pointer;
+        background-color: #f5f7fa;
+        margin: 20px 30px 0 0;
+        border: 1px solid #f2f4f5;
+        box-shadow: 0 2px 10px 0px #f2f4f5;
+        .no {
+            color: #4dcc6f;
+            font-size: 18px;
+            font-weight: bold;
+        }
+        .content {
+            margin-left: 10px;
+            .text1 {
+                font-size: 14px;
+                color: #666666;
+                font-weight: bold;
+                text-align: center;
+            }
+            .text2 {
+                font-size: 16px;
+                color: #000;
+                text-align: center;
+                margin-top: 3px;
+            }
+        }
+
+        &:nth-child(n + 4) {
+            .no {
+                color: #000;
+            }
+        }
+
+        &:hover {
+            box-shadow: 0 2px 10px 0px #feb30e70;
+            .text2 {
+                color: #feb30e;
+                font-weight: bold;
+            }
+        }
+    }
+}
+
+.empty {
+    font-size: 14px;
+    text-align: center;
+    flex-grow: 1;
+    padding: 30px;
+}
+</style>

+ 35 - 0
src/test/java/com/izouma/nineth/repo/OrderRepoTest.java

@@ -0,0 +1,35 @@
+package com.izouma.nineth.repo;
+
+import com.alibaba.fastjson.JSONObject;
+import com.izouma.nineth.ApplicationTests;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.List;
+import java.util.Map;
+
+
+public class OrderRepoTest extends ApplicationTests {
+
+    @Autowired
+    private OrderRepo        orderRepo;
+    @Autowired
+    private TokenHistoryRepo tokenHistoryRepo;
+
+    @Test
+    public void sumPrice() {
+//        System.out.println(orderRepo.sumPrice());
+        List<Object[]> objects = orderRepo.sumPrice();
+        System.out.println(JSONObject.toJSON(objects));
+    }
+
+    @Test
+    public void sumPrice1() {
+        List<Map<String, Object>> objects = tokenHistoryRepo.sumPrice(LocalDateTime.of(LocalDate.of(2022, 3, 1), LocalTime.MIN),
+                LocalDateTime.now(), 3);
+        System.out.println(JSONObject.toJSONString(objects));
+    }
+}