CompanyRoleMapper.xml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.fs.company.mapper.CompanyRoleMapper">
  6. <resultMap type="CompanyRole" id="CompanyRoleResult">
  7. <result property="roleId" column="role_id" />
  8. <result property="companyId" column="company_id" />
  9. <result property="roleName" column="role_name" />
  10. <result property="roleKey" column="role_key" />
  11. <result property="roleSort" column="role_sort" />
  12. <result property="dataScope" column="data_scope" />
  13. <result property="menuCheckStrictly" column="menu_check_strictly" />
  14. <result property="deptCheckStrictly" column="dept_check_strictly" />
  15. <result property="status" column="status" />
  16. <result property="delFlag" column="del_flag" />
  17. <result property="createBy" column="create_by" />
  18. <result property="createTime" column="create_time" />
  19. <result property="updateBy" column="update_by" />
  20. <result property="updateTime" column="update_time" />
  21. <result property="remark" column="remark" />
  22. </resultMap>
  23. <sql id="selectCompanyRoleVo">
  24. 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
  25. </sql>
  26. <select id="selectCompanyRoleList" parameterType="CompanyRole" resultMap="CompanyRoleResult">
  27. <include refid="selectCompanyRoleVo"/>
  28. <where>
  29. <if test="companyId != null "> and company_id = #{companyId}</if>
  30. <if test="roleName != null and roleName != ''"> and role_name like concat('%', #{roleName}, '%')</if>
  31. <if test="roleKey != null and roleKey != ''"> and role_key = #{roleKey}</if>
  32. <if test="roleSort != null "> and role_sort = #{roleSort}</if>
  33. <if test="dataScope != null and dataScope != ''"> and data_scope = #{dataScope}</if>
  34. <if test="menuCheckStrictly != null "> and menu_check_strictly = #{menuCheckStrictly}</if>
  35. <if test="deptCheckStrictly != null "> and dept_check_strictly = #{deptCheckStrictly}</if>
  36. <if test="status != null and status != ''"> and status = #{status}</if>
  37. </where>
  38. </select>
  39. <select id="selectCompanyRoleById" parameterType="Long" resultMap="CompanyRoleResult">
  40. <include refid="selectCompanyRoleVo"/>
  41. where role_id = #{roleId}
  42. </select>
  43. <insert id="insertCompanyRole" parameterType="CompanyRole" useGeneratedKeys="true" keyProperty="roleId">
  44. insert into company_role
  45. <trim prefix="(" suffix=")" suffixOverrides=",">
  46. <if test="companyId != null">company_id,</if>
  47. <if test="roleName != null and roleName != ''">role_name,</if>
  48. <if test="roleKey != null and roleKey != ''">role_key,</if>
  49. <if test="roleSort != null">role_sort,</if>
  50. <if test="dataScope != null">data_scope,</if>
  51. <if test="menuCheckStrictly != null">menu_check_strictly,</if>
  52. <if test="deptCheckStrictly != null">dept_check_strictly,</if>
  53. <if test="status != null and status != ''">status,</if>
  54. <if test="delFlag != null">del_flag,</if>
  55. <if test="createBy != null">create_by,</if>
  56. <if test="createTime != null">create_time,</if>
  57. <if test="updateBy != null">update_by,</if>
  58. <if test="updateTime != null">update_time,</if>
  59. <if test="remark != null">remark,</if>
  60. </trim>
  61. <trim prefix="values (" suffix=")" suffixOverrides=",">
  62. <if test="companyId != null">#{companyId},</if>
  63. <if test="roleName != null and roleName != ''">#{roleName},</if>
  64. <if test="roleKey != null and roleKey != ''">#{roleKey},</if>
  65. <if test="roleSort != null">#{roleSort},</if>
  66. <if test="dataScope != null">#{dataScope},</if>
  67. <if test="menuCheckStrictly != null">#{menuCheckStrictly},</if>
  68. <if test="deptCheckStrictly != null">#{deptCheckStrictly},</if>
  69. <if test="status != null and status != ''">#{status},</if>
  70. <if test="delFlag != null">#{delFlag},</if>
  71. <if test="createBy != null">#{createBy},</if>
  72. <if test="createTime != null">#{createTime},</if>
  73. <if test="updateBy != null">#{updateBy},</if>
  74. <if test="updateTime != null">#{updateTime},</if>
  75. <if test="remark != null">#{remark},</if>
  76. </trim>
  77. </insert>
  78. <update id="updateCompanyRole" parameterType="CompanyRole">
  79. update company_role
  80. <trim prefix="SET" suffixOverrides=",">
  81. <if test="companyId != null">company_id = #{companyId},</if>
  82. <if test="roleName != null and roleName != ''">role_name = #{roleName},</if>
  83. <if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if>
  84. <if test="roleSort != null">role_sort = #{roleSort},</if>
  85. <if test="dataScope != null">data_scope = #{dataScope},</if>
  86. <if test="menuCheckStrictly != null">menu_check_strictly = #{menuCheckStrictly},</if>
  87. <if test="deptCheckStrictly != null">dept_check_strictly = #{deptCheckStrictly},</if>
  88. <if test="status != null and status != ''">status = #{status},</if>
  89. <if test="delFlag != null">del_flag = #{delFlag},</if>
  90. <if test="createBy != null">create_by = #{createBy},</if>
  91. <if test="createTime != null">create_time = #{createTime},</if>
  92. <if test="updateBy != null">update_by = #{updateBy},</if>
  93. <if test="updateTime != null">update_time = #{updateTime},</if>
  94. <if test="remark != null">remark = #{remark},</if>
  95. </trim>
  96. where role_id = #{roleId}
  97. </update>
  98. <delete id="deleteCompanyRoleById" parameterType="Long">
  99. delete from company_role where role_id = #{roleId}
  100. </delete>
  101. <delete id="deleteCompanyRoleByIds" parameterType="String">
  102. delete from company_role where role_id in
  103. <foreach item="roleId" collection="array" open="(" separator="," close=")">
  104. #{roleId}
  105. </foreach>
  106. </delete>
  107. <select id="selectRolePermissionByUserId" parameterType="Long" resultMap="CompanyRoleResult">
  108. <include refid="selectRoleVo"/>
  109. WHERE r.del_flag = '0' and ur.user_id = #{userId}
  110. </select>
  111. <sql id="selectRoleVo">
  112. select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.menu_check_strictly, r.dept_check_strictly,
  113. r.status, r.del_flag, r.create_time, r.remark
  114. from company_role r
  115. left join company_user_role ur on ur.role_id = r.role_id
  116. left join company_user u on u.user_id = ur.user_id
  117. left join company_dept d on u.dept_id = d.dept_id
  118. </sql>
  119. <select id="selectRolesByUserName" parameterType="String" resultMap="CompanyRoleResult">
  120. <include refid="selectRoleVo"/>
  121. WHERE r.del_flag = '0' and u.user_name = #{userName}
  122. </select>
  123. <select id="checkRoleNameUnique" parameterType="String" resultMap="CompanyRoleResult">
  124. <include refid="selectRoleVo"/>
  125. <where>
  126. <if test="roleName != null">
  127. AND r.role_name=#{roleName}
  128. </if>
  129. <if test="companyId != null">
  130. AND r.company_id = #{companyId}
  131. </if>
  132. </where>
  133. limit 1
  134. </select>
  135. <select id="checkRoleKeyUnique" parameterType="String" resultMap="CompanyRoleResult">
  136. <include refid="selectRoleVo"/>
  137. <where>
  138. <if test="roleKey != null">
  139. AND r.role_key=#{roleKey}
  140. </if>
  141. <if test="companyId != null">
  142. AND r.company_id = #{companyId}
  143. </if>
  144. </where>
  145. limit 1
  146. </select>
  147. <select id="selectRoleListByUserId" parameterType="Long" resultType="Integer">
  148. select r.role_id
  149. from company_role r
  150. left join company_user_role ur on ur.role_id = r.role_id
  151. left join company_user u on u.user_id = ur.user_id
  152. where u.user_id = #{userId}
  153. </select>
  154. <select id="selectRoleListByIds" resultType="com.fs.company.domain.CompanyRole">
  155. select * from company_role
  156. where del_flag = '0' and status = '0'
  157. and role_id in
  158. <foreach collection="roleIds" item="roleId" separator="," open="(" close=")">
  159. #{roleId}
  160. </foreach>
  161. </select>
  162. <select id="selectCompanyRoleByRoleKey" resultType="com.fs.company.domain.CompanyRole">
  163. SELECT * FROM company_role WHERE del_flag=0 AND role_key = #{roleKey}
  164. </select>
  165. </mapper>