parent
							
								
									9d78e9ea80
								
							
						
					
					
						commit
						ed238a5881
					
				@ -0,0 +1,64 @@
 | 
				
			|||||||
 | 
					package com.gmh.config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.fasterxml.jackson.annotation.JsonAutoDetect;
 | 
				
			||||||
 | 
					import com.fasterxml.jackson.annotation.JsonTypeInfo;
 | 
				
			||||||
 | 
					import com.fasterxml.jackson.annotation.PropertyAccessor;
 | 
				
			||||||
 | 
					import com.fasterxml.jackson.databind.ObjectMapper;
 | 
				
			||||||
 | 
					import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
 | 
				
			||||||
 | 
					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.core.RedisTemplate;
 | 
				
			||||||
 | 
					import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
 | 
				
			||||||
 | 
					import org.springframework.data.redis.serializer.StringRedisSerializer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * redis配置
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@Configuration
 | 
				
			||||||
 | 
					@EnableCaching
 | 
				
			||||||
 | 
					public class RedisConfig extends CachingConfigurerSupport {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * value的序列化方式为JDK默认序列化
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @Bean(name = "redisTemplateForJdkSerializer")
 | 
				
			||||||
 | 
					    public RedisTemplate<Object, Object> redisTemplateForJdkSerializer(RedisConnectionFactory connectionFactory) {
 | 
				
			||||||
 | 
					        RedisTemplate<Object, Object> template = new RedisTemplate<>();
 | 
				
			||||||
 | 
					        template.setConnectionFactory(connectionFactory);
 | 
				
			||||||
 | 
					        Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
 | 
				
			||||||
 | 
					        ObjectMapper om = new ObjectMapper();
 | 
				
			||||||
 | 
					        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
 | 
				
			||||||
 | 
					        jackson2JsonRedisSerializer.setObjectMapper(om);
 | 
				
			||||||
 | 
					        template.setKeySerializer(new StringRedisSerializer());
 | 
				
			||||||
 | 
					        template.setHashKeySerializer(new StringRedisSerializer());
 | 
				
			||||||
 | 
					        template.afterPropertiesSet();
 | 
				
			||||||
 | 
					        return template;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * value的序列化方式为Json
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @Bean
 | 
				
			||||||
 | 
					    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
 | 
				
			||||||
 | 
					        RedisTemplate<Object, Object> template = new RedisTemplate<>();
 | 
				
			||||||
 | 
					        template.setConnectionFactory(connectionFactory);
 | 
				
			||||||
 | 
					        Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
 | 
				
			||||||
 | 
					        ObjectMapper om = new ObjectMapper();
 | 
				
			||||||
 | 
					        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
 | 
				
			||||||
 | 
					        om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
 | 
				
			||||||
 | 
					        jackson2JsonRedisSerializer.setObjectMapper(om);
 | 
				
			||||||
 | 
					        // 使用StringRedisSerializer来序列化和反序列化redis的key值
 | 
				
			||||||
 | 
					        template.setKeySerializer(new StringRedisSerializer());
 | 
				
			||||||
 | 
					        template.setValueSerializer(jackson2JsonRedisSerializer);
 | 
				
			||||||
 | 
					        // Hash的key也采用StringRedisSerializer的序列化方式
 | 
				
			||||||
 | 
					        template.setHashKeySerializer(new StringRedisSerializer());
 | 
				
			||||||
 | 
					        template.setHashValueSerializer(jackson2JsonRedisSerializer);
 | 
				
			||||||
 | 
					        template.afterPropertiesSet();
 | 
				
			||||||
 | 
					        return template;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					package com.gmh.entity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import lombok.Data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Data
 | 
				
			||||||
 | 
					public class RowCellNum {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Integer rowNum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Integer cellNum;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,11 +1,49 @@
 | 
				
			|||||||
package com.gmh.service.impl;
 | 
					package com.gmh.service.impl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import cn.hutool.core.util.StrUtil;
 | 
				
			||||||
 | 
					import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 | 
				
			||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
					import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
				
			||||||
import com.gmh.dao.SysBaijiaxingDao;
 | 
					import com.gmh.dao.SysBaijiaxingDao;
 | 
				
			||||||
import com.gmh.entity.SysBaijiaxing;
 | 
					import com.gmh.entity.SysBaijiaxing;
 | 
				
			||||||
import com.gmh.service.SysBaijiaxingService;
 | 
					import com.gmh.service.SysBaijiaxingService;
 | 
				
			||||||
 | 
					import com.gmh.utils.RedisUtils;
 | 
				
			||||||
 | 
					import org.springframework.beans.factory.InitializingBean;
 | 
				
			||||||
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
import org.springframework.stereotype.Service;
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.Collection;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.Set;
 | 
				
			||||||
 | 
					import java.util.stream.Collectors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Service
 | 
					@Service
 | 
				
			||||||
public class SysBaijiaxingServiceImpl extends ServiceImpl<SysBaijiaxingDao, SysBaijiaxing> implements SysBaijiaxingService {
 | 
					public class SysBaijiaxingServiceImpl extends ServiceImpl<SysBaijiaxingDao, SysBaijiaxing> implements SysBaijiaxingService, InitializingBean {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Autowired
 | 
				
			||||||
 | 
					    private RedisUtils redisUtils;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean likeChineseName(String val) {
 | 
				
			||||||
 | 
					        if (StrUtil.isBlank(val)) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        String first = val.substring(0, 1);
 | 
				
			||||||
 | 
					        Collection<String> keys = redisUtils.keys(KEY_XINGSHI + first + "*");
 | 
				
			||||||
 | 
					        return keys.size() > 0;
 | 
				
			||||||
 | 
					//        QueryWrapper<SysBaijiaxing> queryWrapper = new QueryWrapper<>();
 | 
				
			||||||
 | 
					//        queryWrapper.apply("{0} LIKE CONCAT(xingshi,'%')", val);
 | 
				
			||||||
 | 
					//        List<SysBaijiaxing> list = list(queryWrapper);
 | 
				
			||||||
 | 
					//        return !list.isEmpty();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static final String KEY_XINGSHI = "cache_xingshi:";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void afterPropertiesSet() {
 | 
				
			||||||
 | 
					        List<SysBaijiaxing> list = list();
 | 
				
			||||||
 | 
					        Set<String> collect = list.stream().map(SysBaijiaxing::getXingshi).collect(Collectors.toSet());
 | 
				
			||||||
 | 
					        for (String xingshi : collect) {
 | 
				
			||||||
 | 
					            redisUtils.setCacheObject(KEY_XINGSHI + xingshi, xingshi);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
					Loading…
					
					
				
		Reference in new issue