Browse Source

首页统计数据错误修复

master
La123123 1 month ago
parent
commit
f4d26db4f2
  1. 18
      im-admin-ui/src/views/index.vue
  2. 3
      im-admin/ruoyi-admin/src/main/resources/application.yml
  3. 9
      im-admin/ruoyi-im/src/main/java/org/dromara/im/mapper/ImUserMapper.java
  4. 7
      im-admin/ruoyi-im/src/main/java/org/dromara/im/service/impl/ImAgentServiceImpl.java
  5. 5
      im-admin/ruoyi-im/src/main/java/org/dromara/im/service/impl/ImUserServiceImpl.java

18
im-admin-ui/src/views/index.vue

@ -70,7 +70,7 @@
<el-col :span="24"> <el-col :span="24">
<el-card> <el-card>
<template #header> <template #header>
<span>用户注册</span> <span>用户新增</span>
<el-select v-model="registrationSelectedDays" style="width: 100px; float: right" size="small" @change="loadRegistrationChartData"> <el-select v-model="registrationSelectedDays" style="width: 100px; float: right" size="small" @change="loadRegistrationChartData">
<el-option label="7天" :value="7"></el-option> <el-option label="7天" :value="7"></el-option>
<el-option label="15天" :value="15"></el-option> <el-option label="15天" :value="15"></el-option>
@ -225,7 +225,7 @@ const processChartData = (privateData: any[], groupData: any[]) => {
return { dates, privateCounts, groupCounts }; return { dates, privateCounts, groupCounts };
}; };
// //
const loadRegistrationChartData = async () => { const loadRegistrationChartData = async () => {
try { try {
const response = await getDailyRegistrationCount(registrationSelectedDays.value); const response = await getDailyRegistrationCount(registrationSelectedDays.value);
@ -248,11 +248,11 @@ const loadRegistrationChartData = async () => {
}); });
} }
} catch (error) { } catch (error) {
console.error('加载用户注册统计图表数据失败:', error); console.error('加载用户新增统计图表数据失败:', error);
} }
}; };
// //
const processRegistrationChartData = (data: any[]) => { const processRegistrationChartData = (data: any[]) => {
const dates: string[] = []; const dates: string[] = [];
const counts: number[] = []; const counts: number[] = [];
@ -393,7 +393,7 @@ onMounted(() => {
initRegistrationChart(); initRegistrationChart();
}); });
// //
const initRegistrationChart = async () => { const initRegistrationChart = async () => {
await nextTick(); await nextTick();
if (registrationChartContainer.value) { if (registrationChartContainer.value) {
@ -401,14 +401,14 @@ const initRegistrationChart = async () => {
const option = { const option = {
title: { title: {
text: '每日用户注册趋势', text: '每日用户新增趋势',
left: 'center' left: 'center'
}, },
tooltip: { tooltip: {
trigger: 'axis', trigger: 'axis',
formatter: (params: any) => { formatter: (params: any) => {
const data = params[0]; const data = params[0];
return `${data.name}<br/>注册用户: ${data.value}`; return `${data.name}<br/>新增用户: ${data.value}`;
} }
}, },
xAxis: { xAxis: {
@ -422,11 +422,11 @@ const initRegistrationChart = async () => {
}, },
yAxis: { yAxis: {
type: 'value', type: 'value',
name: '注册用户数' name: '新增用户数'
}, },
series: [ series: [
{ {
name: '注册用户', name: '新增用户',
type: 'line', type: 'line',
data: [], data: [],
smooth: true, smooth: true,

3
im-admin/ruoyi-admin/src/main/resources/application.yml

@ -132,6 +132,9 @@ mybatis-plus:
# 主键类型 # 主键类型
# AUTO 自增 NONE 空 INPUT 用户输入 ASSIGN_ID 雪花 ASSIGN_UUID 唯一 UUID # AUTO 自增 NONE 空 INPUT 用户输入 ASSIGN_ID 雪花 ASSIGN_UUID 唯一 UUID
idType: AUTO idType: AUTO
# configuration:
# # 这个配置是 MyBatis 原生的配置项,用于开启标准日志工厂
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 数据加密 # 数据加密
mybatis-encryptor: mybatis-encryptor:

9
im-admin/ruoyi-im/src/main/java/org/dromara/im/mapper/ImUserMapper.java

@ -25,6 +25,7 @@ public interface ImUserMapper extends BaseMapperPlus<ImUser, ImUserVo> {
@Select("SELECT DATE(created_time) as date, COUNT(*) as count " + @Select("SELECT DATE(created_time) as date, COUNT(*) as count " +
"FROM im_user " + "FROM im_user " +
"WHERE created_time >= DATE_SUB(CURDATE(), INTERVAL #{days} DAY) " + "WHERE created_time >= DATE_SUB(CURDATE(), INTERVAL #{days} DAY) " +
"AND is_customer = 1 " +
"GROUP BY DATE(created_time) " + "GROUP BY DATE(created_time) " +
"ORDER BY date ASC") "ORDER BY date ASC")
List<Map<String, Object>> getDailyRegistrationCount(@Param("days") Integer days); List<Map<String, Object>> getDailyRegistrationCount(@Param("days") Integer days);
@ -32,15 +33,15 @@ public interface ImUserMapper extends BaseMapperPlus<ImUser, ImUserVo> {
/** /**
* 按天统计用户注册数量带uniqueToken条件 * 按天统计用户注册数量带uniqueToken条件
* @param days 统计天数 * @param days 统计天数
* @param uniqueToken 唯一标识 * @param unique_token 唯一标识
* @return 统计结果 * @return 统计结果
*/ */
@Select("SELECT DATE(created_time) as date, COUNT(*) as count " + @Select("SELECT DATE(created_time) as date, COUNT(*) as count " +
"FROM im_user " + "FROM im_user " +
"WHERE created_time >= DATE_SUB(CURDATE(), INTERVAL #{days} DAY) " + "WHERE is_customer = 1 AND unique_token = #{unique_token}" +
"AND unique_token = #{uniqueToken} " + "AND created_time >= DATE_SUB(CURDATE(), INTERVAL #{days} DAY)" +
"GROUP BY DATE(created_time) " + "GROUP BY DATE(created_time) " +
"ORDER BY date ASC") "ORDER BY date ASC")
List<Map<String, Object>> getDailyRegistrationCount(@Param("days") Integer days, @Param("uniqueToken") String uniqueToken); List<Map<String, Object>> getDailyRegistrationCountByToken(@Param("days") Integer days, @Param("unique_token") String unique_token);
} }

7
im-admin/ruoyi-im/src/main/java/org/dromara/im/service/impl/ImAgentServiceImpl.java

@ -144,10 +144,11 @@ public class ImAgentServiceImpl implements IImAgentService {
Long userId = LoginHelper.getUserId(); Long userId = LoginHelper.getUserId();
if(userId == null){ if(userId == null){
System.out.println("userId is null");
return "error"; return "error";
} }
if(userId == 1){ if(LoginHelper.isSuperAdmin()){
return null; return null;
} }
@ -165,6 +166,7 @@ public class ImAgentServiceImpl implements IImAgentService {
ImAgent agent = baseMapper.selectOne(new LambdaQueryWrapper<ImAgent>().eq(ImAgent::getSysId, userId)); ImAgent agent = baseMapper.selectOne(new LambdaQueryWrapper<ImAgent>().eq(ImAgent::getSysId, userId));
String token = "error"; String token = "error";
System.out.println("走到error");
if(ObjectUtil.isNotNull(agent)){ if(ObjectUtil.isNotNull(agent)){
String uniqueToken = agent.getUniqueToken(); String uniqueToken = agent.getUniqueToken();
if(ObjectUtil.isNotEmpty(uniqueToken)){ if(ObjectUtil.isNotEmpty(uniqueToken)){
@ -173,7 +175,8 @@ public class ImAgentServiceImpl implements IImAgentService {
RedisUtils.setCacheObject(cacheKey, token, Duration.ofHours(1)); RedisUtils.setCacheObject(cacheKey, token, Duration.ofHours(1));
} }
} }
System.out.println("走到末尾");
System.out.println(token);
return token; return token;
} }

5
im-admin/ruoyi-im/src/main/java/org/dromara/im/service/impl/ImUserServiceImpl.java

@ -202,10 +202,13 @@ public class ImUserServiceImpl implements IImUserService {
// 如果不是超级管理员,则使用带uniqueToken的方法 // 如果不是超级管理员,则使用带uniqueToken的方法
if(!LoginHelper.isSuperAdmin()) { if(!LoginHelper.isSuperAdmin()) {
System.out.println("1111111111");
String uniqueToken = imAgentService.getTokenByUserId(); String uniqueToken = imAgentService.getTokenByUserId();
return baseMapper.getDailyRegistrationCount(days, uniqueToken); System.out.println(uniqueToken);
return baseMapper.getDailyRegistrationCountByToken(days, uniqueToken);
} }
System.out.println("222222222222");
return baseMapper.getDailyRegistrationCount(days); return baseMapper.getDailyRegistrationCount(days);
} }

Loading…
Cancel
Save