Commit d3ef1d69 authored by liudong1993's avatar liudong1993

主项目 移除aspose引用

parent ceb29aa4
...@@ -15,9 +15,6 @@ ...@@ -15,9 +15,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Aspose.PDF" Version="20.9.0" />
<PackageReference Include="Aspose.Slides.NET" Version="20.8.0" />
<PackageReference Include="Aspose.Words" Version="20.9.0" />
<PackageReference Include="BarcodeLib" Version="2.2.5" /> <PackageReference Include="BarcodeLib" Version="2.2.5" />
<PackageReference Include="CoreHtmlToImage" Version="1.0.6" /> <PackageReference Include="CoreHtmlToImage" Version="1.0.6" />
<PackageReference Include="LumenWorks.Framework.IO.Core" Version="1.0.1" /> <PackageReference Include="LumenWorks.Framework.IO.Core" Version="1.0.1" />
......
This diff is collapsed.
This diff is collapsed.
...@@ -19,22 +19,26 @@ namespace Mall.Education.Helper ...@@ -19,22 +19,26 @@ namespace Mall.Education.Helper
{ {
/// <summary> /// <summary>
/// 插入图片 /// 插入课程图片记录
/// </summary> /// </summary>
/// <param name="cookie"></param> /// <param name="cookie"></param>
public static void InsertGoodsFileImage() public static int InsertGoodsFileImage(int CourseId, string goodsImages)
{ {
string citySql = $@"SELECT * FROM rb_destination WHERE 1=1 and Status =0 AND Name in('成都市') "; string sql = $@"update rb_goods_course set Image='{goodsImages}' where Id ={CourseId} ";
var cityDataList = MySqlHelper.ExecuteDataset(MySqlHelper.defaultConnection, System.Data.CommandType.Text, citySql, null); var result = MySqlHelper.ExecuteNonQuery(MySqlHelper.defaultConnection, System.Data.CommandType.Text, sql, null);
LogHelper.Write(JsonConvert.SerializeObject(cityDataList.Tables[0].Rows)); return result;
//var sqlOrderDetailResult = MySqlHelper.ExecuteNonQuery(MySqlHelper.defaultConnection, System.Data.CommandType.Text, sqlOrderDetail, null);
} }
/// <summary> /// <summary>
/// 上传图片至阿里云/腾讯云 /// 删除课程图片记录
/// </summary> /// </summary>
public static void UpLoadImage() { /// <param name="cookie"></param>
public static void DelGoodsFileImage()
{
string citySql = $@"SELECT * FROM rb_destination WHERE 1=1 and Status =0 AND Name in('成都市') ";
var cityDataList = MySqlHelper.ExecuteDataset(MySqlHelper.defaultConnection, System.Data.CommandType.Text, citySql, null);
LogHelper.Write(JsonConvert.SerializeObject(cityDataList.Tables[0].Rows));
//var sqlOrderDetailResult = MySqlHelper.ExecuteNonQuery(MySqlHelper.defaultConnection, System.Data.CommandType.Text, sqlOrderDetail, null);
} }
/// <summary> /// <summary>
......
...@@ -25,4 +25,19 @@ namespace Mall.Education.Models ...@@ -25,4 +25,19 @@ namespace Mall.Education.Models
public string FilePath { get; set; } public string FilePath { get; set; }
} }
/// <summary>
/// 课程图片
/// </summary>
public class GoodsImage
{
/// <summary>
/// 排序
/// </summary>
public int Sort { get; set; }
/// <summary>
/// 路径
/// </summary>
public string Path { get; set; }
}
} }
...@@ -5,6 +5,10 @@ using Mall.Education.RabbitMQ; ...@@ -5,6 +5,10 @@ using Mall.Education.RabbitMQ;
using System; using System;
using System.ServiceProcess; using System.ServiceProcess;
using COSSnippet; using COSSnippet;
using Mall.Education.Offices;
using System.IO;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Mall.Education namespace Mall.Education
{ {
...@@ -31,16 +35,80 @@ namespace Mall.Education ...@@ -31,16 +35,80 @@ namespace Mall.Education
//new OfficeHelper().GetWordToImagePathList("C:/Users/Administrator/Desktop/testImage/网课需求(1).docx", "C:/Users/Administrator/Desktop/testImage/Image/", null); //new OfficeHelper().GetWordToImagePathList("C:/Users/Administrator/Desktop/testImage/网课需求(1).docx", "C:/Users/Administrator/Desktop/testImage/Image/", null);
//new Word2ImageConverter().ConvertToImage("C:/Users/Administrator/Desktop/testImage/网课需求(1).docx", "C:/Users/Administrator/Desktop/testImage/Image/");
//new Word2ImageConverter().ConvertToImage("https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Education/wkxq.docx", "C:/Users/Administrator/Desktop/testImage/Image/", System.Drawing.Imaging.ImageFormat.Png, out int PageNum);
//new Pdf2ImageConverter().ConvertToImage("C:/Users/Administrator/Desktop/testImage/MA10048W_zh.pdf", "C:/Users/Administrator/Desktop/testImage/PdfImage/"); //new Pdf2ImageConverter().ConvertToImage("C:/Users/Administrator/Desktop/testImage/MA10048W_zh.pdf", "C:/Users/Administrator/Desktop/testImage/PdfImage/");
//new Ppt2ImageConverter().ConvertToImage("C:/Users/Administrator/Desktop/testImage/kjljlkjk.ppt", "C:/Users/Administrator/Desktop/testImage/PptImage/"); //new Ppt2ImageConverter().ConvertToImage("C:/Users/Administrator/Desktop/testImage/kjljlkjk.ppt", "C:/Users/Administrator/Desktop/testImage/PptImage/");
//FileDataHelper.InsertGoodsFileImage(); //FileDataHelper.InsertGoodsFileImage();
TransferUploadObjectModel m = new TransferUploadObjectModel(); //TransferUploadObjectModel m = new TransferUploadObjectModel();
m.TransferUploadFile("C:/Users/Administrator/Desktop/testImage/Image/网课需求(1)_001.Png", "网课需求(1)_001.Png"); //m.TransferUploadFile("C:/Users/Administrator/Desktop/testImage/Image/网课需求(1)_001.Png", "网课需求(1)_001.Png");
ImageConvertData(new GoodsModel() { CourseId = 1, GoodsId = 1, FilePath = "" });
Console.ReadKey(); Console.ReadKey();
} }
/// <summary>
/// 处理文件
/// </summary>
/// <param name="GoodsModel"></param>
private static void ImageConvertData(GoodsModel GoodsModel)
{
string tempDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tempfile/Image");
if (!Directory.Exists(tempDir))
Directory.CreateDirectory(tempDir);
//是否需要先把文件下载到服务器
GoodsModel.FilePath = "https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Education/wkxq.docx";
//文件生成图片暂存本地
string FileExtension = Path.GetExtension(GoodsModel.FilePath);
string FileName = Path.GetFileNameWithoutExtension(GoodsModel.FilePath);
string FileDirectory = Path.GetDirectoryName(GoodsModel.FilePath);
int PageNum;
System.Drawing.Imaging.ImageFormat imageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
if (FileExtension == ".doc" || FileExtension == ".docx")
{
new Word2ImageConverter().ConvertToImage(GoodsModel.FilePath, tempDir + "/", imageFormat, out PageNum);
}
else if (FileExtension == ".pdf")
{
new Pdf2ImageConverter().ConvertToImage(GoodsModel.FilePath, tempDir + "/", imageFormat, out PageNum);
}
else if (FileExtension == ".ppt" || FileExtension == ".pptx")
{
new Ppt2ImageConverter().ConvertToImage(GoodsModel.FilePath, tempDir + "/", imageFormat, out PageNum);
}
else
{
return;
}
if (PageNum > 0)
{
List<GoodsImage> goodsImages = new List<GoodsImage>();
//开始上传图片至服务器
TransferUploadObjectModel m = new TransferUploadObjectModel();
for (var i = 1; i <= PageNum; i++)
{
string newName = FileName + "_" + i.ToString("000") + "." + imageFormat.ToString();
m.TransferUploadFile(tempDir + "/" + newName, newName);
//上传之后 写入商品课程图片数据
goodsImages.Add(new GoodsImage
{
Sort = i,
Path = FileDirectory + "/" + newName
});
}
//更新图片数据
bool flag = FileDataHelper.InsertGoodsFileImage(GoodsModel.CourseId, JsonConvert.SerializeObject(goodsImages)) > 0;
if (flag == false)
{
Console.WriteLine("更新课程图片列表失败:CourseId:" + GoodsModel.CourseId);
}
}
}
} }
} }
...@@ -33,10 +33,10 @@ namespace Mall.Education.Offices ...@@ -33,10 +33,10 @@ namespace Mall.Education.Offices
this.cancelled = true; this.cancelled = true;
} }
public void ConvertToImage(string originFilePath, string imageOutputDirPath) public void ConvertToImage(string originFilePath, string imageOutputDirPath, ImageFormat imageFormat, out int PageNum)
{ {
this.cancelled = false; this.cancelled = false;
ConvertToImage(originFilePath, imageOutputDirPath, 0, 0, null, 200); ConvertToImage(originFilePath, imageOutputDirPath, 0, 0, imageFormat, 200, out PageNum);
} }
/// <summary> /// <summary>
...@@ -48,8 +48,9 @@ namespace Mall.Education.Offices ...@@ -48,8 +48,9 @@ namespace Mall.Education.Offices
/// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param> /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
/// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param> /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
/// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param> /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
private void ConvertToImage(string wordInputPath, string imageOutputDirPath, int startPageNum, int endPageNum, ImageFormat imageFormat, int resolution) private void ConvertToImage(string wordInputPath, string imageOutputDirPath, int startPageNum, int endPageNum, ImageFormat imageFormat, int resolution,out int PageNum)
{ {
PageNum = 0;
try try
{ {
Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath); Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
...@@ -83,7 +84,7 @@ namespace Mall.Education.Offices ...@@ -83,7 +84,7 @@ namespace Mall.Education.Offices
{ {
int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum;
} }
PageNum = endPageNum;
if (imageFormat == null) if (imageFormat == null)
{ {
imageFormat = ImageFormat.Png; imageFormat = ImageFormat.Png;
...@@ -146,10 +147,10 @@ namespace Mall.Education.Offices ...@@ -146,10 +147,10 @@ namespace Mall.Education.Offices
this.cancelled = true; this.cancelled = true;
} }
public void ConvertToImage(string originFilePath, string imageOutputDirPath) public void ConvertToImage(string originFilePath, string imageOutputDirPath, ImageFormat imageFormat, out int PageNum)
{ {
this.cancelled = false; this.cancelled = false;
ConvertToImage(originFilePath, imageOutputDirPath, 0, 0, 200); ConvertToImage(originFilePath, imageOutputDirPath, 0, 0, imageFormat, 200, out PageNum);
} }
/// <summary> /// <summary>
...@@ -160,8 +161,9 @@ namespace Mall.Education.Offices ...@@ -160,8 +161,9 @@ namespace Mall.Education.Offices
/// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param> /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
/// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为pdf总页数</param> /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为pdf总页数</param>
/// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param> /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
private void ConvertToImage(string originFilePath, string imageOutputDirPath, int startPageNum, int endPageNum, int resolution) private void ConvertToImage(string originFilePath, string imageOutputDirPath, int startPageNum, int endPageNum, ImageFormat imageFormat, int resolution, out int PageNum)
{ {
PageNum = 0;
try try
{ {
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(originFilePath); Aspose.Pdf.Document doc = new Aspose.Pdf.Document(originFilePath);
...@@ -194,7 +196,7 @@ namespace Mall.Education.Offices ...@@ -194,7 +196,7 @@ namespace Mall.Education.Offices
{ {
int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum;
} }
PageNum = endPageNum;
if (resolution <= 0) if (resolution <= 0)
{ {
resolution = 128; resolution = 128;
...@@ -209,14 +211,14 @@ namespace Mall.Education.Offices ...@@ -209,14 +211,14 @@ namespace Mall.Education.Offices
} }
MemoryStream stream = new MemoryStream(); MemoryStream stream = new MemoryStream();
string imgPath = Path.Combine(imageOutputDirPath, imageNamePrefix) + "_" + i.ToString("000") + ".jpg"; string imgPath = Path.Combine(imageOutputDirPath, imageNamePrefix) + "_" + i.ToString("000") + imageFormat.ToString();
Aspose.Pdf.Devices.Resolution reso = new Aspose.Pdf.Devices.Resolution(resolution); Aspose.Pdf.Devices.Resolution reso = new Aspose.Pdf.Devices.Resolution(resolution);
Aspose.Pdf.Devices.JpegDevice jpegDevice = new Aspose.Pdf.Devices.JpegDevice(reso, 100); Aspose.Pdf.Devices.JpegDevice jpegDevice = new Aspose.Pdf.Devices.JpegDevice(reso, 100);
jpegDevice.Process(doc.Pages[i], stream); jpegDevice.Process(doc.Pages[i], stream);
Image img = Image.FromStream(stream); Image img = Image.FromStream(stream);
Bitmap bm = (Bitmap)img; Bitmap bm = (Bitmap)img;
bm.Save(imgPath, ImageFormat.Jpeg); bm.Save(imgPath, imageFormat);
img.Dispose(); img.Dispose();
stream.Dispose(); stream.Dispose();
bm.Dispose(); bm.Dispose();
...@@ -251,9 +253,9 @@ namespace Mall.Education.Offices ...@@ -251,9 +253,9 @@ namespace Mall.Education.Offices
} }
} }
public void ConvertToImage(string originFilePath, string imageOutputDirPath) public void ConvertToImage(string originFilePath, string imageOutputDirPath, ImageFormat imageFormat, out int PageNum)
{ {
ConvertToImage(originFilePath, imageOutputDirPath, 0, 0, 200); ConvertToImage(originFilePath, imageOutputDirPath, 0, 0, 200, imageFormat, out PageNum);
} }
/// <summary> /// <summary>
...@@ -264,8 +266,9 @@ namespace Mall.Education.Offices ...@@ -264,8 +266,9 @@ namespace Mall.Education.Offices
/// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param> /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
/// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为pdf总页数</param> /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为pdf总页数</param>
/// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param> /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
private void ConvertToImage(string originFilePath, string imageOutputDirPath, int startPageNum, int endPageNum, int resolution) private void ConvertToImage(string originFilePath, string imageOutputDirPath, int startPageNum, int endPageNum, int resolution, ImageFormat imageFormat, out int PageNum)
{ {
PageNum = 0;
try try
{ {
Aspose.Slides.Presentation doc = new Aspose.Slides.Presentation(originFilePath); Aspose.Slides.Presentation doc = new Aspose.Slides.Presentation(originFilePath);
...@@ -285,21 +288,6 @@ namespace Mall.Education.Offices ...@@ -285,21 +288,6 @@ namespace Mall.Education.Offices
Directory.CreateDirectory(imageOutputDirPath); Directory.CreateDirectory(imageOutputDirPath);
} }
if (startPageNum <= 0)
{
startPageNum = 1;
}
if (endPageNum > doc.Slides.Count || endPageNum <= 0)
{
endPageNum = doc.Slides.Count;
}
if (startPageNum > endPageNum)
{
int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum;
}
if (resolution <= 0) if (resolution <= 0)
{ {
resolution = 128; resolution = 128;
...@@ -311,7 +299,7 @@ namespace Mall.Education.Offices ...@@ -311,7 +299,7 @@ namespace Mall.Education.Offices
//再将pdf转换为图片 //再将pdf转换为图片
Pdf2ImageConverter converter = new Pdf2ImageConverter(); Pdf2ImageConverter converter = new Pdf2ImageConverter();
converter.ConvertToImage(tmpPdfPath, imageOutputDirPath); converter.ConvertToImage(tmpPdfPath, imageOutputDirPath, imageFormat, out PageNum);
//删除pdf临时文件 //删除pdf临时文件
File.Delete(tmpPdfPath); File.Delete(tmpPdfPath);
......
...@@ -4,6 +4,11 @@ using RabbitMQ.Client.Events; ...@@ -4,6 +4,11 @@ using RabbitMQ.Client.Events;
using System; using System;
using System.Text; using System.Text;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.IO;
using Mall.Education.Offices;
using COSSnippet;
using Mall.Education.Helper;
using System.Collections.Generic;
namespace Mall.Education.RabbitMQ namespace Mall.Education.RabbitMQ
{ {
...@@ -30,61 +35,6 @@ namespace Mall.Education.RabbitMQ ...@@ -30,61 +35,6 @@ namespace Mall.Education.RabbitMQ
return factory; return factory;
} }
///// <summary>
///// 消费消息
///// </summary>
///// <param name="rabbitConfig"></param>
//public static void DealWithMessage(RabbitConfig rabbitConfig)
//{
// using (IConnection conn = GetConnectionFactory(rabbitConfig).CreateConnection())
// {
// using (IModel channel = conn.CreateModel())
// {
// //在MQ上定义一个持久化队列,如果名称相同不会重复创建
// //channel.QueueDeclare(rabbitConfig.QueenName, true, false, false, null);
// //输入1,那如果接收一个消息,但是没有应答,则客户端不会收到下一个消息
// //channel.BasicQos(0, 1, false);
// channel.QueueDeclare(rabbitConfig.QueenName, false, false, false, null);
// var consumer = new EventingBasicConsumer(channel);//消费者
// channel.BasicConsume(rabbitConfig.QueenName, true, consumer);//消费消息
// Console.WriteLine("开始");
// consumer.Received += (model, ea) =>
// {
// //var body = ea.Body;
// Console.WriteLine("123");
// };
// Console.WriteLine("结束");
// //在队列上定义一个消费者
// //EventingBasicConsumer consumer = new EventingBasicConsumer(channel);
// ////消费队列,并设置应答模式为程序主动应答
// //channel.BasicConsume(rabbitConfig.QueenName, true, consumer);
// //consumer.Received += (sender, e) =>
// //{
// // Console.WriteLine("123");
// // //byte[] bytes = e.Body.ToArray();
// // //string message = Encoding.UTF8.GetString(bytes);
// // //try
// // //{
// // // Console.WriteLine(message);
// // // //序列化 操作数据
// // // //var msgModel = JsonConvert.DeserializeObject<FeaturesMQ>(message);
// // //}
// // //catch (Exception)
// // //{
// // // throw;
// // //}
// // //channel.BasicAck(e.DeliveryTag, false);
// //};
// }
// }
//}
[Obsolete] [Obsolete]
public static void DealWithMessage(RabbitConfig rabbitConfig) public static void DealWithMessage(RabbitConfig rabbitConfig)
{ {
...@@ -111,7 +61,11 @@ namespace Mall.Education.RabbitMQ ...@@ -111,7 +61,11 @@ namespace Mall.Education.RabbitMQ
{ {
var GoodsModel = JsonConvert.DeserializeObject<GoodsModel>(msg); var GoodsModel = JsonConvert.DeserializeObject<GoodsModel>(msg);
//处理 //处理
Console.WriteLine(msg); if (GoodsModel != null)
{
ImageConvertData(GoodsModel);
}
//Console.WriteLine(msg);
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -123,5 +77,64 @@ namespace Mall.Education.RabbitMQ ...@@ -123,5 +77,64 @@ namespace Mall.Education.RabbitMQ
} }
} }
} }
/// <summary>
/// 处理文件
/// </summary>
/// <param name="GoodsModel"></param>
private static void ImageConvertData(GoodsModel GoodsModel)
{
string tempDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tempfile/Image");
if (!Directory.Exists(tempDir))
Directory.CreateDirectory(tempDir);
//是否需要先把文件下载到服务器
GoodsModel.FilePath = "https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Education/wkxq.docx";
//文件生成图片暂存本地
string FileExtension = Path.GetExtension(GoodsModel.FilePath);
string FileName = Path.GetFileNameWithoutExtension(GoodsModel.FilePath);
string FileDirectory = Path.GetDirectoryName(GoodsModel.FilePath);
int PageNum;
System.Drawing.Imaging.ImageFormat imageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
if (FileExtension == ".doc" || FileExtension == ".docx")
{
new Word2ImageConverter().ConvertToImage(GoodsModel.FilePath, tempDir + "/", imageFormat, out PageNum);
}
else if (FileExtension == ".pdf")
{
new Pdf2ImageConverter().ConvertToImage(GoodsModel.FilePath, tempDir + "/", imageFormat, out PageNum);
}
else if (FileExtension == ".ppt" || FileExtension == ".pptx")
{
new Ppt2ImageConverter().ConvertToImage(GoodsModel.FilePath, tempDir + "/", imageFormat, out PageNum);
}
else {
return;
}
if (PageNum > 0)
{
List<GoodsImage> goodsImages = new List<GoodsImage>();
//开始上传图片至服务器
TransferUploadObjectModel m = new TransferUploadObjectModel();
for (var i = 1; i <= PageNum; i++)
{
string newName = FileName + "_" + i.ToString("000") + "." + imageFormat.ToString();
m.TransferUploadFile(tempDir + "/" + newName, newName);
//上传之后 写入商品课程图片数据
goodsImages.Add(new GoodsImage
{
Sort = i,
Path = FileDirectory + "/" + newName
});
}
//更新图片数据
bool flag = FileDataHelper.InsertGoodsFileImage(GoodsModel.CourseId, JsonConvert.SerializeObject(goodsImages)) > 0;
if (flag == false) {
Console.WriteLine("更新课程图片列表失败:CourseId:" + GoodsModel.CourseId);
}
}
}
} }
} }
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