소스 검색

直播积分消耗

yuhongqi 3 일 전
부모
커밋
c5f3b28066

+ 1 - 0
fs-service-system/src/main/java/com/fs/live/domain/LiveRewardRecord.java

@@ -57,6 +57,7 @@ public class LiveRewardRecord extends BaseEntity{
     private BigDecimal afterNum;
 
     private String liveName;
+    private String companyName;
 
 
 }

+ 5 - 3
fs-service-system/src/main/java/com/fs/live/mapper/LiveRewardRecordMapper.java

@@ -66,9 +66,10 @@ public interface LiveRewardRecordMapper {
     int deleteLiveRewardRecordByIds(Long[] ids);
 
     @Select({
-            "<script> SELECT lrr.*, l.live_name ",
+            "<script> SELECT lrr.*, l.live_name,ifnull(c.company_name,'总台') as company_name ",
             "FROM live_reward_record lrr ",
             "LEFT JOIN live l ON lrr.live_id = l.live_id ",
+            " left join company c on l.company_id=c.company_id ",
             "WHERE lrr.source_id = #{companyId} ",
             "AND DATE_FORMAT(lrr.create_time, '%Y-%m') IN ",
             "<foreach collection='step' item='date' open='(' separator=',' close=')'>",
@@ -78,9 +79,10 @@ public interface LiveRewardRecordMapper {
     List<LiveRewardRecord> selectLiveRewardRecordListByCompanyId(@Param("step") List<Date> step,@Param("companyId") Long companyId);
 
     @Select({
-            "<script> SELECT lrr.*, l.live_name ",
+            "<script> SELECT lrr.*, l.live_name,ifnull(c.company_name,'总台') as company_name",
             "FROM live_reward_record lrr ",
-            "LEFT JOIN live l ON lrr.live_id = l.live_id ",
+            "LEFT JOIN live l ON lrr.live_id = l.live_id " ,
+            " left join company c on l.company_id=c.company_id " ,
             "WHERE ",
             " DATE_FORMAT(lrr.create_time, '%Y-%m') IN ",
             "<foreach collection='step' item='date' open='(' separator=',' close=')'>",

+ 4 - 4
fs-service-system/src/main/java/com/fs/live/mapper/LiveTrafficLogMapper.java

@@ -64,21 +64,21 @@ public interface LiveTrafficLogMapper
     public int deleteLiveTrafficLogByIds(Long[] logIds);
 
     @Select({"<script> " +
-            " select c.company_name, SUM(l.internet_traffic) AS total_internet_traffic" +
+            " select ifnull(c.company_name,'总台') as company_name, SUM(l.internet_traffic) AS total_internet_traffic" +
             " ,DATE_FORMAT(l.create_time, '%Y-%m') AS `month`  from live_traffic_log l " +
             " left join live lv on lv.live_id = l.live_id " +
             " left join company c on c.company_id = lv.company_id " +
             " where 1 = 1 " +
-            " <if test= 'maps.time != null '>" +
+            " <if test= 'maps.year != null '>" +
             " and YEAR(l.create_time) = #{maps.year} " +
             " </if>" +
             " <if test= 'maps.month != null '>"+
             " and MONTH(l.create_time) = #{maps.month} " +
             " </if>" +
             " <if test = ' maps.companyId !=null '> " +
-            " and l.company_id = #{maps.companyId} " +
+            " and c.company_id = #{maps.companyId} " +
             " </if>" +
-            " group by l.company_id,`month` "+
+            " group by c.company_name,`month` "+
             " </script>"})
     List<LiveTrafficLogListVO> selectTrafficByCompany(@Param("maps") LiveTrafficLogParam param);
 

+ 18 - 13
fs-service-system/src/main/java/com/fs/live/service/impl/LiveRewardRecordServiceImpl.java

@@ -105,24 +105,24 @@ public class LiveRewardRecordServiceImpl implements ILiveRewardRecordService {
     public R statistics(LiveRewardRecordVo param) {
         SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM");
         List<LiveRewardRecord> liveRewardRecords;
+        if(param.getCompanyId() == null) param.setCompanyId(0L);
         if (param.getCompanyId() == 0L) {
             liveRewardRecords = baseMapper.selectLiveRewardRecordListByStep(param.getStep());
         } else {
             liveRewardRecords = baseMapper.selectLiveRewardRecordListByCompanyId(param.getStep(), param.getCompanyId());
         }
-        Map<String, Map<String, BigDecimal>> monthLiveMap = liveRewardRecords.stream()
-                // 第一层:按liveId分组
+        Map<Long, Map<String, BigDecimal>> monthLiveMap = liveRewardRecords.stream()
                 .collect(Collectors.groupingBy(
-                        LiveRewardRecord::getLiveName,
-                        // 第二层:在每个liveId分组内按天统计
+                        LiveRewardRecord::getLiveId,
                         Collectors.groupingBy(
                                 record -> dayFormat.format(record.getCreateTime()),
                                 Collectors.reducing(BigDecimal.ZERO, LiveRewardRecord::getNum, BigDecimal::add)
                         )
                 ));
+        Map<Long, LiveRewardRecord> compnayNameMap = liveRewardRecords.stream().collect(Collectors.toMap(LiveRewardRecord::getLiveId, item -> item,(existing, replacement) -> replacement  ));
         // 1. 生成完整的时间序列(天或月)
         List<String> timeSeries = generateMonthTimeSeries(param.getStep(), dayFormat);
-        List<LiveRewardRecordVo> dayLiveList = formatNestedMap(monthLiveMap, timeSeries);
+        List<LiveRewardRecordVo> dayLiveList = formatNestedMap(monthLiveMap, timeSeries,compnayNameMap);
         return R.ok().put("data", dayLiveList).put("timeSeries",timeSeries);
     }
 
@@ -133,17 +133,22 @@ public class LiveRewardRecordServiceImpl implements ILiveRewardRecordService {
 
 
     // 将嵌套Map(liveId -> 时间->数值)转换为List<LiveTimeData>(每个liveId对应完整时间序列)
-    private List<LiveRewardRecordVo> formatNestedMap(Map<String, Map<String, BigDecimal>> nestedMap, List<String> timeSeries) {
+    private List<LiveRewardRecordVo> formatNestedMap(Map<Long, Map<String, BigDecimal>> nestedMap, List<String> timeSeries,Map<Long, LiveRewardRecord> compnayNameMap) {
         return nestedMap.entrySet().stream()
                 .map(entry -> {
-                    String key = entry.getKey();
-                    Map<String, BigDecimal> timeDataMap = entry.getValue();
-                    // 为当前liveId生成完整时间序列的数值列表(缺失补0)
-                    List<BigDecimal> dataList = timeSeries.stream()
-                            .map(time -> timeDataMap.getOrDefault(time, BigDecimal.ZERO))
-                            .collect(Collectors.toList());
-                    return new LiveRewardRecordVo(key, dataList);
+                    Long liveId = entry.getKey();
+                    LiveRewardRecord liveRewardRecord = compnayNameMap.get(liveId);
+                    if (liveRewardRecord != null) {
+                        Map<String, BigDecimal> timeDataMap = entry.getValue();
+                        // 为当前liveId生成完整时间序列的数值列表(缺失补0)
+                        List<BigDecimal> dataList = timeSeries.stream()
+                                .map(time -> timeDataMap.getOrDefault(time, BigDecimal.ZERO))
+                                .collect(Collectors.toList());
+                        return new LiveRewardRecordVo(liveRewardRecord.getLiveName(), dataList,liveRewardRecord.getCompanyName());
+                    }
+                    return null;
                 })
+                .filter(Objects::nonNull)
                 .collect(Collectors.toList());
     }
     // 生成从start到end的所有月份(yyyy-MM)

+ 3 - 1
fs-service-system/src/main/java/com/fs/live/vo/LiveRewardRecordVo.java

@@ -21,12 +21,14 @@ public class LiveRewardRecordVo {
     private List<BigDecimal> dataList;
     private List<Date> step;
     private Long companyId;
+    private String companyName;
 
     public LiveRewardRecordVo() {
     }
 
-    public LiveRewardRecordVo(String liveNameAndId, List<BigDecimal> dataList) {
+    public LiveRewardRecordVo(String liveNameAndId, List<BigDecimal> dataList, String companyName) {
         this.liveNameAndId = liveNameAndId;
         this.dataList = dataList;
+        this.companyName = companyName;
     }
 }