use of io.jpom.permission.ClassFeature in project Jpom by dromara.
the class DbUserOperateLogService method buildDataMsg.
/**
* 根据 数据ID 和 节点ID 查询相关数据名称
*
* @param classFeature 功能
* @param dataId 数据ID
* @param nodeId 节点ID
* @return map
*/
public Map<String, Object> buildDataMsg(ClassFeature classFeature, String dataId, String nodeId) {
if (classFeature == null) {
return null;
}
Class<? extends BaseDbService<?>> dbService = classFeature.getDbService();
if (dbService == null) {
return null;
}
Map<String, Object> map = new LinkedHashMap<>();
map.put("数据id", dataId);
BaseDbService<?> baseDbCommonService = SpringUtil.getBean(dbService);
Object data = baseDbCommonService.getData(nodeId, dataId);
map.put("数据名称", this.tryGetBeanName(data));
//
map.put("节点id", nodeId);
ClassFeature parent = classFeature.getParent();
if (parent == ClassFeature.NODE) {
Class<? extends BaseDbService<?>> dbServiceParent = parent.getDbService();
BaseDbService<?> baseDbCommonServiceParent = SpringUtil.getBean(dbServiceParent);
Object dataParent = baseDbCommonServiceParent.getData(nodeId, dataId);
map.put("节点名称", this.tryGetBeanName(dataParent));
}
return map;
}
use of io.jpom.permission.ClassFeature in project Jpom by dromara.
the class DbUserOperateLogService method checkMonitor.
/**
* 判断当前操作是否需要报警
*
* @param userOperateLogV1 操作信息
* @param cacheInfo 操作缓存相关
*/
private void checkMonitor(UserOperateLogV1 userOperateLogV1, OperateLogController.CacheInfo cacheInfo) {
ClassFeature classFeature = EnumUtil.fromString(ClassFeature.class, userOperateLogV1.getClassFeature(), null);
MethodFeature methodFeature = EnumUtil.fromString(MethodFeature.class, userOperateLogV1.getMethodFeature(), null);
UserModel optUserItem = userService.getByKey(userOperateLogV1.getUserId());
if (classFeature == null || methodFeature == null || optUserItem == null) {
return;
}
Map<String, Object> dataMap = this.buildDataMsg(classFeature, cacheInfo, userOperateLogV1);
WorkspaceModel workspaceModel = workspaceService.getByKey(userOperateLogV1.getWorkspaceId());
String optTypeMsg = StrUtil.format(" 【{}】->【{}】", classFeature.getName(), methodFeature.getName());
List<MonitorUserOptModel> monitorUserOptModels = monitorUserOptService.listByType(userOperateLogV1.getWorkspaceId(), classFeature, methodFeature, userOperateLogV1.getUserId());
if (CollUtil.isEmpty(monitorUserOptModels)) {
return;
}
String context = this.buildContent(optUserItem, dataMap, workspaceModel, optTypeMsg, userOperateLogV1);
for (MonitorUserOptModel monitorUserOptModel : monitorUserOptModels) {
List<String> notifyUser = monitorUserOptModel.notifyUser();
if (CollUtil.isEmpty(notifyUser)) {
continue;
}
for (String userId : notifyUser) {
UserModel item = userService.getByKey(userId);
if (item == null) {
continue;
}
// 邮箱
String email = item.getEmail();
if (StrUtil.isNotEmpty(email)) {
MonitorModel.Notify notify1 = new MonitorModel.Notify(MonitorModel.NotifyType.mail, email);
ThreadUtil.execute(() -> {
try {
NotifyUtil.send(notify1, "用户操作报警", context);
} catch (Exception e) {
DefaultSystemLog.getLog().error("发送报警信息错误", e);
}
});
}
// dingding
String dingDing = item.getDingDing();
if (StrUtil.isNotEmpty(dingDing)) {
MonitorModel.Notify notify1 = new MonitorModel.Notify(MonitorModel.NotifyType.dingding, dingDing);
ThreadUtil.execute(() -> {
try {
NotifyUtil.send(notify1, "用户操作报警", context);
} catch (Exception e) {
DefaultSystemLog.getLog().error("发送报警信息错误", e);
}
});
}
// 企业微信
String workWx = item.getWorkWx();
if (StrUtil.isNotEmpty(workWx)) {
MonitorModel.Notify notify1 = new MonitorModel.Notify(MonitorModel.NotifyType.workWx, workWx);
ThreadUtil.execute(() -> {
try {
NotifyUtil.send(notify1, "用户操作报警", context);
} catch (Exception e) {
DefaultSystemLog.getLog().error("发送报警信息错误", e);
}
});
}
}
}
}
use of io.jpom.permission.ClassFeature in project Jpom by dromara.
the class OperateLogController method createCacheInfo.
private CacheInfo createCacheInfo(Method method) {
Feature feature = method.getAnnotation(Feature.class);
if (feature == null) {
return null;
}
Class<?> declaringClass = method.getDeclaringClass();
MethodFeature methodFeature = feature.method();
if (methodFeature == MethodFeature.NULL) {
DefaultSystemLog.getLog().error("权限分发配置错误:{} {}", declaringClass, method.getName());
return null;
}
ClassFeature classFeature = feature.cls();
if (classFeature == ClassFeature.NULL) {
Feature feature1 = declaringClass.getAnnotation(Feature.class);
if (feature1 == null || feature1.cls() == ClassFeature.NULL) {
DefaultSystemLog.getLog().error("权限分发配置错误:{} {} class not find", declaringClass, method.getName());
return null;
}
classFeature = feature1.cls();
}
CacheInfo cacheInfo = new CacheInfo();
cacheInfo.setClassFeature(classFeature);
cacheInfo.setMethodFeature(methodFeature);
cacheInfo.setOptTime(SystemClock.now());
cacheInfo.setResultCode(feature.resultCode());
cacheInfo.setLogResponse(feature.logResponse());
//
if (dbUserOperateLogService == null) {
dbUserOperateLogService = SpringUtil.getBean(DbUserOperateLogService.class);
}
return cacheInfo;
}
Aggregations