parent
35f9524378
commit
0179041a6e
@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.common.constants;
|
||||
|
||||
/**
|
||||
* 字典缓存 常量
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-16 17:42
|
||||
*/
|
||||
public interface DictConstants {
|
||||
|
||||
/** 缓存前缀 NAME */
|
||||
String CACHE_PREFIX_NAME = "dict:name:";
|
||||
|
||||
/** 缓存前缀 VALUE*/
|
||||
String CACHE_PREFIX_VALUE = "dict:value:";
|
||||
|
||||
/** 缓存前缀 LIST*/
|
||||
String CACHE_PREFIX_LIST = "dict:list:";
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package org.opsli.common.constants;
|
||||
|
||||
/**
|
||||
* Redis 常量
|
||||
* {} 为项目名称
|
||||
* @author 周鹏程
|
||||
* @date 2021/12/10 19:52
|
||||
*/
|
||||
public final class RedisConstants {
|
||||
|
||||
|
||||
/** 字典名称 */
|
||||
public static final String PREFIX_DICT_NAME = "hash#{}:dict:name:";
|
||||
|
||||
/** 字典值 VALUE */
|
||||
public static final String PREFIX_DICT_VALUE = "hash#{}:dict:value:";
|
||||
|
||||
/** 菜单编号 */
|
||||
public static final String PREFIX_MENU_CODE = "kv#{}:menu:code:";
|
||||
|
||||
/** 参数编号 */
|
||||
public static final String PREFIX_OPTIONS_CODE = "kv#{}:options:code";
|
||||
|
||||
/** 用户搜索记录 */
|
||||
public static final String PREFIX_HIS_USERNAME = "zset#{}:his:username:";
|
||||
|
||||
private RedisConstants(){}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||
|
||||
/**
|
||||
* 热点数据处理 Entity
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-18 00:01
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CacheDataEntity {
|
||||
|
||||
/** key */
|
||||
private String key;
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.enums;
|
||||
|
||||
/**
|
||||
* 缓存操作类型
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
public enum CacheHandleType {
|
||||
|
||||
/** 更新 */
|
||||
UPDATE,
|
||||
|
||||
/** 删除 */
|
||||
DELETE,
|
||||
|
||||
;
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.enums;
|
||||
|
||||
/**
|
||||
* 缓存操作类型
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
public enum DictModelType {
|
||||
|
||||
/** 对象 */
|
||||
OBJECT,
|
||||
|
||||
/** 集合 */
|
||||
COLLECTION,
|
||||
|
||||
;
|
||||
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.enums;
|
||||
|
||||
/**
|
||||
* 消息具体类型
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
public enum MsgArgsType {
|
||||
|
||||
/** 字典模型 */
|
||||
DICT_MODEL,
|
||||
/** 字典模型-集合 */
|
||||
DICT_MODELS,
|
||||
/** 字典模型-传输类型 */
|
||||
DICT_MODEL_TYPE,
|
||||
/** 字典操作类型 */
|
||||
DICT_TYPE,
|
||||
|
||||
/** 用户ID */
|
||||
USER_ID,
|
||||
/** 用户名 */
|
||||
USER_USERNAME,
|
||||
/** 用户数据类型 */
|
||||
USER_MODEL_TYPE,
|
||||
/** 用户数据*/
|
||||
USER_MODEL_DATA,
|
||||
|
||||
/** 组织 用户ID */
|
||||
ORG_USER_ID,
|
||||
/** 组织 用户数据 */
|
||||
ORG_USER_DATA,
|
||||
|
||||
/** 租户ID */
|
||||
TENANT_ID,
|
||||
/** 租户数据 */
|
||||
TENANT_DATA,
|
||||
|
||||
/** 参数编号 */
|
||||
OPTION_CODE,
|
||||
/** 参数数据*/
|
||||
OPTION_MODEL_DATA,
|
||||
|
||||
/** 缓存数据Key */
|
||||
CACHE_DATA_KEY,
|
||||
/** 缓存数据Value */
|
||||
CACHE_DATA_VALUE,
|
||||
/** 缓存数据Type */
|
||||
CACHE_DATA_TYPE,
|
||||
;
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.enums;
|
||||
|
||||
/**
|
||||
* 发布订阅类型
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
public enum PushSubType {
|
||||
|
||||
/** 字典类型 */
|
||||
DICT,
|
||||
|
||||
/** 用户数据 */
|
||||
USER,
|
||||
|
||||
/** 菜单数据 */
|
||||
MENU,
|
||||
|
||||
/** 组织数据 */
|
||||
ORG,
|
||||
|
||||
/** 租户 */
|
||||
TENANT,
|
||||
|
||||
/** 系统数据 */
|
||||
OPTION,
|
||||
|
||||
/** 热点数据 */
|
||||
HOT_DATA,
|
||||
|
||||
;
|
||||
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.enums;
|
||||
|
||||
/**
|
||||
* 用户缓存操作类型
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
public enum UserModelType {
|
||||
|
||||
/** 用户模型 */
|
||||
USER_MODEL,
|
||||
/** 用户角色集合模型 */
|
||||
USER_ROLES_MODEL,
|
||||
/** 用户权限集合模型 */
|
||||
USER_PERMS_MODEL,
|
||||
/** 用户菜单集合模型 */
|
||||
USER_MENU_MODEL,
|
||||
|
||||
;
|
||||
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.handler;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.opsli.api.wrapper.system.dict.DictWrapper;
|
||||
import org.opsli.common.constants.CacheConstants;
|
||||
import org.opsli.common.constants.DictConstants;
|
||||
import org.opsli.common.enums.CacheType;
|
||||
import org.opsli.core.cache.local.CacheUtil;
|
||||
import org.opsli.core.cache.pushsub.enums.CacheHandleType;
|
||||
import org.opsli.core.cache.pushsub.enums.DictModelType;
|
||||
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
|
||||
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||
import org.opsli.plugins.cache.EhCachePlugin;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典消息处理
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
@Slf4j
|
||||
public class DictHandler implements RedisPushSubHandler{
|
||||
|
||||
@Autowired
|
||||
private EhCachePlugin ehCachePlugin;
|
||||
|
||||
@Override
|
||||
public PushSubType getType() {
|
||||
return PushSubType.DICT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handler(JSONObject msgJson) {
|
||||
DictModelType dictModelType = DictModelType.valueOf((String) msgJson.get(MsgArgsType.DICT_MODEL_TYPE.toString()));
|
||||
CacheHandleType type = CacheHandleType.valueOf((String) msgJson.get(MsgArgsType.DICT_TYPE.toString()));
|
||||
|
||||
if(DictModelType.COLLECTION == dictModelType){
|
||||
Object dictListObj = msgJson.get(MsgArgsType.DICT_MODELS.toString());
|
||||
List<DictWrapper> dictWrappers = Convert.toList(DictWrapper.class, dictListObj);
|
||||
if(CollUtil.isNotEmpty(dictWrappers)){
|
||||
for (DictWrapper dictWrapper : dictWrappers) {
|
||||
this.handler(dictWrapper, type);
|
||||
}
|
||||
}
|
||||
} else if(DictModelType.OBJECT == dictModelType){
|
||||
JSONObject jsonObject = msgJson.getJSONObject(MsgArgsType.DICT_MODEL.toString());
|
||||
if(jsonObject == null){
|
||||
return;
|
||||
}
|
||||
|
||||
DictWrapper dictWrapperModel = jsonObject.toJavaObject(DictWrapper.class);
|
||||
this.handler(dictWrapperModel, type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 真正处理 - 只是处理自己本地的缓存
|
||||
* @param dictWrapperModel model
|
||||
* @param type 类型
|
||||
*/
|
||||
private void handler(DictWrapper dictWrapperModel, CacheHandleType type){
|
||||
|
||||
// 解析 key
|
||||
String ehKeyByName = CacheUtil.handleKey(CacheType.EDEN_HASH, DictConstants.CACHE_PREFIX_NAME +
|
||||
dictWrapperModel.getTypeCode() + ":" + dictWrapperModel.getDictName());
|
||||
String ehKeyByValue = CacheUtil.handleKey(CacheType.EDEN_HASH, DictConstants.CACHE_PREFIX_VALUE +
|
||||
dictWrapperModel.getTypeCode() + ":" + dictWrapperModel.getDictValue());
|
||||
|
||||
// 缓存更新
|
||||
if(CacheHandleType.UPDATE == type){
|
||||
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, ehKeyByName);
|
||||
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, ehKeyByValue);
|
||||
|
||||
// 统一转换为 JSONObject
|
||||
String jsonStr = JSONObject.toJSONString(dictWrapperModel.getModel());
|
||||
JSONObject value = JSONObject.parseObject(jsonStr);
|
||||
ehCachePlugin.put(CacheConstants.EHCACHE_SPACE, ehKeyByName, value);
|
||||
ehCachePlugin.put(CacheConstants.EHCACHE_SPACE, ehKeyByValue, value);
|
||||
}
|
||||
// 缓存删除
|
||||
else if(CacheHandleType.DELETE == type){
|
||||
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, ehKeyByName);
|
||||
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, ehKeyByValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.opsli.common.constants.CacheConstants;
|
||||
import org.opsli.core.cache.local.CacheUtil;
|
||||
import org.opsli.core.cache.pushsub.enums.CacheHandleType;
|
||||
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
|
||||
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||
import org.opsli.plugins.cache.EhCachePlugin;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* 热数据处理
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
@Slf4j
|
||||
public class HotDataHandler implements RedisPushSubHandler{
|
||||
|
||||
@Autowired
|
||||
private EhCachePlugin ehCachePlugin;
|
||||
|
||||
@Override
|
||||
public PushSubType getType() {
|
||||
return PushSubType.HOT_DATA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handler(JSONObject msgJson) {
|
||||
String key = (String) msgJson.get(MsgArgsType.CACHE_DATA_KEY.toString());
|
||||
Object value = msgJson.get(MsgArgsType.CACHE_DATA_VALUE.toString());
|
||||
CacheHandleType type = CacheHandleType.valueOf((String )msgJson.get(MsgArgsType.CACHE_DATA_TYPE.toString()));
|
||||
|
||||
if(StringUtils.isEmpty(key)){
|
||||
return;
|
||||
}
|
||||
|
||||
// 拼装缓存key
|
||||
String cacheName = CacheUtil.handleKey(CacheConstants.HOT_DATA_PREFIX +":"+ key);
|
||||
|
||||
if(CacheHandleType.UPDATE == type){
|
||||
ehCachePlugin.put(CacheConstants.EHCACHE_SPACE, cacheName, value);
|
||||
}
|
||||
// 缓存删除
|
||||
else if(CacheHandleType.DELETE == type){
|
||||
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.opsli.common.constants.CacheConstants;
|
||||
import org.opsli.core.cache.local.CacheUtil;
|
||||
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
|
||||
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||
import org.opsli.core.utils.OptionsUtil;
|
||||
import org.opsli.plugins.cache.EhCachePlugin;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* 系统参数消息处理
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
@Slf4j
|
||||
public class OptionHandler implements RedisPushSubHandler{
|
||||
|
||||
@Autowired
|
||||
private EhCachePlugin ehCachePlugin;
|
||||
|
||||
@Override
|
||||
public PushSubType getType() {
|
||||
return PushSubType.OPTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handler(JSONObject msgJson) {
|
||||
// 系统参数刷新
|
||||
this.optionHandler(msgJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户数据处理
|
||||
* @param msgJson 信息Json
|
||||
*/
|
||||
private void optionHandler(JSONObject msgJson){
|
||||
JSONObject data = msgJson.getJSONObject(MsgArgsType.OPTION_MODEL_DATA.toString());
|
||||
// 数据为空则不执行
|
||||
if(data == null){
|
||||
return;
|
||||
}
|
||||
|
||||
// 获得参数编号
|
||||
String optionCode = (String) msgJson.get(MsgArgsType.OPTION_CODE.toString());
|
||||
if(StringUtils.isEmpty(optionCode)){
|
||||
return;
|
||||
}
|
||||
|
||||
String cacheKey = CacheUtil.handleKey(OptionsUtil.PREFIX_CODE + optionCode);
|
||||
|
||||
// 先删除
|
||||
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKey);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.opsli.common.constants.CacheConstants;
|
||||
import org.opsli.core.cache.local.CacheUtil;
|
||||
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
|
||||
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||
import org.opsli.core.utils.OrgUtil;
|
||||
import org.opsli.core.utils.UserUtil;
|
||||
import org.opsli.plugins.cache.EhCachePlugin;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* 用户组织消息处理
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
@Slf4j
|
||||
public class OrgHandler implements RedisPushSubHandler{
|
||||
|
||||
@Autowired
|
||||
private EhCachePlugin ehCachePlugin;
|
||||
|
||||
@Override
|
||||
public PushSubType getType() {
|
||||
return PushSubType.ORG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handler(JSONObject msgJson) {
|
||||
// 用户刷新
|
||||
this.orgHandler(msgJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户组织数据处理
|
||||
* @param msgJson 信息Json
|
||||
*/
|
||||
private void orgHandler(JSONObject msgJson){
|
||||
JSONObject data = msgJson.getJSONObject(MsgArgsType.ORG_USER_DATA.toString());
|
||||
// 数据为空则不执行
|
||||
if(data == null){
|
||||
return;
|
||||
}
|
||||
|
||||
// 获得用户ID
|
||||
String userId = (String) msgJson.get(MsgArgsType.ORG_USER_ID.toString());
|
||||
if(StringUtils.isEmpty(userId)){
|
||||
return;
|
||||
}
|
||||
|
||||
String cacheKey = CacheUtil.handleKey(UserUtil.PREFIX_ID_ORGS + userId);
|
||||
|
||||
// 先删除
|
||||
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKey);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||
|
||||
/**
|
||||
* 标示类 用于获得 消息未知
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
public interface RedisPushSubHandler {
|
||||
|
||||
/**
|
||||
* 获得类型
|
||||
* @return 类型
|
||||
*/
|
||||
PushSubType getType();
|
||||
|
||||
/**
|
||||
* 消息处理
|
||||
* @param msgJson 信息Json
|
||||
*/
|
||||
void handler(JSONObject msgJson);
|
||||
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.opsli.common.constants.CacheConstants;
|
||||
import org.opsli.core.cache.local.CacheUtil;
|
||||
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
|
||||
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||
import org.opsli.core.utils.TenantUtil;
|
||||
import org.opsli.plugins.cache.EhCachePlugin;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* 租户消息处理
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
@Slf4j
|
||||
public class TenantHandler implements RedisPushSubHandler{
|
||||
|
||||
@Autowired
|
||||
private EhCachePlugin ehCachePlugin;
|
||||
|
||||
@Override
|
||||
public PushSubType getType() {
|
||||
return PushSubType.TENANT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handler(JSONObject msgJson) {
|
||||
// 用户刷新
|
||||
this.orgHandler(msgJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 租户数据处理
|
||||
* @param msgJson 信息Json
|
||||
*/
|
||||
private void orgHandler(JSONObject msgJson){
|
||||
JSONObject data = msgJson.getJSONObject(MsgArgsType.TENANT_DATA.toString());
|
||||
// 数据为空则不执行
|
||||
if(data == null){
|
||||
return;
|
||||
}
|
||||
|
||||
// 获得租户ID
|
||||
String tenantId = (String) msgJson.get(MsgArgsType.TENANT_ID.toString());
|
||||
if(StringUtils.isEmpty(tenantId)){
|
||||
return;
|
||||
}
|
||||
|
||||
String cacheKey = CacheUtil.handleKey(TenantUtil.PREFIX_CODE + tenantId);
|
||||
|
||||
// 先删除
|
||||
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKey);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,168 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.opsli.common.constants.CacheConstants;
|
||||
import org.opsli.core.cache.local.CacheUtil;
|
||||
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
|
||||
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||
import org.opsli.core.cache.pushsub.enums.UserModelType;
|
||||
import org.opsli.core.utils.UserUtil;
|
||||
import org.opsli.plugins.cache.EhCachePlugin;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* 用户消息处理
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-16
|
||||
*/
|
||||
@Slf4j
|
||||
public class UserHandler implements RedisPushSubHandler{
|
||||
|
||||
@Autowired
|
||||
private EhCachePlugin ehCachePlugin;
|
||||
|
||||
@Override
|
||||
public PushSubType getType() {
|
||||
return PushSubType.USER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handler(JSONObject msgJson) {
|
||||
UserModelType userModelType = UserModelType.valueOf((String)
|
||||
msgJson.get(MsgArgsType.USER_MODEL_TYPE.toString()));
|
||||
|
||||
// 用户刷新
|
||||
if(UserModelType.USER_MODEL == userModelType){
|
||||
this.userHandler(msgJson);
|
||||
}
|
||||
// 用户角色刷新
|
||||
else if(UserModelType.USER_ROLES_MODEL == userModelType){
|
||||
this.userRolesHandler(msgJson);
|
||||
}
|
||||
// 用户权限刷新
|
||||
else if(UserModelType.USER_PERMS_MODEL == userModelType){
|
||||
this.userPermsHandler(msgJson);
|
||||
}
|
||||
// 用户菜单刷新
|
||||
else if(UserModelType.USER_MENU_MODEL == userModelType){
|
||||
this.userMenusHandler(msgJson);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户数据处理
|
||||
* @param msgJson 信息Json
|
||||
*/
|
||||
private void userHandler(JSONObject msgJson){
|
||||
JSONObject data = msgJson.getJSONObject(MsgArgsType.USER_MODEL_DATA.toString());
|
||||
// 数据为空则不执行
|
||||
if(data == null){
|
||||
return;
|
||||
}
|
||||
|
||||
// 获得用户ID 和 用户名
|
||||
String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString());
|
||||
String username = (String) msgJson.get(MsgArgsType.USER_USERNAME.toString());
|
||||
if(StringUtils.isEmpty(userId) || StringUtils.isEmpty(username) ){
|
||||
return;
|
||||
}
|
||||
|
||||
String cacheKeyById = CacheUtil.handleKey(UserUtil.PREFIX_ID + userId);
|
||||
String cacheKeyByName = CacheUtil.handleKey(UserUtil.PREFIX_USERNAME + username);
|
||||
|
||||
// 先删除
|
||||
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKeyById);
|
||||
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKeyByName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户角色数据处理
|
||||
* @param msgJson 信息Json
|
||||
*/
|
||||
private void userRolesHandler(JSONObject msgJson){
|
||||
JSONArray dataArray = msgJson.getJSONArray(MsgArgsType.USER_MODEL_DATA.toString());
|
||||
// 数据为空则不执行
|
||||
if(dataArray == null || dataArray.isEmpty()){
|
||||
return;
|
||||
}
|
||||
|
||||
// 获得用户ID
|
||||
String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString());
|
||||
if(StringUtils.isEmpty(userId)){
|
||||
return;
|
||||
}
|
||||
|
||||
String cacheKey = CacheUtil.handleKey(UserUtil.PREFIX_ID_ROLES + userId);
|
||||
|
||||
// 先删除
|
||||
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户权限数据处理
|
||||
* @param msgJson 信息Json
|
||||
*/
|
||||
private void userPermsHandler(JSONObject msgJson){
|
||||
JSONArray dataArray = msgJson.getJSONArray(MsgArgsType.USER_MODEL_DATA.toString());
|
||||
// 数据为空则不执行
|
||||
if(dataArray == null || dataArray.isEmpty()){
|
||||
return;
|
||||
}
|
||||
|
||||
// 获得用户ID
|
||||
String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString());
|
||||
if(StringUtils.isEmpty(userId)){
|
||||
return;
|
||||
}
|
||||
|
||||
String cacheKey = CacheUtil.handleKey(UserUtil.PREFIX_ID_PERMISSIONS + userId);
|
||||
|
||||
// 先删除
|
||||
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户菜单数据处理
|
||||
* @param msgJson 信息Json
|
||||
*/
|
||||
private void userMenusHandler(JSONObject msgJson){
|
||||
JSONArray dataArray = msgJson.getJSONArray(MsgArgsType.USER_MODEL_DATA.toString());
|
||||
// 数据为空则不执行
|
||||
if(dataArray == null || dataArray.isEmpty()){
|
||||
return;
|
||||
}
|
||||
|
||||
// 获得用户ID
|
||||
String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString());
|
||||
if(StringUtils.isEmpty(userId)){
|
||||
return;
|
||||
}
|
||||
|
||||
String cacheKey = CacheUtil.handleKey(UserUtil.PREFIX_ID_MENUS + userId);
|
||||
|
||||
// 先删除
|
||||
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKey);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.msgs;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.opsli.core.cache.pushsub.entity.CacheDataEntity;
|
||||
import org.opsli.core.cache.pushsub.enums.CacheHandleType;
|
||||
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
|
||||
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||
import org.opsli.core.cache.pushsub.receiver.RedisPushSubReceiver;
|
||||
import org.opsli.plugins.redis.pushsub.entity.BaseSubMessage;
|
||||
|
||||
/**
|
||||
* 热数据消息
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-15
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public final class CacheDataMsgFactory extends BaseSubMessage{
|
||||
|
||||
/** 通道 */
|
||||
private static final String CHANNEL = RedisPushSubReceiver.BASE_CHANNEL + RedisPushSubReceiver.CHANNEL;
|
||||
|
||||
private CacheDataMsgFactory(){}
|
||||
|
||||
/**
|
||||
* 构建消息 热数据
|
||||
* @param cacheDataEntity 热数据对象
|
||||
* @param value 值
|
||||
* @param cacheHandleType 类型
|
||||
* @return 消息
|
||||
*/
|
||||
public static BaseSubMessage createMsg(CacheDataEntity cacheDataEntity, Object value,
|
||||
CacheHandleType cacheHandleType){
|
||||
BaseSubMessage baseSubMessage = new BaseSubMessage();
|
||||
// 数据
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put(MsgArgsType.CACHE_DATA_KEY.toString(),cacheDataEntity.getKey());
|
||||
jsonObj.put(MsgArgsType.CACHE_DATA_VALUE.toString(),value);
|
||||
jsonObj.put(MsgArgsType.CACHE_DATA_TYPE.toString(), cacheHandleType.toString());
|
||||
|
||||
// 热点数据 - 系统数据
|
||||
baseSubMessage.build(CHANNEL, PushSubType.HOT_DATA.toString(), jsonObj);
|
||||
return baseSubMessage;
|
||||
}
|
||||
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.msgs;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.opsli.api.wrapper.system.dict.DictWrapper;
|
||||
import org.opsli.core.cache.pushsub.enums.CacheHandleType;
|
||||
import org.opsli.core.cache.pushsub.enums.DictModelType;
|
||||
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
|
||||
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||
import org.opsli.core.cache.pushsub.receiver.RedisPushSubReceiver;
|
||||
import org.opsli.plugins.redis.pushsub.entity.BaseSubMessage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典消息
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-15
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public final class DictMsgFactory extends BaseSubMessage{
|
||||
|
||||
/** 通道 */
|
||||
private static final String CHANNEL = RedisPushSubReceiver.BASE_CHANNEL+RedisPushSubReceiver.CHANNEL;
|
||||
|
||||
private DictMsgFactory(){}
|
||||
|
||||
/**
|
||||
* 构建消息 字典
|
||||
* @param dictWrapperModel 字典模型
|
||||
* @param cacheHandleType 缓存类型
|
||||
* @return 消息
|
||||
*/
|
||||
public static BaseSubMessage createMsg(DictWrapper dictWrapperModel, CacheHandleType cacheHandleType){
|
||||
BaseSubMessage baseSubMessage = new BaseSubMessage();
|
||||
// 数据
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put(MsgArgsType.DICT_MODEL.toString(), dictWrapperModel);
|
||||
jsonObj.put(MsgArgsType.DICT_MODEL_TYPE.toString(), DictModelType.OBJECT);
|
||||
jsonObj.put(MsgArgsType.DICT_TYPE.toString(), cacheHandleType.toString());
|
||||
|
||||
// DICT 字典
|
||||
baseSubMessage.build(CHANNEL,PushSubType.DICT.toString(),jsonObj);
|
||||
return baseSubMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建消息 字典
|
||||
* @param dictWrapperModels 字典模型集合
|
||||
* @param cacheHandleType 缓存类型
|
||||
* @return 消息
|
||||
*/
|
||||
public static BaseSubMessage createMsg(List<DictWrapper> dictWrapperModels, CacheHandleType cacheHandleType){
|
||||
BaseSubMessage baseSubMessage = new BaseSubMessage();
|
||||
// 数据
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put(MsgArgsType.DICT_MODELS.toString(), dictWrapperModels);
|
||||
jsonObj.put(MsgArgsType.DICT_MODEL_TYPE.toString(), DictModelType.COLLECTION);
|
||||
jsonObj.put(MsgArgsType.DICT_TYPE.toString(), cacheHandleType.toString());
|
||||
|
||||
// DICT 字典
|
||||
baseSubMessage.build(CHANNEL,PushSubType.DICT.toString(),jsonObj);
|
||||
return baseSubMessage;
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.msgs;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.opsli.api.wrapper.system.menu.MenuModel;
|
||||
import org.opsli.api.wrapper.system.options.OptionsModel;
|
||||
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
|
||||
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||
import org.opsli.core.cache.pushsub.receiver.RedisPushSubReceiver;
|
||||
import org.opsli.plugins.redis.pushsub.entity.BaseSubMessage;
|
||||
|
||||
/**
|
||||
* 参数消息
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-15
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public final class OptionMsgFactory extends BaseSubMessage{
|
||||
|
||||
/** 通道 */
|
||||
private static final String CHANNEL = RedisPushSubReceiver.BASE_CHANNEL+RedisPushSubReceiver.CHANNEL;
|
||||
|
||||
private OptionMsgFactory(){}
|
||||
|
||||
/**
|
||||
* 构建消息 - 参数
|
||||
* @param optionsModel 参数模型
|
||||
* @return 消息
|
||||
*/
|
||||
public static BaseSubMessage createOptionMsg(OptionsModel optionsModel){
|
||||
BaseSubMessage baseSubMessage = new BaseSubMessage();
|
||||
// 数据
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put(MsgArgsType.OPTION_CODE.toString(), optionsModel.getOptionCode());
|
||||
jsonObj.put(MsgArgsType.OPTION_MODEL_DATA.toString(), optionsModel);
|
||||
|
||||
// 参数
|
||||
baseSubMessage.build(CHANNEL,PushSubType.OPTION.toString(),jsonObj);
|
||||
return baseSubMessage;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.msgs;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.opsli.api.wrapper.system.user.UserOrgRefWebModel;
|
||||
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
|
||||
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||
import org.opsli.core.cache.pushsub.receiver.RedisPushSubReceiver;
|
||||
import org.opsli.plugins.redis.pushsub.entity.BaseSubMessage;
|
||||
|
||||
/**
|
||||
* 用户组织消息
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-15
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public final class OrgMsgFactory extends BaseSubMessage{
|
||||
|
||||
/** 通道 */
|
||||
private static final String CHANNEL = RedisPushSubReceiver.BASE_CHANNEL+RedisPushSubReceiver.CHANNEL;
|
||||
|
||||
private OrgMsgFactory(){}
|
||||
|
||||
/**
|
||||
* 构建消息 - 用户组织
|
||||
* @param orgRefModel 用户组织模型
|
||||
* @return 消息
|
||||
*/
|
||||
public static BaseSubMessage createOrgMsg(UserOrgRefWebModel orgRefModel){
|
||||
BaseSubMessage baseSubMessage = new BaseSubMessage();
|
||||
// 数据
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put(MsgArgsType.ORG_USER_ID.toString(), orgRefModel.getUserId());
|
||||
jsonObj.put(MsgArgsType.ORG_USER_DATA.toString(), orgRefModel);
|
||||
|
||||
// 组织
|
||||
baseSubMessage.build(CHANNEL,PushSubType.ORG.toString(),jsonObj);
|
||||
return baseSubMessage;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.msgs;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.opsli.api.wrapper.system.tenant.TenantModel;
|
||||
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
|
||||
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||
import org.opsli.core.cache.pushsub.receiver.RedisPushSubReceiver;
|
||||
import org.opsli.plugins.redis.pushsub.entity.BaseSubMessage;
|
||||
|
||||
/**
|
||||
* 租户消息
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-15
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public final class TenantMsgFactory extends BaseSubMessage{
|
||||
|
||||
/** 通道 */
|
||||
private static final String CHANNEL = RedisPushSubReceiver.BASE_CHANNEL+RedisPushSubReceiver.CHANNEL;
|
||||
|
||||
private TenantMsgFactory(){}
|
||||
|
||||
/**
|
||||
* 构建消息 - 租户
|
||||
* @param tenantModel 租户模型
|
||||
* @return 消息
|
||||
*/
|
||||
public static BaseSubMessage createTenantMsg(TenantModel tenantModel){
|
||||
BaseSubMessage baseSubMessage = new BaseSubMessage();
|
||||
// 数据
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put(MsgArgsType.TENANT_ID.toString(), tenantModel.getId());
|
||||
jsonObj.put(MsgArgsType.TENANT_DATA.toString(), tenantModel);
|
||||
|
||||
// 租户
|
||||
baseSubMessage.build(CHANNEL,PushSubType.TENANT.toString(),jsonObj);
|
||||
return baseSubMessage;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,122 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.msgs;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.opsli.api.wrapper.system.menu.MenuModel;
|
||||
import org.opsli.api.wrapper.system.user.UserModel;
|
||||
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
|
||||
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||
import org.opsli.core.cache.pushsub.enums.UserModelType;
|
||||
import org.opsli.core.cache.pushsub.receiver.RedisPushSubReceiver;
|
||||
import org.opsli.plugins.redis.pushsub.entity.BaseSubMessage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户消息
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-15
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public final class UserMsgFactory extends BaseSubMessage{
|
||||
|
||||
/** 通道 */
|
||||
private static final String CHANNEL = RedisPushSubReceiver.BASE_CHANNEL+RedisPushSubReceiver.CHANNEL;
|
||||
|
||||
private UserMsgFactory(){}
|
||||
|
||||
/**
|
||||
* 构建消息 - 用户
|
||||
* @param userModel 用户模型
|
||||
* @return 消息
|
||||
*/
|
||||
public static BaseSubMessage createUserMsg(UserModel userModel){
|
||||
BaseSubMessage baseSubMessage = new BaseSubMessage();
|
||||
// 数据
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put(MsgArgsType.USER_ID.toString(), userModel.getId());
|
||||
jsonObj.put(MsgArgsType.USER_USERNAME.toString(), userModel.getUsername());
|
||||
jsonObj.put(MsgArgsType.USER_MODEL_TYPE.toString(), UserModelType.USER_MODEL.toString());
|
||||
jsonObj.put(MsgArgsType.USER_MODEL_DATA.toString(), userModel);
|
||||
|
||||
// 用户
|
||||
baseSubMessage.build(CHANNEL,PushSubType.USER.toString(),jsonObj);
|
||||
return baseSubMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建消息 - 用户角色
|
||||
* @param userId 用户ID
|
||||
* @param roles 角色集合
|
||||
* @return 消息
|
||||
*/
|
||||
public static BaseSubMessage createUserRolesMsg(String userId, List<String> roles){
|
||||
BaseSubMessage baseSubMessage = new BaseSubMessage();
|
||||
// 数据
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put(MsgArgsType.USER_ID.toString(), userId);
|
||||
jsonObj.put(MsgArgsType.USER_MODEL_TYPE.toString(), UserModelType.USER_ROLES_MODEL.toString());
|
||||
jsonObj.put(MsgArgsType.USER_MODEL_DATA.toString(), roles);
|
||||
|
||||
// 用户
|
||||
baseSubMessage.build(CHANNEL,PushSubType.USER.toString(),jsonObj);
|
||||
return baseSubMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建消息 - 用户权限
|
||||
* @param userId 用户ID
|
||||
* @param perms 权限集合
|
||||
* @return 消息
|
||||
*/
|
||||
public static BaseSubMessage createUserPermsMsg(String userId, List<String> perms){
|
||||
BaseSubMessage baseSubMessage = new BaseSubMessage();
|
||||
// 数据
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put(MsgArgsType.USER_ID.toString(), userId);
|
||||
jsonObj.put(MsgArgsType.USER_MODEL_TYPE.toString(), UserModelType.USER_PERMS_MODEL.toString());
|
||||
jsonObj.put(MsgArgsType.USER_MODEL_DATA.toString(), perms);
|
||||
|
||||
// 用户
|
||||
baseSubMessage.build(CHANNEL,PushSubType.USER.toString(),jsonObj);
|
||||
return baseSubMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建消息 - 用户菜单
|
||||
* @param userId 用户ID
|
||||
* @param menus 菜单集合
|
||||
* @return 消息
|
||||
*/
|
||||
public static BaseSubMessage createUserMenusMsg(String userId, List<MenuModel> menus){
|
||||
BaseSubMessage baseSubMessage = new BaseSubMessage();
|
||||
// 数据
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put(MsgArgsType.USER_ID.toString(), userId);
|
||||
jsonObj.put(MsgArgsType.USER_MODEL_TYPE.toString(), UserModelType.USER_MENU_MODEL.toString());
|
||||
jsonObj.put(MsgArgsType.USER_MODEL_DATA.toString(), menus);
|
||||
|
||||
// 用户
|
||||
baseSubMessage.build(CHANNEL,PushSubType.USER.toString(),jsonObj);
|
||||
return baseSubMessage;
|
||||
}
|
||||
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.cache.pushsub.receiver;
|
||||
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.opsli.common.enums.SystemInfo;
|
||||
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||
import org.opsli.core.cache.pushsub.handler.RedisPushSubHandler;
|
||||
import org.opsli.core.msg.CoreMsg;
|
||||
import org.opsli.plugins.redis.pushsub.entity.BaseSubMessage;
|
||||
import org.opsli.plugins.redis.pushsub.receiver.BaseReceiver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* Redis 消息订阅 更新本地缓存
|
||||
* 字典缓存更新
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2020-09-15
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class RedisPushSubReceiver extends BaseReceiver {
|
||||
|
||||
/** Spring Bean 前缀 */
|
||||
public static final String SPRING_PREFIX = "redisPushSub_";
|
||||
|
||||
/** 监听信道 */
|
||||
public static final String CHANNEL = "opsli";
|
||||
|
||||
/** 处理方法集合 */
|
||||
private static final ConcurrentMap<PushSubType, RedisPushSubHandler> HANDLER_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
@Autowired
|
||||
private AutowireCapableBeanFactory beanFactory;
|
||||
|
||||
@Autowired
|
||||
private DefaultListableBeanFactory defaultListableBeanFactory;
|
||||
|
||||
public RedisPushSubReceiver() {
|
||||
super(CHANNEL);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public void initRedisPushSubHandler(){
|
||||
|
||||
// 拿到state包下 实现了 SystemEventState 接口的,所有子类
|
||||
Set<Class<?>> clazzSet = ClassUtil.scanPackageBySuper(
|
||||
RedisPushSubHandler.class.getPackage().getName(),
|
||||
RedisPushSubHandler.class
|
||||
);
|
||||
|
||||
for (Class<?> aClass : clazzSet) {
|
||||
// 位运算 去除抽象类
|
||||
if((aClass.getModifiers() & Modifier.ABSTRACT) != 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
Object obj = aClass.newInstance();
|
||||
|
||||
RedisPushSubHandler handler = (RedisPushSubHandler) obj;
|
||||
|
||||
// 加入集合
|
||||
HANDLER_MAP.put(handler.getType(),handler);
|
||||
|
||||
//将new出的对象放入Spring容器中
|
||||
defaultListableBeanFactory.registerSingleton(SPRING_PREFIX+aClass.getSimpleName(), obj);
|
||||
|
||||
//自动注入依赖
|
||||
beanFactory.autowireBean(obj);
|
||||
|
||||
} catch (Exception e){
|
||||
log.error(CoreMsg.REDIS_EXCEPTION_PUSH_SUB.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void receiveMessage(String msg) {
|
||||
if(msg == null || "".equals(msg)){
|
||||
return;
|
||||
}
|
||||
long beginTime = System.currentTimeMillis();
|
||||
// 替换 转意符
|
||||
String replaceAll = msg.replaceAll("\\\\", "");
|
||||
String substring = replaceAll.substring(1, replaceAll.length() - 1);
|
||||
JSONObject msgJson = JSONObject.parseObject(substring);
|
||||
String type = (String) msgJson.get(BaseSubMessage.BASE_TYPE);
|
||||
String identifier = (String) msgJson.get(BaseSubMessage.BASE_ID);
|
||||
// 本机不广播
|
||||
if(SystemInfo.INSTANCE.getSystemID().equals(identifier)){
|
||||
return;
|
||||
}
|
||||
PushSubType pt = PushSubType.valueOf(type);
|
||||
RedisPushSubHandler redisPushSubHandler = HANDLER_MAP.get(pt);
|
||||
if(redisPushSubHandler == null){
|
||||
return;
|
||||
}
|
||||
redisPushSubHandler.handler(msgJson);
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("订阅节点更新缓存 耗时(毫秒):{}",(endTime-beginTime));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue