namespace Yw.Application
{
///
/// SoftwareProjectMenuMapping
///
[Route("Auth/Software/Project/Menu/Mapping")]
[ApiDescriptionSettings("Auth", Name = "软件与项目菜单映射", Order = 4800)]
public class SoftwareProjectMenu_Controller : IDynamicApiController
{
private Service.SoftwareProjectMenuMapping _service = new();
///
/// 获取软件下发菜单列表
///
[Route("GetAuthorizeMenuList@V1.0")]
[HttpGet]
public List GetAuthorizeMenuList([FromQuery][Required] SoftwareIDInput input)
{
var software = new Service.Software().GetByID(input.SoftwareID);
if (software == null)
{
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"SoftwareID:{input.SoftwareID} 数据不存在");
}
var dict = _service.GetAuthorizeMenuList(input.SoftwareID);
if (dict == null || dict.Count < 1)
{
return default;
}
var vmList = new List();
foreach (var item in dict)
{
var vm = new SoftwareProjectMenuHaveDto(item.Key, item.Value);
var vmParent = vmList.Find(x => x.ID == vm.ParentID);
if (vmParent != null)
{
if (!vmParent.Have)
{
vm.Have = false;
}
}
vmList.Add(vm);
}
return vmList;
}
///
/// 设置
///
[Route("Set@V1.0")]
[HttpPost]
public bool Set([Required] SetSoftwareProjectMenuInput input)
{
var software = new Service.Software().GetByID(input.SoftwareID);
if (software == null)
{
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"SoftwareID:{input.SoftwareID} 数据不存在");
}
if (input.MenuIds != null && input.MenuIds.Count > 0)
{
var menuList = new Service.ProjectMenu().GetByIds(input.MenuIds);
if (menuList == null || menuList.Count < 1)
{
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.L001, "菜单id列表与数据库不匹配");
}
var projectIds = menuList.Select(x => x.ProjectID).Distinct().ToList();
if (projectIds.Count != 1 || projectIds[0] != software.ProjectID)
{
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.L001, "菜单id列表与数据库不匹配");
}
}
var bol = _service.Set(input.SoftwareID, input.MenuIds);
return bol;
}
}
}