Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
wenyann 2020-06-02 18:14:25 +08:00
commit 8b1150a33b
4 changed files with 42 additions and 52 deletions

View File

@ -77,27 +77,18 @@ public class TestResourcePoolService {
MSException.throwException(Translator.get("test_resource_pool_name_is_null"));
}
String id = testResourcePoolDTO.getId();
String name = testResourcePoolDTO.getName();
if (StringUtils.isNotBlank(id)) {
TestResourcePool pool = testResourcePoolMapper.selectByPrimaryKey(id);
if (!StringUtils.equals(pool.getName(), name)) {
checkPoolName(name);
}
} else {
checkPoolName(name);
TestResourcePoolExample example = new TestResourcePoolExample();
TestResourcePoolExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(resourcePoolName);
if (StringUtils.isNotBlank(testResourcePoolDTO.getId())) {
criteria.andIdNotEqualTo(testResourcePoolDTO.getId());
}
}
public void checkPoolName(String poolName) {
TestResourcePoolExample testResourcePoolExample = new TestResourcePoolExample();
testResourcePoolExample.createCriteria().andNameEqualTo(poolName);
if (testResourcePoolMapper.countByExample(testResourcePoolExample) > 0) {
if (testResourcePoolMapper.countByExample(example) > 0) {
MSException.throwException(Translator.get("test_resource_pool_name_already_exists"));
}
}
}
public void updateTestResourcePoolStatus(String poolId, String status) {
TestResourcePool testResourcePool = testResourcePoolMapper.selectByPrimaryKey(poolId);

View File

@ -92,7 +92,6 @@ public class UserService {
userRole1.setUpdateTime(System.currentTimeMillis());
userRole1.setCreateTime(System.currentTimeMillis());
userRole1.setSourceId(list.get(j));
// TODO 防止重复插入
userRoleMapper.insertSelective(userRole1);
}
}
@ -196,15 +195,15 @@ public class UserService {
if (!roles.isEmpty()) {
insertUserRole(roles, user.getId());
}
String email = user.getEmail();
User u = userMapper.selectByPrimaryKey(userId);
if (!StringUtils.equals(email, u.getEmail())) {
UserExample userExample = new UserExample();
userExample.createCriteria().andEmailEqualTo(email);
if (userMapper.countByExample(userExample) > 0) {
MSException.throwException(Translator.get("user_email_already_exists"));
}
UserExample example = new UserExample();
UserExample.Criteria criteria = example.createCriteria();
criteria.andEmailEqualTo(user.getEmail());
criteria.andIdNotEqualTo(user.getId());
if (userMapper.countByExample(example) > 0) {
MSException.throwException(Translator.get("user_email_already_exists"));
}
user.setUpdateTime(System.currentTimeMillis());
userMapper.updateByPrimaryKeySelective(user);
}

View File

@ -59,35 +59,21 @@ public class WorkspaceService {
workspace.setOrganizationId(currentOrgId);
long currentTime = System.currentTimeMillis();
String wsName = workspace.getName();
checkWorkspace(workspace);
if (StringUtils.isBlank(workspace.getId())) {
checkWsName(wsName, currentOrgId);
workspace.setId(UUID.randomUUID().toString());
workspace.setCreateTime(currentTime);
workspace.setUpdateTime(currentTime);
workspaceMapper.insertSelective(workspace);
} else {
Workspace ws = workspaceMapper.selectByPrimaryKey(workspace.getId());
if (!StringUtils.equals(ws.getName(), wsName)) {
checkWsName(wsName, currentOrgId);
}
workspace.setUpdateTime(currentTime);
workspaceMapper.updateByPrimaryKeySelective(workspace);
}
return workspace;
}
public void checkWsName(String wsName, String orgId) {
WorkspaceExample example = new WorkspaceExample();
example.createCriteria()
.andOrganizationIdEqualTo(orgId)
.andNameEqualTo(wsName);
if (workspaceMapper.countByExample(example) > 0) {
MSException.throwException(Translator.get("workspace_name_already_exists"));
}
}
public List<Workspace> getWorkspaceList(WorkspaceRequest request) {
WorkspaceExample example = new WorkspaceExample();
WorkspaceExample.Criteria criteria = example.createCriteria();
@ -269,17 +255,17 @@ public class WorkspaceService {
MSException.throwException(Translator.get("organization_id_is_null"));
}
String id = workspace.getId();
String orgId = workspace.getOrganizationId();
String name = workspace.getName();
if (StringUtils.isNotBlank(id)) {
Workspace ws = workspaceMapper.selectByPrimaryKey(id);
if (!StringUtils.equals(ws.getName(), name)) {
checkWsName(name, orgId);
}
} else {
checkWsName(name, orgId);
WorkspaceExample example = new WorkspaceExample();
WorkspaceExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(workspace.getName())
.andOrganizationIdEqualTo(workspace.getOrganizationId());
if (StringUtils.isNotBlank(workspace.getId())) {
criteria.andIdNotEqualTo(workspace.getId());
}
if (workspaceMapper.countByExample(example) > 0) {
MSException.throwException(Translator.get("workspace_name_already_exists"));
}
}
}

View File

@ -15,6 +15,20 @@ VALUES ('test_user', '测试人员', NULL, NULL, 1581576575948, 1581576575948);
INSERT INTO role (id, name, description, type, create_time, update_time)
VALUES ('test_viewer', 'Viewer', NULL, NULL, 1581576575948, 1581576575948);
INSERT INTO organization (id, name, description, create_time, update_time)
VALUES (uuid(), '默认组织', '系统默认创建的组织', 1581576575948, 1581576575948);
INSERT INTO workspace (id, organization_id, name, description, create_time, update_time)
VALUES (uuid(), (select id from organization where name like '默认组织'), '默认工作空间', '系统默认创建的工作空间', 1581576575948, 1581576575948);
INSERT INTO user_role (id, user_id, role_id, source_id, create_time, update_time)
VALUES (uuid(), 'admin', 'org_admin', (select id from organization where name like '默认组织'), 1581576575948, 1581576575948);
INSERT INTO user_role (id, user_id, role_id, source_id, create_time, update_time)
VALUES (uuid(), 'admin', 'test_manager', (select id from workspace where name like '默认工作空间'), 1581576575948, 1581576575948);
INSERT INTO test_resource_pool (id, name, type, description, status, create_time, update_time)
VALUES (uuid(), 'LOCAL', 'NODE', '系统默认创建的本地资源池', 'VALID', 1581576575948, 1581576575948);
INSERT INTO test_resource (id, test_resource_pool_id, configuration, status, create_time, update_time)
VALUES (uuid(), (select id from test_resource_pool where name like 'LOCAL'), 'GgC8aAZVAsiNDdnvp4gobdv1iwAvloLCAaeqb7Ms1VaLzW+iXHsFhGg8ZaPEk53W6xA5A6g+UUUxbKvU2s7yZw==', 'VALID', 1581576575948, 1581576575948);
INSERT INTO test_case_report_template (id, name, content)
VALUES (uuid(), 'default', '{\"components\": [1,2,3,4,5]}');
INSERT INTO system_parameter (param_key, param_value, type, sort)