Search in sources :

Example 1 with MonitorUserOptModel

use of io.jpom.model.data.MonitorUserOptModel in project Jpom by dromara.

the class MonitorUserOptService method listByType.

/**
 * 查询 对应操作的监控信息
 *
 * @param workspaceId   工作空间ID
 * @param classFeature  功能
 * @param methodFeature 操作
 * @return list
 */
public List<MonitorUserOptModel> listByType(String workspaceId, ClassFeature classFeature, MethodFeature methodFeature, String userId) {
    MonitorUserOptModel where = new MonitorUserOptModel();
    if (StrUtil.isNotEmpty(workspaceId)) {
        // 没有工作空间查询全部
        where.setWorkspaceId(workspaceId);
    }
    where.setStatus(true);
    List<MonitorUserOptModel> list = super.listByBean(where);
    if (CollUtil.isEmpty(list)) {
        return null;
    }
    return list.stream().filter(monitorUserOptModel -> {
        List<ClassFeature> classFeatures = monitorUserOptModel.monitorFeature();
        List<MethodFeature> methodFeatures = monitorUserOptModel.monitorOpt();
        boolean b = CollUtil.contains(classFeatures, classFeature) && CollUtil.contains(methodFeatures, methodFeature);
        if (b) {
            List<String> monitorUser = monitorUserOptModel.monitorUser();
            return CollUtil.contains(monitorUser, userId);
        }
        return false;
    }).collect(Collectors.toList());
}
Also used : CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) BaseWorkspaceService(io.jpom.service.h2db.BaseWorkspaceService) MonitorUserOptModel(io.jpom.model.data.MonitorUserOptModel) Service(org.springframework.stereotype.Service) ClassFeature(io.jpom.permission.ClassFeature) MethodFeature(io.jpom.permission.MethodFeature) Collectors(java.util.stream.Collectors) List(java.util.List) MonitorUserOptModel(io.jpom.model.data.MonitorUserOptModel)

Example 2 with MonitorUserOptModel

use of io.jpom.model.data.MonitorUserOptModel in project Jpom by dromara.

the class MonitorUserOptListController method changeStatus.

/**
 * 开启或关闭监控
 *
 * @param id     id
 * @param status 状态
 * @return json
 */
@RequestMapping(value = "changeStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String changeStatus(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "id不能为空") String id, String status) {
    MonitorUserOptModel monitorModel = monitorUserOptService.getByKey(id);
    Assert.notNull(monitorModel, "不存在监控项啦");
    boolean bStatus = Convert.toBool(status, false);
    monitorModel.setStatus(bStatus);
    monitorUserOptService.update(monitorModel);
    return JsonMessage.getString(200, "修改成功");
}
Also used : MonitorUserOptModel(io.jpom.model.data.MonitorUserOptModel) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with MonitorUserOptModel

use of io.jpom.model.data.MonitorUserOptModel in project Jpom by dromara.

the class MonitorUserOptListController method updateMonitor.

/**
 * 增加或修改监控
 *
 * @param id         id
 * @param name       name
 * @param notifyUser user
 * @return json
 */
@RequestMapping(value = "update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String updateMonitor(String id, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "监控名称不能为空") String name, String notifyUser, String monitorUser, String monitorOpt, String monitorFeature) {
    String status = getParameter("status");
    JSONArray jsonArray = JSONArray.parseArray(notifyUser);
    List<String> notifyUsers = jsonArray.toJavaList(String.class).stream().filter(Objects::nonNull).collect(Collectors.toList());
    Assert.notEmpty(notifyUsers, "请选择报警联系人");
    JSONArray monitorUserArray = JSONArray.parseArray(monitorUser);
    List<String> monitorUserArrays = monitorUserArray.toJavaList(String.class).stream().filter(Objects::nonNull).collect(Collectors.toList());
    Assert.notEmpty(monitorUserArrays, "请选择监控人员");
    JSONArray monitorOptArray = JSONArray.parseArray(monitorOpt);
    List<MethodFeature> monitorOptArrays = monitorOptArray.stream().map(o -> EnumUtil.fromString(MethodFeature.class, StrUtil.toString(o), null)).filter(Objects::nonNull).collect(Collectors.toList());
    Assert.notEmpty(monitorOptArrays, "请选择监控的操作");
    JSONArray monitorFeatureArray = JSONArray.parseArray(monitorFeature);
    List<ClassFeature> monitorFeatureArrays = monitorFeatureArray.stream().map(o -> EnumUtil.fromString(ClassFeature.class, StrUtil.toString(o), null)).filter(Objects::nonNull).collect(Collectors.toList());
    Assert.notEmpty(monitorFeatureArrays, "请选择监控的功能");
    boolean start = "on".equalsIgnoreCase(status);
    MonitorUserOptModel monitorModel = monitorUserOptService.getByKey(id);
    if (monitorModel == null) {
        monitorModel = new MonitorUserOptModel();
    }
    monitorModel.monitorUser(monitorUserArrays);
    monitorModel.setStatus(start);
    monitorModel.monitorOpt(monitorOptArrays);
    monitorModel.monitorFeature(monitorFeatureArrays);
    monitorModel.notifyUser(notifyUsers);
    monitorModel.setName(name);
    if (StrUtil.isEmpty(id)) {
        // 添加监控
        monitorUserOptService.insert(monitorModel);
        return JsonMessage.getString(200, "添加成功");
    }
    monitorUserOptService.update(monitorModel);
    return JsonMessage.getString(200, "修改成功");
}
Also used : ClassFeature(io.jpom.permission.ClassFeature) MethodFeature(io.jpom.permission.MethodFeature) JSONArray(com.alibaba.fastjson.JSONArray) MonitorUserOptModel(io.jpom.model.data.MonitorUserOptModel) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with MonitorUserOptModel

use of io.jpom.model.data.MonitorUserOptModel 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);
                    }
                });
            }
        }
    }
}
Also used : WorkspaceModel(io.jpom.model.data.WorkspaceModel) MonitorModel(io.jpom.model.data.MonitorModel) MethodFeature(io.jpom.permission.MethodFeature) UserModel(io.jpom.model.data.UserModel) ClassFeature(io.jpom.permission.ClassFeature) MonitorUserOptModel(io.jpom.model.data.MonitorUserOptModel)

Aggregations

MonitorUserOptModel (io.jpom.model.data.MonitorUserOptModel)4 ClassFeature (io.jpom.permission.ClassFeature)4 MethodFeature (io.jpom.permission.MethodFeature)4 Feature (io.jpom.permission.Feature)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 CollUtil (cn.hutool.core.collection.CollUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 JSONArray (com.alibaba.fastjson.JSONArray)1 MonitorModel (io.jpom.model.data.MonitorModel)1 UserModel (io.jpom.model.data.UserModel)1 WorkspaceModel (io.jpom.model.data.WorkspaceModel)1 BaseWorkspaceService (io.jpom.service.h2db.BaseWorkspaceService)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Service (org.springframework.stereotype.Service)1