using NewPdaSqlServer.DB; // ÄãµÄRepository»ùÀàËùÔÚµÄÃüÃû¿Õ¼ä
|
using NewPdaSqlServer.Dto.Simple;
|
using NewPdaSqlServer.entity; // ÒýÓÃʵÌå
|
using SqlSugar;
|
|
namespace NewPdaSqlServer.service.Simple;
|
|
/// <summary>
|
/// ¿´°å²Ëµ¥ÒµÎñ¹ÜÀíÆ÷
|
/// </summary>
|
public class SimpleManager : Repository<MesSimple>
|
{
|
/// <summary>
|
/// »ñÈ¡Ê÷Ðβ˵¥
|
/// </summary>
|
public ResultDto<List<TreeViewDto>> GetTree()
|
{
|
try
|
{
|
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);
|
}
|
}
|
|
private List<TreeViewDto> BuildTree(List<MesSimple> allNodes, long? parentId)
|
{
|
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>
|
/// »ñÈ¡²Ëµ¥Áбí
|
/// </summary>
|
public ResultDto<List<MesSimpleDto>> GetMenuList()
|
{
|
try
|
{
|
var list = Db.Queryable<MesSimple>()
|
.Where(m => m.IsEnabled && !m.IsDeleted)
|
.OrderBy(m => m.SortOrder)
|
.Select(m => new MesSimpleDto
|
{
|
Id = m.Id,
|
ParentId = m.ParentId,
|
NodeType = m.NodeType,
|
NodeLevel = m.NodeLevel,
|
Code = m.Code,
|
Title = m.Title,
|
Url = m.Url,
|
CarouselDuration = m.CarouselDuration,
|
IsExpanded = m.IsExpanded,
|
IsEnabled = m.IsEnabled,
|
SortOrder = m.SortOrder
|
})
|
.ToList();
|
|
return ResultDto<List<MesSimpleDto>>.Ok(list, list.Count);
|
}
|
catch (Exception ex)
|
{
|
return ResultDto<List<MesSimpleDto>>.Error(ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// ¸ù¾ÝID»ñÈ¡ÊÓͼÁбí
|
/// Âß¼Éý¼¶£º
|
/// 1. ÏÈÕÒ×Ó½Úµã (ÂÖ²¥Ä£Ê½)
|
/// 2. Èç¹ûû×ӽڵ㣬µ«×Ô¼ºÓÐURL (µ¥Ò³Ä£Ê½)£¬Ôò·µ»Ø×Ô¼º
|
/// </summary>
|
public ResultDto<List<BiViewDto>> GetBiViewsByMenuId(long menuId)
|
{
|
try
|
{
|
// 1. Ê×ÏȲéѯµã»÷µÄÕâ¸ö½Úµã±¾Éí (±ØÐëÊÇÆôÓÃÇÒδɾ³ý)
|
var selfNode = Db.Queryable<MesSimple>()
|
.First(m => m.Id == menuId && m.IsEnabled && !m.IsDeleted);
|
|
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
|
{
|
Id = selfNode.Id,
|
ParentId = selfNode.ParentId,
|
Title = selfNode.Title,
|
Url = selfNode.Url,
|
Duration = (selfNode.CarouselDuration == null || selfNode.CarouselDuration <= 0) ? 10 : selfNode.CarouselDuration
|
};
|
return ResultDto<List<BiViewDto>>.Ok(new List<BiViewDto> { selfView
|
}, 1);
|
}
|
|
// 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();
|
|
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();
|
|
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);
|
}
|
}
|
|
}
|