Search in sources :

Example 6 with MethodFeature

use of io.jpom.permission.MethodFeature 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;
}
Also used : ClassFeature(io.jpom.permission.ClassFeature) DbUserOperateLogService(io.jpom.service.dblog.DbUserOperateLogService) MethodFeature(io.jpom.permission.MethodFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 7 with MethodFeature

use of io.jpom.permission.MethodFeature in project Jpom by dromara.

the class MonitorUserOptListController method getOperateTypeList.

/**
 * 操作监控类型列表
 *
 * @return json
 */
@RequestMapping(value = "type_data", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String getOperateTypeList() {
    JSONObject jsonObject = new JSONObject();
    // 
    List<JSONObject> classFeatureList = Arrays.stream(ClassFeature.values()).filter(classFeature -> classFeature != ClassFeature.NULL).map(classFeature -> {
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("title", classFeature.getName());
        jsonObject1.put("value", classFeature.name());
        return jsonObject1;
    }).collect(Collectors.toList());
    jsonObject.put("classFeature", classFeatureList);
    // 
    List<JSONObject> methodFeatureList = Arrays.stream(MethodFeature.values()).filter(methodFeature -> methodFeature != MethodFeature.NULL && methodFeature != MethodFeature.LIST).map(classFeature -> {
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("title", classFeature.getName());
        jsonObject1.put("value", classFeature.name());
        return jsonObject1;
    }).collect(Collectors.toList());
    jsonObject.put("methodFeature", methodFeatureList);
    return JsonMessage.getString(200, "success", jsonObject);
}
Also used : PageResultDto(io.jpom.model.PageResultDto) Arrays(java.util.Arrays) ClassFeature(io.jpom.permission.ClassFeature) MediaType(org.springframework.http.MediaType) EnumUtil(cn.hutool.core.util.EnumUtil) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) Feature(io.jpom.permission.Feature) Objects(java.util.Objects) JsonMessage(cn.jiangzeyin.common.JsonMessage) JSONArray(com.alibaba.fastjson.JSONArray) StrUtil(cn.hutool.core.util.StrUtil) ValidatorRule(cn.jiangzeyin.common.validator.ValidatorRule) List(java.util.List) MonitorUserOptModel(io.jpom.model.data.MonitorUserOptModel) MonitorUserOptService(io.jpom.service.monitor.MonitorUserOptService) ValidatorItem(cn.jiangzeyin.common.validator.ValidatorItem) Convert(cn.hutool.core.convert.Convert) JSONObject(com.alibaba.fastjson.JSONObject) MethodFeature(io.jpom.permission.MethodFeature) BaseServerController(io.jpom.common.BaseServerController) Assert(org.springframework.util.Assert) JSONObject(com.alibaba.fastjson.JSONObject) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with MethodFeature

use of io.jpom.permission.MethodFeature 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)

Aggregations

MethodFeature (io.jpom.permission.MethodFeature)8 ClassFeature (io.jpom.permission.ClassFeature)6 Feature (io.jpom.permission.Feature)5 MonitorUserOptModel (io.jpom.model.data.MonitorUserOptModel)4 StrUtil (cn.hutool.core.util.StrUtil)3 UserModel (io.jpom.model.data.UserModel)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 JSONArray (com.alibaba.fastjson.JSONArray)2 JSONObject (com.alibaba.fastjson.JSONObject)2 WorkspaceModel (io.jpom.model.data.WorkspaceModel)2 Service (org.springframework.stereotype.Service)2 Assert (org.springframework.util.Assert)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 CollUtil (cn.hutool.core.collection.CollUtil)1 Convert (cn.hutool.core.convert.Convert)1 EnumUtil (cn.hutool.core.util.EnumUtil)1 Entity (cn.hutool.db.Entity)1 JsonMessage (cn.jiangzeyin.common.JsonMessage)1 ValidatorItem (cn.jiangzeyin.common.validator.ValidatorItem)1