27 changed files with 1457 additions and 295 deletions
@ -0,0 +1,11 @@ |
|||||
|
package com.base.springcloud.aspect.annotation; |
||||
|
|
||||
|
import java.lang.annotation.*; |
||||
|
|
||||
|
@Target(ElementType.METHOD) |
||||
|
@Documented |
||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||
|
public @interface LoginRequired { |
||||
|
// 部门 ture - 获取部门信息
|
||||
|
boolean department() default false; |
||||
|
} |
||||
@ -1,32 +0,0 @@ |
|||||
package com.base.springcloud.aspect.aspect; |
|
||||
|
|
||||
import org.springframework.context.annotation.Configuration; |
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry; |
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
|
||||
|
|
||||
/** |
|
||||
* Spring Boot 2.0 解决跨域问题 |
|
||||
* |
|
||||
* @Author qinfeng |
|
||||
* |
|
||||
*/ |
|
||||
@Configuration |
|
||||
public class WebMvcConfiguration implements WebMvcConfigurer { |
|
||||
|
|
||||
|
|
||||
@Override |
|
||||
public void addCorsMappings(CorsRegistry registry){ |
|
||||
// 设置允许跨域的路由
|
|
||||
registry.addMapping("/**") |
|
||||
// 设置允许跨域请求的域名------------修改此行
|
|
||||
.allowedOrigins("*") |
|
||||
// 是否允许证书(cookies)
|
|
||||
.allowCredentials(true) |
|
||||
// 设置允许的方法
|
|
||||
.allowedMethods("*") |
|
||||
// 跨域允许时间
|
|
||||
.maxAge(3600); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
} |
|
||||
@ -0,0 +1,25 @@ |
|||||
|
package com.base.springcloud.aspect.config; |
||||
|
|
||||
|
import com.base.springcloud.aspect.interceptor.PayInterceptor; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry; |
||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
||||
|
|
||||
|
public class PayConfigurer implements WebMvcConfigurer { |
||||
|
|
||||
|
@Autowired |
||||
|
private PayInterceptor payInterceptor; |
||||
|
|
||||
|
// 拦截器请求 :'/merchant/**','/payment/**'
|
||||
|
@Override |
||||
|
public void addInterceptors(InterceptorRegistry registry){ |
||||
|
registry.addInterceptor(payInterceptor).addPathPatterns("/merchant/**","/payment/**"); |
||||
|
} |
||||
|
|
||||
|
// 跨域配置
|
||||
|
@Override |
||||
|
public void addCorsMappings(CorsRegistry registry) { |
||||
|
registry.addMapping("/**").allowCredentials(true).allowedOrigins("*").allowedMethods("GET", "PUT", "DELETE", "POST", "OPTIONS").maxAge(3600); |
||||
|
} |
||||
|
} |
||||
@ -1,6 +1,7 @@ |
|||||
package com.base.springcloud.constant; |
package com.base.springcloud.aspect.config; |
||||
|
|
||||
|
|
||||
|
import com.base.springcloud.constant.FastJson2JsonRedisSerializer; |
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect; |
import com.fasterxml.jackson.annotation.JsonAutoDetect; |
||||
import com.fasterxml.jackson.annotation.PropertyAccessor; |
import com.fasterxml.jackson.annotation.PropertyAccessor; |
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
@ -0,0 +1,52 @@ |
|||||
|
package com.base.springcloud.aspect.interceptor; |
||||
|
|
||||
|
import com.base.springcloud.aspect.annotation.LoginRequired; |
||||
|
import com.base.springcloud.util.TokenUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.lang.Nullable; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.web.method.HandlerMethod; |
||||
|
import org.springframework.web.servlet.HandlerInterceptor; |
||||
|
import org.springframework.web.servlet.ModelAndView; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
|
||||
|
@Component |
||||
|
public class PayInterceptor implements HandlerInterceptor { |
||||
|
|
||||
|
@Autowired |
||||
|
private TokenUtils tokenUtils; |
||||
|
|
||||
|
// 在业务处理器处理请求之前被调用
|
||||
|
@Override |
||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
||||
|
LoginRequired loginRequired; |
||||
|
// 根据注解拦截请求
|
||||
|
if (handler instanceof HandlerMethod) { |
||||
|
loginRequired = ((HandlerMethod)handler).getMethodAnnotation(LoginRequired.class); |
||||
|
} else { |
||||
|
return true; |
||||
|
} |
||||
|
// 说明此方法没有LoginRequired注解
|
||||
|
if (loginRequired == null) |
||||
|
return true; |
||||
|
// token数据验证
|
||||
|
tokenUtils.verifyToken(request); |
||||
|
// 部门信息获取
|
||||
|
if(loginRequired.department()) |
||||
|
tokenUtils.departmentInfo(request); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// 在业务处理器处理请求执行完成后
|
||||
|
@Override |
||||
|
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView){ |
||||
|
|
||||
|
}; |
||||
|
|
||||
|
// 在DispatcherServlet完全处理完请求后被调用
|
||||
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex){ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
package com.base.springcloud.dao; |
||||
|
|
||||
|
import com.base.springcloud.entity.User; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
import org.springframework.stereotype.Repository; |
||||
|
|
||||
|
@Repository |
||||
|
public interface UserMapper { |
||||
|
int deleteByPrimaryKey(String id); |
||||
|
|
||||
|
int insert(User record); |
||||
|
|
||||
|
int insertSelective(User record); |
||||
|
|
||||
|
User selectByPrimaryKey(String id); |
||||
|
|
||||
|
int updateByPrimaryKeySelective(User record); |
||||
|
|
||||
|
int updateByPrimaryKey(User record); |
||||
|
|
||||
|
User getUser(@Param("userName") String userName); |
||||
|
} |
||||
@ -0,0 +1,62 @@ |
|||||
|
package com.base.springcloud.entity; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
@Data |
||||
|
public class User { |
||||
|
private String id; |
||||
|
|
||||
|
private String userName; |
||||
|
|
||||
|
private String realName; |
||||
|
|
||||
|
private String password; |
||||
|
|
||||
|
private String salt; |
||||
|
|
||||
|
private String avatar; |
||||
|
|
||||
|
private Date birthday; |
||||
|
|
||||
|
private Integer sex; |
||||
|
|
||||
|
private String email ; |
||||
|
|
||||
|
private String phone; |
||||
|
|
||||
|
private String orgCode; |
||||
|
|
||||
|
private Integer status; |
||||
|
|
||||
|
private Integer delFlag; |
||||
|
|
||||
|
private String thirdId; |
||||
|
|
||||
|
private String thirdType; |
||||
|
|
||||
|
private Integer activitiSync; |
||||
|
|
||||
|
private String workNo; |
||||
|
|
||||
|
private String post; |
||||
|
|
||||
|
private String telephone; |
||||
|
|
||||
|
private String createBy; |
||||
|
|
||||
|
private Date createTime; |
||||
|
|
||||
|
private String updateBy; |
||||
|
|
||||
|
private Date updateTime; |
||||
|
|
||||
|
private Integer userIdentity; |
||||
|
|
||||
|
private String departIds; |
||||
|
|
||||
|
private String ctCompanyId; |
||||
|
|
||||
|
private Integer accountType; |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
package com.base.springcloud.service; |
||||
|
|
||||
|
import com.base.springcloud.bo.RefundBO; |
||||
|
|
||||
|
public interface RefundService { |
||||
|
|
||||
|
/** |
||||
|
* 退款 |
||||
|
* @param refundBO |
||||
|
*/ |
||||
|
void refund(RefundBO refundBO); |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
package com.base.springcloud.service; |
||||
|
|
||||
|
import com.base.springcloud.entity.User; |
||||
|
|
||||
|
public interface UserService { |
||||
|
|
||||
|
/** |
||||
|
* 获取用户信息 |
||||
|
* @param userName |
||||
|
*/ |
||||
|
User getUser(String userName); |
||||
|
|
||||
|
/** |
||||
|
* TOKEN有效期校验 |
||||
|
* @param token |
||||
|
* @param user |
||||
|
*/ |
||||
|
void TokenValidity(String token, User user); |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
package com.base.springcloud.service.imp; |
||||
|
|
||||
|
import com.base.springcloud.bo.RefundBO; |
||||
|
import com.base.springcloud.service.RefundService; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
@Service |
||||
|
public class RefundServiceImp implements RefundService { |
||||
|
|
||||
|
@Override |
||||
|
public void refund(RefundBO refundBO) { |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,64 @@ |
|||||
|
package com.base.springcloud.service.imp; |
||||
|
|
||||
|
import com.base.springcloud.aspect.annotation.BusinessException; |
||||
|
import com.base.springcloud.constant.ErrorConstant; |
||||
|
import com.base.springcloud.constant.PaymentConstant; |
||||
|
import com.base.springcloud.dao.UserMapper; |
||||
|
import com.base.springcloud.entity.User; |
||||
|
import com.base.springcloud.service.UserService; |
||||
|
import com.base.springcloud.util.JwtUtil; |
||||
|
import com.base.springcloud.util.RedisUtil; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.cache.annotation.Cacheable; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.Optional; |
||||
|
|
||||
|
@Service |
||||
|
public class UserServiceImp implements UserService { |
||||
|
|
||||
|
@Autowired |
||||
|
private UserMapper userMapper; |
||||
|
|
||||
|
@Autowired |
||||
|
private RedisUtil redisService; |
||||
|
|
||||
|
/** |
||||
|
* 获取用户信息 |
||||
|
* @param userName |
||||
|
* @return |
||||
|
*/ |
||||
|
@Override |
||||
|
@Cacheable(cacheNames="cache:pay:user", key="#userName") |
||||
|
public User getUser(String userName) { |
||||
|
User user = userMapper.getUser(userName); |
||||
|
if(!Optional.ofNullable(user).isPresent()){ |
||||
|
throw new BusinessException(ErrorConstant.USER_ERROR); |
||||
|
} |
||||
|
// 判断用户状态
|
||||
|
if (user.getStatus() != 1) { |
||||
|
throw new BusinessException(ErrorConstant.USER_LOCKING); |
||||
|
} |
||||
|
return user; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* TOKEN有效期校验 |
||||
|
* @param token |
||||
|
* @param user |
||||
|
*/ |
||||
|
@Override |
||||
|
public void TokenValidity(String token, User user) { |
||||
|
String redisToken = String.valueOf(redisService.get(PaymentConstant.TOKEN_PREFIX + token)); |
||||
|
if(StringUtils.isBlank(redisToken)) |
||||
|
throw new BusinessException(ErrorConstant.TOKEN_EXPIRATION_DATE); |
||||
|
if(!JwtUtil.verify(redisToken, user.getUserName(), user.getPassword())) |
||||
|
throw new BusinessException(ErrorConstant.ILLEGAL_TOKEN); |
||||
|
String newAuthorization = JwtUtil.sign(user.getUserName(), user.getPassword()); |
||||
|
// 设置Toekn缓存有效时间
|
||||
|
redisService.set(PaymentConstant.TOKEN_PREFIX + token, newAuthorization); |
||||
|
redisService.expire(PaymentConstant.TOKEN_PREFIX + token, JwtUtil.EXPIRE_TIME * 2 / 1000); |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,101 @@ |
|||||
|
package com.base.springcloud.util; |
||||
|
|
||||
|
import com.auth0.jwt.JWT; |
||||
|
import com.auth0.jwt.JWTVerifier; |
||||
|
import com.auth0.jwt.algorithms.Algorithm; |
||||
|
import com.auth0.jwt.exceptions.JWTDecodeException; |
||||
|
import com.auth0.jwt.interfaces.DecodedJWT; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* @Author Scott |
||||
|
* @Date 2018-07-12 14:23 |
||||
|
* @Desc JWT工具类 |
||||
|
**/ |
||||
|
public class JwtUtil { |
||||
|
|
||||
|
/** |
||||
|
* Token过期时间30分钟(用户登录过期时间是此时间的两倍,以token在reids缓存时间为准) |
||||
|
*/ |
||||
|
public static final long EXPIRE_TIME = 30 * 60 * 1000; |
||||
|
|
||||
|
/** |
||||
|
* 校验token是否正确 |
||||
|
* |
||||
|
* @param token 密钥 |
||||
|
* @param secret 用户的密码 |
||||
|
* @return 是否正确 |
||||
|
*/ |
||||
|
public static boolean verify(String token, String username, String secret) { |
||||
|
try { |
||||
|
// 根据密码生成JWT效验器
|
||||
|
Algorithm algorithm = Algorithm.HMAC256(secret); |
||||
|
JWTVerifier verifier = JWT.require(algorithm).withClaim("username", username).build(); |
||||
|
// 效验TOKEN
|
||||
|
DecodedJWT jwt = verifier.verify(token); |
||||
|
return true; |
||||
|
} catch (Exception exception) { |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获得token中的信息无需secret解密也能获得 |
||||
|
* |
||||
|
* @return token中包含的用户名 |
||||
|
*/ |
||||
|
public static String getUsername(String token) { |
||||
|
try { |
||||
|
DecodedJWT jwt = JWT.decode(token); |
||||
|
return jwt.getClaim("username").asString(); |
||||
|
} catch (JWTDecodeException e) { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获得token中的信息无需secret解密也能获得 |
||||
|
* |
||||
|
* @return token中包含的用户名 |
||||
|
*/ |
||||
|
public static String getPlatform(String token) { |
||||
|
try { |
||||
|
DecodedJWT jwt = JWT.decode(token); |
||||
|
return jwt.getClaim("platform").asString(); |
||||
|
} catch (JWTDecodeException e) { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 生成签名,5min后过期 |
||||
|
* |
||||
|
* @param username 用户名 |
||||
|
* @param secret 用户的密码 |
||||
|
* @return 加密的token |
||||
|
*/ |
||||
|
public static String sign(String username, String secret) { |
||||
|
Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME); |
||||
|
Algorithm algorithm = Algorithm.HMAC256(secret); |
||||
|
// 附带username信息
|
||||
|
return JWT.create().withClaim("username", username).withExpiresAt(date).sign(algorithm); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 生成签名,5min后过期 |
||||
|
* |
||||
|
* @param username 用户名 |
||||
|
* @param secret 用户的密码 |
||||
|
* @return 加密的token |
||||
|
*/ |
||||
|
public static String sign(String username, String secret,String platform) { |
||||
|
Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME); |
||||
|
Algorithm algorithm = Algorithm.HMAC256(secret); |
||||
|
// 附带username信息
|
||||
|
return JWT.create().withClaim("username", username).withClaim("platform",platform).withExpiresAt(date).sign(algorithm); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,568 @@ |
|||||
|
package com.base.springcloud.util; |
||||
|
|
||||
|
import org.springframework.data.redis.core.RedisTemplate; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.util.CollectionUtils; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import java.util.Collection; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.Set; |
||||
|
import java.util.concurrent.TimeUnit; |
||||
|
|
||||
|
/** |
||||
|
* redis 工具类 |
||||
|
* @Author Scott |
||||
|
* |
||||
|
*/ |
||||
|
@Component |
||||
|
public class RedisUtil { |
||||
|
|
||||
|
@Resource |
||||
|
private RedisTemplate<String, Object> 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((Collection<String>) 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 键 |
||||
|
* @return |
||||
|
*/ |
||||
|
public long incr(String key, long delta) { |
||||
|
if (delta < 0) { |
||||
|
throw new RuntimeException("递增因子必须大于0"); |
||||
|
} |
||||
|
return redisTemplate.opsForValue().increment(key, delta); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 递减 |
||||
|
* |
||||
|
* @param key 键 |
||||
|
* @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 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; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,57 @@ |
|||||
|
package com.base.springcloud.util; |
||||
|
|
||||
|
import com.base.springcloud.aspect.annotation.BusinessException; |
||||
|
import com.base.springcloud.constant.ErrorConstant; |
||||
|
import com.base.springcloud.entity.User; |
||||
|
import com.base.springcloud.service.UserService; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.annotation.PostConstruct; |
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
|
||||
|
@Component |
||||
|
public class TokenUtils { |
||||
|
|
||||
|
@Autowired |
||||
|
private UserService userService; |
||||
|
|
||||
|
private static UserService service; |
||||
|
|
||||
|
@PostConstruct |
||||
|
public void init() { |
||||
|
service= this.userService; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Token验证 |
||||
|
*/ |
||||
|
public static void verifyToken(HttpServletRequest request) { |
||||
|
// 从请求头获取token
|
||||
|
String token = request.getHeader("X-Access-Token"); |
||||
|
|
||||
|
// 如果请求头没有token,则从请求参数中取
|
||||
|
if (StringUtils.isBlank(token)) |
||||
|
token = request.getParameter("token"); |
||||
|
|
||||
|
// 如果还是没有token,则抛异常
|
||||
|
if (StringUtils.isBlank(token)) |
||||
|
throw new BusinessException(ErrorConstant.INVALID_TOKEN); |
||||
|
|
||||
|
// 从token里获取用户姓名
|
||||
|
String username = JwtUtil.getUsername(token); |
||||
|
if (StringUtils.isEmpty(username)) |
||||
|
throw new BusinessException(ErrorConstant.ILLEGAL_TOKEN); |
||||
|
|
||||
|
// 查询用户信息
|
||||
|
User user = service.getUser(username); |
||||
|
|
||||
|
// 校验token是否超时失效 & 或者账号密码是否错误
|
||||
|
service.TokenValidity(token,user); |
||||
|
} |
||||
|
|
||||
|
public static void departmentInfo(HttpServletRequest request) { |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,360 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
<mapper namespace="com.base.springcloud.dao.UserMapper"> |
||||
|
<resultMap id="BaseResultMap" type="com.base.springcloud.entity.User"> |
||||
|
<id column="id" jdbcType="VARCHAR" property="id" /> |
||||
|
<result column="username" jdbcType="VARCHAR" property="userName" /> |
||||
|
<result column="realname" jdbcType="VARCHAR" property="realName" /> |
||||
|
<result column="password" jdbcType="VARCHAR" property="password" /> |
||||
|
<result column="salt" jdbcType="VARCHAR" property="salt" /> |
||||
|
<result column="avatar" jdbcType="VARCHAR" property="avatar" /> |
||||
|
<result column="birthday" jdbcType="TIMESTAMP" property="birthday" /> |
||||
|
<result column="sex" jdbcType="INTEGER" property="sex" /> |
||||
|
<result column="email" jdbcType="VARCHAR" property="email " /> |
||||
|
<result column="phone" jdbcType="VARCHAR" property="phone" /> |
||||
|
<result column="org_code" jdbcType="VARCHAR" property="orgCode" /> |
||||
|
<result column="status" jdbcType="INTEGER" property="status" /> |
||||
|
<result column="del_flag" jdbcType="INTEGER" property="delFlag" /> |
||||
|
<result column="third_id" jdbcType="VARCHAR" property="thirdId" /> |
||||
|
<result column="third_type" jdbcType="VARCHAR" property="thirdType" /> |
||||
|
<result column="activiti_sync" jdbcType="INTEGER" property="activitiSync" /> |
||||
|
<result column="work_no" jdbcType="VARCHAR" property="workNo" /> |
||||
|
<result column="post" jdbcType="VARCHAR" property="post" /> |
||||
|
<result column="telephone" jdbcType="VARCHAR" property="telephone" /> |
||||
|
<result column="create_by" jdbcType="VARCHAR" property="createBy" /> |
||||
|
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> |
||||
|
<result column="update_by" jdbcType="VARCHAR" property="updateBy" /> |
||||
|
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> |
||||
|
<result column="user_identity" jdbcType="INTEGER" property="userIdentity" /> |
||||
|
<result column="depart_ids" jdbcType="VARCHAR" property="departIds" /> |
||||
|
<result column="ct_company_id" jdbcType="TIMESTAMP" property="ctCompanyId" /> |
||||
|
<result column="account_type" jdbcType="INTEGER" property="accountType" /> |
||||
|
</resultMap> |
||||
|
<sql id="Base_Column_List"> |
||||
|
id, username, realname, password, salt, avatar, birthday, sex, email, phone, org_code, |
||||
|
status, del_flag, third_id, third_type, activiti_sync, work_no, post, telephone, |
||||
|
create_by, create_time, update_by, update_time, user_identity, depart_ids, ct_company_id, |
||||
|
account_type |
||||
|
</sql> |
||||
|
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap"> |
||||
|
select |
||||
|
<include refid="Base_Column_List" /> |
||||
|
from sys_user |
||||
|
where id = #{id,jdbcType=VARCHAR} |
||||
|
</select> |
||||
|
<delete id="deleteByPrimaryKey" parameterType="java.lang.String"> |
||||
|
delete from sys_user |
||||
|
where id = #{id,jdbcType=VARCHAR} |
||||
|
</delete> |
||||
|
<insert id="insert" parameterType="com.base.springcloud.entity.User"> |
||||
|
insert into sys_user (id, username, realname, |
||||
|
password, salt, avatar, |
||||
|
birthday, sex, email, |
||||
|
phone, org_code, status, |
||||
|
del_flag, third_id, third_type, |
||||
|
activiti_sync, work_no, post, |
||||
|
telephone, create_by, create_time, |
||||
|
update_by, update_time, user_identity, |
||||
|
depart_ids, ct_company_id, account_type |
||||
|
) |
||||
|
values (#{id,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, #{realName,jdbcType=VARCHAR}, |
||||
|
#{password,jdbcType=VARCHAR}, #{salt,jdbcType=VARCHAR}, #{avatar,jdbcType=VARCHAR}, |
||||
|
#{birthday,jdbcType=TIMESTAMP}, #{sex,jdbcType=INTEGER}, #{email ,jdbcType=VARCHAR}, |
||||
|
#{phone,jdbcType=VARCHAR}, #{orgCode,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, |
||||
|
#{delFlag,jdbcType=INTEGER}, #{thirdId,jdbcType=VARCHAR}, #{thirdType,jdbcType=VARCHAR}, |
||||
|
#{activitiSync,jdbcType=INTEGER}, #{workNo,jdbcType=VARCHAR}, #{post,jdbcType=VARCHAR}, |
||||
|
#{telephone,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, |
||||
|
#{updateBy,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, #{userIdentity,jdbcType=INTEGER}, |
||||
|
#{departIds,jdbcType=VARCHAR}, #{ctCompanyId,jdbcType=TIMESTAMP}, #{accountType,jdbcType=INTEGER} |
||||
|
) |
||||
|
</insert> |
||||
|
<insert id="insertSelective" parameterType="com.base.springcloud.entity.User"> |
||||
|
insert into sys_user |
||||
|
<trim prefix="(" suffix=")" suffixOverrides=","> |
||||
|
<if test="id != null"> |
||||
|
id, |
||||
|
</if> |
||||
|
<if test="userName != null"> |
||||
|
username, |
||||
|
</if> |
||||
|
<if test="realName != null"> |
||||
|
realname, |
||||
|
</if> |
||||
|
<if test="password != null"> |
||||
|
password, |
||||
|
</if> |
||||
|
<if test="salt != null"> |
||||
|
salt, |
||||
|
</if> |
||||
|
<if test="avatar != null"> |
||||
|
avatar, |
||||
|
</if> |
||||
|
<if test="birthday != null"> |
||||
|
birthday, |
||||
|
</if> |
||||
|
<if test="sex != null"> |
||||
|
sex, |
||||
|
</if> |
||||
|
<if test="email != null"> |
||||
|
email, |
||||
|
</if> |
||||
|
<if test="phone != null"> |
||||
|
phone, |
||||
|
</if> |
||||
|
<if test="orgCode != null"> |
||||
|
org_code, |
||||
|
</if> |
||||
|
<if test="status != null"> |
||||
|
status, |
||||
|
</if> |
||||
|
<if test="delFlag != null"> |
||||
|
del_flag, |
||||
|
</if> |
||||
|
<if test="thirdId != null"> |
||||
|
third_id, |
||||
|
</if> |
||||
|
<if test="thirdType != null"> |
||||
|
third_type, |
||||
|
</if> |
||||
|
<if test="activitiSync != null"> |
||||
|
activiti_sync, |
||||
|
</if> |
||||
|
<if test="workNo != null"> |
||||
|
work_no, |
||||
|
</if> |
||||
|
<if test="post != null"> |
||||
|
post, |
||||
|
</if> |
||||
|
<if test="telephone != null"> |
||||
|
telephone, |
||||
|
</if> |
||||
|
<if test="createBy != null"> |
||||
|
create_by, |
||||
|
</if> |
||||
|
<if test="createTime != null"> |
||||
|
create_time, |
||||
|
</if> |
||||
|
<if test="updateBy != null"> |
||||
|
update_by, |
||||
|
</if> |
||||
|
<if test="updateTime != null"> |
||||
|
update_time, |
||||
|
</if> |
||||
|
<if test="userIdentity != null"> |
||||
|
user_identity, |
||||
|
</if> |
||||
|
<if test="departIds != null"> |
||||
|
depart_ids, |
||||
|
</if> |
||||
|
<if test="ctCompanyId != null"> |
||||
|
ct_company_id, |
||||
|
</if> |
||||
|
<if test="accountType != null"> |
||||
|
account_type, |
||||
|
</if> |
||||
|
</trim> |
||||
|
<trim prefix="values (" suffix=")" suffixOverrides=","> |
||||
|
<if test="id != null"> |
||||
|
#{id,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="userName != null"> |
||||
|
#{userName,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="realName != null"> |
||||
|
#{realName,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="password != null"> |
||||
|
#{password,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="salt != null"> |
||||
|
#{salt,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="avatar != null"> |
||||
|
#{avatar,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="birthday != null"> |
||||
|
#{birthday,jdbcType=TIMESTAMP}, |
||||
|
</if> |
||||
|
<if test="sex != null"> |
||||
|
#{sex,jdbcType=INTEGER}, |
||||
|
</if> |
||||
|
<if test="email != null"> |
||||
|
#{email ,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="phone != null"> |
||||
|
#{phone,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="orgCode != null"> |
||||
|
#{orgCode,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="status != null"> |
||||
|
#{status,jdbcType=INTEGER}, |
||||
|
</if> |
||||
|
<if test="delFlag != null"> |
||||
|
#{delFlag,jdbcType=INTEGER}, |
||||
|
</if> |
||||
|
<if test="thirdId != null"> |
||||
|
#{thirdId,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="thirdType != null"> |
||||
|
#{thirdType,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="activitiSync != null"> |
||||
|
#{activitiSync,jdbcType=INTEGER}, |
||||
|
</if> |
||||
|
<if test="workNo != null"> |
||||
|
#{workNo,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="post != null"> |
||||
|
#{post,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="telephone != null"> |
||||
|
#{telephone,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="createBy != null"> |
||||
|
#{createBy,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="createTime != null"> |
||||
|
#{createTime,jdbcType=TIMESTAMP}, |
||||
|
</if> |
||||
|
<if test="updateBy != null"> |
||||
|
#{updateBy,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="updateTime != null"> |
||||
|
#{updateTime,jdbcType=TIMESTAMP}, |
||||
|
</if> |
||||
|
<if test="userIdentity != null"> |
||||
|
#{userIdentity,jdbcType=INTEGER}, |
||||
|
</if> |
||||
|
<if test="departIds != null"> |
||||
|
#{departIds,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="ctCompanyId != null"> |
||||
|
#{ctCompanyId,jdbcType=TIMESTAMP}, |
||||
|
</if> |
||||
|
<if test="accountType != null"> |
||||
|
#{accountType,jdbcType=INTEGER}, |
||||
|
</if> |
||||
|
</trim> |
||||
|
</insert> |
||||
|
<update id="updateByPrimaryKeySelective" parameterType="com.base.springcloud.entity.User"> |
||||
|
update sys_user |
||||
|
<set> |
||||
|
<if test="userName != null"> |
||||
|
username = #{userName,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="realName != null"> |
||||
|
realname = #{realName,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="password != null"> |
||||
|
password = #{password,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="salt != null"> |
||||
|
salt = #{salt,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="avatar != null"> |
||||
|
avatar = #{avatar,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="birthday != null"> |
||||
|
birthday = #{birthday,jdbcType=TIMESTAMP}, |
||||
|
</if> |
||||
|
<if test="sex != null"> |
||||
|
sex = #{sex,jdbcType=INTEGER}, |
||||
|
</if> |
||||
|
<if test="email != null"> |
||||
|
email = #{email ,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="phone != null"> |
||||
|
phone = #{phone,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="orgCode != null"> |
||||
|
org_code = #{orgCode,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="status != null"> |
||||
|
status = #{status,jdbcType=INTEGER}, |
||||
|
</if> |
||||
|
<if test="delFlag != null"> |
||||
|
del_flag = #{delFlag,jdbcType=INTEGER}, |
||||
|
</if> |
||||
|
<if test="thirdId != null"> |
||||
|
third_id = #{thirdId,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="thirdType != null"> |
||||
|
third_type = #{thirdType,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="activitiSync != null"> |
||||
|
activiti_sync = #{activitiSync,jdbcType=INTEGER}, |
||||
|
</if> |
||||
|
<if test="workNo != null"> |
||||
|
work_no = #{workNo,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="post != null"> |
||||
|
post = #{post,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="telephone != null"> |
||||
|
telephone = #{telephone,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="createBy != null"> |
||||
|
create_by = #{createBy,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="createTime != null"> |
||||
|
create_time = #{createTime,jdbcType=TIMESTAMP}, |
||||
|
</if> |
||||
|
<if test="updateBy != null"> |
||||
|
update_by = #{updateBy,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="updateTime != null"> |
||||
|
update_time = #{updateTime,jdbcType=TIMESTAMP}, |
||||
|
</if> |
||||
|
<if test="userIdentity != null"> |
||||
|
user_identity = #{userIdentity,jdbcType=INTEGER}, |
||||
|
</if> |
||||
|
<if test="departIds != null"> |
||||
|
depart_ids = #{departIds,jdbcType=VARCHAR}, |
||||
|
</if> |
||||
|
<if test="ctCompanyId != null"> |
||||
|
ct_company_id = #{ctCompanyId,jdbcType=TIMESTAMP}, |
||||
|
</if> |
||||
|
<if test="accountType != null"> |
||||
|
account_type = #{accountType,jdbcType=INTEGER}, |
||||
|
</if> |
||||
|
</set> |
||||
|
where id = #{id,jdbcType=VARCHAR} |
||||
|
</update> |
||||
|
<update id="updateByPrimaryKey" parameterType="com.base.springcloud.entity.User"> |
||||
|
update sys_user |
||||
|
set username = #{userName,jdbcType=VARCHAR}, |
||||
|
realname = #{realName,jdbcType=VARCHAR}, |
||||
|
password = #{password,jdbcType=VARCHAR}, |
||||
|
salt = #{salt,jdbcType=VARCHAR}, |
||||
|
avatar = #{avatar,jdbcType=VARCHAR}, |
||||
|
birthday = #{birthday,jdbcType=TIMESTAMP}, |
||||
|
sex = #{sex,jdbcType=INTEGER}, |
||||
|
email = #{email ,jdbcType=VARCHAR}, |
||||
|
phone = #{phone,jdbcType=VARCHAR}, |
||||
|
org_code = #{orgCode,jdbcType=VARCHAR}, |
||||
|
status = #{status,jdbcType=INTEGER}, |
||||
|
del_flag = #{delFlag,jdbcType=INTEGER}, |
||||
|
third_id = #{thirdId,jdbcType=VARCHAR}, |
||||
|
third_type = #{thirdType,jdbcType=VARCHAR}, |
||||
|
activiti_sync = #{activitiSync,jdbcType=INTEGER}, |
||||
|
work_no = #{workNo,jdbcType=VARCHAR}, |
||||
|
post = #{post,jdbcType=VARCHAR}, |
||||
|
telephone = #{telephone,jdbcType=VARCHAR}, |
||||
|
create_by = #{createBy,jdbcType=VARCHAR}, |
||||
|
create_time = #{createTime,jdbcType=TIMESTAMP}, |
||||
|
update_by = #{updateBy,jdbcType=VARCHAR}, |
||||
|
update_time = #{updateTime,jdbcType=TIMESTAMP}, |
||||
|
user_identity = #{userIdentity,jdbcType=INTEGER}, |
||||
|
depart_ids = #{departIds,jdbcType=VARCHAR}, |
||||
|
ct_company_id = #{ctCompanyId,jdbcType=TIMESTAMP}, |
||||
|
account_type = #{accountType,jdbcType=INTEGER} |
||||
|
where id = #{id,jdbcType=VARCHAR} |
||||
|
</update> |
||||
|
<select id="getUser" parameterType="java.lang.String" resultMap="BaseResultMap"> |
||||
|
select |
||||
|
<include refid="Base_Column_List" /> |
||||
|
from sys_user |
||||
|
where username = #{userName,jdbcType=VARCHAR} |
||||
|
</select> |
||||
|
</mapper> |
||||
Loading…
Reference in new issue