|
|
@@ -6,11 +6,13 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.jzg.commons.constants.SystemConstants;
|
|
|
import com.jzg.commons.entity.dto.SysSystemAddParam;
|
|
|
import com.jzg.commons.entity.dto.SysSystemEditParam;
|
|
|
import com.jzg.commons.entity.dto.SysSystemParam;
|
|
|
import com.jzg.commons.entity.enums.YesNoEnum;
|
|
|
import com.jzg.commons.entity.po.*;
|
|
|
+import com.jzg.commons.entity.vo.SysConfigVo;
|
|
|
import com.jzg.commons.entity.vo.SysSystemPermsVo;
|
|
|
import com.jzg.commons.entity.vo.SysSystemVo;
|
|
|
import com.jzg.commons.entity.vo.UpAndDownVo;
|
|
|
@@ -18,7 +20,6 @@ import com.jzg.commons.util.MinioUtils;
|
|
|
import com.jzg.commons.util.StringUtils;
|
|
|
import com.jzg.mapper.*;
|
|
|
import com.jzg.service.SysSystemService;
|
|
|
-import com.jzg.commons.util.MinioUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
@@ -61,22 +62,12 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
|
|
|
private String bucketName;
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public boolean updatePerms(SysSystemPermsVo sysSystemPermsVo) {
|
|
|
- String permsStr = JSON.toJSONString(sysSystemPermsVo.getPerms());
|
|
|
- List<SysConfig> configs = sysConfigMapper.selectList(new LambdaQueryWrapper<SysConfig>()
|
|
|
- .eq(SysConfig::getType, 1).eq(SysConfig::getSystemCode,sysSystemPermsVo.getSystemCode()));
|
|
|
- SysConfig config;
|
|
|
- if(CollUtil.isEmpty(configs)){
|
|
|
- config = new SysConfig();
|
|
|
- config.setSysConfig(permsStr);
|
|
|
- config.setType(1);
|
|
|
- config.setSystemCode(sysSystemPermsVo.getSystemCode());
|
|
|
- sysConfigMapper.insert(config);
|
|
|
- }else{
|
|
|
- config = configs.get(0);
|
|
|
- config.setSysConfig(permsStr);
|
|
|
- sysConfigMapper.updateById(config);
|
|
|
- }
|
|
|
+ // 保存勾选菜单配置
|
|
|
+ String permsStr = sysSystemPermsVo.getPermsStr();
|
|
|
+ this.saveConfig(permsStr, 1, sysSystemPermsVo.getSystemCode());
|
|
|
+
|
|
|
// 获取租户管理员角色id
|
|
|
LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(SysRole::getSystemCode, sysSystemPermsVo.getSystemCode())
|
|
|
@@ -86,34 +77,71 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
|
|
|
LambdaQueryWrapper<SysRolePerms> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(SysRolePerms::getRoleId,roles.get(0).getId());
|
|
|
sysRolePermsMapper.delete(wrapper);
|
|
|
- List<SysRolePerms> perms = new ArrayList<>();
|
|
|
- sysSystemPermsVo.getPerms().forEach(per->{
|
|
|
- SysRolePerms sysSystemPerms = new SysRolePerms();
|
|
|
- sysSystemPerms.setRoleId(roles.get(0).getId());
|
|
|
- sysSystemPerms.setPermsId(per.getPermsId());
|
|
|
- sysSystemPerms.setPerms(per.getPerms());
|
|
|
- perms.add(sysSystemPerms);
|
|
|
- });
|
|
|
- return !sysRolePermsMapper.insert(perms).isEmpty();
|
|
|
+
|
|
|
+ List<SysSystemPermsVo.PermsVo> permsList = sysSystemPermsVo.getPerms();
|
|
|
+ return this.savePerms(permsList, roles.get(0).getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存配置信息
|
|
|
+ * @param configStr 配置json
|
|
|
+ * @param type 1.全部菜单
|
|
|
+ * @param sysCode 系统code
|
|
|
+ */
|
|
|
+ public void saveConfig(String configStr, Integer type, String sysCode){
|
|
|
+ List<SysConfig> checkConfigs = sysConfigMapper.selectList(new LambdaQueryWrapper<SysConfig>()
|
|
|
+ .eq(SysConfig::getType, type).eq(SysConfig::getSystemCode,sysCode));
|
|
|
+ SysConfig config;
|
|
|
+ if(CollUtil.isEmpty(checkConfigs)){
|
|
|
+ config = new SysConfig();
|
|
|
+ config.setSysConfig(configStr);
|
|
|
+ config.setType(2);
|
|
|
+ config.setSystemCode(sysCode);
|
|
|
+ sysConfigMapper.insert(config);
|
|
|
+ }else{
|
|
|
+ config = checkConfigs.get(0);
|
|
|
+ config.setSysConfig(configStr);
|
|
|
+ sysConfigMapper.updateById(config);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+
|
|
|
+ * 递归把传过来的tree转为list
|
|
|
+ *
|
|
|
+ * @param result 结果集
|
|
|
+ * @param root 当前对象
|
|
|
+ */
|
|
|
+ public void recursionTreeToList(List<SysSystemPermsVo.PermsVo> result, SysSystemPermsVo.PermsVo root) {
|
|
|
+ result.add(root);
|
|
|
+ if (CollUtil.isEmpty(root.getChildren())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (SysSystemPermsVo.PermsVo child : root.getChildren()) {
|
|
|
+ this.recursionTreeToList(result, child);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<SysRolePerms> getSystemPerms(String systemCode) {
|
|
|
+ public List<String> getSystemPerms(String systemCode) {
|
|
|
LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(SysRole::getSystemCode, systemCode)
|
|
|
.like(SysRole::getName,"管理员");
|
|
|
List<SysRole> roles = sysRoleMapper.selectList(queryWrapper);
|
|
|
- List<SysRolePerms> sysSystemPerms = sysRolePermsMapper.selectList(new LambdaQueryWrapper<SysRolePerms>()
|
|
|
- .eq(SysRolePerms::getRoleId, roles.get(0).getId()));
|
|
|
- return sysSystemPerms;
|
|
|
+ List<SysRolePerms> sysSystemPerms = sysRolePermsMapper.getByRoleId(roles.get(0).getId());
|
|
|
+ List<String> permsIds = sysSystemPerms.stream().map(SysRolePerms::getPermsId).collect(Collectors.toList());
|
|
|
+ return permsIds;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public boolean updateConfig(SysConfig config) {
|
|
|
List<SysConfig> configs = sysConfigMapper.selectList(new LambdaQueryWrapper<SysConfig>()
|
|
|
- .eq(SysConfig::getType, 0));
|
|
|
+ .eq(SysConfig::getType, 0)
|
|
|
+ .eq(SysConfig::getSystemCode, SystemConstants.SYSTEM_PLATFORM.getCode()));
|
|
|
if(CollUtil.isEmpty(configs)){
|
|
|
config.setType(0);
|
|
|
+ config.setSystemCode(SystemConstants.SYSTEM_PLATFORM.getCode());
|
|
|
sysConfigMapper.insert(config);
|
|
|
}else{
|
|
|
config.setId(configs.get(0).getId());
|
|
|
@@ -123,9 +151,13 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public SysConfig getSystemConfig() {
|
|
|
+ public SysConfig getSystemConfig(SysConfigVo sysConfigVo) {
|
|
|
List<SysConfig> configs = sysConfigMapper.selectList(new LambdaQueryWrapper<SysConfig>()
|
|
|
- .eq(SysConfig::getType, 0));
|
|
|
+ .eq(SysConfig::getType, sysConfigVo.getType())
|
|
|
+ .eq(StringUtils.isNotEmpty(sysConfigVo.getSystemCode()),SysConfig::getSystemCode, sysConfigVo.getSystemCode()));
|
|
|
+ if(CollUtil.isEmpty(configs)){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
return configs.get(0);
|
|
|
}
|
|
|
|
|
|
@@ -135,7 +167,7 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public SysSystem getBySystemCode(String systemCode ) {
|
|
|
+ public SysSystem getBySystemCode(String systemCode) {
|
|
|
return this.getOne(new LambdaQueryWrapper<SysSystem>()
|
|
|
.eq(SysSystem::getSysCode, systemCode)
|
|
|
.eq(SysSystem::getAvailable, YesNoEnum.YES.getCode())
|
|
|
@@ -252,11 +284,45 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
|
|
|
userRole.setUserId(userId);
|
|
|
userRole.setRoleId(role.getId());
|
|
|
sysUserRoleMapper.insert(userRole);
|
|
|
+ // 初始化权限信息
|
|
|
+ // 1.初始化配置的保存
|
|
|
+ List<SysConfig> configs = sysConfigMapper.selectList(new LambdaQueryWrapper<SysConfig>()
|
|
|
+ .eq(SysConfig::getType, 0)
|
|
|
+ .eq(SysConfig::getSystemCode, SystemConstants.SYSTEM_PLATFORM.getCode()));
|
|
|
+ this.saveConfig(configs.get(0).getSysConfig(), 0, SystemConstants.SYSTEM_PLATFORM.getCode());
|
|
|
+
|
|
|
+ List<SysSystemPermsVo.PermsVo> permsList = JSON.parseArray(configs.get(0).getSysConfig(),SysSystemPermsVo.PermsVo.class);;
|
|
|
+
|
|
|
+ this.savePerms(permsList, role.getId());
|
|
|
// 租户绑定管理员信息
|
|
|
sysSystem.setUserId(userId);
|
|
|
this.updateById(sysSystem);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 租户权限保存
|
|
|
+ * @param permsList 树形租户权限
|
|
|
+ * @param roleId 角色id
|
|
|
+ */
|
|
|
+ public boolean savePerms(List<SysSystemPermsVo.PermsVo> permsList, String roleId){
|
|
|
+ List<SysSystemPermsVo.PermsVo> all = new ArrayList<>();
|
|
|
+ for (SysSystemPermsVo.PermsVo permsVo : permsList) {
|
|
|
+ List<SysSystemPermsVo.PermsVo> result = new ArrayList<>();
|
|
|
+ this.recursionTreeToList(result, permsVo);
|
|
|
+ all.addAll(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SysRolePerms> perms = new ArrayList<>();
|
|
|
+ all.forEach(per->{
|
|
|
+ SysRolePerms sysSystemPerms = new SysRolePerms();
|
|
|
+ sysSystemPerms.setRoleId(roleId);
|
|
|
+ sysSystemPerms.setPermsId(per.getId());
|
|
|
+ sysSystemPerms.setPerms(per.getAuth());
|
|
|
+ perms.add(sysSystemPerms);
|
|
|
+ });
|
|
|
+ return !sysRolePermsMapper.insert(perms).isEmpty();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void sysEdit(SysSystemEditParam param) {
|