组织,工作空间同名检查
This commit is contained in:
parent
e4d1046152
commit
c727bf356c
|
@ -48,16 +48,7 @@ public class OrganizationService {
|
|||
private UserService userService;
|
||||
|
||||
public Organization addOrganization(Organization organization) {
|
||||
if (StringUtils.isBlank(organization.getName())) {
|
||||
MSException.throwException(Translator.get("organization_name_is_null"));
|
||||
}
|
||||
|
||||
OrganizationExample organizationExample = new OrganizationExample();
|
||||
organizationExample.createCriteria().andNameEqualTo(organization.getName());
|
||||
if (organizationMapper.countByExample(organizationExample) > 0) {
|
||||
MSException.throwException(Translator.get("organization_name_already_exists"));
|
||||
}
|
||||
|
||||
checkOrgNameRepeat(organization);
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
organization.setId(UUID.randomUUID().toString());
|
||||
organization.setCreateTime(currentTimeMillis);
|
||||
|
@ -75,6 +66,17 @@ public class OrganizationService {
|
|||
return organizationMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
private void checkOrgNameRepeat(Organization organization) {
|
||||
if (StringUtils.isBlank(organization.getName())) {
|
||||
MSException.throwException(Translator.get("organization_name_is_null"));
|
||||
}
|
||||
OrganizationExample organizationExample = new OrganizationExample();
|
||||
organizationExample.createCriteria().andNameEqualTo(organization.getName());
|
||||
if (organizationMapper.countByExample(organizationExample) > 0) {
|
||||
MSException.throwException(Translator.get("organization_name_already_exists"));
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteOrganization(String organizationId) {
|
||||
WorkspaceExample example = new WorkspaceExample();
|
||||
WorkspaceExample.Criteria criteria = example.createCriteria();
|
||||
|
@ -97,6 +99,7 @@ public class OrganizationService {
|
|||
}
|
||||
|
||||
public void updateOrganization(Organization organization) {
|
||||
checkOrgNameRepeat(organization);
|
||||
organization.setCreateTime(null);
|
||||
organization.setUpdateTime(System.currentTimeMillis());
|
||||
organizationMapper.updateByPrimaryKeySelective(organization);
|
||||
|
|
|
@ -58,14 +58,16 @@ public class WorkspaceService {
|
|||
workspace.setOrganizationId(SessionUtils.getCurrentOrganizationId());
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
WorkspaceExample example = new WorkspaceExample();
|
||||
example.createCriteria()
|
||||
.andOrganizationIdEqualTo(SessionUtils.getCurrentOrganizationId())
|
||||
.andNameEqualTo(workspace.getName());
|
||||
if (workspaceMapper.countByExample(example) > 0) {
|
||||
MSException.throwException(Translator.get("workspace_name_already_exists"));
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(workspace.getId())) {
|
||||
WorkspaceExample example = new WorkspaceExample();
|
||||
example.createCriteria()
|
||||
.andOrganizationIdEqualTo(SessionUtils.getCurrentOrganizationId())
|
||||
.andNameEqualTo(workspace.getName());
|
||||
if (workspaceMapper.countByExample(example) > 0) {
|
||||
MSException.throwException(Translator.get("workspace_name_already_exists"));
|
||||
}
|
||||
workspace.setId(UUID.randomUUID().toString());
|
||||
workspace.setCreateTime(currentTime);
|
||||
workspace.setUpdateTime(currentTime);
|
||||
|
@ -235,12 +237,21 @@ public class WorkspaceService {
|
|||
}
|
||||
|
||||
public void updateWorkspaceByAdmin(Workspace workspace) {
|
||||
checkWorkspace(workspace);
|
||||
workspace.setCreateTime(null);
|
||||
workspace.setUpdateTime(System.currentTimeMillis());
|
||||
workspaceMapper.updateByPrimaryKeySelective(workspace);
|
||||
}
|
||||
|
||||
public void addWorkspaceByAdmin(Workspace workspace) {
|
||||
checkWorkspace(workspace);
|
||||
workspace.setId(UUID.randomUUID().toString());
|
||||
workspace.setCreateTime(System.currentTimeMillis());
|
||||
workspace.setUpdateTime(System.currentTimeMillis());
|
||||
workspaceMapper.insertSelective(workspace);
|
||||
}
|
||||
|
||||
private void checkWorkspace(Workspace workspace) {
|
||||
if (StringUtils.isBlank(workspace.getName())) {
|
||||
MSException.throwException(Translator.get("workspace_name_is_null"));
|
||||
}
|
||||
|
@ -254,9 +265,5 @@ public class WorkspaceService {
|
|||
if (workspaceMapper.countByExample(example) > 0) {
|
||||
MSException.throwException(Translator.get("workspace_name_already_exists"));
|
||||
}
|
||||
workspace.setId(UUID.randomUUID().toString());
|
||||
workspace.setCreateTime(System.currentTimeMillis());
|
||||
workspace.setUpdateTime(System.currentTimeMillis());
|
||||
workspaceMapper.insertSelective(workspace);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue