Commit 79d1fbb7 authored by 黄奎's avatar 黄奎

页面修改

parent 16097b7d
......@@ -7,7 +7,7 @@ namespace Edu.Common.Data
{
public class XlsQuestionHelper
{
public List<XlsItem> GetXlsQuestionData(string filePath)
public static List<XlsItem> GetXlsQuestionData(string filePath)
{
List<XlsItem> xlsItems = new List<XlsItem>();
var dt = Common.Plugin.NPOIHelper.ImportExcelToDatatable(filePath, 0, 0, true);
......
......@@ -27,6 +27,11 @@ namespace Edu.Model.Entity.Question
/// </summary>
public string Title { get; set; }
/// <summary>
/// 问题内容
/// </summary>
public string QuestionContent { get; set; }
/// <summary>
/// 难易程度(1-易,2-中,3-难)
/// </summary>
......
......@@ -57,7 +57,7 @@ namespace Edu.Model.ViewModel.Question
/// <summary>
/// 选项
/// </summary>
public object AnswerObj { get; set; }
public object QuestionContentObj { get; set; }
/// <summary>
/// 知识点名称
......
......@@ -31,7 +31,14 @@ namespace Edu.Module.Question
break;
//填空题
case "fill-in":
obj = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(data);
if (!string.IsNullOrEmpty(data))
{
obj = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(data);
}
else
{
obj = null;
}
break;
//判断题
case "judge":
......
......@@ -80,6 +80,7 @@ namespace Edu.Module.Question
Dictionary<string, object> fileds = new Dictionary<string, object>()
{
{nameof(RB_Question_ViewModel.Title),model.Title },
{nameof(RB_Question_ViewModel.QuestionContent),(!string.IsNullOrEmpty(model.QuestionContent)?model.QuestionContent:"") },
{nameof(RB_Question_ViewModel.DifficultyType),(int)model.DifficultyType },
{nameof(RB_Question_ViewModel.AnswerParse),model.AnswerParse },
{nameof(RB_Question_ViewModel.QuestionTypeId),model.QuestionTypeId },
......@@ -151,7 +152,8 @@ namespace Edu.Module.Question
var extModel = questionRepository.GetEntity<RB_Question_ViewModel>(QuestionId);
if (extModel != null)
{
extModel.AnswerObj = analysisQuestion.ParsingQuestion(extModel.QuestionTypeKey, extModel.Answer);
extModel.QuestionContentObj = analysisQuestion.ParsingQuestion(extModel.QuestionTypeKey, extModel.QuestionContent);
if (!string.IsNullOrEmpty(extModel.Knowledge))
{
extModel.QuestionPointList = GetPointListModule(new RB_Question_Point_ViewModel() { QPointIds = extModel.Knowledge });
......
using Edu.Cache.User;
using Edu.Common.API;
using Edu.Common.Data;
using Edu.Common.Enum.Question;
using Edu.Common.Plugin;
using Edu.Model.ViewModel.Question;
......@@ -9,6 +10,7 @@ using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Edu.WebApi.Controllers.Course
{
......@@ -271,5 +273,65 @@ namespace Edu.WebApi.Controllers.Course
return flag ? ApiResult.Success() : ApiResult.Failed();
}
#endregion
/// <summary>
/// 导入Excel问题
/// </summary>
/// <returns></returns>
public ApiResult ImportExcelQuestion(string filePath,int CourseId)
{
var list = Common.Data.XlsQuestionHelper.GetXlsQuestionData(filePath);
if (list != null && list.Count > 0)
{
var difficultyList = Common.Plugin.EnumHelper.EnumToList(typeof(DifficultyTypeEnum));
var questionTypeList = questionModule.GetQuestionTypeListModule(new RB_Question_Type_ViewModel());
foreach (var item in list)
{
var model = GetQuestionModel(item, difficultyList, questionTypeList);
model.CourseId = CourseId;
}
}
return ApiResult.Success();
}
private RB_Question_ViewModel GetQuestionModel(XlsItem item, List<EnumItem> difficultyList, List<RB_Question_Type_ViewModel> questionTypeList)
{
var DifficultyType = DifficultyTypeEnum.Easy;
if (item.EasyType == "中")
{
DifficultyType = DifficultyTypeEnum.Middle;
}
if (item.EasyType == "难")
{
DifficultyType = DifficultyTypeEnum.Difficult;
}
RB_Question_ViewModel model = new RB_Question_ViewModel
{
Title = item.QuestionTitle,
DifficultyType= DifficultyType,
AnswerParse=item.AnswerAnalysis
};
switch (item.QuestionTypeName)
{
case "单选题":
Int32.TryParse(item.ChooseOptionCount, out int ChooseOptionCount);
if(ChooseOptionCount>0)
{
List<optionItem> singleList = new List<optionItem>();
//for (var i = 0; i < ChooseOptionCount; i++)
//{
// singleList.Add(new optionItem() {
// Name=
// })
//}
model.QuestionContentObj = singleList;
}
break;
}
return model;
}
}
}
\ No newline at end of file
......@@ -5,11 +5,13 @@ using System.Linq;
using System.Threading.Tasks;
using Edu.Common.API;
using Edu.Common.Plugin;
using Edu.WebApi.Controllers.Course;
using Edu.WebApi.Filter;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
namespace Edu.WebApi.Controllers.Upload
{
......@@ -26,7 +28,7 @@ namespace Edu.WebApi.Controllers.Upload
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public ApiResult UploadExcelQuestion()
public ApiResult UploadFile()
{
try
{
......@@ -35,6 +37,10 @@ namespace Edu.WebApi.Controllers.Upload
{
return new ApiResult { Code = (int)ResultCode.Fail, Message = "未选择文件", Data = "" };
}
var json = !string.IsNullOrEmpty(Request.Form["params"]) ? JObject.Parse(Request.Form["params"].ToString()) : null;
Int32.TryParse(json["Analysis"].ToString(), out int Analysis);
Int32.TryParse(json["Excel"].ToString(), out int Excel);
Int32.TryParse(json["CourseId"].ToString(), out int CourseId);
string filename = files[0].FileName;
string fileExtention = System.IO.Path.GetExtension(files[0].FileName);
......@@ -42,7 +48,8 @@ namespace Edu.WebApi.Controllers.Upload
List<string> ExtList = new List<string>() {
".xls",
".xlsx",
".csv"
".doc",
".docx"
};
if (!ExtList.Contains(fileExtention))
{
......@@ -59,7 +66,12 @@ namespace Edu.WebApi.Controllers.Upload
{
files[0].CopyTo(fstream);
}
//导入Excel文件
if (Analysis == 1 && Excel == 1 && CourseId > 0)
{
return new QuestionController().ImportExcelQuestion(path_server, CourseId);
}
return ApiResult.Success("", new { Name = filename, Path = path_server });
}
catch (Exception ex)
......
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