Commit d2fa0358 authored by 黄奎's avatar 黄奎

页面修改

parent 681c3e39
......@@ -35,7 +35,7 @@ namespace Edu.Common
}
/// <summary>
/// 格式化时间【yyyy-MM-dd HH:mm:ss
/// 格式化时间【yyyy-MM-dd】
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
......
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Net;
namespace Edu.Common.Plugin
{
/// <summary>
/// 图片转换
/// </summary>
public class ImageHelper
{
/**
* 生成图片
* string targetFile = @"F:/Test/temp/";
* ImageHelper.CreateImage("F:/Test/1.docx", targetFile);
* ImageHelper.CreateImage("F:/Test/2.pdf", targetFile);
* ImageHelper.CreateImage("F:/Test/3.ppt", targetFile);
* ImageHelper.CreateImage("F:/Test/4.xls", targetFile);
*/
public static List<string> CreateImage(string sourceFile, string targetFile)
{
IImageHelper imageHelper = null;
//获取文件扩展名
string extension = Path.GetExtension(sourceFile).ToLower();
switch (extension)
{
case ".doc":
imageHelper = new WordToImage();
break;
case ".docx":
imageHelper = new WordToImage();
break;
case ".ppt":
imageHelper = new PptToImage();
break;
case ".pptx":
imageHelper = new PptToImage();
break;
case ".pdf":
imageHelper = new PdfToImage();
break;
case ".xls":
imageHelper = new ExcelToImage();
break;
case ".xlsx":
imageHelper = new ExcelToImage();
break;
}
return imageHelper.CreateImage(sourceFile, targetFile);
}
/// <summary>
/// 生成图片
/// </summary>
/// <param name="url"></param>
public static void CreateImage(string url)
{
string tempPath =Common.Config.GetFileUrl(url);
string path = Environment.CurrentDirectory + tempPath;//下载到的地址+文件名
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
//发送请求并获取相应回应数据
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才开始向目标网页发送Post请求
Stream responseStream = response.GetResponseStream();
string newFilePath = path.Substring(0, path.LastIndexOf("/"));
if (!System.IO.Directory.Exists(newFilePath))//如果不存在就创建file文件夹
{
System.IO.Directory.CreateDirectory(newFilePath);
}
//创建本地文件写入流
Stream stream = new FileStream(path, FileMode.Create);
byte[] bArr = new byte[1024];
int size = responseStream.Read(bArr, 0, (int)bArr.Length);
while (size > 0)
{
stream.Write(bArr, 0, size);
size = responseStream.Read(bArr, 0, (int)bArr.Length);
}
stream.Close();
responseStream.Close();
}
}
/// <summary>
/// 生成图片接口
/// </summary>
interface IImageHelper
{
/// <summary>
/// 生成图片方法
/// </summary>
/// <param name="sourceFile">源文件地址</param>
/// <param name="targetFile">目标文件路径</param>
/// <param name="prefix">生成文件前缀</param>
/// <returns></returns>
List<string> CreateImage(string sourceFile, string targetFile, string prefix = "");
}
/// <summary>
/// Excel转图片
/// </summary>
class ExcelToImage : IImageHelper
{
/// <summary>
/// 生成图片地址
/// </summary>
/// <param name="sourceFile">源文件地址</param>
/// <param name="targetFile">目标文件路径</param>
/// <param name="prefix">生成文件前缀</param>
/// <returns></returns>
public List<string> CreateImage(string sourceFile, string targetFile, string prefix = "")
{
List<string> list = new List<string>();
try
{
Spire.Xls.Workbook xls = new Spire.Xls.Workbook();
xls.LoadFromFile(sourceFile, Spire.Xls.ExcelVersion.Version97to2003);
string tempPdf = targetFile + "xls_temp_" + DateTime.Now.Ticks + ".pdf";
xls.SaveToFile(tempPdf, Spire.Xls.FileFormat.PDF);
list = new PdfToImage().CreateImage(tempPdf, targetFile, prefix: "xls_");
File.Delete(tempPdf);
}
catch (Exception ex)
{
Common.Plugin.LogHelper.Write(ex, "WordToImage");
}
return list;
}
}
/// <summary>
/// Word转图片
/// </summary>
class WordToImage : IImageHelper
{
/// <summary>
/// 生成图片地址
/// </summary>
/// <param name="sourceFile">源文件地址</param>
/// <param name="targetFile">目标文件路径</param>
/// <param name="prefix">生成文件前缀</param>
/// <returns></returns>
public List<string> CreateImage(string sourceFile, string targetFile, string prefix = "")
{
List<string> list = new List<string>();
try
{
Aspose.Words.Document doc = new Aspose.Words.Document(sourceFile);
Aspose.Words.Saving.ImageSaveOptions iso = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Png)
{
Resolution = 128,
PrettyFormat = true,
UseAntiAliasing = true
};
for (int i = 0; i < doc.PageCount; i++)
{
iso.PageIndex = i;
string newFilePath = targetFile + "doc_" + i + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".png";
list.Add(newFilePath);
doc.Save(newFilePath, iso);
}
}
catch (Exception ex)
{
Common.Plugin.LogHelper.Write(ex, "WordToImage");
}
return list;
}
}
/// <summary>
/// Pdf转图片
/// </summary>
class PdfToImage : IImageHelper
{
/// <summary>
/// 生成图片地址
/// </summary>
/// <param name="sourceFile">源文件地址</param>
/// <param name="targetFile">目标文件路径</param>
/// <param name="prefix">生成文件前缀</param>
/// <returns></returns>
public List<string> CreateImage(string sourceFile, string targetFile, string prefix = "")
{
List<string> list = new List<string>();
string license = AppContext.BaseDirectory + @"ExtPlug\Aspose.Total.lic";
try
{
//加载证书
Aspose.Pdf.License license2 = new Aspose.Pdf.License();
license2.SetLicense(license);
Aspose.Pdf.Document document = new Aspose.Pdf.Document(sourceFile);
var device = new Aspose.Pdf.Devices.PngDevice();
//遍历每一页转为PNG
for (var i = 1; i <= document.Pages.Count; i++)
{
string filePathOutPut = targetFile + (!string.IsNullOrWhiteSpace(prefix) ? prefix : "pdf_") + i + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".png";
FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
try
{
device.Process(document.Pages[i], fs);
fs.Close();
list.Add(filePathOutPut);
}
catch (Exception ex)
{
Common.Plugin.LogHelper.Write(ex, "PdfToImage1");
fs.Close();
}
}
}
catch (Exception ex)
{
Common.Plugin.LogHelper.Write(ex, "PdfToImage");
}
return list;
}
}
/// <summary>
/// ppt转图片
/// </summary>
class PptToImage : IImageHelper
{
/// <summary>
/// 生成图片地址
/// </summary>
/// <param name="sourceFile">源文件地址</param>
/// <param name="targetFile">目标文件路径</param>
/// <param name="prefix">生成文件前缀</param>
/// <returns></returns>
public List<string> CreateImage(string sourceFile, string targetFile, string prefix = "")
{
List<string> list = new List<string>();
try
{
Spire.Presentation.Presentation ppt = new Spire.Presentation.Presentation();
ppt.LoadFromFile(sourceFile);
//遍历幻灯片
for (int i = 0; i < ppt.Slides.Count; i++)
{
string newFilePath = string.Format(targetFile + "ppt_" + i + "_" + @"{0}.png", DateTime.Now.ToString("yyyyMMddHHmmssfff"));
//保存为PNG图片
Image image = ppt.Slides[i].SaveAsImage();
image.Save(newFilePath, ImageFormat.Png);
list.Add(newFilePath);
}
ppt.Dispose();
}
catch (Exception ex)
{
Common.Plugin.LogHelper.Write(ex, "PptToImage");
}
return list;
}
}
}
\ No newline at end of file
......@@ -95,5 +95,10 @@ namespace Edu.Model.Entity.Course
/// 集团编号
/// </summary>
public int Group_Id { get; set; }
/// <summary>
/// 排序
/// </summary>
public int SortNum { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Edu.Model.ViewModel.Course
{
public class ChapterTree_ViewModel
{
/// <summary>
/// 主键(章节编号)
/// </summary>
public int ChapterId { get; set; }
/// <summary>
/// 课程Id
/// </summary>
public int CourseId { get; set; }
/// <summary>
/// 章节编号
/// </summary>
public string ChapterNo { get; set; }
/// <summary>
/// 章节名称
/// </summary>
public string ChapterName { get; set; }
/// <summary>
/// 章节内容
/// </summary>
public string ChapterContent { get; set; }
/// <summary>
/// 父节点编号
/// </summary>
public int ParentId { get; set; }
/// <summary>
/// 下级列表
/// </summary>
public List<ChapterTree_ViewModel> ChildList { get; set; }
}
}
......@@ -12,5 +12,25 @@ namespace Edu.Model.ViewModel.Course
/// 课程编号【逗号分隔】
/// </summary>
public string CourseIds { get; set; }
/// <summary>
/// 创建人
/// </summary>
public string CreateByName { get; set; }
/// <summary>
/// 更新人
/// </summary>
public string UpdateByName { get; set; }
/// <summary>
/// 创建时间字符串
/// </summary>
public string CreateTimeStr { get { return Common.ConvertHelper.FormatTime(this.CreateTime); } }
/// <summary>
/// 更新时间
/// </summary>
public string UpdateTimeStr { get { return Common.ConvertHelper.FormatTime(this.UpdateTime); } }
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
using Edu.Model.ViewModel.Course;
using Edu.Repository.Course;
using System.Collections.Generic;
using System.Linq;
using VT.FW.DB;
namespace Edu.Module.Course
......@@ -247,6 +248,7 @@ namespace Edu.Module.Course
#region 课程章节管理
/// <summary>
/// 获取课程章节列表
/// </summary>
......@@ -257,6 +259,51 @@ namespace Edu.Module.Course
return chapterRepository.GetChapterListRepository(query);
}
/// <summary>
/// 获取课程章节树形列表
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public List<ChapterTree_ViewModel> GetChapterTreeListModule(RB_Course_Chapter_ViewModel query)
{
var list = GetChapterListModule(query);
List<ChapterTree_ViewModel> treeList = GetChapterChild(list, 0);
return treeList;
}
/// <summary>
/// 递归遍历所有章节
/// </summary>
/// <param name="sourceList">源数据</param>
/// <param name="parentId">父节点编号</param>
/// <returns></returns>
public List<ChapterTree_ViewModel> GetChapterChild(List<RB_Course_Chapter_ViewModel> sourceList,int parentId)
{
List<ChapterTree_ViewModel> resultList = new List<ChapterTree_ViewModel>();
//获取下级节点
var subList = sourceList?.Where(qItem => qItem.ParentId==parentId).OrderBy(qitem=>qitem.SortNum).ToList();
//如果存在下级节点
if (subList != null&& subList.Count>0)
{
foreach (var childItem in subList)
{
var childModel = new ChapterTree_ViewModel()
{
ChapterId = childItem.ChapterId,
ParentId = childItem.ParentId,
ChapterContent = childItem.ChapterContent,
ChapterName = childItem.ChapterName,
ChapterNo = childItem.ChapterNo,
CourseId = childItem.CourseId,
ChildList = new List<ChapterTree_ViewModel>()
};
childModel.ChildList.AddRange(GetChapterChild(sourceList, childItem.ChapterId));
resultList.Add(childModel);
}
}
return resultList;
}
/// <summary>
/// 新增修改课程章节
/// </summary>
......@@ -301,6 +348,7 @@ namespace Edu.Module.Course
/// <returns></returns>
public bool RemoveChapterModule(object ChapterId)
{
Dictionary<string, object> fileds = new Dictionary<string, object>()
{
{nameof(RB_Course_Chapter_ViewModel.Status) ,(int)DateStateEnum.Delete},
......
......@@ -26,6 +26,8 @@ SELECT *
FROM rb_course_chapter
WHERE 1=1
");
builder.AppendFormat(" AND {0}={1} ", nameof(RB_Course_Chapter_ViewModel.Group_Id), query.Group_Id);
builder.AppendFormat(" AND {0}={1} ", nameof(RB_Course_Chapter_ViewModel.School_Id), query.School_Id);
if (query != null)
{
if (query.CourseId > 0)
......
......@@ -330,7 +330,7 @@ namespace Edu.WebApi.Controllers.Course
#endregion
#region 课程章节管理
/// <summary>
/// 添加修改课程章节
/// </summary>
......@@ -363,7 +363,115 @@ namespace Edu.WebApi.Controllers.Course
return ApiResult.Success(data: list);
}
/// <summary>
/// 获取章节树形列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetChapterTree()
{
var query = Common.Plugin.JsonHelper.DeserializeObject<RB_Course_Chapter_ViewModel>(RequestParm.Msg.ToString());
query.Group_Id = base.UserInfo.Group_Id;
query.School_Id = base.UserInfo.School_Id;
var list = courseModule.GetChapterTreeListModule(query);
return ApiResult.Success(data: list);
}
/// <summary>
/// 删除课程章节
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult RemoveChapter()
{
var ChapterId = base.ParmJObj.GetInt("ChapterId", 0);
var flag = courseModule.RemoveChapterModule(ChapterId);
return flag ? ApiResult.Success() : ApiResult.Failed();
}
/// <summary>
/// 获取课程章节详情
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetChapter()
{
var ChapterId = base.ParmJObj.GetInt("ChapterId", 0);
var extModel = courseModule.GetChapterModule(ChapterId);
return ApiResult.Success(data: extModel);
}
#endregion
#region 课程通知管理
/// <summary>
/// 获取课程通知分页列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetNoticePageList()
{
var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
var query = Common.Plugin.JsonHelper.DeserializeObject<RB_Course_Notice_ViewModel>(RequestParm.Msg.ToString());
query.Group_Id = base.UserInfo.Group_Id;
query.School_Id = base.UserInfo.School_Id;
var list = courseModule.GetNoticePageListModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
foreach (var item in list)
{
if (item.CreateBy > 0)
{
item.CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
}
if (item.UpdateBy > 0)
{
item.UpdateByName = UserReidsCache.GetUserLoginInfo(item.UpdateBy)?.AccountName ?? "";
}
}
pageModel.Count = rowsCount;
pageModel.PageData = list;
return ApiResult.Success(data: pageModel);
}
/// <summary>
/// 添加修改课程通知
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetNotice()
{
var extModel = Common.Plugin.JsonHelper.DeserializeObject<RB_Course_Notice_ViewModel>(RequestParm.Msg.ToString());
extModel.CreateTime = DateTime.Now;
extModel.CreateBy = base.UserInfo.Id;
extModel.UpdateBy = base.UserInfo.Id;
extModel.UpdateTime = DateTime.Now;
extModel.Group_Id = this.UserInfo.Group_Id;
extModel.School_Id = this.UserInfo.School_Id;
bool flag = courseModule.SetNoticeModule(extModel);
return flag ? ApiResult.Success() : ApiResult.Failed();
}
/// <summary>
/// 获取课程通知
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetNotice()
{
var NoticeId = base.ParmJObj.GetInt("NoticeId", 0);
var extModel = courseModule.GetNoticeModule(NoticeId);
return ApiResult.Success(data: extModel);
}
/// <summary>
/// 删除课程通知
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult RemoveNotice()
{
var NoticeId = base.ParmJObj.GetInt("NoticeId", 0);
var flag = courseModule.RemoveNoticeModule(NoticeId);
return flag ? ApiResult.Success() : ApiResult.Failed();
}
#endregion
}
}
......@@ -28,10 +28,5 @@
<ProjectReference Include="..\Edu.Module.User\Edu.Module.User.csproj" />
<ProjectReference Include="..\Edu.Repository\Edu.Repository.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="ExtPlug\Aspose.Total.lic">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
<?xml version="1.0" encoding="utf-8" ?>
<License>
<Data>
<LicensedTo>Aspose Scotland Team</LicensedTo>
<EmailTo>billy.lundie@aspose.com</EmailTo>
<LicenseType>Developer OEM</LicenseType>
<LicenseNote>Limited to 1 developer, unlimited physical locations</LicenseNote>
<OrderID>140408052324</OrderID>
<UserID>94236</UserID>
<OEM>This is a redistributable license</OEM>
<Products>
<Product>Aspose.Total for .NET</Product>
</Products>
<EditionType>Enterprise</EditionType>
<SerialNumber>9a59547c-41f0-428b-ba72-7c4368f151d7</SerialNumber>
<SubscriptionExpiry>20151231</SubscriptionExpiry>
<LicenseVersion>3.0</LicenseVersion>
<LicenseInstructions>http://www.aspose.com/corporate/purchase/license-instructions.aspx</LicenseInstructions>
</Data>
<Signature>FO3PHsblgDt8F59sMT1l1amyi9qk2V6E8dQkIP7LdTJSxDibNEFu1zOinQbqFfKv/ruttvcxoROkc1tUe0DtO6cP1Zf6J0VemgSY8i/LZECTGszRqJVQRZ0MoVnBhuPAJk5eli7fhVcF8hWd3E4XQ3LzfmJCuaj2NEteRi5Hrfg=</Signature>
</License>
\ No newline at end of file
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