升级:redkale-2.8

This commit is contained in:
梁显优 2023-07-05 01:44:24 +08:00
parent d8b0879bba
commit e1b1b35552
18 changed files with 117 additions and 234 deletions

View File

@ -0,0 +1,29 @@
redkale.name=app_local
redkale.port=2060
redkale.excludelibs.value=^.*mysql.*$;^.*google.*$
redkale.properties.load=config.properties
# --- executor ---
# redkale.executor.threads = 32
# redkale.executor.hash = true
# --- listener ---
# redkale.listener[0].value =
# ========================== server ===============================
redkale.server[0].protocol=HTTP
redkale.server[0].port=6060
redkale.server[0].host=0.0.0.0
redkale.server[0].maxbody=2m
redkale.server[0].services[0].autoload=true
# --- rest ---
redkale.server[0].rest.path=os
redkale.server[0].rest.autoload=true
redkale.server[0].rest.base=net.tccn.bbs.base.BaseServlet
# --- request ---
redkale.server[0].request.remoteaddr=request.headers.X-Real-IP
# --- servlets ---
redkale.server[0].servlets.autoload=true
redkale.server[0].render.value=net.tccn.bbs.base.TplRender
#redkale.server[0].render.suffixs = .html
# --- response ---
# redkale.server[0].response.addheader[0].name = X-Node
# redkale.server[0].response.addheader[0].value = system.property.APP_NODE
# =================================================================

View File

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<application port="5002">
<resources>
<listener value="net.tccn.redim.RedbbsListener"/>
<source name="redis" value="org.redkalex.cache.RedisCacheSource" xxx="16">
<node addr="127.0.0.1" password="123456" port="6379"/>
</source>
<properties load="conf.txt"/>
</resources>
<server host="0.0.0.0" port="80" protocol="HTTP" root="root">
<services autoload="true"/>
<rest autoload="true" base="net.tccn.bbs.base.BaseServlet" path="os"/>
<request>
<remoteaddr value="request.headers.X-Real-IP"/>
</request>
<response>
<addheader name="Access-Control-Allow-Origin" value="request.headers.Origin"/>
<setheader name="Access-Control-Allow-Headers" value="request.headers.Access-Control-Request-Headers"/>
<setheader name="Access-Control-Allow-Credentials" value="true"/>
<options auto="true"/>
</response>
<servlets autoload="true" path=""/>
<render value="net.tccn.bbs.base.TplRender"/>
</server>
</application>

View File

@ -1,3 +1,3 @@
----------- file conf ---------- # upload config
file.upload_dir=${APP_HOME}/root/upload/ file.upload_dir=${APP_HOME}/root/upload/
file.view_path=http://127.0.0.1/upload/ file.view_path=http://127.0.0.1/upload/

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="redbbs" transaction-type="RESOURCE_LOCAL">
<shared-cache-mode>ALL</shared-cache-mode>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="123456"/>
</properties>
</persistence-unit>
</persistence>

9
conf/source.properties Normal file
View File

@ -0,0 +1,9 @@
############ DataSource @Resource(name="redbbs") ############
# redbbs
redkale.datasource[redbbs].url=jdbc:mysql://127.0.0.1:3306/redbbs
redkale.datasource[redbbs].user=root
redkale.datasource[redbbs].password=123456
############ CacheSource @Resource(name="redis_cache") ############
redkale.cachesource[redis_cache].node[0].url=redis://127.0.0.1:6379
redkale.cachesource[redis_cache].node[0].password=123456
redkale.cachesource[redis_cache].node[0].db=0

View File

@ -17,12 +17,12 @@
<dependency> <dependency>
<groupId>org.redkale</groupId> <groupId>org.redkale</groupId>
<artifactId>redkale</artifactId> <artifactId>redkale</artifactId>
<version>2.2.0</version> <version>2.8.0-dev</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.redkalex</groupId> <groupId>org.redkalex</groupId>
<artifactId>redkale-plugins</artifactId> <artifactId>redkale-plugins</artifactId>
<version>2.2.0</version> <version>2.8.0-dev</version>
</dependency> </dependency>
<dependency> <dependency>
@ -40,6 +40,7 @@
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.22</version> <version>1.18.22</version>
<scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>
@ -52,8 +53,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version> <version>3.11.0</version>
<configuration> <configuration>
<source>1.8</source> <source>17</source>
<target>1.8</target> <target>17</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -15,17 +15,12 @@ public class BaseService implements Service {
protected final int sessionExpireSeconds = 7 * 24 * 60 * 60; protected final int sessionExpireSeconds = 7 * 24 * 60 * 60;
protected static final RetResult RET_SUCCESS = RetResult.success(); protected final static RetResult RET_SUCCESS = RetResult.success();
@Resource(name = "redbbs") @Resource(name = "redbbs")
protected DataSource dataSource; protected DataSource dataSource;
/* 使用redis 代码中配置此处即可 @Resource(name = "redis_cache")
@Resource(name = "redis")*/
@Resource(name = "cacheSource")
protected CacheSource<Long> sessions;
@Resource(name = "cacheSource")
protected CacheSource cacheSource; protected CacheSource cacheSource;
protected static final boolean winos = System.getProperty("os.name").contains("Window"); protected static final boolean winos = System.getProperty("os.name").contains("Window");
@ -38,4 +33,5 @@ public class BaseService implements Service {
protected RetResult retError(String info) { protected RetResult retError(String info) {
return new RetResult<>(-1, info); return new RetResult<>(-1, info);
} }
} }

View File

@ -46,7 +46,6 @@ public class BaseServlet extends HttpServlet {
@Override @Override
protected void preExecute(HttpRequest request, HttpResponse response) throws IOException { protected void preExecute(HttpRequest request, HttpResponse response) throws IOException {
String sessionid = request.getSessionid(true); String sessionid = request.getSessionid(true);
int currentid = 0; int currentid = 0;
if (sessionid != null) { if (sessionid != null) {
@ -64,6 +63,10 @@ public class BaseServlet extends HttpServlet {
response.finish(HttpScope.refer(uri)); response.finish(HttpScope.refer(uri));
return; return;
} }
if (uri.startsWith("/upload/")) {
response.finish(HttpScope.refer(uri));
return;
}
//异步记录访问日志 //异步记录访问日志
final int userid = currentid; final int userid = currentid;
@ -74,9 +77,7 @@ public class BaseServlet extends HttpServlet {
para.set(key, request.getParameter(key)); para.set(key, request.getParameter(key));
} }
Kv headers = Kv.create(); Kv headers = Kv.create();
request.getHeaders().forEach((k, v) -> { request.getHeaders().forEach((k, v) -> headers.set(k, request.getHeader(k)));
headers.set(k, request.getHeader(k));
});
VisLog visLog = new VisLog(); VisLog visLog = new VisLog();
visLog.setIp(request.getRemoteAddr()); visLog.setIp(request.getRemoteAddr());
@ -99,7 +100,7 @@ public class BaseServlet extends HttpServlet {
@Override @Override
protected void authenticate(HttpRequest request, HttpResponse response) throws IOException { protected void authenticate(HttpRequest request, HttpResponse response) throws IOException {
if (request.currentUser() == null) { if (request.currentIntUserid() == 0) {
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))) { if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))) {
response.finish(RetCodes.retResult(RET_USER_UNLOGIN, "未登录,登录后重试").toString()); response.finish(RetCodes.retResult(RET_USER_UNLOGIN, "未登录,登录后重试").toString());
} else { } else {
@ -141,10 +142,6 @@ public class BaseServlet extends HttpServlet {
return para == null || "".equals(para) ? defaultValue : para; return para == null || "".equals(para) ? defaultValue : para;
} }
public int getParaToInt(HttpRequest request, int index, int defaultValue) {
String para = getPara(request, index);
return para == null || "".equals(para) ? defaultValue : Integer.parseInt(para);
}
public int getParaToInt(HttpRequest request, int index) { public int getParaToInt(HttpRequest request, int index) {
int n = 0; int n = 0;
@ -155,19 +152,19 @@ public class BaseServlet extends HttpServlet {
try { try {
n = Integer.parseInt(para); n = Integer.parseInt(para);
} catch (Exception e) { } catch (Exception e) {
//throw new RuntimeException(e);
} }
return n; return n;
} }
//设置私密帖子过滤 //设置私密帖子过滤
protected FilterNode setPrivate(HttpRequest request, FilterNode node) { protected FilterNode setPrivate(HttpRequest request, FilterNode node) {
UserInfo user = request.currentUser(); UserInfo userInfo = request.currentUser();
if (user == null) { if (userInfo == null) {
node.and("status", FilterExpress.NOTEQUAL, 30); node.and("status", FilterExpress.NOTEQUAL, 30);
} else if (!userService.isAdmin(user.getUserid())) { } else if (!userService.isAdmin(userInfo.getUserid())) {
//select * from content c where c.status != -1 and (c.status!=30 or (c.status=30 and c.userid=100001)) //select * from content c where c.status != -1 and (c.status!=30 or (c.status=30 and c.userid=100001))
node.and(FilterNode.create("status", FilterExpress.NOTEQUAL, 30).or(FilterNode.create("status", 30).and("userid", user.getUserid()))); node.and(FilterNode.create("status", FilterExpress.NOTEQUAL, 30).or(FilterNode.create("status", 30).and("userid", userInfo.getUserid())));
} }
return node; return node;

View File

@ -17,7 +17,7 @@ import java.util.Map;
/** /**
* Created by JUECHENG at 2018/1/30 0:18. * Created by JUECHENG at 2018/1/30 0:18.
*/ */
public class TplRender implements HttpRender<HttpScope> { public class TplRender implements HttpRender {
@Resource(name = "SERVER_ROOT") @Resource(name = "SERVER_ROOT")
protected File webroot; protected File webroot;
@ -37,25 +37,17 @@ public class TplRender implements HttpRender<HttpScope> {
@Override @Override
public void renderTo(HttpRequest request, HttpResponse response, Convert convert, HttpScope scope) { public void renderTo(HttpRequest request, HttpResponse response, Convert convert, HttpScope scope) {
//UserInfo mine = request.currentUser();//当前登录人 String sessionid = request.getSessionid(false);
UserInfo mine = userService.current(sessionid);//当前登录人
Template template = engine.getTemplate(scope.getReferid()); Template template = engine.getTemplate(scope.getReferid());
Map attr = scope.getAttributes(); Map attr = scope.getAttributes();
if (attr == null) { if (attr == null) attr = Kv.create();
attr = Kv.create(); attr.put("mine", mine);
} attr.put("token", sessionid);
UserInfo userInfo = userService.find(request.currentUserid(int.class));
attr.put("mine", userInfo);
attr.put("token", request.getSessionid(false));
String str = template.renderToString(attr); String str = template.renderToString(attr);
response.setContentType("text/html; charset=UTF-8"); response.setContentType("text/html; charset=UTF-8");
response.finish(str); response.finish(str);
} }
@Override
public Class getType() {
return HttpScope.class;
}
} }

View File

@ -6,9 +6,6 @@
package net.tccn.bbs.base; package net.tccn.bbs.base;
import net.tccn.bbs.base.util.Kv; import net.tccn.bbs.base.util.Kv;
import org.redkale.source.DataJdbcSource;
import org.redkale.source.DataSource;
import org.redkale.source.Flipper;
import org.redkale.util.Comment; import org.redkale.util.Comment;
import org.redkale.util.Reproduce; import org.redkale.util.Reproduce;
import org.redkale.util.Sheet; import org.redkale.util.Sheet;
@ -42,7 +39,7 @@ public final class Utils {
} }
public static String dateFmt(long time) { public static String dateFmt(long time) {
/** /*
* 刚刚 60秒内 60 * 1000 * 刚刚 60秒内 60 * 1000
* x分钟前 1小时候内 60 * 60*1000 * x分钟前 1小时候内 60 * 60*1000
* x小时前 1天内 24 * 60*60*1000 * x小时前 1天内 24 * 60*60*1000
@ -86,15 +83,15 @@ public final class Utils {
} }
public static <T> T[] listToArray(List list, T[] ts) { public static <T> T[] listToArray(List list, T[] ts) {
for (int i = 0; i < list.size(); i++) { for (Object o : list) {
ts[0] = (T) list.get(i); ts[0] = (T) o;
} }
return ts; return ts;
} }
public static int[] listToArray(List list, int[] ts) { public static int[] listToArray(List list, int[] ts) {
for (int i = 0; i < list.size(); i++) { for (Object o : list) {
ts[0] = (int) list.get(i); ts[0] = (int) o;
} }
return ts; return ts;
} }
@ -121,7 +118,7 @@ public final class Utils {
return false; return false;
} }
private static Map<String, Reproduce> reproduceMap = new HashMap<>(); private static final Map<String, Reproduce> reproduceMap = new HashMap<>();
/** /**
* @param d 目标对象 * @param d 目标对象
@ -135,9 +132,7 @@ public final class Utils {
Reproduce<D, S> reproduce = reproduceMap.get(reproductKey); Reproduce<D, S> reproduce = reproduceMap.get(reproductKey);
if (reproduce == null) { if (reproduce == null) {
if (reproduce == null) { reproduceMap.put(reproductKey, reproduce = (Reproduce<D, S>) Reproduce.create(d.getClass(), s.getClass()));
reproduceMap.put(reproductKey, reproduce = (Reproduce<D, S>) Reproduce.create(d.getClass(), s.getClass()));
}
} }
return reproduce.apply(d, s); return reproduce.apply(d, s);
@ -169,6 +164,7 @@ public final class Utils {
Kv row = Kv.of(); Kv row = Kv.of();
for (int i = 1; i <= count; i++) { for (int i = 1; i <= count; i++) {
String columnTypeName = metaData.getColumnTypeName(i); String columnTypeName = metaData.getColumnTypeName(i);
//String columnName = metaData.getColumnName(i);
String columnLabel = metaData.getColumnLabel(i); String columnLabel = metaData.getColumnLabel(i);
row.put(columnLabel, null); row.put(columnLabel, null);
@ -231,7 +227,6 @@ public final class Utils {
*/ */
public static <T> List<T> mix(List<T> list) { public static <T> List<T> mix(List<T> list) {
int len = list.size(); int len = list.size();
Random random = new Random();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
int r = random.nextInt(len); int r = random.nextInt(len);
if (i == r) continue; if (i == r) continue;
@ -255,7 +250,6 @@ public final class Utils {
@Comment("获取随机数字符") @Comment("获取随机数字符")
public static String randomNumber(int len) { public static String randomNumber(int len) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Random random = new Random();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
sb.append(random.nextInt(9)); sb.append(random.nextInt(9));
} }
@ -265,7 +259,6 @@ public final class Utils {
@Comment("获取随机数集合") @Comment("获取随机数集合")
private static List<Integer> getRandoms(int max, int len) { private static List<Integer> getRandoms(int max, int len) {
Set<Integer> randoms = new HashSet<>(); Set<Integer> randoms = new HashSet<>();
Random random = new Random();
while (randoms.size() < len && randoms.size() < max) { while (randoms.size() < len && randoms.size() < max) {
randoms.add(random.nextInt(max)); randoms.add(random.nextInt(max));
} }
@ -298,7 +291,7 @@ public final class Utils {
*/ */
public static int strLength(String value) { public static int strLength(String value) {
int valueLength = 0; int valueLength = 0;
String chinese = "[\u4e00-\u9fa5]"; String chinese = "[一-龥]";
for (int i = 0; i < value.length(); i++) { for (int i = 0; i < value.length(); i++) {
String temp = value.substring(i, i + 1); String temp = value.substring(i, i + 1);
if (temp.matches(chinese)) { if (temp.matches(chinese)) {
@ -552,9 +545,9 @@ public final class Utils {
@Comment("对象转GET请求参数转换为字符结果p1=v1&p2=v2&p3=v3") @Comment("对象转GET请求参数转换为字符结果p1=v1&p2=v2&p3=v3")
public static String convertHttpParams(Object o, List<String> removeFields, boolean encode) { public static String convertHttpParams(Object o, List<String> removeFields, boolean encode) {
Class<? extends Object> c = o.getClass(); Class<?> c = o.getClass();
Field[] fields = c.getDeclaredFields(); Field[] fields = c.getDeclaredFields();
Map<String, Object> map = new TreeMap<String, Object>(); Map<String, Object> map = new TreeMap<>();
for (Field field : fields) { for (Field field : fields) {
field.setAccessible(true); field.setAccessible(true);
String name = field.getName(); String name = field.getName();
@ -579,13 +572,13 @@ public final class Utils {
if (map == null || map.isEmpty()) { if (map == null || map.isEmpty()) {
return ""; return "";
} }
Set<String> sortSet = new TreeSet<String>(); Set<String> sortSet = new TreeSet<>();
for (Map.Entry<String, Object> entry : map.entrySet()) { for (Map.Entry<String, Object> entry : map.entrySet()) {
sortSet.add(entry.getKey()); sortSet.add(entry.getKey());
} }
// 参数名按ASCII码从小到大排序字典序,然后使用( & )连接排好序的key=value集合 // 参数名按ASCII码从小到大排序字典序,然后使用( & )连接排好序的key=value集合
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
boolean isFirst = true; boolean isFirst = true;
for (String key : sortSet) { for (String key : sortSet) {
if (isFirst) { if (isFirst) {
@ -601,7 +594,7 @@ public final class Utils {
@Comment("对象转map") @Comment("对象转map")
public static Map<String, Object> convertToMap(Object o, List<String> removeFields) { public static Map<String, Object> convertToMap(Object o, List<String> removeFields) {
Class<? extends Object> c = o.getClass(); Class<?> c = o.getClass();
List<Field> fields = Stream.of(c.getDeclaredFields()).collect(Collectors.toList()); List<Field> fields = Stream.of(c.getDeclaredFields()).collect(Collectors.toList());
if (c.getSuperclass() != null) { if (c.getSuperclass() != null) {
Field[] superFields = c.getSuperclass().getDeclaredFields(); Field[] superFields = c.getSuperclass().getDeclaredFields();
@ -654,32 +647,6 @@ public final class Utils {
return String.format("{%s}", builder.deleteCharAt(builder.length() - 1).toString()); return String.format("{%s}", builder.deleteCharAt(builder.length() - 1).toString());
} }
public static <T> Sheet<T> querySheetBySql(DataSource dataSource, String sql, Flipper flipper, Class<T> type) {
DataJdbcSource jdbcSource = (DataJdbcSource) dataSource;
//总条数
int total = jdbcSource.directQuery("select count(0) c from (" + sql + ") c", rs -> {
int result = 0;
try {
while (rs.next()) {
result = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
}
return result;
});
if (total == 0) {
return new Sheet<>(0, new ArrayList<>());
}
if (flipper != null) {
sql = String.format("%s %s limit %s,%s ", sql, Utils.isEmpty(flipper.getSort()) ? "" : "order by " + flipper.getSort(), flipper.getOffset(), flipper.getLimit());
}
List<T> dataList = jdbcSource.directQuery(sql, rs -> Utils.queryList(rs, type));
return new Sheet<>(total, dataList);
}
@Comment("获取次日0点0分0秒时间戳") @Comment("获取次日0点0分0秒时间戳")
public static long getNextDayZero() { public static long getNextDayZero() {
LocalDate localDate = LocalDate.now(); LocalDate localDate = LocalDate.now();
@ -710,7 +677,7 @@ public final class Utils {
return count; return count;
} }
private static Random random = new Random(); private static final Random random = new Random();
public static int randomNum(int len) { public static int randomNum(int len) {
int rs = random.nextInt(9); int rs = random.nextInt(9);

View File

@ -13,7 +13,7 @@ import javax.persistence.*;
@Setter @Setter
@Getter @Getter
@Cacheable(interval = 5 * 60) @Cacheable(interval = 5 * 60)
@Table(catalog = "redbbs", name = "commentinfo", comment = "[评论表]") @Table(comment = "[评论表]")
public class CommentInfo extends BaseEntity { public class CommentInfo extends BaseEntity {
@Id @Id
@ -44,9 +44,6 @@ public class CommentInfo extends BaseEntity {
@Column(comment = "[状态]1正常-1删除") @Column(comment = "[状态]1正常-1删除")
private short status = 10; private short status = 10;
/*@Transient
private CommentBean pCommentInfo;*/
@Transient @Transient
private String title; private String title;
@Transient @Transient
@ -55,19 +52,4 @@ public class CommentInfo extends BaseEntity {
@Transient @Transient
private UserInfo user; private UserInfo user;
/*public CommentBean createInfo() {
CommentBean info = new CommentBean();
info.setCommentid(commentid);
info.setUserid(userid);
info.setPid(pid);
info.setCate(cate);
info.setContentid(contentid);
info.setContent(content);
info.setSupportnum(supportnum);
info.setStatus(status);
info.setCreatetime(Utils.dateFmt(createtime));
return info;
}*/
} }

View File

@ -85,9 +85,7 @@ public class CommentService extends BaseService {
List<Integer> commentids = Utils.toList(comments, x -> x.getCommentid()); List<Integer> commentids = Utils.toList(comments, x -> x.getCommentid());
FilterNode node = FilterNode.create("cate", 10).and("status", 10).and("userid", userid).and("tid", IN, (Serializable) commentids); FilterNode node = FilterNode.create("cate", 10).and("status", 10).and("userid", userid).and("tid", IN, (Serializable) commentids);
List<Integer> supports = dataSource.queryColumnList("tid", ActLog.class, node); List<Integer> supports = dataSource.queryColumnList("tid", ActLog.class, node);
comments.forEach(x -> { comments.forEach(x -> x.setHadsupport(supports.contains(x.getCommentid()) ? 1 : 0));
x.setHadsupport(supports.contains(x.getCommentid()) ? 1 : 0);
});
return comments; return comments;
} }
@ -138,17 +136,10 @@ public class CommentService extends BaseService {
return RetResult.success(); return RetResult.success();
} }
/**
* todo:用户评论榜 待完成
*
* @return
*/
@Comment("用户评论榜") @Comment("用户评论榜")
public Map<String, Number> commentRank() { public Map<String, Number> commentRank() {
dataSource.querySheet(CommentInfo.class, new Flipper(8), FilterNode.create("userid", IN)); dataSource.querySheet(CommentInfo.class, new Flipper(8), FilterNode.create("userid", IN));
Map<String, Number> numberMap = dataSource.getNumberMap(CommentInfo.class, FilterFuncColumn.create(FilterFunc.DISTINCTCOUNT, "userid")); return dataSource.getNumberMap(CommentInfo.class, FilterFuncColumn.create(FilterFunc.DISTINCTCOUNT, "userid"));
return numberMap;
} }
} }

View File

@ -14,7 +14,7 @@ import javax.persistence.*;
@Setter @Setter
@Getter @Getter
@Cacheable(interval = 5 * 60) @Cacheable(interval = 5 * 60)
@Table(catalog = "redbbs", name = "contentinfo", comment = "[内容表]") @Table(comment = "[内容表]")
public class ContentInfo extends BaseEntity { public class ContentInfo extends BaseEntity {
@Id @Id
@ -72,24 +72,4 @@ public class ContentInfo extends BaseEntity {
private static final Kv types = Kv.by(10, "求助").set(20, "分享").set(30, "讨论").set(40, "公告").set(50, "动态"); private static final Kv types = Kv.by(10, "求助").set(20, "分享").set(30, "讨论").set(40, "公告").set(50, "动态");
/*public ContentInfo createInfo() {
ContentInfo info = new ContentInfo();
info.setContentid(contentid);
info.setUserid(userid);
info.setTitle(title);
info.setContent(content);
info.setCate(cate);
info.setType(type);
info.setViewnum(viewnum);
info.setReplynum(replynum);
info.setWonderful(wonderful);
info.setTop(top);
info.setSolved(solved);
info.setStatus(status);
info.setTypename(types.getOrDefault((int) type, "其他").toString());
info.setCreatetime(Utils.dateFmt(createtime));
return info;
}*/
} }

View File

@ -27,6 +27,7 @@ import static org.redkale.source.FilterExpress.NOTEQUAL;
/** /**
* Created by Lxy at 2017/11/26 9:33. * Created by Lxy at 2017/11/26 9:33.
*/ */
@SuppressWarnings("Convert2MethodRef")
@RestService(name = "content", comment = "文章帖子服务") @RestService(name = "content", comment = "文章帖子服务")
public class ContentService extends BaseService { public class ContentService extends BaseService {

View File

@ -16,7 +16,7 @@ import javax.persistence.Table;
@Setter @Setter
@Getter @Getter
@Cacheable(interval = 5 * 60) @Cacheable(interval = 5 * 60)
@Table(catalog = "redbbs", name = "userdetail") @Table(comment = "用户表")
public class UserDetail implements java.io.Serializable { public class UserDetail implements java.io.Serializable {
@Id @Id
@ -47,7 +47,7 @@ public class UserDetail implements java.io.Serializable {
@Column(length = 32, comment = "[邮箱]") @Column(length = 32, comment = "[邮箱]")
private String email = ""; private String email = "";
@Column(comment = "") @Column()
private int roleid; private int roleid;
@Column(length = 128, comment = "[个人博客地址]") @Column(length = 128, comment = "[个人博客地址]")
@ -77,24 +77,24 @@ public class UserDetail implements java.io.Serializable {
//------ //------
public UserInfo createUserInfo() { public UserInfo createUserInfo() {
UserInfo user = new UserInfo(); UserInfo info = new UserInfo();
user.setUserid(userid); info.setUserid(userid);
user.setUsername(username); info.setUsername(username);
user.setSex(sex); info.setSex(sex);
user.setPassword(password); info.setPassword(password);
user.setPhone(phone); info.setPhone(phone);
user.setNickname(nickname); info.setNickname(nickname);
user.setAvatar(avatar); info.setAvatar(avatar);
user.setRelaname(realname); info.setRelaname(realname);
user.setEmail(email); info.setEmail(email);
user.setRoleid(roleid); info.setRoleid(roleid);
user.setSite(site); info.setSite(site);
user.setGit(git); info.setGit(git);
user.setCreatetime(createtime); info.setCreatetime(createtime);
user.setSign(sign); info.setSign(sign);
user.setCity(city); info.setCity(city);
user.setStatus(getStatus()); info.setStatus(getStatus());
return user; return info;
} }
public String passwordForMd5() { public String passwordForMd5() {

View File

@ -35,15 +35,4 @@ public class UserInfo extends BaseEntity {
private int status = 1; private int status = 1;
private String time = ""; private String time = "";
/**
* 检查用户权限
*
* @param moduleid
* @param actionid
* @return
*/
public boolean checkAuth(int moduleid, int actionid) {
return !(moduleid == 2 && actionid == 1);
}
} }

View File

@ -26,7 +26,7 @@ import static net.tccn.bbs.base.util.RetCodes.RET_USER_ACCOUNT_PWD_ILLEGAL;
public class UserService extends BaseService { public class UserService extends BaseService {
@RestMapping(name = "login", auth = false, comment = "登录校验") @RestMapping(name = "login", auth = false, comment = "登录校验")
public RetResult<UserInfo> login(LoginBean bean) { public RetResult login(LoginBean bean) {
if (bean == null || bean.emptyUsername()) { if (bean == null || bean.emptyUsername()) {
return retError("参数错误"); return retError("参数错误");
} }
@ -38,7 +38,7 @@ public class UserService extends BaseService {
//log(null, 0, "用户或密码错误"); //log(null, 0, "用户或密码错误");
return RetCodes.retResult(RET_USER_ACCOUNT_PWD_ILLEGAL, "用户名或密码错误"); return RetCodes.retResult(RET_USER_ACCOUNT_PWD_ILLEGAL, "用户名或密码错误");
} }
sessions.setAsync(sessionExpireSeconds, bean.getSessionid(), (long) user.getUserid()); cacheSource.setexLongAsync(bean.getSessionid(), sessionExpireSeconds, user.getUserid());
retResult.setRetcode(0); retResult.setRetcode(0);
retResult.setResult(Kv.by("token", bean.getSessionid())); retResult.setResult(Kv.by("token", bean.getSessionid()));
retResult.setRetinfo("登录成功."); retResult.setRetinfo("登录成功.");
@ -50,9 +50,10 @@ public class UserService extends BaseService {
if (sessionid == null) return 0; if (sessionid == null) return 0;
long userid = 0; long userid = 0;
try { try {
userid = sessions.getLong(sessionid, 0); userid = cacheSource.getLong(sessionid, 0);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); //e.printStackTrace();
return 0;
} }
return (int) userid; return (int) userid;
} }
@ -64,8 +65,7 @@ public class UserService extends BaseService {
long userid = 0; long userid = 0;
try { try {
userid = sessions.getLong(sessionid, 0); userid = cacheSource.getLongAndRefresh(sessionid, sessionExpireSeconds, 0L);
sessions.getAndRefresh(sessionid, sessionExpireSeconds);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -73,8 +73,7 @@ public class UserService extends BaseService {
if (userid == 0) { if (userid == 0) {
return null; return null;
} }
UserInfo user = find((int) userid); return find((int) userid);
return user;
} }
@RestMapping(name = "info", comment = "用户信息") @RestMapping(name = "info", comment = "用户信息")
@ -83,8 +82,7 @@ public class UserService extends BaseService {
return null; return null;
} }
UserDetail user = dataSource.find(UserDetail.class, userid); UserDetail user = dataSource.find(UserDetail.class, userid);
UserInfo bean = user.createUserInfo(); return user.createUserInfo();
return bean;
} }
@Comment("根据用户ID, 批量查询一批用户信息") @Comment("根据用户ID, 批量查询一批用户信息")
@ -95,13 +93,12 @@ public class UserService extends BaseService {
FilterNode node = FilterNode.create("userid", (Serializable) userids); FilterNode node = FilterNode.create("userid", (Serializable) userids);
List<UserDetail> records = dataSource.queryList(UserDetail.class, node); List<UserDetail> records = dataSource.queryList(UserDetail.class, node);
Map<Integer, UserInfo> map = Utils.toMap(records, x -> x.getUserid(), x -> x.createUserInfo()); return Utils.toMap(records, x -> x.getUserid(), x -> x.createUserInfo());
return map;
} }
@RestMapping(name = "logout", auth = false, comment = "退出登录") @RestMapping(name = "logout", auth = false, comment = "退出登录")
public RetResult logout(@RestSessionid String sessionid) { public RetResult logout(@RestSessionid String sessionid) {
sessions.remove(sessionid); cacheSource.remove(sessionid);
return RetResult.success(); return RetResult.success();
//return new HttpResult().header("Location", "/").status(302); //return new HttpResult().header("Location", "/").status(302);
@ -109,9 +106,7 @@ public class UserService extends BaseService {
@RestMapping(name = "query", auth = false, comment = "用户数据查询") @RestMapping(name = "query", auth = false, comment = "用户数据查询")
public Sheet<UserDetail> query(Flipper flipper, @RestParam(name = "bean", comment = "过滤条件") final UserBean userBean) { public Sheet<UserDetail> query(Flipper flipper, @RestParam(name = "bean", comment = "过滤条件") final UserBean userBean) {
Sheet<UserDetail> users = dataSource.querySheet(UserDetail.class, flipper, userBean); return dataSource.querySheet(UserDetail.class, flipper, userBean);
return users;
} }
@RestMapping(name = "changepwd", comment = "修改密码") @RestMapping(name = "changepwd", comment = "修改密码")

View File

@ -81,12 +81,12 @@ public class ImFriendServiceImpl extends BaseService implements ImFriendService
true, this.getClass(), new InetSocketAddress("192.168.227.1", 7070));*/ true, this.getClass(), new InetSocketAddress("192.168.227.1", 7070));*/
TransportFactory sncpTransportFactory = application.getSncpTransportFactory(); /*TransportFactory sncpTransportFactory = application.getSncpTransportFactory();
TransportGroupInfo groupInfo = sncpTransportFactory.findGroupInfo("ALL"); TransportGroupInfo groupInfo = sncpTransportFactory.findGroupInfo("ALL");
System.out.println(groupInfo.toString()); System.out.println(groupInfo.toString());
groupInfo.putAddress(new InetSocketAddress("120.24.230.60", 7070)); groupInfo.putAddress(new InetSocketAddress("120.24.230.60", 7070));*/
//sncpTransportFactory.addGroupInfo(groupInfo); //sncpTransportFactory.addGroupInfo(groupInfo);