add system settings
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
|
||||
DROP TABLE IF EXISTS `t_settings`;
|
||||
CREATE TABLE `t_settings` (
|
||||
`id` int(11) NOT NULL PRIMARY KEY,
|
||||
`value` varchar(64) NOT NULL,
|
||||
`desc` varchar(128) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
insert into t_settings(`id`, `value`,`desc`) values (1, '3000', '最大群成员数量');
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
|
||||
DROP TABLE IF EXISTS `t_settings`;
|
||||
CREATE TABLE `t_settings` (
|
||||
`id` int(11) NOT NULL PRIMARY KEY,
|
||||
`value` varchar(64) NOT NULL,
|
||||
`desc` varchar(128) NOT NULL default ""
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = utf8mb4
|
||||
COLLATE = utf8mb4_unicode_ci;
|
||||
|
||||
|
||||
insert into t_settings(`id`, `value`,`desc`) values (1, "3000", "最大群成员数量");
|
||||
+1
-1
@@ -147,7 +147,7 @@
|
||||
<dependency>
|
||||
<groupId>com.mchange</groupId>
|
||||
<artifactId>c3p0</artifactId>
|
||||
<version>[0.9.5.3,)</version>
|
||||
<version>0.9.5.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- needs extra dependencies: objenesis & hamcrest -->
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package com.xiaoleilu.loServer.action.admin;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.InputGetUserInfo;
|
||||
import cn.wildfirechat.pojos.InputOutputUserInfo;
|
||||
import cn.wildfirechat.pojos.SystemSettingPojo;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.google.gson.Gson;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||
import com.xiaoleilu.loServer.annotation.Route;
|
||||
import com.xiaoleilu.loServer.handler.Request;
|
||||
import com.xiaoleilu.loServer.handler.Response;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
@Route(APIPath.Get_System_Setting)
|
||||
@HttpMethod("POST")
|
||||
public class GetSystemSettingAction extends AdminAction {
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
SystemSettingPojo inputUserId = getRequestBody(request.getNettyRequest(), SystemSettingPojo.class);
|
||||
if (inputUserId != null) {
|
||||
SystemSettingPojo output = messagesStore.getSystemSetting(inputUserId.id);
|
||||
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result;
|
||||
if (output == null) {
|
||||
result = RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_EXIST);
|
||||
} else {
|
||||
result = RestResult.ok(output);
|
||||
}
|
||||
|
||||
response.setContent(new Gson().toJson(result));
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package com.xiaoleilu.loServer.action.admin;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.InputGetUserInfo;
|
||||
import cn.wildfirechat.pojos.InputOutputUserInfo;
|
||||
import cn.wildfirechat.pojos.SystemSettingPojo;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.google.gson.Gson;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||
import com.xiaoleilu.loServer.annotation.Route;
|
||||
import com.xiaoleilu.loServer.handler.Request;
|
||||
import com.xiaoleilu.loServer.handler.Response;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
@Route(APIPath.Put_System_Setting)
|
||||
@HttpMethod("POST")
|
||||
public class PutSystemSettingAction extends AdminAction {
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
SystemSettingPojo inputUserId = getRequestBody(request.getNettyRequest(), SystemSettingPojo.class);
|
||||
if (inputUserId != null
|
||||
&& (!StringUtil.isNullOrEmpty(inputUserId.value) || !StringUtil.isNullOrEmpty(inputUserId.desc))) {
|
||||
|
||||
|
||||
boolean success = messagesStore.updateSystemSetting(inputUserId.id, inputUserId.value, inputUserId.desc);
|
||||
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result;
|
||||
if (!success) {
|
||||
result = RestResult.resultOf(ErrorCode.ERROR_CODE_SERVER_ERROR);
|
||||
} else {
|
||||
result = RestResult.ok();
|
||||
}
|
||||
|
||||
response.setContent(new Gson().toJson(result));
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
package io.moquette.persistence;
|
||||
|
||||
import cn.wildfirechat.pojos.SystemSettingPojo;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import cn.wildfirechat.server.ThreadPoolExecutorWrapper;
|
||||
@@ -76,6 +77,79 @@ public class DatabaseStore {
|
||||
return out;
|
||||
}
|
||||
|
||||
boolean updateSystemSetting(int id, String value, String desc) {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "insert into t_settings " +
|
||||
" (`id`, `value`, `desc`) values(?, ?, ?)" +
|
||||
" ON DUPLICATE KEY UPDATE " +
|
||||
"`value` = ?," +
|
||||
"`desc` = ?";
|
||||
|
||||
|
||||
statement = connection.prepareStatement(sql);
|
||||
int index = 1;
|
||||
statement.setLong(index++, id);
|
||||
statement.setString(index++, value);
|
||||
statement.setString(index++, desc);
|
||||
statement.setString(index++, value);
|
||||
statement.setString(index++, desc);
|
||||
|
||||
int count = statement.executeUpdate();
|
||||
LOG.info("Update rows {}", count);
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SystemSettingPojo getSystemSetting(int id) {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "select `value`, `desc` from t_settings where `id` = ?";
|
||||
|
||||
statement = connection.prepareStatement(sql);
|
||||
int index = 1;
|
||||
statement.setLong(index++, id);
|
||||
|
||||
rs = statement.executeQuery();
|
||||
while (rs.next()) {
|
||||
SystemSettingPojo out = new SystemSettingPojo();
|
||||
index = 1;
|
||||
|
||||
out.id = id;
|
||||
|
||||
String value = rs.getString(index++);
|
||||
value = (value == null ? "" : value);
|
||||
out.value = value;
|
||||
|
||||
value = rs.getString(index++);
|
||||
value = (value == null ? "" : value);
|
||||
out.desc = value;
|
||||
|
||||
return out;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement, rs);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
List<WFCMessage.User> searchUserFromDB(String keyword, boolean buzzy, int page) {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.moquette.persistence;
|
||||
|
||||
import cn.wildfirechat.pojos.SystemSettingPojo;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.google.protobuf.ByteString;
|
||||
@@ -1442,6 +1443,16 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return databaseStore.searchUserFromDB(keyword, buzzy, page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateSystemSetting(int id, String value, String desc) {
|
||||
return databaseStore.updateSystemSetting(id, value, desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemSettingPojo getSystemSetting(int id) {
|
||||
return databaseStore.getSystemSetting(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createChatroom(String chatroomId, WFCMessage.ChatroomInfo chatroomInfo) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.moquette.spi;
|
||||
|
||||
import cn.wildfirechat.pojos.SystemSettingPojo;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.xiaoleilu.loServer.model.FriendData;
|
||||
import cn.wildfirechat.pojos.InputOutputUserBlockStatus;
|
||||
@@ -135,6 +136,8 @@ public interface IMessagesStore {
|
||||
WFCMessage.User getUserInfoByMobile(String mobile);
|
||||
List<WFCMessage.User> searchUser(String keyword, boolean buzzy, int page);
|
||||
|
||||
boolean updateSystemSetting(int id, String value, String desc);
|
||||
SystemSettingPojo getSystemSetting(int id);
|
||||
void createChatroom(String chatroomId, WFCMessage.ChatroomInfo chatroomInfo);
|
||||
void destoryChatroom(String chatroomId);
|
||||
WFCMessage.ChatroomInfo getChatroomInfo(String chatroomId);
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<!--MySQL数据库用户名-->
|
||||
<property name="user">root</property>
|
||||
<!--MySQL数据库密码-->
|
||||
<property name="password">123456</property>
|
||||
<property name="password">lt123456</property>
|
||||
<!-- 初始化连接池中的连接数,取值应在minPoolSize与maxPoolSize之间,默认为3-->
|
||||
<property name="initialPoolSize">10</property>
|
||||
<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。默认值: 0 -->
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
public class SystemSettingPojo {
|
||||
public int id;
|
||||
public String value;
|
||||
public String desc;
|
||||
}
|
||||
@@ -35,6 +35,9 @@ public interface APIPath {
|
||||
String Group_Member_Add = "/admin/group/member/add";
|
||||
String Group_Member_Kickoff = "/admin/group/member/del";
|
||||
|
||||
String Get_System_Setting = "/admin/system/get_setting";
|
||||
String Put_System_Setting = "/admin/system/put_setting";
|
||||
|
||||
|
||||
String Channel_Message_Send = "/channel/message/send";
|
||||
|
||||
|
||||
@@ -128,6 +128,9 @@ public class ProtoConstants {
|
||||
}
|
||||
|
||||
|
||||
public interface SystemSettingType {
|
||||
int Group_Max_Member_Count = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package cn.wildfirechat.sdk;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.pojos.InputFriendRequest;
|
||||
import cn.wildfirechat.pojos.InputGetFriendList;
|
||||
import cn.wildfirechat.pojos.SystemSettingPojo;
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
||||
|
||||
public class GeneralAdmin {
|
||||
public static IMResult<SystemSettingPojo> getSystemSetting(int id) throws Exception {
|
||||
String path = APIPath.Get_System_Setting;
|
||||
SystemSettingPojo input = new SystemSettingPojo();
|
||||
input.id = id;
|
||||
return AdminHttpUtils.httpJsonPost(path, input, SystemSettingPojo.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> setSystemSetting(int id, String value, String desc) throws Exception {
|
||||
String path = APIPath.Put_System_Setting;
|
||||
SystemSettingPojo input = new SystemSettingPojo();
|
||||
input.id = id;
|
||||
input.value = value;
|
||||
input.desc = desc;
|
||||
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,8 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.wildfirechat.proto.ProtoConstants.SystemSettingType.Group_Max_Member_Count;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
//初始化服务API
|
||||
@@ -293,6 +295,30 @@ public class Main {
|
||||
}
|
||||
|
||||
|
||||
IMResult<SystemSettingPojo> resultGetSystemSetting = GeneralAdmin.getSystemSetting(Group_Max_Member_Count);
|
||||
if (resultGetSystemSetting != null && resultGetSystemSetting.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("success");
|
||||
} else {
|
||||
System.out.println("get system setting failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<Void> resultSetSystemSetting = GeneralAdmin.setSystemSetting(Group_Max_Member_Count, "2000", "最大群人数为2000");
|
||||
if (resultSetSystemSetting != null && resultSetSystemSetting.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("success");
|
||||
} else {
|
||||
System.out.println("get system setting failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
resultGetSystemSetting = GeneralAdmin.getSystemSetting(Group_Max_Member_Count);
|
||||
if (resultGetSystemSetting != null && resultGetSystemSetting.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultGetSystemSetting.getResult().value.equals("2000")) {
|
||||
System.out.println("success");
|
||||
} else {
|
||||
System.out.println("get system setting failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
//初始化机器人API
|
||||
RobotHttpUtils.init("http://localhost", "robot1", "123456");
|
||||
//***********************************************
|
||||
|
||||
Reference in New Issue
Block a user