From aee31d0d62f71931a7713737b9e30e83efc7378b Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Tue, 7 Dec 2021 18:29:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E7=AB=AF=E7=9B=AE=E5=BD=95api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/mapper/ext/MobileDirMapper.java | 18 +++++ .../base/mapper/ext/MobileDirMapper.xml | 74 ++++++++++++++++++ .../java/io/dataease/mobile/api/DirApi.java | 22 ++++++ .../io/dataease/mobile/dto/DirItemDTO.java | 21 +++++ .../io/dataease/mobile/dto/DirRequest.java | 19 +++++ .../dataease/mobile/entity/PanelEntity.java | 17 ++++ .../io/dataease/mobile/server/DirServer.java | 22 ++++++ .../dataease/mobile/service/DirService.java | 77 +++++++++++++++++++ .../dataease/mobile/service/HomeService.java | 16 ++-- 9 files changed, 276 insertions(+), 10 deletions(-) create mode 100644 backend/src/main/java/io/dataease/base/mapper/ext/MobileDirMapper.java create mode 100644 backend/src/main/java/io/dataease/base/mapper/ext/MobileDirMapper.xml create mode 100644 backend/src/main/java/io/dataease/mobile/api/DirApi.java create mode 100644 backend/src/main/java/io/dataease/mobile/dto/DirItemDTO.java create mode 100644 backend/src/main/java/io/dataease/mobile/dto/DirRequest.java create mode 100644 backend/src/main/java/io/dataease/mobile/entity/PanelEntity.java create mode 100644 backend/src/main/java/io/dataease/mobile/server/DirServer.java create mode 100644 backend/src/main/java/io/dataease/mobile/service/DirService.java diff --git a/backend/src/main/java/io/dataease/base/mapper/ext/MobileDirMapper.java b/backend/src/main/java/io/dataease/base/mapper/ext/MobileDirMapper.java new file mode 100644 index 0000000000..84181a51c3 --- /dev/null +++ b/backend/src/main/java/io/dataease/base/mapper/ext/MobileDirMapper.java @@ -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 query(String pid); + + List queryWithName(String name); + + List idsWithUser(String userId); + + List idsWithDept(String deptId); + + List idsWithRoles(@Param("roleIds") List roleIds); +} diff --git a/backend/src/main/java/io/dataease/base/mapper/ext/MobileDirMapper.xml b/backend/src/main/java/io/dataease/base/mapper/ext/MobileDirMapper.xml new file mode 100644 index 0000000000..1d4fdd7f5c --- /dev/null +++ b/backend/src/main/java/io/dataease/base/mapper/ext/MobileDirMapper.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/backend/src/main/java/io/dataease/mobile/api/DirApi.java b/backend/src/main/java/io/dataease/mobile/api/DirApi.java new file mode 100644 index 0000000000..e7a87c0ab4 --- /dev/null +++ b/backend/src/main/java/io/dataease/mobile/api/DirApi.java @@ -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 query(@RequestBody DirRequest request); +} diff --git a/backend/src/main/java/io/dataease/mobile/dto/DirItemDTO.java b/backend/src/main/java/io/dataease/mobile/dto/DirItemDTO.java new file mode 100644 index 0000000000..f4f607a316 --- /dev/null +++ b/backend/src/main/java/io/dataease/mobile/dto/DirItemDTO.java @@ -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; +} diff --git a/backend/src/main/java/io/dataease/mobile/dto/DirRequest.java b/backend/src/main/java/io/dataease/mobile/dto/DirRequest.java new file mode 100644 index 0000000000..95a28f926f --- /dev/null +++ b/backend/src/main/java/io/dataease/mobile/dto/DirRequest.java @@ -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; + +} diff --git a/backend/src/main/java/io/dataease/mobile/entity/PanelEntity.java b/backend/src/main/java/io/dataease/mobile/entity/PanelEntity.java new file mode 100644 index 0000000000..7dceda0378 --- /dev/null +++ b/backend/src/main/java/io/dataease/mobile/entity/PanelEntity.java @@ -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; +} diff --git a/backend/src/main/java/io/dataease/mobile/server/DirServer.java b/backend/src/main/java/io/dataease/mobile/server/DirServer.java new file mode 100644 index 0000000000..7376e305cb --- /dev/null +++ b/backend/src/main/java/io/dataease/mobile/server/DirServer.java @@ -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 query(DirRequest request) { + return dirService.query(request); + } +} diff --git a/backend/src/main/java/io/dataease/mobile/service/DirService.java b/backend/src/main/java/io/dataease/mobile/service/DirService.java new file mode 100644 index 0000000000..3525dc4a2c --- /dev/null +++ b/backend/src/main/java/io/dataease/mobile/service/DirService.java @@ -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 permissions() { + CurrentUserDto user = AuthUtils.getUser(); + Long userId = user.getUserId(); + Long deptId = user.getDeptId(); + List roles = user.getRoles().stream().map(item -> item.getId().toString()).collect(Collectors.toList()); + + List idsWithUser = mobileDirMapper.idsWithUser(userId.toString()); + List idsWithDept = mobileDirMapper.idsWithDept(deptId.toString()); + List idsWithRoles = mobileDirMapper.idsWithRoles(roles); + + List panelIds = new ArrayList<>(); + panelIds.addAll(idsWithUser); + panelIds.addAll(idsWithDept); + panelIds.addAll(idsWithRoles); + return panelIds.stream().distinct().collect(Collectors.toList()); + } + + public List query(DirRequest request) { + CurrentUserDto user = AuthUtils.getUser(); + List 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 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 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); + } + + +} diff --git a/backend/src/main/java/io/dataease/mobile/service/HomeService.java b/backend/src/main/java/io/dataease/mobile/service/HomeService.java index dbc7782ddb..41d23b7b6b 100644 --- a/backend/src/main/java/io/dataease/mobile/service/HomeService.java +++ b/backend/src/main/java/io/dataease/mobile/service/HomeService.java @@ -7,7 +7,6 @@ import io.dataease.mobile.dto.HomeItemDTO; import io.dataease.base.mapper.ext.HomeMapper; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -20,15 +19,11 @@ public class HomeService { private HomeMapper homeMapper; public List query(Integer type) { - List result = new ArrayList<>(); CurrentUserDto user = AuthUtils.getUser(); switch (type){ - case 0: - result = homeMapper.queryStore(user.getUserId()); - break; + case 1: - result = homeMapper.queryHistory(); - break; + return homeMapper.queryHistory(); case 2: Map param = new HashMap<>(); Long deptId = user.getDeptId(); @@ -36,9 +31,10 @@ public class HomeService { param.put("userId", user.getUserId()); param.put("deptId", deptId); param.put("roleIds", roleIds); - result = homeMapper.queryShare(param); - break; + List result = homeMapper.queryShare(param); + return result; + default: + return homeMapper.queryStore(user.getUserId()); } - return result; } }