Compare commits
No commits in common. "f9243af8187edcc875a40e4d0c0da0acc9fe7f34" and "86666b8a041ff0f9cd957ee49b96759192d6bfc8" have entirely different histories.
f9243af818
...
86666b8a04
|
|
@ -49,15 +49,10 @@ import static org.apache.dubbo.metadata.report.support.Constants.DEFAULT_METADAT
|
||||||
public class RedisMetadataReport extends AbstractMetadataReport {
|
public class RedisMetadataReport extends AbstractMetadataReport {
|
||||||
|
|
||||||
private static final String REDIS_DATABASE_KEY = "database";
|
private static final String REDIS_DATABASE_KEY = "database";
|
||||||
|
|
||||||
private static final String SENTINEL_KEY = "sentinel";
|
|
||||||
private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(RedisMetadataReport.class);
|
private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(RedisMetadataReport.class);
|
||||||
|
|
||||||
// protected , for test
|
// protected , for test
|
||||||
protected JedisPool pool;
|
protected JedisPool pool;
|
||||||
|
|
||||||
protected JedisSentinelPool sentinelPool;
|
|
||||||
|
|
||||||
private Set<HostAndPort> jedisClusterNodes;
|
private Set<HostAndPort> jedisClusterNodes;
|
||||||
private int timeout;
|
private int timeout;
|
||||||
private String password;
|
private String password;
|
||||||
|
|
@ -80,14 +75,6 @@ public class RedisMetadataReport extends AbstractMetadataReport {
|
||||||
for (URL tmpUrl : urls) {
|
for (URL tmpUrl : urls) {
|
||||||
jedisClusterNodes.add(new HostAndPort(tmpUrl.getHost(), tmpUrl.getPort()));
|
jedisClusterNodes.add(new HostAndPort(tmpUrl.getHost(), tmpUrl.getPort()));
|
||||||
}
|
}
|
||||||
} else if (url.getParameter(SENTINEL_KEY,false)) {
|
|
||||||
Set<String> sentinels = new HashSet<>();
|
|
||||||
List<URL> urls = url.getBackupUrls();
|
|
||||||
for (URL tmpUrl : urls) {
|
|
||||||
sentinels.add(tmpUrl.getHost()+":"+ tmpUrl.getPort());
|
|
||||||
}
|
|
||||||
int database = url.getParameter(REDIS_DATABASE_KEY, 0);
|
|
||||||
sentinelPool = new JedisSentinelPool("mymaster",sentinels ,new GenericObjectPoolConfig<>(), timeout, password, database);
|
|
||||||
} else {
|
} else {
|
||||||
int database = url.getParameter(REDIS_DATABASE_KEY, 0);
|
int database = url.getParameter(REDIS_DATABASE_KEY, 0);
|
||||||
pool = new JedisPool(new JedisPoolConfig(), url.getHost(), url.getPort(), timeout, password, database);
|
pool = new JedisPool(new JedisPoolConfig(), url.getHost(), url.getPort(), timeout, password, database);
|
||||||
|
|
@ -141,25 +128,11 @@ public class RedisMetadataReport extends AbstractMetadataReport {
|
||||||
private void storeMetadata(BaseMetadataIdentifier metadataIdentifier, String v) {
|
private void storeMetadata(BaseMetadataIdentifier metadataIdentifier, String v) {
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
storeMetadataStandalone(metadataIdentifier, v);
|
storeMetadataStandalone(metadataIdentifier, v);
|
||||||
}else if(sentinelPool != null) {
|
|
||||||
storeMetadataInSentinel(metadataIdentifier, v);
|
|
||||||
} else {
|
} else {
|
||||||
storeMetadataInCluster(metadataIdentifier, v);
|
storeMetadataInCluster(metadataIdentifier, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeMetadataInSentinel(BaseMetadataIdentifier metadataIdentifier, String v) {
|
|
||||||
try (Jedis jedisSentinel = sentinelPool.getResource()) {
|
|
||||||
jedisSentinel.set(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), v, jedisParams);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
String msg =
|
|
||||||
"Failed to put " + metadataIdentifier + " to redis cluster " + v + ", cause: " + e.getMessage();
|
|
||||||
logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e);
|
|
||||||
throw new RpcException(msg, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void storeMetadataInCluster(BaseMetadataIdentifier metadataIdentifier, String v) {
|
private void storeMetadataInCluster(BaseMetadataIdentifier metadataIdentifier, String v) {
|
||||||
try (JedisCluster jedisCluster =
|
try (JedisCluster jedisCluster =
|
||||||
new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) {
|
new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) {
|
||||||
|
|
@ -185,24 +158,11 @@ public class RedisMetadataReport extends AbstractMetadataReport {
|
||||||
private void deleteMetadata(BaseMetadataIdentifier metadataIdentifier) {
|
private void deleteMetadata(BaseMetadataIdentifier metadataIdentifier) {
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
deleteMetadataStandalone(metadataIdentifier);
|
deleteMetadataStandalone(metadataIdentifier);
|
||||||
}else if(sentinelPool != null) {
|
|
||||||
deleteMetadataSentinel(metadataIdentifier);
|
|
||||||
} else {
|
} else {
|
||||||
deleteMetadataInCluster(metadataIdentifier);
|
deleteMetadataInCluster(metadataIdentifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteMetadataSentinel(BaseMetadataIdentifier metadataIdentifier) {
|
|
||||||
try (Jedis jedisSentinel = sentinelPool.getResource()) {
|
|
||||||
jedisSentinel.del(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
|
|
||||||
} catch (Throwable e) {
|
|
||||||
String msg = "Failed to delete " + metadataIdentifier + " from redis , cause: " + e.getMessage();
|
|
||||||
logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e);
|
|
||||||
throw new RpcException(msg, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void deleteMetadataInCluster(BaseMetadataIdentifier metadataIdentifier) {
|
private void deleteMetadataInCluster(BaseMetadataIdentifier metadataIdentifier) {
|
||||||
try (JedisCluster jedisCluster =
|
try (JedisCluster jedisCluster =
|
||||||
new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) {
|
new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) {
|
||||||
|
|
@ -227,24 +187,11 @@ public class RedisMetadataReport extends AbstractMetadataReport {
|
||||||
private String getMetadata(BaseMetadataIdentifier metadataIdentifier) {
|
private String getMetadata(BaseMetadataIdentifier metadataIdentifier) {
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
return getMetadataStandalone(metadataIdentifier);
|
return getMetadataStandalone(metadataIdentifier);
|
||||||
}else if(sentinelPool != null) {
|
|
||||||
return getMetadataSentinel(metadataIdentifier);
|
|
||||||
} else {
|
} else {
|
||||||
return getMetadataInCluster(metadataIdentifier);
|
return getMetadataInCluster(metadataIdentifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMetadataSentinel(BaseMetadataIdentifier metadataIdentifier) {
|
|
||||||
try (Jedis jedisSentinel = sentinelPool.getResource()) {
|
|
||||||
return jedisSentinel.get(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
|
|
||||||
} catch (Throwable e) {
|
|
||||||
String msg = "Failed to get " + metadataIdentifier + " from redis , cause: " + e.getMessage();
|
|
||||||
logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e);
|
|
||||||
throw new RpcException(msg, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private String getMetadataInCluster(BaseMetadataIdentifier metadataIdentifier) {
|
private String getMetadataInCluster(BaseMetadataIdentifier metadataIdentifier) {
|
||||||
try (JedisCluster jedisCluster =
|
try (JedisCluster jedisCluster =
|
||||||
new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) {
|
new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) {
|
||||||
|
|
@ -296,8 +243,6 @@ public class RedisMetadataReport extends AbstractMetadataReport {
|
||||||
private boolean storeMapping(String key, String field, String value, String ticket) {
|
private boolean storeMapping(String key, String field, String value, String ticket) {
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
return storeMappingStandalone(key, field, value, ticket);
|
return storeMappingStandalone(key, field, value, ticket);
|
||||||
}else if(sentinelPool != null) {
|
|
||||||
return storeMappingSentinel(key, field, value, ticket);
|
|
||||||
} else {
|
} else {
|
||||||
return storeMappingInCluster(key, field, value, ticket);
|
return storeMappingInCluster(key, field, value, ticket);
|
||||||
}
|
}
|
||||||
|
|
@ -333,33 +278,6 @@ public class RedisMetadataReport extends AbstractMetadataReport {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* use 'watch' to implement cas.
|
|
||||||
* Find information about slot distribution by key.
|
|
||||||
*/
|
|
||||||
private boolean storeMappingSentinel(String key, String field, String value, String ticket) {
|
|
||||||
try (Jedis jedisSentinel = sentinelPool.getResource()) {
|
|
||||||
jedisSentinel.watch(key);
|
|
||||||
String oldValue = jedisSentinel.hget(key, field);
|
|
||||||
if (null == oldValue || null == ticket || oldValue.equals(ticket)) {
|
|
||||||
Transaction transaction = jedisSentinel.multi();
|
|
||||||
transaction.hset(key, field, value);
|
|
||||||
List<Object> result = transaction.exec();
|
|
||||||
if (null != result) {
|
|
||||||
jedisSentinel.publish(buildPubSubKey(), field);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jedisSentinel.unwatch();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
String msg = "Failed to put " + key + ":" + field + " to redis " + value + ", cause: " + e.getMessage();
|
|
||||||
logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e);
|
|
||||||
throw new RpcException(msg, e);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* use 'watch' to implement cas.
|
* use 'watch' to implement cas.
|
||||||
* Find information about slot distribution by key.
|
* Find information about slot distribution by key.
|
||||||
|
|
@ -421,8 +339,6 @@ public class RedisMetadataReport extends AbstractMetadataReport {
|
||||||
private String getMappingData(String key, String field) {
|
private String getMappingData(String key, String field) {
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
return getMappingDataStandalone(key, field);
|
return getMappingDataStandalone(key, field);
|
||||||
}else if(sentinelPool != null) {
|
|
||||||
return getMappingDataSentinel(key, field);
|
|
||||||
} else {
|
} else {
|
||||||
return getMappingDataInCluster(key, field);
|
return getMappingDataInCluster(key, field);
|
||||||
}
|
}
|
||||||
|
|
@ -439,17 +355,6 @@ public class RedisMetadataReport extends AbstractMetadataReport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMappingDataSentinel(String key, String field) {
|
|
||||||
try (Jedis jedisSentinel = sentinelPool.getResource()) {
|
|
||||||
return jedisSentinel.hget(key, field);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
String msg = "Failed to get " + key + ":" + field + " from redis , cause: " + e.getMessage();
|
|
||||||
logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e);
|
|
||||||
throw new RpcException(msg, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private String getMappingDataStandalone(String key, String field) {
|
private String getMappingDataStandalone(String key, String field) {
|
||||||
try (Jedis jedis = pool.getResource()) {
|
try (Jedis jedis = pool.getResource()) {
|
||||||
return jedis.hget(key, field);
|
return jedis.hget(key, field);
|
||||||
|
|
@ -597,14 +502,6 @@ public class RedisMetadataReport extends AbstractMetadataReport {
|
||||||
logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e);
|
logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e);
|
||||||
throw new RpcException(msg, e);
|
throw new RpcException(msg, e);
|
||||||
}
|
}
|
||||||
} else if (sentinelPool != null) {
|
|
||||||
try (Jedis jedisSentinel = sentinelPool.getResource()) {
|
|
||||||
jedisSentinel.subscribe(notifySub, path);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
String msg = "Failed to subscribe " + path + ", cause: " + e.getMessage();
|
|
||||||
logger.error(TRANSPORT_FAILED_RESPONSE, "", "", msg, e);
|
|
||||||
throw new RpcException(msg, e);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
try (JedisCluster jedisCluster = new JedisCluster(
|
try (JedisCluster jedisCluster = new JedisCluster(
|
||||||
jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) {
|
jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig<>())) {
|
||||||
|
|
|
||||||
|
|
@ -23,27 +23,15 @@ dubbo:
|
||||||
address: redis://${spring.data.redis.host}:${spring.data.redis.port}
|
address: redis://${spring.data.redis.host}:${spring.data.redis.port}
|
||||||
group: DUBBO_GROUP
|
group: DUBBO_GROUP
|
||||||
username: dubbo
|
username: dubbo
|
||||||
password: ruoyi123
|
password: ${spring.data.redis.password}
|
||||||
# 集群开关
|
# 集群开关
|
||||||
sentinel: false
|
cluster: false
|
||||||
parameters:
|
parameters:
|
||||||
namespace: ${spring.profiles.active}
|
namespace: ${spring.profiles.active}
|
||||||
database: ${spring.data.redis.database}
|
database: ${spring.data.redis.database}
|
||||||
timeout: ${spring.data.redis.timeout}
|
timeout: ${spring.data.redis.timeout}
|
||||||
backup: 10.129.128.116:26380,10.129.128.115:26380,10.129.128.114:26380
|
# 集群地址 cluster 为 true 生效
|
||||||
# metadata-report:
|
backup: 127.0.0.1:6379,127.0.0.1:6381
|
||||||
# address: redis://${spring.data.redis.host}:${spring.data.redis.port}
|
|
||||||
# group: DUBBO_GROUP
|
|
||||||
# username: dubbo
|
|
||||||
# password: ${spring.data.redis.password}
|
|
||||||
# # 集群开关
|
|
||||||
# cluster: false
|
|
||||||
# parameters:
|
|
||||||
# namespace: ${spring.profiles.active}
|
|
||||||
# database: ${spring.data.redis.database}
|
|
||||||
# timeout: ${spring.data.redis.timeout}
|
|
||||||
# # 集群地址 cluster 为 true 生效
|
|
||||||
# backup: 127.0.0.1:6379,127.0.0.1:6381
|
|
||||||
# 消费者相关配置
|
# 消费者相关配置
|
||||||
consumer:
|
consumer:
|
||||||
# 结果缓存(LRU算法)
|
# 结果缓存(LRU算法)
|
||||||
|
|
@ -55,12 +43,3 @@ dubbo:
|
||||||
retries: 0
|
retries: 0
|
||||||
# 初始化检查
|
# 初始化检查
|
||||||
check: false
|
check: false
|
||||||
|
|
||||||
logging:
|
|
||||||
level:
|
|
||||||
# 设置 Dubbo 核心包的日志级别为 DEBUG
|
|
||||||
org.apache.dubbo: DEBUG
|
|
||||||
# 如果需要更细粒度的调试,可指定元数据报告模块
|
|
||||||
org.apache.dubbo.metadata: DEBUG
|
|
||||||
# Redis 客户端日志(可选)
|
|
||||||
io.lettuce.core: WARN # 避免 Redis 连接日志过多
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ import org.springframework.core.task.VirtualThreadTaskExecutor;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -95,22 +94,6 @@ public class RedisConfiguration {
|
||||||
.setReadMode(clusterServersConfig.getReadMode())
|
.setReadMode(clusterServersConfig.getReadMode())
|
||||||
.setSubscriptionMode(clusterServersConfig.getSubscriptionMode());
|
.setSubscriptionMode(clusterServersConfig.getSubscriptionMode());
|
||||||
}
|
}
|
||||||
// 哨兵模式
|
|
||||||
RedissonProperties.Sentinel sentinel = redissonProperties.getSentinel();
|
|
||||||
if (Objects.nonNull(sentinel)) {
|
|
||||||
config.useSentinelServers()
|
|
||||||
.setNameMapper(new KeyPrefixHandler(redissonProperties.getKeyPrefix()))
|
|
||||||
.setTimeout(sentinel.getTimeout())
|
|
||||||
.setClientName(sentinel.getClientName())
|
|
||||||
.setIdleConnectionTimeout(sentinel.getIdleConnectionTimeout())
|
|
||||||
.setSubscriptionConnectionPoolSize(sentinel.getSubscriptionConnectionPoolSize())
|
|
||||||
.setMasterConnectionMinimumIdleSize(sentinel.getMasterConnectionMinimumIdleSize())
|
|
||||||
.setMasterConnectionPoolSize(sentinel.getMasterConnectionPoolSize())
|
|
||||||
.setSlaveConnectionMinimumIdleSize(sentinel.getSlaveConnectionMinimumIdleSize())
|
|
||||||
.setSlaveConnectionPoolSize(sentinel.getSlaveConnectionPoolSize())
|
|
||||||
.setReadMode(sentinel.getReadMode())
|
|
||||||
.setSubscriptionMode(sentinel.getSubscriptionMode());
|
|
||||||
}
|
|
||||||
log.info("初始化 redis 配置");
|
log.info("初始化 redis 配置");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,6 @@ public class RedissonProperties {
|
||||||
*/
|
*/
|
||||||
private ClusterServersConfig clusterServersConfig;
|
private ClusterServersConfig clusterServersConfig;
|
||||||
|
|
||||||
private Sentinel sentinel;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public static class SingleServerConfig {
|
public static class SingleServerConfig {
|
||||||
|
|
@ -134,60 +132,4 @@ public class RedissonProperties {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
public static class Sentinel {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户端名称
|
|
||||||
*/
|
|
||||||
private String clientName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* master最小空闲连接数
|
|
||||||
*/
|
|
||||||
private int masterConnectionMinimumIdleSize;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* master连接池大小
|
|
||||||
*/
|
|
||||||
private int masterConnectionPoolSize;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* slave最小空闲连接数
|
|
||||||
*/
|
|
||||||
private int slaveConnectionMinimumIdleSize;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* slave连接池大小
|
|
||||||
*/
|
|
||||||
private int slaveConnectionPoolSize;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 连接空闲超时,单位:毫秒
|
|
||||||
*/
|
|
||||||
private int idleConnectionTimeout;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 命令等待超时,单位:毫秒
|
|
||||||
*/
|
|
||||||
private int timeout;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发布和订阅连接池大小
|
|
||||||
*/
|
|
||||||
private int subscriptionConnectionPoolSize;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 读取模式
|
|
||||||
*/
|
|
||||||
private ReadMode readMode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 订阅模式
|
|
||||||
*/
|
|
||||||
private SubscriptionMode subscriptionMode;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,25 @@
|
||||||
package org.dromara.system.controller.system;
|
package org.dromara.system.controller.system;
|
||||||
|
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import jdk.dynalink.linker.LinkerServices;
|
import jdk.dynalink.linker.LinkerServices;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.dromara.common.core.domain.R;
|
import org.dromara.common.core.domain.R;
|
||||||
import org.dromara.common.redis.utils.RedisUtils;
|
import org.dromara.common.redis.utils.RedisUtils;
|
||||||
import org.dromara.common.web.core.BaseController;
|
import org.dromara.common.web.core.BaseController;
|
||||||
import org.dromara.system.domain.DeviceRedis;
|
import org.dromara.system.domain.DeviceRedis;
|
||||||
import org.dromara.system.domain.bo.SysDeptBo;
|
|
||||||
import org.dromara.system.domain.bo.TDeviceBo;
|
import org.dromara.system.domain.bo.TDeviceBo;
|
||||||
import org.dromara.system.domain.vo.*;
|
import org.dromara.system.domain.vo.DeviceStaticsVo;
|
||||||
|
import org.dromara.system.domain.vo.SysDeptVo;
|
||||||
|
import org.dromara.system.domain.vo.SysDictDataVo;
|
||||||
import org.dromara.system.service.*;
|
import org.dromara.system.service.*;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RestController
|
@RestController
|
||||||
|
|
@ -29,50 +34,14 @@ public class IndexStaticsController extends BaseController {
|
||||||
private final IDeviceRedisService redisService;
|
private final IDeviceRedisService redisService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 在线终端数量
|
* 首页顶部统计 全省各个终端数量及在在线数
|
||||||
* */
|
|
||||||
@PostMapping("/onlineCount")
|
|
||||||
public R onlineCount(TDeviceBo deviceInfo){
|
|
||||||
List<TDeviceVo> list = deviceService.queryList(deviceInfo);
|
|
||||||
String keys = "online_users:";
|
|
||||||
//List<String> strs = redisUtil.match(keys);
|
|
||||||
Date date = new Date();
|
|
||||||
Integer count = 0;
|
|
||||||
|
|
||||||
return R.ok(count);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 首页顶部统计 各个终端数量及在在线数
|
|
||||||
* */
|
* */
|
||||||
@GetMapping("/topPan")
|
@GetMapping("/topPan")
|
||||||
public R topPan(){
|
public R topPan(String zzjgdm){
|
||||||
DeviceRedis redis = new DeviceRedis();
|
DeviceRedis redis = new DeviceRedis();
|
||||||
List<DeviceRedisVo> list = redisService.countByCondition(redis);
|
redis.setZzjgdm(zzjgdm);
|
||||||
return R.ok(list);
|
return R.ok(redisService.countByCondition(redis));
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 通过Redis的数据来判断服务是否正常
|
|
||||||
* */
|
|
||||||
@RequestMapping("/serviceStatus")
|
|
||||||
public R serviceStatus(){
|
|
||||||
DeviceRedis redis = new DeviceRedis();
|
|
||||||
List<DeviceRedisVo> list = redisService.countByCondition(redis);
|
|
||||||
List<HashMap> maps = new ArrayList<>();
|
|
||||||
for (DeviceRedisVo redisVo : list) {
|
|
||||||
HashMap map = new HashMap();
|
|
||||||
Integer status = 1;
|
|
||||||
map.put("deviceType",redisVo.getDeviceType());
|
|
||||||
if (0 == redisVo.getOnline()){
|
|
||||||
status = 0;
|
|
||||||
}
|
|
||||||
map.put("status",status);
|
|
||||||
maps.add(map);
|
|
||||||
}
|
|
||||||
return R.ok(maps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -173,47 +142,7 @@ public class IndexStaticsController extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 终端种类占比
|
|
||||||
* */
|
|
||||||
@PostMapping("/deviceTypePen")
|
|
||||||
public R deviceTypePen(TDeviceBo deviceInfo){
|
|
||||||
List<SysDictDataVo> dataList = dictTypeService.selectDictDataByType("zd_device_type");
|
|
||||||
List<HashMap> list = new ArrayList<>();
|
|
||||||
for (SysDictDataVo data : dataList) {
|
|
||||||
HashMap map = new HashMap();
|
|
||||||
deviceInfo.setDeviceType(data.getDictValue());
|
|
||||||
Long count = deviceService.countByCondition(deviceInfo);
|
|
||||||
map.put("name",data.getDictLabel());
|
|
||||||
map.put("value",count);
|
|
||||||
list.add(map);
|
|
||||||
}
|
|
||||||
return R.ok(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
*终端单位分布
|
|
||||||
* */
|
|
||||||
@PostMapping("/deviceBar")
|
|
||||||
public R deviceBar(TDeviceBo deviceInfo){
|
|
||||||
|
|
||||||
SysDeptBo dept = new SysDeptBo();
|
|
||||||
dept.setParentId(deviceInfo.getZzjgdm());
|
|
||||||
//dept.setIsStuck("1");
|
|
||||||
List<SysDeptVo> depts = deptService.selectDeptList(dept);
|
|
||||||
HashMap map = new HashMap();
|
|
||||||
List<String> names = new ArrayList<>();
|
|
||||||
List<Long> datas = new ArrayList<>();
|
|
||||||
for (SysDeptVo sysDept : depts) {
|
|
||||||
names.add(sysDept.getDeptName());
|
|
||||||
deviceInfo.setZzjgdm(sysDept.getDeptId());
|
|
||||||
Long count = deviceService.countByCondition(deviceInfo);
|
|
||||||
datas.add(count);
|
|
||||||
}
|
|
||||||
map.put("name",names);
|
|
||||||
map.put("data",datas);
|
|
||||||
return R.ok(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -124,12 +124,6 @@ public class TDeviceController extends BaseController {
|
||||||
return toAjax(tDeviceService.updateByBo(bo));
|
return toAjax(tDeviceService.updateByBo(bo));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/updateBatch")
|
|
||||||
public R<Void> updateBatch(@RequestBody TDeviceBo deviceInfo){
|
|
||||||
int num = tDeviceService.updateBatch(deviceInfo.getDeviceCode(),deviceInfo.getZzjgdm(),deviceInfo.getZzjgmc());
|
|
||||||
return toAjax(num);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除device
|
* 删除device
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ public class DeviceRedisVo {
|
||||||
|
|
||||||
private String deviceType;
|
private String deviceType;
|
||||||
|
|
||||||
// private String online;
|
private String online;
|
||||||
|
|
||||||
private String zzjgdm;
|
private String zzjgdm;
|
||||||
|
|
||||||
|
|
@ -22,6 +22,6 @@ public class DeviceRedisVo {
|
||||||
|
|
||||||
private Integer co;
|
private Integer co;
|
||||||
|
|
||||||
private Integer online;
|
private Integer onlien;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import org.dromara.system.domain.vo.TDeviceExportVo;
|
||||||
import org.dromara.system.domain.vo.TDeviceVo;
|
import org.dromara.system.domain.vo.TDeviceVo;
|
||||||
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
|
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -36,6 +35,4 @@ public interface TDeviceMapper extends BaseMapperPlus<TDevice, TDeviceVo> {
|
||||||
})
|
})
|
||||||
Page<TDeviceVo> selectPageDevicetList(@Param("page") Page<TDevice> page, @Param(Constants.WRAPPER) Wrapper<TDevice> queryWrapper);
|
Page<TDeviceVo> selectPageDevicetList(@Param("page") Page<TDevice> page, @Param(Constants.WRAPPER) Wrapper<TDevice> queryWrapper);
|
||||||
|
|
||||||
int updateBatch(HashMap<String,Object> map);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,6 @@ public interface ITDeviceService {
|
||||||
*/
|
*/
|
||||||
Boolean updateByBo(TDeviceBo bo);
|
Boolean updateByBo(TDeviceBo bo);
|
||||||
|
|
||||||
int updateBatch(String deviceCodes,String zzjgdm,String zzjgmc);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验并批量删除device信息
|
* 校验并批量删除device信息
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package org.dromara.system.service.impl;
|
package org.dromara.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.convert.Convert;
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
|
@ -191,16 +190,6 @@ public class TDeviceServiceImpl implements ITDeviceService {
|
||||||
return baseMapper.updateById(update) > 0;
|
return baseMapper.updateById(update) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int updateBatch(String deviceCodes, String zzjgdm, String zzjgmc) {
|
|
||||||
String[] ids = Convert.toStrArray(deviceCodes);
|
|
||||||
HashMap<String,Object> map = new HashMap<>();
|
|
||||||
map.put("zzjgdm",zzjgdm);
|
|
||||||
map.put("deviceCode",ids);
|
|
||||||
map.put("zzjgmc",zzjgmc);
|
|
||||||
return baseMapper.updateBatch(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存前的数据校验
|
* 保存前的数据校验
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
<!-- 全省各类设备总数、在线数 -->
|
<!-- 全省各类设备总数、在线数 -->
|
||||||
<select id="countByCondition" resultMap="deviceRedisResult">
|
<select id="countByCondition" resultMap="deviceRedisResult">
|
||||||
SELECT d.dict_label type_name,dict_value device_type,COALESCE(r.co,0) online,COALESCE(td.co,0) co from sys_dict_data d
|
SELECT d.dict_label type_name,dict_value,COALESCE(r.co,0) online,COALESCE(td.co,0) co from sys_dict_data d
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT device_type,count(*) co FROM (
|
SELECT device_type,count(*) co FROM (
|
||||||
SELECT * FROM t_device_redis
|
SELECT * FROM t_device_redis
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,4 @@
|
||||||
${ew.getCustomSqlSegment}
|
${ew.getCustomSqlSegment}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<update id="updateBatch" parameterType="map">
|
|
||||||
update t_device set zzjgdm = #{zzjgdm},zzjgmc = #{zzjgmc}
|
|
||||||
where device_code in
|
|
||||||
<foreach item="deviceCode" collection="deviceCode" open="(" separator="," close=")">
|
|
||||||
#{deviceCode}
|
|
||||||
</foreach>
|
|
||||||
</update>
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue