最新一版2.0

pull/3/head
zmyYYDS 2023-12-21 11:48:40 +08:00
parent 8e16bf16a9
commit dd88506d9e
3 changed files with 45 additions and 4 deletions

View File

@ -10,10 +10,7 @@ import net.srt.framework.common.utils.Result;
import net.srt.framework.common.utils.TreeNodeVo; import net.srt.framework.common.utils.TreeNodeVo;
import net.srt.service.MetamodelService; import net.srt.service.MetamodelService;
import net.srt.vo.MetamodelVO; import net.srt.vo.MetamodelVO;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
@ -38,4 +35,11 @@ public class MetamodelController {
MetamodelEntity entity = metamodelService.getById(id); MetamodelEntity entity = metamodelService.getById(id);
return Result.ok(MetamodelConvert.INSTANCE.convert(entity)); return Result.ok(MetamodelConvert.INSTANCE.convert(entity));
} }
@PostMapping
@Operation(summary = "保存")
public Result<String> save(@RequestBody MetamodelVO vo){
metamodelService.save(vo);
return Result.ok();
}
} }

View File

@ -3,9 +3,12 @@ package net.srt.service;
import net.srt.entity.MetamodelEntity; import net.srt.entity.MetamodelEntity;
import net.srt.framework.common.utils.TreeNodeVo; import net.srt.framework.common.utils.TreeNodeVo;
import net.srt.framework.mybatis.service.BaseService; import net.srt.framework.mybatis.service.BaseService;
import net.srt.vo.MetamodelVO;
import java.util.List; import java.util.List;
public interface MetamodelService extends BaseService<MetamodelEntity> { public interface MetamodelService extends BaseService<MetamodelEntity> {
List<TreeNodeVo> listTree(); List<TreeNodeVo> listTree();
void save(MetamodelVO vo);
} }

View File

@ -1,6 +1,7 @@
package net.srt.service.impl; package net.srt.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import net.srt.convert.MetamodelConvert;
import net.srt.dao.MetamodelDao; import net.srt.dao.MetamodelDao;
import net.srt.entity.MetamodelEntity; import net.srt.entity.MetamodelEntity;
import net.srt.framework.common.utils.BeanUtil; import net.srt.framework.common.utils.BeanUtil;
@ -8,7 +9,9 @@ import net.srt.framework.common.utils.BuildTreeUtils;
import net.srt.framework.common.utils.TreeNodeVo; import net.srt.framework.common.utils.TreeNodeVo;
import net.srt.framework.mybatis.service.impl.BaseServiceImpl; import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
import net.srt.service.MetamodelService; import net.srt.service.MetamodelService;
import net.srt.vo.MetamodelVO;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import srt.cloud.framework.dbswitch.common.util.StringUtil;
import java.util.List; import java.util.List;
@Service @Service
@ -32,4 +35,35 @@ public class MetamodelServiceImpl extends BaseServiceImpl<MetamodelDao, Metamode
}); });
return BuildTreeUtils.buildTree(treeNodeVos); return BuildTreeUtils.buildTree(treeNodeVos);
} }
@Override
public void save(MetamodelVO vo) {
MetamodelEntity entity = MetamodelConvert.INSTANCE.convert(vo);
entity.setPath(recursionPath(entity,null));
entity.setProjectId(getProjectId());
entity.setBuiltin(0);
buildField(entity);
baseMapper.insert(entity);
}
private void buildField(MetamodelEntity entity) {
if(entity.getIfLeaf() == 0){
entity.setIcon("/src/assets/model.png");
}else {
entity.setIcon("/src/assets/folder.png");
}
}
private String recursionPath(MetamodelEntity metamodelEntity,String path){
if(StringUtil.isBlank(path)){
path = metamodelEntity.getName();
}
if(metamodelEntity.getParentId()!=0){
MetamodelEntity parent = getById(metamodelEntity.getParentId());
path = parent.getName() + "/" + path;
return recursionPath(parent,path);
}
return path;
}
} }