Skip to content

Commit 36c20c4

Browse files
committed
dashboard add matcj data
1 parent 3fdde56 commit 36c20c4

File tree

6 files changed

+27
-13
lines changed

6 files changed

+27
-13
lines changed

CarzyCarServer/src/main/java/com/tastsong/crazycar/controller/BackgroundDashboardController.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import com.tastsong.crazycar.service.BackgroundDashboardService;
1010

11-
import cn.hutool.json.JSONArray;
1211
import cn.hutool.json.JSONObject;
1312

1413
@RestController
@@ -27,18 +26,9 @@ public Object getDashboardData() throws Exception {
2726
data.putOpt("map_num", dashboardService.getMapNum());
2827
data.putOpt("time_trial_times", 99);
2928
data.putOpt("match_times", 44);
30-
int size = 7;
3129
data.putOpt("login_user_num", dashboardService.getUserLoginData(7));
3230
data.putOpt("time_trial_num", dashboardService.getTimeTrialData(7));
33-
34-
JSONArray matchItems = new JSONArray();
35-
for (int i = 0; i < size; i++){
36-
JSONObject item = new JSONObject();
37-
item.putOpt("timestamp", System.currentTimeMillis() - 1000 * 60 * 60 *24 * (7 - i));
38-
item.putOpt("count", (i + 1) * 8);
39-
matchItems.add(item);
40-
}
41-
data.putOpt("match_num", matchItems);
31+
data.putOpt("match_num", dashboardService.getMatchData(7));
4232
return data;
4333
}
4434
}

CarzyCarServer/src/main/java/com/tastsong/crazycar/mapper/MatchMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.List;
44

5+
import com.tastsong.crazycar.model.DataStatisticsModel;
56
import com.tastsong.crazycar.model.MatchMapInfoModel;
67
import com.tastsong.crazycar.model.MatchRankModel;
78
import com.tastsong.crazycar.model.MatchRecordModel;
@@ -18,4 +19,5 @@ public interface MatchMapper {
1819
public Integer delMatchRank(Integer uid, Integer cid);
1920
public List<MatchRankModel> getMatchRankList(Integer uid, Integer cid);
2021
public Integer initMatchRank(Integer uid, Integer cid);
22+
public List<DataStatisticsModel> getMatchData(Integer offsetTime);
2123
}

CarzyCarServer/src/main/java/com/tastsong/crazycar/service/BackgroundDashboardService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.tastsong.crazycar.mapper.AvatarMapper;
99
import com.tastsong.crazycar.mapper.EquipMapper;
10+
import com.tastsong.crazycar.mapper.MatchMapper;
1011
import com.tastsong.crazycar.mapper.TimeTrialMapper;
1112
import com.tastsong.crazycar.mapper.UserMapper;
1213
import com.tastsong.crazycar.model.DataStatisticsModel;
@@ -25,6 +26,9 @@ public class BackgroundDashboardService {
2526
@Autowired
2627
private TimeTrialMapper timeTrialMapper;
2728

29+
@Autowired
30+
private MatchMapper matchMapper;
31+
2832
public Integer getUserNum(){
2933
return userMapper.getAllUserNum();
3034
}
@@ -48,4 +52,8 @@ public List<DataStatisticsModel> getUserLoginData(Integer offsetTime){
4852
public List<DataStatisticsModel> getTimeTrialData(Integer offsetTime){
4953
return timeTrialMapper.getTimeTrialData(offsetTime);
5054
}
55+
56+
public List<DataStatisticsModel> getMatchData(Integer offsetTime){
57+
return matchMapper.getMatchData(offsetTime);
58+
}
5159
}

CarzyCarServer/src/main/resources/mapper/MatchMapper.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,12 @@
7979
(select @rownum:= 0) r
8080
) as history_rank where rownum = 1 and complete_time != -1;
8181
</select>
82+
83+
<select id="getMatchData" parameterType="Integer" resultType="DataStatisticsModel">
84+
select COUNT(*) as count, record_time as timestamp
85+
from match_record
86+
where record_time > (unix_timestamp(CAST(SYSDATE()AS DATE)) - 60 * 60 * 24 * ${offsetTime})
87+
group by FROM_UNIXTIME(record_time, '%y-%m-%d')
88+
order by record_time limit ${offsetTime};
89+
</select>
8290
</mapper>

CrazyCarBackground/src/views/dashboard/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default {
7878
var match_actualData = []
7979
var match_x
8080
for (match_x in match_num) {
81-
var match_time = new Date(match_num[match_x].timestamp)
81+
var match_time = new Date(match_num[match_x].timestamp * 1000)
8282
match_date.push(match_time.getMonth() + '.' + match_time.getDay())
8383
match_actualData.push(match_num[match_x].count)
8484
}

CrazyCarDB/CrazyCar.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,15 @@ insert into match_record ( uid, cid, complete_time, record_time)
524524
(3, 1, 10, 1629544644);
525525
insert into match_record ( uid, cid, complete_time, record_time)
526526
values
527-
(4, 1, 16, 1629544644);
527+
(4, 1, 16, 1658476385);
528528
select record_time from match_record where uid = 1 ;
529529

530+
select COUNT(*) as count, record_time as timestamp
531+
from match_record
532+
where record_time > (unix_timestamp(CAST(SYSDATE()AS DATE)) - 60 * 60 * 24 * 2)
533+
group by FROM_UNIXTIME(record_time, '%y-%m-%d')
534+
order by record_time limit 2;
535+
530536
drop table if exists match_rank_0;
531537
create table match_rank_0 as
532538
select * from (select user_rank.*, @rank_num := @rank_num + 1 as rank_num

0 commit comments

Comments
 (0)