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