stylefeng / Guns

Guns基于SpringBoot 2,致力于做更简洁的后台管理系统,完美整合springmvc + shiro + mybatis-plus + beetl!Guns项目代码简洁,注释丰富,上手容易,同时Guns包含许多基础模块(用户管理,角色管理,部门管理,字典管理等10个模块),可以直接作为一个后台管理系统的脚手架!
Apache License 2.0
3.86k stars 1.59k forks source link

RoleMapper::roleTreeListByRoleId没必要地复杂 #94

Closed wtune closed 3 years ago

wtune commented 4 years ago

描述

原查询

SELECT 
  r.role_id as id, 
  pid as "pId", 
  name AS "name", 
  (
    CASE WHEN (
      pid = 0 
      OR pid IS NULL
    ) THEN 'true' ELSE 'false' END
  ) as "open", 
  (
    CASE WHEN (
      r1.role_id = 0 
      OR r1.role_id IS NULL
    ) THEN 'false' ELSE 'true' END
  ) as "checked" 
FROM 
  sys_role r 
  LEFT JOIN (
    SELECT 
      role_id 
    FROM 
      sys_role 
    WHERE 
      role_id IN ( #{params} )
  ) r1 ON r.role_id = r1.role_id 
ORDER BY 
  pid, 
  sort ASC;

等价于

SELECT 
  r.role_id as id, 
  pid as "pId", 
  name AS "name", 
  (
    CASE WHEN (
      pid = 0 
      OR pid IS NULL
    ) THEN 'true' ELSE 'false' END
  ) AS "open", 
  (
    CASE WHEN ( r.role_id = 0 OR
      r.role_id IN ( #{params} )
    ) THEN 'false' ELSE 'true' END
  ) AS "checked" 
FROM 
  sys_role r 
ORDER BY 
  pid, 
  sort ASC;

可能的修改方法

见#93