|
@@ -4,7 +4,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.google.gson.reflect.TypeToken;
|
|
import com.google.gson.reflect.TypeToken;
|
|
import com.qmth.boot.core.cache.service.CacheService;
|
|
import com.qmth.boot.core.cache.service.CacheService;
|
|
import com.qmth.sop.business.bean.auth.AuthBean;
|
|
import com.qmth.sop.business.bean.auth.AuthBean;
|
|
|
|
+import com.qmth.sop.business.bean.dto.MenuDto;
|
|
|
|
+import com.qmth.sop.business.bean.dto.MenuPrivilegeDto;
|
|
import com.qmth.sop.business.bean.result.FormWidgetResult;
|
|
import com.qmth.sop.business.bean.result.FormWidgetResult;
|
|
|
|
+import com.qmth.sop.business.bean.result.MenuResult;
|
|
import com.qmth.sop.business.cache.CommonCacheService;
|
|
import com.qmth.sop.business.cache.CommonCacheService;
|
|
import com.qmth.sop.business.entity.*;
|
|
import com.qmth.sop.business.entity.*;
|
|
import com.qmth.sop.business.service.*;
|
|
import com.qmth.sop.business.service.*;
|
|
@@ -19,6 +22,7 @@ import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -573,12 +577,175 @@ public class CommonCacheServiceImpl implements CommonCacheService {
|
|
cacheService.evict(SystemConstant.TABLE_PROP_CACHE, String.valueOf(widgetId));
|
|
cacheService.evict(SystemConstant.TABLE_PROP_CACHE, String.valueOf(widgetId));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 添加用户菜单缓存
|
|
|
|
+ *
|
|
|
|
+ * @param userId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public MenuResult userMenuCache(Long userId) {
|
|
|
|
+ return userMenuCommon(userId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改用户菜单缓存
|
|
|
|
+ *
|
|
|
|
+ * @param userId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public MenuResult updateUserMenuCache(Long userId) {
|
|
|
|
+ cacheService.evict(SystemConstant.USER_MENU_CACHE, String.valueOf(userId));
|
|
|
|
+ return userMenuCommon(userId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除用户菜单缓存
|
|
|
|
+ *
|
|
|
|
+ * @param userId
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void removeUserMenuCache(Long userId) {
|
|
|
|
+ cacheService.evict(SystemConstant.USER_MENU_CACHE, String.valueOf(userId));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 添加角色缓存
|
|
|
|
+ *
|
|
|
|
+ * @param roleId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public SysRole roleCache(Long roleId) {
|
|
|
|
+ return roleCacheCommon(roleId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改角色缓存
|
|
|
|
+ *
|
|
|
|
+ * @param roleId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public SysRole updateRoleCache(Long roleId) {
|
|
|
|
+ cacheService.evict(SystemConstant.ROLE_CACHE, String.valueOf(roleId));
|
|
|
|
+ return roleCacheCommon(roleId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除角色缓存
|
|
|
|
+ *
|
|
|
|
+ * @param roleId
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void removeRoleCache(Long roleId) {
|
|
|
|
+ cacheService.evict(SystemConstant.ROLE_CACHE, String.valueOf(roleId));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 角色缓存共用
|
|
|
|
+ *
|
|
|
|
+ * @param roleId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ protected SysRole roleCacheCommon(Long roleId) {
|
|
|
|
+ SysRole sysRole = (SysRole) cacheService.get(SystemConstant.ROLE_CACHE, String.valueOf(roleId));
|
|
|
|
+ if (Objects.isNull(sysRole)) {
|
|
|
|
+ sysRole = sysRoleService.getById(roleId);
|
|
|
|
+ if (Objects.nonNull(sysRole)) {
|
|
|
|
+ cacheService.put(SystemConstant.ROLE_CACHE, String.valueOf(roleId), sysRole);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return sysRole;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取用户菜单
|
|
|
|
+ *
|
|
|
|
+ * @param userId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ protected MenuResult userMenuCommon(Long userId) {
|
|
|
|
+ MenuResult menuResult = (MenuResult) cacheService.get(SystemConstant.USER_MENU_CACHE, String.valueOf(userId));
|
|
|
|
+ if (Objects.isNull(menuResult)) {
|
|
|
|
+ SysUser sysUser = this.userCache(userId);
|
|
|
|
+ List<SysUserRole> sysUserRoleList = this.userRolePrivilegeCache(userId);
|
|
|
|
+ List<SysRolePrivilege> sysRolePrivilegeList = new ArrayList<>();
|
|
|
|
+ for (SysUserRole s : sysUserRoleList) {
|
|
|
|
+ SysRole sysRole = this.roleCache(s.getRoleId());
|
|
|
|
+ if (Objects.nonNull(sysRole) && sysRole.getEnable()) {
|
|
|
|
+ sysRolePrivilegeList.addAll(this.rolePrivilegeCache(s.getRoleId()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Set<Long> privilegeIds = sysRolePrivilegeList.stream().map(s -> s.getPrivilegeId()).collect(Collectors.toSet());
|
|
|
|
+ QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ sysPrivilegeQueryWrapper.lambda()
|
|
|
|
+ .eq(SysPrivilege::getEnable, true).eq(SysPrivilege::getFrontDisplay, true)
|
|
|
|
+ .orderByAsc(SysPrivilege::getSequence);
|
|
|
|
+
|
|
|
|
+ if (!privilegeIds.isEmpty()) {
|
|
|
|
+ sysPrivilegeQueryWrapper.lambda().in(SysPrivilege::getId, privilegeIds);
|
|
|
|
+ }
|
|
|
|
+ List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
|
|
|
|
+ List<MenuDto> menuDtoList = GsonUtil.fromJson(JacksonUtil.parseJson(sysPrivilegeList), new TypeToken<List<MenuDto>>() {
|
|
|
|
+ }.getType());
|
|
|
|
+ LinkedMultiValueMap<Long, MenuDto> linkedMultiValueMap = new LinkedMultiValueMap<>();
|
|
|
|
+ List<MenuPrivilegeDto> menuPrivilegeDtoList = new ArrayList<>();
|
|
|
|
+ for (MenuDto m : menuDtoList) {
|
|
|
|
+ if (Objects.isNull(m.getParentId()) || m.getType() == PrivilegeEnum.MENU) {
|
|
|
|
+ menuPrivilegeDtoList.add(GsonUtil.fromJson(GsonUtil.toJson(m), MenuPrivilegeDto.class));
|
|
|
|
+ } else {
|
|
|
|
+ if (!linkedMultiValueMap.containsKey(m.getParentId())) {
|
|
|
|
+ linkedMultiValueMap.add(m.getParentId(), m);
|
|
|
|
+ } else {
|
|
|
|
+ List<MenuDto> menuDtos = linkedMultiValueMap.get(m.getParentId());
|
|
|
|
+ menuDtos.add(m);
|
|
|
|
+ linkedMultiValueMap.put(m.getParentId(), menuDtos);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (MenuPrivilegeDto m : menuPrivilegeDtoList) {
|
|
|
|
+ List<MenuDto> menuDtos = linkedMultiValueMap.get(m.getId());
|
|
|
|
+ List<MenuDto> urls = null, buttons = null, links = null, lists = null, conditions = null;
|
|
|
|
+ if (Objects.nonNull(menuDtos)) {
|
|
|
|
+ for (MenuDto menuDto : menuDtos) {
|
|
|
|
+ if (menuDto.getType() == PrivilegeEnum.BUTTON) {
|
|
|
|
+ buttons = Objects.isNull(buttons) ? new ArrayList<>() : buttons;
|
|
|
|
+ buttons.add(GsonUtil.fromJson(GsonUtil.toJson(menuDto), MenuPrivilegeDto.class));
|
|
|
|
+ m.setButtons(buttons);
|
|
|
|
+ } else if (menuDto.getType() == PrivilegeEnum.LINK) {
|
|
|
|
+ links = Objects.isNull(links) ? new ArrayList<>() : links;
|
|
|
|
+ links.add(GsonUtil.fromJson(GsonUtil.toJson(menuDto), MenuPrivilegeDto.class));
|
|
|
|
+ m.setLinks(links);
|
|
|
|
+ } else if (menuDto.getType() == PrivilegeEnum.URL) {
|
|
|
|
+ urls = Objects.isNull(urls) ? new ArrayList<>() : urls;
|
|
|
|
+ urls.add(GsonUtil.fromJson(GsonUtil.toJson(menuDto), MenuPrivilegeDto.class));
|
|
|
|
+ m.setUrls(urls);
|
|
|
|
+ } else if (menuDto.getType() == PrivilegeEnum.LIST) {
|
|
|
|
+ lists = Objects.isNull(lists) ? new ArrayList<>() : lists;
|
|
|
|
+ lists.add(GsonUtil.fromJson(GsonUtil.toJson(menuDto), MenuPrivilegeDto.class));
|
|
|
|
+ m.setLists(lists);
|
|
|
|
+ } else if (menuDto.getType() == PrivilegeEnum.CONDITION) {
|
|
|
|
+ conditions = Objects.isNull(conditions) ? new ArrayList<>() : conditions;
|
|
|
|
+ conditions.add(GsonUtil.fromJson(GsonUtil.toJson(menuDto), MenuPrivilegeDto.class));
|
|
|
|
+ m.setConditions(conditions);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ menuResult = new MenuResult(userId, menuPrivilegeDtoList);
|
|
|
|
+ cacheService.put(SystemConstant.USER_MENU_CACHE, String.valueOf(userId), menuResult);
|
|
|
|
+ }
|
|
|
|
+ return menuResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 控件缓存共用
|
|
* 控件缓存共用
|
|
*
|
|
*
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private List<TDTableProp> tablePropCacheCommon(Long widgetId) {
|
|
|
|
|
|
+ protected List<TDTableProp> tablePropCacheCommon(Long widgetId) {
|
|
List<TDTableProp> tablePropList = (List<TDTableProp>) cacheService.get(SystemConstant.TABLE_PROP_CACHE, String.valueOf(widgetId));
|
|
List<TDTableProp> tablePropList = (List<TDTableProp>) cacheService.get(SystemConstant.TABLE_PROP_CACHE, String.valueOf(widgetId));
|
|
if (CollectionUtils.isEmpty(tablePropList)) {
|
|
if (CollectionUtils.isEmpty(tablePropList)) {
|
|
tablePropList = tdTablePropService.list(new QueryWrapper<TDTableProp>().lambda().eq(TDTableProp::getWidgetId, widgetId));
|
|
tablePropList = tdTablePropService.list(new QueryWrapper<TDTableProp>().lambda().eq(TDTableProp::getWidgetId, widgetId));
|
|
@@ -595,7 +762,7 @@ public class CommonCacheServiceImpl implements CommonCacheService {
|
|
* @param id
|
|
* @param id
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private TDFormWidget formWidgetCacheCommon(Long id) {
|
|
|
|
|
|
+ protected TDFormWidget formWidgetCacheCommon(Long id) {
|
|
TDFormWidget tdFormWidget = (TDFormWidget) cacheService.get(SystemConstant.FORM_WIDGET_CACHE, String.valueOf(id));
|
|
TDFormWidget tdFormWidget = (TDFormWidget) cacheService.get(SystemConstant.FORM_WIDGET_CACHE, String.valueOf(id));
|
|
if (Objects.isNull(tdFormWidget)) {
|
|
if (Objects.isNull(tdFormWidget)) {
|
|
tdFormWidget = tdFormWidgetService.getById(id);
|
|
tdFormWidget = tdFormWidgetService.getById(id);
|
|
@@ -611,7 +778,7 @@ public class CommonCacheServiceImpl implements CommonCacheService {
|
|
*
|
|
*
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private List<FormWidgetResult> formWidgetCacheCommon() {
|
|
|
|
|
|
+ protected List<FormWidgetResult> formWidgetCacheCommon() {
|
|
List<FormWidgetResult> formWidgetResultList = (List<FormWidgetResult>) cacheService.get(SystemConstant.FORM_WIDGET_CACHE, SystemConstant.FORM_WIDGET_CACHE);
|
|
List<FormWidgetResult> formWidgetResultList = (List<FormWidgetResult>) cacheService.get(SystemConstant.FORM_WIDGET_CACHE, SystemConstant.FORM_WIDGET_CACHE);
|
|
if (CollectionUtils.isEmpty(formWidgetResultList)) {
|
|
if (CollectionUtils.isEmpty(formWidgetResultList)) {
|
|
List<TDFormWidget> tdFormWidgetList = tdFormWidgetService.list(new QueryWrapper<TDFormWidget>().select(" DISTINCT code "));
|
|
List<TDFormWidget> tdFormWidgetList = tdFormWidgetService.list(new QueryWrapper<TDFormWidget>().select(" DISTINCT code "));
|
|
@@ -630,7 +797,7 @@ public class CommonCacheServiceImpl implements CommonCacheService {
|
|
* @param privilegePropertyEnum
|
|
* @param privilegePropertyEnum
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private Set<String> privilegeUrlCacheCommon(PrivilegePropertyEnum privilegePropertyEnum) {
|
|
|
|
|
|
+ protected Set<String> privilegeUrlCacheCommon(PrivilegePropertyEnum privilegePropertyEnum) {
|
|
Set<String> privilegeUrlSet = (Set<String>) cacheService.get(SystemConstant.PRIVILEGE_URL_CACHE, privilegePropertyEnum.name());
|
|
Set<String> privilegeUrlSet = (Set<String>) cacheService.get(SystemConstant.PRIVILEGE_URL_CACHE, privilegePropertyEnum.name());
|
|
if (CollectionUtils.isEmpty(privilegeUrlSet)) {
|
|
if (CollectionUtils.isEmpty(privilegeUrlSet)) {
|
|
List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(new QueryWrapper<SysPrivilege>().lambda().eq(SysPrivilege::getType, PrivilegeEnum.URL).eq(SysPrivilege::getProperty, privilegePropertyEnum).eq(SysPrivilege::getEnable, true));
|
|
List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(new QueryWrapper<SysPrivilege>().lambda().eq(SysPrivilege::getType, PrivilegeEnum.URL).eq(SysPrivilege::getProperty, privilegePropertyEnum).eq(SysPrivilege::getEnable, true));
|
|
@@ -648,7 +815,7 @@ public class CommonCacheServiceImpl implements CommonCacheService {
|
|
* @param orgId
|
|
* @param orgId
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private SysOrg orgCacheCommon(Long orgId) {
|
|
|
|
|
|
+ protected SysOrg orgCacheCommon(Long orgId) {
|
|
SysOrg sysOrg = (SysOrg) cacheService.get(SystemConstant.ORG_CACHE, String.valueOf(orgId));
|
|
SysOrg sysOrg = (SysOrg) cacheService.get(SystemConstant.ORG_CACHE, String.valueOf(orgId));
|
|
if (Objects.isNull(sysOrg)) {
|
|
if (Objects.isNull(sysOrg)) {
|
|
sysOrg = sysOrgService.getById(orgId);
|
|
sysOrg = sysOrgService.getById(orgId);
|
|
@@ -665,7 +832,7 @@ public class CommonCacheServiceImpl implements CommonCacheService {
|
|
* @param userId
|
|
* @param userId
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private List<SysUserRole> userRoleCacheCommon(Long userId) {
|
|
|
|
|
|
+ protected List<SysUserRole> userRoleCacheCommon(Long userId) {
|
|
List<SysUserRole> sysUserRoleList = (List<SysUserRole>) cacheService.get(SystemConstant.USER_ROLE_PRIVILEGE_CACHE, String.valueOf(userId));
|
|
List<SysUserRole> sysUserRoleList = (List<SysUserRole>) cacheService.get(SystemConstant.USER_ROLE_PRIVILEGE_CACHE, String.valueOf(userId));
|
|
if (CollectionUtils.isEmpty(sysUserRoleList)) {
|
|
if (CollectionUtils.isEmpty(sysUserRoleList)) {
|
|
sysUserRoleList = sysUserRoleService.list(new QueryWrapper<SysUserRole>().lambda().eq(SysUserRole::getUserId, userId).eq(SysUserRole::getEnable, true));
|
|
sysUserRoleList = sysUserRoleService.list(new QueryWrapper<SysUserRole>().lambda().eq(SysUserRole::getUserId, userId).eq(SysUserRole::getEnable, true));
|
|
@@ -682,7 +849,7 @@ public class CommonCacheServiceImpl implements CommonCacheService {
|
|
* @param roleId
|
|
* @param roleId
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private List<SysRolePrivilege> rolePrivilegeCacheCommon(Long roleId) {
|
|
|
|
|
|
+ protected List<SysRolePrivilege> rolePrivilegeCacheCommon(Long roleId) {
|
|
List<SysRolePrivilege> sysRolePrivilegeList = (List<SysRolePrivilege>) cacheService.get(SystemConstant.ROLE_PRIVILEGE_CACHE, String.valueOf(roleId));
|
|
List<SysRolePrivilege> sysRolePrivilegeList = (List<SysRolePrivilege>) cacheService.get(SystemConstant.ROLE_PRIVILEGE_CACHE, String.valueOf(roleId));
|
|
if (CollectionUtils.isEmpty(sysRolePrivilegeList)) {
|
|
if (CollectionUtils.isEmpty(sysRolePrivilegeList)) {
|
|
sysRolePrivilegeList = sysRolePrivilegeService.list(new QueryWrapper<SysRolePrivilege>().lambda().eq(SysRolePrivilege::getRoleId, roleId));
|
|
sysRolePrivilegeList = sysRolePrivilegeService.list(new QueryWrapper<SysRolePrivilege>().lambda().eq(SysRolePrivilege::getRoleId, roleId));
|