feat: 新增移动端目录api
This commit is contained in:
parent
51fb52a066
commit
aee31d0d62
@ -0,0 +1,18 @@
|
|||||||
|
package io.dataease.base.mapper.ext;
|
||||||
|
|
||||||
|
import io.dataease.mobile.entity.PanelEntity;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface MobileDirMapper {
|
||||||
|
List<PanelEntity> query(String pid);
|
||||||
|
|
||||||
|
List<PanelEntity> queryWithName(String name);
|
||||||
|
|
||||||
|
List<String> idsWithUser(String userId);
|
||||||
|
|
||||||
|
List<String> idsWithDept(String deptId);
|
||||||
|
|
||||||
|
List<String> idsWithRoles(@Param("roleIds") List<String> roleIds);
|
||||||
|
}
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
<?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="io.dataease.base.mapper.ext.MobileDirMapper">
|
||||||
|
|
||||||
|
<select id="query" resultType="io.dataease.mobile.entity.PanelEntity">
|
||||||
|
select
|
||||||
|
id,
|
||||||
|
name as text,
|
||||||
|
pid,
|
||||||
|
node_type as `type`
|
||||||
|
from panel_group g
|
||||||
|
where pid = #{pid} and g.mobile_layout = 1
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="queryWithName" resultType="io.dataease.mobile.entity.PanelEntity">
|
||||||
|
select
|
||||||
|
id,
|
||||||
|
name as text,
|
||||||
|
pid,
|
||||||
|
node_type as `type`
|
||||||
|
from panel_group g
|
||||||
|
where g.mobile_layout = 1
|
||||||
|
<if test="name != null">
|
||||||
|
and name like CONCAT('%', #{name, jdbcType=VARCHAR}, '%')
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="idsWithUser" resultType="java.lang.String">
|
||||||
|
select a.auth_source
|
||||||
|
from sys_auth a
|
||||||
|
left join sys_auth_detail d on a.id = d.auth_id
|
||||||
|
where
|
||||||
|
a.auth_target_type = 'user' and
|
||||||
|
a.auth_target = #{userId} and
|
||||||
|
a.auth_source_type = 'panel' and
|
||||||
|
d.privilege_type = 1 and
|
||||||
|
d.privilege_value = 1
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="idsWithDept" resultType="java.lang.String">
|
||||||
|
select a.auth_source
|
||||||
|
from sys_auth a
|
||||||
|
left join sys_auth_detail d on a.id = d.auth_id
|
||||||
|
where
|
||||||
|
a.auth_target_type = 'dept' and
|
||||||
|
a.auth_target = #{deptId} and
|
||||||
|
a.auth_source_type = 'panel' and
|
||||||
|
d.privilege_type = 1 and
|
||||||
|
d.privilege_value = 1
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="idsWithRoles" resultType="java.lang.String">
|
||||||
|
select a.auth_source
|
||||||
|
from sys_auth a
|
||||||
|
left join sys_auth_detail d on a.id = d.auth_id
|
||||||
|
where
|
||||||
|
a.auth_target_type = 'role' and
|
||||||
|
a.auth_target in
|
||||||
|
<foreach collection="roleIds" item="roleId" open='(' separator=',' close=')'>
|
||||||
|
#{roleId}
|
||||||
|
</foreach>
|
||||||
|
and
|
||||||
|
a.auth_source_type = 'panel' and
|
||||||
|
d.privilege_type = 1 and
|
||||||
|
d.privilege_value = 1
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
22
backend/src/main/java/io/dataease/mobile/api/DirApi.java
Normal file
22
backend/src/main/java/io/dataease/mobile/api/DirApi.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package io.dataease.mobile.api;
|
||||||
|
|
||||||
|
|
||||||
|
import io.dataease.mobile.dto.DirItemDTO;
|
||||||
|
import io.dataease.mobile.dto.DirRequest;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Api(tags = "移动端:目录")
|
||||||
|
@RequestMapping("/mobile/dir")
|
||||||
|
public interface DirApi {
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("查询")
|
||||||
|
@PostMapping("/query")
|
||||||
|
List<DirItemDTO> query(@RequestBody DirRequest request);
|
||||||
|
}
|
||||||
21
backend/src/main/java/io/dataease/mobile/dto/DirItemDTO.java
Normal file
21
backend/src/main/java/io/dataease/mobile/dto/DirItemDTO.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package io.dataease.mobile.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ApiModel("目录数据实体")
|
||||||
|
public class DirItemDTO implements Serializable {
|
||||||
|
|
||||||
|
@ApiModelProperty("ID")
|
||||||
|
private String id;
|
||||||
|
@ApiModelProperty("名称")
|
||||||
|
private String text;
|
||||||
|
@ApiModelProperty(value = "类型", allowableValues = "{@code folder, panel}")
|
||||||
|
private String type;
|
||||||
|
@ApiModelProperty("子集数")
|
||||||
|
private Integer subs;
|
||||||
|
}
|
||||||
19
backend/src/main/java/io/dataease/mobile/dto/DirRequest.java
Normal file
19
backend/src/main/java/io/dataease/mobile/dto/DirRequest.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package io.dataease.mobile.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ApiModel("目录查询条件")
|
||||||
|
public class DirRequest implements Serializable {
|
||||||
|
|
||||||
|
@ApiModelProperty("父ID")
|
||||||
|
private String pid;
|
||||||
|
|
||||||
|
@ApiModelProperty("名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package io.dataease.mobile.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PanelEntity implements Serializable {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private String text;
|
||||||
|
|
||||||
|
private String pid;
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
package io.dataease.mobile.server;
|
||||||
|
|
||||||
|
import io.dataease.mobile.api.DirApi;
|
||||||
|
import io.dataease.mobile.dto.DirItemDTO;
|
||||||
|
import io.dataease.mobile.dto.DirRequest;
|
||||||
|
import io.dataease.mobile.service.DirService;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class DirServer implements DirApi {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DirService dirService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DirItemDTO> query(DirRequest request) {
|
||||||
|
return dirService.query(request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
package io.dataease.mobile.service;
|
||||||
|
|
||||||
|
import io.dataease.auth.api.dto.CurrentUserDto;
|
||||||
|
import io.dataease.base.mapper.ext.MobileDirMapper;
|
||||||
|
import io.dataease.commons.utils.AuthUtils;
|
||||||
|
import io.dataease.commons.utils.CommonBeanFactory;
|
||||||
|
import io.dataease.mobile.dto.DirItemDTO;
|
||||||
|
import io.dataease.mobile.dto.DirRequest;
|
||||||
|
import io.dataease.mobile.entity.PanelEntity;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DirService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MobileDirMapper mobileDirMapper;
|
||||||
|
|
||||||
|
|
||||||
|
public List<String> permissions() {
|
||||||
|
CurrentUserDto user = AuthUtils.getUser();
|
||||||
|
Long userId = user.getUserId();
|
||||||
|
Long deptId = user.getDeptId();
|
||||||
|
List<String> roles = user.getRoles().stream().map(item -> item.getId().toString()).collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<String> idsWithUser = mobileDirMapper.idsWithUser(userId.toString());
|
||||||
|
List<String> idsWithDept = mobileDirMapper.idsWithDept(deptId.toString());
|
||||||
|
List<String> idsWithRoles = mobileDirMapper.idsWithRoles(roles);
|
||||||
|
|
||||||
|
List<String> panelIds = new ArrayList<>();
|
||||||
|
panelIds.addAll(idsWithUser);
|
||||||
|
panelIds.addAll(idsWithDept);
|
||||||
|
panelIds.addAll(idsWithRoles);
|
||||||
|
return panelIds.stream().distinct().collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DirItemDTO> query(DirRequest request) {
|
||||||
|
CurrentUserDto user = AuthUtils.getUser();
|
||||||
|
List<PanelEntity> panelEntities = new ArrayList<>();
|
||||||
|
if (StringUtils.isNotBlank(request.getName())) {
|
||||||
|
panelEntities = mobileDirMapper.queryWithName(request.getName());
|
||||||
|
}else {
|
||||||
|
panelEntities = mobileDirMapper.query(request.getPid());
|
||||||
|
}
|
||||||
|
if (CollectionUtils.isEmpty(panelEntities)) return null;
|
||||||
|
|
||||||
|
List<DirItemDTO> dtos = panelEntities.stream().map(data -> {
|
||||||
|
DirItemDTO dirItemDTO = new DirItemDTO();
|
||||||
|
dirItemDTO.setId(data.getId());
|
||||||
|
dirItemDTO.setText(data.getText());
|
||||||
|
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());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public DirService proxy() {
|
||||||
|
return CommonBeanFactory.getBean(DirService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -7,7 +7,6 @@ import io.dataease.mobile.dto.HomeItemDTO;
|
|||||||
import io.dataease.base.mapper.ext.HomeMapper;
|
import io.dataease.base.mapper.ext.HomeMapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -20,15 +19,11 @@ public class HomeService {
|
|||||||
private HomeMapper homeMapper;
|
private HomeMapper homeMapper;
|
||||||
|
|
||||||
public List<HomeItemDTO> query(Integer type) {
|
public List<HomeItemDTO> query(Integer type) {
|
||||||
List<HomeItemDTO> result = new ArrayList<>();
|
|
||||||
CurrentUserDto user = AuthUtils.getUser();
|
CurrentUserDto user = AuthUtils.getUser();
|
||||||
switch (type){
|
switch (type){
|
||||||
case 0:
|
|
||||||
result = homeMapper.queryStore(user.getUserId());
|
|
||||||
break;
|
|
||||||
case 1:
|
case 1:
|
||||||
result = homeMapper.queryHistory();
|
return homeMapper.queryHistory();
|
||||||
break;
|
|
||||||
case 2:
|
case 2:
|
||||||
Map<String, Object> param = new HashMap<>();
|
Map<String, Object> param = new HashMap<>();
|
||||||
Long deptId = user.getDeptId();
|
Long deptId = user.getDeptId();
|
||||||
@ -36,9 +31,10 @@ public class HomeService {
|
|||||||
param.put("userId", user.getUserId());
|
param.put("userId", user.getUserId());
|
||||||
param.put("deptId", deptId);
|
param.put("deptId", deptId);
|
||||||
param.put("roleIds", roleIds);
|
param.put("roleIds", roleIds);
|
||||||
result = homeMapper.queryShare(param);
|
List<HomeItemDTO> result = homeMapper.queryShare(param);
|
||||||
break;
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
|
default:
|
||||||
|
return homeMapper.queryStore(user.getUserId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user