TestResource CURD and getUserRoleList
This commit is contained in:
parent
70becf8c29
commit
092ddc069c
|
@ -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<TestResource> 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);
|
||||
}
|
||||
}
|
|
@ -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<Role> getUserRolesList(@PathVariable(value = "userId") String userId) {
|
||||
return userService.getUserRolesList(userId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<TestResource> getTestResourceList(String testResourcePoolId) {
|
||||
TestResourceExample testResourceExample = new TestResourceExample();
|
||||
testResourceExample.createCriteria().andTestResourcePoolIdEqualTo(testResourcePoolId);
|
||||
List<TestResource> 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);
|
||||
}
|
||||
}
|
|
@ -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<Role> getUserRolesList(String userId) {
|
||||
UserRoleExample userRoleExample = new UserRoleExample();
|
||||
userRoleExample.createCriteria().andUserIdEqualTo(userId);
|
||||
List<UserRole> userRolesList = userRoleMapper.selectByExample(userRoleExample);
|
||||
List<String> roleIds = userRolesList.stream().map(UserRole::getRoleId).collect(Collectors.toList());
|
||||
RoleExample roleExample = new RoleExample();
|
||||
roleExample.createCriteria().andIdIn(roleIds);
|
||||
return roleMapper.selectByExample(roleExample);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue