using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Description;
using Learun.Application.Base.SystemModule;
using Learun.Application.TwoDevelopment.ZZDT_EC;
using Learun.Util;
namespace Learun.Application.Web.AppApi
{
///
/// 元件库文件接口
///
[RoutePrefix("api/LibraryFileApi")]
[HandlerApiLogin(FilterMode.Enforce)]
[TokenAuthorize]
public class LibraryFileApiController : WebApiControllerBase
{
private ec_library_catalogueIBLL ec_library_catalogueIBLL = new ec_library_catalogueBLL();
private ec_library_fileIBLL ec_library_fileIBLL = new ec_library_fileBLL();
private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL();
///
/// 获取元件库目录
///
/// 项目ID
///
[HttpGet]
[ResponseType(typeof(List))]
public IHttpActionResult GetTemplateCatalogue(string projectId)
{
try
{
string queryJson = "{\"ProjectId\":\"" + projectId + "\"}";
var listCatalogue = ec_library_catalogueIBLL.GetList(queryJson);
var listFile = ec_library_fileIBLL.GetList(queryJson);
List treeList = new List();
foreach (var itemCatalogue in listCatalogue)
{
TreeModel nodeCatalogue = new TreeModel();
nodeCatalogue.id = itemCatalogue.LibraryCatalogueID;
nodeCatalogue.text = itemCatalogue.LibraryCatalogueName;
nodeCatalogue.value = itemCatalogue.LibraryCatalogueID;
nodeCatalogue.nodeType = "0";
nodeCatalogue.showcheck = false;
nodeCatalogue.checkstate = 0;
nodeCatalogue.isexpand = false;
nodeCatalogue.parentId = itemCatalogue.UpLibraryCatalogueID;
nodeCatalogue.NodeExtData = itemCatalogue;
treeList.Add(nodeCatalogue);
var listFileTmp = listFile.Where(x => x.LibraryCatalogueID == itemCatalogue.LibraryCatalogueID).ToList();
foreach (var itemFile in listFileTmp)
{
TreeModel nodeFile = new TreeModel();
nodeFile.id = itemFile.LibraryFileID;
nodeFile.text = itemFile.LibraryFileName;
nodeFile.value = itemFile.LibraryFileID;
nodeFile.nodeType = "1";
nodeFile.showcheck = false;
nodeFile.checkstate = 0;
nodeFile.isexpand = false;
nodeFile.parentId = itemCatalogue.LibraryCatalogueID;
nodeFile.NodeExtData = itemFile;
treeList.Add(nodeFile);
}
}
return Success(treeList.ToTree());
}
catch (Exception ex)
{
return Fail(ex.Message);
}
}
///
/// 获取元件库文件信息
///
/// 项目ID
/// 元件库文件ID
///
[HttpGet]
[ResponseType(typeof(ec_library_fileEntity))]
public IHttpActionResult GetEntity(string projectId, string libraryFileID)
{
try
{
var entity = ec_library_fileIBLL.GetEntity(libraryFileID, projectId);
var fileList = annexesFileIBLL.GetList(entity.FolderId).ToList();
if (fileList != null && fileList.Count > 0)
{
entity.FileId = fileList[0].F_Id;
}
return Success(entity);
}
catch (Exception ex)
{
return Fail(ex.Message);
}
}
}
}