Browse Source

UI 查询接口

tianyunperfect 3 years ago
parent
commit
eaa493e8d1

+ 8 - 0
book-dao/src/main/java/com/book/dao/polardb/mapper/Sun2Mapper.java

@@ -8,6 +8,7 @@ import org.springframework.stereotype.Repository;
 
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @Mapper
 @Repository
@@ -95,4 +96,11 @@ public interface Sun2Mapper {
      * @return {@link String}
      */
     String selectIncomeRecharge(@Param("dateStr") String dateStr);
+
+    /**
+     * 回收历史统计
+     *
+     * @return {@link Map}
+     */
+    Map selectHistoryIncome();
 }

+ 3 - 0
book-dao/src/main/resources/mapper/polar/Sun2Mapper.xml

@@ -116,5 +116,8 @@
     <select id="selectIncomeRecharge" resultType="java.lang.String">
         SELECT sum(t.recharge_sum) from sun_static_income_hundred t where t.static_date=#{dateStr};
     </select>
+    <select id="selectHistoryIncome" resultType="java.util.Map">
+        SELECT sum(t.all_recharge) as all_recharge ,sum(t.all_spend) as all_spend FROM sun_static_income t;
+    </select>
 
 </mapper>

+ 20 - 0
book-server/src/main/java/com/book/server/controller/SunDataController.java

@@ -413,6 +413,26 @@ public class SunDataController extends BaseController {
         return Result.success(sunDataService.getUserStaticByDateAndChannel(date));
     }
 
+    /**
+     * 回收统计-按天
+     *
+     * @return {@link Result}
+     */
+    @GetMapping("/getIncomeByDay")
+    public Result getIncomeByDay(int page, int size) {
+        return Result.success(sunDataService.getIncomeByDay(page, size));
+    }
+
+    /**
+     * 回收统计-按渠道
+     *
+     * @return {@link Result}
+     */
+    @GetMapping("/getIncomeByDayChannel")
+    public Result getIncomeByDayChannel(int page, int size,String channelId) {
+        return Result.success(sunDataService.getIncomeByDayChannel(page, size,channelId));
+    }
+
 
     public static void main(String[] args) {
         System.out.println(UUID.randomUUID().toString());

+ 4 - 0
book-server/src/main/java/com/book/server/service/SunDataService.java

@@ -90,4 +90,8 @@ public interface SunDataService {
     SunStaticIncome getYesterdayIncomeStatic();
 
     SunStaticIncome getHistoryIncomeStatic();
+
+    Map getIncomeByDay(int page, int size);
+
+    Map getIncomeByDayChannel(int page, int size, String channelId);
 }

+ 72 - 1
book-server/src/main/java/com/book/server/service/impl/SunDataServiceImpl.java

@@ -31,6 +31,7 @@ import java.nio.charset.StandardCharsets;
 import java.text.ParseException;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
 
 /**
  * created in 2021/9/28
@@ -738,8 +739,78 @@ public class SunDataServiceImpl implements SunDataService {
 
     @Override
     public SunStaticIncome getHistoryIncomeStatic() {
+        Map map = sun2Mapper.selectHistoryIncome();
+        if (map == null) {
+            return null;
+        }
+        float all_recharge = getFloatFromDb(map.get("all_recharge"));
+        float all_spend = getFloatFromDb(map.get("all_spend"));
+        float roi = 0f;
+        if (all_spend != 0) {
+            roi = all_recharge / all_spend;
+        }
+        return SunStaticIncome.builder()
+                .allRecharge(String.format("%.2f", all_recharge))
+                .allSpend(String.format("%.2f", all_spend))
+                .allRoi(String.format("%.2f", roi))
+                .build();
+    }
+
+    @Override
+    public Map getIncomeByDay(int page, int size) {
+        HashMap<String, Object> resMap = new HashMap<>();
+        SunStaticIncomeExample example = SunStaticIncomeExample.newAndCreateCriteria().example();
+        //总共多少条
+        long l = sunStaticIncomeMapper.countByExample(example);
+        resMap.put("total", l);
+        // 排序查询指定页
+        example.orderBy(SunStaticIncome.Column.staticDate.desc());
+        example.page(page, size);
+        List<SunStaticIncome> sunStaticIncomes = sunStaticIncomeMapper.selectByExample(example);
+
+        //查询另一张表对应的前 60 天的数据
+        List<String> collect = sunStaticIncomes.stream().map(SunStaticIncome::getStaticDate).collect(Collectors.toList());
+        List<SunStaticIncomeHundred> sunStaticIncomeHundreds = sunStaticIncomeHundredMapper.selectByExample(
+                SunStaticIncomeHundredExample.newAndCreateCriteria().andStaticDateIn(collect).andDayNumLessThan(61).example());
 
-        return null;
+
+        ArrayList<Object> objects = new ArrayList<>();
+        for (SunStaticIncome sunStaticIncome : sunStaticIncomes) {
+            HashMap<String, Object> map = new HashMap<>();
+            map.put("income", sunStaticIncome);
+            map.put("incomeDay", sunStaticIncomeHundreds.stream().filter(x -> sunStaticIncome.getStaticDate().equals(x.getStaticDate())).collect(Collectors.toList()));
+            objects.add(map);
+        }
+        resMap.put("list", objects);
+        return resMap;
+    }
+
+    @Override
+    public Map getIncomeByDayChannel(int page, int size, String channelId) {
+        HashMap<String, Object> resMap = new HashMap<>();
+        SunStaticIncomeChannelExample example = SunStaticIncomeChannelExample.newAndCreateCriteria().andChannelIdEqualTo(channelId).example();
+        //总共多少条
+        long l = sunStaticIncomeChannelMapper.countByExample(example);
+        resMap.put("total", l);
+        // 排序查询指定页
+        example.orderBy(SunStaticIncomeChannel.Column.staticDate.desc());
+        example.page(page, size);
+        List<SunStaticIncomeChannel> sunStaticIncomes = sunStaticIncomeChannelMapper.selectByExample(example);
+
+        //查询另一张表对应的前 60 天的数据
+        List<String> collect = sunStaticIncomes.stream().map(SunStaticIncomeChannel::getStaticDate).collect(Collectors.toList());
+        List<SunStaticIncomeHundredChannel> sunStaticIncomeHundreds = sunStaticIncomeHundredChannelMapper.selectByExample(
+                SunStaticIncomeHundredChannelExample.newAndCreateCriteria().andStaticDateIn(collect).andChannelIdEqualTo(channelId).andDayNumLessThan(61).example());
+
+        ArrayList<Object> objects = new ArrayList<>();
+        for (SunStaticIncomeChannel sunStaticIncome : sunStaticIncomes) {
+            HashMap<String, Object> map = new HashMap<>();
+            map.put("income", sunStaticIncome);
+            map.put("incomeDay", sunStaticIncomeHundreds.stream().filter(x -> sunStaticIncome.getStaticDate().equals(x.getStaticDate())).collect(Collectors.toList()));
+            objects.add(map);
+        }
+        resMap.put("list", objects);
+        return resMap;
     }
 
     private SunStaticUserDay getSunUserByDate(String startDate, String endDate) {