1. 后端门户逻辑

This commit is contained in:
chenbowen
2026-01-23 10:23:30 +08:00
parent 83545f90bd
commit 6ff39a4f83
4 changed files with 77 additions and 50 deletions

View File

@@ -4,6 +4,9 @@ import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.util.object.BeanUtils; import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.framework.excel.core.util.ExcelUtils; import com.zt.plat.framework.excel.core.util.ExcelUtils;
import com.zt.plat.framework.tenant.core.aop.TenantIgnore;
import com.zt.plat.module.infra.api.file.FileApi;
import com.zt.plat.module.infra.api.file.dto.FileRespDTO;
import com.zt.plat.module.system.controller.admin.portal.vo.PortalPageReqVO; import com.zt.plat.module.system.controller.admin.portal.vo.PortalPageReqVO;
import com.zt.plat.module.system.controller.admin.portal.vo.PortalRespVO; import com.zt.plat.module.system.controller.admin.portal.vo.PortalRespVO;
import com.zt.plat.module.system.controller.admin.portal.vo.PortalSaveReqVO; import com.zt.plat.module.system.controller.admin.portal.vo.PortalSaveReqVO;
@@ -13,6 +16,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
@@ -20,7 +24,12 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.springframework.util.StringUtils;
import static com.zt.plat.framework.common.pojo.CommonResult.success; import static com.zt.plat.framework.common.pojo.CommonResult.success;
import static com.zt.plat.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static com.zt.plat.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@@ -39,6 +48,9 @@ public class PortalController {
@Resource @Resource
private PortalService portalService; private PortalService portalService;
@Resource
private FileApi fileApi;
@PostMapping("/create") @PostMapping("/create")
@Operation(summary = "创建门户网站") @Operation(summary = "创建门户网站")
@PreAuthorize("@ss.hasPermission('system:portal:create')") @PreAuthorize("@ss.hasPermission('system:portal:create')")
@@ -97,9 +109,60 @@ public class PortalController {
*/ */
@GetMapping("/list") @GetMapping("/list")
@Operation(summary = "获取我的门户列表") @Operation(summary = "获取我的门户列表")
@PermitAll
@TenantIgnore
public CommonResult<List<PortalRespVO>> getMyPortalList() { public CommonResult<List<PortalRespVO>> getMyPortalList() {
Long userId = getLoginUserId(); Long userId = null;
List<PortalDO> portals = portalService.getPortalListByUserId(userId); try {
userId = getLoginUserId();
} catch (Exception ignored) {
// 未登录时获取公开门户
}
List<PortalDO> portals = (userId == null)
? portalService.getPublicPortalList()
: portalService.getPortalListByUserId(userId);
return success(BeanUtils.toBean(portals, PortalRespVO.class)); return success(BeanUtils.toBean(portals, PortalRespVO.class));
} }
/**
* 匿名获取公开门户的图标文件信息
* 仅允许访问门户中已配置的图标文件
*/
@GetMapping("/public-icon-files")
@Operation(summary = "获取公开门户图标文件信息")
@PermitAll
@TenantIgnore
public CommonResult<List<FileRespDTO>> getPublicPortalIconFiles(@RequestParam("fileIds") List<Long> fileIds) {
if (fileIds == null || fileIds.isEmpty()) {
return success(java.util.Collections.emptyList());
}
List<PortalDO> portals = portalService.getPublicPortalList();
Set<Long> allowedFileIds = new HashSet<>();
for (PortalDO portal : portals) {
if (portal.getIconType() == null || portal.getIconType() != 2) {
continue;
}
if (!StringUtils.hasText(portal.getIconFileId())) {
continue;
}
try {
allowedFileIds.add(Long.parseLong(portal.getIconFileId()));
} catch (NumberFormatException ignored) {
// ignore invalid fileId
}
}
List<FileRespDTO> result = new ArrayList<>();
for (Long fileId : fileIds) {
if (!allowedFileIds.contains(fileId)) {
continue;
}
CommonResult<FileRespDTO> fileResult = fileApi.getFileInfo(fileId);
if (fileResult != null && fileResult.isSuccess() && fileResult.getData() != null) {
result.add(fileResult.getData());
}
}
return success(result);
}
} }

View File

@@ -1,48 +0,0 @@
package com.zt.plat.module.system.controller.app.portal;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.system.controller.admin.portal.vo.PortalRespVO;
import com.zt.plat.module.system.dal.dataobject.portal.PortalDO;
import com.zt.plat.module.system.service.portal.PortalService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import static com.zt.plat.framework.common.pojo.CommonResult.success;
import static com.zt.plat.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
/**
* 用户端 - 门户网站 Controller
*
* @author 中铜数字供应链平台
*/
@Tag(name = "用户端 - 门户网站")
@RestController
@RequestMapping("/system/portal")
@Validated
public class AppPortalController {
@Resource
private PortalService portalService;
/**
* 获取当前用户可访问的门户列表
* 此接口无需权限验证,因为已经通过登录验证,
* 返回的门户列表已经根据用户权限进行了过滤
*/
@GetMapping("/list")
@Operation(summary = "获取我的门户列表")
public CommonResult<List<PortalRespVO>> getMyPortalList() {
Long userId = getLoginUserId();
List<PortalDO> portals = portalService.getPortalListByUserId(userId);
return success(BeanUtils.toBean(portals, PortalRespVO.class));
}
}

View File

@@ -60,4 +60,11 @@ public interface PortalService {
*/ */
List<PortalDO> getPortalListByUserId(Long userId); List<PortalDO> getPortalListByUserId(Long userId);
/**
* 获得公开门户列表(无需登录)
*
* @return 门户列表
*/
List<PortalDO> getPublicPortalList();
} }

View File

@@ -126,6 +126,11 @@ public class PortalServiceImpl implements PortalService {
return portalMapper.selectListByPermissions(permissions); return portalMapper.selectListByPermissions(permissions);
} }
@Override
public List<PortalDO> getPublicPortalList() {
return portalMapper.selectListByPermissions(Collections.emptyList());
}
@VisibleForTesting @VisibleForTesting
public PortalDO validatePortalExists(Long id) { public PortalDO validatePortalExists(Long id) {
if (id == null) { if (id == null) {