认证-参数项收集-添加角色切换(六种角色)

This commit is contained in:
liyawei
2022-06-11 17:45:19 +08:00
parent 0b3eb8b229
commit 2e0b7ad09b
5 changed files with 225 additions and 22 deletions
@@ -183,8 +183,9 @@ public class ParamsCollectManifestEOController extends JeroController<ParamsColl
@ApiOperation(value="参数项收集清单-判断当前登录用户类型", notes="参数项收集清单-判断当前登录用户类型")
@GetMapping(value = "/getLoginUserType")
// @RequiresPermissions("params:collectManifest:list")
public Result<?> getLoginUserTypes(ParamsCollectManifestVO paramsCollectManifestVO) {
String loginUserType = paramsCollectManifestEOService.getLoginUserTypes(paramsCollectManifestVO);
public Result<?> getLoginUserTypes(ParamsCollectManifestVO paramsCollectManifestVO,
@RequestParam(name="cut") String cut) {
List<Map<String, String>> loginUserType = paramsCollectManifestEOService.getLoginUserTypes(paramsCollectManifestVO, cut);
return Result.OK(loginUserType);
}
@@ -0,0 +1,100 @@
package com.jero.modules.cert.collect.enums;
import cn.hutool.core.collection.CollectionUtil;
import com.jero.modules.project.entity.ConditionAssessmentEO;
import com.jero.modules.split.enums.StandFileClassifyEnum;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* @Author: liyawei
* @Description:
* @Date: Created in 10:56 2022/6/11
*/
public enum CollectManifestRoleIdEnum {
STUDIO_ID("R&H Studio","R&H Studio","studio","1534019911296118786",1),
ADMIN_ID("R&H Manager","Administrator","admin","f6817f48af4fb3af11b9e8bf182f618b",2),
MANAGER_ID("系统管理员","R&H Manager","manager","1534020391015444481",3);
String name;
String enName;
String value;
String id;
Integer order;
CollectManifestRoleIdEnum(String name, String enName, String value, String id, Integer order) {
this.name = name;
this.enName = enName;
this.value = value;
this.id = id;
this.order = order;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getEnName() {
return enName;
}
public void setEnName(String enName) {
this.enName = enName;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Integer getOrder() {
return order;
}
public void setOrder(Integer order) {
this.order = order;
}
public static List<String> getIdList() {
List<String> idList = new ArrayList<>();
CollectManifestRoleIdEnum[] values = values();
for (CollectManifestRoleIdEnum collectManifestRoleIdEnum : values) {
idList.add(collectManifestRoleIdEnum.getId());
}
return idList;
}
public static List<CollectManifestRoleIdEnum> getByIdList(List<String> idList) {
List<CollectManifestRoleIdEnum> collectManifestRoleIdEnums = new ArrayList<>();
if (CollectionUtil.isNotEmpty(idList)) {
CollectManifestRoleIdEnum[] values = values();
for (CollectManifestRoleIdEnum collectManifestRoleIdEnum : values) {
if (idList.contains(collectManifestRoleIdEnum.getId())) {
collectManifestRoleIdEnums.add(collectManifestRoleIdEnum);
}
}
}
if (CollectionUtil.isNotEmpty(collectManifestRoleIdEnums) && collectManifestRoleIdEnums.size() > 1) {
collectManifestRoleIdEnums.stream().sorted(Comparator.comparing(CollectManifestRoleIdEnum :: getOrder));
}
return collectManifestRoleIdEnums;
}
}
@@ -1,21 +1,29 @@
package com.jero.modules.cert.collect.enums;
import java.util.ArrayList;
import java.util.List;
/**
* @Author: liyawei
* @Description:
* @Date: Created in 16:47 2022/5/11
*/
public enum CollectManifestUserTypeEnum {
HOMO("认证工程师","homo"),
SDT("工程接口人","sdt"),
DRE("填写人","dre"),
GUEST("游客","guest");
HOMO("认证工程师", "Homologation Engineer", "homo"),
SDT("工程接口人", "Sdt People","sdt"),
DRE("填写人", "Dre People","dre"),
STUDIO("R&H Studio","R&H Studio","studio"),
MANAGER("R&H Manager","R&H Manager","manager"),
ADMIN("系统管理员","Administrator","admin"),
GUEST("游客", "Guest","guest");
String name;
String enName;
String value;
CollectManifestUserTypeEnum(String name, String value) {
CollectManifestUserTypeEnum(String name, String enName, String value) {
this.name = name;
this.enName = enName;
this.value = value;
}
@@ -27,6 +35,14 @@ public enum CollectManifestUserTypeEnum {
this.name = name;
}
public String getEnName() {
return enName;
}
public void setEnName(String enName) {
this.enName = enName;
}
public String getValue() {
return value;
}
@@ -34,4 +50,18 @@ public enum CollectManifestUserTypeEnum {
public void setValue(String value) {
this.value = value;
}
public static boolean doesValueExist(String value) {
CollectManifestUserTypeEnum[] values = values();
List<String> valueList = new ArrayList<>();
for (CollectManifestUserTypeEnum collectManifestUserTypeEnum : values) {
valueList.add(collectManifestUserTypeEnum.getValue());
}
if (valueList.contains(value)) {
return true;
}
return false;
}
}
@@ -89,7 +89,7 @@ public interface IParamsCollectManifestEOService extends IService<ParamsCollectM
List<Map<String,String>> querySdtList(ParamsCollectManifestVO paramsCollectManifestVO);
String getLoginUserTypes(ParamsCollectManifestVO paramsCollectManifestVO);
List<Map<String, String>> getLoginUserTypes(ParamsCollectManifestVO paramsCollectManifestVO, String cut);
Map<String, Object> isCollectFinished(String paramsManifestId);
@@ -3,6 +3,7 @@ package com.jero.modules.cert.collect.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.jero.common.constant.CommonConstant;
@@ -17,10 +18,7 @@ import com.jero.modules.cert.collect.entity.ParamsCollectManifestEO;
import com.jero.modules.cert.collect.entity.ParamsConfigDataEO;
import com.jero.modules.cert.collect.entity.ParamsConfigEO;
import com.jero.modules.cert.collect.entity.ParamsManifestEO;
import com.jero.modules.cert.collect.enums.CollectManifestStateEnum;
import com.jero.modules.cert.collect.enums.CollectManifestUserTypeEnum;
import com.jero.modules.cert.collect.enums.ConfigDataTypeEnum;
import com.jero.modules.cert.collect.enums.ConfigLockEnum;
import com.jero.modules.cert.collect.enums.*;
import com.jero.modules.cert.collect.mapper.ParamsCollectManifestEOMapper;
import com.jero.modules.cert.collect.service.IParamsCollectManifestEOService;
import com.jero.modules.cert.collect.service.IParamsConfigDataEOService;
@@ -44,8 +42,10 @@ import com.jero.modules.project.service.IProjectRelatedPersonnelService;
import com.jero.modules.system.entity.SysAnnouncement;
import com.jero.modules.system.entity.SysDictItem;
import com.jero.modules.system.entity.SysUser;
import com.jero.modules.system.entity.SysUserRole;
import com.jero.modules.system.service.ISysAnnouncementService;
import com.jero.modules.system.service.ISysDictItemService;
import com.jero.modules.system.service.ISysUserRoleService;
import com.jero.modules.system.service.ISysUserService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
@@ -107,6 +107,8 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
private IParamsManifestEOService paramsManifestEOService;
@Autowired
private IReportCertCategoryParamsInfoEOService reportCertCategoryParamsInfoEOService;
@Autowired
private ISysUserRoleService sysUserRoleService;
@@ -219,7 +221,18 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
String userTypes = paramsCollectManifestEO.getUserTypes();
if (StringUtils.isBlank(userTypes)) {
throw new JeroBootException("用户类型参数不能为空!");
if (CutEnum.CN.getValue().equals(cut)) {
throw new JeroBootException("用户类型参数不能为空!");
} else {
throw new JeroBootException("User type can not be null!");
}
}
if (!CollectManifestUserTypeEnum.doesValueExist(userTypes)) {
if (CutEnum.CN.getValue().equals(cut)) {
throw new JeroBootException("用户类型不存在!");
} else {
throw new JeroBootException("User type is not exist!");
}
}
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); // 获取当前登录用户
if ("sdt".equals(userTypes)) {
@@ -741,11 +754,11 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
}
@Override
public String getLoginUserTypes(ParamsCollectManifestVO paramsCollectManifestVO) {
public List<Map<String, String>> getLoginUserTypes(ParamsCollectManifestVO paramsCollectManifestVO, String cut) {
String projectId = paramsCollectManifestVO.getProjectId();
String paramsManifestId = paramsCollectManifestVO.getParamsManifestId();
StringBuilder userTypesBuilder=new StringBuilder(); // 一个用户可以有多个用户类型
List<Map<String, String>> userTypeList = new ArrayList<>(); // 一个用户可以有多个用户类型
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); // 获取当前登录用户
// 查询项目下所有责任领域下的 homo,sdt人员
@@ -760,7 +773,15 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
List<String> homoIdList = Arrays.asList(homoIdStr.split(",")).stream().distinct().collect(Collectors.toList());
homoList = sysUserService.listByIds(homoIdList).stream().map(SysUser::getUsername).collect(Collectors.toList());
} else {
return CollectManifestUserTypeEnum.GUEST.getValue();
Map<String, String> map = new HashMap<>();
if (CutEnum.CN.getValue().equals(cut)) {
map.put("label", CollectManifestUserTypeEnum.GUEST.getName());
} else {
map.put("label", CollectManifestUserTypeEnum.GUEST.getEnName());
}
map.put("value", CollectManifestUserTypeEnum.GUEST.getValue());
userTypeList.add(map);
return userTypeList;
}
// 项目下有homo-->必定有sdt
List<String> sdtIdList = Arrays.asList(sdtIdStr.split(",")).stream().distinct().collect(Collectors.toList());
@@ -783,26 +804,77 @@ public class ParamsCollectManifestEOServiceImpl extends ServiceImpl<ParamsCollec
.distinct()
.collect(Collectors.toList());
if (!homoList.contains(loginUser.getUsername())
// 查询当前登录用户角色 是否包含管理员/领导/studio
List<SysUserRole> userRoles = sysUserRoleService.list(new QueryWrapper<SysUserRole>().lambda().eq(SysUserRole::getUserId, loginUser.getId())); // 查询用户所有角色
List<String> userRoleIds = new ArrayList<>(); // 用户管理员/领导/studio角色
if (CollectionUtil.isNotEmpty(userRoles)) {
List<String> roleIdList = CollectManifestRoleIdEnum.getIdList();
List<String> userRoleIdList = userRoles.stream().map(SysUserRole::getRoleId).collect(Collectors.toList());
userRoleIds = roleIdList.stream().filter(e->userRoleIdList.contains(e)).collect(Collectors.toList());
}
if (CollectionUtil.isEmpty(userRoleIds) && !homoList.contains(loginUser.getUsername())
&& !sdtList.contains(loginUser.getUsername())
&& !dreListOfPCM.contains(loginUser.getUsername())) {
return CollectManifestUserTypeEnum.GUEST.getValue();
Map<String, String> map = new HashMap<>();
if (CutEnum.CN.getValue().equals(cut)) {
map.put("label", CollectManifestUserTypeEnum.GUEST.getName());
} else {
map.put("label", CollectManifestUserTypeEnum.GUEST.getEnName());
}
map.put("value", CollectManifestUserTypeEnum.GUEST.getValue());
userTypeList.add(map);
return userTypeList;
}
if (homoList.contains(loginUser.getUsername())) {
userTypesBuilder.append(CollectManifestUserTypeEnum.HOMO.getValue()).append(",");
Map<String, String> map = new HashMap<>();
if (CutEnum.CN.getValue().equals(cut)) {
map.put("label", CollectManifestUserTypeEnum.HOMO.getName());
} else {
map.put("label", CollectManifestUserTypeEnum.HOMO.getEnName());
}
map.put("value", CollectManifestUserTypeEnum.HOMO.getValue());
userTypeList.add(map);
}
if (sdtList.contains(loginUser.getUsername())) {
userTypesBuilder.append(CollectManifestUserTypeEnum.SDT.getValue()).append(",");
Map<String, String> map = new HashMap<>();
if (CutEnum.CN.getValue().equals(cut)) {
map.put("label", CollectManifestUserTypeEnum.SDT.getName());
} else {
map.put("label", CollectManifestUserTypeEnum.SDT.getEnName());
}
map.put("value", CollectManifestUserTypeEnum.SDT.getValue());
userTypeList.add(map);
}
if (dreListOfPCM.contains(loginUser.getUsername())) {
userTypesBuilder.append(CollectManifestUserTypeEnum.DRE.getValue()).append(",");
Map<String, String> map = new HashMap<>();
if (CutEnum.CN.getValue().equals(cut)) {
map.put("label", CollectManifestUserTypeEnum.DRE.getName());
} else {
map.put("label", CollectManifestUserTypeEnum.DRE.getEnName());
}
map.put("value", CollectManifestUserTypeEnum.DRE.getValue());
userTypeList.add(map);
}
return userTypesBuilder.substring(0, userTypesBuilder.toString().length() - 1);
if (CollectionUtil.isNotEmpty(userRoleIds)) {
List<CollectManifestRoleIdEnum> collectManifestRoleIdEnumList = CollectManifestRoleIdEnum.getByIdList(userRoleIds);
for (CollectManifestRoleIdEnum collectManifestRoleIdEnum : collectManifestRoleIdEnumList) {
Map<String, String> map = new HashMap<>();
if (CutEnum.CN.getValue().equals(cut)) {
map.put("label", collectManifestRoleIdEnum.getName());
} else {
map.put("label", collectManifestRoleIdEnum.getEnName());
}
map.put("value", collectManifestRoleIdEnum.getValue());
userTypeList.add(map);
}
}
return userTypeList;
}
@Override