فهرست منبع

租户权限的修改

dongxin 1 سال پیش
والد
کامیت
3392175b5c

+ 36 - 0
commons/src/main/java/com/jzg/commons/entity/po/SysConfig.java

@@ -0,0 +1,36 @@
+package com.jzg.commons.entity.po;
+
+import java.io.Serializable;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * 全局配置表 sys_config
+ *
+ * @author dongxin
+ */
+@Schema(description = "全局配置表")
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class SysConfig {
+
+    /** 主键 */
+    @Schema(description = "主键")
+    private String id;
+
+    /** 系统配置json */
+    @Schema(description = "系统配置json")
+    private String sysConfig;
+
+    /** 配置类型 0-初始化配置 1-权限配置 */
+    @Schema(description = "配置类型 0-初始化配置 1-权限配置")
+    private Integer type;
+
+    /** 系统code */
+    @Schema(description = "系统code")
+    private String systemCode;
+}

+ 3 - 0
commons/src/main/java/com/jzg/commons/entity/vo/SysSystemPermsVo.java

@@ -18,6 +18,9 @@ public class SysSystemPermsVo {
     @Schema(description = "权限列表")
     private List<PermsVo> perms;
 
+    @NotBlank(message = "权限列表json不能为空")
+    @Schema(description = "权限列表json")
+    private String permsStr;
 
     @Data
     public static class PermsVo{

+ 4 - 0
commons/src/main/java/com/jzg/commons/entity/vo/SysSystemVo.java

@@ -101,4 +101,8 @@ public class SysSystemVo extends BaseModel {
     /** 系统图标url */
     @Schema(description = "系统图标url")
     private String sysIconUrl;
+
+    /** 机构数量 */
+    @Schema(description = "机构数量")
+    private Integer deptCount;
 }

+ 40 - 6
platform/src/main/java/com/jzg/controller/SysSystemController.java

@@ -6,6 +6,7 @@ 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.SysConfig;
 import com.jzg.commons.entity.vo.SysSystemPermsVo;
 import com.jzg.commons.entity.vo.SysSystemVo;
 import com.jzg.commons.entity.vo.UpAndDownVo;
@@ -33,20 +34,53 @@ public class SysSystemController {
     @Autowired
     private SysSystemService sysSystemService;
 
+    /**
+     * 获取初始化配置
+     * @return
+     */
+    @GetMapping("/getSystemConfig")
+    @Operation(summary = "获取初始化配置")
+    public HttpResult getSystemConfig(){
+        return HttpResult.ok(sysSystemService.getSystemConfig());
+    }
+
+
+    /**
+     * 更新初始化配置
+     * @param sysConfig
+     * @return
+     */
+    @PostMapping("/updateConfig")
+    @Operation(summary = "更新初始化配置")
+    public HttpResult updateConfig(@RequestBody SysConfig sysConfig){
+        return sysSystemService.updateConfig(sysConfig) ?
+                HttpResult.ok("更新初始化配置成功") :
+                HttpResult.error("更新初始化配置失败");
+    }
+
+    /**
+     * 修改租户权限
+     * @param sysSystemPermsVo
+     * @return
+     */
     @PostMapping("/updatePerms")
-    @Operation(summary = "租户权限")
+    @Operation(summary = "修改租户权限")
     public HttpResult updatePerms(@RequestBody SysSystemPermsVo sysSystemPermsVo){
         return sysSystemService.updatePerms(sysSystemPermsVo) ?
                 HttpResult.ok("修改租户权限成功") :
                 HttpResult.error("修改租户权限失败");
     }
 
+    /**
+     * 获取租户权限
+     * @param systemCode
+     * @return
+     */
     @PostMapping("/getSystemPerms")
     @Operation(summary = "获取租户权限")
     public HttpResult getSystemPerms(String systemCode){
         return HttpResult.ok(sysSystemService.getSystemPerms(systemCode));
     }
-
     /**
      * 租户列表
      * @param param
@@ -97,10 +131,10 @@ public class SysSystemController {
     @PutMapping("/sysEdit")
     public HttpResult sysEdit(@Validated @RequestBody SysSystemEditParam param) {
         // 编码和名称不允许重复
-        boolean codeExists = sysSystemService.isExistsCode(param.getSysCode(), param.getId());
-        boolean nameExists = sysSystemService.isExistsName(param.getSysName(), param.getId());
-        AssertionUtils.isFail(codeExists,"租户编码重复!");
-        AssertionUtils.isFail(nameExists,"租户名称重复!");
+        boolean codeExits = sysSystemService.isExistsCode(param.getSysCode(), param.getId());
+        boolean nameExits = sysSystemService.isExistsName(param.getSysName(), param.getId());
+        AssertionUtils.isFail(codeExits,"租户编码重复!");
+        AssertionUtils.isFail(nameExits,"租户名称重复!");
         sysSystemService.sysEdit(param);
         return HttpResult.ok("修改成功");
     }

+ 0 - 2
platform/src/main/java/com/jzg/controller/UserRoleController.java

@@ -1,6 +1,5 @@
 package com.jzg.controller;
 
-
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.jzg.commons.constants.SystemConstants;
 import com.jzg.commons.core.base.BaseController;
@@ -15,7 +14,6 @@ import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
-
 import java.util.List;
 import java.util.Objects;
 

+ 20 - 0
platform/src/main/java/com/jzg/mapper/SysConfigMapper.java

@@ -0,0 +1,20 @@
+package com.jzg.mapper;
+
+import com.jzg.commons.entity.po.SysConfig;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+* @author dongxin
+* @description 针对表【sys_config(全局配置表)】的数据库操作Mapper
+* @createDate 2025-01-20 17:26:28
+* @Entity generator.domain.SysConfig
+*/
+@Mapper
+public interface SysConfigMapper extends BaseMapper<SysConfig> {
+
+}
+
+
+
+

+ 15 - 1
platform/src/main/java/com/jzg/service/SysSystemService.java

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
 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.po.SysConfig;
+import com.jzg.commons.entity.po.SysRolePerms;
 import com.jzg.commons.entity.po.SysSystem;
 import com.jzg.commons.entity.po.SysSystemPerms;
 import com.jzg.commons.entity.vo.SysSystemPermsVo;
@@ -20,6 +22,18 @@ import java.util.List;
  */
 public interface SysSystemService extends IService<SysSystem> {
 
+    /**
+     * 更新初始化配置
+     * @return
+     */
+    public boolean updateConfig(SysConfig config);
+
+    /**
+     * 获取初始化配置
+     * @return
+     */
+    public SysConfig getSystemConfig();
+
     /**
      * 更新租户权限
      * @return
@@ -31,7 +45,7 @@ public interface SysSystemService extends IService<SysSystem> {
      * @param systemCode
      * @return
      */
-    public List<SysSystemPerms> getSystemPerms(String systemCode);
+    public List<SysRolePerms> getSystemPerms(String systemCode);
 
     /**
      * 根据SystemCode 查询 System对象

+ 94 - 20
platform/src/main/java/com/jzg/service/impl/SysSystemServiceImpl.java

@@ -26,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -38,7 +39,7 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
     implements SysSystemService {
 
     @Autowired
-    private SysSystemPermsMapper sysSystemPermsMapper;
+    private SysRolePermsMapper sysRolePermsMapper;
     @Autowired
     private SysUploadFilesMapper sysUploadFilesMapper;
     @Autowired
@@ -50,34 +51,85 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
     @Autowired
     private SysDeptMapper sysDeptMapper;
     @Autowired
+    private SysConfigMapper sysConfigMapper;
+    @Autowired
     private SysUserJzgInfoMapper sysUserJzgInfoMapper;
     @Autowired
+    private SysUserPlateInfoMapper sysUserPlateInfoMapper;
+    @Autowired
     private MinioUtils minioUtils;
     @Value("${minio.bucket-name}")
     private String bucketName;
 
     @Override
     public boolean updatePerms(SysSystemPermsVo sysSystemPermsVo) {
-        List<SysSystemPerms> perms = new ArrayList<>();
+        String permsStr = sysSystemPermsVo.getPermsStr();
+        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);
+        }
+        // 获取租户管理员角色id
+        LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(SysRole::getSystemCode, sysSystemPermsVo.getSystemCode())
+                .like(SysRole::getName,"管理员");
+        List<SysRole> roles = sysRoleMapper.selectList(queryWrapper);
+
+        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->{
-            SysSystemPerms sysSystemPerms = new SysSystemPerms();
-            sysSystemPerms.setId(IdGenerate.nextId());
-            sysSystemPerms.setSystemCode(sysSystemPerms.getSystemCode());
+            SysRolePerms sysSystemPerms = new SysRolePerms();
+            sysSystemPerms.setRoleId(roles.get(0).getId());
             sysSystemPerms.setPermsId(per.getPermsId());
             sysSystemPerms.setPerms(per.getPerms());
             perms.add(sysSystemPerms);
         });
-        return !sysSystemPermsMapper.insert(perms).isEmpty();
+        return !sysRolePermsMapper.insert(perms).isEmpty();
     }
 
     @Override
-    public List<SysSystemPerms> getSystemPerms(String systemCode) {
-        List<SysSystemPerms> sysSystemPerms = sysSystemPermsMapper.selectList(new LambdaQueryWrapper<SysSystemPerms>()
-                .eq(SysSystemPerms::getSystemCode, systemCode));
-
+    public List<SysRolePerms> 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;
     }
 
+    @Override
+    public boolean updateConfig(SysConfig config) {
+        List<SysConfig> configs = sysConfigMapper.selectList(new LambdaQueryWrapper<SysConfig>()
+                .eq(SysConfig::getType, 0));
+        if(CollUtil.isEmpty(configs)){
+            config.setType(0);
+            sysConfigMapper.insert(config);
+        }else{
+            config.setId(configs.get(0).getId());
+            sysConfigMapper.updateById(config);
+        }
+        return true;
+    }
+
+    @Override
+    public SysConfig getSystemConfig() {
+        List<SysConfig> configs = sysConfigMapper.selectList(new LambdaQueryWrapper<SysConfig>()
+                .eq(SysConfig::getType, 0));
+        return configs.get(0);
+    }
+
     /**
      * 根据SystemCode 查询 System对象
      * @param systemCode
@@ -86,7 +138,9 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
     @Override
     public SysSystem getBySystemCode(String systemCode ) {
         return this.getOne(new LambdaQueryWrapper<SysSystem>()
-                .eq(SysSystem::getSysCode, systemCode));
+                .eq(SysSystem::getSysCode, systemCode)
+                .eq(SysSystem::getAvailable, YesNoEnum.YES.getCode())
+                .eq(SysSystem::getIsDelete, YesNoEnum.NO.getCode()));
     }
 
     /**
@@ -117,11 +171,19 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
         Page<SysSystemVo> sysPage = baseMapper.queryPage(page, param);
         List<SysSystemVo> sysSystemList = sysPage.getRecords();
         if(CollUtil.isNotEmpty(sysSystemList)){
+            // 查询所有机构
+            List<SysDept> deptList = sysDeptMapper.selectList(new LambdaQueryWrapper<>());
+            Map<String,List<SysDept>> deptMap = deptList.stream()
+                    .collect(Collectors.groupingBy(SysDept::getSystemCode));
             sysSystemList.forEach(sysSystem->{
                 SysUploadFiles files = sysUploadFilesMapper.selectById(sysSystem.getSysIcon());
                 if(StringUtils.isNotNull(files)){
                     sysSystem.setSysIconUrl(minioUtils.getPresignedObjectUrl(bucketName,files.getFileName()));
                 }
+                if(deptMap.containsKey(sysSystem.getSysCode())){
+                    int count = deptMap.get(sysSystem.getSysCode()).size();
+                    sysSystem.setDeptCount(count);
+                }
             });
         }
         return sysPage;
@@ -168,16 +230,27 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
             userId = user.getId();
         }
         // 新增用户机构关联信息
-        SysUserJzgInfo info = new SysUserJzgInfo();
+        SysUserPlateInfo info = new SysUserPlateInfo();
         info.setUserId(userId);
-        info.setDeptId("");// 后期放最顶级的机构
-        sysUserJzgInfoMapper.insert(info);
+        info.setSystemCode(sysSystem.getSysCode());
+        info.setIsEnable(1);
+        sysUserPlateInfoMapper.insert(info);
+        // 查询该租户是否有管理员角色
+        LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(SysRole::getSystemCode, sysSystem.getSysCode())
+                .like(SysRole::getName,"管理员");
+        List<SysRole> roles = sysRoleMapper.selectList(queryWrapper);
+        SysRole role;
         // 新增管理员角色
-        SysRole role = new SysRole(sysSystem.getSysCode());
-        sysRoleMapper.insert(role);
+        if(CollUtil.isNotEmpty(roles)){
+            role = roles.get(0);
+        }else{
+            role = new SysRole(sysSystem.getSysCode());
+            sysRoleMapper.insert(role);
+        }
         // 关联用户角色
         SysUserRole userRole = new SysUserRole();
-        userRole.setUserId(userId);
+        userRole.setUserId(info.getId());
         userRole.setRoleId(role.getId());
         sysUserRoleMapper.insert(userRole);
         // 租户绑定管理员信息
@@ -207,10 +280,11 @@ public class SysSystemServiceImpl extends ServiceImpl<SysSystemMapper, SysSystem
             sysUser = new SysUser(param);
             sysUserMapper.insert(sysUser);
             // 新增用户机构关联信息
-            SysUserJzgInfo info = new SysUserJzgInfo();
+            SysUserPlateInfo info = new SysUserPlateInfo();
             info.setUserId(sysUser.getId());
-            info.setDeptId("");// 后期放最顶级的机构
-            sysUserJzgInfoMapper.insert(info);
+            info.setSystemCode(sysSystem.getSysCode());
+            info.setIsEnable(1);
+            sysUserPlateInfoMapper.insert(info);
         }
     }
 

+ 7 - 0
platform/src/main/resources/mapper/SysConfigMapper.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.jzg.organization.mapper.SysConfigMapper">
+
+</mapper>

+ 12 - 6
tenant/organization/src/main/java/com/jzg/organization/controller/DeptController.java

@@ -2,10 +2,8 @@ package com.jzg.organization.controller;
 
 import com.jzg.commons.core.base.BaseController;
 import com.jzg.commons.core.page.HttpResult;
-import com.jzg.commons.entity.po.SysArea;
 import com.jzg.commons.entity.dto.SysDeptParam;
 import com.jzg.commons.entity.po.SysDept;
-import com.jzg.commons.entity.vo.SysAreaVo;
 import com.jzg.commons.entity.vo.SysDeptVo;
 import com.jzg.commons.util.StringUtils;
 import com.jzg.organization.service.SysAreaService;
@@ -13,7 +11,7 @@ import com.jzg.organization.service.SysDeptService;
 import io.swagger.v3.oas.annotations.Operation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
-import java.util.ArrayList;
+
 import java.util.List;
 
 /**
@@ -25,9 +23,6 @@ public class DeptController extends BaseController {
     @Autowired
     private SysDeptService sysDeptService;
 
-    @Autowired
-    private SysAreaService sysAreaService;
-
     @Operation(summary = "新增机构接口", description = "新增机构接口")
     @PostMapping(value = "/add")
     public HttpResult<Boolean> addDept(@RequestBody SysDeptVo sysDeptVo) {
@@ -70,4 +65,15 @@ public class DeptController extends BaseController {
         List<SysDeptVo> deptTree = sysDeptService.getDeptTree(deptId,param);
         return HttpResult.ok(deptTree);
     }
+
+    /**
+     * 机构信息查询
+     * @param id
+     * @return
+     */
+    @GetMapping(value = { "/deptGet"})
+    @Operation(summary = "机构信息查询")
+    public HttpResult deptGet(String id) {
+        return HttpResult.ok(sysDeptService.queryById(id));
+    }
 }

+ 6 - 0
tenant/organization/src/main/java/com/jzg/organization/service/SysDeptService.java

@@ -41,4 +41,10 @@ public interface SysDeptService extends IService<SysDept> {
     List<SysDeptVo> getDeptTree(String deptId, SysDeptParam param);
 
 
+    /**
+     * 根据id获取机构信息
+     * @param id
+     * @return
+     */
+    SysDeptVo queryById(String id);
 }

+ 14 - 5
tenant/organization/src/main/java/com/jzg/organization/service/impl/SysDeptServiceImpl.java

@@ -1,5 +1,6 @@
 package com.jzg.organization.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jzg.commons.core.base.BaseController;
@@ -191,12 +192,13 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
             areas.add(item.getCity());
             areas.add(item.getArea());
             List<SysArea> sysAreaVos = sysAreaService.queryAllByAreaCode(areas);
-            String areaString = "";
-            for(int i=0;i<sysAreaVos.size();i++){
-                areaString = areaString + sysAreaVos.get(i).getAreaCname() + "-";
+            if(CollUtil.isNotEmpty(sysAreaVos)) {
+                String areaString = "";
+                for(int i=0;i<sysAreaVos.size();i++){
+                    areaString = areaString + sysAreaVos.get(i).getAreaCname() + "-";
+                }
+                item.setDivision(areaString.substring(0,areaString.length()-1));
             }
-
-            item.setDivision(areaString.substring(0,areaString.length()-1));
         });
 
         Map<String, List<SysDeptVo>> map = voDept.stream().collect(Collectors.groupingBy(SysDeptVo::getParentId));
@@ -215,4 +217,11 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
         return newResultDept;
     }
 
+    @Override
+    public SysDeptVo queryById(String id) {
+        SysDept sysDept = getById(id);
+        SysDeptVo sysDeptVo = new SysDeptVo(sysDept);
+        return sysDeptVo;
+    }
+
 }