|
|
|
@@ -47,7 +47,7 @@ public class ComponentServiceImpl implements ComponentService { |
|
|
|
@Override |
|
|
|
public Component queryById(Integer id) { |
|
|
|
Component component = this.componentDao.queryById(id); |
|
|
|
if (component == null){ |
|
|
|
if (component == null) { |
|
|
|
throw new RuntimeException("组件不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -58,14 +58,14 @@ public class ComponentServiceImpl implements ComponentService { |
|
|
|
public List<Map> queryAllGroupedByCategory() throws Exception { |
|
|
|
List<Component> componentList = this.componentDao.queryAll(); |
|
|
|
List<Map> result = new ArrayList<>(); |
|
|
|
if (componentList.isEmpty()){ |
|
|
|
if (componentList.isEmpty()) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
List<SysDictData> categoryTypeList = DictUtils.getDictCache("category_type"); |
|
|
|
Map<Integer,List<Component>> groupedComponent = componentList.stream().collect(Collectors.groupingBy(Component::getCategoryId)); |
|
|
|
for (Map.Entry <Integer,List<Component>> entry : groupedComponent.entrySet()) { |
|
|
|
Map<Integer, List<Component>> groupedComponent = componentList.stream().collect(Collectors.groupingBy(Component::getCategoryId)); |
|
|
|
for (Map.Entry<Integer, List<Component>> entry : groupedComponent.entrySet()) { |
|
|
|
List<SysDictData> categorys = categoryTypeList.stream().filter(sysDictData -> StringUtils.equals(sysDictData.getDictValue(), String.valueOf(entry.getKey()))).collect(Collectors.toList()); |
|
|
|
if (categorys.size() ==0){ |
|
|
|
if (categorys.size() == 0) { |
|
|
|
throw new Exception("组件类型不存在"); |
|
|
|
} |
|
|
|
Map map = new HashMap(); |
|
|
|
@@ -80,8 +80,8 @@ public class ComponentServiceImpl implements ComponentService { |
|
|
|
/** |
|
|
|
* 分页查询 |
|
|
|
* |
|
|
|
* @param component 筛选条件 |
|
|
|
* @param pageRequest 分页对象 |
|
|
|
* @param component 筛选条件 |
|
|
|
* @param pageRequest 分页对象 |
|
|
|
* @return 查询结果 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@@ -104,7 +104,7 @@ public class ComponentServiceImpl implements ComponentService { |
|
|
|
component.setControlStrategy(controlStrategy); |
|
|
|
|
|
|
|
//json转换,存数据库 |
|
|
|
String inParameters= gson.toJson(componentVo.getInParameters(), LinkedHashMap.class); |
|
|
|
String inParameters = gson.toJson(componentVo.getInParameters(), LinkedHashMap.class); |
|
|
|
String outParameters = gson.toJson(componentVo.getOutParameters(), LinkedHashMap.class); |
|
|
|
String envVariable = gson.toJson(componentVo.getEnvVirables(), LinkedHashMap.class); |
|
|
|
component.setEnvVirables(envVariable); |
|
|
|
@@ -118,9 +118,9 @@ public class ComponentServiceImpl implements ComponentService { |
|
|
|
component.setState(1); |
|
|
|
|
|
|
|
// 检查相同category_id下的component_name是否已存在 |
|
|
|
Integer existingCount = this.componentDao.countByNameAndCategoryId(component.getComponentName(),component.getCategoryId()); |
|
|
|
Integer existingCount = this.componentDao.countByNameAndCategoryId(component.getComponentName(), component.getCategoryId()); |
|
|
|
|
|
|
|
if(existingCount != null && existingCount > 0) { |
|
|
|
if (existingCount != null && existingCount > 0) { |
|
|
|
throw new RuntimeException("该类别下已有同名组件"); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -139,15 +139,15 @@ public class ComponentServiceImpl implements ComponentService { |
|
|
|
Component component = this.queryById(componentVo.getId()); |
|
|
|
//只能更新当前存在的组件 |
|
|
|
|
|
|
|
if (component == null){ |
|
|
|
if (component == null) { |
|
|
|
throw new RuntimeException("组件不存在,无法更新"); |
|
|
|
} |
|
|
|
|
|
|
|
//将object转成string类型 |
|
|
|
component = ConvertUtil.entityToVo(componentVo,Component.class); |
|
|
|
component = ConvertUtil.entityToVo(componentVo, Component.class); |
|
|
|
Gson gson = new Gson(); |
|
|
|
|
|
|
|
String inParameters= gson.toJson(componentVo.getInParameters(), LinkedHashMap.class); |
|
|
|
String inParameters = gson.toJson(componentVo.getInParameters(), LinkedHashMap.class); |
|
|
|
String outParameters = gson.toJson(componentVo.getOutParameters(), LinkedHashMap.class); |
|
|
|
|
|
|
|
String envVariable = gson.toJson(componentVo.getEnvVirables(), LinkedHashMap.class); |
|
|
|
@@ -174,24 +174,24 @@ public class ComponentServiceImpl implements ComponentService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String removeById(Integer id) { |
|
|
|
public String removeById(Integer id) throws Exception { |
|
|
|
Component component = this.componentDao.queryById(id); |
|
|
|
//先进行判断 组件是否存在 |
|
|
|
|
|
|
|
if (component == null ){ |
|
|
|
return "组件不存在"; |
|
|
|
if (component == null) { |
|
|
|
throw new Exception("组件不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
//判断权限,只有admin和创建者本身可以删除该组件 |
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser(); |
|
|
|
String username = loginUser.getUsername(); |
|
|
|
String createdBy = component.getCreateBy(); |
|
|
|
if (!(StringUtils.equals(username,"admin") || StringUtils.equals(username,createdBy))){ |
|
|
|
return "无权限删除该组件"; |
|
|
|
if (!(StringUtils.equals(username, "admin") || StringUtils.equals(username, createdBy))) { |
|
|
|
throw new Exception("无权限删除该组件"); |
|
|
|
} |
|
|
|
|
|
|
|
component.setState(0); |
|
|
|
return this.componentDao.update(component)>0?"删除成功":"删除失败"; |
|
|
|
return this.componentDao.update(component) > 0 ? "删除成功" : "删除失败"; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|