|
|
@@ -139,10 +139,15 @@ public class OrganizationService {
|
|
|
user.setDepartmentId(Long.valueOf(body.get("departmentId").toString()));
|
|
|
if (body.containsKey("superiorId") && body.get("superiorId") != null)
|
|
|
user.setSuperiorId(Long.valueOf(body.get("superiorId").toString()));
|
|
|
- if (body.containsKey("role") && "SUPER_ADMIN".equals(body.get("role").toString()))
|
|
|
- user.setRole(UserRole.SUPER_ADMIN);
|
|
|
- else
|
|
|
+ if (body.containsKey("role") && body.get("role") != null) {
|
|
|
+ try {
|
|
|
+ user.setRole(UserRole.valueOf(body.get("role").toString()));
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ throw new BusinessException("无效角色: " + body.get("role"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
user.setRole(UserRole.EMPLOYEE);
|
|
|
+ }
|
|
|
userMapper.insert(user);
|
|
|
return UserInfo.from(user);
|
|
|
}
|
|
|
@@ -156,8 +161,13 @@ public class OrganizationService {
|
|
|
user.setDepartmentId(Long.valueOf(body.get("departmentId").toString()));
|
|
|
if (body.containsKey("superiorId") && body.get("superiorId") != null)
|
|
|
user.setSuperiorId(Long.valueOf(body.get("superiorId").toString()));
|
|
|
- if (body.containsKey("role"))
|
|
|
- user.setRole("SUPER_ADMIN".equals(body.get("role").toString()) ? UserRole.SUPER_ADMIN : UserRole.EMPLOYEE);
|
|
|
+ if (body.containsKey("role")) {
|
|
|
+ try {
|
|
|
+ user.setRole(UserRole.valueOf(body.get("role").toString()));
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ throw new BusinessException("无效角色: " + body.get("role"));
|
|
|
+ }
|
|
|
+ }
|
|
|
if (body.containsKey("password") && !body.get("password").toString().isEmpty())
|
|
|
user.setPasswordHash(passwordEncoder.encode(body.get("password").toString()));
|
|
|
userMapper.updateById(user);
|