修改了用户登录的功能模块,添加了用户最新登录时间的信息,优化代码
This commit is contained in:
parent
c6adc85b61
commit
2129b3d3fd
@ -101,6 +101,7 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
|
|||||||
permissions.add(new GrantedAuthorityImpl(sysAuthorityEntity.getAuthorityName()));
|
permissions.add(new GrantedAuthorityImpl(sysAuthorityEntity.getAuthorityName()));
|
||||||
}
|
}
|
||||||
customAuthenticationProvider.sysUserService.updateLoginNum(userEntity.getId(),userEntity.getLoginNum() + 1);
|
customAuthenticationProvider.sysUserService.updateLoginNum(userEntity.getId(),userEntity.getLoginNum() + 1);
|
||||||
|
customAuthenticationProvider.sysUserService.updateLoginLastTime(userEntity.getId(),DateTimeUtil.dateTimeToString(LocalDateTime.now()));
|
||||||
// 生成令牌
|
// 生成令牌
|
||||||
Authentication authToken = new UsernamePasswordAuthenticationToken(userName, encryptPassword, permissions);
|
Authentication authToken = new UsernamePasswordAuthenticationToken(userName, encryptPassword, permissions);
|
||||||
return authToken;
|
return authToken;
|
||||||
|
@ -22,12 +22,10 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
import org.springframework.data.redis.serializer.*;
|
||||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
|
||||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
|
||||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -39,14 +37,14 @@ import java.time.Duration;
|
|||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableCaching
|
@EnableCaching
|
||||||
public class RedisConfig extends CachingConfigurerSupport {
|
public class RedisConfig extends CachingConfigurerSupport{
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(RedisConfig.class);
|
private static final Logger logger = LoggerFactory.getLogger(RedisConfig.class);
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private LettuceConnectionFactory lettuceConnectionFactory;
|
private LettuceConnectionFactory lettuceConnectionFactory;
|
||||||
|
|
||||||
private Duration timeToLive = Duration.ofSeconds(3600*6);
|
private static final Duration TIME_TO_LIVE = Duration.ofSeconds(3600*6);
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Override
|
@Override
|
||||||
@ -59,11 +57,10 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||||||
sb.append(":");
|
sb.append(":");
|
||||||
sb.append(method.getName());
|
sb.append(method.getName());
|
||||||
for (Object obj : params) {
|
for (Object obj : params) {
|
||||||
sb.append(":" + String.valueOf(obj));
|
sb.append(":").append(obj);
|
||||||
}
|
}
|
||||||
String rsToUse = String.valueOf(sb);
|
// logger.info("自动生成Redis Key -> [{}]", rsToUse);
|
||||||
// logger.info("自动生成Redis Key -> [{}]", rsToUse);
|
return String.valueOf(sb);
|
||||||
return rsToUse;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +74,7 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||||||
//value序列化方式
|
//value序列化方式
|
||||||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(valueSerializer()))
|
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(valueSerializer()))
|
||||||
.disableCachingNullValues()
|
.disableCachingNullValues()
|
||||||
.entryTtl(timeToLive);
|
.entryTtl(TIME_TO_LIVE);
|
||||||
|
|
||||||
RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager.RedisCacheManagerBuilder
|
RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager.RedisCacheManagerBuilder
|
||||||
.fromConnectionFactory(lettuceConnectionFactory)
|
.fromConnectionFactory(lettuceConnectionFactory)
|
||||||
@ -91,13 +88,13 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||||||
/**
|
/**
|
||||||
* RedisTemplate配置 在单独使用redisTemplate的时候 重新定义序列化方式
|
* RedisTemplate配置 在单独使用redisTemplate的时候 重新定义序列化方式
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean(name = "redisTemplate")
|
||||||
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) {
|
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) {
|
||||||
// 设置序列化
|
// 设置序列化
|
||||||
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
|
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
|
||||||
ObjectMapper om = new ObjectMapper();
|
ObjectMapper om = new ObjectMapper();
|
||||||
// 配置null值序列化成空字符串
|
// 配置null值序列化成空字符串
|
||||||
om.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {
|
om.getSerializerProvider().setNullValueSerializer(new JsonSerializer<>() {
|
||||||
@Override
|
@Override
|
||||||
public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
|
public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
|
||||||
jsonGenerator.writeString("");
|
jsonGenerator.writeString("");
|
||||||
@ -113,7 +110,7 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||||||
ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
|
ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
|
||||||
jackson2JsonRedisSerializer.setObjectMapper(om);
|
jackson2JsonRedisSerializer.setObjectMapper(om);
|
||||||
// 配置redisTemplate
|
// 配置redisTemplate
|
||||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
|
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||||
redisTemplate.setConnectionFactory(lettuceConnectionFactory);
|
redisTemplate.setConnectionFactory(lettuceConnectionFactory);
|
||||||
RedisSerializer<?> stringSerializer = new StringRedisSerializer();
|
RedisSerializer<?> stringSerializer = new StringRedisSerializer();
|
||||||
redisTemplate.setKeySerializer(stringSerializer);
|
redisTemplate.setKeySerializer(stringSerializer);
|
||||||
@ -130,7 +127,7 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||||||
|
|
||||||
private RedisSerializer<Object> valueSerializer() {
|
private RedisSerializer<Object> valueSerializer() {
|
||||||
// 设置序列化
|
// 设置序列化
|
||||||
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(
|
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(
|
||||||
Object.class);
|
Object.class);
|
||||||
ObjectMapper om = new ObjectMapper();
|
ObjectMapper om = new ObjectMapper();
|
||||||
// 解决jackson无法反序列化LocalDateTime的问题,引入jsr310标准
|
// 解决jackson无法反序列化LocalDateTime的问题,引入jsr310标准
|
||||||
@ -150,6 +147,35 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置数据存入 redis 的序列化方式,并开启事务
|
||||||
|
*
|
||||||
|
* @param redisTemplate
|
||||||
|
* @param factory
|
||||||
|
*/
|
||||||
|
private void initRedisTemplate(RedisTemplate<String, Object> redisTemplate, RedisConnectionFactory factory) {
|
||||||
|
//如果不配置Serializer,那么存储的时候缺省使用String,如果用User类型存储,那么会提示错误User can't cast to String!
|
||||||
|
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||||
|
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||||
|
// 开启事务
|
||||||
|
redisTemplate.setEnableTransactionSupport(true);
|
||||||
|
redisTemplate.setConnectionFactory(factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注入封装RedisTemplate 给RedisUtil提供操作类
|
||||||
|
* @param redisTemplate
|
||||||
|
* @return RedisUtil
|
||||||
|
*/
|
||||||
|
@Bean(name = "redisUtil")
|
||||||
|
public RedisUtil redisUtil(RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
RedisUtil redisUtil = new RedisUtil();
|
||||||
|
redisUtil.setRedisTemplate(redisTemplate);
|
||||||
|
return redisUtil;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Bean
|
@Bean
|
||||||
public CacheErrorHandler errorHandler() {
|
public CacheErrorHandler errorHandler() {
|
||||||
|
533
src/main/java/com/xkrs/common/config/RedisUtil.java
Normal file
533
src/main/java/com/xkrs/common/config/RedisUtil.java
Normal file
@ -0,0 +1,533 @@
|
|||||||
|
package com.xkrs.common.config;
|
||||||
|
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* redis工具类
|
||||||
|
* @author tajochen
|
||||||
|
*/
|
||||||
|
public class RedisUtil {
|
||||||
|
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
|
public void setRedisTemplate(RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
this.redisTemplate = redisTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定缓存失效时间
|
||||||
|
* @param key 键
|
||||||
|
* @param time 时间(秒)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean expire(String key,long time){
|
||||||
|
try {
|
||||||
|
if(time>0){
|
||||||
|
redisTemplate.expire(key, time, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据key 获取过期时间
|
||||||
|
* @param key 键 不能为null
|
||||||
|
* @return 时间(秒) 返回0 代表为永久有效
|
||||||
|
*/
|
||||||
|
public long getExpire(String key){
|
||||||
|
return redisTemplate.getExpire(key,TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断key是否存在
|
||||||
|
* @param key 键
|
||||||
|
* @return true 存在 false不存在
|
||||||
|
*/
|
||||||
|
public boolean hasKey(String key){
|
||||||
|
try {
|
||||||
|
return redisTemplate.hasKey(key);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除缓存
|
||||||
|
* @param key 可以传一个值 或多个
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void del(String ... key){
|
||||||
|
if(key!=null&&key.length>0){
|
||||||
|
if(key.length==1){
|
||||||
|
redisTemplate.delete(key[0]);
|
||||||
|
}else{
|
||||||
|
redisTemplate.delete(String.valueOf(CollectionUtils.arrayToList(key)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//============================String=============================
|
||||||
|
/**
|
||||||
|
* 普通缓存获取
|
||||||
|
* @param key 键
|
||||||
|
* @return 值
|
||||||
|
*/
|
||||||
|
public Object get(String key){
|
||||||
|
return key==null?null:redisTemplate.opsForValue().get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 普通缓存放入
|
||||||
|
* @param key 键
|
||||||
|
* @param value 值
|
||||||
|
* @return true成功 false失败
|
||||||
|
*/
|
||||||
|
public boolean set(String key,Object value) {
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForValue().set(key, value);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 普通缓存放入并设置时间
|
||||||
|
* @param key 键
|
||||||
|
* @param value 值
|
||||||
|
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
|
||||||
|
* @return true成功 false 失败
|
||||||
|
*/
|
||||||
|
public boolean set(String key,Object value,long time){
|
||||||
|
try {
|
||||||
|
if(time>0){
|
||||||
|
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
|
||||||
|
} else {
|
||||||
|
set(key, value);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递增
|
||||||
|
* @param key 键
|
||||||
|
* @param delta 要增加几(大于0)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public long incr(String key, long delta){
|
||||||
|
if(delta<0){
|
||||||
|
throw new RuntimeException("递增因子必须大于0");
|
||||||
|
}
|
||||||
|
return redisTemplate.opsForValue().increment(key, delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递减
|
||||||
|
* @param key 键
|
||||||
|
* @param delta 要减少几(小于0)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public long decr(String key, long delta){
|
||||||
|
if(delta<0){
|
||||||
|
throw new RuntimeException("递减因子必须大于0");
|
||||||
|
}
|
||||||
|
return redisTemplate.opsForValue().increment(key, -delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
//================================Map=================================
|
||||||
|
/**
|
||||||
|
* HashGet
|
||||||
|
* @param key 键 不能为null
|
||||||
|
* @param item 项 不能为null
|
||||||
|
* @return 值
|
||||||
|
*/
|
||||||
|
public Object hget(String key,String item){
|
||||||
|
return redisTemplate.opsForHash().get(key, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取hashKey对应的所有键值
|
||||||
|
* @param key 键
|
||||||
|
* @return 对应的多个键值
|
||||||
|
*/
|
||||||
|
public Map<Object,Object> hmget(String key){
|
||||||
|
return redisTemplate.opsForHash().entries(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HashSet
|
||||||
|
* @param key 键
|
||||||
|
* @param map 对应多个键值
|
||||||
|
* @return true 成功 false 失败
|
||||||
|
*/
|
||||||
|
public boolean hmset(String key, Map<String,Object> map){
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForHash().putAll(key, map);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HashSet 并设置时间
|
||||||
|
* @param key 键
|
||||||
|
* @param map 对应多个键值
|
||||||
|
* @param time 时间(秒)
|
||||||
|
* @return true成功 false失败
|
||||||
|
*/
|
||||||
|
public boolean hmset(String key, Map<String,Object> map, long time){
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForHash().putAll(key, map);
|
||||||
|
if(time>0){
|
||||||
|
expire(key, time);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向一张hash表中放入数据,如果不存在将创建
|
||||||
|
* @param key 键
|
||||||
|
* @param item 项
|
||||||
|
* @param value 值
|
||||||
|
* @return true 成功 false失败
|
||||||
|
*/
|
||||||
|
public boolean hset(String key,String item,Object value) {
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForHash().put(key, item, value);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向一张hash表中放入数据,如果不存在将创建
|
||||||
|
* @param key 键
|
||||||
|
* @param item 项
|
||||||
|
* @param value 值
|
||||||
|
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
|
||||||
|
* @return true 成功 false失败
|
||||||
|
*/
|
||||||
|
public boolean hset(String key,String item,Object value,long time) {
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForHash().put(key, item, value);
|
||||||
|
if(time>0){
|
||||||
|
expire(key, time);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除hash表中的值
|
||||||
|
* @param key 键 不能为null
|
||||||
|
* @param item 项 可以使多个 不能为null
|
||||||
|
*/
|
||||||
|
public void hdel(String key, Object... item){
|
||||||
|
redisTemplate.opsForHash().delete(key,item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断hash表中是否有该项的值
|
||||||
|
* @param key 键 不能为null
|
||||||
|
* @param item 项 不能为null
|
||||||
|
* @return true 存在 false不存在
|
||||||
|
*/
|
||||||
|
public boolean hHasKey(String key, String item){
|
||||||
|
return redisTemplate.opsForHash().hasKey(key, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
|
||||||
|
* @param key 键
|
||||||
|
* @param item 项
|
||||||
|
* @param by 要增加几(大于0)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public double hincr(String key, String item,double by){
|
||||||
|
return redisTemplate.opsForHash().increment(key, item, by);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* hash递减
|
||||||
|
* @param key 键
|
||||||
|
* @param item 项
|
||||||
|
* @param by 要减少记(小于0)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public double hdecr(String key, String item,double by){
|
||||||
|
return redisTemplate.opsForHash().increment(key, item,-by);
|
||||||
|
}
|
||||||
|
|
||||||
|
//============================set=============================
|
||||||
|
/**
|
||||||
|
* 根据key获取Set中的所有值
|
||||||
|
* @param key 键
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Set<Object> sGet(String key){
|
||||||
|
try {
|
||||||
|
return redisTemplate.opsForSet().members(key);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据value从一个set中查询,是否存在
|
||||||
|
* @param key 键
|
||||||
|
* @param value 值
|
||||||
|
* @return true 存在 false不存在
|
||||||
|
*/
|
||||||
|
public boolean sHasKey(String key,Object value){
|
||||||
|
try {
|
||||||
|
return Boolean.TRUE.equals(redisTemplate.opsForSet().isMember(key, value));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将数据放入set缓存
|
||||||
|
* @param key 键
|
||||||
|
* @param values 值 可以是多个
|
||||||
|
* @return 成功个数
|
||||||
|
*/
|
||||||
|
public long sSet(String key, Object...values) {
|
||||||
|
try {
|
||||||
|
return redisTemplate.opsForSet().add(key, values);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将set数据放入缓存
|
||||||
|
* @param key 键
|
||||||
|
* @param time 时间(秒)
|
||||||
|
* @param values 值 可以是多个
|
||||||
|
* @return 成功个数
|
||||||
|
*/
|
||||||
|
public long sSetAndTime(String key,long time,Object...values) {
|
||||||
|
try {
|
||||||
|
Long count = redisTemplate.opsForSet().add(key, values);
|
||||||
|
if(time>0)
|
||||||
|
{expire(key, time);}
|
||||||
|
return count;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取set缓存的长度
|
||||||
|
* @param key 键
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public long sGetSetSize(String key){
|
||||||
|
try {
|
||||||
|
return redisTemplate.opsForSet().size(key);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除值为value的
|
||||||
|
* @param key 键
|
||||||
|
* @param values 值 可以是多个
|
||||||
|
* @return 移除的个数
|
||||||
|
*/
|
||||||
|
public long setRemove(String key, Object ...values) {
|
||||||
|
try {
|
||||||
|
Long count = redisTemplate.opsForSet().remove(key, values);
|
||||||
|
return count;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//===============================list=================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取list缓存的内容
|
||||||
|
* @param key 键
|
||||||
|
* @param start 开始
|
||||||
|
* @param end 结束 0 到 -1代表所有值
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<Object> lGet(String key, long start, long end){
|
||||||
|
try {
|
||||||
|
return redisTemplate.opsForList().range(key, start, end);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取list缓存的长度
|
||||||
|
* @param key 键
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public long lGetListSize(String key){
|
||||||
|
try {
|
||||||
|
return redisTemplate.opsForList().size(key);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过索引 获取list中的值
|
||||||
|
* @param key 键
|
||||||
|
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Object lGetIndex(String key,long index){
|
||||||
|
try {
|
||||||
|
return redisTemplate.opsForList().index(key, index);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将list放入缓存
|
||||||
|
* @param key 键
|
||||||
|
* @param value 值
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean lSet(String key, Object value) {
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForList().rightPush(key, value);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将list放入缓存
|
||||||
|
* @param key 键
|
||||||
|
* @param value 值
|
||||||
|
* @param time 时间(秒)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean lSet(String key, Object value, long time) {
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForList().rightPush(key, value);
|
||||||
|
if (time > 0)
|
||||||
|
{expire(key, time);}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将list放入缓存
|
||||||
|
* @param key 键
|
||||||
|
* @param value 值
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean lSet(String key, List<Object> value) {
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForList().rightPushAll(key, value);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将list放入缓存
|
||||||
|
* @param key 键
|
||||||
|
* @param value 值
|
||||||
|
* @param time 时间(秒)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean lSet(String key, List<Object> value, long time) {
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForList().rightPushAll(key, value);
|
||||||
|
if (time > 0) {
|
||||||
|
expire(key, time);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据索引修改list中的某条数据
|
||||||
|
* @param key 键
|
||||||
|
* @param index 索引
|
||||||
|
* @param value 值
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean lUpdateIndex(String key, long index,Object value) {
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForList().set(key, index, value);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除N个值为value
|
||||||
|
* @param key 键
|
||||||
|
* @param count 移除多少个
|
||||||
|
* @param value 值
|
||||||
|
* @return 移除的个数
|
||||||
|
*/
|
||||||
|
public long lRemove(String key,long count,Object value) {
|
||||||
|
try {
|
||||||
|
Long remove = redisTemplate.opsForList().remove(key, count, value);
|
||||||
|
return remove;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -44,4 +44,18 @@ public interface CityDao extends JpaRepository<CityEntity,Long>, JpaSpecificatio
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<CityEntity> findByProCode(String proCode);
|
List<CityEntity> findByProCode(String proCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据市名称查询信息
|
||||||
|
* @param cityName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<CityEntity> findByCityName(String cityName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据省名称查询信息
|
||||||
|
* @param proName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<CityEntity> findByProName(String proName);
|
||||||
}
|
}
|
||||||
|
@ -27,4 +27,18 @@ public interface CountyDao extends JpaRepository<CountyEntity,Long> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<CountyEntity> findByCityCode(String cityCode);
|
List<CountyEntity> findByCityCode(String cityCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据countyCode查询信息
|
||||||
|
* @param countyCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
CountyEntity findByCountyCode(String countyCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据县名称查询信息
|
||||||
|
* @param countyName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
CountyEntity findByCountyName(String countyName);
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
|
|||||||
* 查询用户信息
|
* 查询用户信息
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Query(value = "select new com.xkrs.model.vo.SysUserVo (id,reallyName,telephone,countyCode,activeFlag,addTime,overTime,dayNum,accountType,countyName,lastEntryIp,loginNum) " +
|
@Query(value = "select new com.xkrs.model.vo.SysUserVo (id,reallyName,telephone,countyCode,activeFlag,addTime,overTime,dayNum,accountType,countyName,lastEntryIp,loginNum,loginLastTime) " +
|
||||||
"from SysUserEntity")
|
"from SysUserEntity")
|
||||||
List<SysUserVo> selectAll();
|
List<SysUserVo> selectAll();
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
|
|||||||
* @param userName
|
* @param userName
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Query(value = "select new com.xkrs.model.vo.SysUserVo (id,reallyName,telephone,countyCode,activeFlag,addTime,overTime,dayNum,accountType,countyName,lastEntryIp,loginNum) " +
|
@Query(value = "select new com.xkrs.model.vo.SysUserVo (id,reallyName,telephone,countyCode,activeFlag,addTime,overTime,dayNum,accountType,countyName,lastEntryIp,loginNum,loginLastTime) " +
|
||||||
"from SysUserEntity where userName = :userName")
|
"from SysUserEntity where userName = :userName")
|
||||||
SysUserVo selectUserByUserName(String userName);
|
SysUserVo selectUserByUserName(String userName);
|
||||||
|
|
||||||
@ -153,4 +153,13 @@ public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
|
|||||||
@Query(value = "update sys_user set login_num = ?2 where id = ?1",nativeQuery = true)
|
@Query(value = "update sys_user set login_num = ?2 where id = ?1",nativeQuery = true)
|
||||||
@Modifying(clearAutomatically=true)
|
@Modifying(clearAutomatically=true)
|
||||||
void updateLoginNum(Integer userId,Integer loginNum);
|
void updateLoginNum(Integer userId,Integer loginNum);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改登陆时间
|
||||||
|
* @param userId
|
||||||
|
* @param loginLastTime
|
||||||
|
*/
|
||||||
|
@Query(value = "update sys_user set login_last_time = ?2 where id = ?1",nativeQuery = true)
|
||||||
|
@Modifying(clearAutomatically=true)
|
||||||
|
void updateLoginLastTime(Integer userId,String loginLastTime);
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ public class CountyEntity {
|
|||||||
* 主键id
|
* 主键id
|
||||||
*/
|
*/
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "city_seq_gen")
|
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "county_seq_gen")
|
||||||
@SequenceGenerator(name = "city_seq_gen", sequenceName = "city_id_seq",allocationSize = 1)
|
@SequenceGenerator(name = "county_seq_gen", sequenceName = "county_id_seq",allocationSize = 1)
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,6 +92,11 @@ public class SysUserEntity implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Integer loginNum;
|
private Integer loginNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户最新登录时间
|
||||||
|
*/
|
||||||
|
private String loginLastTime;
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -244,6 +249,14 @@ public class SysUserEntity implements Serializable {
|
|||||||
this.loginNum = loginNum;
|
this.loginNum = loginNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLoginLastTime() {
|
||||||
|
return loginLastTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoginLastTime(String loginLastTime) {
|
||||||
|
this.loginLastTime = loginLastTime;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SysUserEntity{" +
|
return "SysUserEntity{" +
|
||||||
@ -266,6 +279,7 @@ public class SysUserEntity implements Serializable {
|
|||||||
", accountType='" + accountType + '\'' +
|
", accountType='" + accountType + '\'' +
|
||||||
", countyName='" + countyName + '\'' +
|
", countyName='" + countyName + '\'' +
|
||||||
", loginNum=" + loginNum +
|
", loginNum=" + loginNum +
|
||||||
|
", loginLastTime='" + loginLastTime + '\'' +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,9 @@ public class SysUserVo implements Serializable {
|
|||||||
|
|
||||||
private Integer loginNum;
|
private Integer loginNum;
|
||||||
|
|
||||||
public SysUserVo(Integer id, String reallyName, String telephone, String countyCode, Integer activeFlag, String addTime, String overTime, Integer dayNum, String accountType, String countyName, String lastEntryIp, Integer loginNum) {
|
private String loginLastTime;
|
||||||
|
|
||||||
|
public SysUserVo(Integer id, String reallyName, String telephone, String countyCode, Integer activeFlag, String addTime, String overTime, Integer dayNum, String accountType, String countyName, String lastEntryIp, Integer loginNum, String loginLastTime) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.reallyName = reallyName;
|
this.reallyName = reallyName;
|
||||||
this.telephone = telephone;
|
this.telephone = telephone;
|
||||||
@ -45,6 +47,7 @@ public class SysUserVo implements Serializable {
|
|||||||
this.countyName = countyName;
|
this.countyName = countyName;
|
||||||
this.lastEntryIp = lastEntryIp;
|
this.lastEntryIp = lastEntryIp;
|
||||||
this.loginNum = loginNum;
|
this.loginNum = loginNum;
|
||||||
|
this.loginLastTime = loginLastTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
@ -142,5 +145,13 @@ public class SysUserVo implements Serializable {
|
|||||||
public void setLoginNum(Integer loginNum) {
|
public void setLoginNum(Integer loginNum) {
|
||||||
this.loginNum = loginNum;
|
this.loginNum = loginNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLoginLastTime() {
|
||||||
|
return loginLastTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoginLastTime(String loginLastTime) {
|
||||||
|
this.loginLastTime = loginLastTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +153,13 @@ public interface SysUserService {
|
|||||||
*/
|
*/
|
||||||
void updateLoginNum(Integer userId,Integer loginNum);
|
void updateLoginNum(Integer userId,Integer loginNum);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 记录用户登录时间
|
||||||
|
* @param userId
|
||||||
|
* @param loginLastTime
|
||||||
|
*/
|
||||||
|
void updateLoginLastTime(Integer userId,String loginLastTime);
|
||||||
|
|
||||||
|
|
||||||
List<Map<String,String>> findCityByProCode(String proCode);
|
List<Map<String,String>> findCityByProCode(String proCode);
|
||||||
|
|
||||||
|
@ -2,10 +2,7 @@ package com.xkrs.service.impl;
|
|||||||
|
|
||||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||||
import com.xkrs.dao.*;
|
import com.xkrs.dao.*;
|
||||||
import com.xkrs.model.entity.RelRoleAuthorityEntity;
|
import com.xkrs.model.entity.*;
|
||||||
import com.xkrs.model.entity.RelUserRoleEntity;
|
|
||||||
import com.xkrs.model.entity.SysRoleEntity;
|
|
||||||
import com.xkrs.model.entity.SysUserEntity;
|
|
||||||
import com.xkrs.model.qo.SysUserQo;
|
import com.xkrs.model.qo.SysUserQo;
|
||||||
import com.xkrs.model.vo.SysUserVo;
|
import com.xkrs.model.vo.SysUserVo;
|
||||||
import com.xkrs.service.RedisService;
|
import com.xkrs.service.RedisService;
|
||||||
@ -54,6 +51,12 @@ public class SysUserServiceImpl implements SysUserService {
|
|||||||
@Resource
|
@Resource
|
||||||
private NationwideDao nationwideDao;
|
private NationwideDao nationwideDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CountyDao countyDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CityDao cityDao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查用户名是否存在
|
* 检查用户名是否存在
|
||||||
* @param userName
|
* @param userName
|
||||||
@ -77,21 +80,57 @@ public class SysUserServiceImpl implements SysUserService {
|
|||||||
String salt = KeyGenerators.string().generateKey();
|
String salt = KeyGenerators.string().generateKey();
|
||||||
SysUserEntity sysUserEntity = new SysUserEntity();
|
SysUserEntity sysUserEntity = new SysUserEntity();
|
||||||
sysUserEntity.setUserName(sysUserQo.getUserName());
|
sysUserEntity.setUserName(sysUserQo.getUserName());
|
||||||
|
String o = (String) redisService.get(sysUserQo.getUserName());
|
||||||
|
if("".equals(o) || o == null){
|
||||||
|
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"请先发送验证码!",locale);
|
||||||
|
}
|
||||||
if(!redisService.get(sysUserQo.getUserName()).equals(sysUserQo.getVerificationCode())){
|
if(!redisService.get(sysUserQo.getUserName()).equals(sysUserQo.getVerificationCode())){
|
||||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"验证码错误,请重新输入!",locale);
|
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"验证码错误,请重新输入!",locale);
|
||||||
}
|
}
|
||||||
|
if("".equals(sysUserQo.getReallyName()) || sysUserQo.getReallyName() == null){
|
||||||
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"真实姓名不能为空!",locale);
|
||||||
|
}
|
||||||
sysUserEntity.setReallyName(sysUserQo.getReallyName());
|
sysUserEntity.setReallyName(sysUserQo.getReallyName());
|
||||||
sysUserEntity.setSalt(salt);
|
sysUserEntity.setSalt(salt);
|
||||||
sysUserEntity.setPassword(encry256(sysUserQo.getPassword() + salt));
|
sysUserEntity.setPassword(encry256(sysUserQo.getPassword() + salt));
|
||||||
sysUserEntity.setTelephone(sysUserQo.getUserName());
|
sysUserEntity.setTelephone(sysUserQo.getUserName());
|
||||||
|
|
||||||
sysUserEntity.setCountyCode(sysUserQo.getCountyCode());
|
sysUserEntity.setCountyCode(sysUserQo.getCountyCode());
|
||||||
|
if("".equals(sysUserQo.getCountyName()) || sysUserQo.getCountyName() == null){
|
||||||
|
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"省市区名称不能为空!",locale);
|
||||||
|
}
|
||||||
|
|
||||||
if("0000".equals(sysUserQo.getCountyCode().substring(2))){
|
if("0000".equals(sysUserQo.getCountyCode().substring(2))){
|
||||||
|
List<CityEntity> byProCode = cityDao.findByProCode(sysUserQo.getCountyCode());
|
||||||
|
if(byProCode == null || byProCode.size() == 0){
|
||||||
|
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"省编码不存在!",locale);
|
||||||
|
}
|
||||||
|
List<CityEntity> byProName = cityDao.findByProName(sysUserQo.getCountyName());
|
||||||
|
if(byProName == null || byProName.size() == 0){
|
||||||
|
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"您所选择的区域不存在!",locale);
|
||||||
|
}
|
||||||
sysUserEntity.setActiveFlag(1);
|
sysUserEntity.setActiveFlag(1);
|
||||||
sysUserEntity.setAccountType("省级");
|
sysUserEntity.setAccountType("省级");
|
||||||
}else if("00".equals(sysUserQo.getCountyCode().substring(4)) && !"0000".equals(sysUserQo.getCountyCode().substring(2))){
|
}else if("00".equals(sysUserQo.getCountyCode().substring(4)) && !"0000".equals(sysUserQo.getCountyCode().substring(2))){
|
||||||
|
List<CityEntity> byCityCode = cityDao.findByCityCode(sysUserQo.getCountyCode());
|
||||||
|
if(byCityCode == null || byCityCode.size() == 0){
|
||||||
|
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"市编码不存在!",locale);
|
||||||
|
}
|
||||||
|
List<CityEntity> byCityName = cityDao.findByCityName(sysUserQo.getCountyName());
|
||||||
|
if(byCityName == null || byCityName.size() == 0){
|
||||||
|
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"您所选择的区域不存在!",locale);
|
||||||
|
}
|
||||||
sysUserEntity.setActiveFlag(1);
|
sysUserEntity.setActiveFlag(1);
|
||||||
sysUserEntity.setAccountType("市级");
|
sysUserEntity.setAccountType("市级");
|
||||||
}else {
|
}else {
|
||||||
|
CountyEntity byCountyCode = countyDao.findByCountyCode(sysUserQo.getCountyCode());
|
||||||
|
if(byCountyCode == null){
|
||||||
|
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"编码不存在!",locale);
|
||||||
|
}
|
||||||
|
CountyEntity byCountyName = countyDao.findByCountyName(sysUserQo.getCountyName());
|
||||||
|
if(byCountyName == null){
|
||||||
|
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"您所选择的区域不存在!",locale);
|
||||||
|
}
|
||||||
sysUserEntity.setActiveFlag(0);
|
sysUserEntity.setActiveFlag(0);
|
||||||
sysUserEntity.setAccountType("县级");
|
sysUserEntity.setAccountType("县级");
|
||||||
}
|
}
|
||||||
@ -99,7 +138,7 @@ public class SysUserServiceImpl implements SysUserService {
|
|||||||
sysUserEntity.setAddTime(dateTimeToString(LocalDateTime.now()));
|
sysUserEntity.setAddTime(dateTimeToString(LocalDateTime.now()));
|
||||||
sysUserEntity.setDeleteFlag(0);
|
sysUserEntity.setDeleteFlag(0);
|
||||||
sysUserEntity.setDayNum(7);
|
sysUserEntity.setDayNum(7);
|
||||||
String string = dateTimeToString(LocalDateTime.now().plusDays(7L));
|
String string = dateTimeToString(LocalDateTime.now().plusDays(3L));
|
||||||
sysUserEntity.setOverTime(string);
|
sysUserEntity.setOverTime(string);
|
||||||
sysUserEntity.setLoginNum(0);
|
sysUserEntity.setLoginNum(0);
|
||||||
sysUserEntity.setCountyName(sysUserQo.getCountyName());
|
sysUserEntity.setCountyName(sysUserQo.getCountyName());
|
||||||
@ -376,6 +415,17 @@ public class SysUserServiceImpl implements SysUserService {
|
|||||||
sysUserDao.updateLoginNum(userId,loginNum);
|
sysUserDao.updateLoginNum(userId,loginNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 记录用户登录时间
|
||||||
|
* @param userId
|
||||||
|
* @param loginLastTime
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor=Exception.class)
|
||||||
|
@Override
|
||||||
|
public void updateLoginLastTime(Integer userId, String loginLastTime) {
|
||||||
|
sysUserDao.updateLoginLastTime(userId,loginLastTime);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, String>> findCityByProCode(String proCode) {
|
public List<Map<String, String>> findCityByProCode(String proCode) {
|
||||||
return nationwideDao.findCityByProCode(proCode);
|
return nationwideDao.findCityByProCode(proCode);
|
||||||
|
@ -289,7 +289,7 @@ public class AddressUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String latAndLng = getLocal("34.68", "117.74");
|
String latAndLng = getLocal("36.89", "115.90");
|
||||||
System.out.println(latAndLng);
|
System.out.println(latAndLng);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,11 +218,8 @@ public class DateTimeUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
LocalDateTime overTime = DateTimeUtil.stringToDateTime("2021-08-15 00:00:00");
|
long l = dateToTimeMillis(LocalDateTime.now());
|
||||||
// 计算距离结束时间的天数作为token
|
System.out.println("------"+l);
|
||||||
Duration duration = Duration.between(LocalDateTime.now(), overTime);
|
|
||||||
long l = duration.toDays();
|
|
||||||
System.out.println(l);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user