72 lines
2.8 KiB
C#
72 lines
2.8 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Web.Http;
|
|
using WX.CRM.Common;
|
|
|
|
namespace WxFile.Api.Controllers
|
|
{
|
|
public class Mp4Controller : ApiController
|
|
{
|
|
/// <summary>
|
|
/// 获取从业考试视频json
|
|
/// </summary>
|
|
/// <param name="type">
|
|
/// JRSCJCZS:金融市场基础知识
|
|
/// ZJFLFG:证券法律法规
|
|
/// </param>
|
|
/// <returns></returns>
|
|
[Route("Mp4/Get/{type}")]
|
|
[HttpGet]
|
|
public HttpResponseMessage GetMessage(string type)
|
|
{
|
|
string filepath = Utility.GetSettingByKey("Mpd4Config_" + type);
|
|
List<Mp4Folder> folds = new List<Mp4Folder>();
|
|
//LogHelper.Info(filepath);
|
|
|
|
DirectoryInfo theFolder = new DirectoryInfo(filepath);
|
|
DirectoryInfo[] dirInfo = theFolder.GetDirectories();
|
|
foreach (var item in dirInfo)
|
|
{
|
|
List<Mp4File> childs = new List<Mp4File>();
|
|
FileInfo[] fileInfo = item.GetFiles("*.*", SearchOption.AllDirectories);
|
|
foreach (var file in fileInfo)
|
|
{
|
|
|
|
childs.Add(new Mp4File() { name = file.Name, httpath = $"/Mp4/{theFolder.Name}/{item.Name}/{file.Name}", sortname = GetName(file.Name) });
|
|
}
|
|
folds.Add(new Mp4Folder() { name = item.Name, childs = childs.OrderBy(m => m.sortname).ToList(), sortname = GetName(item.Name) });
|
|
}
|
|
folds = folds.OrderBy(m => m.sortname).ToList();
|
|
|
|
return new HttpResponseMessage { Content = new StringContent(folds.ToJson(), System.Text.Encoding.UTF8, "application/json") };
|
|
//return Content<string>(HttpStatusCode.OK, cld.ToString());
|
|
}
|
|
private string GetName(string name)
|
|
{
|
|
name = name.Replace("一", "1").Replace("二", "2").Replace("三", "3").Replace("四", "4").Replace("五", "5").Replace("六", "6").Replace("七", "7").Replace("八", "8").Replace("九", "9");
|
|
name = name.Replace("10", "A").Replace("11", "B").Replace("12", "C").Replace("13", "D").Replace("14", "E").Replace("15", "F").Replace("16", "G").Replace("17", "H").Replace("18", "I").Replace("19", "J");
|
|
return name;
|
|
}
|
|
}
|
|
public class Mp4Folder
|
|
{
|
|
public string name { get; set; }
|
|
/// <summary>
|
|
/// 排序用的名称
|
|
/// </summary>
|
|
public string sortname { get; set; }
|
|
public List<Mp4File> childs { get; set; }
|
|
}
|
|
public class Mp4File
|
|
{
|
|
public string name { get; set; }
|
|
/// <summary>
|
|
/// 排序用的名称
|
|
/// </summary>
|
|
public string sortname { get; set; }
|
|
public string httpath { get; set; }
|
|
}
|
|
}
|