修改redis 配置以及websocket信息

master
bmpandlcm 1 year ago
parent 54400024c7
commit 3973955d2a

@ -11,18 +11,15 @@
<component name="ChangeListManager">
<list default="true" id="29bcb86b-1634-41e0-a498-79481163cba8" name="Changes" comment="修改附件查询地址">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/config/RedisSessionConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/config/RedisSessionConfig.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/controller/QcodeInfoController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/controller/QcodeInfoController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/controller/UserController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/controller/UserController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/controller/UserVehicleController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/controller/UserVehicleController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/ApponintmentInfoServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/ApponintmentInfoServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/RotationServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/RotationServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/SerivceAreaOperationMealServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/SerivceAreaOperationMealServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/ServiceAreaPicServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/ServiceAreaPicServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/controller/WebSocketRedis.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/controller/WebSocketRedis.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/QCodeInfoServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/QCodeInfoServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/ServiceAreaServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/ServiceAreaServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/ServiceAreaSpecialServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/ServiceAreaSpecialServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/SolveUserAndVehcleServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/SolveUserAndVehcleServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/UserTableServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/UserTableServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/UserVehicleServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/UserVehicleServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/util/ImageUtils.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/util/ImageUtils.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/nmgs/util/redisConfigUtil.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/nmgs/util/redisConfigUtil.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/static/application.properties" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/static/application.properties" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -519,7 +516,7 @@
<workItem from="1728605829375" duration="862000" />
<workItem from="1728607523010" duration="7179000" />
<workItem from="1728692165883" duration="9764000" />
<workItem from="1728865362356" duration="597000" />
<workItem from="1728865362356" duration="17966000" />
</task>
<task id="LOCAL-00001" summary="特请处理">
<option name="closed" value="true" />
@ -577,7 +574,15 @@
<option name="project" value="LOCAL" />
<updated>1727602958566</updated>
</task>
<option name="localTasksCounter" value="8" />
<task id="LOCAL-00008" summary="修改附件查询地址">
<option name="closed" value="true" />
<created>1728871055602</created>
<option name="number" value="00008" />
<option name="presentableId" value="LOCAL-00008" />
<option name="project" value="LOCAL" />
<updated>1728871055602</updated>
</task>
<option name="localTasksCounter" value="9" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -602,9 +607,9 @@
<option name="timeStamp" value="20" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/nmgs/service/impl/QCodeInfoServiceImpl.java</url>
<line>1150</line>
<option name="timeStamp" value="32" />
<url>jar://$PROJECT_DIR$/../../apache-maven-3.8.6/repository/org/springframework/data/spring-data-redis/2.7.11/spring-data-redis-2.7.11.jar!/org/springframework/data/redis/connection/jedis/JedisConnectionFactory.class</url>
<line>111</line>
<option name="timeStamp" value="34" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>

@ -205,7 +205,7 @@
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.1</version>
<!-- <version>2.7.1</version>-->
</dependency>
<!--httpclient-->
<dependency>

@ -5,18 +5,16 @@ import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nmgs.util.LogUtil;
import com.nmgs.util.PropertiesUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.RedisNode;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;
@ -24,7 +22,12 @@ import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import java.util.Map;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static com.nmgs.util.WebServiceUtil.logger;
@Component
@EnableCaching
@ -41,23 +44,74 @@ public class RedisSessionConfig extends CachingConfigurerSupport {
timeout=Integer.parseInt(PropertiesUtil.getValue("redis.timeout"));
}
// 配置Redis连接工厂
@Bean
/* @Bean
public RedisConnectionFactory redisConnectionFactory() {
// 创建Redis的单机配置
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(host, port);
config.setPassword(password);
// 返回Lettuce连接工厂
return new LettuceConnectionFactory(config);
}*/
private static List<String> nodes = Arrays.asList(PropertiesUtil.getValue("redis.sentinel.nodes").split(","));
@Bean
public JedisPoolConfig getRedisConfig() {
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
// 最大空闲数
jedisPoolConfig.setMaxIdle(1000);
// 连接池的最大数据库连接数
jedisPoolConfig.setMaxTotal(100000);
// 最大建立连接等待时间
jedisPoolConfig.setMaxWaitMillis(5 * 1000);
// 逐出连接的最小空闲时间 默认1800000毫秒(30分钟)
jedisPoolConfig.setMinEvictableIdleTimeMillis(1800000);
// 每次逐出检查时 逐出的最大数目 如果为负数就是 : 1/abs(n), 默认3
jedisPoolConfig.setNumTestsPerEvictionRun(3);
// 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1
jedisPoolConfig.setTimeBetweenEvictionRunsMillis(-1);
// 是否在从池中取出连接前进行检验,如果检验失败,则从池中去除连接并尝试取出另一个
jedisPoolConfig.setTestOnBorrow(true);
// 在空闲时检查有效性, 默认false
jedisPoolConfig.setTestWhileIdle(false);
return jedisPoolConfig;
}
@Bean
public static RedisSentinelConfiguration sentinelConfiguration() {
RedisSentinelConfiguration redisSentinelConfiguration = new RedisSentinelConfiguration();
//配置matser的名称
redisSentinelConfiguration.master("mymaster");
//配置redis的哨兵sentinel
Set<RedisNode> redisNodeSet = new HashSet<>();
nodes.forEach(x -> {
redisNodeSet.add(new RedisNode(x.split(":")[0], Integer.parseInt(x.split(":")[1])));
});
System.out.println("redisNodeSet -->" + redisNodeSet);
redisSentinelConfiguration.setSentinels(redisNodeSet);
redisSentinelConfiguration.setPassword("nmgjtjt");
return redisSentinelConfiguration;
}
@Bean
public JedisConnectionFactory jedisConnectionFactory(JedisPoolConfig jedisPoolConfig, RedisSentinelConfiguration sentinelConfig) {
JedisConnectionFactory jedisConnectionFactory = null;
try {
jedisConnectionFactory = new JedisConnectionFactory(sentinelConfig, jedisPoolConfig);
} catch (Exception e) {
e.printStackTrace();
}
return jedisConnectionFactory;
}
// 配置RedisTemplate
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
public RedisTemplate<String, Object> redisTemplate(JedisConnectionFactory connectionFactory) {
// 创建RedisTemplate实例
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
Jackson2JsonRedisSerializer jacksonSeial = new Jackson2JsonRedisSerializer(Object.class);
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
ObjectMapper om = new ObjectMapper();
@ -74,24 +128,26 @@ public class RedisSessionConfig extends CachingConfigurerSupport {
}
@Bean
RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
RedisMessageListenerContainer container(JedisConnectionFactory connectionFactory) {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
return container;
}
public static Jedis jedisResource() {
try{
try {
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxTotal(10000);//最大连接数
jedisPoolConfig.setMaxIdle(1000);//最大空闲数
JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port,timeout,"nmgjtjt");
JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, "nmgjtjt");
Jedis resource = jedisPool.getResource();
resource.auth("nmgjtjt");
return resource;
}catch (Exception e){
LogUtil.WriteLog_Error("redis连接出错了======"+e.getMessage(),"redisConfigUtil");
} catch (Exception e) {
LogUtil.WriteLog_Error("redis连接出错了======" + e.getMessage(), "redisConfigUtil");
return null;
}
}
}

@ -29,8 +29,8 @@ public class QcodeInfoController {
)
@ApiOperation(value="根据用户和积分类型获取二维码内容",httpMethod = "POST")
public ResultData<String> getQcodeInfoByUserId(@RequestParam("openId") String openId,@RequestParam("integrateType") String integrateType,@RequestParam("rebateIntegrate") String rebateIntegrate){
String qcodeInfoByUserId = qCodeInfoServiceImpl.getQcodeInfoByUserId(openId, integrateType, rebateIntegrate);
//String qcodeInfoByUserId = qCodeInfoServiceImpl.getQcodeInfoByUserIdRedis(openId, integrateType, rebateIntegrate);
//String qcodeInfoByUserId = qCodeInfoServiceImpl.getQcodeInfoByUserId(openId, integrateType, rebateIntegrate);
String qcodeInfoByUserId = qCodeInfoServiceImpl.getQcodeInfoByUserIdRedis(openId, integrateType, rebateIntegrate);
if("-2".equals(qcodeInfoByUserId)){
return ResultData.success(2,"用户未找到");
}else if("-3".equals(qcodeInfoByUserId)){
@ -63,8 +63,8 @@ public class QcodeInfoController {
discountMoney="0";
}
LogUtil.WriteLog_Info("积分核减操作开始====="+PubTools.getCurrentDate(),"QcodeInfoController");
JSONObject retStrJSON = qCodeInfoServiceImpl.solveQcode(content, serverOperationId,orderId, Double.parseDouble(payMoney), Double.parseDouble(discountMoneyBefore), Double.parseDouble(discountMoney));
//JSONObject retStrJSON = qCodeInfoServiceImpl.solveQcodeRedis(content, serverOperationId,orderId, Double.parseDouble(payMoney), Double.parseDouble(discountMoneyBefore), Double.parseDouble(discountMoney));
//JSONObject retStrJSON = qCodeInfoServiceImpl.solveQcode(content, serverOperationId,orderId, Double.parseDouble(payMoney), Double.parseDouble(discountMoneyBefore), Double.parseDouble(discountMoney));
JSONObject retStrJSON = qCodeInfoServiceImpl.solveQcodeRedis(content, serverOperationId, orderId, Double.parseDouble(payMoney), Double.parseDouble(discountMoneyBefore), Double.parseDouble(discountMoney));
String retStr= retStrJSON.get("ret").toString();
String openId= PubTools.isEmpty(retStrJSON.get("openId"))?"":retStrJSON.get("openId").toString();

@ -67,9 +67,10 @@ public class UserController {
if(i<0){
return ResultData.fail("认证失败");
}else if(i>0){
WebsocketUtil.sendCheckMessageForAll("user");
//redisConfigUtil.publish(Consistant.USER + USERID, "user");
//redisConfigUtil.publish(Consistant.USER + USERID,"unSubscribe_"+ USERID);
//WebsocketUtil.sendCheckMessageForAll("user");
redisConfigUtil.publish(Consistant.USER + USERID, "user");
//测试取消订阅
// redisConfigUtil.publish(Consistant.USER + USERID, "unSubscribe_" + USERID);
return ResultData.success(1,"已提交");
}
return ResultData.success(1,"已提交");

@ -83,11 +83,13 @@ public class WebSocketRedis {
*
*/
@OnClose
public void onClose() throws IOException {
public void onClose(Session session) throws IOException {
//从set中删除
webSocketSet.remove(this);
//在线数减1
subOnlineCount();
SubscribeListener subscribeListener = new SubscribeListener();
subscribeListener.setSession(session);
redisMessageListenerContainer.removeMessageListener(subscribeListener);
}
@ -98,13 +100,13 @@ public class WebSocketRedis {
* @param session
*/
@OnMessage
public void onMessage(String message, Session session) {
public void onMessage(String message, Session session) throws IOException {
System.out.println("来自客户端的消息:{}"+message);
JSONObject retJo=new JSONObject();
retJo.put("code",1);
retJo.put("msg",message);
retJo.put("data","");
redisConfigUtil.publish(Consistant.USER + "aeb2ae994c834fd19816595c03bd08fe",JSONObject.toJSONString(retJo));
this.sendMessage(session, retJo.toJSONString());
}
/**
@ -124,8 +126,8 @@ public class WebSocketRedis {
* @param message
* @throws IOException
*/
public void sendMessage(String message) throws IOException {
this.session.getBasicRemote().sendText(message);
public void sendMessage(Session session, String message) throws IOException {
session.getBasicRemote().sendText(message);
}
public int getOnlineCount() {

@ -1163,6 +1163,8 @@ public class QCodeInfoServiceImpl {
JSONObject joMap=null;
if(content1 instanceof JSONObject){
joMap=(JSONObject)content1;
} else if (content1 instanceof String) {
joMap = JSONObject.parseObject(content1.toString());
}
if(joMap== null){
ret="4";
@ -1639,7 +1641,7 @@ public class QCodeInfoServiceImpl {
}else{
//需要判断是否是餐饮预约
String appointMentSql="select t.ID,t.SERVICEOPERATIONID,tt.JOBNUMBER,tt.COMPLETESTATUS from APPOINTMENT_INFO_TABLE t,SERVICE_AREA_OPERATORS_TABLE tt where t.SERVICEOPERATIONID = tt.ID AND t.ORDERID='"+content+"'";
String appointMentSql = "select t.ID,t.SERVICEOPERATIONID,tt.JOBNUMBER,t.COMPLETESTATUS from APPOINTMENT_INFO_TABLE t,SERVICE_AREA_OPERATORS_TABLE tt where t.SERVICEOPERATIONID = tt.ID AND t.ORDERID='" + content + "'";
List appointMentList = this.mapperI.selectforlist(appointMentSql);
if(appointMentList != null && appointMentList.size()>0) {
Map<String, Object> appointment = (Map<String, Object>) appointMentList.get(0);

@ -242,6 +242,7 @@ static{
" oper.STROEPIC,\n" +
" oper.PHONE,\n" +
" oper.POSITION,\n" +
" (SELECT IPS.BAK1 FROM INTEGRAL_PUBLIC_SET ips WHERE IPS.PARAMCODE='PICURL') AS PICURL,\n" +
" oper.OPENTIME,\n" +
" oper.OPEN,\n" +
" case when oper.OPEN=0 then '暂停服务' else '营业中' end AS OPENNAME,\n" +

@ -27,22 +27,19 @@ public class redisConfigUtil {
redisTemplate.convertAndSend(key, value);
}
/**
* KEY
* @param key
* @return
*/
public static Long delIntegral(String key){
Jedis jedis = RedisSessionConfig.jedisResource();
if(jedis == null){
if (redisTemplate == null) {
return -1L;
}
Boolean exists = jedis.exists(Consistant.INTEGRAL_PRE + key);
Boolean exists = redisTemplate.hasKey(Consistant.INTEGRAL_PRE + key);
if(exists){
return jedis.del(Consistant.INTEGRAL_PRE + key);
redisTemplate.delete(Consistant.INTEGRAL_PRE + key);
}
return 0L;
}
@ -54,12 +51,10 @@ public class redisConfigUtil {
* @return
*/
public static Long setIntegral(String key,String obj){
Jedis jedis = RedisSessionConfig.jedisResource();;
if(jedis == null){
if (redisTemplate == null) {
return -1L;
}
redisTemplate.opsForValue().set(key, obj);
String set = jedis.set(Consistant.INTEGRAL_PRE + key, obj);
redisTemplate.opsForValue().set(Consistant.INTEGRAL_PRE + key, obj);
return 0L;
}
@ -69,28 +64,15 @@ public class redisConfigUtil {
* @return
*/
public static Object getIntegral(String key){
Jedis jedis = RedisSessionConfig.jedisResource();;
if(jedis == null){
return "-1";
if (redisTemplate == null) {
return -1L;
}
Boolean exists = jedis.exists(Consistant.INTEGRAL_PRE + key);
Boolean exists = redisTemplate.hasKey(Consistant.INTEGRAL_PRE + key);
if(exists){
return JSON.parseObject(jedis.get(Consistant.INTEGRAL_PRE + key));
return redisTemplate.opsForValue().get(Consistant.INTEGRAL_PRE + key);
}else{
return null;
}
}
public static Long del(String key){
Jedis jedis = RedisSessionConfig.jedisResource();;
if(jedis == null){
return -1L;
}
Boolean exists = jedis.exists(key);
if(exists){
return jedis.del(key);
}
return 0L;
}
}

@ -32,6 +32,27 @@ spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1
server.tomcat.max-swallow-size=-1
server.tomcat.max-threads=1000
########################################################
###REDIS (RedisProperties) redis?????
########################################################
# database name?0-15?
spring.redis.database=0
# server host1 ??????????ip
#spring.redis.host=10.15.0.13
# server password ????????????
spring.redis.password=nmgjtjt
#connection port ??????????
#spring.redis.port=6381
# pool settings ...???
spring.redis.pool.max-idle=1000
spring.redis.pool.min-idle=0
spring.redis.pool.max-active=1000
spring.redis.pool.max-wait=-1
# name of Redis server ?????Redis server???
#spring.redis.sentinel.master=mymaster
# comma-separated list of host:port pairs ???????
#spring.redis.sentinel.nodes=10.15.0.13:26381,10.15.0.13:26382,10.15.0.13:26383
#mybatis-plus??SQL??
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
logging.level.com.nmgs.ssmpback.mapper=debug

Loading…
Cancel
Save