huminghao pirms 1 mēnesi
vecāks
revīzija
c8b8ac97ec

+ 40
- 0
zhywpt-app-iaw/src/main/java/cn/com/taiji/iaw/api/comm/DicController.java Parādīt failu

@@ -0,0 +1,40 @@
package cn.com.taiji.iaw.api.comm;

import cn.com.taiji.common.manager.ManagerException;
import cn.com.taiji.common.web.ApiResponse;
import cn.com.taiji.iaw.api.MyValidController;
import cn.com.taiji.iaw.dto.CommRequestDTO;
import cn.com.taiji.iaw.dto.comm.DictItemModel;
import cn.com.taiji.iaw.manager.comm.DictManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
* @Author:ChenChao
* @Date:2025/7/17 15:36
* @Filename:DicController
* @description:
*/
@Api(tags = {"字典"})
@RestController
@RequestMapping("/api/dic")
public class DicController extends MyValidController {

@Autowired
private DictManager dictManager;
@ApiOperation(value = "2-4.字典项目获取所有")
@PostMapping(value = "/itemGetAll")
public ApiResponse<Map<String, List<DictItemModel>>> itemGetAll(@RequestBody @Valid CommRequestDTO req) throws ManagerException {
Map<String, List<DictItemModel>> response = dictManager.getAllDictItem(req);
return ApiResponse.of(response);
}
}

+ 7
- 1
zhywpt-app-iaw/src/main/java/cn/com/taiji/iaw/api/portal/PortalController.java Parādīt failu

@@ -1,6 +1,7 @@
package cn.com.taiji.iaw.api.portal;

import cn.com.taiji.common.manager.ManagerException;
import cn.com.taiji.common.manager.net.http.ServiceHandleException;
import cn.com.taiji.common.web.ApiResponse;
import cn.com.taiji.core.model.comm.protocol.ats.weiXin.AtsGetWeChatOpenIdRequest;
import cn.com.taiji.core.model.comm.protocol.ats.weiXin.AtsGetWeChatOpenIdResponse;
@@ -9,7 +10,6 @@ import cn.com.taiji.iaw.api.MyValidController;
import cn.com.taiji.iaw.dto.CommRequestDTO;
import cn.com.taiji.iaw.dto.comm.AccountInfoChangeInfoRequestDTO;
import cn.com.taiji.iaw.dto.comm.ChangeMobileCensorChangeMobileRequestDTO;
import cn.com.taiji.iaw.dto.issue.order.GetAccountInfoRequestDTO;
import cn.com.taiji.iaw.dto.issue.order.GetAccountInfoResponseDTO;
import cn.com.taiji.iaw.dto.portal.*;
import cn.com.taiji.iaw.manager.portal.PortalManager;
@@ -156,5 +156,11 @@ public class PortalController extends MyValidController {
return ApiResponse.of(portalManager.getAccountInfo(dto));
}

@ApiOperation(value = "根据系统类型和openId获取菜单列表")
@PostMapping(value = "/menuListBySystemTypeAndOpenId")
public ApiResponse<RbacMenuListBySystemTypeAndOpenIdResponseDTO> systemTypeByAccountRole(@RequestBody RbacMenuListBySystemTypeAndOpenIdRequestDTO dto) throws ServiceHandleException {
return ApiResponse.of(portalManager.menuListBySystemTypeAndOpenId(dto)).setMessage("操作成功");
}


}

+ 29
- 0
zhywpt-app-iaw/src/main/java/cn/com/taiji/iaw/dto/comm/DictItemModel.java Parādīt failu

@@ -0,0 +1,29 @@
package cn.com.taiji.iaw.dto.comm;

import cn.com.taiji.common.model.BaseModel;
import cn.com.taiji.core.entity.basic.DictItem;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class DictItemModel extends BaseModel {
private String dictTypeId;
private String code;
private String name;
private String description;
private Integer order;
private String dictItemId;
public static DictItemModel fromDictItem(DictItem dictItem) {
DictItemModel dictItemModel = new DictItemModel();
dictItemModel.setDictItemId(dictItem.getId());
dictItemModel.setDictTypeId(dictItem.getTypeId());
dictItemModel.setCode(dictItem.getCode());
dictItemModel.setName(dictItem.getName());
dictItemModel.setDescription(dictItem.getDescription());
// dictItemModel.setOrder(dictItem.getOrder());
return dictItemModel;
}
}



+ 35
- 0
zhywpt-app-iaw/src/main/java/cn/com/taiji/iaw/dto/portal/RbacMenuListBySystemTypeAndOpenIdMenuVO.java Parādīt failu

@@ -0,0 +1,35 @@
package cn.com.taiji.iaw.dto.portal;

import cn.com.taiji.common.model.BaseModel;
import cn.com.taiji.core.entity.dict.EnableStatus;
import cn.com.taiji.core.entity.dict.user.RbacSource;
import cn.com.taiji.core.entity.dict.user.RbacStatus;
import cn.com.taiji.core.entity.dict.user.SystemType;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.List;

@Getter
@Setter
@Accessors(chain = true)
public class RbacMenuListBySystemTypeAndOpenIdMenuVO extends BaseModel {
private String id;
private String name;
private String description;
private String link;
private String pid;
private Integer floor;
private Integer sort;
private String insertTime;
private String updateTime;
private SystemType systemType;
private RbacSource menuSource;
private RbacStatus status;
private String iconPath;
private List<RbacMenuListBySystemTypeAndOpenIdMenuVO> children;
private Boolean hasPerm;
private List<RbacMenuListBySystemTypeAndOpenIdPermVO> perms;
private EnableStatus isRecommend;
}

+ 25
- 0
zhywpt-app-iaw/src/main/java/cn/com/taiji/iaw/dto/portal/RbacMenuListBySystemTypeAndOpenIdPermVO.java Parādīt failu

@@ -0,0 +1,25 @@
package cn.com.taiji.iaw.dto.portal;

import cn.com.taiji.common.model.BaseModel;
import cn.com.taiji.core.entity.dict.user.RbacSource;
import cn.com.taiji.core.entity.dict.user.RbacStatus;
import cn.com.taiji.core.entity.dict.user.SystemType;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

@Getter
@Setter
@Accessors(chain = true)
public class RbacMenuListBySystemTypeAndOpenIdPermVO extends BaseModel {
private String id;
private String description;// 备注
private String permIdentity;// 按钮的权限标识
private RbacStatus status;// 功能按钮是否启用 1:启用 2:不启用(默认)
private Integer sort;
private SystemType systemType;// 所属系统
private RbacSource menuSource;// 按钮所属来源方
private String insertTime;
private String menuId;
// private SimpleMenuVo menuVo;// 按钮所在的菜单
}

+ 21
- 0
zhywpt-app-iaw/src/main/java/cn/com/taiji/iaw/dto/portal/RbacMenuListBySystemTypeAndOpenIdRequestDTO.java Parādīt failu

@@ -0,0 +1,21 @@
package cn.com.taiji.iaw.dto.portal;//package cn.com.taiji.core.model.comm.protocol.issues.portal;

import cn.com.taiji.core.dto.AbstractBizRequestDTO;
import cn.com.taiji.core.entity.dict.user.SystemType;
import cn.com.taiji.core.model.comm.protocol.constraint.EnumInteger;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotNull;

@Getter
@Setter
@Accessors(chain = true)
public class RbacMenuListBySystemTypeAndOpenIdRequestDTO extends AbstractBizRequestDTO {

@NotNull(message = "systemType不能为空")
@EnumInteger(enumClazz = SystemType.class)
private Integer systemType;

}

+ 20
- 0
zhywpt-app-iaw/src/main/java/cn/com/taiji/iaw/dto/portal/RbacMenuListBySystemTypeAndOpenIdResponseDTO.java Parādīt failu

@@ -0,0 +1,20 @@
package cn.com.taiji.iaw.dto.portal;//package cn.com.taiji.core.model.comm.protocol.issues.portal;

import cn.com.taiji.common.model.BaseModel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.List;


@Getter
@Setter
@Accessors(chain = true)
public class RbacMenuListBySystemTypeAndOpenIdResponseDTO extends BaseModel {
private List<RbacMenuListBySystemTypeAndOpenIdMenuVO> menuList;

public RbacMenuListBySystemTypeAndOpenIdResponseDTO(List<RbacMenuListBySystemTypeAndOpenIdMenuVO> menuList) {
this.menuList = menuList;
}
}

+ 44
- 0
zhywpt-app-iaw/src/main/java/cn/com/taiji/iaw/manager/comm/DictManager.java Parādīt failu

@@ -0,0 +1,44 @@
package cn.com.taiji.iaw.manager.comm;

import cn.com.taiji.common.manager.ManagerException;
import cn.com.taiji.core.entity.basic.DictItem;
import cn.com.taiji.core.entity.basic.DictType;
import cn.com.taiji.core.repo.jpa.basic.DictItemRepo;
import cn.com.taiji.core.repo.jpa.basic.DictTypeRepo;
import cn.com.taiji.iaw.dto.CommRequestDTO;
import cn.com.taiji.iaw.dto.comm.DictItemModel;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @Author:ChenChao
* @Date:2025/7/17 15:41
* @Filename:DictManager
* @description:
*/
@Service
public class DictManager {

@Autowired
private DictItemRepo dictItemRepo;
@Autowired
private DictTypeRepo dictTypeRepo;

public Map<String, List<DictItemModel>> getAllDictItem(CommRequestDTO req) throws ManagerException {
Map<String, List<DictItemModel>> dictTypeModels = Maps.newHashMap();
List<DictType> dictTypes = dictTypeRepo.findAll();
for (DictType dictType : dictTypes) {
List<DictItem> dictItemList = dictItemRepo.findByTypeId(dictType.getId());
if (dictItemList == null)
throw new ManagerException("未查询到对应数据,请检查参数!");
List<DictItemModel> dictItemModels =
dictItemList.stream().map(DictItemModel::fromDictItem).collect(Collectors.toList());
dictTypeModels.put(dictType.getCode(), dictItemModels);
}
return dictTypeModels;
}
}

+ 3
- 0
zhywpt-app-iaw/src/main/java/cn/com/taiji/iaw/manager/portal/PortalManager.java Parādīt failu

@@ -49,4 +49,7 @@ public interface PortalManager {
ChangeAccountInfoResponse changeInfo(AccountInfoChangeInfoRequestDTO dto) throws ManagerException;

GetAccountInfoResponseDTO getAccountInfo(CommRequestDTO dto) throws ManagerException;

RbacMenuListBySystemTypeAndOpenIdResponseDTO menuListBySystemTypeAndOpenId(RbacMenuListBySystemTypeAndOpenIdRequestDTO dto) throws ServiceHandleException;

}

+ 158
- 2
zhywpt-app-iaw/src/main/java/cn/com/taiji/iaw/manager/portal/PortalManagerImpl.java Parādīt failu

@@ -2,23 +2,37 @@ package cn.com.taiji.iaw.manager.portal;

import cn.com.taiji.common.manager.ManagerException;
import cn.com.taiji.common.manager.net.http.ServiceHandleException;
import cn.com.taiji.common.pub.BeanTools;
import cn.com.taiji.common.pub.TimeTools;
import cn.com.taiji.core.entity.basic.QtkCustomerInfo;
import cn.com.taiji.core.entity.user.AccountInfo;
import cn.com.taiji.core.entity.dict.basic.SourceType;
import cn.com.taiji.core.entity.dict.user.RbacStatus;
import cn.com.taiji.core.entity.dict.user.SystemType;
import cn.com.taiji.core.entity.user.*;
import cn.com.taiji.core.manager.tools.minio.MinioUtil;
import cn.com.taiji.core.model.comm.protocol.ats.weiXin.AtsGetWeChatOpenIdRequest;
import cn.com.taiji.core.model.comm.protocol.ats.weiXin.AtsGetWeChatOpenIdResponse;
import cn.com.taiji.core.model.comm.protocol.ias.portal.*;
import cn.com.taiji.core.model.comm.protocol.valid.GlyServiceError;
import cn.com.taiji.core.repo.jpa.basic.QtkCustomerInfoRepo;
import cn.com.taiji.core.repo.jpa.user.AccountInfoRepo;
import cn.com.taiji.core.repo.jpa.user.*;
import cn.com.taiji.iaw.dto.CommRequestDTO;
import cn.com.taiji.iaw.dto.comm.AccountInfoChangeInfoRequestDTO;
import cn.com.taiji.iaw.dto.comm.ChangeMobileCensorChangeMobileRequestDTO;
import cn.com.taiji.iaw.dto.issue.order.GetAccountInfoResponseDTO;
import cn.com.taiji.iaw.dto.portal.*;
import cn.com.taiji.iaw.manager.AbstractCommManager;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static cn.com.taiji.core.manager.tools.SystemFinals.*;

@Service
public class PortalManagerImpl extends AbstractCommManager implements PortalManager {
@@ -29,6 +43,16 @@ public class PortalManagerImpl extends AbstractCommManager implements PortalMana
private AccountInfoRepo accountInfoRepo;
@Autowired
private QtkCustomerInfoRepo qtkCustomerInfoRepo;
@Autowired
private AccountUserRoleRepo accountUserRoleRepo;
@Autowired
private UserRoleMenuPermRepo userRoleMenuPermRepo;
@Autowired
private UserRoleUserMenuRepo userRoleUserMenuRepo;
@Autowired
private UserMenuRepo userMenuRepo;
@Resource
private UserPermRepo userPermRepo;

@Override
public RegisterResponse register(RegisterDTO dto) throws ManagerException {
@@ -137,4 +161,136 @@ public class PortalManagerImpl extends AbstractCommManager implements PortalMana
resDTO.setCustomerIdVld(accountInfo.getExpireDate() == null ? "长期" : accountInfo.getExpireDate().format(TimeTools.yyyyMMdd));
return resDTO;
}

@Override
public RbacMenuListBySystemTypeAndOpenIdResponseDTO menuListBySystemTypeAndOpenId(RbacMenuListBySystemTypeAndOpenIdRequestDTO dto) throws ServiceHandleException {
//TODO 根据登录来源方区分
// 小程序:则查询AccountUserRole中 根据openId、SystemType.MINI_PROGRAM、LoginSource.MINI_PROGRAM 去找,然后再额外分配一个基本角色
// APP:则查询AccountUserRole中 根据openId和SystemType.COMMON、LoginSource.MINI_PROGRAM 去找,然后再额外分配一个基本角色
// WEB:则查询AccountUserRole中 根据openId和SystemType.xitong、LoginSource.MINI_PROGRAM 去找
// ...
// 注册账号的时候就进行角色分配?还是固定有一个基本角色的概念在
// 目前做法:创建了一个基本角色,可以去给基本角色去进行菜单分配,
// 每个人在进入小程序的时候会默认分配一个基本角色,然后再去查询,在小程序中该账号是否又分配了其他的角色,并返回这些角色
// 每个人在进入APP的时候会默认分配一个基本角色,然后再去查询,在小程序中该账号是否又分配了其他的角色,并返回这些角色
String openId = findOpenIdByToken(dto.getAccessToken());
SystemType systemType = SystemType.fromCode(dto.getSystemType());
if (systemType == null) throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("系统类型错误");
SourceType loginSource = SourceType.findByCode(dto.getLoginSource());
if (loginSource == null) throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("来源错误");
List<String> roleIds = accountUserRoleRepo.findRoleByOpenIdAndSystemType(openId, systemType);
if (isEmpty(roleIds))
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("该账号在该系统中没有分配角色,无法访问该系统!");
if (loginSource == SourceType.SERVICE_HALL) roleIds.add(appBaseRoleId);// APP
if (loginSource == SourceType.WECHAT) roleIds.add(miniProgramBaseRoleId);// 微信小程序
if (loginSource == SourceType.ALI) roleIds.add(zfbMiniProgramBaseRoleId);// 支付宝小程序
if (loginSource == SourceType.WEB && roleIds.size() > 1)
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("该账号在一个系统中只能分配一个角色,该账户在该系统中分配了多个角色,暂时无法访问,请联系管理员处理!");
List<UserRoleUserMenu> userRoleUserMenuList = userRoleUserMenuRepo.getListByRoleIds(roleIds);

//4、获取分好层级的所有菜单
List<RbacMenuListBySystemTypeAndOpenIdMenuVO> pMenuList = new ArrayList<>();
//4.1、判断是否查询到角色对应的分配的菜单
if (!CollectionUtils.isEmpty(userRoleUserMenuList)) {
List<String> menuIds = new ArrayList<>();
List<UserMenu> menuList = new ArrayList<>();

menuIds.addAll(userRoleUserMenuList.stream().map(rm -> rm.getMenuId()).collect(Collectors.toList()));
menuList.addAll(userMenuRepo.findAllById(menuIds));

//4.2、过滤被禁用的菜单
menuList = menuList.stream().filter(m -> RbacStatus.ENABLE.equals(m.getStatus())).collect(Collectors.toList());

//4.3、包装为vo类
List<RbacMenuListBySystemTypeAndOpenIdMenuVO> menuVoList = new ArrayList<>();
for (UserMenu userMenu : menuList) {
RbacMenuListBySystemTypeAndOpenIdMenuVO menuVo = new RbacMenuListBySystemTypeAndOpenIdMenuVO();
BeanTools.copyProperties(userMenu, menuVo);
menuVoList.add(menuVo);
}

//4.4、获取顶层父菜单
pMenuList = menuVoList.stream().filter(m -> 1 == m.getFloor()).collect(Collectors.toList());
//4.5、顶级父菜单排序
pMenuList = pMenuList.stream().sorted((m1, m2) -> m1.getSort() - m2.getSort()).collect(Collectors.toList());
//4.5、获取非顶层的父菜单
menuVoList = menuVoList.stream().filter(m -> 1 != m.getFloor()).collect(Collectors.toList());

//4.6、为顶层父菜单配置子菜单
for (RbacMenuListBySystemTypeAndOpenIdMenuVO pMenu : pMenuList) {

//TODO 目前是通过查询菜单列表的时候,同步把该角色在该菜单对应的权限标识,附在最底层的菜单中
//通过递归的方式,设置到最底层的子菜单
setSubByRole(pMenu, menuVoList, userRoleUserMenuList);
}
}
return new RbacMenuListBySystemTypeAndOpenIdResponseDTO(pMenuList);
}

public void setSubByRole(RbacMenuListBySystemTypeAndOpenIdMenuVO pMenu, List<RbacMenuListBySystemTypeAndOpenIdMenuVO> menuList, List<UserRoleUserMenu> userRoleUserMenuList) throws ServiceHandleException {
boolean hasSub = false;
//设置该父菜单的子菜单
List<RbacMenuListBySystemTypeAndOpenIdMenuVO> subMenuList = new ArrayList<>();
for (RbacMenuListBySystemTypeAndOpenIdMenuVO subMenu : menuList) {
if (pMenu.getId().equals(subMenu.getPid())) {
subMenuList.add(subMenu);
hasSub = true;
}
}
//判断是否有子菜单
if (hasSub) {
//子菜单排序
subMenuList = subMenuList.stream().sorted((m1, m2) -> m1.getSort() - m2.getSort()).collect(Collectors.toList());
;
pMenu.setChildren(subMenuList);
pMenu.setHasPerm(false);//改成没有权限标识
pMenu.setPerms(new ArrayList<>());

//有子菜单,则该父菜单的子菜单们继续递归
for (RbacMenuListBySystemTypeAndOpenIdMenuVO subMenu : pMenu.getChildren()) {
setSubByRole(subMenu, menuList, userRoleUserMenuList);
}
} else {
//无子菜单,则表明是最底层,
pMenu.setChildren(new ArrayList<>());
pMenu.setHasPerm(true);//改成没有权限标识
//查询该菜单的所有权限标识
pMenu.setPerms(new ArrayList<>());

//在角色-菜单 中间表中,找到改菜单对应的所有角色
List<UserRoleUserMenu> roleMenuRelation = userRoleUserMenuList.stream().filter(urum -> urum.getMenuId().equals(pMenu.getId())).collect(Collectors.toList());
;
List<String> roleIdList = roleMenuRelation.stream().map(r -> r.getRoleId()).collect(Collectors.toList());
;

if (roleIdList != null && roleIdList.size() > 0) {
//获取该用户在 该端、该系统、该菜单下,所有角色对应的权限标识
List<UserRoleMenuPerm> roleMenuPermRelation = userRoleMenuPermRepo.findListByRoleIdListAndMenuId(roleIdList, pMenu.getId());

if (roleMenuPermRelation != null && roleMenuPermRelation.size() > 0) {
List<String> permIdList = roleMenuPermRelation.stream().map(r -> r.getPermId()).collect(Collectors.toList());
;
//获取权限标识列表
List<UserPerm> permList = userPermRepo.findAllById(permIdList);
List<RbacMenuListBySystemTypeAndOpenIdPermVO> permVoList = new ArrayList<>();
if (permList != null && permList.size() > 0) {
//过滤禁用的权限标识
permList = permList.stream().filter(b -> b.getStatus().equals(RbacStatus.ENABLE)).collect(Collectors.toList());
;

for (UserPerm perm : permList) {
RbacMenuListBySystemTypeAndOpenIdPermVO permVo = new RbacMenuListBySystemTypeAndOpenIdPermVO();
BeanUtils.copyProperties(perm, permVo);
permVoList.add(permVo);
}
}
if (permVoList != null && permVoList.size() > 0) {
//设置该菜单的所有权限标识
pMenu.setPerms(permVoList);
}
}
}
}
}

}

Notiek ielāde…
Atcelt
Saglabāt