Browse Source

产品签约自动关联到超管角色

yuandeguo 3 years ago
parent
commit
2e3c1c456e

+ 1 - 1
saas-account/src/main/java/com/persagy/account/pojo/dto/SaasGroupProductPage.java

@@ -25,7 +25,7 @@ import lombok.ToString;
 @Setter
 @ToString
 @EqualsAndHashCode(callSuper = false)
-@TableName("saas_group_product_detail")
+@TableName("saas_group_product_page")
 public class SaasGroupProductPage extends Model<SaasGroupProductPage> {
 	private static final long serialVersionUID = -4851547634570454698L;
 

+ 3 - 0
saas-account/src/main/java/com/persagy/account/service/ISaasRoleMenuService.java

@@ -49,5 +49,8 @@ public interface ISaasRoleMenuService extends ISuperService<SaasRoleMenu> {
 	 */
 	int countFunction(String roleId, String menuId);
 
+    void createDefaultSaasRoleMenu(String groupCode, String productId);
+
+	void updateDefaultSaasRoleMenu(String groupCode, String beforeProductId, String afterProductId);
 }
 

+ 28 - 9
saas-account/src/main/java/com/persagy/account/service/impl/SaasGroupProductServiceImpl.java

@@ -1,22 +1,27 @@
 package com.persagy.account.service.impl;
 
-import java.util.Date;
-import java.util.Set;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
-import com.persagy.account.mapper.SaasGroupProductPageMapper;
 import com.persagy.account.mapper.SaasGroupProductMapper;
+import com.persagy.account.mapper.SaasGroupProductPageMapper;
 import com.persagy.account.mapper.SaasProjectProductMapper;
 import com.persagy.account.pojo.dto.SaasGroupProduct;
 import com.persagy.account.pojo.dto.SaasGroupProductPage;
 import com.persagy.account.pojo.dto.SaasProjectProduct;
 import com.persagy.account.service.ISaasGroupProductService;
+import com.persagy.account.service.ISaasRoleMenuService;
+import com.persagy.common.enums.ResponseCode;
 import com.persagy.common.service.impl.SuperServiceImpl;
+import com.persagy.common.utils.ResponseResultUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Date;
+import java.util.Objects;
+import java.util.Set;
 
 /**
  * 集团签约产品
@@ -26,6 +31,7 @@ import com.persagy.common.service.impl.SuperServiceImpl;
  * @author zhangqiankun
  * @date 2021-05-07 12:02:40
  */
+@Slf4j
 @Service
 public class SaasGroupProductServiceImpl extends SuperServiceImpl<SaasGroupProductMapper, SaasGroupProduct> implements ISaasGroupProductService {
 
@@ -34,7 +40,9 @@ public class SaasGroupProductServiceImpl extends SuperServiceImpl<SaasGroupProdu
 	
 	@Autowired
 	private SaasGroupProductPageMapper saasGroupProductPageMapper;
-	
+	@Autowired
+	private ISaasRoleMenuService saasRoleMenuService;
+
 	@Override
 	@Transactional
 	public boolean createSaasGroupProduct(SaasGroupProduct saasGroupProduct, Set<String> pageIds) {
@@ -44,6 +52,8 @@ public class SaasGroupProductServiceImpl extends SuperServiceImpl<SaasGroupProdu
 		if (SqlHelper.retBool(result)) {
 			// 创建签约信息与产品页面的关联关系
 			result = this.saasGroupProductPageMapper.insertSaasGroupProductPage(saasGroupProduct.getId(), pageIds);
+			// 将签约的产品关联到超管默认角色
+			saasRoleMenuService.createDefaultSaasRoleMenu(saasGroupProduct.getGroupCode(),saasGroupProduct.getProductId());
 		}
 		return SqlHelper.retBool(result);
 	}
@@ -51,6 +61,11 @@ public class SaasGroupProductServiceImpl extends SuperServiceImpl<SaasGroupProdu
 	@Override
 	@Transactional
 	public boolean updateSaasGroupProduct(SaasGroupProduct saasGroupProduct, Set<String> pageIds) {
+		SaasGroupProduct oldSaasGroupProduct = this.baseMapper.selectById(saasGroupProduct.getId());
+		if (Objects.isNull(oldSaasGroupProduct)){
+			log.info("签约信息不存在,签约ID:{}",saasGroupProduct.getId());
+			return false;
+		}
 		// 优先更新产品集团签约信息
 		Integer result = this.baseMapper.updateById(saasGroupProduct);
 		if (SqlHelper.retBool(result)) {
@@ -59,6 +74,10 @@ public class SaasGroupProductServiceImpl extends SuperServiceImpl<SaasGroupProdu
 			this.saasGroupProductPageMapper.delete(queryWrapper);
 			// 创建签约信息与产品页面的关联关系
 			result = this.saasGroupProductPageMapper.insertSaasGroupProductPage(saasGroupProduct.getId(), pageIds);
+			// 修改签约产品与超管角色的关联
+			if (!StringUtils.equals(oldSaasGroupProduct.getProductId(),saasGroupProduct.getProductId())){
+				saasRoleMenuService.updateDefaultSaasRoleMenu(saasGroupProduct.getGroupCode(),oldSaasGroupProduct.getProductId(),saasGroupProduct.getProductId());
+			}
 		}
 		return SqlHelper.retBool(result);
 	}

+ 85 - 5
saas-account/src/main/java/com/persagy/account/service/impl/SaasRoleMenuServiceImpl.java

@@ -1,18 +1,26 @@
 package com.persagy.account.service.impl;
 
-import java.util.List;
-
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
+import com.persagy.account.mapper.SaasProductMapper;
+import com.persagy.account.mapper.SaasRoleMapper;
 import com.persagy.account.mapper.SaasRoleMenuMapper;
+import com.persagy.account.pojo.dto.SaasProduct;
+import com.persagy.account.pojo.dto.SaasRole;
 import com.persagy.account.pojo.dto.SaasRoleMenu;
 import com.persagy.account.pojo.vo.auth.SaasMenuFunctionVO;
 import com.persagy.account.service.ISaasRoleMenuService;
 import com.persagy.common.constant.SaasCommonConstant;
 import com.persagy.common.service.impl.SuperServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.Objects;
 
 /**
  * 角色-菜单功能关联信息
@@ -22,9 +30,17 @@ import com.persagy.common.service.impl.SuperServiceImpl;
  * @author zhangqiankun
  * @date 2021-03-13 15:29:50
  */
+@Slf4j
 @Service
 public class SaasRoleMenuServiceImpl extends SuperServiceImpl<SaasRoleMenuMapper, SaasRoleMenu> implements ISaasRoleMenuService {
 
+	@Autowired
+	private SaasProductMapper saasProductMapper;
+	@Autowired
+	private SaasRoleMenuMapper saasRoleMenuMapper;
+	@Autowired
+	private SaasRoleMapper saasRoleMapper;
+
 	@Override
 	@Transactional
 	public boolean batchCreateSaasRoleMenu(String groupCode, String roleId, List<SaasMenuFunctionVO> auths) {
@@ -55,4 +71,68 @@ public class SaasRoleMenuServiceImpl extends SuperServiceImpl<SaasRoleMenuMapper
 		return count == null ? 0 : count;
 	}
 
+	/**
+	 * 签约产品时将签约产品使用权限默认赋给超管角色
+	 * @param groupCode
+	 * @param productId
+	 */
+	@Override
+	public void createDefaultSaasRoleMenu(String groupCode, String productId) {
+
+		SaasProduct saasProduct = saasProductMapper.selectById(productId);
+		if (Objects.isNull(saasProduct) || StringUtils.isBlank(saasProduct.getMenuId())){
+			log.info("产品信息不存在或产品为关联菜单,产品ID:{}",productId);
+			return;
+		}
+		//获取集团业务超管账号默认角色
+		LambdaQueryWrapper<SaasRole> queryWrapper = new SaasRole.Builder().createQueryWrapper().groupCodeEq(groupCode)
+				.roleTypeEq(SaasCommonConstant.STR_STATUS_2).validEq(SaasCommonConstant.STATUS_1).builderQueryWrapper();
+		SaasRole saasRole = this.saasRoleMapper.selectOne(queryWrapper);
+		if (saasRole == null) {
+			log.info("集团业务超管账号默认角色不存在,集团编码:{}",groupCode);
+			return;
+		}
+		SaasRoleMenu saasRoleMenu = new SaasRoleMenu();
+		saasRoleMenu.setRoleId(saasRole.getId());
+		saasRoleMenu.setMenuId(saasProduct.getMenuId());
+		saasRoleMenu.setGroupCode(groupCode);
+		saasRoleMenuMapper.insert(saasRoleMenu);
+	}
+
+	/**
+	 * 更新签约产品与超管角色的默认菜单权限
+	 * @param groupCode
+	 * @param beforeProductId
+	 * @param afterProductId
+	 */
+	@Override
+	public void updateDefaultSaasRoleMenu(String groupCode, String beforeProductId, String afterProductId) {
+
+		//获取集团业务超管账号默认角色
+		LambdaQueryWrapper<SaasRole> queryWrapper = new SaasRole.Builder().createQueryWrapper().groupCodeEq(groupCode)
+				.roleTypeEq(SaasCommonConstant.STR_STATUS_2).validEq(SaasCommonConstant.STATUS_1).builderQueryWrapper();
+		SaasRole saasRole = this.saasRoleMapper.selectOne(queryWrapper);
+		if (saasRole == null) {
+			log.info("集团业务超管账号默认角色不存在,集团编码:{}",groupCode);
+			return;
+		}
+		//删除原来的关联关系
+		SaasProduct beforeSaasProduct = saasProductMapper.selectById(beforeProductId);
+		if (Objects.nonNull(beforeSaasProduct) && StringUtils.isNotBlank(beforeSaasProduct.getMenuId())){
+			LambdaUpdateWrapper<SaasRoleMenu> saasRoleMenuWrapper = new SaasRoleMenu.Builder().createUpdateWrapper()
+					.groupCodeEq(groupCode).menuIdEq(beforeSaasProduct.getMenuId()).builderUpdateWrapper();
+			saasRoleMenuMapper.delete(saasRoleMenuWrapper);
+		}
+		//创建新的关联关系
+		SaasProduct afterSaasProduct = saasProductMapper.selectById(afterProductId);
+		if (Objects.isNull(afterSaasProduct) || StringUtils.isBlank(afterSaasProduct.getMenuId())){
+			log.info("产品信息不存在或产品为关联菜单,产品ID:{}",afterProductId);
+			return;
+		}
+		SaasRoleMenu saasRoleMenu = new SaasRoleMenu();
+		saasRoleMenu.setRoleId(saasRole.getId());
+		saasRoleMenu.setMenuId(afterSaasProduct.getMenuId());
+		saasRoleMenu.setGroupCode(groupCode);
+		saasRoleMenuMapper.insert(saasRoleMenu);
+	}
 }

+ 35 - 0
saas-doc/doc/saas-account/queryMenuFunctionList.puml

@@ -0,0 +1,35 @@
+@startuml
+start
+if (超管?) then (是)
+  :根据菜单ID查询菜单;
+else (否)
+  :根据账号ID验证菜单权限;
+endif
+if (菜单为默认菜单?) then (是)
+  :根据默认菜单查询功能点;
+  :返回功能点;
+  stop
+else (否)
+  if(是否有productId?) then(否)
+    if(超管?)then(是)
+       :直接根据菜单ID查询
+       功能点(SAAS_FUNCTION);
+    else(否)
+       :根据账号角色菜单关联查询功能点
+       (SAAS_ROLE_MENU.functionId);
+    endif
+    :返回功能点信息;
+    stop
+  else (是)
+    if(是否为系统账号?)then(是)
+    else(否)
+        :根据集团视角和项目视角
+        验证集团或项目签约产品
+        (若无签约产品直接返回);
+    endif
+    :查询产品页树(SaasProductPage);
+    :返回产品页信息;
+    stop
+  endif
+endif
+@enduml