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

页面修改

parent 16097b7d
...@@ -7,7 +7,7 @@ namespace Edu.Common.Data ...@@ -7,7 +7,7 @@ namespace Edu.Common.Data
{ {
public class XlsQuestionHelper public class XlsQuestionHelper
{ {
public List<XlsItem> GetXlsQuestionData(string filePath) public static List<XlsItem> GetXlsQuestionData(string filePath)
{ {
List<XlsItem> xlsItems = new List<XlsItem>(); List<XlsItem> xlsItems = new List<XlsItem>();
var dt = Common.Plugin.NPOIHelper.ImportExcelToDatatable(filePath, 0, 0, true); var dt = Common.Plugin.NPOIHelper.ImportExcelToDatatable(filePath, 0, 0, true);
......
...@@ -27,6 +27,11 @@ namespace Edu.Model.Entity.Question ...@@ -27,6 +27,11 @@ namespace Edu.Model.Entity.Question
/// </summary> /// </summary>
public string Title { get; set; } public string Title { get; set; }
/// <summary>
/// 问题内容
/// </summary>
public string QuestionContent { get; set; }
/// <summary> /// <summary>
/// 难易程度(1-易,2-中,3-难) /// 难易程度(1-易,2-中,3-难)
/// </summary> /// </summary>
......
...@@ -57,7 +57,7 @@ namespace Edu.Model.ViewModel.Question ...@@ -57,7 +57,7 @@ namespace Edu.Model.ViewModel.Question
/// <summary> /// <summary>
/// 选项 /// 选项
/// </summary> /// </summary>
public object AnswerObj { get; set; } public object QuestionContentObj { get; set; }
/// <summary> /// <summary>
/// 知识点名称 /// 知识点名称
......
...@@ -31,7 +31,14 @@ namespace Edu.Module.Question ...@@ -31,7 +31,14 @@ namespace Edu.Module.Question
break; break;
//填空题 //填空题
case "fill-in": 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; break;
//判断题 //判断题
case "judge": case "judge":
......
...@@ -80,6 +80,7 @@ namespace Edu.Module.Question ...@@ -80,6 +80,7 @@ namespace Edu.Module.Question
Dictionary<string, object> fileds = new Dictionary<string, object>() Dictionary<string, object> fileds = new Dictionary<string, object>()
{ {
{nameof(RB_Question_ViewModel.Title),model.Title }, {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.DifficultyType),(int)model.DifficultyType },
{nameof(RB_Question_ViewModel.AnswerParse),model.AnswerParse }, {nameof(RB_Question_ViewModel.AnswerParse),model.AnswerParse },
{nameof(RB_Question_ViewModel.QuestionTypeId),model.QuestionTypeId }, {nameof(RB_Question_ViewModel.QuestionTypeId),model.QuestionTypeId },
...@@ -151,7 +152,8 @@ namespace Edu.Module.Question ...@@ -151,7 +152,8 @@ namespace Edu.Module.Question
var extModel = questionRepository.GetEntity<RB_Question_ViewModel>(QuestionId); var extModel = questionRepository.GetEntity<RB_Question_ViewModel>(QuestionId);
if (extModel != null) if (extModel != null)
{ {
extModel.AnswerObj = analysisQuestion.ParsingQuestion(extModel.QuestionTypeKey, extModel.Answer);
extModel.QuestionContentObj = analysisQuestion.ParsingQuestion(extModel.QuestionTypeKey, extModel.QuestionContent);
if (!string.IsNullOrEmpty(extModel.Knowledge)) if (!string.IsNullOrEmpty(extModel.Knowledge))
{ {
extModel.QuestionPointList = GetPointListModule(new RB_Question_Point_ViewModel() { QPointIds = extModel.Knowledge }); extModel.QuestionPointList = GetPointListModule(new RB_Question_Point_ViewModel() { QPointIds = extModel.Knowledge });
......
using Edu.Cache.User; using Edu.Cache.User;
using Edu.Common.API; using Edu.Common.API;
using Edu.Common.Data;
using Edu.Common.Enum.Question; using Edu.Common.Enum.Question;
using Edu.Common.Plugin; using Edu.Common.Plugin;
using Edu.Model.ViewModel.Question; using Edu.Model.ViewModel.Question;
...@@ -9,6 +10,7 @@ using Microsoft.AspNetCore.Cors; ...@@ -9,6 +10,7 @@ using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace Edu.WebApi.Controllers.Course namespace Edu.WebApi.Controllers.Course
{ {
...@@ -271,5 +273,65 @@ namespace Edu.WebApi.Controllers.Course ...@@ -271,5 +273,65 @@ namespace Edu.WebApi.Controllers.Course
return flag ? ApiResult.Success() : ApiResult.Failed(); return flag ? ApiResult.Success() : ApiResult.Failed();
} }
#endregion #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; ...@@ -5,11 +5,13 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Edu.Common.API; using Edu.Common.API;
using Edu.Common.Plugin; using Edu.Common.Plugin;
using Edu.WebApi.Controllers.Course;
using Edu.WebApi.Filter; using Edu.WebApi.Filter;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
namespace Edu.WebApi.Controllers.Upload namespace Edu.WebApi.Controllers.Upload
{ {
...@@ -26,7 +28,7 @@ namespace Edu.WebApi.Controllers.Upload ...@@ -26,7 +28,7 @@ namespace Edu.WebApi.Controllers.Upload
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
[AllowAnonymous] [AllowAnonymous]
public ApiResult UploadExcelQuestion() public ApiResult UploadFile()
{ {
try try
{ {
...@@ -35,6 +37,10 @@ namespace Edu.WebApi.Controllers.Upload ...@@ -35,6 +37,10 @@ namespace Edu.WebApi.Controllers.Upload
{ {
return new ApiResult { Code = (int)ResultCode.Fail, Message = "未选择文件", Data = "" }; 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 filename = files[0].FileName;
string fileExtention = System.IO.Path.GetExtension(files[0].FileName); string fileExtention = System.IO.Path.GetExtension(files[0].FileName);
...@@ -42,7 +48,8 @@ namespace Edu.WebApi.Controllers.Upload ...@@ -42,7 +48,8 @@ namespace Edu.WebApi.Controllers.Upload
List<string> ExtList = new List<string>() { List<string> ExtList = new List<string>() {
".xls", ".xls",
".xlsx", ".xlsx",
".csv" ".doc",
".docx"
}; };
if (!ExtList.Contains(fileExtention)) if (!ExtList.Contains(fileExtention))
{ {
...@@ -59,7 +66,12 @@ namespace Edu.WebApi.Controllers.Upload ...@@ -59,7 +66,12 @@ namespace Edu.WebApi.Controllers.Upload
{ {
files[0].CopyTo(fstream); 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 }); return ApiResult.Success("", new { Name = filename, Path = path_server });
} }
catch (Exception ex) 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