Commit 8143c125 authored by 黄奎's avatar 黄奎

页面修改

parent 870c9819
......@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
namespace Edu.Common.Plugin
{
......@@ -16,16 +17,89 @@ namespace Edu.Common.Plugin
/// <param name="path"></param>
/// <param name="serverPath"></param>
/// <returns></returns>
public static List<FileItem> GetFileAllPath(string path,string savePath)
public static List<FileItem> GetFileAllPath(string path, string savePath)
{
List<FileItem> fileList = new List<FileItem>();
DirectoryInfo rootFolder = new DirectoryInfo(path);
if (rootFolder != null)
{
int leval = 0;
GetDirectoryAndFile(path, leval, fileList);
foreach (var item in fileList)
{
string str = @"录音 [0123456789]*";
Regex reg = new Regex(str);
var fileNameArray = Regex.Split(item.FileName, str);
string newFileName = item.FileName;
if (fileNameArray != null && fileNameArray.Length > 0)
{
newFileName = fileNameArray.Length > 1 ? fileNameArray[1] : fileNameArray[0];
}
string newPathFileName = savePath + @"\" + newFileName.TrimStart().TrimEnd();
File.Copy(item.FileUrl, newPathFileName, true);
item.FileUrl = newPathFileName;
}
return fileList;
}
/// <summary>
/// 获取所有文件
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static List<FileItem> GetFileList(string path)
{
List<FileItem> fileList = new List<FileItem>();
DirectoryInfo theFolder = new DirectoryInfo(@path);
//遍历文件
foreach (FileInfo NextFile in theFolder.GetFiles())
{
string extName = Path.GetExtension(NextFile.Name).ToLower();
if (extName == ".mp3")
{
fileList.Add(new FileItem()
{
FileName = NextFile.Name,
FileUrl = NextFile.FullName
});
}
}
return fileList;
}
/// <summary>
/// 列出path路径对应的文件夹中的子文件夹和文件
/// 然后再递归列出子文件夹内的文件和文件夹
/// </summary>
/// <param name="path">需要列出内容的文件夹的路径</param>
/// <param name="leval">当前递归层级,用于控制输出前导空格的数量</param>
private static void GetDirectoryAndFile(string path, int leval, List<FileItem> list)
{
DirectoryInfo theFolder = new DirectoryInfo(@path);
leval++;
//遍历文件
foreach (FileInfo NextFile in theFolder.GetFiles())
{
for (int i = 0; i < leval; i++)
{
string extName = Path.GetExtension(NextFile.Name).ToLower();
if (extName == ".mp3")
{
list.Add(new FileItem()
{
FileName = NextFile.Name,
FileUrl = NextFile.FullName
});
}
}
}
//遍历文件夹
foreach (DirectoryInfo NextFolder in theFolder.GetDirectories())
{
for (int i = 0; i < leval; i++)
{
GetDirectoryAndFile(NextFolder.FullName, leval, list);
}
}
}
}
/// <summary>
......
......@@ -1198,6 +1198,30 @@ namespace Edu.Module.Course
}
}
/// <summary>
/// 重新更新课程单词URL
/// </summary>
public void RunWordsUrlModule()
{
var list= course_WordsRepository.GetCourseWordsListRepository(new RB_Course_Words_Extend() {});
string newPath = @"G:\NewWords";
var fileList = Common.Plugin.FileHelper.GetFileList(newPath);
if (list != null && list.Count > 0 && fileList != null && fileList.Count > 0)
{
Dictionary<string, object> fileds = new Dictionary<string, object>();
foreach (var item in list)
{
var tempWords = fileList.Where(qitem => qitem.FileName == item.WordContent + ".mp3")?.FirstOrDefault();
if (tempWords != null)
{
fileds.Clear();
fileds.Add(nameof(RB_Course_Words_Extend.FileUrl), tempWords.FileUrl);
bool flag = course_WordsRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Words_Extend.Id), item.Id));
}
}
}
}
/// <summary>
/// 获取课程章节列表
/// </summary>
......

using Edu.Repository.Course;
using System;
namespace Edu.Test
......@@ -11,6 +12,13 @@ namespace Edu.Test
//filePath = @"C:/Users/qiaoyajun/Desktop/EduWordTemplate.doc";
//filePath = @"C:/Users/qiaoyajun/Desktop/EduWordTemplate.doc";
//var data = Common.Data.QuestionHelper.GetWordQuestionData(filePath);
//string newPath = @"G:\NewWords";
//string filePath = @"G:\Words";
//var list = Common.Plugin.FileHelper.GetFileAllPath(filePath, newPath);
//string str = Common.Plugin.JsonHelper.Serialize(list);
// Console.WriteLine(str);
Console.ReadKey();
}
}
}
......@@ -63,6 +63,7 @@ namespace Edu.WebApi.Controllers.User
[AllowAnonymous]
public ApiResult Test()
{
courseModule.RunWordsUrlModule();
return ApiResult.Success();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment