Browse Source

数据集、模型审批功能开发

dev-opt-cp
ddmte32 11 months ago
parent
commit
3a22e540ad
5 changed files with 80 additions and 0 deletions
  1. +10
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/annotations/NeedApproval.java
  2. +63
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/annotations/aspect/ModelApprovalAspect.java
  3. +2
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java
  4. +3
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/NewModelFromGitController.java
  5. +2
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/NewDatasetVo.java

+ 10
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/annotations/NeedApproval.java View File

@@ -0,0 +1,10 @@
package com.ruoyi.platform.annotations;

import java.lang.annotation.*;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface NeedApproval {
// 可以添加一些配置参数,如审批类型等
}

+ 63
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/annotations/aspect/ModelApprovalAspect.java View File

@@ -0,0 +1,63 @@
package com.ruoyi.platform.annotations.aspect;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.redis.service.RedisService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@Aspect
@Component
public class ModelApprovalAspect {
//
// // 注入审批服务(假设已存在)
// private final ApprovalService approvalService;
//
// public ModelApprovalAspect(ApprovalService approvalService) {
// this.approvalService = approvalService;
// }

@Autowired
private RedisService redisService;

@Around("@annotation(com.ruoyi.platform.annotations.NeedApproval)")
public Object checkApproval(ProceedingJoinPoint joinPoint) throws Throwable {
// 获取方法参数,第一个参数是模型对象
Object[] args = joinPoint.getArgs();
if (args.length == 0) {
return joinPoint.proceed();
}

Object model = args[0];

try {
Method getIsPublic = model.getClass().getMethod("getIsPublic");
Method getName = model.getClass().getMethod("getName");
Method getId = model.getClass().getMethod("getId");
boolean isPublic = (boolean) getIsPublic.invoke(model);
String name = (String) getIsPublic.invoke(getName);
int id = (int) getIsPublic.invoke(getId);

if (isPublic) {
Class<?> modelClass = model.getClass();
Field isApproved = modelClass.getDeclaredField("isApproved");
isApproved.setAccessible(false);
redisService.setCacheObject("ModelApproval_"+name+"_"+id, model);
// 公共模型,提交审批并阻止原方法执行
// approvalService.submitForApproval(model);
return AjaxResult.success("模型已提交审批");
} else {
// 个人模型,直接放行
return joinPoint.proceed();
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
return joinPoint.proceed();
}
}
}

+ 2
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java View File

@@ -2,6 +2,7 @@ package com.ruoyi.platform.controller.dataset;

import cn.hutool.core.collection.CollectionUtil;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.platform.annotations.NeedApproval;
import com.ruoyi.platform.domain.Dataset;
import com.ruoyi.platform.service.NewDatasetService;
import com.ruoyi.platform.utils.DVCUtils;
@@ -44,6 +45,7 @@ public class NewDatasetFromGitController {
*/
@PostMapping("/addDatasetAndVersion")
@ApiOperation("添加数据集和版本")
@NeedApproval
public AjaxResult addDatasetAndVersion(@RequestBody NewDatasetVo datasetVo) throws Exception {
return AjaxResult.success(this.newDatasetService.newCreateDataset(datasetVo));



+ 3
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/NewModelFromGitController.java View File

@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.domain.GenericsAjaxResult;
import com.ruoyi.platform.annotations.NeedApproval;
import com.ruoyi.platform.domain.ModelsVersion;
import com.ruoyi.platform.service.ModelsService;
import com.ruoyi.platform.vo.ModelsVo;
@@ -30,6 +31,7 @@ public class NewModelFromGitController extends BaseController {

@PostMapping("/addModel")
@ApiOperation("添加模型")
@NeedApproval
public GenericsAjaxResult<String> addModelAndVersion(@RequestBody ModelsVo modelsVo) {
return genericsSuccess(this.modelsService.newCreateModel(modelsVo));
}
@@ -143,6 +145,7 @@ public class NewModelFromGitController extends BaseController {
return AjaxResult.success();
}


@DeleteMapping("/deleteVersion")
@ApiOperation(value = "删除模型版本")
public AjaxResult deleteVersion(@RequestParam("id") Integer id, @RequestParam("identifier") String identifier, @RequestParam("owner") String owner, @RequestParam("version") String version


+ 2
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/NewDatasetVo.java View File

@@ -32,6 +32,8 @@ public class NewDatasetVo implements Serializable {
*/
@ApiModelProperty(name = "is_public", value = "是否公开1公开,0私有")
private Boolean isPublic;
@ApiModelProperty(name = "is_approved", value = "是否审批通过1通过,0不通过")
private Boolean isApproved;
@ApiModelProperty(name = "data_type",value = "数据集类型")
private String dataType;
@ApiModelProperty(name = "data_tag",value = "数据集标签")


Loading…
Cancel
Save