代码格式调整,升级优化
This commit is contained in:
36
pom.xml
36
pom.xml
@@ -7,39 +7,26 @@
|
|||||||
<groupId>com.lxyer</groupId>
|
<groupId>com.lxyer</groupId>
|
||||||
<artifactId>redbbs</artifactId>
|
<artifactId>redbbs</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<build>
|
|
||||||
<finalName>redbbs</finalName>
|
|
||||||
<sourceDirectory>src</sourceDirectory>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<source>11</source>
|
|
||||||
<target>11</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!--maven 打包使用下面的包 -->
|
<!--maven 打包使用下面的包 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.redkale</groupId>
|
<groupId>org.redkale</groupId>
|
||||||
<artifactId>redkale</artifactId>
|
<artifactId>redkale</artifactId>
|
||||||
<version>2.0.0.alpha1</version>
|
<version>2.0.0.rc3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.redkalex</groupId>
|
<groupId>org.redkalex</groupId>
|
||||||
<artifactId>redkale-plugins</artifactId>
|
<artifactId>redkale-plugins</artifactId>
|
||||||
<version>2.0.0.alpha1</version>
|
<version>2.0.0.rc3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<version>5.1.34</version>
|
<version>8.0.18</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jfinal</groupId>
|
<groupId>com.jfinal</groupId>
|
||||||
<artifactId>enjoy</artifactId>
|
<artifactId>enjoy</artifactId>
|
||||||
@@ -60,5 +47,18 @@
|
|||||||
</dependency>-->
|
</dependency>-->
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>redbbs</finalName>
|
||||||
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>11</source>
|
||||||
|
<target>11</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
@@ -22,11 +22,6 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util', 'face'], f
|
|||||||
if(device.ie && device.ie < 8){
|
if(device.ie && device.ie < 8){
|
||||||
layer.alert('如果您非得使用 IE 浏览器访问社区,那么请使用 IE8+');
|
layer.alert('如果您非得使用 IE 浏览器访问社区,那么请使用 IE8+');
|
||||||
}
|
}
|
||||||
//1216.top都统一访问到www.1216.top; 考虑SEO
|
|
||||||
var addr = window.location.href
|
|
||||||
if(addr.indexOf("1216.top") > -1 && addr.indexOf("www.1216.top") == -1){
|
|
||||||
window.location.href = addr.replace("1216.top", "www.1216.top");
|
|
||||||
}
|
|
||||||
|
|
||||||
layui.focusInsert = function(obj, str){
|
layui.focusInsert = function(obj, str){
|
||||||
var result, val = obj.value;
|
var result, val = obj.value;
|
||||||
|
@@ -17,7 +17,7 @@ public class ArangoKit {
|
|||||||
|
|
||||||
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
||||||
|
|
||||||
protected static Function<String, String> chDev = (s) -> s + (winos ? "_dev" : "");
|
protected static Function<String, String> chDev = (s) -> s + (winos ? "_dev" : "");
|
||||||
|
|
||||||
//Arango
|
//Arango
|
||||||
protected static ArangoDB arangoDb = new ArangoDB.Builder().host("120.24.230.60", 8529).user("root").password("abc123").build();
|
protected static ArangoDB arangoDb = new ArangoDB.Builder().host("120.24.230.60", 8529).user("root").password("abc123").build();
|
||||||
@@ -50,6 +50,7 @@ public class ArangoKit {
|
|||||||
public static long findInt(String aql) {
|
public static long findInt(String aql) {
|
||||||
return dbDev.query(aql, long.class).first();
|
return dbDev.query(aql, long.class).first();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long findInt(String aql, Map para) {
|
public static long findInt(String aql, Map para) {
|
||||||
return dbDev.query(aql, long.class).first();
|
return dbDev.query(aql, long.class).first();
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,7 @@ public class ArangoService extends BaseService {
|
|||||||
|
|
||||||
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
||||||
|
|
||||||
protected Function<String, String> chDev = (s) -> s + (isDev ? "_dev" : "");
|
protected Function<String, String> chDev = (s) -> s + (isDev ? "_dev" : "");
|
||||||
|
|
||||||
@Resource(name = "property.arango.host")
|
@Resource(name = "property.arango.host")
|
||||||
private String arangoHost = "127.0.0.1";
|
private String arangoHost = "127.0.0.1";
|
||||||
@@ -45,18 +45,20 @@ public class ArangoService extends BaseService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(AnyValue config) {
|
public void init(AnyValue config) {
|
||||||
System.out.println("isDev :" + isDev);
|
CompletableFuture.runAsync(() -> {
|
||||||
|
System.out.println("isDev :" + isDev);
|
||||||
|
|
||||||
arangoDb = new ArangoDB.Builder().host(arangoHost, port).user(user).password(password).build();
|
arangoDb = new ArangoDB.Builder().host(arangoHost, port).user(user).password(password).build();
|
||||||
db = arangoDb.db(chDev.apply(database));
|
db = arangoDb.db(chDev.apply(database));
|
||||||
colVisLog = db.collection(chDev.apply(VIS_LOG));
|
colVisLog = db.collection(chDev.apply(VIS_LOG));
|
||||||
|
|
||||||
if (!db.exists()) {
|
if (!db.exists()) {
|
||||||
db.create();
|
db.create();
|
||||||
}
|
}
|
||||||
if (!colVisLog.exists()) {
|
if (!colVisLog.exists()) {
|
||||||
colVisLog.create();
|
colVisLog.create();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(auth = false)
|
@RestMapping(auth = false)
|
||||||
@@ -79,6 +81,7 @@ public class ArangoService extends BaseService {
|
|||||||
public static long findInt(String aql) {
|
public static long findInt(String aql) {
|
||||||
return db.query(aql, long.class).first();
|
return db.query(aql, long.class).first();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long findInt(String aql, Map para) {
|
public static long findInt(String aql, Map para) {
|
||||||
return db.query(aql, long.class).first();
|
return db.query(aql, long.class).first();
|
||||||
}
|
}
|
||||||
|
@@ -58,15 +58,15 @@ public class BaseService implements Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(ignore = true)
|
@RestMapping(ignore = true)
|
||||||
public int currentUserid(String sessionid){
|
public int currentUserid(String sessionid) {
|
||||||
if (sessionid == null) return 0;
|
if (sessionid == null) return 0;
|
||||||
long userid = 0;
|
long userid = 0;
|
||||||
try {
|
try {
|
||||||
userid = sessions.getLong(sessionid, 0);
|
userid = sessions.getLong(sessionid, 0);
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return (int)userid;
|
return (int) userid;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ import static net.tccn.bbs.base.kit.RetCodes.RET_USER_UNLOGIN;
|
|||||||
/**
|
/**
|
||||||
* Created by Lxy at 2017/10/3 13:39.
|
* Created by Lxy at 2017/10/3 13:39.
|
||||||
*/
|
*/
|
||||||
|
@HttpUserType(UserInfo.class)
|
||||||
public class BaseServlet extends HttpServlet {
|
public class BaseServlet extends HttpServlet {
|
||||||
|
|
||||||
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
||||||
@@ -61,26 +62,26 @@ public class BaseServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String uri = request.getRequestURI();
|
String uri = request.getRequestURI();
|
||||||
if (uri.startsWith("/res")){
|
if (uri.startsWith("/res")) {
|
||||||
File file = new File(webroot + uri);
|
File file = new File(webroot + uri);
|
||||||
response.finish(file);
|
response.finish(file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (uri.endsWith(".html")){
|
if (uri.endsWith(".html")) {
|
||||||
response.finish(HttpScope.refer(uri));
|
response.finish(HttpScope.refer(uri));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//异步记录访问日志
|
//异步记录访问日志
|
||||||
final int userid = currentid;
|
final int userid = currentid;
|
||||||
CompletableFuture.runAsync(()->{
|
CompletableFuture.runAsync(() -> {
|
||||||
|
|
||||||
Kv para = Kv.create();
|
Kv para = Kv.create();
|
||||||
for (String key : request.getParameterNames()){
|
for (String key : request.getParameterNames()) {
|
||||||
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));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -106,9 +107,9 @@ 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.currentUser() == null) {
|
||||||
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 {
|
||||||
response.finish(HttpScope.refer("/user/login.html"));
|
response.finish(HttpScope.refer("/user/login.html"));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -116,55 +117,60 @@ public class BaseServlet extends HttpServlet {
|
|||||||
response.nextEvent();
|
response.nextEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLimit(HttpRequest request){
|
public int getLimit(HttpRequest request) {
|
||||||
return request.getIntParameter("limit", 1);
|
return request.getIntParameter("limit", 1);
|
||||||
}
|
}
|
||||||
public int getOffset(HttpRequest request){
|
|
||||||
|
public int getOffset(HttpRequest request) {
|
||||||
return request.getIntParameter("offset", 10);
|
return request.getIntParameter("offset", 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPara(HttpRequest request){
|
public String getPara(HttpRequest request) {
|
||||||
String requestURI = request.getRequestURI();
|
String requestURI = request.getRequestURI();
|
||||||
String subStr = requestURI.substring(requestURI.lastIndexOf("/") + 1);
|
String subStr = requestURI.substring(requestURI.lastIndexOf("/") + 1);
|
||||||
return subStr.contains("-") ? subStr.substring(0, subStr.indexOf("-")) : subStr;
|
return subStr.contains("-") ? subStr.substring(0, subStr.indexOf("-")) : subStr;
|
||||||
}
|
}
|
||||||
public String getPara(HttpRequest request,int index){
|
|
||||||
|
public String getPara(HttpRequest request, int index) {
|
||||||
String requestURI = request.getRequestURI();
|
String requestURI = request.getRequestURI();
|
||||||
String subStr = requestURI.substring(requestURI.lastIndexOf("/") + 1);
|
String subStr = requestURI.substring(requestURI.lastIndexOf("/") + 1);
|
||||||
|
|
||||||
String[] paraArr = subStr.split("-");
|
String[] paraArr = subStr.split("-");
|
||||||
if (index < 0){
|
if (index < 0) {
|
||||||
return paraArr.length < -index ? null : paraArr[paraArr.length+index];
|
return paraArr.length < -index ? null : paraArr[paraArr.length + index];
|
||||||
}else {
|
} else {
|
||||||
return paraArr.length < index+1 ? null : paraArr[index];
|
return paraArr.length < index + 1 ? null : paraArr[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public <T> T getPara(HttpRequest request, int index, T defaultValue){
|
|
||||||
T para = (T)getPara(request,index);
|
public <T> T getPara(HttpRequest request, int index, T defaultValue) {
|
||||||
|
T para = (T) getPara(request, index);
|
||||||
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);
|
public int getParaToInt(HttpRequest request, int index, int defaultValue) {
|
||||||
|
String para = getPara(request, index);
|
||||||
return para == null || "".equals(para) ? defaultValue : Integer.parseInt(para);
|
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;
|
||||||
String para = getPara(request,index);
|
String para = getPara(request, index);
|
||||||
if (para == null || "".equals(para)) n = 0;
|
if (para == null || "".equals(para)) n = 0;
|
||||||
try {
|
try {
|
||||||
n = Integer.parseInt(para);
|
n = Integer.parseInt(para);
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
//设置私密帖子过滤
|
//设置私密帖子过滤
|
||||||
protected FilterNode setPrivate(HttpRequest request,FilterNode node){
|
protected FilterNode setPrivate(HttpRequest request, FilterNode node) {
|
||||||
UserInfo userInfo = request.currentUser();
|
UserInfo userInfo = request.currentUser();
|
||||||
if (userInfo == null){
|
if (userInfo == null) {
|
||||||
node.and("status", FilterExpress.NOTEQUAL, 30);
|
node.and("status", FilterExpress.NOTEQUAL, 30);
|
||||||
}else if (!userService.isAdmin(userInfo.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", userInfo.getUserid())));
|
node.and(FilterNode.create("status", FilterExpress.NOTEQUAL, 30).or(FilterNode.create("status", 30).and("userid", userInfo.getUserid())));
|
||||||
}
|
}
|
||||||
|
@@ -27,15 +27,15 @@ public class FileService extends BaseService {
|
|||||||
String path = String.format(format, System.currentTimeMillis()) + suffix;
|
String path = String.format(format, System.currentTimeMillis()) + suffix;
|
||||||
File destFile = new File((winos ? "D:/wk/_own/redbbs/root/tem/" : dir) + path);
|
File destFile = new File((winos ? "D:/wk/_own/redbbs/root/tem/" : dir) + path);
|
||||||
destFile.getParentFile().mkdir();
|
destFile.getParentFile().mkdir();
|
||||||
if (!tmpFile.renameTo(destFile)){
|
if (!tmpFile.renameTo(destFile)) {
|
||||||
try{
|
try {
|
||||||
Files.copy(tmpFile.toPath(), destFile.toPath(), StandardCopyOption.ATOMIC_MOVE);
|
Files.copy(tmpFile.toPath(), destFile.toPath(), StandardCopyOption.ATOMIC_MOVE);
|
||||||
}finally {
|
} finally {
|
||||||
tmpFile.delete();//删除临时文件
|
tmpFile.delete();//删除临时文件
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RetResult result = RetResult.success();
|
RetResult result = RetResult.success();
|
||||||
result.setRetinfo((winos ? "/tem/": view) + path);
|
result.setRetinfo((winos ? "/tem/" : view) + path);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,12 +21,12 @@ public class JBean<T> /*extends RetResult*/ {
|
|||||||
this.retinfo = retinfo;
|
this.retinfo = retinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JBean by(int retcode, String retinfo){
|
public static JBean by(int retcode, String retinfo) {
|
||||||
JBean jBean = new JBean(retcode, retinfo);
|
JBean jBean = new JBean(retcode, retinfo);
|
||||||
return jBean;
|
return jBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JBean by(int retcode, String retinfo, Object t){
|
public static JBean by(int retcode, String retinfo, Object t) {
|
||||||
JBean jBean = new JBean(retcode, retinfo);
|
JBean jBean = new JBean(retcode, retinfo);
|
||||||
jBean.setResult(t);
|
jBean.setResult(t);
|
||||||
return jBean;
|
return jBean;
|
||||||
@@ -68,7 +68,7 @@ public class JBean<T> /*extends RetResult*/ {
|
|||||||
this.attach = attach;
|
this.attach = attach;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JBean attach(String key, Object object){
|
public JBean attach(String key, Object object) {
|
||||||
if (attach == null)
|
if (attach == null)
|
||||||
attach = new HashMap<>();
|
attach = new HashMap<>();
|
||||||
attach.put(key, object);
|
attach.put(key, object);
|
||||||
@@ -76,11 +76,12 @@ public class JBean<T> /*extends RetResult*/ {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final JBean ok = new JBean(0);
|
private static final JBean ok = new JBean(0);
|
||||||
public static JBean ok(){
|
|
||||||
|
public static JBean ok() {
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JBean faild(String retinfo){
|
public static JBean faild(String retinfo) {
|
||||||
return new JBean(-1, retinfo);
|
return new JBean(-1, retinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,7 +25,7 @@ import java.util.function.Function;
|
|||||||
/**
|
/**
|
||||||
* Created by liangxianyou at 2018/6/20 22:54.
|
* Created by liangxianyou at 2018/6/20 22:54.
|
||||||
*/
|
*/
|
||||||
@RestService(name = "xxx",automapping = true, comment = "日志记录")
|
@RestService(name = "xxx", automapping = true, comment = "日志记录")
|
||||||
public class TaskQueue<T extends Object> extends BaseService implements Runnable {
|
public class TaskQueue<T extends Object> extends BaseService implements Runnable {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@@ -63,7 +63,7 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
|||||||
VisLog visLog = (VisLog) _task;
|
VisLog visLog = (VisLog) _task;
|
||||||
//[访问量]
|
//[访问量]
|
||||||
String uri = visLog.getUri();
|
String uri = visLog.getUri();
|
||||||
if (uri != null && uri.startsWith("/jie/detail/")){
|
if (uri != null && uri.startsWith("/jie/detail/")) {
|
||||||
updateViewNum(visLog);
|
updateViewNum(visLog);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -93,11 +93,11 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(ignore = true, comment = "访问热帖数据")
|
@RestMapping(ignore = true, comment = "访问热帖数据")
|
||||||
public Sheet<ContentInfo> hotView(String sessionid){
|
public Sheet<ContentInfo> hotView(String sessionid) {
|
||||||
int limit = 8;
|
int limit = 8;
|
||||||
String cacheKey = "hotView";
|
String cacheKey = "hotView";
|
||||||
Object ids = cacheSource.get(cacheKey);
|
Object ids = cacheSource.get(cacheKey);
|
||||||
if (isEmpty.test(ids)){
|
if (isEmpty.test(ids)) {
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
cal.set(Calendar.DAY_OF_MONTH, -7);
|
cal.set(Calendar.DAY_OF_MONTH, -7);
|
||||||
|
|
||||||
@@ -136,9 +136,9 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
|||||||
|
|
||||||
//权限过滤
|
//权限过滤
|
||||||
UserInfo userInfo = userService.current(sessionid);
|
UserInfo userInfo = userService.current(sessionid);
|
||||||
if (userInfo == null){ //访客
|
if (userInfo == null) { //访客
|
||||||
node.and("status", FilterExpress.NOTEQUAL, 30);
|
node.and("status", FilterExpress.NOTEQUAL, 30);
|
||||||
}else if (!userService.isAdmin(userInfo.getUserid())){ //非管理员
|
} else if (!userService.isAdmin(userInfo.getUserid())) { //非管理员
|
||||||
node.and(FilterNode.create("status", FilterExpress.NOTEQUAL, 30).or(FilterNode.create("status", 30).and("userid", userInfo.getUserid())));
|
node.and(FilterNode.create("status", FilterExpress.NOTEQUAL, 30).or(FilterNode.create("status", 30).and("userid", userInfo.getUserid())));
|
||||||
}
|
}
|
||||||
return contentService.contentQuery(flipper, node);
|
return contentService.contentQuery(flipper, node);
|
||||||
@@ -148,7 +148,7 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
|||||||
* TODO:帖子访客记录 --待完成
|
* TODO:帖子访客记录 --待完成
|
||||||
*/
|
*/
|
||||||
@RestMapping(ignore = true, comment = "帖子访客记录")
|
@RestMapping(ignore = true, comment = "帖子访客记录")
|
||||||
public Sheet<Map> readRecordAsync(Flipper flipper ,int contentid){
|
public Sheet<Map> readRecordAsync(Flipper flipper, int contentid) {
|
||||||
/*Bson filter = eq("uri", "/jie/detail/"+ contentid);
|
/*Bson filter = eq("uri", "/jie/detail/"+ contentid);
|
||||||
|
|
||||||
FindIterable<Document> documents = visLog.find(filter).limit(flipper.getLimit()).skip(flipper.getOffset());
|
FindIterable<Document> documents = visLog.find(filter).limit(flipper.getLimit()).skip(flipper.getOffset());
|
||||||
|
@@ -8,5 +8,6 @@ import net.tccn.bbs.base.iface.UI;
|
|||||||
*/
|
*/
|
||||||
public interface UF<I extends UI> {
|
public interface UF<I extends UI> {
|
||||||
int getUserid();
|
int getUserid();
|
||||||
|
|
||||||
I createInfo();
|
I createInfo();
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,6 @@ import javax.persistence.Column;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author lxyer
|
* @author lxyer
|
||||||
*/
|
*/
|
||||||
public class ActLogBean implements Serializable, FilterBean {
|
public class ActLogBean implements Serializable, FilterBean {
|
||||||
|
@@ -1,18 +1,17 @@
|
|||||||
package net.tccn.bbs.base.entity;
|
package net.tccn.bbs.base.entity;
|
||||||
|
|
||||||
|
import org.redkale.convert.json.JsonConvert;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import org.redkale.convert.json.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author lxyer
|
* @author lxyer
|
||||||
*/
|
*/
|
||||||
@Cacheable(interval = 5*60)
|
@Cacheable(interval = 5 * 60)
|
||||||
@Table(catalog = "redbbs", name = "sys_actlog")
|
@Table(catalog = "redbbs", name = "sys_actlog")
|
||||||
public class ActLog implements java.io.Serializable {
|
public class ActLog implements java.io.Serializable {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
|
||||||
@Column(comment = "[日志id]")
|
@Column(comment = "[日志id]")
|
||||||
private int logid;
|
private int logid;
|
||||||
|
|
||||||
|
@@ -8,10 +8,9 @@ import javax.persistence.Id;
|
|||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author lxyer
|
* @author lxyer
|
||||||
*/
|
*/
|
||||||
@Cacheable(interval = 5*60)
|
@Cacheable(interval = 5 * 60)
|
||||||
@Table(catalog = "redbbs", name = "sys_dynattr", comment = "[动态属性表]")
|
@Table(catalog = "redbbs", name = "sys_dynattr", comment = "[动态属性表]")
|
||||||
public class DynAttr implements java.io.Serializable {
|
public class DynAttr implements java.io.Serializable {
|
||||||
|
|
||||||
|
@@ -12,16 +12,16 @@ import java.util.List;
|
|||||||
public interface CService<I extends UI> {
|
public interface CService<I extends UI> {
|
||||||
|
|
||||||
@RestMapping(ignore = true)
|
@RestMapping(ignore = true)
|
||||||
default <A extends C> Sheet<I> createInfo(Sheet<A> fSheet){
|
default <A extends C> Sheet<I> createInfo(Sheet<A> fSheet) {
|
||||||
Sheet<I> sheet = new Sheet<>();
|
Sheet<I> sheet = new Sheet<>();
|
||||||
|
|
||||||
if (fSheet == null || fSheet.getTotal() < 1){
|
if (fSheet == null || fSheet.getTotal() < 1) {
|
||||||
sheet.setTotal(0);
|
sheet.setTotal(0);
|
||||||
sheet.setRows(new ArrayList<>());
|
sheet.setRows(new ArrayList<>());
|
||||||
}else {
|
} else {
|
||||||
int total = (int)fSheet.getTotal();
|
int total = (int) fSheet.getTotal();
|
||||||
List<I> rows = new ArrayList<>(total);
|
List<I> rows = new ArrayList<>(total);
|
||||||
fSheet.forEach(x->rows.add((I)x.createInfo()));
|
fSheet.forEach(x -> rows.add((I) x.createInfo()));
|
||||||
|
|
||||||
sheet.setTotal(total);
|
sheet.setTotal(total);
|
||||||
sheet.setRows(rows);
|
sheet.setRows(rows);
|
||||||
|
@@ -9,23 +9,29 @@ public interface UI<I extends UI> {
|
|||||||
|
|
||||||
//抽象方法
|
//抽象方法
|
||||||
int getUserid();
|
int getUserid();
|
||||||
|
|
||||||
UserRecord getUser();
|
UserRecord getUser();
|
||||||
|
|
||||||
I setUser(UserRecord user);
|
I setUser(UserRecord user);
|
||||||
|
|
||||||
//默认实现方法
|
//默认实现方法
|
||||||
default String getRealname(){
|
default String getRealname() {
|
||||||
return getUser() == null ? null : getUser().getRealname();
|
return getUser() == null ? null : getUser().getRealname();
|
||||||
}
|
}
|
||||||
default String getNickname(){
|
|
||||||
|
default String getNickname() {
|
||||||
return getUser() == null ? null : getUser().getNickname();
|
return getUser() == null ? null : getUser().getNickname();
|
||||||
}
|
}
|
||||||
default String getSite(){
|
|
||||||
|
default String getSite() {
|
||||||
return getUser() == null ? "" : getUser().getSite();
|
return getUser() == null ? "" : getUser().getSite();
|
||||||
}
|
}
|
||||||
default String getGit(){
|
|
||||||
|
default String getGit() {
|
||||||
return getUser() == null ? "" : getUser().getGit();
|
return getUser() == null ? "" : getUser().getGit();
|
||||||
}
|
}
|
||||||
default String getAvatar(){
|
|
||||||
|
default String getAvatar() {
|
||||||
return getUser() == null ? null : getUser().getAvatar();
|
return getUser() == null ? null : getUser().getAvatar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,11 +17,11 @@ public interface UIService<I extends UI> extends CService<I> {
|
|||||||
DataSource getSource();
|
DataSource getSource();
|
||||||
|
|
||||||
@RestMapping(ignore = true)
|
@RestMapping(ignore = true)
|
||||||
default Sheet<I> setIUser(Sheet<I> sheet){
|
default Sheet<I> setIUser(Sheet<I> sheet) {
|
||||||
int[] userids = sheet.stream().mapToInt(I::getUserid).toArray();
|
int[] userids = sheet.stream().mapToInt(I::getUserid).toArray();
|
||||||
|
|
||||||
List<UserRecord> users = getSource().queryList(UserRecord.class, FilterNode.create("userid", FilterExpress.IN, userids));
|
List<UserRecord> users = getSource().queryList(UserRecord.class, FilterNode.create("userid", FilterExpress.IN, userids));
|
||||||
sheet.forEach(x->{
|
sheet.forEach(x -> {
|
||||||
UserRecord user = users.stream().filter(u -> u.getUserid() == x.getUserid()).findAny().orElse(null);
|
UserRecord user = users.stream().filter(u -> u.getUserid() == x.getUserid()).findAny().orElse(null);
|
||||||
x.setUser(user);
|
x.setUser(user);
|
||||||
});
|
});
|
||||||
@@ -29,7 +29,7 @@ public interface UIService<I extends UI> extends CService<I> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(ignore = true)
|
@RestMapping(ignore = true)
|
||||||
default I setIUser(I i){
|
default I setIUser(I i) {
|
||||||
UserRecord user = getSource().find(UserRecord.class, i.getUserid());
|
UserRecord user = getSource().find(UserRecord.class, i.getUserid());
|
||||||
|
|
||||||
return (I) i.setUser(user);
|
return (I) i.setUser(user);
|
||||||
|
@@ -12,10 +12,11 @@ import java.text.SimpleDateFormat;
|
|||||||
@RestService
|
@RestService
|
||||||
public class EJ {
|
public class EJ {
|
||||||
|
|
||||||
public String date(long time){
|
public String date(long time) {
|
||||||
return date(time, "yyyy-MM-dd HH:mm:ss");
|
return date(time, "yyyy-MM-dd HH:mm:ss");
|
||||||
}
|
}
|
||||||
public String date(long time, String pattern){
|
|
||||||
|
public String date(long time, String pattern) {
|
||||||
return new SimpleDateFormat(pattern).format(time);
|
return new SimpleDateFormat(pattern).format(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,7 +10,7 @@ import java.util.regex.Pattern;
|
|||||||
*/
|
*/
|
||||||
public final class LxyKit {
|
public final class LxyKit {
|
||||||
|
|
||||||
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
|
||||||
@@ -23,45 +23,45 @@ public final class LxyKit {
|
|||||||
long diff = now - time;
|
long diff = now - time;
|
||||||
if (diff < 60 * 1000)
|
if (diff < 60 * 1000)
|
||||||
return "刚刚";
|
return "刚刚";
|
||||||
else if (diff < 60 * 60 *1000)
|
else if (diff < 60 * 60 * 1000)
|
||||||
return Math.floorDiv(diff, 60 *1000) + "分钟前";
|
return Math.floorDiv(diff, 60 * 1000) + "分钟前";
|
||||||
else if (diff < 24 * 60*60*1000)
|
else if (diff < 24 * 60 * 60 * 1000)
|
||||||
return Math.floorDiv(diff, 60 *60*1000) + "小时前";
|
return Math.floorDiv(diff, 60 * 60 * 1000) + "小时前";
|
||||||
else if (diff > 24 * 60*60*1000 && diff < 7 * 24*60*60*1000)
|
else if (diff > 24 * 60 * 60 * 1000 && diff < 7 * 24 * 60 * 60 * 1000)
|
||||||
return Math.floorDiv(diff, 24 * 60*60*1000) + "天前";
|
return Math.floorDiv(diff, 24 * 60 * 60 * 1000) + "天前";
|
||||||
else
|
else
|
||||||
return new SimpleDateFormat("yyyy-MM-dd").format(time);
|
return new SimpleDateFormat("yyyy-MM-dd").format(time);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String delHTMLTag(String htmlStr){
|
public static String delHTMLTag(String htmlStr) {
|
||||||
String regEx_script="<script[^>]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式
|
String regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式
|
||||||
String regEx_style="<style[^>]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式
|
String regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式
|
||||||
String regEx_html="<[^>]+>"; //定义HTML标签的正则表达式
|
String regEx_html = "<[^>]+>"; //定义HTML标签的正则表达式
|
||||||
|
|
||||||
Pattern p_script=Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE);
|
Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher m_script=p_script.matcher(htmlStr);
|
Matcher m_script = p_script.matcher(htmlStr);
|
||||||
htmlStr=m_script.replaceAll(""); //过滤script标签
|
htmlStr = m_script.replaceAll(""); //过滤script标签
|
||||||
|
|
||||||
Pattern p_style=Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE);
|
Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher m_style=p_style.matcher(htmlStr);
|
Matcher m_style = p_style.matcher(htmlStr);
|
||||||
htmlStr=m_style.replaceAll(""); //过滤style标签
|
htmlStr = m_style.replaceAll(""); //过滤style标签
|
||||||
|
|
||||||
Pattern p_html=Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE);
|
Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
|
||||||
Matcher m_html=p_html.matcher(htmlStr);
|
Matcher m_html = p_html.matcher(htmlStr);
|
||||||
htmlStr=m_html.replaceAll(""); //过滤html标签
|
htmlStr = m_html.replaceAll(""); //过滤html标签
|
||||||
|
|
||||||
return htmlStr.trim(); //返回文本字符串
|
return htmlStr.trim(); //返回文本字符串
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (int i = 0; i < list.size(); i++) {
|
||||||
ts[0] = (T) list.get(i);
|
ts[0] = (T) list.get(i);
|
||||||
}
|
}
|
||||||
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 (int i = 0; i < list.size(); i++) {
|
||||||
ts[0] = (int) list.get(i);
|
ts[0] = (int) list.get(i);
|
||||||
}
|
}
|
||||||
|
@@ -55,7 +55,6 @@ public abstract class RetCodes {
|
|||||||
public static final int RET_COMMENT_PARA_ILLEGAL = 3004_0002;
|
public static final int RET_COMMENT_PARA_ILLEGAL = 3004_0002;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static RetResult retResult(int retcode) {
|
public static RetResult retResult(int retcode) {
|
||||||
return new RetResult(retcode);
|
return new RetResult(retcode);
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,6 @@ import javax.persistence.Column;
|
|||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author lxyer
|
* @author lxyer
|
||||||
*/
|
*/
|
||||||
public class UserInfo implements java.io.Serializable {
|
public class UserInfo implements java.io.Serializable {
|
||||||
@@ -58,7 +57,7 @@ public class UserInfo implements java.io.Serializable {
|
|||||||
this.sex = sex;
|
this.sex = sex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConvertColumn(ignore = true,type = ConvertType.JSON)
|
@ConvertColumn(ignore = true, type = ConvertType.JSON)
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
@@ -178,6 +177,7 @@ public class UserInfo implements java.io.Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查用户权限
|
* 检查用户权限
|
||||||
|
*
|
||||||
* @param moduleid
|
* @param moduleid
|
||||||
* @param actionid
|
* @param actionid
|
||||||
* @return
|
* @return
|
||||||
|
@@ -9,10 +9,9 @@ import javax.persistence.Id;
|
|||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author lxyer
|
* @author lxyer
|
||||||
*/
|
*/
|
||||||
@Cacheable(interval = 5*60)
|
@Cacheable(interval = 5 * 60)
|
||||||
@Table(catalog = "redbbs", name = "sys_userrecord")
|
@Table(catalog = "redbbs", name = "sys_userrecord")
|
||||||
public class UserRecord implements java.io.Serializable {
|
public class UserRecord implements java.io.Serializable {
|
||||||
|
|
||||||
@@ -221,11 +220,11 @@ public class UserRecord implements java.io.Serializable {
|
|||||||
return userInfo;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String passwordForMd5(){
|
public String passwordForMd5() {
|
||||||
return md5IfNeed(password);
|
return md5IfNeed(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String md5IfNeed(String password){
|
public static String md5IfNeed(String password) {
|
||||||
return Utility.md5Hex(password);
|
return Utility.md5Hex(password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,44 +30,45 @@ import static net.tccn.bbs.base.kit.RetCodes.*;
|
|||||||
public class UserService extends BaseService {
|
public class UserService extends BaseService {
|
||||||
|
|
||||||
@RestMapping(auth = false, comment = "登录校验")
|
@RestMapping(auth = false, comment = "登录校验")
|
||||||
public RetResult<UserInfo> login(@RestParam(name = "bean") LoginBean loginBean){
|
public RetResult<UserInfo> login(LoginBean bean) {
|
||||||
if (loginBean == null || loginBean.emptyUsername()) return RetCodes.retResult(RetCodes.RET_PARAMS_ILLEGAL, "参数错误");
|
if (bean == null || bean.emptyUsername()) return RetCodes.retResult(RetCodes.RET_PARAMS_ILLEGAL, "参数错误");
|
||||||
|
|
||||||
final RetResult retResult = new RetResult();
|
final RetResult retResult = new RetResult();
|
||||||
|
|
||||||
UserRecord user = source.find(UserRecord.class, "username", loginBean.getUsername());
|
UserRecord user = source.find(UserRecord.class, "username", bean.getUsername());
|
||||||
if (user == null || !Objects.equals(user.getPassword(), loginBean.getPassword())){
|
if (user == null || !Objects.equals(user.getPassword(), bean.getPassword())) {
|
||||||
//log(null, 0, "用户或密码错误");
|
//log(null, 0, "用户或密码错误");
|
||||||
return RetCodes.retResult(RetCodes.RET_USER_ACCOUNT_PWD_ILLEGAL, "用户名或密码错误");
|
return RetCodes.retResult(RetCodes.RET_USER_ACCOUNT_PWD_ILLEGAL, "用户名或密码错误");
|
||||||
}
|
}
|
||||||
sessions.setAsync(sessionExpireSeconds, loginBean.getSessionid(), (long)user.getUserid());
|
sessions.setAsync(sessionExpireSeconds, bean.getSessionid(), (long) user.getUserid());
|
||||||
retResult.setRetcode(0);
|
retResult.setRetcode(0);
|
||||||
retResult.setResult(Kv.by("token", loginBean.getSessionid()));
|
retResult.setResult(Kv.by("token", bean.getSessionid()));
|
||||||
retResult.setRetinfo("登录成功.");
|
retResult.setRetinfo("登录成功.");
|
||||||
return retResult;
|
return retResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserInfo current(String sessionid){
|
public UserInfo current(String sessionid) {
|
||||||
if (sessionid == null) return null;
|
if (sessionid == null) return null;
|
||||||
|
|
||||||
long userid = 0;
|
long userid = 0;
|
||||||
try {
|
try {
|
||||||
userid = sessions.getLong(sessionid, 0);
|
userid = sessions.getLong(sessionid, 0);
|
||||||
sessions.getAndRefresh(sessionid, sessionExpireSeconds);
|
sessions.getAndRefresh(sessionid, sessionExpireSeconds);
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return userid == 0 ? null : findUserInfo((int)userid);
|
return userid == 0 ? null : find((int) userid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "info", comment = "用户信息")
|
@RestMapping(name = "info", comment = "用户信息")
|
||||||
public UserInfo findUserInfo(int userid) {
|
public UserInfo find(int userid) {
|
||||||
UserRecord user = source.find(UserRecord.class, userid);
|
UserRecord user = source.find(UserRecord.class, userid);
|
||||||
return user == null ? null : user.createUserInfo();
|
UserInfo bean = user.createUserInfo();
|
||||||
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
sessions.remove(sessionid);
|
||||||
|
|
||||||
return RetResult.success();
|
return RetResult.success();
|
||||||
@@ -75,14 +76,14 @@ public class UserService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "query", auth = false, comment = "用户数据查询")
|
@RestMapping(name = "query", auth = false, comment = "用户数据查询")
|
||||||
public Sheet<UserRecord> queryUser(Flipper flipper, @RestParam(name = "bean", comment = "过滤条件") final UserBean userBean){
|
public Sheet<UserRecord> query(Flipper flipper, @RestParam(name = "bean", comment = "过滤条件") final UserBean userBean) {
|
||||||
Sheet<UserRecord> users = source.querySheet(UserRecord.class, flipper, userBean);
|
Sheet<UserRecord> users = source.querySheet(UserRecord.class, flipper, userBean);
|
||||||
|
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "changepwd", comment = "修改密码")
|
@RestMapping(name = "changepwd", comment = "修改密码")
|
||||||
public RetResult updatePwd(@RestSessionid String sessionid, String pass, String nowpass){
|
public RetResult updatePwd(@RestSessionid String sessionid, String pass, String nowpass) {
|
||||||
UserInfo userInfo = current(sessionid);//不会为空
|
UserInfo userInfo = current(sessionid);//不会为空
|
||||||
|
|
||||||
if (!Objects.equals(userInfo.getPassword(), UserRecord.md5IfNeed(nowpass)))
|
if (!Objects.equals(userInfo.getPassword(), UserRecord.md5IfNeed(nowpass)))
|
||||||
@@ -94,50 +95,51 @@ public class UserService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "register", auth = false, comment = "用户注册")
|
@RestMapping(name = "register", auth = false, comment = "用户注册")
|
||||||
public RetResult register(@RestParam(name = "bean") UserRecord user){
|
public RetResult register(UserRecord bean) {
|
||||||
/*用户名、密码、邮箱*/
|
/*用户名、密码、邮箱*/
|
||||||
if (user.getEmail() == null) return RetCodes.retResult(RET_USER_EMAIL_ILLEGAL, "邮件地址无效");
|
if (bean.getEmail() == null) return RetCodes.retResult(RET_USER_EMAIL_ILLEGAL, "邮件地址无效");
|
||||||
if (user.getPassword() == null || user.getPassword().length() < 6) return RetCodes.retResult(RET_USER_PASSWORD_ILLEGAL, "密码设置无效");
|
if (bean.getPassword() == null || bean.getPassword().length() < 6)
|
||||||
|
return RetCodes.retResult(RET_USER_PASSWORD_ILLEGAL, "密码设置无效");
|
||||||
|
|
||||||
UserRecord _user = source.find(UserRecord.class, FilterNode.create("email", user.getEmail()));
|
UserRecord _user = source.find(UserRecord.class, FilterNode.create("email", bean.getEmail()));
|
||||||
if (_user != null) return RetCodes.retResult(RET_USER_USERNAME_EXISTS, "用户名已存在");
|
if (_user != null) return RetCodes.retResult(RET_USER_USERNAME_EXISTS, "用户名已存在");
|
||||||
|
|
||||||
user.setCreatetime(System.currentTimeMillis());
|
bean.setCreatetime(System.currentTimeMillis());
|
||||||
user.setPassword(user.passwordForMd5());
|
bean.setPassword(bean.passwordForMd5());
|
||||||
user.setStatus((short) 10);
|
bean.setStatus((short) 10);
|
||||||
user.setUsername(user.getEmail());
|
bean.setUsername(bean.getEmail());
|
||||||
user.setAvatar("/res/images/avatar/"+ new Random().nextInt(21) +".jpg");//默认头像
|
bean.setAvatar("/res/images/avatar/" + new Random().nextInt(21) + ".jpg");//默认头像
|
||||||
|
|
||||||
int maxId = source.getNumberResult(UserRecord.class, FilterFunc.MAX, 10_0000, "userid").intValue();
|
int maxId = source.getNumberResult(UserRecord.class, FilterFunc.MAX, 10_0000, "userid").intValue();
|
||||||
if (maxId < 10_0000) maxId = 10_0000;
|
if (maxId < 10_0000) maxId = 10_0000;
|
||||||
user.setUserid(maxId+1);
|
bean.setUserid(maxId + 1);
|
||||||
source.insert(user);
|
source.insert(bean);
|
||||||
|
|
||||||
//记录日志
|
//记录日志
|
||||||
return RetResult.success();
|
return RetResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "update", comment = "用户信息修改")
|
@RestMapping(name = "update", comment = "用户信息修改")
|
||||||
public RetResult userUpdate(@RestSessionid String sessionid, @RestParam(name = "bean") UserRecord user, String[] columns){
|
public RetResult userUpdate(UserInfo user, UserRecord bean, String[] columns) {
|
||||||
String nickname = user.getNickname();
|
String nickname = bean.getNickname();
|
||||||
if (nickname == null && nickname.isEmpty())
|
if (nickname == null && nickname.isEmpty())
|
||||||
return RetCodes.retResult(RET_USER_NICKNAME_ILLEGAL, "昵称无效");
|
return RetCodes.retResult(RET_USER_NICKNAME_ILLEGAL, "昵称无效");
|
||||||
|
|
||||||
nickname = nickname.replace(" ", "");
|
nickname = nickname.replace(" ", "");
|
||||||
UserRecord _user = source.find(UserRecord.class, FilterNode.create("nickname", nickname));
|
UserRecord _user = source.find(UserRecord.class, FilterNode.create("nickname", nickname));
|
||||||
if (_user != null && _user.getUserid() != currentUserid(sessionid))
|
if (_user != null && _user.getUserid() != user.getUserid())
|
||||||
return RetCodes.retResult(RET_USER_NICKNAME_EXISTS, "昵称已存在");
|
return RetCodes.retResult(RET_USER_NICKNAME_EXISTS, "昵称已存在");
|
||||||
|
|
||||||
user.setNickname(nickname);//去除昵称中的空格
|
bean.setNickname(nickname);//去除昵称中的空格
|
||||||
source.updateColumn(user
|
source.updateColumn(bean
|
||||||
,FilterNode.create("userid", currentUserid(sessionid))
|
, FilterNode.create("userid", user.getUserid())
|
||||||
,SelectColumn.includes(columns)
|
, SelectColumn.includes(columns)
|
||||||
);
|
);
|
||||||
return RetResult.success();
|
return RetResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
//最新加入
|
//最新加入
|
||||||
public Sheet<UserInfo> lastReg(){
|
public Sheet<UserInfo> lastReg() {
|
||||||
Sheet<UserRecord> users = source.querySheet(UserRecord.class
|
Sheet<UserRecord> users = source.querySheet(UserRecord.class
|
||||||
, SelectColumn.includes("userid", "nickname", "avatar", "createtime")
|
, SelectColumn.includes("userid", "nickname", "avatar", "createtime")
|
||||||
, new Flipper().sort("createtime DESC").limit(8)
|
, new Flipper().sort("createtime DESC").limit(8)
|
||||||
@@ -146,7 +148,7 @@ public class UserService extends BaseService {
|
|||||||
Sheet<UserInfo> infos = new Sheet<>();
|
Sheet<UserInfo> infos = new Sheet<>();
|
||||||
ArrayList<UserInfo> list = new ArrayList<>();
|
ArrayList<UserInfo> list = new ArrayList<>();
|
||||||
|
|
||||||
users.forEach(x->{
|
users.forEach(x -> {
|
||||||
UserInfo info = x.createUserInfo();
|
UserInfo info = x.createUserInfo();
|
||||||
info.setTime(LxyKit.dateFmt(x.getCreatetime()));
|
info.setTime(LxyKit.dateFmt(x.getCreatetime()));
|
||||||
list.add(info);
|
list.add(info);
|
||||||
@@ -164,7 +166,7 @@ public class UserService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(ignore = true, comment = "判断用户是否是管理员")
|
@RestMapping(ignore = true, comment = "判断用户是否是管理员")
|
||||||
public boolean isAdmin(int userid){
|
public boolean isAdmin(int userid) {
|
||||||
if (userid <= 0) return false;
|
if (userid <= 0) return false;
|
||||||
|
|
||||||
List<Integer> userIds = source.queryColumnList("userid", UserRecord.class, FilterNode.create("roleid", 1));
|
List<Integer> userIds = source.queryColumnList("userid", UserRecord.class, FilterNode.create("roleid", 1));
|
||||||
|
@@ -1,23 +1,20 @@
|
|||||||
package net.tccn.bbs.comment;
|
package net.tccn.bbs.comment;
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
|
|
||||||
import net.tccn.bbs.base.iface.C;
|
import net.tccn.bbs.base.iface.C;
|
||||||
import net.tccn.bbs.base.kit.LxyKit;
|
import net.tccn.bbs.base.kit.LxyKit;
|
||||||
import org.redkale.convert.json.*;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author lxyer
|
* @author lxyer
|
||||||
*/
|
*/
|
||||||
@Cacheable(interval = 5*60)
|
@Cacheable(interval = 5 * 60)
|
||||||
@Table(catalog = "redbbs", name = "sys_comment", comment = "[评论表]")
|
@Table(catalog = "redbbs", name = "sys_comment", comment = "[评论表]")
|
||||||
public class Comment implements Serializable, C<CommentInfo> {
|
public class Comment implements Serializable, C<CommentInfo> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
|
||||||
@Column(comment = "[评论id]")
|
@Column(comment = "[评论id]")
|
||||||
private int commentid;
|
private int commentid;
|
||||||
|
|
||||||
@@ -122,7 +119,7 @@ public class Comment implements Serializable, C<CommentInfo> {
|
|||||||
return JsonConvert.root().convertTo(this);
|
return JsonConvert.root().convertTo(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommentInfo createInfo(){
|
public CommentInfo createInfo() {
|
||||||
CommentInfo info = new CommentInfo();
|
CommentInfo info = new CommentInfo();
|
||||||
info.setCommentid(commentid);
|
info.setCommentid(commentid);
|
||||||
info.setUserid(userid);
|
info.setUserid(userid);
|
||||||
|
@@ -9,10 +9,9 @@ import javax.persistence.Column;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author lxyer
|
* @author lxyer
|
||||||
*/
|
*/
|
||||||
public class CommentInfo implements UI<CommentInfo>,Serializable, CI<CommentInfo> {
|
public class CommentInfo implements UI<CommentInfo>, Serializable, CI<CommentInfo> {
|
||||||
|
|
||||||
@Column(comment = "[评论id]")
|
@Column(comment = "[评论id]")
|
||||||
private int commentid;
|
private int commentid;
|
||||||
|
@@ -24,11 +24,11 @@ import static net.tccn.bbs.base.kit.RetCodes.RET_COMMENT_PARA_ILLEGAL;
|
|||||||
/**
|
/**
|
||||||
* Created by Lxy at 2017/11/29 10:00.
|
* Created by Lxy at 2017/11/29 10:00.
|
||||||
*/
|
*/
|
||||||
@RestService(automapping = true, comment = "评论服务")
|
@RestService(name = "comment", comment = "评论服务")
|
||||||
public class CommentService extends BaseService implements UIService<CommentInfo> {
|
public class CommentService extends BaseService implements UIService<CommentInfo> {
|
||||||
|
|
||||||
@RestMapping(name = "save", comment = "评论保存")
|
@RestMapping(name = "save", comment = "评论保存")
|
||||||
public RetResult commentSave(@RestSessionid String sessionid, @RestParam(name = "bean") Comment comment){
|
public RetResult save(@RestSessionid String sessionid, @RestParam(name = "bean") Comment comment) {
|
||||||
int contentid = comment.getContentid();
|
int contentid = comment.getContentid();
|
||||||
|
|
||||||
//数据校验
|
//数据校验
|
||||||
@@ -50,14 +50,14 @@ public class CommentService extends BaseService implements UIService<CommentInfo
|
|||||||
//update replyNum
|
//update replyNum
|
||||||
int count = source.getNumberResult(Comment.class, FilterFunc.COUNT, "commentid", FilterNode.create("contentid", contentid)).intValue();
|
int count = source.getNumberResult(Comment.class, FilterFunc.COUNT, "commentid", FilterNode.create("contentid", contentid)).intValue();
|
||||||
source.updateColumn(Content.class, contentid, ColumnValue.create("replynum", count));
|
source.updateColumn(Content.class, contentid, ColumnValue.create("replynum", count));
|
||||||
}else {
|
} else {
|
||||||
source.updateColumn(comment, SelectColumn.includes("content"));
|
source.updateColumn(comment, SelectColumn.includes("content"));
|
||||||
}
|
}
|
||||||
return RetResult.success();
|
return RetResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "query", auth = false,comment = "查询评论")
|
@RestMapping(name = "query", auth = false, comment = "查询评论")
|
||||||
public Sheet<CommentInfo> commentQuery(@RestSessionid String sessionid , int contentId, Flipper flipper){
|
public Sheet<CommentInfo> query(@RestSessionid String sessionid, int contentId, Flipper flipper) {
|
||||||
int userid = currentUserid(sessionid);
|
int userid = currentUserid(sessionid);
|
||||||
|
|
||||||
flipper.setSort("supportnum DESC,commentid ASC");
|
flipper.setSort("supportnum DESC,commentid ASC");
|
||||||
@@ -67,12 +67,12 @@ public class CommentService extends BaseService implements UIService<CommentInfo
|
|||||||
setIUser(infos);
|
setIUser(infos);
|
||||||
|
|
||||||
//用户点赞的评论
|
//用户点赞的评论
|
||||||
if (userid > 0){
|
if (userid > 0) {
|
||||||
int[] commentids = comments.stream().mapToInt(Comment::getCommentid).toArray();
|
int[] commentids = comments.stream().mapToInt(Comment::getCommentid).toArray();
|
||||||
FilterNode node = FilterNode.create("cate", 10).and("status", 10).and("userid", userid).and("tid", FilterExpress.IN, commentids);
|
FilterNode node = FilterNode.create("cate", 10).and("status", 10).and("userid", userid).and("tid", FilterExpress.IN, commentids);
|
||||||
List<Integer> hadSupport = source.queryColumnList("tid", ActLog.class, node);
|
List<Integer> hadSupport = source.queryColumnList("tid", ActLog.class, node);
|
||||||
|
|
||||||
infos.forEach(x->{
|
infos.forEach(x -> {
|
||||||
x.setHadsupport(hadSupport.contains(x.getCommentid()) ? 1 : -1);//
|
x.setHadsupport(hadSupport.contains(x.getCommentid()) ? 1 : -1);//
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -80,15 +80,15 @@ public class CommentService extends BaseService implements UIService<CommentInfo
|
|||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(ignore = true, comment = "查询用户评论数据")
|
@org.redkale.util.Comment("查询用户评论数据")
|
||||||
public Sheet<CommentInfo> queryByUserid(int userid){
|
public Sheet<CommentInfo> queryByUserid(int userid) {
|
||||||
Sheet<Comment> comments = source.querySheet(Comment.class, new Flipper().sort("createtime DESC"), FilterNode.create("userid", userid));
|
Sheet<Comment> comments = source.querySheet(Comment.class, new Flipper().sort("createtime DESC"), FilterNode.create("userid", userid));
|
||||||
|
|
||||||
int[] contentIds = comments.stream().mapToInt(x -> x.getCommentid()).toArray();
|
int[] contentIds = comments.stream().mapToInt(x -> x.getCommentid()).toArray();
|
||||||
List<Content> contents = source.queryList(Content.class, SelectColumn.includes("contentid","title"), FilterNode.create("contentid", FilterExpress.IN, contentIds));
|
List<Content> contents = source.queryList(Content.class, SelectColumn.includes("contentid", "title"), FilterNode.create("contentid", FilterExpress.IN, contentIds));
|
||||||
|
|
||||||
Sheet<CommentInfo> infos = createInfo(comments);
|
Sheet<CommentInfo> infos = createInfo(comments);
|
||||||
infos.forEach(x->{
|
infos.forEach(x -> {
|
||||||
Content content = contents.stream().filter(k -> k.getContentid() == x.getContentid()).findFirst().orElse(new Content());
|
Content content = contents.stream().filter(k -> k.getContentid() == x.getContentid()).findFirst().orElse(new Content());
|
||||||
x.setTitle(content.getTitle());
|
x.setTitle(content.getTitle());
|
||||||
});
|
});
|
||||||
@@ -96,15 +96,15 @@ public class CommentService extends BaseService implements UIService<CommentInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "support", comment = "点赞")
|
@RestMapping(name = "support", comment = "点赞")
|
||||||
public RetResult support(@RestSessionid String sessionid, int commentid, int ok){
|
public RetResult support(@RestSessionid String sessionid, int commentid, int ok) {
|
||||||
int userid = currentUserid(sessionid);
|
int userid = currentUserid(sessionid);
|
||||||
|
|
||||||
source.findAsync(ActLog.class, FilterNode.create("userid", userid).and("tid", commentid).and("cate", 10)).thenAccept(actLog -> {
|
source.findAsync(ActLog.class, FilterNode.create("userid", userid).and("tid", commentid).and("cate", 10)).thenAccept(actLog -> {
|
||||||
if (actLog == null && ok == 1){
|
if (actLog == null && ok == 1) {
|
||||||
actLog = new ActLog(10, commentid, userid);
|
actLog = new ActLog(10, commentid, userid);
|
||||||
actLog.setCreatetime(System.currentTimeMillis());
|
actLog.setCreatetime(System.currentTimeMillis());
|
||||||
source.insert(actLog);
|
source.insert(actLog);
|
||||||
}else if (actLog != null && actLog.getStatus() != ok){
|
} else if (actLog != null && actLog.getStatus() != ok) {
|
||||||
actLog.setStatus((short) -10);
|
actLog.setStatus((short) -10);
|
||||||
source.update(actLog);
|
source.update(actLog);
|
||||||
}/*else {
|
}/*else {
|
||||||
@@ -112,7 +112,7 @@ public class CommentService extends BaseService implements UIService<CommentInfo
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
int count = source.getNumberResult(ActLog.class, FilterFunc.COUNT, 0, "logid", FilterNode.create("tid", commentid).and("status", 10)).intValue();
|
int count = source.getNumberResult(ActLog.class, FilterFunc.COUNT, 0, "logid", FilterNode.create("tid", commentid).and("status", 10)).intValue();
|
||||||
source.updateColumn(Comment.class, commentid,"supportnum", count);
|
source.updateColumn(Comment.class, commentid, "supportnum", count);
|
||||||
});
|
});
|
||||||
|
|
||||||
return RetResult.success();
|
return RetResult.success();
|
||||||
@@ -120,10 +120,11 @@ public class CommentService extends BaseService implements UIService<CommentInfo
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* todo:用户评论榜 待完成
|
* todo:用户评论榜 待完成
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RestMapping(ignore = true, name = "rankuser", auth = false, comment = "用户评论榜")
|
@org.redkale.util.Comment("用户评论榜")
|
||||||
public Map<String, Number> commentRank(){
|
public Map<String, Number> commentRank() {
|
||||||
Flipper flipper = new Flipper().limit(8);
|
Flipper flipper = new Flipper().limit(8);
|
||||||
source.querySheet(Comment.class, flipper, FilterNode.create("userid", FilterExpress.IN));
|
source.querySheet(Comment.class, flipper, FilterNode.create("userid", FilterExpress.IN));
|
||||||
|
|
||||||
|
@@ -9,15 +9,13 @@ import javax.persistence.*;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author lxyer
|
* @author lxyer
|
||||||
*/
|
*/
|
||||||
@Cacheable(interval = 5*60)
|
@Cacheable(interval = 5 * 60)
|
||||||
@Table(catalog = "redbbs", name = "sys_content", comment = "[内容表]")
|
@Table(catalog = "redbbs", name = "sys_content", comment = "[内容表]")
|
||||||
public class Content implements Serializable, C<ContentInfo> {
|
public class Content implements Serializable, C<ContentInfo> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
|
||||||
@Column(comment = "[内容id]")
|
@Column(comment = "[内容id]")
|
||||||
private int contentid;
|
private int contentid;
|
||||||
|
|
||||||
@@ -195,7 +193,7 @@ public class Content implements Serializable, C<ContentInfo> {
|
|||||||
info.setSolved(solved);
|
info.setSolved(solved);
|
||||||
info.setStatus(status);
|
info.setStatus(status);
|
||||||
|
|
||||||
info.setTypename(types.getOrDefault((int)type, "其他").toString());
|
info.setTypename(types.getOrDefault((int) type, "其他").toString());
|
||||||
info.setCreatetime(LxyKit.dateFmt(createtime));
|
info.setCreatetime(LxyKit.dateFmt(createtime));
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
@@ -4,19 +4,16 @@ import org.redkale.convert.json.JsonConvert;
|
|||||||
import org.redkale.source.FilterBean;
|
import org.redkale.source.FilterBean;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author lxyer
|
* @author lxyer
|
||||||
*/
|
*/
|
||||||
@Table(catalog = "db_redbbs", name = "content", comment = "[内容表]")
|
@Table(catalog = "db_redbbs", name = "content", comment = "[内容表]")
|
||||||
public class ContentBean implements FilterBean,java.io.Serializable {
|
public class ContentBean implements FilterBean, java.io.Serializable {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
|
||||||
@Column(comment = "[内容id]")
|
@Column(comment = "[内容id]")
|
||||||
private int contentid;
|
private int contentid;
|
||||||
|
|
||||||
|
@@ -10,7 +10,7 @@ import java.io.Serializable;
|
|||||||
/**
|
/**
|
||||||
* Created by Lxy at 2017/11/26 20:52.
|
* Created by Lxy at 2017/11/26 20:52.
|
||||||
*/
|
*/
|
||||||
public class ContentInfo implements UI<ContentInfo>,Serializable, CI {
|
public class ContentInfo implements UI<ContentInfo>, Serializable, CI {
|
||||||
|
|
||||||
private int contentid;
|
private int contentid;
|
||||||
private int userid;
|
private int userid;
|
||||||
@@ -161,6 +161,7 @@ public class ContentInfo implements UI<ContentInfo>,Serializable, CI {
|
|||||||
|
|
||||||
//-----------
|
//-----------
|
||||||
private UserRecord user;
|
private UserRecord user;
|
||||||
|
|
||||||
@ConvertColumn(ignore = true)
|
@ConvertColumn(ignore = true)
|
||||||
@Override
|
@Override
|
||||||
public UserRecord getUser() {
|
public UserRecord getUser() {
|
||||||
|
@@ -7,9 +7,15 @@ import net.tccn.bbs.base.iface.UIService;
|
|||||||
import net.tccn.bbs.base.kit.RetCodes;
|
import net.tccn.bbs.base.kit.RetCodes;
|
||||||
import net.tccn.bbs.base.user.UserInfo;
|
import net.tccn.bbs.base.user.UserInfo;
|
||||||
import net.tccn.bbs.base.user.UserService;
|
import net.tccn.bbs.base.user.UserService;
|
||||||
import org.redkale.net.http.*;
|
import org.redkale.net.http.HttpScope;
|
||||||
|
import org.redkale.net.http.RestMapping;
|
||||||
|
import org.redkale.net.http.RestService;
|
||||||
|
import org.redkale.net.http.RestSessionid;
|
||||||
import org.redkale.service.RetResult;
|
import org.redkale.service.RetResult;
|
||||||
import org.redkale.source.*;
|
import org.redkale.source.FilterExpress;
|
||||||
|
import org.redkale.source.FilterFunc;
|
||||||
|
import org.redkale.source.FilterNode;
|
||||||
|
import org.redkale.source.Flipper;
|
||||||
import org.redkale.util.Comment;
|
import org.redkale.util.Comment;
|
||||||
import org.redkale.util.SelectColumn;
|
import org.redkale.util.SelectColumn;
|
||||||
import org.redkale.util.Sheet;
|
import org.redkale.util.Sheet;
|
||||||
@@ -19,14 +25,14 @@ import javax.annotation.Resource;
|
|||||||
/**
|
/**
|
||||||
* Created by Lxy at 2017/11/26 9:33.
|
* Created by Lxy at 2017/11/26 9:33.
|
||||||
*/
|
*/
|
||||||
@RestService(automapping = true, comment = "文章帖子服务")
|
@RestService(name = "content", comment = "文章帖子服务")
|
||||||
public class ContentService extends BaseService implements UIService<ContentInfo> {
|
public class ContentService extends BaseService implements UIService<ContentInfo> {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
protected UserService userService;
|
protected UserService userService;
|
||||||
|
|
||||||
@RestMapping(ignore = true, comment = "根据条件查询帖子数据")
|
@Comment("根据条件查询帖子数据")
|
||||||
public Sheet<ContentInfo> contentQuery(Flipper flipper, FilterNode filterNode){
|
public Sheet<ContentInfo> contentQuery(Flipper flipper, FilterNode filterNode) {
|
||||||
Sheet<Content> contents = source.querySheet(Content.class, flipper, filterNode);
|
Sheet<Content> contents = source.querySheet(Content.class, flipper, filterNode);
|
||||||
|
|
||||||
createInfo(contents);
|
createInfo(contents);
|
||||||
@@ -37,22 +43,32 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "query", auth = false, comment = "内容列表")
|
@RestMapping(name = "query", auth = false, comment = "内容列表")
|
||||||
public Sheet<ContentInfo> contentQuery(Flipper flipper, String actived, String sessionid){
|
public Sheet<ContentInfo> query(Flipper flipper, String actived, String sessionid) {
|
||||||
UserInfo current = userService.current(sessionid);
|
UserInfo current = userService.current(sessionid);
|
||||||
int currentid = current == null ? 0 : current.getUserid();
|
int currentid = current == null ? 0 : current.getUserid();
|
||||||
|
|
||||||
FilterNode filterNode = FilterNode.create("status", FilterExpress.NOTEQUAL, -10);
|
FilterNode filterNode = FilterNode.create("status", FilterExpress.NOTEQUAL, -10);
|
||||||
switch (actived){
|
switch (actived) {
|
||||||
case "top": filterNode.and("top", FilterExpress.GREATERTHANOREQUALTO, 20);break;
|
case "top":
|
||||||
case "untop": filterNode.and("top", 10);break;
|
filterNode.and("top", FilterExpress.GREATERTHANOREQUALTO, 20);
|
||||||
case "unsolved": filterNode.and("solved", 10);break;
|
break;
|
||||||
case "solved": filterNode.and("solved", 20);break;
|
case "untop":
|
||||||
case "wonderful": filterNode.and("wonderful", FilterExpress.GREATERTHANOREQUALTO, 20);break;
|
filterNode.and("top", 10);
|
||||||
|
break;
|
||||||
|
case "unsolved":
|
||||||
|
filterNode.and("solved", 10);
|
||||||
|
break;
|
||||||
|
case "solved":
|
||||||
|
filterNode.and("solved", 20);
|
||||||
|
break;
|
||||||
|
case "wonderful":
|
||||||
|
filterNode.and("wonderful", FilterExpress.GREATERTHANOREQUALTO, 20);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userService.isAdmin(currentid)){//私密贴:非管理员限制查看
|
if (!userService.isAdmin(currentid)) {//私密贴:非管理员限制查看
|
||||||
filterNode.and(FilterNode.create("status", FilterExpress.NOTEQUAL, 30).or(FilterNode.create("status", 30).and("userid", currentid)));
|
filterNode.and(FilterNode.create("status", FilterExpress.NOTEQUAL, 30).or(FilterNode.create("status", 30).and("userid", currentid)));
|
||||||
}else if (currentid <= 0){//私密贴:未登录限制查看
|
} else if (currentid <= 0) {//私密贴:未登录限制查看
|
||||||
filterNode.and("status", FilterExpress.NOTEQUAL, 30);
|
filterNode.and("status", FilterExpress.NOTEQUAL, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,25 +77,25 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
|||||||
|
|
||||||
|
|
||||||
@RestMapping(name = "save", comment = "帖子保存")
|
@RestMapping(name = "save", comment = "帖子保存")
|
||||||
public RetResult contentSave(@RestParam(name = "bean")Content content, @RestSessionid String sessionid){
|
public RetResult save(UserInfo user, Content bean) {
|
||||||
//数据校验
|
//数据校验
|
||||||
if (content.getTitle().isEmpty() || content.getTitle().length() > 64){
|
if (bean.getTitle().isEmpty() || bean.getTitle().length() > 64) {
|
||||||
return RetCodes.retResult(-1, "少年你的文章标题太长啦,精简化标题吧,为了更好的SEO长度请少于64个字节");
|
return RetCodes.retResult(-1, "少年你的文章标题太长啦,精简化标题吧,为了更好的SEO长度请少于64个字节");
|
||||||
}
|
}
|
||||||
|
|
||||||
int userid = currentUserid(sessionid);
|
int userid = user.getUserid();
|
||||||
|
|
||||||
if (content.getContentid() < 1){
|
if (bean.getContentid() < 1) {
|
||||||
int maxId = source.getNumberResult(Content.class, FilterFunc.MAX, 10_0000, "contentid").intValue();
|
int maxId = source.getNumberResult(Content.class, FilterFunc.MAX, 10_0000, "contentid").intValue();
|
||||||
content.setContentid(maxId+1);
|
bean.setContentid(maxId + 1);
|
||||||
content.setCreatetime(System.currentTimeMillis());
|
bean.setCreatetime(System.currentTimeMillis());
|
||||||
content.setUserid(userid);
|
bean.setUserid(userid);
|
||||||
|
|
||||||
source.insert(content);
|
source.insert(bean);
|
||||||
}else {
|
} else {
|
||||||
source.findAsync(Content.class, content.getContentid()).thenAccept(x->{
|
source.findAsync(Content.class, bean.getContentid()).thenAccept(x -> {
|
||||||
if (x.getUserid() == userid || userService.isAdmin(userid)){//身份验证 后修改内容
|
if (x.getUserid() == userid || userService.isAdmin(userid)) {//身份验证 后修改内容
|
||||||
source.updateColumnAsync(content,SelectColumn.includes("title", "digest", "content","type", "status"));
|
source.updateColumnAsync(bean, SelectColumn.includes("title", "digest", "content", "type", "status"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -88,8 +104,8 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "info", auth = false, comment = "帖子详情")
|
@RestMapping(name = "info", auth = false, comment = "帖子详情")
|
||||||
public ContentInfo contentInfo(@RestSessionid String sessionid, int contentid){
|
public ContentInfo info(UserInfo user, int contentid) {
|
||||||
int userId = userService.currentUserid(sessionid);
|
int userId = user != null ? user.getUserid() : 0;
|
||||||
|
|
||||||
Content content = source.find(Content.class, contentid);
|
Content content = source.find(Content.class, contentid);
|
||||||
if (content == null) return null;
|
if (content == null) return null;
|
||||||
@@ -97,7 +113,7 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
|||||||
ContentInfo contentInfo = setIUser(content.createInfo());
|
ContentInfo contentInfo = setIUser(content.createInfo());
|
||||||
|
|
||||||
//收藏状态
|
//收藏状态
|
||||||
if (userId > 0){
|
if (userId > 0) {
|
||||||
ActLog actLog = source.find(ActLog.class, FilterNode.create("cate", 20).and("tid", contentid).and("status", 10));
|
ActLog actLog = source.find(ActLog.class, FilterNode.create("cate", 20).and("tid", contentid).and("status", 10));
|
||||||
if (actLog != null) contentInfo.setHadcollect(1);
|
if (actLog != null) contentInfo.setHadcollect(1);
|
||||||
}
|
}
|
||||||
@@ -105,19 +121,19 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "collect", comment = "帖子收藏")
|
@RestMapping(name = "collect", comment = "帖子收藏")
|
||||||
public RetResult collect(@RestSessionid String sessionid, int contentid, int ok){
|
public RetResult collect(@RestSessionid String sessionid, int contentid, int ok) {
|
||||||
int userid = userService.currentUserid(sessionid);//不会为空
|
int userid = userService.currentUserid(sessionid);//不会为空
|
||||||
|
|
||||||
ActLog actLog = source.find(ActLog.class, FilterNode.create("userid", userid).and("tid", contentid).and("cate", 20));
|
ActLog actLog = source.find(ActLog.class, FilterNode.create("userid", userid).and("tid", contentid).and("cate", 20));
|
||||||
if (actLog == null && ok == 1){
|
if (actLog == null && ok == 1) {
|
||||||
actLog = new ActLog(20, contentid, userid);//.cate(2).tid(contentId).userId(userId);
|
actLog = new ActLog(20, contentid, userid);//.cate(2).tid(contentId).userId(userId);
|
||||||
actLog.setCreatetime(System.currentTimeMillis());
|
actLog.setCreatetime(System.currentTimeMillis());
|
||||||
source.insert(actLog);
|
source.insert(actLog);
|
||||||
}else if (actLog != null && actLog.getStatus() != ok){
|
} else if (actLog != null && actLog.getStatus() != ok) {
|
||||||
actLog.setStatus((short) ok);
|
actLog.setStatus((short) ok);
|
||||||
actLog.setCreatetime(System.currentTimeMillis());
|
actLog.setCreatetime(System.currentTimeMillis());
|
||||||
source.update(actLog);
|
source.update(actLog);
|
||||||
}else {
|
} else {
|
||||||
return RetCodes.retResult(-1, ok == 1 ? "已收藏" : "已取消收藏");
|
return RetCodes.retResult(-1, ok == 1 ? "已收藏" : "已取消收藏");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +141,7 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "collectquery", comment = "收藏列表")
|
@RestMapping(name = "collectquery", comment = "收藏列表")
|
||||||
public Sheet<ContentInfo> collectQuery(@RestSessionid String sessionid){
|
public Sheet<ContentInfo> collectQuery(@RestSessionid String sessionid) {
|
||||||
int userid = currentUserid(sessionid);
|
int userid = currentUserid(sessionid);
|
||||||
|
|
||||||
Flipper flipper = new Flipper().sort("createtime DESC");
|
Flipper flipper = new Flipper().sort("createtime DESC");
|
||||||
@@ -144,24 +160,24 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
|||||||
public RetResult contentSet(@RestSessionid String sessionid,
|
public RetResult contentSet(@RestSessionid String sessionid,
|
||||||
@Comment("帖子id") int id,
|
@Comment("帖子id") int id,
|
||||||
@Comment("status|top|wonderful") String field,
|
@Comment("status|top|wonderful") String field,
|
||||||
@Comment("目标修改值")short v){
|
@Comment("目标修改值") short v) {
|
||||||
//只有管理员可访问
|
//只有管理员可访问
|
||||||
int userid = currentUserid(sessionid);
|
int userid = currentUserid(sessionid);
|
||||||
//身份验证 后修改内容
|
//身份验证 后修改内容
|
||||||
source.findAsync(Content.class, id).thenAccept(content -> {
|
source.findAsync(Content.class, id).thenAccept(content -> {
|
||||||
if (content.getUserid() == userid && userService.isAdmin(userid)){//管理员可以做更多
|
if (content.getUserid() == userid && userService.isAdmin(userid)) {//管理员可以做更多
|
||||||
//field: status|top|wonderful
|
//field: status|top|wonderful
|
||||||
// update content set {field}={v} where id={id}
|
// update content set {field}={v} where id={id}
|
||||||
source.updateColumn(Content.class, id, field, v);
|
source.updateColumn(Content.class, id, field, v);
|
||||||
}else if (content.getUserid() == userid && ("status".equals(field))){//非管理员只能修改状态
|
} else if (content.getUserid() == userid && ("status".equals(field))) {//非管理员只能修改状态
|
||||||
source.updateColumn(Content.class, id, field, v);
|
source.updateColumn(Content.class, id, field, v);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return RetResult.success();
|
return RetResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "t",auth = false, comment = "测试HttpScope 模板使用")
|
@RestMapping(name = "t", auth = false, comment = "测试HttpScope 模板使用")
|
||||||
public HttpScope t(@RestSessionid String sessionid){
|
public HttpScope t(@RestSessionid String sessionid) {
|
||||||
ContentService contentService = this;
|
ContentService contentService = this;
|
||||||
Flipper flipper = new Flipper().limit(30).sort("top DESC,createtime DESC");
|
Flipper flipper = new Flipper().limit(30).sort("top DESC,createtime DESC");
|
||||||
//置顶贴
|
//置顶贴
|
||||||
@@ -174,7 +190,7 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
|||||||
|
|
||||||
//热议
|
//热议
|
||||||
Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC");
|
Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC");
|
||||||
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", sessionid);
|
Sheet<ContentInfo> hotReply = contentService.query(flipper3, "", sessionid);
|
||||||
|
|
||||||
//最新加入
|
//最新加入
|
||||||
Sheet<UserInfo> lastReg = userService.lastReg();
|
Sheet<UserInfo> lastReg = userService.lastReg();
|
||||||
|
@@ -2,6 +2,7 @@ package net.tccn.bbs.servlet;
|
|||||||
|
|
||||||
import com.jfinal.kit.Kv;
|
import com.jfinal.kit.Kv;
|
||||||
import net.tccn.bbs.base.BaseServlet;
|
import net.tccn.bbs.base.BaseServlet;
|
||||||
|
import net.tccn.bbs.base.user.UserInfo;
|
||||||
import net.tccn.bbs.comment.CommentInfo;
|
import net.tccn.bbs.comment.CommentInfo;
|
||||||
import net.tccn.bbs.content.ContentInfo;
|
import net.tccn.bbs.content.ContentInfo;
|
||||||
import org.redkale.net.http.*;
|
import org.redkale.net.http.*;
|
||||||
@@ -15,16 +16,16 @@ import static org.redkale.source.FilterExpress.NOTEQUAL;
|
|||||||
* 帖子相关
|
* 帖子相关
|
||||||
* Created by liangxianyou at 2018/6/4 13:15.
|
* Created by liangxianyou at 2018/6/4 13:15.
|
||||||
*/
|
*/
|
||||||
@WebServlet(value = {"/jie" ,"/jie/*","/column","/column/*"}, comment = "文章帖子入口")
|
@WebServlet(value = {"/jie", "/jie/*", "/column", "/column/*"}, comment = "文章帖子入口")
|
||||||
public class ContentServlet extends BaseServlet {
|
public class ContentServlet extends BaseServlet {
|
||||||
@HttpMapping(url = "/jie", auth = false, comment = "问答列表")
|
@HttpMapping(url = "/jie", auth = false, comment = "问答列表")
|
||||||
public void jie(HttpRequest request, HttpResponse response){
|
public void jie(HttpRequest request, HttpResponse response) {
|
||||||
String actived = getPara(request, 0, "all");
|
String actived = getPara(request, 0, "all");
|
||||||
int curr = request.getIntParameter("curr", 1);
|
int curr = request.getIntParameter("curr", 1);
|
||||||
|
|
||||||
//分页帖子列表
|
//分页帖子列表
|
||||||
Flipper flipper = new Flipper().offset((curr-1)*15).limit(15).sort("top DESC,createtime DESC");
|
Flipper flipper = new Flipper().offset((curr - 1) * 15).limit(15).sort("top DESC,createtime DESC");
|
||||||
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, actived, request.getSessionid(false));
|
Sheet<ContentInfo> contents = contentService.query(flipper, actived, request.getSessionid(false));
|
||||||
|
|
||||||
Kv kv = Kv.by("contents", contents).set("url", request.getRequestURI())
|
Kv kv = Kv.by("contents", contents).set("url", request.getRequestURI())
|
||||||
.set("actived", actived).set("curr", curr);
|
.set("actived", actived).set("curr", curr);
|
||||||
@@ -34,12 +35,14 @@ public class ContentServlet extends BaseServlet {
|
|||||||
|
|
||||||
@HttpMapping(url = "/jie/add", comment = "发表/编辑问答")
|
@HttpMapping(url = "/jie/add", comment = "发表/编辑问答")
|
||||||
@HttpParam(name = "#", type = int.class, comment = "内容ID")
|
@HttpParam(name = "#", type = int.class, comment = "内容ID")
|
||||||
public void add(HttpRequest request, HttpResponse response){
|
public void add(HttpRequest request, HttpResponse response) {
|
||||||
int contentid = getParaToInt(request, 0);
|
int contentid = getParaToInt(request, 0);
|
||||||
|
String sessionid = request.getSessionid(false);
|
||||||
|
UserInfo user = userService.current(sessionid);
|
||||||
|
|
||||||
ContentInfo contentInfo = null;
|
ContentInfo contentInfo = null;
|
||||||
if (contentid > 0){
|
if (contentid > 0) {
|
||||||
contentInfo = contentService.contentInfo(request.getSessionid(false), contentid);
|
contentInfo = contentService.info(user, contentid);
|
||||||
}
|
}
|
||||||
|
|
||||||
Kv kv = Kv.by("bean", contentInfo);
|
Kv kv = Kv.by("bean", contentInfo);
|
||||||
@@ -47,12 +50,13 @@ public class ContentServlet extends BaseServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@HttpMapping(url = "/jie/detail", auth = false, comment = "问答详情")
|
@HttpMapping(url = "/jie/detail", auth = false, comment = "问答详情")
|
||||||
public void detail(HttpRequest request, HttpResponse response){
|
public void detail(HttpRequest request, HttpResponse response) {
|
||||||
int contentid = getParaToInt(request,0);
|
int contentid = getParaToInt(request, 0);
|
||||||
String sessionid = request.getSessionid(false);
|
String sessionid = request.getSessionid(false);
|
||||||
|
UserInfo user = userService.current(sessionid);
|
||||||
|
|
||||||
ContentInfo content = contentService.contentInfo(sessionid, contentid);
|
ContentInfo content = contentService.info(user, contentid);
|
||||||
Sheet<CommentInfo> comments = commentService.commentQuery(sessionid,contentid, new Flipper().limit(30));
|
Sheet<CommentInfo> comments = commentService.query(sessionid, contentid, new Flipper().limit(30));
|
||||||
|
|
||||||
//热帖
|
//热帖
|
||||||
//Flipper flipper2 = new Flipper().limit(8).sort("viewNum DESC");
|
//Flipper flipper2 = new Flipper().limit(8).sort("viewNum DESC");
|
||||||
@@ -69,7 +73,7 @@ public class ContentServlet extends BaseServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@HttpMapping(url = "/column", auth = false, comment = "帖子栏目")
|
@HttpMapping(url = "/column", auth = false, comment = "帖子栏目")
|
||||||
public void column(HttpRequest request, HttpResponse response){
|
public void column(HttpRequest request, HttpResponse response) {
|
||||||
String sessionid = request.getSessionid(false);
|
String sessionid = request.getSessionid(false);
|
||||||
|
|
||||||
String para = getPara(request);//空,qz,fx,jy,gg,dt,
|
String para = getPara(request);//空,qz,fx,jy,gg,dt,
|
||||||
@@ -79,7 +83,7 @@ public class ContentServlet extends BaseServlet {
|
|||||||
|
|
||||||
Kv column = Kv.by("qz", 10).set("fx", 20).set("jy", 30).set("gg", 40).set("dt", 50);//栏目
|
Kv column = Kv.by("qz", 10).set("fx", 20).set("jy", 30).set("gg", 40).set("dt", 50);//栏目
|
||||||
|
|
||||||
Flipper flipper = new Flipper().offset((curr-1) * 20).limit(20).sort("top DESC,createtime DESC");
|
Flipper flipper = new Flipper().offset((curr - 1) * 20).limit(20).sort("top DESC,createtime DESC");
|
||||||
//帖子列表
|
//帖子列表
|
||||||
FilterNode filterNode = FilterNode.create("status", NOTEQUAL, -10).and("type", column.getAs(para));
|
FilterNode filterNode = FilterNode.create("status", NOTEQUAL, -10).and("type", column.getAs(para));
|
||||||
if (solved > 0) filterNode.and("solved", 20);
|
if (solved > 0) filterNode.and("solved", 20);
|
||||||
|
@@ -14,7 +14,7 @@ import java.util.Map;
|
|||||||
* 文件相关
|
* 文件相关
|
||||||
* Created by liangxianyou at 2018/6/4 13:17.
|
* Created by liangxianyou at 2018/6/4 13:17.
|
||||||
*/
|
*/
|
||||||
@WebServlet(value = {"/upload","/upload/*"}, comment = "文件管理入口")
|
@WebServlet(value = {"/upload", "/upload/*"}, comment = "文件管理入口")
|
||||||
public class FileServlet extends BaseServlet {
|
public class FileServlet extends BaseServlet {
|
||||||
|
|
||||||
private static final String dir = "/var/www/upload/redbbs/";
|
private static final String dir = "/var/www/upload/redbbs/";
|
||||||
@@ -22,7 +22,7 @@ public class FileServlet extends BaseServlet {
|
|||||||
private static final String format = "%1$tY%1$tm%1$td%1$tH%1$tM%1$tS";
|
private static final String format = "%1$tY%1$tm%1$td%1$tH%1$tM%1$tS";
|
||||||
|
|
||||||
@HttpMapping(url = "/upload/img", auth = false, comment = "图片上传")
|
@HttpMapping(url = "/upload/img", auth = false, comment = "图片上传")
|
||||||
public void uploadImg(HttpRequest request, HttpResponse response){
|
public void uploadImg(HttpRequest request, HttpResponse response) {
|
||||||
try {
|
try {
|
||||||
Map ret = new HashMap();
|
Map ret = new HashMap();
|
||||||
ret.put("errno", 0);
|
ret.put("errno", 0);
|
||||||
@@ -32,12 +32,12 @@ public class FileServlet extends BaseServlet {
|
|||||||
String name = part.getName();
|
String name = part.getName();
|
||||||
String suffix = name.substring(name.lastIndexOf("."));
|
String suffix = name.substring(name.lastIndexOf("."));
|
||||||
String path = String.format(format, System.currentTimeMillis()) + suffix;
|
String path = String.format(format, System.currentTimeMillis()) + suffix;
|
||||||
File destFile = new File((winos ? "D:/wk/_own/redbbs/root/tem/" : dir) + path);
|
File destFile = new File((winos ? "E:/wk/own/redbbs/root/tem/" : dir) + path);
|
||||||
destFile.getParentFile().mkdir();
|
destFile.getParentFile().mkdir();
|
||||||
|
|
||||||
part.save(destFile);
|
part.save(destFile);
|
||||||
|
|
||||||
data.add((winos ? "/tem/": view) + path);
|
data.add((winos ? "/tem/" : view) + path);
|
||||||
}
|
}
|
||||||
ret.put("data", data);
|
ret.put("data", data);
|
||||||
|
|
||||||
|
@@ -17,11 +17,11 @@ import static org.redkale.source.FilterExpress.NOTEQUAL;
|
|||||||
/**
|
/**
|
||||||
* Created by Lxy at 2017/11/25 12:31.
|
* Created by Lxy at 2017/11/25 12:31.
|
||||||
*/
|
*/
|
||||||
@WebServlet(value = {"/","/project" /* ,"/article","/article/*" */}, comment = "首页一级菜单入口")
|
@WebServlet(value = {"/", "/project" /* ,"/article","/article/*" */}, comment = "首页一级菜单入口")
|
||||||
public class IndexServlet extends BaseServlet {
|
public class IndexServlet extends BaseServlet {
|
||||||
|
|
||||||
@HttpMapping(url = "/", auth = false, comment = "社区首页")
|
@HttpMapping(url = "/", auth = false, comment = "社区首页")
|
||||||
public void abc(HttpRequest request, HttpResponse response){
|
public void abc(HttpRequest request, HttpResponse response) {
|
||||||
|
|
||||||
String sessionid = request.getSessionid(false);
|
String sessionid = request.getSessionid(false);
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ public class IndexServlet extends BaseServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@HttpMapping(url = "/site", auth = false, comment = "网站首页")
|
@HttpMapping(url = "/site", auth = false, comment = "网站首页")
|
||||||
public void site(HttpRequest request, HttpResponse response){
|
public void site(HttpRequest request, HttpResponse response) {
|
||||||
|
|
||||||
response.finish(HttpScope.refer("/site.html"));
|
response.finish(HttpScope.refer("/site.html"));
|
||||||
}
|
}
|
||||||
@@ -69,12 +69,13 @@ public class IndexServlet extends BaseServlet {
|
|||||||
|
|
||||||
//====================================项目相关====================================
|
//====================================项目相关====================================
|
||||||
@HttpMapping(url = "/project", auth = false, comment = "项目首页")
|
@HttpMapping(url = "/project", auth = false, comment = "项目首页")
|
||||||
public void project(HttpRequest request, HttpResponse response){
|
public void project(HttpRequest request, HttpResponse response) {
|
||||||
String sessionid = request.getSessionid(false);
|
String sessionid = request.getSessionid(false);
|
||||||
|
UserInfo user = userService.current(sessionid);
|
||||||
int contentid = 22;
|
int contentid = 22;
|
||||||
|
|
||||||
ContentInfo content = contentService.contentInfo(sessionid, contentid);
|
ContentInfo content = contentService.info(user, contentid);
|
||||||
Sheet<CommentInfo> comments = commentService.commentQuery(sessionid,contentid, new Flipper().limit(30));
|
Sheet<CommentInfo> comments = commentService.query(sessionid, contentid, new Flipper().limit(30));
|
||||||
|
|
||||||
Kv kv = Kv.by("bean", content).set("comments", comments);
|
Kv kv = Kv.by("bean", content).set("comments", comments);
|
||||||
response.finish(HttpScope.refer("/project/index.html").attr(kv));
|
response.finish(HttpScope.refer("/project/index.html").attr(kv));
|
||||||
|
@@ -22,12 +22,13 @@ public class UserServlet extends BaseServlet {
|
|||||||
|
|
||||||
|
|
||||||
@HttpMapping(url = "/user/login", auth = false, comment = "前往登录页")
|
@HttpMapping(url = "/user/login", auth = false, comment = "前往登录页")
|
||||||
public void login(HttpRequest request, HttpResponse response){
|
public void login(HttpRequest request, HttpResponse response) {
|
||||||
|
|
||||||
response.finish(HttpScope.refer("/user/login.html"));
|
response.finish(HttpScope.refer("/user/login.html"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@HttpMapping(url = "/user/reg", auth = false, comment = "前往登录页")
|
@HttpMapping(url = "/user/reg", auth = false, comment = "前往登录页")
|
||||||
public void reg(HttpRequest request, HttpResponse response){
|
public void reg(HttpRequest request, HttpResponse response) {
|
||||||
/*List<Kv> list = new ArrayList<>();
|
/*List<Kv> list = new ArrayList<>();
|
||||||
list.add(Kv.by("k", 1).set("a", "1+1=?").set("q", 2));
|
list.add(Kv.by("k", 1).set("a", "1+1=?").set("q", 2));
|
||||||
list.add(Kv.by("k", 2).set("a", "1*1=?").set("q", 1));
|
list.add(Kv.by("k", 2).set("a", "1*1=?").set("q", 1));
|
||||||
@@ -38,19 +39,19 @@ public class UserServlet extends BaseServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@HttpMapping(url = "/user/set", auth = true, comment = "用户设置")
|
@HttpMapping(url = "/user/set", auth = true, comment = "用户设置")
|
||||||
public void set(HttpRequest request, HttpResponse response){
|
public void set(HttpRequest request, HttpResponse response) {
|
||||||
response.finish(HttpScope.refer("/user/set.html"));
|
response.finish(HttpScope.refer("/user/set.html"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@HttpMapping(url = "/user", auth = false, comment = "用户首页")
|
@HttpMapping(url = "/user", auth = false, comment = "用户首页")
|
||||||
public void user(HttpRequest request, HttpResponse response){
|
public void user(HttpRequest request, HttpResponse response) {
|
||||||
String para = getPara(request);
|
String para = getPara(request);
|
||||||
|
|
||||||
//-------个人中心---------
|
//-------个人中心---------
|
||||||
if ("user".equals(para) || "".equals(para)){
|
if ("user".equals(para) || "".equals(para)) {
|
||||||
UserInfo user = request.currentUser();
|
UserInfo user = request.currentUser();
|
||||||
if (user == null){
|
if (user == null) {
|
||||||
response.finish(HttpScope.refer("/user/login.html"));
|
response.finish(HttpScope.refer("/user/login.html"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -71,25 +72,25 @@ public class UserServlet extends BaseServlet {
|
|||||||
|
|
||||||
//-------用户主页------
|
//-------用户主页------
|
||||||
int userid = 0;
|
int userid = 0;
|
||||||
if ("nick".equals(para)){//通过@ 点击跳转
|
if ("nick".equals(para)) {//通过@ 点击跳转
|
||||||
String nickname = request.getParameter("nickname");
|
String nickname = request.getParameter("nickname");
|
||||||
UserBean userBean = new UserBean();
|
UserBean userBean = new UserBean();
|
||||||
userBean.setNickname(nickname);
|
userBean.setNickname(nickname);
|
||||||
Sheet<UserRecord> users = userService.queryUser(new Flipper().limit(1), userBean);
|
Sheet<UserRecord> users = userService.query(new Flipper().limit(1), userBean);
|
||||||
if (users.getTotal() > 0){
|
if (users.getTotal() > 0) {
|
||||||
userid = users.stream().findFirst().orElse(null).getUserid();
|
userid = users.stream().findFirst().orElse(null).getUserid();
|
||||||
}
|
}
|
||||||
}else {//直接访问
|
} else {//直接访问
|
||||||
userid = getParaToInt(request,0);
|
userid = getParaToInt(request, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//用户信息
|
//用户信息
|
||||||
UserInfo user = userService.findUserInfo(userid);
|
UserInfo user = userService.find(userid);
|
||||||
|
|
||||||
//帖子
|
//帖子
|
||||||
Flipper flipper = new Flipper().limit(8).sort("createtime DESC");
|
Flipper flipper = new Flipper().limit(8).sort("createtime DESC");
|
||||||
FilterNode node = FilterNode.create("userid", userid).and("status", FilterExpress.NOTEQUAL, -10);
|
FilterNode node = FilterNode.create("userid", userid).and("status", FilterExpress.NOTEQUAL, -10);
|
||||||
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(request,node));
|
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(request, node));
|
||||||
|
|
||||||
//回复
|
//回复
|
||||||
Sheet<CommentInfo> comments = commentService.queryByUserid(userid);
|
Sheet<CommentInfo> comments = commentService.queryByUserid(userid);
|
||||||
|
@@ -14,7 +14,6 @@ import java.util.Random;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Created by liangxianyou at 2018/7/8 22:51.
|
* Created by liangxianyou at 2018/7/8 22:51.
|
||||||
*/
|
*/
|
||||||
@RestWebSocket(name = "chat", catalog = "ws", comment = "文字聊天", anyuser = true)
|
@RestWebSocket(name = "chat", catalog = "ws", comment = "文字聊天", anyuser = true)
|
||||||
@@ -41,32 +40,32 @@ public class ChatWebSocket extends WebSocket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture createUserid() {
|
public CompletableFuture createUserid() {
|
||||||
return CompletableFuture.supplyAsync(()-> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
int userid = 0;
|
int userid = 0;
|
||||||
|
|
||||||
//fixme: 1、isyk => tour; 2、set cate to user global
|
//fixme: 1、isyk => tour; 2、set cate to user global
|
||||||
if (getAttribute("isyk") == null){//tour
|
if (getAttribute("isyk") == null) {//tour
|
||||||
userid = imFriendService.currentUserid(getSessionid());
|
userid = imFriendService.currentUserid(getSessionid());
|
||||||
setAttribute("isyk", true);
|
setAttribute("isyk", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//如果未获取登录信息,使用token.hashCode 负值 作为登录用户
|
//如果未获取登录信息,使用token.hashCode 负值 作为登录用户
|
||||||
if (userid == 0){
|
if (userid == 0) {
|
||||||
//MsgInfo msgInfo = new MsgInfo();
|
//MsgInfo msgInfo = new MsgInfo();
|
||||||
userid = - Math.abs(getSessionid().hashCode());
|
userid = -Math.abs(getSessionid().hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
//接收离线信息
|
//接收离线信息
|
||||||
int finalUserid = userid;
|
int finalUserid = userid;
|
||||||
CompletableFuture.runAsync(()->{
|
CompletableFuture.runAsync(() -> {
|
||||||
JBean<List<MsgRecord>> list = chatService.offlineMsg(finalUserid);
|
JBean<List<MsgRecord>> list = chatService.offlineMsg(finalUserid);
|
||||||
List<net.tccn.redim.entity.MsgRecord> recordList = list.getResult();
|
List<net.tccn.redim.entity.MsgRecord> recordList = list.getResult();
|
||||||
|
|
||||||
if (recordList != null && recordList.size() > 0){
|
if (recordList != null && recordList.size() > 0) {
|
||||||
recordList.forEach(msgRecord->{
|
recordList.forEach(msgRecord -> {
|
||||||
JBean<net.tccn.redim.info.MsgInfo> msgInfo = chatService.createMsgInfo(msgRecord);
|
JBean<net.tccn.redim.info.MsgInfo> msgInfo = chatService.createMsgInfo(msgRecord);
|
||||||
send(msgInfo.getResult()).thenAccept(x->{
|
send(msgInfo.getResult()).thenAccept(x -> {
|
||||||
if ((Integer)x == 0){//发送成功
|
if ((Integer) x == 0) {//发送成功
|
||||||
msgRecord.setStatus((short) 20);
|
msgRecord.setStatus((short) 20);
|
||||||
}
|
}
|
||||||
chatService.update(msgRecord);
|
chatService.update(msgRecord);
|
||||||
@@ -90,8 +89,8 @@ public class ChatWebSocket extends WebSocket {
|
|||||||
|
|
||||||
JBean<MsgInfo> msgInfo = chatService.createMsgInfo(msg);
|
JBean<MsgInfo> msgInfo = chatService.createMsgInfo(msg);
|
||||||
|
|
||||||
sendMessage(msgInfo.getResult(), msg.getTouserid()).thenAccept(x->{
|
sendMessage(msgInfo.getResult(), msg.getTouserid()).thenAccept(x -> {
|
||||||
if ((Integer)x == 0){//发送成功
|
if ((Integer) x == 0) {//发送成功
|
||||||
msg.setStatus((short) 20);
|
msg.setStatus((short) 20);
|
||||||
}
|
}
|
||||||
chatService.insert(msg);
|
chatService.insert(msg);
|
||||||
|
@@ -5,15 +5,13 @@ import org.redkale.convert.json.JsonConvert;
|
|||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author lxyer
|
* @author lxyer
|
||||||
*/
|
*/
|
||||||
@Cacheable(interval = 5*60)
|
@Cacheable(interval = 5 * 60)
|
||||||
@Table(catalog = "redbbs", name = "im_msgrecord", comment = "[聊天记录表]")
|
@Table(catalog = "redbbs", name = "im_msgrecord", comment = "[聊天记录表]")
|
||||||
public class MsgRecord implements java.io.Serializable {
|
public class MsgRecord implements java.io.Serializable {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
|
||||||
@Column(comment = "[主键id]")
|
@Column(comment = "[主键id]")
|
||||||
private int msgid;
|
private int msgid;
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ResourceType(net.tccn.redim.service.ImFriendService.class)
|
@ResourceType(net.tccn.redim.service.ImFriendService.class)
|
||||||
@RestService(name = "imfriend",automapping = true, comment = "好友管理")
|
@RestService(name = "imfriend", automapping = true, comment = "好友管理")
|
||||||
public class ImFriendServiceImpl extends BaseService implements ImFriendService {
|
public class ImFriendServiceImpl extends BaseService implements ImFriendService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@@ -39,9 +39,9 @@ public class ImFriendServiceImpl extends BaseService implements ImFriendService
|
|||||||
Kv data = Kv.create();
|
Kv data = Kv.create();
|
||||||
|
|
||||||
//mine
|
//mine
|
||||||
Kv mine = Kv.by("username", "游客").set("id", "0").set("sign","").set("status", "online").set("avatar", "/res/images/avatar/13.jpg");
|
Kv mine = Kv.by("username", "游客").set("id", "0").set("sign", "").set("status", "online").set("avatar", "/res/images/avatar/13.jpg");
|
||||||
UserInfo userInfo = userService.current(sessionid);
|
UserInfo userInfo = userService.current(sessionid);
|
||||||
if (userInfo != null){
|
if (userInfo != null) {
|
||||||
mine.set("username", userInfo.getNickname());
|
mine.set("username", userInfo.getNickname());
|
||||||
mine.set("id", userInfo.getUserid());
|
mine.set("id", userInfo.getUserid());
|
||||||
mine.set("sign", userInfo.getSign());
|
mine.set("sign", userInfo.getSign());
|
||||||
@@ -54,7 +54,7 @@ public class ImFriendServiceImpl extends BaseService implements ImFriendService
|
|||||||
List<Kv> group = new ArrayList<>();
|
List<Kv> group = new ArrayList<>();
|
||||||
|
|
||||||
List<Kv> list = new ArrayList();
|
List<Kv> list = new ArrayList();
|
||||||
records.forEach(x->{
|
records.forEach(x -> {
|
||||||
Kv _friend = Kv.by("id", x.getUserid());
|
Kv _friend = Kv.by("id", x.getUserid());
|
||||||
_friend.set("username", x.getNickname());
|
_friend.set("username", x.getNickname());
|
||||||
_friend.set("sign", x.getSign());
|
_friend.set("sign", x.getSign());
|
||||||
@@ -92,7 +92,6 @@ public class ImFriendServiceImpl extends BaseService implements ImFriendService
|
|||||||
//sncpTransportFactory.addGroupInfo(groupInfo);
|
//sncpTransportFactory.addGroupInfo(groupInfo);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return friends(sessionid);
|
return friends(sessionid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@ import java.util.List;
|
|||||||
* @author: liangxianyou at 2018/8/12 13:10.
|
* @author: liangxianyou at 2018/8/12 13:10.
|
||||||
*/
|
*/
|
||||||
@ResourceType(net.tccn.redim.service.ImMsgService.class)
|
@ResourceType(net.tccn.redim.service.ImMsgService.class)
|
||||||
@RestService(name = "immsg",automapping = true, comment = "聊天记录管理")
|
@RestService(name = "immsg", automapping = true, comment = "聊天记录管理")
|
||||||
public class ImMsgServiceImpl extends BaseService implements ImMsgService {
|
public class ImMsgServiceImpl extends BaseService implements ImMsgService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,7 +36,7 @@ public class ImMsgServiceImpl extends BaseService implements ImMsgService {
|
|||||||
* @param msg
|
* @param msg
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public JBean update(MsgRecord ... msg) {
|
public JBean update(MsgRecord... msg) {
|
||||||
source.updateAsync(msg);
|
source.updateAsync(msg);
|
||||||
return JBean.ok();
|
return JBean.ok();
|
||||||
}
|
}
|
||||||
@@ -62,12 +62,12 @@ public class ImMsgServiceImpl extends BaseService implements ImMsgService {
|
|||||||
int fromuserid = msg.getFromuserid();
|
int fromuserid = msg.getFromuserid();
|
||||||
|
|
||||||
UserRecord userRecord;
|
UserRecord userRecord;
|
||||||
if (fromuserid > 0){
|
if (fromuserid > 0) {
|
||||||
userRecord = source.find(UserRecord.class, fromuserid);
|
userRecord = source.find(UserRecord.class, fromuserid);
|
||||||
info.setUsername(userRecord.getUsername());
|
info.setUsername(userRecord.getUsername());
|
||||||
info.setAvatar(userRecord.getAvatar());
|
info.setAvatar(userRecord.getAvatar());
|
||||||
info.setType("friend");
|
info.setType("friend");
|
||||||
}else {
|
} else {
|
||||||
info.setUsername("游客");
|
info.setUsername("游客");
|
||||||
info.setAvatar("/res/images/avatar/12.jpg");
|
info.setAvatar("/res/images/avatar/12.jpg");
|
||||||
info.setType("friend");
|
info.setType("friend");
|
||||||
|
@@ -6,52 +6,64 @@ import org.redkale.service.Service;
|
|||||||
public interface ImFriendService extends Service {
|
public interface ImFriendService extends Service {
|
||||||
|
|
||||||
//================ 查询相关 =================
|
//================ 查询相关 =================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分组好友数据
|
* 分组好友数据
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
JBean friends(String sessionid);
|
JBean friends(String sessionid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据条件查询好友
|
* 根据条件查询好友
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
JBean friendList(String sessionid);
|
JBean friendList(String sessionid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 群组数据
|
* 群组数据
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
JBean groups(String sessionid);
|
JBean groups(String sessionid);
|
||||||
|
|
||||||
|
|
||||||
//================ 操作好友相关 =================
|
//================ 操作好友相关 =================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存好友分组
|
* 保存好友分组
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
JBean itemSave(String sessionid);
|
JBean itemSave(String sessionid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加好友
|
* 添加好友
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
JBean addFriend(String sessionid);
|
JBean addFriend(String sessionid);
|
||||||
|
|
||||||
//================ 操作群组相关 =================
|
//================ 操作群组相关 =================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存群组
|
* 保存群组
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
JBean groupSave(String sessionid);
|
JBean groupSave(String sessionid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加入群组
|
* 加入群组
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
JBean addGroup(String sessionid);
|
JBean addGroup(String sessionid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录人用户id
|
* 登录人用户id
|
||||||
|
*
|
||||||
* @param sessionid
|
* @param sessionid
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@@ -12,6 +12,7 @@ public interface ImMsgService extends Service {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息入库
|
* 消息入库
|
||||||
|
*
|
||||||
* @param msg
|
* @param msg
|
||||||
*/
|
*/
|
||||||
JBean insert(MsgRecord... msg);
|
JBean insert(MsgRecord... msg);
|
||||||
@@ -23,6 +24,7 @@ public interface ImMsgService extends Service {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 历史消息
|
* 历史消息
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
JBean list();
|
JBean list();
|
||||||
@@ -36,6 +38,7 @@ public interface ImMsgService extends Service {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取离线消息
|
* 获取离线消息
|
||||||
|
*
|
||||||
* @param userid
|
* @param userid
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@@ -19,7 +19,7 @@ public class ImServlet extends HttpServlet {
|
|||||||
ImFriendService imFriendService;
|
ImFriendService imFriendService;
|
||||||
|
|
||||||
@HttpMapping(url = "/imx/friends", comment = "测试函数")
|
@HttpMapping(url = "/imx/friends", comment = "测试函数")
|
||||||
public void abc(HttpRequest request, HttpResponse response){
|
public void abc(HttpRequest request, HttpResponse response) {
|
||||||
|
|
||||||
String token = request.getParameter("token");
|
String token = request.getParameter("token");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user