From 092ddc069ca0be3eba8fc8dd5e00e583b426cc0c Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Fri, 14 Feb 2020 17:43:15 +0800 Subject: [PATCH 1/2] TestResource CURD and getUserRoleList --- .../controller/TestResourceController.java | 36 +++++++++++++++ .../controller/UserController.java | 7 +++ .../service/TestResourceService.java | 44 +++++++++++++++++++ .../io/metersphere/service/UserService.java | 11 +++++ 4 files changed, 98 insertions(+) create mode 100644 backend/src/main/java/io/metersphere/controller/TestResourceController.java create mode 100644 backend/src/main/java/io/metersphere/service/TestResourceService.java diff --git a/backend/src/main/java/io/metersphere/controller/TestResourceController.java b/backend/src/main/java/io/metersphere/controller/TestResourceController.java new file mode 100644 index 0000000000..2f2b50b9ba --- /dev/null +++ b/backend/src/main/java/io/metersphere/controller/TestResourceController.java @@ -0,0 +1,36 @@ +package io.metersphere.controller; + +import io.metersphere.base.domain.TestResource; +import io.metersphere.service.TestResourceService; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +@RequestMapping("testresource") +@RestController +public class TestResourceController { + + @Resource + private TestResourceService testResourceService; + + @PostMapping("/add") + public TestResource addTestResource(@RequestBody TestResource testResource) { + return testResourceService.addTestResource(testResource); + } + + @GetMapping("/list/{testResourcePoolId}") + public List getTestResourceList(@PathVariable(value = "testResourcePoolId") String testResourcePoolId) { + return testResourceService.getTestResourceList(testResourcePoolId); + } + + @GetMapping("/delete/{testResourceId}") + public void deleteTestResource(@PathVariable(value = "testResourceId") String testResourceId) { + testResourceService.deleteTestResource(testResourceId); + } + + @PostMapping("/update") + public void updateTestResource(@RequestBody TestResource testResource) { + testResourceService.updateTestResource(testResource); + } +} diff --git a/backend/src/main/java/io/metersphere/controller/UserController.java b/backend/src/main/java/io/metersphere/controller/UserController.java index 6de2f5e69b..15b801b4be 100644 --- a/backend/src/main/java/io/metersphere/controller/UserController.java +++ b/backend/src/main/java/io/metersphere/controller/UserController.java @@ -1,7 +1,9 @@ package io.metersphere.controller; +import io.metersphere.base.domain.Role; import io.metersphere.base.domain.User; import io.metersphere.dto.UserDTO; +import io.metersphere.dto.UserOperateDTO; import io.metersphere.service.UserService; import org.springframework.web.bind.annotation.*; @@ -28,4 +30,9 @@ public class UserController { @PostMapping("/update") public void updateUser(@RequestBody User user) { userService.updateUser(user); } + + @GetMapping("/role/list/{userId}") + public List getUserRolesList(@PathVariable(value = "userId") String userId) { + return userService.getUserRolesList(userId); + } } diff --git a/backend/src/main/java/io/metersphere/service/TestResourceService.java b/backend/src/main/java/io/metersphere/service/TestResourceService.java new file mode 100644 index 0000000000..b74c8bfdc2 --- /dev/null +++ b/backend/src/main/java/io/metersphere/service/TestResourceService.java @@ -0,0 +1,44 @@ +package io.metersphere.service; + +import io.metersphere.base.domain.TestResource; +import io.metersphere.base.domain.TestResourceExample; +import io.metersphere.base.mapper.TestResourceMapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; +import java.util.UUID; + +@Service +@Transactional(rollbackFor = Exception.class) +public class TestResourceService { + + @Resource + private TestResourceMapper testResourceMapper; + + public TestResource addTestResource(TestResource testResource) { + testResource.setId(UUID.randomUUID().toString()); + testResource.setStatus("1"); + testResource.setCreateTime(System.currentTimeMillis()); + testResource.setUpdateTime(System.currentTimeMillis()); + testResourceMapper.insertSelective(testResource); + return testResource; + } + + public List getTestResourceList(String testResourcePoolId) { + TestResourceExample testResourceExample = new TestResourceExample(); + testResourceExample.createCriteria().andTestResourcePoolIdEqualTo(testResourcePoolId); + List testResources = testResourceMapper.selectByExampleWithBLOBs(testResourceExample); + return testResources; + } + + public void deleteTestResource(String testResourceId) { + testResourceMapper.deleteByPrimaryKey(testResourceId); + } + + public void updateTestResource(TestResource testResource) { + testResource.setUpdateTime(System.currentTimeMillis()); + testResourceMapper.updateByPrimaryKeySelective(testResource); + } +} diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index 40dd7bbb7a..50589d6232 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -6,6 +6,7 @@ import io.metersphere.base.mapper.UserMapper; import io.metersphere.base.mapper.UserRoleMapper; import io.metersphere.commons.exception.MSException; import io.metersphere.dto.UserDTO; +import io.metersphere.dto.UserOperateDTO; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; @@ -102,4 +103,14 @@ public class UserService { user.setUpdateTime(System.currentTimeMillis()); userMapper.updateByPrimaryKeySelective(user); } + + public List getUserRolesList(String userId) { + UserRoleExample userRoleExample = new UserRoleExample(); + userRoleExample.createCriteria().andUserIdEqualTo(userId); + List userRolesList = userRoleMapper.selectByExample(userRoleExample); + List roleIds = userRolesList.stream().map(UserRole::getRoleId).collect(Collectors.toList()); + RoleExample roleExample = new RoleExample(); + roleExample.createCriteria().andIdIn(roleIds); + return roleMapper.selectByExample(roleExample); + } } From 361ea39dd137474cb2539108b0a0fc3c71fb5897 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Fri, 14 Feb 2020 21:18:47 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0v-permission=E6=8C=87?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/settings/SettingMenu.vue | 6 ++--- frontend/src/performance/main.js | 6 ++++- frontend/src/performance/permission.js | 23 +++++++++++++++++-- frontend/src/performance/store.js | 13 ++++++++++- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/frontend/src/performance/components/settings/SettingMenu.vue b/frontend/src/performance/components/settings/SettingMenu.vue index 0fd7cd8bf1..c0f3bf6b0f 100644 --- a/frontend/src/performance/components/settings/SettingMenu.vue +++ b/frontend/src/performance/components/settings/SettingMenu.vue @@ -5,9 +5,9 @@