This commit is contained in:
heavyrian2012
2022-08-14 22:08:35 +08:00
parent b0fe1636a7
commit 3c1c5ce6d3
8 changed files with 3407 additions and 231 deletions
+1
View File
@@ -0,0 +1 @@
alter table `t_channel` add column `_menu` BLOB DEFAULT NULL;
+1
View File
@@ -0,0 +1 @@
alter table `t_channel` add column `_menu` BLOB DEFAULT NULL;
@@ -2972,7 +2972,8 @@ public class DatabaseStore {
", `_secret`" + ", `_secret`" +
", `_callback`" + ", `_callback`" +
", `_automatic`" + ", `_automatic`" +
", `_dt`) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" + ", `_menu`" +
", `_dt`) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" +
" ON DUPLICATE KEY UPDATE `_name`=?" + " ON DUPLICATE KEY UPDATE `_name`=?" +
", `_portrait`=?" + ", `_portrait`=?" +
", `_owner`=?" + ", `_owner`=?" +
@@ -2982,12 +2983,20 @@ public class DatabaseStore {
", `_secret`=?" + ", `_secret`=?" +
", `_callback`=?" + ", `_callback`=?" +
", `_automatic`=?" + ", `_automatic`=?" +
", `_menu`=?" +
", `_dt`=?"; ", `_dt`=?";
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
int index = 1; WFCMessage.ChannelMenuList.Builder builder = WFCMessage.ChannelMenuList.newBuilder();
if (!channelInfo.getMenuList().isEmpty()) {
for (WFCMessage.ChannelMenu menuBtn:channelInfo.getMenuList()) {
builder.addMenu(menuBtn);
}
}
byte[] menuBytes = builder.build().toByteArray();
int index = 1;
statement.setString(index++, channelInfo.getTargetId()); statement.setString(index++, channelInfo.getTargetId());
statement.setString(index++, channelInfo.getName()); statement.setString(index++, channelInfo.getName());
statement.setString(index++, channelInfo.getPortrait()); statement.setString(index++, channelInfo.getPortrait());
@@ -2998,6 +3007,7 @@ public class DatabaseStore {
statement.setString(index++, channelInfo.getSecret()); statement.setString(index++, channelInfo.getSecret());
statement.setString(index++, channelInfo.getCallback()); statement.setString(index++, channelInfo.getCallback());
statement.setInt(index++, channelInfo.getAutomatic()); statement.setInt(index++, channelInfo.getAutomatic());
statement.setBytes(index++, menuBytes);
statement.setLong(index++, channelInfo.getUpdateDt() == 0 ? System.currentTimeMillis() : channelInfo.getUpdateDt()); statement.setLong(index++, channelInfo.getUpdateDt() == 0 ? System.currentTimeMillis() : channelInfo.getUpdateDt());
statement.setString(index++, channelInfo.getName()); statement.setString(index++, channelInfo.getName());
@@ -3009,6 +3019,7 @@ public class DatabaseStore {
statement.setString(index++, channelInfo.getSecret()); statement.setString(index++, channelInfo.getSecret());
statement.setString(index++, channelInfo.getCallback()); statement.setString(index++, channelInfo.getCallback());
statement.setInt(index++, channelInfo.getAutomatic()); statement.setInt(index++, channelInfo.getAutomatic());
statement.setBytes(index++, menuBytes);
statement.setLong(index++, channelInfo.getUpdateDt() == 0 ? System.currentTimeMillis() : channelInfo.getUpdateDt()); statement.setLong(index++, channelInfo.getUpdateDt() == 0 ? System.currentTimeMillis() : channelInfo.getUpdateDt());
int count = statement.executeUpdate(); int count = statement.executeUpdate();
@@ -3061,6 +3072,7 @@ public class DatabaseStore {
", `_secret`" + ", `_secret`" +
", `_callback`" + ", `_callback`" +
", `_automatic`" + ", `_automatic`" +
", `_menu`" +
", `_dt` from t_channel where `_cid` = ?"; ", `_dt` from t_channel where `_cid` = ?";
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
@@ -3111,6 +3123,21 @@ public class DatabaseStore {
intValue = rs.getInt(index++); intValue = rs.getInt(index++);
builder.setAutomatic(intValue); builder.setAutomatic(intValue);
try {
byte[] bytes = null;
Blob blob = rs.getBlob(index++);
if (blob != null) {
bytes = toByteArray(blob.getBinaryStream());
}
WFCMessage.ChannelMenuList menuButtonList = WFCMessage.ChannelMenuList.parseFrom(bytes);
if (menuButtonList.getMenuCount() > 0) {
builder.addAllMenu(menuButtonList.getMenuList());
}
} catch (IOException e) {
e.printStackTrace();
}
long longValue = rs.getLong(index++); long longValue = rs.getLong(index++);
builder.setUpdateDt(longValue); builder.setUpdateDt(longValue);
@@ -3888,9 +3888,15 @@ public class MemoryMessagesStore implements IMessagesStore {
e.printStackTrace(); e.printStackTrace();
Utility.printExecption(LOG, e); Utility.printExecption(LOG, e);
} }
} else if(modifyType == Modify_Channel_Menu) {
OutputGetChannelInfo.OutputMenuList outputMenuButtons = new Gson().fromJson(value, OutputGetChannelInfo.OutputMenuList.class);
if (!outputMenuButtons.isEmpty()) {
for (OutputGetChannelInfo.OutputMenu outputMenuButton : outputMenuButtons) {
newInfoBuilder.addMenu(outputMenuButton.toPbInfo());
}
}
} }
newInfoBuilder.setUpdateDt(System.currentTimeMillis()); newInfoBuilder.setUpdateDt(System.currentTimeMillis());
mIMap.put(channelId, newInfoBuilder.build()); mIMap.put(channelId, newInfoBuilder.build());
callbackChannelInfoUpdateEvent(operator, channelId, Channel_Event_Update); callbackChannelInfoUpdateEvent(operator, channelId, Channel_Event_Update);
@@ -10,8 +10,63 @@ package cn.wildfirechat.pojos;
import cn.wildfirechat.proto.WFCMessage; import cn.wildfirechat.proto.WFCMessage;
import io.netty.util.internal.StringUtil;
import java.util.ArrayList;
import java.util.List;
public class OutputGetChannelInfo { public class OutputGetChannelInfo {
public static class OutputMenu {
public String type;
public String name;
public String key;
public String url;
public String mediaId;
public String articleId;
public String appId;
public String appPage;
public List<OutputMenu> subMenus;
public static OutputMenu fromPbInfo(WFCMessage.ChannelMenu channelMenuMenu) {
OutputMenu out = new OutputMenu();
out.type = channelMenuMenu.getType();
out.name = channelMenuMenu.getName();
out.key = channelMenuMenu.getKey();
out.url = channelMenuMenu.getUrl();
out.mediaId = channelMenuMenu.getMediaId();
out.articleId = channelMenuMenu.getArticleId();
out.appId = channelMenuMenu.getAppId();
out.appPage = channelMenuMenu.getAppPage();
if (channelMenuMenu.getSubMenuCount() > 0) {
out.subMenus = new ArrayList<>();
for (WFCMessage.ChannelMenu menuMenu : channelMenuMenu.getSubMenuList()) {
out.subMenus.add(fromPbInfo(menuMenu));
}
}
return out;
}
public WFCMessage.ChannelMenu.Builder toPbInfo() {
WFCMessage.ChannelMenu.Builder builder = WFCMessage.ChannelMenu.newBuilder();
builder.setType(type);
builder.setName(name);
if (!StringUtil.isNullOrEmpty(key)) builder.setKey(key);
if (!StringUtil.isNullOrEmpty(url)) builder.setUrl(url);
if (!StringUtil.isNullOrEmpty(mediaId)) builder.setMediaId(mediaId);
if (!StringUtil.isNullOrEmpty(articleId)) builder.setArticleId(articleId);
if (!StringUtil.isNullOrEmpty(appId)) builder.setAppId(appId);
if (!StringUtil.isNullOrEmpty(appPage)) builder.setAppPage(appPage);
if (subMenus != null && !subMenus.isEmpty()) {
subMenus.forEach(menuMenu -> builder.addSubMenu(menuMenu.toPbInfo()));
}
return builder;
}
}
public static class OutputMenuList extends ArrayList<OutputMenu> {
}
private String channelId; private String channelId;
private String name; private String name;
private String desc; private String desc;
@@ -24,7 +79,7 @@ public class OutputGetChannelInfo {
private String callback; private String callback;
private int automatic; private int automatic;
private String secret; private String secret;
public List<OutputMenu> menus;
public String getChannelId() { public String getChannelId() {
return channelId; return channelId;
@@ -136,6 +191,13 @@ public class OutputGetChannelInfo {
out.status = channelInfo.getStatus();; out.status = channelInfo.getStatus();;
out.updateDt = channelInfo.getUpdateDt(); out.updateDt = channelInfo.getUpdateDt();
out.secret = channelInfo.getSecret(); out.secret = channelInfo.getSecret();
if (channelInfo.getMenuCount() > 0) {
out.menus = new ArrayList<>();
for (WFCMessage.ChannelMenu channelMenuMenu : channelInfo.getMenuList()) {
out.menus.add(OutputMenu.fromPbInfo(channelMenuMenu));
}
}
return out; return out;
} }
} }
@@ -173,6 +173,7 @@ public class ProtoConstants {
int Modify_Channel_Secret = 4; int Modify_Channel_Secret = 4;
int Modify_Channel_Callback = 5; int Modify_Channel_Callback = 5;
int Modify_Channel_OnlyCallback = 6; int Modify_Channel_OnlyCallback = 6;
int Modify_Channel_Menu = 7;
} }
//Channel -> status //Channel -> status
File diff suppressed because it is too large Load Diff
@@ -8,6 +8,7 @@ import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.sdk.model.IMResult; import cn.wildfirechat.sdk.model.IMResult;
import cn.wildfirechat.sdk.utilities.AdminHttpUtils; import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
import cn.wildfirechat.sdk.utilities.RobotHttpUtils; import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
import com.google.gson.Gson;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
@@ -827,8 +828,8 @@ public class Main {
IMResult<OutputGetChannelInfo> resultGetChannel = GeneralAdmin.getChannelInfo(inputCreateChannel.getTargetId()); IMResult<OutputGetChannelInfo> resultGetChannel = GeneralAdmin.getChannelInfo(inputCreateChannel.getTargetId());
if(resultGetChannel != null && resultGetChannel.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS if(resultGetChannel != null && resultGetChannel.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS
&& resultGetChannel.getResult().getName().equals(channelName) && resultGetChannel.getResult().getName().equals(channelName)
&& resultGetChannel.getResult().getOwner().equals(channelOwner)) { && resultGetChannel.getResult().getOwner().equals(channelOwner)) {
System.out.println("success"); System.out.println("success");
} else { } else {
System.out.println("get channel failure"); System.out.println("get channel failure");
@@ -1356,7 +1357,11 @@ public class Main {
inputCreateChannel.setName("testChannel"); inputCreateChannel.setName("testChannel");
inputCreateChannel.setOwner("userId1"); inputCreateChannel.setOwner("userId1");
String secret = "channelsecret"; String secret = "channelsecret";
String channelId = "channelId123";
inputCreateChannel.setSecret(secret); inputCreateChannel.setSecret(secret);
inputCreateChannel.setTargetId(channelId);
inputCreateChannel.setAuto(1);
inputCreateChannel.setCallback("http://192.168.1.81:8088/wf/channelId123");
inputCreateChannel.setState(Channel_State_Mask_FullInfo | Channel_State_Mask_Unsubscribed_User_Access | Channel_State_Mask_Active_Subscribe | Channel_State_Mask_Message_Unsubscribed); inputCreateChannel.setState(Channel_State_Mask_FullInfo | Channel_State_Mask_Unsubscribed_User_Access | Channel_State_Mask_Active_Subscribe | Channel_State_Mask_Message_Unsubscribed);
IMResult<OutputCreateChannel> resultCreateChannel = GeneralAdmin.createChannel(inputCreateChannel); IMResult<OutputCreateChannel> resultCreateChannel = GeneralAdmin.createChannel(inputCreateChannel);
if (resultCreateChannel != null && resultCreateChannel.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { if (resultCreateChannel != null && resultCreateChannel.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
@@ -1368,7 +1373,7 @@ public class Main {
//2. 初始化api,注意端口是80,不是18080 //2. 初始化api,注意端口是80,不是18080
ChannelServiceApi channelServiceApi = new ChannelServiceApi(IMUrl, resultCreateChannel.getResult().getTargetId(), secret); ChannelServiceApi channelServiceApi = new ChannelServiceApi(IMUrl, channelId, secret);
//3. 测试channel api功能 //3. 测试channel api功能
@@ -1450,6 +1455,38 @@ public class Main {
System.exit(-1); System.exit(-1);
} }
List<OutputGetChannelInfo.OutputMenu> menus = new ArrayList<>();
OutputGetChannelInfo.OutputMenu menu1 = new OutputGetChannelInfo.OutputMenu();
menu1.type = "view";
menu1.name = "一级菜单1";
menu1.key = "key1";
menu1.url = "http://www.baidu.com";
menus.add(menu1);
OutputGetChannelInfo.OutputMenu menu2 = new OutputGetChannelInfo.OutputMenu();
menu2.type = "view";
menu2.name = "一级菜单2";
menu2.key = "key2";
menu2.url = "http://www.sohu.com";
menu2.subMenus = new ArrayList<>();
menus.add(menu2);
OutputGetChannelInfo.OutputMenu menu21 = new OutputGetChannelInfo.OutputMenu();
menu21.type = "click";
menu21.name = "二级菜单21";
menu21.key = "key21";
menu21.url = "http://www.sohu.com";
menu2.subMenus.add(menu21);
String menuStr = new Gson().toJson(menus);
voidIMResult = channelServiceApi.modifyChannelInfo(ProtoConstants.ModifyChannelInfoType.Modify_Channel_Menu, menuStr);
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("modify channel menu success");
} else {
System.out.println("modify channel menu failure");
System.exit(-1);
}
IMResult<OutputGetChannelInfo> outputGetChannelInfoIMResult = channelServiceApi.getChannelInfo(); IMResult<OutputGetChannelInfo> outputGetChannelInfoIMResult = channelServiceApi.getChannelInfo();
if (outputGetChannelInfoIMResult != null && outputGetChannelInfoIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { if (outputGetChannelInfoIMResult != null && outputGetChannelInfoIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("get channel info success"); System.out.println("get channel info success");