4 changed files with 119 additions and 27 deletions
@ -0,0 +1,18 @@ |
|||
package com.ccsens.carbasics.service; |
|||
|
|||
import com.ccsens.common.bean.dto.CRoleDto; |
|||
import com.ccsens.common.bean.vo.CRoleVo; |
|||
|
|||
/** |
|||
* @author AUSU |
|||
*/ |
|||
public interface IRoleCarService { |
|||
/** |
|||
* 查询用户角色列表 |
|||
* @param param 项目id |
|||
* @param userId 用户id |
|||
* @return 角色展示列表 |
|||
*/ |
|||
CRoleVo.QueryRole queryShowRoleCar(CRoleDto.QueryRoleById param, Long userId); |
|||
|
|||
} |
@ -0,0 +1,69 @@ |
|||
package com.ccsens.carbasics.service; |
|||
|
|||
import cn.hutool.core.bean.BeanUtil; |
|||
import cn.hutool.core.collection.CollectionUtil; |
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import com.ccsens.carbasics.util.Constant; |
|||
import com.ccsens.common.bean.dto.CRoleDto; |
|||
import com.ccsens.common.bean.po.ProRole; |
|||
import com.ccsens.common.bean.vo.CRoleVo; |
|||
import com.ccsens.common.persist.dao.ProRoleDao; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Propagation; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import javax.annotation.Resource; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author AUSU |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
|||
public class RoleCarService implements IRoleCarService { |
|||
|
|||
@Resource |
|||
private ProRoleDao proRoleDao; |
|||
|
|||
@Override |
|||
public CRoleVo.QueryRole queryShowRoleCar(CRoleDto.QueryRoleById param, Long userId) { |
|||
//返回的对象
|
|||
CRoleVo.QueryRole queryRole = new CRoleVo.QueryRole(); |
|||
List<CRoleVo.RoleInfo> visibleList = new ArrayList<>(); |
|||
List<CRoleVo.RoleInfo> invisibleList = new ArrayList<>(); |
|||
//查询当前用户在项目下的角色,没有则算作关注者
|
|||
List<ProRole> userRoleList = proRoleDao.queryRoleByUserId(param.getProjectId(),userId); |
|||
//查询平车角色
|
|||
CRoleVo.RoleInfo carRole = proRoleDao.queryByName(Constant.CAR_ROLE_NAME, param.getProjectId()); |
|||
if (CollectionUtil.isNotEmpty(userRoleList)) { |
|||
if (1 < userRoleList.size()) { |
|||
userRoleList.forEach(userRole -> { |
|||
if (CollectionUtil.isEmpty(visibleList)) { |
|||
CRoleVo.RoleInfo userRoleInfo = new CRoleVo.RoleInfo(); |
|||
BeanUtil.copyProperties(userRole,userRoleInfo); |
|||
visibleList.add(userRoleInfo); |
|||
}else { |
|||
CRoleVo.RoleInfo userRoleInfo = new CRoleVo.RoleInfo(); |
|||
BeanUtil.copyProperties(userRole,userRoleInfo); |
|||
invisibleList.add(userRoleInfo); |
|||
} |
|||
}); |
|||
}else { |
|||
CRoleVo.RoleInfo userRoleInfo = new CRoleVo.RoleInfo(); |
|||
BeanUtil.copyProperties(userRoleList.get(0),userRoleInfo); |
|||
invisibleList.add(userRoleInfo); |
|||
} |
|||
} |
|||
if (ObjectUtil.isNotNull(carRole)) { |
|||
visibleList.add(carRole); |
|||
} |
|||
queryRole.setVisibleList(visibleList); |
|||
queryRole.setInvisibleList(invisibleList); |
|||
//查询平车角色
|
|||
return queryRole; |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue