|
@@ -16,6 +16,7 @@ using TEAMModelOS.Model.Core.Models;
|
|
|
using TEAMModelOS.Model.Evaluation.Dtos.Own;
|
|
|
using TEAMModelOS.Model.Evaluation.Models;
|
|
|
using TEAMModelOS.SDK.Context.Configuration;
|
|
|
+using TEAMModelOS.SDK.Context.Constant;
|
|
|
using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
|
|
|
using TEAMModelOS.SDK.Extension.SnowFlake;
|
|
|
using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
|
|
@@ -25,7 +26,9 @@ using TEAMModelOS.SDK.Helper.Common.StringHelper;
|
|
|
using TEAMModelOS.SDK.Helper.Network.HttpHelper;
|
|
|
using TEAMModelOS.SDK.Helper.Security.ShaHash;
|
|
|
using TEAMModelOS.SDK.Module.AzureBlob.Container;
|
|
|
+using TEAMModelOS.SDK.Module.AzureBlob.Implements;
|
|
|
using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
|
|
|
+using TEAMModelOS.SDK.Module.AzureTable.Interfaces;
|
|
|
using TEAMModelOS.SDK.Module.PowerPointX;
|
|
|
using TEAMModelOS.SDK.Module.PowerPointX.Model;
|
|
|
using TEAMModelOS.Service.Core.Implements;
|
|
@@ -35,9 +38,27 @@ namespace TEAMModelOS.Service.Evaluation.Implements
|
|
|
{
|
|
|
public class ImportExerciseService : BaseService, IImportExerciseService
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
- public async Task<Dictionary<string, object>> UploadPPTX(IFormFile file) {
|
|
|
+ private static string SummaryTag = "【题文】";
|
|
|
+ private static string AnswerTag = "【答案】";
|
|
|
+ private static string AnalysisTag = "【解析】";
|
|
|
+ private static string EndedTag = "【结束】";
|
|
|
+ private static string Options = "ABCDEFGHIJ";
|
|
|
+ private static string CompleteStart = "【";
|
|
|
+ private static string CompleteEnd = "】";
|
|
|
+ Dictionary<string, string> TestType = new Dictionary<string, string> {
|
|
|
+ { "Single", "单选题|多选题" }, { "Multiple", "多选题|判断题" },
|
|
|
+ { "Judge", "判断题|填空题" }, { "Complete", "填空题|主观题" },
|
|
|
+ { "Subjective", "主观题|【完结】" } };
|
|
|
+ private readonly IAzureTableDBRepository azureTableDBRepository;
|
|
|
+ private readonly IHttpContextAccessor httpContextAccessor;
|
|
|
+ private readonly IAzureBlobDBRepository azureBlobDBRepository;
|
|
|
+ public ImportExerciseService(IHttpContextAccessor _httpContextAccessor, IAzureBlobDBRepository _azureBlobDBRepository)
|
|
|
+ {
|
|
|
+ azureBlobDBRepository = _azureBlobDBRepository;
|
|
|
+ httpContextAccessor = _httpContextAccessor;
|
|
|
+
|
|
|
+ }
|
|
|
+ public async Task<Dictionary<string, object>> UploadPPTX(IFormFile file) {
|
|
|
Dictionary<string, object> resdict = new Dictionary<string, object>();
|
|
|
PresentationConvert convert = new PresentationConvert();
|
|
|
PPTXInfo info= convert.LoadPresentation(file.OpenReadStream());
|
|
@@ -53,12 +74,12 @@ namespace TEAMModelOS.Service.Evaluation.Implements
|
|
|
Dictionary<string, object> dict = new Dictionary<string, object> { { "Sha1Code", shaCode } };
|
|
|
List<AzureBlobModel> models = await FindListByDict<AzureBlobModel>(dict);
|
|
|
|
|
|
- if (models.IsNotEmpty())
|
|
|
- {
|
|
|
- resdict.Add("HtmlString", HttpHelper.HttpGet(models[0].BlobUrl));
|
|
|
- resdict.Add("Sha1Code", models[0].Sha1Code);
|
|
|
- return resdict;
|
|
|
- }
|
|
|
+ //if (models.IsNotEmpty())
|
|
|
+ //{
|
|
|
+ // resdict.Add("HtmlString", HttpHelper.HttpGet(models[0].BlobUrl));
|
|
|
+ // resdict.Add("Sha1Code", models[0].Sha1Code);
|
|
|
+ // return resdict;
|
|
|
+ //}
|
|
|
|
|
|
string folder = BaseConfigModel.ContentRootPath + "/Upload/" + IdWorker.getInstance().NextId();
|
|
|
System.IO.Directory.CreateDirectory(folder);
|
|
@@ -77,12 +98,12 @@ namespace TEAMModelOS.Service.Evaluation.Implements
|
|
|
return resdict;
|
|
|
}
|
|
|
|
|
|
- public static dynamic ConvertDocxToHtml(string filePath ,string folder)
|
|
|
+ public dynamic ConvertDocxToHtml(string filePath, string folder)
|
|
|
{
|
|
|
+ string FolderName = DateTime.Now.ToString("yyyyMMdd");
|
|
|
byte[] byteArray = File.ReadAllBytes(filePath);
|
|
|
|
|
|
//byte[] bytes = new byte[stream.Length];
|
|
|
-
|
|
|
using (MemoryStream memoryStream = new MemoryStream())
|
|
|
{
|
|
|
memoryStream.Write(byteArray, 0, byteArray.Length);
|
|
@@ -91,61 +112,92 @@ namespace TEAMModelOS.Service.Evaluation.Implements
|
|
|
int imageCounter = 0;
|
|
|
WmlToHtmlConverterSettings settings = new WmlToHtmlConverterSettings()
|
|
|
{
|
|
|
- PageTitle = "My Page Title",
|
|
|
+ PageTitle = "",
|
|
|
AdditionalCss = "body { margin: 1cm auto; max-width: 20cm; padding: 0; }",
|
|
|
|
|
|
FabricateCssClasses = true,
|
|
|
CssClassPrefix = "pt-",
|
|
|
RestrictToSupportedLanguages = false,
|
|
|
RestrictToSupportedNumberingFormats = false,
|
|
|
- ImageHandler = imageInfo =>
|
|
|
+ ImageHandler = imageInfo =>
|
|
|
{
|
|
|
++imageCounter;
|
|
|
string extension = imageInfo.ContentType.Split('/')[1].ToLower();
|
|
|
ImageFormat imageFormat = null;
|
|
|
- if (extension == "png") imageFormat = ImageFormat.Png;
|
|
|
- else if (extension == "gif") imageFormat = ImageFormat.Gif;
|
|
|
- else if (extension == "bmp") imageFormat = ImageFormat.Bmp;
|
|
|
- else if (extension == "jpeg") imageFormat = ImageFormat.Jpeg;
|
|
|
- else if (extension == "tiff")
|
|
|
+ if (extension.Equals("png")) imageFormat = ImageFormat.Png;
|
|
|
+ else if (extension.Equals("gif")) imageFormat = ImageFormat.Gif;
|
|
|
+ else if (extension.Equals("bmp")) imageFormat = ImageFormat.Bmp;
|
|
|
+ else if (extension.Equals("jpeg")) imageFormat = ImageFormat.Jpeg;
|
|
|
+ else if (extension.Equals("tiff"))
|
|
|
{
|
|
|
extension = "gif";
|
|
|
imageFormat = ImageFormat.Gif;
|
|
|
}
|
|
|
- else if (extension == "x-wmf")
|
|
|
+ else if (extension.Equals( "x-wmf"))
|
|
|
{
|
|
|
extension = "wmf";
|
|
|
imageFormat = ImageFormat.Wmf;
|
|
|
}
|
|
|
|
|
|
if (imageFormat == null) return null;
|
|
|
-
|
|
|
string base64 = null;
|
|
|
+ string mimeType = null;
|
|
|
+ string shaCode = null;
|
|
|
try
|
|
|
{
|
|
|
- using (MemoryStream ms = new MemoryStream())
|
|
|
+ if (extension.Equals("wmf"))
|
|
|
{
|
|
|
- imageInfo.Bitmap.Save(ms, imageFormat);
|
|
|
- var ba = ms.ToArray();
|
|
|
- base64 = System.Convert.ToBase64String(ba);
|
|
|
+ var buffer = Encoding.Default.GetBytes(imageInfo.Mathxml);
|
|
|
+ base64 = System.Convert.ToBase64String(buffer);
|
|
|
+ mimeType = "image/svg+xml";
|
|
|
+ shaCode = ShaHashHelper.GetSHA1( new MemoryStream(buffer));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ ImageFormat format = imageInfo.Bitmap.RawFormat;
|
|
|
+ ImageCodecInfo codec = ImageCodecInfo.GetImageDecoders()
|
|
|
+ .First(c => c.FormatID == format.Guid);
|
|
|
+ mimeType = codec.MimeType;
|
|
|
+ using (MemoryStream ms = new MemoryStream())
|
|
|
+ {
|
|
|
+
|
|
|
+ imageInfo.Bitmap.Save(ms, imageFormat);
|
|
|
+ var ba = ms.ToArray();
|
|
|
+ base64 = System.Convert.ToBase64String(ba);
|
|
|
+ shaCode = ShaHashHelper.GetSHA1(ms);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
catch (System.Runtime.InteropServices.ExternalException)
|
|
|
{ return null; }
|
|
|
|
|
|
- ImageFormat format = imageInfo.Bitmap.RawFormat;
|
|
|
- ImageCodecInfo codec = ImageCodecInfo.GetImageDecoders()
|
|
|
- .First(c => c.FormatID == format.Guid);
|
|
|
- string mimeType = codec.MimeType;
|
|
|
-
|
|
|
string imageSource =
|
|
|
string.Format("data:{0};base64,{1}", mimeType, base64);
|
|
|
-
|
|
|
+ #region 处理图片存到Bolb
|
|
|
+ string[] strs = imageSource.Split(',');
|
|
|
+ string fileExt = StringHelper.SubMidString(strs[0], ":", ";");
|
|
|
+ if (ContentTypeDict.extdict.TryGetValue(fileExt, out string ext))
|
|
|
+ {
|
|
|
+ fileExt = ext;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //解决多种扩展名不能获取的
|
|
|
+ string[] sp = StringHelper.SubMidString(strs[0], "/", ";").Split("-");
|
|
|
+ fileExt = sp[sp.Length - 1];
|
|
|
+ sp = fileExt.Split("+");
|
|
|
+ fileExt = "." + sp[sp.Length - 1];
|
|
|
+ }
|
|
|
+ Stream stream = new MemoryStream(Convert.FromBase64String(strs[1]));
|
|
|
+ // long bizno = IdWorker.getInstance().NextId();
|
|
|
+ string filename = shaCode + fileExt;
|
|
|
+ AzureBlobModel model = azureBlobDBRepository.UploadFileByFolderNAsyn(stream, FolderName, filename, "exercise", false);
|
|
|
+ #endregion
|
|
|
XElement img = new XElement(Xhtml.img,
|
|
|
- new XAttribute(NoNamespace.src, imageSource),
|
|
|
+ new XAttribute(NoNamespace.src, model.BlobUrl),
|
|
|
imageInfo.ImgStyleAttribute,
|
|
|
imageInfo.AltText != null ?
|
|
|
new XAttribute(NoNamespace.alt, imageInfo.AltText) : null);
|
|
|
+ stream.Close();
|
|
|
return img;
|
|
|
}
|
|
|
};
|
|
@@ -156,33 +208,16 @@ namespace TEAMModelOS.Service.Evaluation.Implements
|
|
|
var htmlString = htmls.ToString(SaveOptions.DisableFormatting);
|
|
|
//引入MathJax插件
|
|
|
htmlString = htmlString + "<script type=\"text/javascript\" src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\"></script>";
|
|
|
- File.WriteAllText(folder+"/"+"index.html", htmlString);
|
|
|
- return new { htmlString ,blobPath= folder + "/" + "index.html" };
|
|
|
+ File.WriteAllText(folder + "/" + "index.html", htmlString);
|
|
|
+ return new { htmlString, blobPath = folder + "/" + "index.html" };
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
- private static string SummaryTag = "【题文】";
|
|
|
- private static string AnswerTag = "【答案】";
|
|
|
- private static string AnalysisTag = "【解析】";
|
|
|
- private static string EndedTag = "【结束】";
|
|
|
- private static string Options = "ABCDEFGHIJ";
|
|
|
- private static string CompleteStart = "【";
|
|
|
- private static string CompleteEnd = "】";
|
|
|
- Dictionary<string, string> TestType = new Dictionary<string, string> {
|
|
|
- { "Single", "单选题|多选题" }, { "Multiple", "多选题|判断题" },
|
|
|
- { "Judge", "判断题|填空题" }, { "Complete", "填空题|主观题" },
|
|
|
- { "Subjective", "主观题|【完结】" } };
|
|
|
- //private readonly IAzureTableDBRepository azureTableDBRepository;
|
|
|
- private readonly IHttpContextAccessor httpContextAccessor;
|
|
|
- private readonly IAzureBlobDBRepository azureBlobDBRepository;
|
|
|
+
|
|
|
|
|
|
- public ImportExerciseService(IHttpContextAccessor _httpContextAccessor , IAzureBlobDBRepository _azureBlobDBRepository)
|
|
|
- {
|
|
|
- azureBlobDBRepository = _azureBlobDBRepository;
|
|
|
- httpContextAccessor = _httpContextAccessor;
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
|
|
|
public async Task<List<ExerciseDto>> AnalyzeWordAsync(DocInfoDto dict, string Lang)
|
|
@@ -241,41 +276,41 @@ namespace TEAMModelOS.Service.Evaluation.Implements
|
|
|
default: break;
|
|
|
}
|
|
|
}
|
|
|
- SaveExercise(tests, Lang);
|
|
|
+ ///SaveExercise(tests, Lang);
|
|
|
return tests;
|
|
|
}
|
|
|
|
|
|
|
|
|
- public async void SaveExercise(List<ExerciseDto> exercises, string Lang)
|
|
|
- {
|
|
|
- string tmdid = "";
|
|
|
- List<string> ids = HttpContextHelper.GetLoginUser(httpContextAccessor, "id");
|
|
|
- if (ids.IsNotEmpty())
|
|
|
- {
|
|
|
- tmdid = ids[0];
|
|
|
- }
|
|
|
- List<ExerciseVerify> exerciseVerifies = new List<ExerciseVerify>();
|
|
|
- exercises.ForEach(x =>
|
|
|
- {
|
|
|
- ExerciseVerify exercise0 = new ExerciseVerify { TeamModelId = tmdid, RowKey = x.ShaCode, Type = 0, PartitionKey = Lang, Content = x.Question, SummaryCode = x.ShaCode, Status = 1 };
|
|
|
- exerciseVerifies.Add(exercise0);
|
|
|
- if (x.Option.IsNotEmpty())
|
|
|
- {
|
|
|
- string opt = MessagePackHelper.ObjectToJson(x.Option);
|
|
|
- ExerciseVerify exercise1 = new ExerciseVerify { TeamModelId = tmdid, RowKey = x.ShaCode + "-" + ShaHashHelper.GetSHA1(opt), Type = 1, PartitionKey = Lang, Content = opt, SummaryCode = x.ShaCode, Status = 1 };
|
|
|
- exerciseVerifies.Add(exercise1);
|
|
|
- }
|
|
|
- if (x.Answer.IsNotEmpty())
|
|
|
- {
|
|
|
- string ans = MessagePackHelper.ObjectToJson(x.Answer);
|
|
|
- ExerciseVerify exercise2 = new ExerciseVerify { TeamModelId = tmdid, RowKey = x.ShaCode + "-" + ShaHashHelper.GetSHA1(ans), Type = 2, PartitionKey = Lang, Content = ans, SummaryCode = x.ShaCode, Status = 1 };
|
|
|
- exerciseVerifies.Add(exercise2);
|
|
|
- }
|
|
|
- ExerciseVerify exercise3 = new ExerciseVerify { TeamModelId = tmdid, RowKey = x.ShaCode + "-" + ShaHashHelper.GetSHA1(x.Explain), Type = 3, PartitionKey = Lang, Content = x.Explain, SummaryCode = x.ShaCode, Status = 1 };
|
|
|
- exerciseVerifies.Add(exercise3);
|
|
|
- });
|
|
|
- await this.SaveOrUpdateAll(exerciseVerifies);
|
|
|
- }
|
|
|
+ //public async void SaveExercise(List<ExerciseDto> exercises, string Lang)
|
|
|
+ //{
|
|
|
+ // string tmdid = "";
|
|
|
+ // List<string> ids = HttpContextHelper.GetLoginUser(httpContextAccessor, "id");
|
|
|
+ // if (ids.IsNotEmpty())
|
|
|
+ // {
|
|
|
+ // tmdid = ids[0];
|
|
|
+ // }
|
|
|
+ // List<ExerciseVerify> exerciseVerifies = new List<ExerciseVerify>();
|
|
|
+ // exercises.ForEach(x =>
|
|
|
+ // {
|
|
|
+ // ExerciseVerify exercise0 = new ExerciseVerify { TeamModelId = tmdid, RowKey = x.ShaCode, Type = 0, PartitionKey = Lang, Content = x.Question, SummaryCode = x.ShaCode, Status = 1 };
|
|
|
+ // exerciseVerifies.Add(exercise0);
|
|
|
+ // if (x.Option.IsNotEmpty())
|
|
|
+ // {
|
|
|
+ // string opt = MessagePackHelper.ObjectToJson(x.Option);
|
|
|
+ // ExerciseVerify exercise1 = new ExerciseVerify { TeamModelId = tmdid, RowKey = x.ShaCode + "-" + ShaHashHelper.GetSHA1(opt), Type = 1, PartitionKey = Lang, Content = opt, SummaryCode = x.ShaCode, Status = 1 };
|
|
|
+ // exerciseVerifies.Add(exercise1);
|
|
|
+ // }
|
|
|
+ // if (x.Answer.IsNotEmpty())
|
|
|
+ // {
|
|
|
+ // string ans = MessagePackHelper.ObjectToJson(x.Answer);
|
|
|
+ // ExerciseVerify exercise2 = new ExerciseVerify { TeamModelId = tmdid, RowKey = x.ShaCode + "-" + ShaHashHelper.GetSHA1(ans), Type = 2, PartitionKey = Lang, Content = ans, SummaryCode = x.ShaCode, Status = 1 };
|
|
|
+ // exerciseVerifies.Add(exercise2);
|
|
|
+ // }
|
|
|
+ // ExerciseVerify exercise3 = new ExerciseVerify { TeamModelId = tmdid, RowKey = x.ShaCode + "-" + ShaHashHelper.GetSHA1(x.Explain), Type = 3, PartitionKey = Lang, Content = x.Explain, SummaryCode = x.ShaCode, Status = 1 };
|
|
|
+ // exerciseVerifies.Add(exercise3);
|
|
|
+ // });
|
|
|
+ // await this.SaveOrUpdateAll(exerciseVerifies);
|
|
|
+ //}
|
|
|
|
|
|
|
|
|
public static List<ExerciseDto> SingleConvert(string TypeKey, string testHtml)
|