|
|
@ -21,7 +21,7 @@ import java.util.List; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class) |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
|
|
|
public class ProRoleService implements IProRoleService { |
|
|
|
@Autowired |
|
|
|
private ProRoleDao proRoleDao; |
|
|
@ -50,7 +50,7 @@ public class ProRoleService implements IProRoleService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<ProRole> getProRoleByProjectIdAndUserId(Long projectId, Long currentUserId) { |
|
|
|
return proRoleDao.selectFirstRoleByProjectIdAndUserId(projectId,currentUserId); |
|
|
|
return proRoleDao.selectFirstRoleByProjectIdAndUserId(projectId, currentUserId); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -63,11 +63,24 @@ public class ProRoleService implements IProRoleService { |
|
|
|
memberRoleList = getRealMemberRolesByProjectId(projectId); |
|
|
|
//获取用户在项目中的角色
|
|
|
|
List<ProRole> roleList = proMemberService.selectRolesByUserIdAndProjectId(currentUserId, projectId); |
|
|
|
//是否mine
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(memberRoleList)) { |
|
|
|
for (ProjectVo.RoleInfo memberRole : memberRoleList) { |
|
|
|
if (ObjectUtil.isNotNull(roleList)) { |
|
|
|
for(ProRole role:roleList){ |
|
|
|
if (CollectionUtil.isNotEmpty(roleList)) { |
|
|
|
//用户是否只是关注者
|
|
|
|
Boolean isAttention = false; |
|
|
|
if(roleList.size() == 1){ |
|
|
|
ProRole role = roleList.get(0); |
|
|
|
if(role.getName().equalsIgnoreCase(WebConstant.ROLE_NAME.Attention.phase)){ |
|
|
|
isAttention = true; |
|
|
|
} |
|
|
|
} |
|
|
|
//是否mine(若是用户是关注者,则所有角色都暂时属于关注者)
|
|
|
|
for (ProjectVo.RoleInfo memberRole : memberRoleList) { |
|
|
|
if(isAttention){ |
|
|
|
memberRole.setMine(true); |
|
|
|
continue; |
|
|
|
} |
|
|
|
for (ProRole role : roleList) { |
|
|
|
if (memberRole.getId().equals(role.getId())) { |
|
|
|
memberRole.setMine(true); |
|
|
|
break; |
|
|
@ -76,39 +89,35 @@ public class ProRoleService implements IProRoleService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//排除该角色不能看的其他角色
|
|
|
|
// List<Long> carelessMemberRoleList = getCareLessRoleByProjectIdAndUserId(projectId, currentUserId);
|
|
|
|
List<Long> excludeIdList = new ArrayList<>(); |
|
|
|
if(CollectionUtil.isNotEmpty(roleList)){ |
|
|
|
for(ProRole role :roleList){ |
|
|
|
ProRoleExcludeExample excludeExample = new ProRoleExcludeExample(); |
|
|
|
excludeExample.createCriteria().andOtherRoleIdEqualTo(role.getId()); |
|
|
|
List<ProRoleExclude> excludeList = excludeDao.selectByExample(excludeExample); |
|
|
|
if(CollectionUtil.isNotEmpty(excludeList)){ |
|
|
|
for(ProRoleExclude roleExclude : excludeList){ |
|
|
|
excludeIdList.add(roleExclude.getRoleId()); |
|
|
|
//排除该角色不能看的其他角色
|
|
|
|
List<Long> excludeIdList = new ArrayList<>(); |
|
|
|
for (ProRole role : roleList) { |
|
|
|
ProRoleExcludeExample excludeExample = new ProRoleExcludeExample(); |
|
|
|
excludeExample.createCriteria().andOtherRoleIdEqualTo(role.getId()); |
|
|
|
List<ProRoleExclude> excludeList = excludeDao.selectByExample(excludeExample); |
|
|
|
if (CollectionUtil.isNotEmpty(excludeList)) { |
|
|
|
for (ProRoleExclude roleExclude : excludeList) { |
|
|
|
excludeIdList.add(roleExclude.getRoleId()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(excludeIdList)) { |
|
|
|
for (Long otherRoleId : excludeIdList) { |
|
|
|
for (ProjectVo.RoleInfo memberRole : memberRoleList) { |
|
|
|
if (otherRoleId.longValue() == memberRole.getId().longValue()) { |
|
|
|
if(!memberRole.isMine()){ |
|
|
|
memberRoleList.remove(memberRole); |
|
|
|
if (CollectionUtil.isNotEmpty(excludeIdList)) { |
|
|
|
for (Long otherRoleId : excludeIdList) { |
|
|
|
for (ProjectVo.RoleInfo memberRole : memberRoleList) { |
|
|
|
if (otherRoleId.longValue() == memberRole.getId().longValue()) { |
|
|
|
//若是关注者,正常删除。若不是关注者,不删除自己所属的角色
|
|
|
|
if(isAttention){ |
|
|
|
memberRoleList.remove(memberRole); |
|
|
|
}else if (!memberRole.isMine()) { |
|
|
|
memberRoleList.remove(memberRole); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//是否PM
|
|
|
|
if (CollectionUtil.isNotEmpty(memberRoleList)) { |
|
|
|
//是否PM
|
|
|
|
for (ProjectVo.RoleInfo memberRole : memberRoleList) { |
|
|
|
ProRole parentRole = proRoleDao.selectByPrimaryKey(memberRole.getParentId()); |
|
|
|
if (parentRole.getName().equalsIgnoreCase(WebConstant.ROLE_NAME.PM.value)) { |
|
|
@ -117,25 +126,22 @@ public class ProRoleService implements IProRoleService { |
|
|
|
memberRole.setPm(false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//奖惩干系人信息
|
|
|
|
if (CollectionUtil.isNotEmpty(memberRoleList)) { |
|
|
|
//奖惩干系人信息
|
|
|
|
for (ProjectVo.RoleInfo memberRole : memberRoleList) { |
|
|
|
if (CollectionUtil.isNotEmpty(memberRole.getMembers())) { |
|
|
|
for (ProjectVo.ProMemberVo member : memberRole.getMembers()) { |
|
|
|
String mAccount = userService.selectAccountByPhone(member.getMPhone()); |
|
|
|
member.setMUsername(mAccount); |
|
|
|
//查找奖惩干系人
|
|
|
|
if(ObjectUtil.isNotNull(member.getStakeholderId())) { |
|
|
|
if (ObjectUtil.isNotNull(member.getStakeholderId())) { |
|
|
|
ProMember stakeholder = proMemberDao.selectByPrimaryKey(member.getStakeholderId()); |
|
|
|
if(ObjectUtil.isNotNull(stakeholder)){ |
|
|
|
if (ObjectUtil.isNotNull(stakeholder)) { |
|
|
|
member.setSId(stakeholder.getId()); |
|
|
|
member.setSName(stakeholder.getNickname()); |
|
|
|
member.setMPhone(stakeholder.getPhone()); |
|
|
|
String stakeholderAccount = userService.selectAccountByPhone(member.getMPhone()); |
|
|
|
member.setSUsername(stakeholderAccount); |
|
|
|
if(ObjectUtil.isNotNull(stakeholder.getUserId())){ |
|
|
|
if (ObjectUtil.isNotNull(stakeholder.getUserId())) { |
|
|
|
if (currentUserId.longValue() == stakeholder.getUserId()) { |
|
|
|
member.setStakeholder(true); |
|
|
|
} |
|
|
@ -159,6 +165,7 @@ public class ProRoleService implements IProRoleService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取此用户不可见的角色 |
|
|
|
* |
|
|
|
* @param projectId |
|
|
|
* @param currentUserId |
|
|
|
* @return |
|
|
@ -169,18 +176,19 @@ public class ProRoleService implements IProRoleService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取用户在项目中的最高权限 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public int selectPowerByRoleName(Long userId,Long projectId) { |
|
|
|
public int selectPowerByRoleName(Long userId, Long projectId) { |
|
|
|
int power = 0; |
|
|
|
SysProject project = projectDao.selectByPrimaryKey(projectId); |
|
|
|
if(project.getCreatorId().longValue() == userId){ |
|
|
|
if (project.getCreatorId().longValue() == userId) { |
|
|
|
power = 2; |
|
|
|
} |
|
|
|
List<ProRole> roles = getProRoleByProjectIdAndUserId(projectId,userId); |
|
|
|
if(CollectionUtil.isNotEmpty(roles)){ |
|
|
|
for(ProRole role:roles){ |
|
|
|
List<ProRole> roles = getProRoleByProjectIdAndUserId(projectId, userId); |
|
|
|
if (CollectionUtil.isNotEmpty(roles)) { |
|
|
|
for (ProRole role : roles) { |
|
|
|
int i = proRoleDao.selectPowerByRoleName(role.getDescription()); |
|
|
|
power = i > power ? i : power; |
|
|
|
} |
|
|
@ -194,7 +202,7 @@ public class ProRoleService implements IProRoleService { |
|
|
|
@Override |
|
|
|
public TaskVo.RoleCheckList selectRoleByCheckOrExecutor(Long roleId) { |
|
|
|
TaskVo.RoleCheckList roleCheckList = new TaskVo.RoleCheckList(); |
|
|
|
if(roleId != 0) { |
|
|
|
if (roleId != 0) { |
|
|
|
ProRole role = proRoleDao.selectByPrimaryKey(roleId); |
|
|
|
roleCheckList.setId(role.getId()); |
|
|
|
roleCheckList.setName(role.getName()); |
|
|
@ -211,7 +219,7 @@ public class ProRoleService implements IProRoleService { |
|
|
|
ProRoleExample roleExample = new ProRoleExample(); |
|
|
|
roleExample.createCriteria().andProjectIdEqualTo(projectId).andNameEqualTo(WebConstant.ROLE_NAME.AllMember.phase); |
|
|
|
List<ProRole> roleList = proRoleDao.selectByExample(roleExample); |
|
|
|
if(CollectionUtil.isNotEmpty(roleList)){ |
|
|
|
if (CollectionUtil.isNotEmpty(roleList)) { |
|
|
|
role = roleList.get(0); |
|
|
|
} |
|
|
|
return role; |
|
|
@ -223,12 +231,12 @@ public class ProRoleService implements IProRoleService { |
|
|
|
* 删除角色 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void deleteRole(Long userId,Long roleId){ |
|
|
|
public void deleteRole(Long userId, Long roleId) { |
|
|
|
ProRole role = proRoleDao.selectByPrimaryKey(roleId); |
|
|
|
//本用户在项目中的角色
|
|
|
|
List<ProRole> proRoles = getProRoleByProjectIdAndUserId(role.getProjectId(), userId); |
|
|
|
//用户在项目中的最高权限
|
|
|
|
int power = selectPowerByRoleName(userId,role.getProjectId()); |
|
|
|
int power = selectPowerByRoleName(userId, role.getProjectId()); |
|
|
|
if (power > 1) { |
|
|
|
deleteRoleByRoleId(roleId); |
|
|
|
} else { |
|
|
@ -244,22 +252,22 @@ public class ProRoleService implements IProRoleService { |
|
|
|
ProRoleExample roleExample = new ProRoleExample(); |
|
|
|
roleExample.createCriteria().andProjectIdEqualTo(projectId); |
|
|
|
List<ProRole> roleList = proRoleDao.selectByExample(roleExample); |
|
|
|
if(CollectionUtil.isNotEmpty(roleList)){ |
|
|
|
for(ProRole role:roleList){ |
|
|
|
if (CollectionUtil.isNotEmpty(roleList)) { |
|
|
|
for (ProRole role : roleList) { |
|
|
|
deleteRoleByRoleId(role.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void deleteRoleByRoleId(Long roleId){ |
|
|
|
private void deleteRoleByRoleId(Long roleId) { |
|
|
|
//删除角色下的任务
|
|
|
|
taskDetailService.deleteTaskByRoleId(roleId); |
|
|
|
//删除成员和成员角色关联表
|
|
|
|
ProMemberRoleExample memberRoleExample = new ProMemberRoleExample(); |
|
|
|
memberRoleExample.createCriteria().andRoleIdEqualTo(roleId); |
|
|
|
List<ProMemberRole> memberRoleList = memberRoleDao.selectByExample(memberRoleExample); |
|
|
|
if(CollectionUtil.isNotEmpty(memberRoleList)){ |
|
|
|
for(ProMemberRole memberRole:memberRoleList){ |
|
|
|
if (CollectionUtil.isNotEmpty(memberRoleList)) { |
|
|
|
for (ProMemberRole memberRole : memberRoleList) { |
|
|
|
proMemberDao.deleteByPrimaryKey(memberRole.getMemberId()); |
|
|
|
memberRoleDao.deleteByPrimaryKey(memberRole.getId()); |
|
|
|
} |
|
|
|