From 63d047db30e03608479ab3d340e925bc3366357c Mon Sep 17 00:00:00 2001
From: huawei <huawei@2214094776>
Date: 星期六, 20 十二月 2025 09:11:45 +0800
Subject: [PATCH] 看板模块
---
Dto/Simple/BiViewDto.cs | 42 +--
/dev/null | 40 ---
Controllers/Simple/SimpleController.cs | 103 ---------
Dto/Simple/ResultDto.cs | 1
entity/MesSimple.cs | 75 ++---
service/Simple/SimpleManager.cs | 244 ++++++++-------------
Dto/Simple/TreeViewDto.cs | 34 +-
Dto/Simple/MesSimpleDto.cs | 65 +++--
8 files changed, 196 insertions(+), 408 deletions(-)
diff --git a/Controllers/Simple/SimpleController.cs b/Controllers/Simple/SimpleController.cs
index 637df1e..8dfe26f 100644
--- a/Controllers/Simple/SimpleController.cs
+++ b/Controllers/Simple/SimpleController.cs
@@ -1,127 +1,30 @@
using Microsoft.AspNetCore.Mvc;
using NewPdaSqlServer.Dto.Simple;
-using NewPdaSqlServer.service.Simple;
+using NewPdaSqlServer.service.Simple;
namespace NewPdaSqlServer.Controllers.Simple;
-/// <summary>
-/// 看板目录接口控制器
-/// 路由前缀: /simple (与Java版本完全一致)
-/// 实现与Java SimpleController完全相同的接口
-/// </summary>
[Route("simple")]
[ApiController]
public class SimpleController : ControllerBase
{
private readonly SimpleManager _simpleManager = new();
- /// <summary>
- /// 获取树形菜单
- /// 对应Java: @PostMapping("/getTree")
- /// </summary>
- /// <returns>树形菜单数据</returns>
- /// <remarks>
- /// 请求示例:
- /// POST /simple/getTree
- /// Content-Type: application/json
- ///
- /// 返回数据结构:
- /// {
- /// "code": 0,
- /// "msg": "请求成功",
- /// "count": 2,
- /// "data": [
- /// {
- /// "id": 1,
- /// "title": "生产看板",
- /// "field": "production",
- /// "spread": true,
- /// "children": [...]
- /// }
- /// ]
- /// }
- /// </remarks>
- /// <response code="200">成功获取树形菜单</response>
[HttpPost("getTree")]
public ResultDto<List<TreeViewDto>> GetTree()
{
return _simpleManager.GetTree();
}
- /// <summary>
- /// 获取菜单列表
- /// 对应Java: @PostMapping("/list")
- /// 注意: 此接口已基本废弃,前端改用树形菜单方式展示
- /// </summary>
- /// <returns>菜单列表数据</returns>
- /// <remarks>
- /// 请求示例:
- /// POST /simple/list
- /// Content-Type: application/json
- ///
- /// 返回数据结构:
- /// {
- /// "code": 0,
- /// "msg": "请求成功",
- /// "count": 5,
- /// "data": [
- /// {
- /// "id": 1,
- /// "isTop": 1,
- /// "fid": 0,
- /// "title": "生产效率看板",
- /// "field": "efficiency",
- /// "href": "http://bi.example.com/dashboard1",
- /// "spread": 0,
- /// "disabled": 0,
- /// "lbtime": 10
- /// }
- /// ]
- /// }
- /// </remarks>
- /// <response code="200">成功获取菜单列表</response>
[HttpPost("list")]
public ResultDto<List<MesSimpleDto>> GetList()
{
return _simpleManager.GetMenuList();
}
- /// <summary>
- /// 根据菜单ID获取BI视图列表
- /// 对应Java: @GetMapping("/listByMenuId/{menuId}")
- /// 核心接口:用于获取轮播页面的BI看板链接列表
- /// </summary>
- /// <param name="menuId">菜单ID (路径参数)</param>
- /// <returns>BI视图列表</returns>
- /// <remarks>
- /// 请求示例:
- /// GET /simple/listByMenuId/102
- ///
- /// 返回数据结构:
- /// {
- /// "code": 0,
- /// "msg": "请求成功",
- /// "count": 3,
- /// "data": [
- /// {
- /// "id": 1001,
- /// "pid": 102,
- /// "name": "质量趋势分析",
- /// "href": "http://bi.example.com/quality/trend",
- /// "lbtime": 10
- /// }
- /// ]
- /// }
- ///
- /// 业务说明:
- /// - 返回指定菜单下所有的BI看板链接
- /// - lbtime字段从父菜单继承(MES_SIMPLE表)
- /// - 前端使用此数据创建iframe进行轮播展示
- /// </remarks>
- /// <response code="200">成功获取BI视图列表</response>
[HttpGet("listByMenuId/{menuId}")]
- public ResultDto<List<BiViewDto>> GetBiViews(int menuId)
+ public ResultDto<List<BiViewDto>> GetBiViews(long menuId)
{
return _simpleManager.GetBiViewsByMenuId(menuId);
}
-}
+}
\ No newline at end of file
diff --git a/Dto/Simple/BiViewDto.cs b/Dto/Simple/BiViewDto.cs
index 23cc5b5..7038ba2 100644
--- a/Dto/Simple/BiViewDto.cs
+++ b/Dto/Simple/BiViewDto.cs
@@ -3,37 +3,25 @@
namespace NewPdaSqlServer.Dto.Simple;
/// <summary>
-/// BI瑙嗗浘DTO - 鐢ㄤ簬杞挱椤甸潰鐨勮鍥炬暟鎹�
+/// BI瑙嗗浘DTO - 涓撻棬鐢ㄤ簬杞挱椤甸潰灞曠ず (瀵瑰簲 NodeType = 1)
/// </summary>
public class BiViewDto
{
- /// <summary>
- /// BI瑙嗗浘涓婚敭ID
- /// </summary>
[JsonProperty("id")]
- public int Id { get; set; }
+ public long Id { get; set; }
+
+ [JsonProperty("parentId")]
+ public long? ParentId { get; set; }
+
+ [JsonProperty("title")]
+ public string? Title { get; set; }
+
+ [JsonProperty("url")]
+ public string? Url { get; set; }
/// <summary>
- /// 鎵�灞炵埗鑿滃崟ID
+ /// 杞挱闂撮殧(绉�)
/// </summary>
- [JsonProperty("pid")]
- public int? Pid { get; set; }
-
- /// <summary>
- /// BI瑙嗗浘鍚嶇О
- /// </summary>
- [JsonProperty("name")]
- public string? Name { get; set; }
-
- /// <summary>
- /// BI鐪嬫澘鐨勫畬鏁碪RL鍦板潃
- /// </summary>
- [JsonProperty("href")]
- public string? Href { get; set; }
-
- /// <summary>
- /// 杞挱鏃堕棿闂撮殧(绉�)
- /// </summary>
- [JsonProperty("lbtime")]
- public int? Lbtime { get; set; }
-}
+ [JsonProperty("duration")]
+ public int? Duration { get; set; }
+}
\ No newline at end of file
diff --git a/Dto/Simple/ChildrenDto.cs b/Dto/Simple/ChildrenDto.cs
deleted file mode 100644
index 12ca976..0000000
--- a/Dto/Simple/ChildrenDto.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using Newtonsoft.Json;
-
-namespace NewPdaSqlServer.Dto.Simple;
-
-/// <summary>
-/// 子菜单项 - 树形结构的子节点
-/// </summary>
-public class ChildrenDto
-{
- /// <summary>
- /// 子菜单ID
- /// </summary>
- [JsonProperty("id")]
- public long Id { get; set; }
-
- /// <summary>
- /// 子菜单名称
- /// </summary>
- [JsonProperty("title")]
- public string? Title { get; set; }
-
- /// <summary>
- /// 英文标识
- /// </summary>
- [JsonProperty("field")]
- public string? Field { get; set; }
-
- /// <summary>
- /// 跳转链接
- /// 如果值为"轮播",则自动生成bi_view.html链接
- /// 否则使用数据库中配置的原始href
- /// </summary>
- [JsonProperty("href")]
- public string? Href { get; set; }
-}
diff --git a/Dto/Simple/MesSimpleDto.cs b/Dto/Simple/MesSimpleDto.cs
index 7164606..21840dd 100644
--- a/Dto/Simple/MesSimpleDto.cs
+++ b/Dto/Simple/MesSimpleDto.cs
@@ -1,64 +1,73 @@
using Newtonsoft.Json;
+using System;
namespace NewPdaSqlServer.Dto.Simple;
/// <summary>
-/// 菜单实体DTO - 用于列表展示
-/// 与Java版本MesSimplesimple字段完全一致
+/// 菜单实体DTO - 对应新的 MES_SIMPLE 表结构
/// </summary>
public class MesSimpleDto
{
- /// <summary>
- /// 自增主键ID
- /// </summary>
[JsonProperty("id")]
public long Id { get; set; }
/// <summary>
- /// 是否为根节点 (0表示为根节点)
+ /// 父节点ID (NULL为根节点)
/// </summary>
- [JsonProperty("isTop")]
- public int? IsTop { get; set; }
+ [JsonProperty("parentId")]
+ public long? ParentId { get; set; }
/// <summary>
- /// 父节点id
+ /// 节点类型: 0=目录, 1=页面/轮播
/// </summary>
- [JsonProperty("fid")]
- public long? Fid { get; set; }
+ [JsonProperty("nodeType")]
+ public int NodeType { get; set; }
/// <summary>
- /// 名称
+ /// 层级 (0-5)
+ /// </summary>
+ [JsonProperty("nodeLevel")]
+ public int NodeLevel { get; set; }
+
+ /// <summary>
+ /// 唯一业务编码
+ /// </summary>
+ [JsonProperty("code")]
+ public string? Code { get; set; }
+
+ /// <summary>
+ /// 显示标题
/// </summary>
[JsonProperty("title")]
public string? Title { get; set; }
/// <summary>
- /// 英文名
+ /// 跳转地址
/// </summary>
- [JsonProperty("field")]
- public string? Field { get; set; }
+ [JsonProperty("url")]
+ public string? Url { get; set; }
/// <summary>
- /// 地址
+ /// 轮播时长(秒)
/// </summary>
- [JsonProperty("href")]
- public string? Href { get; set; }
+ [JsonProperty("carouselDuration")]
+ public int? CarouselDuration { get; set; }
/// <summary>
- /// 节点是否初始展开 (0为不展开,1为展开)
+ /// 是否默认展开
/// </summary>
- [JsonProperty("spread")]
- public int? Spread { get; set; }
+ [JsonProperty("isExpanded")]
+ public bool IsExpanded { get; set; }
/// <summary>
- /// 节点是否为展示 (0为展示,1为不展示)
+ /// 是否启用
/// </summary>
- [JsonProperty("disabled")]
- public int? Disabled { get; set; }
+ [JsonProperty("isEnabled")]
+ public bool IsEnabled { get; set; }
/// <summary>
- /// 轮播时间(秒)
+ /// 排序
/// </summary>
- [JsonProperty("lbtime")]
- public int? Lbtime { get; set; }
-}
+ [JsonProperty("sortOrder")]
+ public int SortOrder { get; set; }
+}
\ No newline at end of file
diff --git a/Dto/Simple/ResultDto.cs b/Dto/Simple/ResultDto.cs
index 96bed90..a1803a2 100644
--- a/Dto/Simple/ResultDto.cs
+++ b/Dto/Simple/ResultDto.cs
@@ -3,7 +3,6 @@
namespace NewPdaSqlServer.Dto.Simple;
/// <summary>
-/// 缁熶竴杩斿洖缁撴灉灏佽 - 涓嶫ava鐗堟湰瀹屽叏鍏煎
/// 瀛楁鍚嶄娇鐢╟ode/msg/count/data浠ヤ繚鎸佸墠绔吋瀹�
/// </summary>
/// <typeparam name="T">鏁版嵁绫诲瀷</typeparam>
diff --git a/Dto/Simple/TreeViewDto.cs b/Dto/Simple/TreeViewDto.cs
index c5a0423..9fa652c 100644
--- a/Dto/Simple/TreeViewDto.cs
+++ b/Dto/Simple/TreeViewDto.cs
@@ -1,39 +1,37 @@
using Newtonsoft.Json;
+using System.Collections.Generic;
namespace NewPdaSqlServer.Dto.Simple;
/// <summary>
-/// 鏍戝舰瑙嗗浘 - 鐢ㄤ簬Layui Tree缁勪欢娓叉煋
+/// 鏍戝舰缁撴瀯DTO - 閫傞厤 Layui Tree 缁勪欢
/// </summary>
public class TreeViewDto
{
- /// <summary>
- /// 鑿滃崟椤笽D
- /// </summary>
[JsonProperty("id")]
public long Id { get; set; }
- /// <summary>
- /// 鑿滃崟鏄剧ず鍚嶇О
- /// </summary>
[JsonProperty("title")]
public string? Title { get; set; }
- /// <summary>
- /// 鑿滃崟鑻辨枃鏍囪瘑
- /// </summary>
[JsonProperty("field")]
- public string? Field { get; set; }
+ public string? Field { get; set; } // 瀵瑰簲 Code
- /// <summary>
- /// 鏄惁榛樿灞曞紑瀛愯妭鐐�
- /// </summary>
[JsonProperty("spread")]
- public bool Spread { get; set; }
+ public bool Spread { get; set; } // 瀵瑰簲 IsExpanded
/// <summary>
- /// 瀛愯彍鍗曞垪琛�
+ /// 璺宠浆閾炬帴 (Layui Tree鐐瑰嚮鏃堕渶瑕�)
/// </summary>
+ [JsonProperty("href")]
+ public string? Href { get; set; } // 瀵瑰簲 Url
+
+ /// <summary>
+ /// 鑺傜偣绫诲瀷 (鍓嶇鍥炬爣鍒ゆ柇渚濇嵁)
+ /// </summary>
+ [JsonProperty("nodeType")]
+ public int NodeType { get; set; }
+
[JsonProperty("children")]
- public List<ChildrenDto>? Children { get; set; }
-}
+ public List<TreeViewDto>? Children { get; set; }
+}
\ No newline at end of file
diff --git a/entity/MesSimple.cs b/entity/MesSimple.cs
index 46377f8..0470e7f 100644
--- a/entity/MesSimple.cs
+++ b/entity/MesSimple.cs
@@ -1,64 +1,53 @@
+using System;
using SqlSugar;
namespace NewPdaSqlServer.entity;
/// <summary>
-/// 菜单维护表
+/// 看板菜单配置表 (MES_SIMPLE)
/// </summary>
[SugarTable("MES_SIMPLE")]
public class MesSimple
{
- /// <summary>
- /// 自增列主键
- /// </summary>
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
public long Id { get; set; }
- /// <summary>
- /// 是否为根节点 (0表示为根节点)
- /// </summary>
- [SugarColumn(ColumnName = "is_top")]
- public int? IsTop { get; set; }
+ [SugarColumn(ColumnName = "parent_id", IsNullable = true)]
+ public long? ParentId { get; set; }
- /// <summary>
- /// 父节点id
- /// </summary>
- [SugarColumn(ColumnName = "fid")]
- public long? Fid { get; set; }
+ [SugarColumn(ColumnName = "node_level")]
+ public int NodeLevel { get; set; }
- /// <summary>
- /// 名称
- /// </summary>
+ [SugarColumn(ColumnName = "node_type")]
+ public int NodeType { get; set; }
+
+ [SugarColumn(ColumnName = "code")]
+ public string? Code { get; set; }
+
[SugarColumn(ColumnName = "title")]
public string? Title { get; set; }
- /// <summary>
- /// 英文名
- /// </summary>
- [SugarColumn(ColumnName = "field")]
- public string? Field { get; set; }
+ [SugarColumn(ColumnName = "url")]
+ public string? Url { get; set; }
- /// <summary>
- /// 地址
- /// </summary>
- [SugarColumn(ColumnName = "href")]
- public string? Href { get; set; }
+ [SugarColumn(ColumnName = "carousel_duration", IsNullable = true)]
+ public int? CarouselDuration { get; set; }
- /// <summary>
- /// 节点是否初始展开 (0为不展开,1为展开)
- /// </summary>
- [SugarColumn(ColumnName = "spread")]
- public int? Spread { get; set; }
+ [SugarColumn(ColumnName = "is_expanded")]
+ public bool IsExpanded { get; set; }
- /// <summary>
- /// 节点是否为展示 (0为展示,1为不展示)
- /// </summary>
- [SugarColumn(ColumnName = "disabled")]
- public int? Disabled { get; set; }
+ [SugarColumn(ColumnName = "is_enabled")]
+ public bool IsEnabled { get; set; }
- /// <summary>
- /// 轮播时间(秒)
- /// </summary>
- [SugarColumn(ColumnName = "lbtime")]
- public int? Lbtime { get; set; }
-}
+ [SugarColumn(ColumnName = "sort_order")]
+ public int SortOrder { get; set; }
+
+ [SugarColumn(ColumnName = "is_deleted")]
+ public bool IsDeleted { get; set; }
+
+ [SugarColumn(ColumnName = "created_by")]
+ public string? CreatedBy { get; set; }
+
+ [SugarColumn(ColumnName = "created_at")]
+ public DateTime CreatedAt { get; set; }
+}
\ No newline at end of file
diff --git a/entity/MesSimpleCcb.cs b/entity/MesSimpleCcb.cs
deleted file mode 100644
index 364d7bd..0000000
--- a/entity/MesSimpleCcb.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-using SqlSugar;
-
-namespace NewPdaSqlServer.entity;
-
-/// <summary>
-/// BI视图表 - 存储每个菜单下具体的BI看板链接
-/// </summary>
-[SugarTable("MES_SIMPLE_CCB")]
-public class MesSimpleCcb
-{
- /// <summary>
- /// 主键ID
- /// </summary>
- [SugarColumn(ColumnName = "id", IsPrimaryKey = true)]
- public int Id { get; set; }
-
- /// <summary>
- /// 父节点ID (关联MES_SIMPLE.id)
- /// </summary>
- [SugarColumn(ColumnName = "pid")]
- public int? Pid { get; set; }
-
- /// <summary>
- /// BI视图名称
- /// </summary>
- [SugarColumn(ColumnName = "name")]
- public string? Name { get; set; }
-
- /// <summary>
- /// BI看板完整URL地址
- /// </summary>
- [SugarColumn(ColumnName = "href")]
- public string? Href { get; set; }
-
- /// <summary>
- /// 轮播时间(秒) - 实际使用时会被父菜单的lbtime覆盖
- /// </summary>
- [SugarColumn(ColumnName = "lbtime")]
- public int? Lbtime { get; set; }
-}
diff --git a/service/Simple/SimpleManager.cs b/service/Simple/SimpleManager.cs
index 91c46a2..0002038 100644
--- a/service/Simple/SimpleManager.cs
+++ b/service/Simple/SimpleManager.cs
@@ -1,67 +1,76 @@
-using NewPdaSqlServer.DB;
+using NewPdaSqlServer.DB; // 你的Repository基类所在的命名空间
using NewPdaSqlServer.Dto.Simple;
-using NewPdaSqlServer.entity;
+using NewPdaSqlServer.entity; // 引用实体
using SqlSugar;
namespace NewPdaSqlServer.service.Simple;
/// <summary>
/// 看板菜单业务管理器
-/// 实现与Java版本MesSimpleServiceImpl完全一致的业务逻辑
/// </summary>
public class SimpleManager : Repository<MesSimple>
{
/// <summary>
/// 获取树形菜单
- /// 对应Java: getTree()
/// </summary>
- /// <returns>树形菜单数据</returns>
public ResultDto<List<TreeViewDto>> GetTree()
{
try
{
- var tree = ToTree();
+ var allNodes = Db.Queryable<MesSimple>()
+ .Where(m => m.IsEnabled && !m.IsDeleted)
+ .OrderBy(m => m.SortOrder)
+ .ToList();
+
+ var tree = BuildTree(allNodes, null);
return ResultDto<List<TreeViewDto>>.Ok(tree, tree.Count);
}
catch (Exception ex)
{
- return ResultDto<List<TreeViewDto>>.Error(ex.Message);
+ return ResultDto<List<TreeViewDto>>.Error("获取树形菜单失败: " + ex.Message);
}
}
- /// <summary>
- /// 转换为树形结构
- /// 对应Java: toTree()
- /// </summary>
- /// <returns>树形视图列表</returns>
- public List<TreeViewDto> ToTree()
+ private List<TreeViewDto> BuildTree(List<MesSimple> allNodes, long? parentId)
{
- return ConvertToTreeViewList(GetTopList());
+ return allNodes
+ .Where(x => x.ParentId == parentId)
+ .Select(x => new TreeViewDto
+ {
+ Id = x.Id,
+ Title = x.Title,
+ Field = x.Code,
+ Spread = x.IsExpanded,
+ Href = x.Url,
+ NodeType = x.NodeType,
+ Children = BuildTree(allNodes, x.Id)
+ })
+ .ToList();
}
/// <summary>
/// 获取菜单列表
- /// 对应Java: getMenuList()
- /// 查询条件: disabled=0 且 isTop>0 (排除根节点)
/// </summary>
- /// <returns>菜单列表</returns>
public ResultDto<List<MesSimpleDto>> GetMenuList()
{
try
{
var list = Db.Queryable<MesSimple>()
- .Where(m => m.Disabled == 0 && m.IsTop > 0)
+ .Where(m => m.IsEnabled && !m.IsDeleted)
+ .OrderBy(m => m.SortOrder)
.Select(m => new MesSimpleDto
{
Id = m.Id,
- IsTop = m.IsTop,
- Fid = m.Fid,
+ ParentId = m.ParentId,
+ NodeType = m.NodeType,
+ NodeLevel = m.NodeLevel,
+ Code = m.Code,
Title = m.Title,
- Field = m.Field,
- Href = m.Href,
- Spread = m.Spread,
- Disabled = m.Disabled,
- Lbtime = m.Lbtime
+ Url = m.Url,
+ CarouselDuration = m.CarouselDuration,
+ IsExpanded = m.IsExpanded,
+ IsEnabled = m.IsEnabled,
+ SortOrder = m.SortOrder
})
.ToList();
@@ -74,139 +83,72 @@
}
/// <summary>
- /// 根据菜单ID获取BI视图列表
- /// 对应Java: getBiViewsByMenuId()
+ /// 根据ID获取视图列表
+ /// 逻辑升级:
+ /// 1. 先找子节点 (轮播模式)
+ /// 2. 如果没子节点,但自己有URL (单页模式),则返回自己
/// </summary>
- /// <param name="menuId">菜单ID</param>
- /// <returns>BI视图列表</returns>
- public ResultDto<List<BiViewDto>> GetBiViewsByMenuId(int menuId)
+ public ResultDto<List<BiViewDto>> GetBiViewsByMenuId(long menuId)
+{
+ try
{
- try
- {
- // 查询指定菜单下的所有BI视图
- var list = Db.Queryable<MesSimpleCcb>()
- .Where(b => b.Pid == menuId && b.Href != null)
- .Select(b => new BiViewDto
- {
- Id = b.Id,
- Pid = b.Pid,
- Name = b.Name,
- Href = b.Href,
- Lbtime = b.Lbtime
- })
- .ToList();
+ // 1. 首先查询点击的这个节点本身 (必须是启用且未删除)
+ var selfNode = Db.Queryable<MesSimple>()
+ .First(m => m.Id == menuId && m.IsEnabled && !m.IsDeleted);
- // 如果有数据,获取父菜单的轮播时间配置并赋值给所有BI视图
- if (list.Count > 0)
+ if (selfNode == null) return ResultDto<List<BiViewDto>>.Error("该节点不存在或已禁用");
+
+ // 安全检查:如果前端传了 NodeType=0 的 ID 进来,这里拦截
+ if (selfNode.NodeType == 0) return ResultDto<List<BiViewDto>>.Error("目录节点不可直接预览");
+
+ // 2. 判断自己是否有 URL
+ // 排除空值和占位符 "轮播"
+ if (!string.IsNullOrEmpty(selfNode.Url) && selfNode.Url != "轮播")
+ {
+ var selfView = new BiViewDto
{
- var simple = Db.Queryable<MesSimple>()
- .Where(m => m.Id == menuId)
- .First();
-
- if (simple != null)
- {
- // 将父菜单的lbtime赋值给所有BI视图
- list.ForEach(biView => biView.Lbtime = simple.Lbtime);
- }
- }
-
- return ResultDto<List<BiViewDto>>.Ok(list, list.Count);
- }
- catch (Exception ex)
- {
- return ResultDto<List<BiViewDto>>.Error(ex.Message);
- }
- }
-
- #region 私有方法
-
- /// <summary>
- /// 获取根节点列表
- /// 查询条件: isTop=0 且 disabled=0
- /// </summary>
- /// <returns>根节点列表</returns>
- private List<MesSimple> GetTopList()
- {
- return Db.Queryable<MesSimple>()
- .Where(m => m.IsTop == 0 && m.Disabled == 0)
- .ToList();
- }
-
- /// <summary>
- /// 转换为树形视图列表
- /// 对应Java: convertToTreeViewList()
- /// 使用并行处理提升性能
- /// </summary>
- /// <param name="mesSimpleList">根节点列表</param>
- /// <returns>树形视图列表</returns>
- private List<TreeViewDto> ConvertToTreeViewList(List<MesSimple> mesSimpleList)
- {
- // 使用Parallel.ForEach实现并行处理,类似Java的CompletableFuture
- var treeViews = new List<TreeViewDto>();
- var lockObj = new object();
-
- Parallel.ForEach(mesSimpleList, mesSimple =>
- {
- var treeView = ConvertToTreeView(mesSimple);
- lock (lockObj)
- {
- treeViews.Add(treeView);
- }
- });
-
- return treeViews;
- }
-
- /// <summary>
- /// 转换单个菜单项为树形视图
- /// 对应Java: convertToTreeView()
- /// </summary>
- /// <param name="mesSimple">菜单实体</param>
- /// <returns>树形视图</returns>
- private TreeViewDto ConvertToTreeView(MesSimple mesSimple)
- {
- var treeView = new TreeViewDto
- {
- Id = mesSimple.Id,
- Title = mesSimple.Title,
- Field = mesSimple.Field,
- Spread = mesSimple.Spread == 1
- };
-
- // 查询子节点
- var childList = Db.Queryable<MesSimple>()
- .Where(m => m.Disabled == 0 && m.Fid == mesSimple.Id)
- .ToList();
-
- // 转换子节点
- var childrenList = new List<ChildrenDto>();
- foreach (var child in childList)
- {
- var children = new ChildrenDto
- {
- Id = child.Id,
- Title = child.Title,
- Field = child.Field
+ Id = selfNode.Id,
+ ParentId = selfNode.ParentId,
+ Title = selfNode.Title,
+ Url = selfNode.Url,
+ Duration = (selfNode.CarouselDuration == null || selfNode.CarouselDuration <= 0) ? 10 : selfNode.CarouselDuration
};
-
- // 处理href字段
- // 如果href值为"轮播",则自动生成轮播页面链接
- if ("轮播".Equals(child.Href))
- {
- children.Href = $"bi_view.html?menuId={child.Id}&lbsj={child.Lbtime}";
- }
- else
- {
- children.Href = child.Href;
- }
-
- childrenList.Add(children);
+ return ResultDto<List<BiViewDto>>.Ok(new List<BiViewDto> { selfView
+}, 1);
}
- treeView.Children = childrenList;
+ // 3. 自己没有 URL,查找子目录/子项
+ // 查询 ParentId = menuId 且类型为 2 的子项
+ var childNodes = Db.Queryable<MesSimple>()
+ .Where(b => b.ParentId == menuId && b.NodeType == 2 && b.IsEnabled && !b.IsDeleted)
+ .OrderBy(b => b.SortOrder)
+ .ToList();
- return treeView;
- }
+if (childNodes.Count > 0)
+{
+ var resultList = childNodes.Select(b => new BiViewDto
+ {
+ Id = b.Id,
+ ParentId = b.ParentId,
+ Title = b.Title,
+ Url = b.Url,
+ // 子项如果没时间,继承当前 menuId 节点的时间配置
+ Duration = (b.CarouselDuration == null || b.CarouselDuration <= 0)
+ ? (selfNode.CarouselDuration ?? 10)
+ : b.CarouselDuration
+ }).ToList();
- #endregion
+ return ResultDto<List<BiViewDto>>.Ok(resultList, resultList.Count);
}
+
+// 4. 自己没 URL 且 子项也没 URL
+// 返回空列表,前端 bi_view.html 收到后会弹出“当前菜单下没有可轮播的内容”
+return ResultDto<List<BiViewDto>>.Ok(new List<BiViewDto>(), 0);
+ }
+ catch (Exception ex)
+ {
+ return ResultDto<List<BiViewDto>>.Error("数据查询失败: " + ex.Message);
+ }
+}
+
+}
\ No newline at end of file
--
Gitblit v1.9.3