diff --git a/conf/persistence.xml b/conf/persistence.xml index d100f00..1b82022 100644 --- a/conf/persistence.xml +++ b/conf/persistence.xml @@ -6,7 +6,10 @@ ALL - + + + + diff --git a/pom.xml b/pom.xml index 7fc4812..2c51595 100644 --- a/pom.xml +++ b/pom.xml @@ -28,12 +28,24 @@ 2.2.0 + + org.redkalex + redkale-plugins + 2.2.0 + + com.mysql mysql-connector-j 8.2.0 + + org.postgresql + postgresql + 42.7.5 + + net.tccn zhub-client-redkale diff --git a/src/com/zchd/base/BaseService.java b/src/com/zchd/base/BaseService.java index 5f5d20a..17a97e0 100644 --- a/src/com/zchd/base/BaseService.java +++ b/src/com/zchd/base/BaseService.java @@ -1,15 +1,20 @@ package com.zchd.base; +import com.zchd.base.util.Utils; import net.tccn.zhub.ZHubClient; import org.redkale.convert.json.JsonConvert; import org.redkale.service.AbstractService; import org.redkale.service.RetResult; +import org.redkale.source.DataJdbcSource; import org.redkale.source.DataSource; +import org.redkale.source.PoolSource; +import org.redkale.util.AnyValue; import org.redkale.util.Sheet; import org.redkalex.cache.redis.MyRedisCacheSource; import javax.annotation.Resource; import java.io.File; +import java.sql.Connection; import java.util.List; import java.util.logging.Logger; @@ -42,6 +47,21 @@ public class BaseService extends AbstractService { @Resource(name = "APP_NAME") protected String APP_NAME = ""; + @Override + public void init(AnyValue config) { + + PoolSource source = ((DataJdbcSource) zimSource).getReadPoolSource(); + // postgresql 设置当前schema + if ("postgresql".equals(source.getDbtype())) { + String url = source.getUrl(); + String schema = getCurrentSchema(url); + if (Utils.isEmpty(schema)) { + schema = "public"; + } + ((DataJdbcSource) zimSource).directExecute(String.format("SET search_path TO %s;", schema)); + } + } + protected RetResult retError(String info) { return new RetResult<>(100, info); } @@ -49,4 +69,21 @@ public class BaseService extends AbstractService { protected RetResult retError(int code, String info) { return new RetResult<>(code, info); } + + /** + * 获取 postgresql url当前schema + * + * @param url + * @return + */ + protected String getCurrentSchema(String url) { + String[] arr = url.split("currentSchema="); + if (arr.length > 1) { + String[] arr2 = arr[1].split("&"); + if (arr2.length > 0) { + return arr2[0]; + } + } + return ""; + } } diff --git a/src/com/zchd/zim/ImAccountService.java b/src/com/zchd/zim/ImAccountService.java index d218b15..7c349ae 100644 --- a/src/com/zchd/zim/ImAccountService.java +++ b/src/com/zchd/zim/ImAccountService.java @@ -42,6 +42,7 @@ public class ImAccountService extends BaseService { @Override public void init(AnyValue config) { + super.init(config); CompletableFuture.runAsync(() -> { List list = zimSource.queryColumnList("userid", ImUser.class, new Flipper(1, "userid DESC"), (FilterBean) null); diff --git a/src/com/zchd/zim/ImChatWebSocket.java b/src/com/zchd/zim/ImChatWebSocket.java index 9ca460b..551e7fb 100644 --- a/src/com/zchd/zim/ImChatWebSocket.java +++ b/src/com/zchd/zim/ImChatWebSocket.java @@ -79,7 +79,7 @@ public class ImChatWebSocket extends WebSocket { final int userid = (int) getUserid(); getLogger().info("im:state-change:" + userid + "---ws connected---"); intCache.setBit("im:user", userid, true); - // 推送离线状态 + // 推送上线状态 zhub.publish("im:online:" + getAttribute("appid"), getAttribute("guserid")); // 上线开启订阅 messageMonitor.online(userid);