Commit e1c86395 authored by 黄奎's avatar 黄奎

新增方法

parent 76fef689
using System;
using System.Collections.Generic;
using System.Text;
namespace Edu.Model.ViewModel.Exam
{
/// <summary>
/// 试卷文件树形结构
/// </summary>
public class ExamFolderTreeModel
{
/// <summary>
/// 试卷编号
/// </summary>
public int PaperId { get; set; }
/// <summary>
/// 试卷名称
/// </summary>
public string PaperName { get; set; }
/// <summary>
/// 父节点编号
/// </summary>
public int ParentId { get; set; }
/// <summary>
/// 下级文件夹列表
/// </summary>
public List<ExamFolderTreeModel> ChildList { get; set; }
}
}
...@@ -26,5 +26,10 @@ namespace Edu.Model.ViewModel.Exam ...@@ -26,5 +26,10 @@ namespace Edu.Model.ViewModel.Exam
/// 试卷编号 /// 试卷编号
/// </summary> /// </summary>
public string QPaperIds { get; set; } public string QPaperIds { get; set; }
/// <summary>
/// 是否查询文件夹
/// </summary>
public int IsQueryFolder { get; set; }
} }
} }
...@@ -5,7 +5,6 @@ using System; ...@@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using VT.FW.DB; using VT.FW.DB;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions;
using Edu.Cache.User; using Edu.Cache.User;
using Edu.Common.Plugin; using Edu.Common.Plugin;
using Edu.Module.Question; using Edu.Module.Question;
...@@ -117,7 +116,7 @@ namespace Edu.Module.Exam ...@@ -117,7 +116,7 @@ namespace Edu.Module.Exam
} }
/// <summary> /// <summary>
/// 递归遍历所有章节 /// 递归遍历所有下级文件夹或试卷
/// </summary> /// </summary>
/// <param name="sourceList">源数据</param> /// <param name="sourceList">源数据</param>
/// <param name="parentId">父节点编号</param> /// <param name="parentId">父节点编号</param>
...@@ -608,5 +607,64 @@ namespace Edu.Module.Exam ...@@ -608,5 +607,64 @@ namespace Edu.Module.Exam
flag = examination_PaperRepository.Update(fileds, new WhereHelper(nameof(RB_Examination_Paper_ViewModel.PaperId), PaperId)); flag = examination_PaperRepository.Update(fileds, new WhereHelper(nameof(RB_Examination_Paper_ViewModel.PaperId), PaperId));
return flag; return flag;
} }
/// <summary>
/// 获取文件夹树形结构
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public object GetFolderTreeModule(RB_Examination_Paper_ViewModel query)
{
List<ExamFolderTreeModel> list = new List<ExamFolderTreeModel>();
var dataList = examination_PaperRepository.GetExaminationPaperListRepository(query);
if (dataList != null&&dataList.Count>0)
{
var rootList = dataList?.Where(qitem => qitem.ParentId == 0)?.ToList();
foreach (var rItem in rootList)
{
ExamFolderTreeModel fTreeModel = new ExamFolderTreeModel()
{
PaperId = rItem.PaperId,
ParentId = rItem.ParentId,
PaperName = rItem.PaperName,
ChildList = new List<ExamFolderTreeModel>()
};
fTreeModel.ChildList = GetFolderChild(dataList, rItem.PaperId);
list.Add(fTreeModel);
}
}
return list;
}
/// <summary>
/// 递归遍历所有下级文件夹
/// </summary>
/// <param name="sourceList">源数据</param>
/// <param name="parentId">父节点编号</param>
/// <returns></returns>
public List<ExamFolderTreeModel> GetFolderChild(List<RB_Examination_Paper_ViewModel> sourceList, int parentId)
{
List<ExamFolderTreeModel> resultList = new List<ExamFolderTreeModel>();
//获取下级节点
var subList = sourceList?.Where(qItem => qItem.ParentId == parentId).ToList();
//如果存在下级节点
if (subList != null && subList.Count > 0)
{
foreach (var childItem in subList)
{
var childModel = new ExamFolderTreeModel()
{
PaperId = childItem.PaperId,
ParentId = childItem.ParentId,
PaperName = childItem.PaperName,
ChildList = new List<ExamFolderTreeModel>()
};
childModel.ChildList.AddRange(GetFolderChild(sourceList, childItem.PaperId));
resultList.Add(childModel);
}
}
return resultList;
}
} }
} }
...@@ -60,6 +60,56 @@ WHERE 1=1 ...@@ -60,6 +60,56 @@ WHERE 1=1
return GetPage<RB_Examination_Paper_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString(), parameters).ToList(); return GetPage<RB_Examination_Paper_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString(), parameters).ToList();
} }
/// <summary>
/// 获取试卷列表
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public List<RB_Examination_Paper_ViewModel> GetExaminationPaperListRepository(RB_Examination_Paper_ViewModel query)
{
var parameters = new DynamicParameters();
StringBuilder builder = new StringBuilder();
builder.AppendFormat(@"
SELECT A.*
FROM RB_Examination_Paper AS A
WHERE 1=1
");
builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Examination_Paper_ViewModel.ParentId), 0);
if (query != null)
{
if (query.Group_Id > 0)
{
builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Examination_Paper_ViewModel.Group_Id), query.Group_Id);
}
if (!string.IsNullOrEmpty(query.PaperName))
{
builder.AppendFormat(" AND A.{0} LIKE @PaperName ", nameof(RB_Examination_Paper_ViewModel.PaperName));
parameters.Add("PaperName", "%" + query.PaperName.Trim() + "%");
}
if (query.ParentId > 0)
{
builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Examination_Paper_ViewModel.ParentId), query.ParentId);
}
if (query.PaperId > 0)
{
builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Examination_Paper_ViewModel.PaperId), query.PaperId);
}
if (!string.IsNullOrEmpty(query.QPaperIds))
{
builder.AppendFormat(@" AND A.{0} IN({1}) ", nameof(RB_Examination_Paper_ViewModel.PaperId), query.QPaperIds);
}
//查询文件夹
if (query.IsQueryFolder == 1)
{
builder.AppendFormat(@" AND A.{0}=1 ", nameof(RB_Examination_Paper_ViewModel.PaperType));
}
}
builder.AppendFormat(" ORDER BY A.{0} DESC ", nameof(RB_Examination_Paper_ViewModel.PaperId));
return Get<RB_Examination_Paper_ViewModel>(builder.ToString(), parameters).ToList();
}
/// <summary> /// <summary>
/// 获取试卷所有下级列表 /// 获取试卷所有下级列表
/// </summary> /// </summary>
......
...@@ -256,11 +256,11 @@ namespace Edu.WebApi.Controllers.Exam ...@@ -256,11 +256,11 @@ namespace Edu.WebApi.Controllers.Exam
} }
/// <summary> /// <summary>
/// 新增修改文件夹 /// 新增修改文件夹
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost]
public ApiResult SetPaperFolder() public ApiResult SetPaperFolder()
{ {
var extModel = new RB_Examination_Paper_ViewModel() var extModel = new RB_Examination_Paper_ViewModel()
...@@ -280,8 +280,7 @@ namespace Edu.WebApi.Controllers.Exam ...@@ -280,8 +280,7 @@ namespace Edu.WebApi.Controllers.Exam
bool flag = paperModule.SetExaminationPaperFolderModule(extModel); bool flag = paperModule.SetExaminationPaperFolderModule(extModel);
return flag ? ApiResult.Success(data: extModel) : ApiResult.Failed(); return flag ? ApiResult.Success(data: extModel) : ApiResult.Failed();
} }
/// <summary> /// <summary>
/// 根据编号获取试卷信息 /// 根据编号获取试卷信息
...@@ -357,5 +356,24 @@ namespace Edu.WebApi.Controllers.Exam ...@@ -357,5 +356,24 @@ namespace Edu.WebApi.Controllers.Exam
var flag = paperModule.MoveExamnationPaperModule(PaperId, ParentId); var flag = paperModule.MoveExamnationPaperModule(PaperId, ParentId);
return flag ? ApiResult.Success() : ApiResult.Failed(); return flag ? ApiResult.Success() : ApiResult.Failed();
} }
/// <summary>
/// 获取文件夹树形结构
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetFolderTree()
{
var extModel = new RB_Examination_Paper_ViewModel()
{
CreateBy = UserInfo.Id,
Group_Id = base.UserInfo.Group_Id,
ParentId = base.ParmJObj.GetInt("ParentId"),
IsQueryFolder=1,
};
var obj = paperModule.GetFolderTreeModule(extModel);
return ApiResult.Success(data: obj);
}
} }
} }
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