Commit 53b6f38c authored by 黄奎's avatar 黄奎

新增接口

parent 4fec8383
......@@ -177,7 +177,6 @@ namespace Edu.Common.Data
if (tempArray != null && tempArray.Length > 0)
{
string strTitle = tempArray[0].Trim();
if (htmlList != null && htmlList.Count > 0)
{
foreach (var hItem in htmlList)
......
......@@ -7,7 +7,7 @@ using VT.FW.DB;
namespace Edu.Model.Entity.Question
{
/// <summary>
/// 题库实体类
/// 问题实体类
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
......@@ -23,6 +23,11 @@ namespace Edu.Model.Entity.Question
/// </summary>
public int CourseId { get; set; }
/// <summary>
/// 题库编号
/// </summary>
public int BankId { get; set; }
/// <summary>
/// 问题名称
/// </summary>
......
using Edu.Common.Enum;
using System;
using VT.FW.DB;
namespace Edu.Model.Entity.Question
{
/// <summary>
/// 题库实体类
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_Question_Bank
{
/// <summary>
/// 题库编号(主键)
/// </summary>
public int BankId { get; set; }
/// <summary>
/// BankName
/// </summary>
public string BankName { get; set; }
/// <summary>
/// 集团编号
/// </summary>
public int Group_Id { get; set; }
/// <summary>
/// 学校编号
/// </summary>
public int School_Id { get; set; }
/// <summary>
/// 创建人
/// </summary>
public int CreateBy { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreateTime { get; set; }
/// <summary>
/// 修改人
/// </summary>
public int UpdateBy { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdateTime { get; set; }
/// <summary>
/// 删除状态
/// </summary>
public DateStateEnum Status { get; set; }
}
}
using Edu.Common;
using Edu.Model.Entity.Question;
namespace Edu.Model.ViewModel.Question
{
/// <summary>
/// 题库视图实体类
/// </summary>
public class RB_Question_Bank_ViewModel : RB_Question_Bank
{
/// <summary>
/// 创建人
/// </summary>
public string CreateByName { get; set; }
/// <summary>
/// 修改人
/// </summary>
public string UpdateByName { get; set; }
/// <summary>
/// 创建时间字符串
/// </summary>
public string CreateTimeStr { get { return this.CreateTime.FormatTime(); } }
/// <summary>
/// 更新时间字符串
/// </summary>
public string UpdateTimeStr { get { return this.UpdateTime.FormatTime(); } }
/// <summary>
/// 题量
/// </summary>
public int QuestionCount { get; set; }
}
}
......@@ -19,7 +19,7 @@ namespace Edu.Module.Question
private readonly RB_Question_TypeRepository question_TypeRepository = new RB_Question_TypeRepository();
/// <summary>
/// 题库仓储层对象
/// 问题仓储层对象
/// </summary>
private readonly RB_QuestionRepository questionRepository = new RB_QuestionRepository();
......@@ -34,6 +34,74 @@ namespace Edu.Module.Question
/// </summary>
private readonly AnalysisQuestionTypeModule analysisQuestion = new AnalysisQuestionTypeModule();
/// <summary>
/// 题库仓储层对象
/// </summary>
private readonly RB_Question_BankRepository question_BankRepository = new RB_Question_BankRepository();
/// <summary>
/// 获取题库分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="rowsCount"></param>
/// <param name="query"></param>
/// <returns></returns>
public List<RB_Question_Bank_ViewModel> GetQuestionBankPageListModule(int pageIndex, int pageSize, out long rowsCount, RB_Question_Bank_ViewModel query)
{
return question_BankRepository.GetQuestionBankPageListRepository(pageIndex, pageSize, out rowsCount, query);
}
/// <summary>
/// 新增修改题库
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public bool SetQuestionBankModule(RB_Question_Bank_ViewModel model)
{
bool flag;
if (model.BankId > 0)
{
Dictionary<string, object> fileds = new Dictionary<string, object>()
{
{nameof(RB_Question_Bank_ViewModel.BankName), model.BankName }
};
flag = questionRepository.Update(fileds, new WhereHelper(nameof(RB_Question_Bank_ViewModel.BankId), model.BankId));
}
else
{
var newId = question_BankRepository.Insert(model);
model.BankId = newId;
flag = newId > 0;
}
return flag;
}
/// <summary>
/// 根据编号获取题库
/// </summary>
/// <param name="BankId"></param>
/// <returns></returns>
public RB_Question_Bank_ViewModel GetQuestionBankModule(object BankId)
{
return question_BankRepository.GetEntity<RB_Question_Bank_ViewModel>(BankId);
}
/// <summary>
/// 删除题库
/// </summary>
/// <param name="bankId"></param>
/// <param name="status"></param>
/// <returns></returns>
public bool RemoveQuestionBankModule(int bankId, int status)
{
Dictionary<string, object> fileds = new Dictionary<string, object>()
{
{nameof(RB_Question_Bank_ViewModel.Status),status }
};
return questionRepository.Update(fileds, new WhereHelper(nameof(RB_Question_Bank_ViewModel.BankId), bankId));
}
/// <summary>
/// 获取题目类型列表
/// </summary>
......@@ -45,7 +113,7 @@ namespace Edu.Module.Question
}
/// <summary>
/// 获取题库分页列表
/// 获取问题分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
......@@ -58,7 +126,7 @@ namespace Edu.Module.Question
}
/// <summary>
/// 获取题库列表
/// 获取问题列表
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
......@@ -101,6 +169,14 @@ namespace Edu.Module.Question
var newId = questionRepository.Insert(model);
model.QuestionId = newId;
flag = newId > 0;
if (flag)
{
Dictionary<string, object> sortFileds = new Dictionary<string, object>()
{
{nameof(RB_Question_ViewModel.SortNum),newId },
};
flag = questionRepository.Update(sortFileds, new WhereHelper(nameof(RB_Question_ViewModel.QuestionId), newId));
}
}
return flag;
}
......@@ -124,7 +200,7 @@ namespace Edu.Module.Question
{
Dictionary<string, object> fileds = new Dictionary<string, object>()
{
{nameof(RB_Question_ViewModel.Status),(int )DateStateEnum.Delete},
{nameof(RB_Question_ViewModel.Status),(int)DateStateEnum.Delete},
};
bool flag = questionRepository.Update(fileds, new WhereHelper(nameof(RB_Question_ViewModel.QuestionId), QuestionId));
return flag;
......@@ -179,7 +255,7 @@ namespace Edu.Module.Question
/// <param name="questionKey"></param>
/// <param name="questionContent"></param>
/// <returns></returns>
public object ParsingQuestionModule(string questionKey,string questionContent)
public object ParsingQuestionModule(string questionKey, string questionContent)
{
return analysisQuestion.ParsingQuestion(questionKey, questionContent);
}
......
......@@ -8,12 +8,12 @@ using VT.FW.DB.Dapper;
namespace Edu.Repository.Question
{
/// <summary>
/// 题库仓储层
/// 问题仓储层
/// </summary>
public class RB_QuestionRepository : BaseRepository<Model.Entity.Question.RB_Question>
{
/// <summary>
/// 获取题库列表
/// 获取问题列表
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
......@@ -40,7 +40,7 @@ WHERE 1=1
}
/// <summary>
/// 获取题库分页列表
/// 获取问题分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
......@@ -63,6 +63,10 @@ WHERE 1=1 ");
}
else
{
if (query.BankId > 0)
{
builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Question_ViewModel.BankId), query.BankId);
}
if (query.CourseId > 0)
{
builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Question_ViewModel.CourseId), query.CourseId);
......@@ -93,5 +97,6 @@ WHERE 1=1 ");
return GetPage<RB_Question_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString(), parameters).ToList();
}
}
}
}
\ No newline at end of file
using Edu.Common.Enum;
using Edu.Model.Entity.Question;
using Edu.Model.ViewModel.Question;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB.Dapper;
namespace Edu.Repository.Question
{
/// <summary>
/// 题库仓储层
/// </summary>
public class RB_Question_BankRepository : BaseRepository<RB_Question_Bank>
{
/// <summary>
/// 获取题库分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="rowsCount"></param>
/// <param name="query"></param>
/// <returns></returns>
public List<RB_Question_Bank_ViewModel> GetQuestionBankPageListRepository(int pageIndex, int pageSize, out long rowsCount, RB_Question_Bank_ViewModel query)
{
rowsCount = 0;
var parameters = new DynamicParameters();
StringBuilder builder = new StringBuilder();
builder.AppendFormat(@"
SELECT A.*,IFNULL(B.QuestionCount,0) AS QuestionCount
FROM RB_Question_Bank AS A LEFT JOIN( SELECT BankId,COUNT(1) AS QuestionCount FROM rb_question WHERE `Status`=0 GROUP BY BankId) AS B ON A.BankId=B.BankId
WHERE 1=1");
builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Question_Bank_ViewModel.Status), (int)DateStateEnum.Normal);
if (query == null)
{
return new List<RB_Question_Bank_ViewModel>();
}
else
{
if (query.BankId > 0)
{
builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Question_Bank_ViewModel.BankId), query.BankId);
}
if (!string.IsNullOrEmpty(query.BankName))
{
builder.AppendFormat(" AND A.{0} LIKE @BankName ", nameof(RB_Question_Bank_ViewModel.BankName));
parameters.Add("BankName", "%" + query.BankName.Trim() + "%");
}
builder.AppendFormat(" ORDER BY A.{0} DESC ", nameof(RB_Question_ViewModel.QuestionId));
return GetPage<RB_Question_Bank_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString(), parameters).ToList();
}
}
}
}
......@@ -28,6 +28,86 @@ namespace Edu.WebApi.Controllers.Course
private readonly QuestionModule questionModule = AOP.AOPHelper.CreateAOPObject<QuestionModule>();
#region 题库管理
/// <summary>
/// 获取课程问题分页列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetQuestionBankPageList()
{
var pageModel = Common.Plugin.JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
var query = new RB_Question_Bank_ViewModel()
{
BankId = base.ParmJObj.GetInt("BankId"),
BankName = base.ParmJObj.GetStringValue("BankName"),
};
var list = questionModule.GetQuestionBankPageListModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
List<object> resultList = new List<object>();
foreach (var item in list)
{
if (item.CreateBy > 0)
{
item.CreateByName = UserReidsCache.GetUserLoginInfo(item.CreateBy)?.AccountName ?? "";
}
resultList.Add(new
{
item.BankId,
item.BankName,
item.CreateByName,
item.QuestionCount
});
}
pageModel.Count = rowsCount;
pageModel.PageData = resultList;
return ApiResult.Success(data: pageModel);
}
/// <summary>
/// 获取题库实体
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetQuestionBank()
{
var BankId = base.ParmJObj.GetInt("BankId", 0);
var extModel = questionModule.GetQuestionBankModule(BankId);
return ApiResult.Success(data: extModel);
}
/// <summary>
/// 添加修改题库
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetQuestionBank()
{
var extModel = Common.Plugin.JsonHelper.DeserializeObject<RB_Question_Bank_ViewModel>(RequestParm.Msg.ToString());
extModel.CreateTime = DateTime.Now;
extModel.CreateBy = base.UserInfo.Id;
extModel.UpdateBy = base.UserInfo.Id;
extModel.UpdateTime = DateTime.Now;
extModel.Status = Common.Enum.DateStateEnum.Normal;
extModel.Group_Id = base.UserInfo.Group_Id;
extModel.School_Id = base.UserInfo.School_Id;
bool flag = questionModule.SetQuestionBankModule(extModel);
return flag ? ApiResult.Success() : ApiResult.Failed();
}
/// <summary>
/// 删除题库
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult RemoveQuestionBank()
{
var bankId = base.ParmJObj.GetInt("bankId", 0);
int status= base.ParmJObj.GetInt("status", 0);
var flag = questionModule.RemoveQuestionBankModule(bankId, status);
return flag ? ApiResult.Success() : ApiResult.Failed();
}
/// <summary>
/// 获取题目类型列表
......@@ -54,6 +134,7 @@ namespace Edu.WebApi.Controllers.Course
CourseId = base.ParmJObj.GetInt("CourseId"),
Title = base.ParmJObj.GetStringValue("Title"),
PointName = base.ParmJObj.GetStringValue("PointName"),
BankId=base.ParmJObj.GetInt("BankId")
};
try
{
......@@ -572,13 +653,14 @@ namespace Edu.WebApi.Controllers.Course
var list = Common.Plugin.JsonHelper.DeserializeObject<List<RB_Question_ViewModel>>(RequestParm.Msg.ToString());
if (list != null && list.Count > 0)
{
flag = questionModule.SetQuestionBatchModule(list);
foreach (var item in list)
{
flag = questionModule.SetQuestionModule(item);
}
}
return flag ? ApiResult.Success() : ApiResult.Failed();
}
/// <summary>
/// 删除课程问题
/// </summary>
......
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