beanDefinitions = scanner.findCandidateComponents(basePackage);
+ return beanDefinitions.stream()
+ .map(BeanDefinition::getBeanClassName)
+ .map(className -> {
+ try {
+ return Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ })
+ .collect(Collectors.toSet());
+ }
+
+ private static ClassPathScanningCandidateComponentProvider getInstance(){
+ if (scanner == null){
+ scanner = new ClassPathScanningCandidateComponentProvider(false);
+ }
+ return scanner;
+ }
+
+}
\ No newline at end of file
diff --git a/renren-fast/src/main/java/io/renren/common/utils/ConfigConstant.java b/renren-fast/src/main/java/io/renren/common/utils/ConfigConstant.java
new file mode 100644
index 0000000..32897da
--- /dev/null
+++ b/renren-fast/src/main/java/io/renren/common/utils/ConfigConstant.java
@@ -0,0 +1,21 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package io.renren.common.utils;
+
+/**
+ * 系统参数相关Key
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class ConfigConstant {
+ /**
+ * 云存储配置KEY
+ */
+ public final static String CLOUD_STORAGE_CONFIG_KEY = "CLOUD_STORAGE_CONFIG_KEY";
+}
diff --git a/renren-fast/src/main/java/io/renren/common/utils/Constant.java b/renren-fast/src/main/java/io/renren/common/utils/Constant.java
new file mode 100644
index 0000000..da3d5bc
--- /dev/null
+++ b/renren-fast/src/main/java/io/renren/common/utils/Constant.java
@@ -0,0 +1,152 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package io.renren.common.utils;
+
+import io.renren.common.validator.group.AliyunGroup;
+import io.renren.common.validator.group.QcloudGroup;
+import io.renren.common.validator.group.QiniuGroup;
+
+import java.util.Optional;
+import java.util.stream.Stream;
+
+/**
+ * 常量
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class Constant {
+ /**
+ * 超级管理员ID
+ */
+ public static final int SUPER_ADMIN = 1;
+ /**
+ * 当前页码
+ */
+ public static final String PAGE = "page";
+ /**
+ * 每页显示记录数
+ */
+ public static final String LIMIT = "limit";
+ /**
+ * 排序字段
+ */
+ public static final String ORDER_FIELD = "sidx";
+ /**
+ * 排序方式
+ */
+ public static final String ORDER = "order";
+ /**
+ * 升序
+ */
+ public static final String ASC = "asc";
+
+ /**
+ * 菜单类型
+ *
+ * @author chenshun
+ * @email sunlightcs@gmail.com
+ * @date 2016年11月15日 下午1:24:29
+ */
+ public enum MenuType {
+ /**
+ * 目录
+ */
+ CATALOG(0),
+ /**
+ * 菜单
+ */
+ MENU(1),
+ /**
+ * 按钮
+ */
+ BUTTON(2);
+
+ private int value;
+
+ MenuType(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+ }
+
+ /**
+ * 定时任务状态
+ *
+ * @author chenshun
+ * @email sunlightcs@gmail.com
+ * @date 2016年12月3日 上午12:07:22
+ */
+ public enum ScheduleStatus {
+ /**
+ * 正常
+ */
+ NORMAL(0),
+ /**
+ * 暂停
+ */
+ PAUSE(1);
+
+ private int value;
+
+ ScheduleStatus(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+ }
+
+ /**
+ * 云服务商
+ */
+ public enum CloudService {
+ /**
+ * 七牛云
+ */
+ QINIU(1, QiniuGroup.class),
+ /**
+ * 阿里云
+ */
+ ALIYUN(2, AliyunGroup.class),
+ /**
+ * 腾讯云
+ */
+ QCLOUD(3, QcloudGroup.class);
+
+ private int value;
+
+ private Class> validatorGroupClass;
+
+ CloudService(int value, Class> validatorGroupClass) {
+ this.value = value;
+ this.validatorGroupClass = validatorGroupClass;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public Class> getValidatorGroupClass() {
+ return this.validatorGroupClass;
+ }
+
+ public static CloudService getByValue(Integer value) {
+ Optional first = Stream.of(CloudService.values()).filter(cs -> value.equals(cs.value)).findFirst();
+ if (!first.isPresent()) {
+ throw new IllegalArgumentException("非法的枚举值:" + value);
+ }
+ return first.get();
+ }
+ }
+
+}
diff --git a/renren-fast/src/main/java/io/renren/common/utils/DateUtils.java b/renren-fast/src/main/java/io/renren/common/utils/DateUtils.java
new file mode 100644
index 0000000..798f7ba
--- /dev/null
+++ b/renren-fast/src/main/java/io/renren/common/utils/DateUtils.java
@@ -0,0 +1,166 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package io.renren.common.utils;
+
+import org.apache.commons.lang.StringUtils;
+import org.joda.time.DateTime;
+import org.joda.time.LocalDate;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * 日期处理
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class DateUtils {
+ /** 时间格式(yyyy-MM-dd) */
+ public final static String DATE_PATTERN = "yyyy-MM-dd";
+ /** 时间格式(yyyy-MM-dd HH:mm:ss) */
+ public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
+
+ /**
+ * 日期格式化 日期格式为:yyyy-MM-dd
+ * @param date 日期
+ * @return 返回yyyy-MM-dd格式日期
+ */
+ public static String format(Date date) {
+ return format(date, DATE_PATTERN);
+ }
+
+ /**
+ * 日期格式化 日期格式为:yyyy-MM-dd
+ * @param date 日期
+ * @param pattern 格式,如:DateUtils.DATE_TIME_PATTERN
+ * @return 返回yyyy-MM-dd格式日期
+ */
+ public static String format(Date date, String pattern) {
+ if(date != null){
+ SimpleDateFormat df = new SimpleDateFormat(pattern);
+ return df.format(date);
+ }
+ return null;
+ }
+
+ /**
+ * 字符串转换成日期
+ * @param strDate 日期字符串
+ * @param pattern 日期的格式,如:DateUtils.DATE_TIME_PATTERN
+ */
+ public static Date stringToDate(String strDate, String pattern) {
+ if (StringUtils.isBlank(strDate)){
+ return null;
+ }
+
+ DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
+ return fmt.parseLocalDateTime(strDate).toDate();
+ }
+
+ /**
+ * 根据周数,获取开始日期、结束日期
+ * @param week 周期 0本周,-1上周,-2上上周,1下周,2下下周
+ * @return 返回date[0]开始日期、date[1]结束日期
+ */
+ public static Date[] getWeekStartAndEnd(int week) {
+ DateTime dateTime = new DateTime();
+ LocalDate date = new LocalDate(dateTime.plusWeeks(week));
+
+ date = date.dayOfWeek().withMinimumValue();
+ Date beginDate = date.toDate();
+ Date endDate = date.plusDays(6).toDate();
+ return new Date[]{beginDate, endDate};
+ }
+
+ /**
+ * 对日期的【秒】进行加/减
+ *
+ * @param date 日期
+ * @param seconds 秒数,负数为减
+ * @return 加/减几秒后的日期
+ */
+ public static Date addDateSeconds(Date date, int seconds) {
+ DateTime dateTime = new DateTime(date);
+ return dateTime.plusSeconds(seconds).toDate();
+ }
+
+ /**
+ * 对日期的【分钟】进行加/减
+ *
+ * @param date 日期
+ * @param minutes 分钟数,负数为减
+ * @return 加/减几分钟后的日期
+ */
+ public static Date addDateMinutes(Date date, int minutes) {
+ DateTime dateTime = new DateTime(date);
+ return dateTime.plusMinutes(minutes).toDate();
+ }
+
+ /**
+ * 对日期的【小时】进行加/减
+ *
+ * @param date 日期
+ * @param hours 小时数,负数为减
+ * @return 加/减几小时后的日期
+ */
+ public static Date addDateHours(Date date, int hours) {
+ DateTime dateTime = new DateTime(date);
+ return dateTime.plusHours(hours).toDate();
+ }
+
+ /**
+ * 对日期的【天】进行加/减
+ *
+ * @param date 日期
+ * @param days 天数,负数为减
+ * @return 加/减几天后的日期
+ */
+ public static Date addDateDays(Date date, int days) {
+ DateTime dateTime = new DateTime(date);
+ return dateTime.plusDays(days).toDate();
+ }
+
+ /**
+ * 对日期的【周】进行加/减
+ *
+ * @param date 日期
+ * @param weeks 周数,负数为减
+ * @return 加/减几周后的日期
+ */
+ public static Date addDateWeeks(Date date, int weeks) {
+ DateTime dateTime = new DateTime(date);
+ return dateTime.plusWeeks(weeks).toDate();
+ }
+
+ /**
+ * 对日期的【月】进行加/减
+ *
+ * @param date 日期
+ * @param months 月数,负数为减
+ * @return 加/减几月后的日期
+ */
+ public static Date addDateMonths(Date date, int months) {
+ DateTime dateTime = new DateTime(date);
+ return dateTime.plusMonths(months).toDate();
+ }
+
+ /**
+ * 对日期的【年】进行加/减
+ *
+ * @param date 日期
+ * @param years 年数,负数为减
+ * @return 加/减几年后的日期
+ */
+ public static Date addDateYears(Date date, int years) {
+ DateTime dateTime = new DateTime(date);
+ return dateTime.plusYears(years).toDate();
+ }
+}
diff --git a/renren-fast/src/main/java/io/renren/common/utils/HttpContextUtils.java b/renren-fast/src/main/java/io/renren/common/utils/HttpContextUtils.java
new file mode 100644
index 0000000..09aa2c7
--- /dev/null
+++ b/renren-fast/src/main/java/io/renren/common/utils/HttpContextUtils.java
@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package io.renren.common.utils;
+
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class HttpContextUtils {
+
+ public static HttpServletRequest getHttpServletRequest() {
+ return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
+ }
+
+ public static String getDomain(){
+ HttpServletRequest request = getHttpServletRequest();
+ StringBuffer url = request.getRequestURL();
+ return url.delete(url.length() - request.getRequestURI().length(), url.length()).toString();
+ }
+
+ public static String getOrigin(){
+ HttpServletRequest request = getHttpServletRequest();
+ return request.getHeader("Origin");
+ }
+}
diff --git a/renren-fast/src/main/java/io/renren/common/utils/IPUtils.java b/renren-fast/src/main/java/io/renren/common/utils/IPUtils.java
new file mode 100644
index 0000000..2f20be6
--- /dev/null
+++ b/renren-fast/src/main/java/io/renren/common/utils/IPUtils.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package io.renren.common.utils;
+
+import com.alibaba.druid.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * IP地址
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class IPUtils {
+ private static Logger logger = LoggerFactory.getLogger(IPUtils.class);
+
+ /**
+ * 获取IP地址
+ *
+ * 使用Nginx等反向代理软件, 则不能通过request.getRemoteAddr()获取IP地址
+ * 如果使用了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP地址,X-Forwarded-For中第一个非unknown的有效IP字符串,则为真实IP地址
+ */
+ public static String getIpAddr(HttpServletRequest request) {
+ String ip = null;
+ try {
+ ip = request.getHeader("x-forwarded-for");
+ if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("Proxy-Client-IP");
+ }
+ if (StringUtils.isEmpty(ip) || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("WL-Proxy-Client-IP");
+ }
+ if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("HTTP_CLIENT_IP");
+ }
+ if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("HTTP_X_FORWARDED_FOR");
+ }
+ if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getRemoteAddr();
+ }
+ } catch (Exception e) {
+ logger.error("IPUtils ERROR ", e);
+ }
+
+// //使用代理,则获取第一个IP地址
+// if(StringUtils.isEmpty(ip) && ip.length() > 15) {
+// if(ip.indexOf(",") > 0) {
+// ip = ip.substring(0, ip.indexOf(","));
+// }
+// }
+
+ return ip;
+ }
+
+}
diff --git a/renren-fast/src/main/java/io/renren/common/utils/MapUtils.java b/renren-fast/src/main/java/io/renren/common/utils/MapUtils.java
new file mode 100644
index 0000000..95b6fb3
--- /dev/null
+++ b/renren-fast/src/main/java/io/renren/common/utils/MapUtils.java
@@ -0,0 +1,26 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package io.renren.common.utils;
+
+import java.util.HashMap;
+
+
+/**
+ * Map工具类
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class MapUtils extends HashMap {
+
+ @Override
+ public MapUtils put(String key, Object value) {
+ super.put(key, value);
+ return this;
+ }
+}
diff --git a/renren-fast/src/main/java/io/renren/common/utils/PageUtils.java b/renren-fast/src/main/java/io/renren/common/utils/PageUtils.java
new file mode 100644
index 0000000..360452d
--- /dev/null
+++ b/renren-fast/src/main/java/io/renren/common/utils/PageUtils.java
@@ -0,0 +1,110 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package io.renren.common.utils;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 分页工具类
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class PageUtils implements Serializable {
+ private static final long serialVersionUID = 1L;
+ /**
+ * 总记录数
+ */
+ private int totalCount;
+ /**
+ * 每页记录数
+ */
+ private int pageSize;
+ /**
+ * 总页数
+ */
+ private int totalPage;
+ /**
+ * 当前页数
+ */
+ private int currPage;
+ /**
+ * 列表数据
+ */
+ private List> list;
+
+ /**
+ * 分页
+ * @param list 列表数据
+ * @param totalCount 总记录数
+ * @param pageSize 每页记录数
+ * @param currPage 当前页数
+ */
+ public PageUtils(List> list, int totalCount, int pageSize, int currPage) {
+ this.list = list;
+ this.totalCount = totalCount;
+ this.pageSize = pageSize;
+ this.currPage = currPage;
+ this.totalPage = (int)Math.ceil((double)totalCount/pageSize);
+ }
+
+ /**
+ * 分页
+ */
+ public PageUtils(IPage> page) {
+ this.list = page.getRecords();
+ this.totalCount = (int)page.getTotal();
+ this.pageSize = (int)page.getSize();
+ this.currPage = (int)page.getCurrent();
+ this.totalPage = (int)page.getPages();
+ }
+
+ public int getTotalCount() {
+ return totalCount;
+ }
+
+ public void setTotalCount(int totalCount) {
+ this.totalCount = totalCount;
+ }
+
+ public int getPageSize() {
+ return pageSize;
+ }
+
+ public void setPageSize(int pageSize) {
+ this.pageSize = pageSize;
+ }
+
+ public int getTotalPage() {
+ return totalPage;
+ }
+
+ public void setTotalPage(int totalPage) {
+ this.totalPage = totalPage;
+ }
+
+ public int getCurrPage() {
+ return currPage;
+ }
+
+ public void setCurrPage(int currPage) {
+ this.currPage = currPage;
+ }
+
+ public List> getList() {
+ return list;
+ }
+
+ public void setList(List> list) {
+ this.list = list;
+ }
+
+}
diff --git a/renren-fast/src/main/java/io/renren/common/utils/Query.java b/renren-fast/src/main/java/io/renren/common/utils/Query.java
new file mode 100644
index 0000000..ff825a0
--- /dev/null
+++ b/renren-fast/src/main/java/io/renren/common/utils/Query.java
@@ -0,0 +1,77 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package io.renren.common.utils;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.renren.common.xss.SQLFilter;
+import org.apache.commons.lang.StringUtils;
+
+import java.util.Map;
+
+/**
+ * 查询参数
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class Query {
+
+ public IPage getPage(Map params) {
+ return this.getPage(params, null, false);
+ }
+
+ public IPage getPage(Map params, String defaultOrderField, boolean isAsc) {
+ //分页参数
+ long curPage = 1;
+ long limit = 10;
+
+ if(params.get(Constant.PAGE) != null){
+ curPage = Long.parseLong((String)params.get(Constant.PAGE));
+ }
+ if(params.get(Constant.LIMIT) != null){
+ limit = Long.parseLong((String)params.get(Constant.LIMIT));
+ }
+
+ //分页对象
+ Page page = new Page<>(curPage, limit);
+
+ //分页参数
+ params.put(Constant.PAGE, page);
+
+ //排序字段
+ //防止SQL注入(因为sidx、order是通过拼接SQL实现排序的,会有SQL注入风险)
+ String orderField = SQLFilter.sqlInject((String)params.get(Constant.ORDER_FIELD));
+ String order = (String)params.get(Constant.ORDER);
+
+
+ //前端字段排序
+ if(StringUtils.isNotEmpty(orderField) && StringUtils.isNotEmpty(order)){
+ if(Constant.ASC.equalsIgnoreCase(order)) {
+ return page.addOrder(OrderItem.asc(orderField));
+ }else {
+ return page.addOrder(OrderItem.desc(orderField));
+ }
+ }
+
+ //没有排序字段,则不排序
+ if(StringUtils.isBlank(defaultOrderField)){
+ return page;
+ }
+
+ //默认排序
+ if(isAsc) {
+ page.addOrder(OrderItem.asc(defaultOrderField));
+ }else {
+ page.addOrder(OrderItem.desc(defaultOrderField));
+ }
+
+ return page;
+ }
+}
diff --git a/renren-fast/src/main/java/io/renren/common/utils/R.java b/renren-fast/src/main/java/io/renren/common/utils/R.java
new file mode 100644
index 0000000..1da0da6
--- /dev/null
+++ b/renren-fast/src/main/java/io/renren/common/utils/R.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package io.renren.common.utils;
+
+import org.apache.http.HttpStatus;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 返回数据
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class R extends HashMap {
+ private static final long serialVersionUID = 1L;
+
+ public R() {
+ put("code", 0);
+ put("msg", "success");
+ }
+
+ public static R error() {
+ return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常,请联系管理员");
+ }
+
+ public static R error(String msg) {
+ return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
+ }
+
+ public static R error(int code, String msg) {
+ R r = new R();
+ r.put("code", code);
+ r.put("msg", msg);
+ return r;
+ }
+
+ public static R ok(String msg) {
+ R r = new R();
+ r.put("msg", msg);
+ return r;
+ }
+
+ public static R ok(Map map) {
+ R r = new R();
+ r.putAll(map);
+ return r;
+ }
+
+ public static R ok() {
+ return new R();
+ }
+
+ public R put(String key, Object value) {
+ super.put(key, value);
+ return this;
+ }
+}
diff --git a/renren-fast/src/main/java/io/renren/common/utils/RedisKeys.java b/renren-fast/src/main/java/io/renren/common/utils/RedisKeys.java
new file mode 100644
index 0000000..d033b05
--- /dev/null
+++ b/renren-fast/src/main/java/io/renren/common/utils/RedisKeys.java
@@ -0,0 +1,21 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package io.renren.common.utils;
+
+/**
+ * Redis所有Keys
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class RedisKeys {
+
+ public static String getSysConfigKey(String key){
+ return "sys:config:" + key;
+ }
+}
diff --git a/renren-fast/src/main/java/io/renren/common/utils/RedisUtils.java b/renren-fast/src/main/java/io/renren/common/utils/RedisUtils.java
new file mode 100644
index 0000000..34bbb8f
--- /dev/null
+++ b/renren-fast/src/main/java/io/renren/common/utils/RedisUtils.java
@@ -0,0 +1,99 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package io.renren.common.utils;
+
+import com.google.gson.Gson;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.*;
+import org.springframework.stereotype.Component;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Redis工具类
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+@Component
+public class RedisUtils {
+ @Autowired
+ private RedisTemplate redisTemplate;
+ @Autowired
+ private ValueOperations valueOperations;
+ @Autowired
+ private HashOperations hashOperations;
+ @Autowired
+ private ListOperations listOperations;
+ @Autowired
+ private SetOperations setOperations;
+ @Autowired
+ private ZSetOperations zSetOperations;
+ /** 默认过期时长,单位:秒 */
+ public final static long DEFAULT_EXPIRE = 60 * 60 * 24;
+ /** 不设置过期时长 */
+ public final static long NOT_EXPIRE = -1;
+ private final static Gson gson = new Gson();
+
+ public void set(String key, Object value, long expire){
+ valueOperations.set(key, toJson(value));
+ if(expire != NOT_EXPIRE){
+ redisTemplate.expire(key, expire, TimeUnit.SECONDS);
+ }
+ }
+
+ public void set(String key, Object value){
+ set(key, value, DEFAULT_EXPIRE);
+ }
+
+ public T get(String key, Class clazz, long expire) {
+ String value = valueOperations.get(key);
+ if(expire != NOT_EXPIRE){
+ redisTemplate.expire(key, expire, TimeUnit.SECONDS);
+ }
+ return value == null ? null : fromJson(value, clazz);
+ }
+
+ public T get(String key, Class clazz) {
+ return get(key, clazz, NOT_EXPIRE);
+ }
+
+ public String get(String key, long expire) {
+ String value = valueOperations.get(key);
+ if(expire != NOT_EXPIRE){
+ redisTemplate.expire(key, expire, TimeUnit.SECONDS);
+ }
+ return value;
+ }
+
+ public String get(String key) {
+ return get(key, NOT_EXPIRE);
+ }
+
+ public void delete(String key) {
+ redisTemplate.delete(key);
+ }
+
+ /**
+ * Object转成JSON数据
+ */
+ private String toJson(Object object){
+ if(object instanceof Integer || object instanceof Long || object instanceof Float ||
+ object instanceof Double || object instanceof Boolean || object instanceof String){
+ return String.valueOf(object);
+ }
+ return gson.toJson(object);
+ }
+
+ /**
+ * JSON数据,转成Object
+ */
+ private T fromJson(String json, Class clazz){
+ return gson.fromJson(json, clazz);
+ }
+}
diff --git a/renren-fast/src/main/java/io/renren/common/utils/ShiroUtils.java b/renren-fast/src/main/java/io/renren/common/utils/ShiroUtils.java
new file mode 100644
index 0000000..fdf0f14
--- /dev/null
+++ b/renren-fast/src/main/java/io/renren/common/utils/ShiroUtils.java
@@ -0,0 +1,61 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package io.renren.common.utils;
+
+import io.renren.common.exception.RRException;
+import io.renren.modules.sys.entity.SysUserEntity;
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.session.Session;
+import org.apache.shiro.subject.Subject;
+
+/**
+ * Shiro工具类
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class ShiroUtils {
+
+ public static Session getSession() {
+ return SecurityUtils.getSubject().getSession();
+ }
+
+ public static Subject getSubject() {
+ return SecurityUtils.getSubject();
+ }
+
+ public static SysUserEntity getUserEntity() {
+ return (SysUserEntity)SecurityUtils.getSubject().getPrincipal();
+ }
+
+ public static Long getUserId() {
+ return getUserEntity().getUserId();
+ }
+
+ public static void setSessionAttribute(Object key, Object value) {
+ getSession().setAttribute(key, value);
+ }
+
+ public static Object getSessionAttribute(Object key) {
+ return getSession().getAttribute(key);
+ }
+
+ public static boolean isLogin() {
+ return SecurityUtils.getSubject().getPrincipal() != null;
+ }
+
+ public static String getKaptcha(String key) {
+ Object kaptcha = getSessionAttribute(key);
+ if(kaptcha == null){
+ throw new RRException("验证码已失效");
+ }
+ getSession().removeAttribute(key);
+ return kaptcha.toString();
+ }
+
+}
diff --git a/renren-fast/src/main/java/io/renren/common/utils/SpringContextUtils.java b/renren-fast/src/main/java/io/renren/common/utils/SpringContextUtils.java
new file mode 100644
index 0000000..84e787c
--- /dev/null
+++ b/renren-fast/src/main/java/io/renren/common/utils/SpringContextUtils.java
@@ -0,0 +1,51 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package io.renren.common.utils;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+/**
+ * Spring Context 工具类
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+@Component
+public class SpringContextUtils implements ApplicationContextAware {
+ public static ApplicationContext applicationContext;
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext)
+ throws BeansException {
+ SpringContextUtils.applicationContext = applicationContext;
+ }
+
+ public static Object getBean(String name) {
+ return applicationContext.getBean(name);
+ }
+
+ public static T getBean(String name, Class requiredType) {
+ return applicationContext.getBean(name, requiredType);
+ }
+
+ public static boolean containsBean(String name) {
+ return applicationContext.containsBean(name);
+ }
+
+ public static boolean isSingleton(String name) {
+ return applicationContext.isSingleton(name);
+ }
+
+ public static Class extends Object> getType(String name) {
+ return applicationContext.getType(name);
+ }
+
+}
\ No newline at end of file
diff --git a/renren-fast/src/main/java/io/renren/common/validator/Assert.java b/renren-fast/src/main/java/io/renren/common/validator/Assert.java
new file mode 100644
index 0000000..614e9bc
--- /dev/null
+++ b/renren-fast/src/main/java/io/renren/common/validator/Assert.java
@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package io.renren.common.validator;
+
+import io.renren.common.exception.RRException;
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * 数据校验
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public abstract class Assert {
+
+ public static void isBlank(String str, String message) {
+ if (StringUtils.isBlank(str)) {
+ throw new RRException(message);
+ }
+ }
+
+ public static void isNull(Object object, String message) {
+ if (object == null) {
+ throw new RRException(message);
+ }
+ }
+}
diff --git a/renren-fast/src/main/java/io/renren/common/validator/ValidatorUtils.java b/renren-fast/src/main/java/io/renren/common/validator/ValidatorUtils.java
new file mode 100644
index 0000000..06cdb0a
--- /dev/null
+++ b/renren-fast/src/main/java/io/renren/common/validator/ValidatorUtils.java
@@ -0,0 +1,54 @@
+/**
+ * Copyright (c) 2016-2019 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package io.renren.common.validator;
+
+import io.renren.common.exception.RRException;
+import io.renren.common.utils.Constant;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import java.util.Set;
+
+/**
+ * hibernate-validator校验工具类
+ *
+ * 参考文档:http://docs.jboss.org/hibernate/validator/5.4/reference/en-US/html_single/
+ *
+ * @author Mark sunlightcs@gmail.com
+ */
+public class ValidatorUtils {
+ private static Validator validator;
+
+ static {
+ validator = Validation.buildDefaultValidatorFactory().getValidator();
+ }
+
+ /**
+ * 校验对象
+ * @param object 待校验对象
+ * @param groups 待校验的组
+ * @throws RRException 校验不通过,则报RRException异常
+ */
+ public static void validateEntity(Object object, Class>... groups)
+ throws RRException {
+ Set> constraintViolations = validator.validate(object, groups);
+ if (!constraintViolations.isEmpty()) {
+ StringBuilder msg = new StringBuilder();
+ for (ConstraintViolation