|
|
@ -59,6 +59,7 @@ import org.apache.commons.lang.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.text.MessageFormat; |
|
|
|
import java.text.MessageFormat; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
@ -578,6 +579,62 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService { |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* grant project by code |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param loginUser login user |
|
|
|
|
|
|
|
* @param userId user id |
|
|
|
|
|
|
|
* @param projectCodes project code array |
|
|
|
|
|
|
|
* @return grant result code |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Map<String, Object> grantProjectByCode(final User loginUser, final int userId, final String projectCodes) { |
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
|
|
result.put(Constants.STATUS, false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 1. only admin can operate
|
|
|
|
|
|
|
|
if (this.check(result, !this.isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. check if user is existed
|
|
|
|
|
|
|
|
User tempUser = this.userMapper.selectById(userId); |
|
|
|
|
|
|
|
if (tempUser == null) { |
|
|
|
|
|
|
|
putMsg(result, Status.USER_NOT_EXIST, userId); |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3. if the selected projectCodes are empty, delete all items associated with the user
|
|
|
|
|
|
|
|
if (this.check(result, StringUtils.isEmpty(projectCodes), Status.SUCCESS)) { |
|
|
|
|
|
|
|
this.projectUserMapper.deleteProjectRelation(0, userId); |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4. maintain the relationship between project and user
|
|
|
|
|
|
|
|
Set<Long> projectCodeSet = Arrays.stream(projectCodes.split(Constants.COMMA)).map(Long::parseLong).collect(Collectors.toSet()); |
|
|
|
|
|
|
|
final List<Project> projectList = this.projectMapper.queryByCodes(projectCodeSet); |
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(projectList)) { |
|
|
|
|
|
|
|
logger.info("project not exists"); |
|
|
|
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUNT, projectCodes); |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (final Project project : projectList) { |
|
|
|
|
|
|
|
final Date today = new Date(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ProjectUser projectUser = new ProjectUser(); |
|
|
|
|
|
|
|
projectUser.setUserId(userId); |
|
|
|
|
|
|
|
projectUser.setProjectId(project.getId()); |
|
|
|
|
|
|
|
projectUser.setPerm(7); |
|
|
|
|
|
|
|
projectUser.setCreateTime(today); |
|
|
|
|
|
|
|
projectUser.setUpdateTime(today); |
|
|
|
|
|
|
|
this.projectUserMapper.insert(projectUser); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* grant resource |
|
|
|
* grant resource |
|
|
|
* |
|
|
|
* |
|
|
|