forked from github/dataease
Merge pull request #1490 from dataease/pr@dev@refactor_panel-mobile
refactor: 优化移动端目录查询
This commit is contained in:
commit
c3c7e20319
@ -7,10 +7,11 @@
|
||||
s.panel_group_id as id,
|
||||
g.name as title,
|
||||
s.create_time as `time`
|
||||
from panel_store s
|
||||
from( SELECT GET_V_AUTH_MODEL_ID_P_USE_MOBILE ( #{userId}, 'panel' ) cids ) t, panel_store s
|
||||
inner join panel_group g
|
||||
on s.panel_group_id = g.id
|
||||
where s.user_id = #{userId}
|
||||
and FIND_IN_SET( g.id, cids )
|
||||
order by s.create_time desc
|
||||
</select>
|
||||
|
||||
|
@ -6,9 +6,9 @@ import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
public interface MobileDirMapper {
|
||||
List<PanelEntity> query(String pid);
|
||||
List<PanelEntity> query(@Param("pid") String pid,@Param("userId") String userId);
|
||||
|
||||
List<PanelEntity> queryWithName(String name);
|
||||
List<PanelEntity> queryWithName(@Param("name") String name,@Param("userId") String userId);
|
||||
|
||||
List<String> idsWithUser(String userId);
|
||||
|
||||
|
@ -3,23 +3,30 @@
|
||||
<mapper namespace="io.dataease.base.mapper.ext.MobileDirMapper">
|
||||
|
||||
<select id="query" resultType="io.dataease.mobile.entity.PanelEntity">
|
||||
select
|
||||
SELECT
|
||||
id,
|
||||
name as text,
|
||||
NAME AS text,
|
||||
pid,
|
||||
node_type as `type`
|
||||
from panel_group g
|
||||
where pid = #{pid} and g.mobile_layout = 1
|
||||
node_type AS `type`
|
||||
FROM
|
||||
panel_group g,
|
||||
( SELECT GET_V_AUTH_MODEL_ID_P_USE_MOBILE ( #{userId}, 'panel' ) cids ) t
|
||||
WHERE
|
||||
g.pid = #{pid}
|
||||
AND FIND_IN_SET( g.id, cids )
|
||||
</select>
|
||||
|
||||
<select id="queryWithName" resultType="io.dataease.mobile.entity.PanelEntity">
|
||||
select
|
||||
SELECT
|
||||
id,
|
||||
name as text,
|
||||
NAME AS text,
|
||||
pid,
|
||||
node_type as `type`
|
||||
from panel_group g
|
||||
where g.mobile_layout = 1
|
||||
node_type AS `type`
|
||||
FROM
|
||||
panel_group g,
|
||||
( SELECT GET_V_AUTH_MODEL_ID_P_USE_MOBILE ( #{userId}, 'panel' ) cids ) t
|
||||
WHERE
|
||||
FIND_IN_SET( g.id, cids )
|
||||
<if test="name != null">
|
||||
and name like CONCAT('%', #{name, jdbcType=VARCHAR}, '%')
|
||||
</if>
|
||||
|
@ -40,12 +40,13 @@ public class DirService {
|
||||
}
|
||||
|
||||
public List<DirItemDTO> query(DirRequest request) {
|
||||
CurrentUserDto user = AuthUtils.getUser();
|
||||
// CurrentUserDto user = AuthUtils.getUser();
|
||||
String userId = String.valueOf(AuthUtils.getUser().getUserId());
|
||||
List<PanelEntity> panelEntities = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(request.getName())) {
|
||||
panelEntities = mobileDirMapper.queryWithName(request.getName());
|
||||
panelEntities = mobileDirMapper.queryWithName(request.getName(),userId);
|
||||
}else {
|
||||
panelEntities = mobileDirMapper.query(request.getPid());
|
||||
panelEntities = mobileDirMapper.query(request.getPid(),userId);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(panelEntities)) return null;
|
||||
|
||||
@ -56,16 +57,17 @@ public class DirService {
|
||||
dirItemDTO.setType(data.getType());
|
||||
return dirItemDTO;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
if (user.getUserId() == 1 && StringUtils.equals("admin", user.getUsername())) {
|
||||
return dtos;
|
||||
}
|
||||
List<String> permissions = proxy().permissions();
|
||||
return dtos.stream().filter(
|
||||
dto -> permissions.stream().anyMatch(
|
||||
permission -> StringUtils.equals(permission, dto.getId())
|
||||
)
|
||||
).collect(Collectors.toList());
|
||||
|
||||
// if (user.getUserId() == 1 && StringUtils.equals("admin", user.getUsername())) {
|
||||
// return dtos;
|
||||
// }
|
||||
// List<String> permissions = proxy().permissions();
|
||||
// return dtos.stream().filter(
|
||||
// dto -> permissions.stream().anyMatch(
|
||||
// permission -> StringUtils.equals(permission, dto.getId())
|
||||
// )
|
||||
// ).collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
|
@ -22,3 +22,74 @@ ALTER TABLE `panel_link`CHANGE COLUMN `user_id` `user_id` BIGINT(20) NOT NULL ,D
|
||||
ALTER TABLE `panel_group`
|
||||
ADD COLUMN `mobile_layout` tinyint(1) NULL DEFAULT 0 COMMENT '启用移动端布局' AFTER `remark`;
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
-- Function structure for GET_PANEL_WITH_PRIVILEGE_AND_MOBILE
|
||||
-- ----------------------------
|
||||
DROP FUNCTION IF EXISTS `GET_PANEL_WITH_PRIVILEGE_AND_MOBILE`;
|
||||
delimiter ;;
|
||||
CREATE FUNCTION `GET_PANEL_WITH_PRIVILEGE_AND_MOBILE`(userId longtext,modelType varchar(255),privilegeType varchar(255))
|
||||
RETURNS longtext CHARSET utf8
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
|
||||
DECLARE oTempLeafIds longtext;
|
||||
select GROUP_CONCAT(auth_source) into oTempLeafIds from (
|
||||
SELECT
|
||||
sys_auth.auth_source_type,
|
||||
sys_auth.auth_source
|
||||
FROM
|
||||
sys_auth
|
||||
LEFT JOIN sys_auth_detail ON sys_auth.id = sys_auth_detail.auth_id
|
||||
WHERE
|
||||
sys_auth_detail.privilege_type = privilegeType
|
||||
and sys_auth.auth_source_type = modelType
|
||||
AND (
|
||||
(
|
||||
sys_auth.auth_target_type = 'dept'
|
||||
AND sys_auth.auth_target in ( SELECT dept_id FROM sys_user WHERE user_id = userId )
|
||||
)
|
||||
OR (
|
||||
sys_auth.auth_target_type = 'user'
|
||||
AND sys_auth.auth_target = userId
|
||||
)
|
||||
OR (
|
||||
sys_auth.auth_target_type = 'role'
|
||||
AND sys_auth.auth_target in ( SELECT role_id FROM sys_users_roles WHERE user_id = userId )
|
||||
)
|
||||
OR (1 = ( SELECT is_admin FROM sys_user WHERE user_id = userId ))
|
||||
)
|
||||
and sys_auth.auth_source in (select id from panel_group where mobile_layout='1')
|
||||
GROUP BY
|
||||
sys_auth.auth_source_type,
|
||||
sys_auth.auth_source
|
||||
having (sum( sys_auth_detail.privilege_value )> 0 or 1 = ( SELECT is_admin FROM sys_user WHERE user_id = userId ))) temp;
|
||||
RETURN oTempLeafIds;
|
||||
END
|
||||
;;
|
||||
delimiter ;
|
||||
|
||||
-- ----------------------------
|
||||
-- Function structure for GET_V_AUTH_MODEL_ID_P_USE_MOBILE
|
||||
-- ----------------------------
|
||||
DROP FUNCTION IF EXISTS `GET_V_AUTH_MODEL_ID_P_USE_MOBILE`;
|
||||
delimiter ;;
|
||||
CREATE FUNCTION `GET_V_AUTH_MODEL_ID_P_USE_MOBILE`(userId longtext,modelType varchar(255))
|
||||
RETURNS longtext CHARSET utf8
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
|
||||
DECLARE oTempLeafIds longtext;
|
||||
DECLARE oTempAllIds longtext;
|
||||
|
||||
select GET_PANEL_WITH_PRIVILEGE_AND_MOBILE(userId,modelType,1) into oTempLeafIds;
|
||||
|
||||
select GROUP_CONCAT(id) into oTempAllIds from (select GET_V_AUTH_MODEL_WITH_PARENT ( oTempLeafIds ,modelType) cids) t, v_auth_model where v_auth_model.model_type=modelType and FIND_IN_SET(v_auth_model.id,cids) order by id asc;
|
||||
|
||||
RETURN oTempAllIds;
|
||||
END
|
||||
;;
|
||||
delimiter ;
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user