Browse Source

修改查询角色接口

master
ma 4 years ago
parent
commit
f768c092c1
  1. 56
      src/main/java/com/ccsens/carbasics/api/RoleController.java
  2. 18
      src/main/java/com/ccsens/carbasics/service/IRoleCarService.java
  3. 69
      src/main/java/com/ccsens/carbasics/service/RoleCarService.java
  4. 3
      src/main/java/com/ccsens/carbasics/util/Constant.java

56
src/main/java/com/ccsens/carbasics/api/RoleController.java

@ -2,6 +2,7 @@ package com.ccsens.carbasics.api;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ccsens.carbasics.service.IRoleCarService;
import com.ccsens.cloudutil.annotation.MustLogin;
import com.ccsens.common.bean.dto.CRoleDto;
import com.ccsens.common.bean.vo.CRoleVo;
@ -32,38 +33,41 @@ import java.util.List;
public class RoleController {
@Resource
private IProRoleService roleService;
@Resource
private IRoleCarService roleCarService;
@MustLogin
@ApiOperation(value = "根据项目id查找角色", notes = "")
@RequestMapping(value = "/show", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<CRoleVo.QueryRole> queryByProjectId(@ApiParam @Validated @RequestBody QueryDto<CRoleDto.QueryRoleById> params) {
params.getParam().setNum(0);
CRoleVo.QueryRole queryRole = roleService.queryShowRole(params.getParam(), params.getUserId());
List<CRoleVo.RoleInfo> r1 = new ArrayList<>();
List<CRoleVo.RoleInfo> r2 = new ArrayList<>();
//处理角色,只查看自己所属的角色
if(ObjectUtil.isNotNull(queryRole)){
if(CollectionUtil.isNotEmpty(queryRole.getVisibleList())){
queryRole.getVisibleList().forEach(roleInfo -> {
if(roleInfo.getMine() == 1){
r1.add(roleInfo);
}else {
r2.add(roleInfo);
}
});
}
if(CollectionUtil.isNotEmpty(queryRole.getInvisibleList())){
queryRole.getInvisibleList().forEach(roleInfo -> {
if(roleInfo.getMine() == 1){
r1.add(roleInfo);
}else {
r2.add(roleInfo);
}
});
}
}
queryRole.setVisibleList(r1);
queryRole.setInvisibleList(r2);
// CRoleVo.QueryRole queryRole = roleService.queryShowRole(params.getParam(), params.getUserId());
CRoleVo.QueryRole queryRole = roleCarService.queryShowRoleCar(params.getParam(), params.getUserId());
// List<CRoleVo.RoleInfo> r1 = new ArrayList<>();
// List<CRoleVo.RoleInfo> r2 = new ArrayList<>();
// //处理角色,只查看自己所属的角色
// if(ObjectUtil.isNotNull(queryRole)){
// if(CollectionUtil.isNotEmpty(queryRole.getVisibleList())){
// queryRole.getVisibleList().forEach(roleInfo -> {
// if(roleInfo.getMine() == 1){
// r1.add(roleInfo);
// }else {
// r2.add(roleInfo);
// }
// });
// }
// if(CollectionUtil.isNotEmpty(queryRole.getInvisibleList())){
// queryRole.getInvisibleList().forEach(roleInfo -> {
// if(roleInfo.getMine() == 1){
// r1.add(roleInfo);
// }else {
// r2.add(roleInfo);
// }
// });
// }
// }
// queryRole.setVisibleList(r1);
// queryRole.setInvisibleList(r2);
return JsonResponse.newInstance().ok(queryRole);
}

18
src/main/java/com/ccsens/carbasics/service/IRoleCarService.java

@ -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);
}

69
src/main/java/com/ccsens/carbasics/service/RoleCarService.java

@ -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;
}
}

3
src/main/java/com/ccsens/carbasics/util/Constant.java

@ -20,7 +20,8 @@ public class Constant {
public static final String STRING_REGEX = ",|,|;|;|、|/";
/**xls*/
public static final String XLS = "xls";
/**平车角色名*/
public static final String CAR_ROLE_NAME = "平车";
public static final class TimeCheck{
public static final Map<String, Map<String, TimeCheckItem>> compareItems = new HashMap<>();

Loading…
Cancel
Save