jiangping
2024-05-23 a675a9d1acfacbc0f305f868929b4f0f086ec2dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?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.doumee.dao.system.SystemDataPermissionMapper">
 
  <!-- 查询部门列表 -->
  <resultMap id="SystemDataPermissionListVO" type="com.doumee.dao.system.vo.SystemDataPermissionListVO" autoMapping="true">
    <id column="ID" property="id"/>
    <association property="role" javaType="com.doumee.dao.system.model.SystemRole">
      <result column="ROLE_ID" property="id"/>
      <result column="ROLE_CODE" property="code"/>
      <result column="ROLE_NAME" property="name"/>
    </association>
    <association property="createUserInfo" javaType="com.doumee.dao.system.model.SystemUser">
      <result column="CREATE_USER_ID" property="id"/>
      <result column="CREATE_USER_NAME" property="username"/>
    </association>
    <association property="updateUserInfo" javaType="com.doumee.dao.system.model.SystemUser">
      <result column="UPDATE_USER_ID" property="id"/>
      <result column="UPDATE_USER_NAME" property="username"/>
    </association>
  </resultMap>
  <select id="selectManageList" resultMap="SystemDataPermissionListVO">
    SELECT
      sdp.`ID`, sdp.`BUSINESS_CODE`, sdp.`ROLE_ID`, sdp.`TYPE`, sdp.`CUSTOM_DATA`, sdp.`DISABLED`, sdp.`REMARK`, sdp.DISABLED, sdp.`CREATE_TIME`, sdp.`UPDATE_TIME`,
      role.`ID` AS ROLE_ID, role.`CODE` AS ROLE_CODE, role.`NAME` AS ROLE_NAME,
      create_user.ID CREATE_USER_ID, create_user.`USERNAME` CREATE_USER_NAME,
      update_user.ID UPDETE_USER_ID, update_user.`USERNAME` UPDATE_USER_NAME
    FROM SYSTEM_DATA_PERMISSION sdp
    INNER JOIN `SYSTEM_ROLE` role ON role.ID = sdp.ROLE_ID
    LEFT JOIN `SYSTEM_USER` create_user ON create_user.ID = sdp.CREATE_USER
    LEFT JOIN `SYSTEM_USER` update_user ON update_user.ID = sdp.UPDATE_USER
    <where>
      sdp.DELETED = 0
      <if test="dto.businessCode != null and dto.businessCode != ''">
        AND sdp.`BUSINESS_CODE` = #{dto.businessCode}
      </if>
      <if test="dto.roleId != null">
        AND role.`ID` =  #{dto.roleId}
      </if>
      <if test="dto.type != null">
        AND sdp.`TYPE` =  #{dto.type}
      </if>
    </where>
    ${orderByClause}
  </select>
  <select id="selectUserList" resultMap="SystemDataPermissionListVO">
    SELECT
    sdp.`ID`, sdp.`BUSINESS_CODE`, sdp.`ROLE_ID`, sdp.`TYPE`, sdp.`CUSTOM_DATA`, sdp.`DISABLED`, sdp.`REMARK`, sdp.DISABLED, sdp.`CREATE_TIME`, sdp.`UPDATE_TIME`,
    role.`ID` AS ROLE_ID, role.`CODE` AS ROLE_CODE, role.`NAME` AS ROLE_NAME,
    create_user.ID CREATE_USER_ID, create_user.`USERNAME` CREATE_USER_NAME,
    update_user.ID UPDETE_USER_ID, update_user.`USERNAME` UPDATE_USER_NAME
    FROM SYSTEM_DATA_PERMISSION sdp
    INNER JOIN `SYSTEM_ROLE` role ON role.ID = sdp.ROLE_ID
    LEFT JOIN `SYSTEM_USER` create_user ON create_user.ID = sdp.CREATE_USER
    LEFT JOIN `SYSTEM_USER` update_user ON update_user.ID = sdp.UPDATE_USER
    <where>
      sdp.DELETED = 0
      <if test="dto.businessCode != null and dto.businessCode != ''">
        AND sdp.`BUSINESS_CODE` = #{dto.businessCode}
      </if>
      <if test="dto.roleId != null">
        AND role.`ID` =  #{dto.roleId}
      </if>
      <if test="dto.type != null">
        AND sdp.`TYPE` =  #{dto.type}
      </if>
      <if test="userId != null">
        AND exists (select sr.id from system_user_role sr where sr.role_id=sdp.role_id and sr.user_id=#{userId} and sr.STATUS=0 and sr.deleted=0)
      </if>
    </where>
    order by role.`TYPE` asc
  </select>
</mapper>