Explorar el Código

用户角色设置默认角色,注册角色绑定默认角色

xgb hace 1 mes
padre
commit
32df94ba1b

+ 13 - 0
fs-company-app/src/main/java/com/fs/app/controller/CompanyUserController.java

@@ -20,6 +20,7 @@ import com.fs.common.utils.bean.BeanUtils;
 import com.fs.company.domain.*;
 import com.fs.company.mapper.CompanyRoleMapper;
 import com.fs.company.mapper.CompanyUserMapper;
+import com.fs.company.mapper.CompanyUserRoleMapper;
 import com.fs.company.param.companyUserAddPrintParam;
 import com.fs.company.service.*;
 import com.fs.company.vo.CompanyTagUserVO;
@@ -90,6 +91,7 @@ public class CompanyUserController extends AppBaseController {
     private final IFsUserCompanyUserService fsUserCompanyUserService;
     private final ICompanyTagUserService companyTagUserService;
     private final FastgptChatVoiceHomoMapper fastgptChatVoiceHomoMapper;
+    private final CompanyUserRoleMapper companyUserRoleMapper;
     public static final String SOP_TEMP_VOICE_KEY = "sop:tempVoice";
 
     @Login
@@ -245,6 +247,17 @@ public class CompanyUserController extends AppBaseController {
         }
 
         companyUserService.insertUser(companyUser);
+
+        // 查询公司是否存在默认角色,如果存在则自动绑定
+        // 查询公司是否存在默认角色
+        CompanyRole defaultRole = companyRoleMapper.selectDefaultRoleByCompanyId(company.getCompanyId());
+        if (Objects.nonNull(defaultRole)) {
+            CompanyUserRole companyUserRole = new CompanyUserRole();
+            companyUserRole.setUserId(companyUser.getUserId());
+            companyUserRole.setRoleId(defaultRole.getRoleId());
+            companyUserRoleMapper.insertCompanyUserRole(companyUserRole);
+        }
+
         return R.ok();
     }
 

+ 12 - 0
fs-service/src/main/java/com/fs/company/domain/CompanyRole.java

@@ -44,6 +44,9 @@ public class CompanyRole extends BaseEntity
     /** 角色状态(0正常 1停用) */
     private String status;
 
+    /** 是否默认角色(0否 1是) */
+    private String defaultRole;
+
     /** 删除标志(0代表存在 2代表删除) */
     private String delFlag;
 
@@ -137,6 +140,15 @@ public class CompanyRole extends BaseEntity
     {
         return status;
     }
+
+    public String getDefaultRole() {
+        return defaultRole;
+    }
+
+    public void setDefaultRole(String defaultRole) {
+        this.defaultRole = defaultRole;
+    }
+
     public void setDelFlag(String delFlag)
     {
         this.delFlag = delFlag;

+ 7 - 0
fs-service/src/main/java/com/fs/company/mapper/CompanyRoleMapper.java

@@ -85,4 +85,11 @@ public interface CompanyRoleMapper
      * **/
     CompanyRole selectCompanyRoleByRoleKey(@Param("roleKey") String roleKey);
     Long selectRolesByUserNameAndCompanyId(@Param("roleName") String roleName,@Param("companyId") Long companyId);
+
+    /**
+     * 根据公司ID查询默认角色
+     * @param companyId 公司ID
+     * @return 默认角色
+     */
+    CompanyRole selectDefaultRoleByCompanyId(@Param("companyId") Long companyId);
 }

+ 11 - 1
fs-service/src/main/resources/mapper/company/CompanyRoleMapper.xml

@@ -14,6 +14,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="menuCheckStrictly"    column="menu_check_strictly"    />
         <result property="deptCheckStrictly"    column="dept_check_strictly"    />
         <result property="status"    column="status"    />
+        <result property="defaultRole"    column="default_role"    />
         <result property="delFlag"    column="del_flag"    />
         <result property="createBy"    column="create_by"    />
         <result property="createTime"    column="create_time"    />
@@ -23,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectCompanyRoleVo">
-        select role_id, company_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, del_flag, create_by, create_time, update_by, update_time, remark from company_role
+        select role_id, company_id, role_name, role_key, role_sort, data_scope, menu_check_strictly, dept_check_strictly, status, default_role, del_flag, create_by, create_time, update_by, update_time, remark from company_role
     </sql>
 
     <select id="selectCompanyRoleList" parameterType="CompanyRole" resultMap="CompanyRoleResult">
@@ -56,6 +57,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="menuCheckStrictly != null">menu_check_strictly,</if>
             <if test="deptCheckStrictly != null">dept_check_strictly,</if>
             <if test="status != null and status != ''">status,</if>
+            <if test="defaultRole != null and defaultRole != ''">default_role,</if>
             <if test="delFlag != null">del_flag,</if>
             <if test="createBy != null">create_by,</if>
             <if test="createTime != null">create_time,</if>
@@ -72,6 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="menuCheckStrictly != null">#{menuCheckStrictly},</if>
             <if test="deptCheckStrictly != null">#{deptCheckStrictly},</if>
             <if test="status != null and status != ''">#{status},</if>
+            <if test="defaultRole != null and defaultRole != ''">#{defaultRole},</if>
             <if test="delFlag != null">#{delFlag},</if>
             <if test="createBy != null">#{createBy},</if>
             <if test="createTime != null">#{createTime},</if>
@@ -92,6 +95,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="menuCheckStrictly != null">menu_check_strictly = #{menuCheckStrictly},</if>
             <if test="deptCheckStrictly != null">dept_check_strictly = #{deptCheckStrictly},</if>
             <if test="status != null and status != ''">status = #{status},</if>
+            <if test="defaultRole != null and defaultRole != ''">default_role = #{defaultRole},</if>
             <if test="delFlag != null">del_flag = #{delFlag},</if>
             <if test="createBy != null">create_by = #{createBy},</if>
             <if test="createTime != null">create_time = #{createTime},</if>
@@ -186,4 +190,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select role_id from company_role where  del_flag = '0' and status = '0' and  role_name= #{roleName}  and company_id = #{companyId}
     </select>
 
+    <select id="selectDefaultRoleByCompanyId" resultType="com.fs.company.domain.CompanyRole">
+        select * from company_role 
+        where del_flag = '0' and status = '0' and default_role = '1' and company_id = #{companyId}
+        limit 1
+    </select>
+
 </mapper>