Commit 9365efb9 authored by 黄奎's avatar 黄奎

设置章节调整

parent 48207e87
......@@ -792,7 +792,7 @@ namespace Edu.Module.Course
var result = GetChapterTreeListModule(query);
List<ChapterCurrentHoursItem> list = new List<ChapterCurrentHoursItem>();
var currentHours = 0.00;
result.ForEach(x =>
foreach (var x in result)
{
if (x.ChildList != null && x.ChildList.Count > 0)
{
......@@ -801,7 +801,7 @@ namespace Edu.Module.Course
ChapterId = x.ChapterId,
CurrentHours = -1.00
});
x.ChildList.ForEach(y =>
foreach (var y in x.ChildList)
{
if (y.StudyHours > 0)
{
......@@ -820,7 +820,7 @@ namespace Edu.Module.Course
CurrentHours = -1.00
});
}
});
}
}
else
{
......@@ -842,7 +842,8 @@ namespace Edu.Module.Course
});
}
}
});
}
if (list != null && list.Count > 0)
{
return chapterRepository.SetBatchCurrentHoursRepository(list);
......@@ -884,14 +885,14 @@ namespace Edu.Module.Course
flag = chapterRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Chapter_ViewModel.ChapterId), model.ChapterId));
if (flag && model.ParentId == 0)
{
if (oldCourseRate != model.CourseRate)
{
//if (oldCourseRate != model.CourseRate)
// {
//修改了等级了 重新初始化
System.Threading.Tasks.Task.Run(() =>
{
chapterRepository.SetInitChapterGradeNo(model.CourseId, model.ChapterNo, model.Group_Id);
chapterRepository.SetInitChapterGradeNo(model.CourseId,model.Group_Id);
});
}
// }
}
}
else
......@@ -906,7 +907,10 @@ namespace Edu.Module.Course
model.ChapterId = newId;
flag = newId > 0;
}
SetBatchAllChapterCurrentHoursModule(model.CourseId);
Task.Run(() =>
{
SetBatchAllChapterCurrentHoursModule(model.CourseId);
});
return flag;
}
......
......@@ -93,18 +93,6 @@ namespace Edu.Repository.Course
return base.Execute(builder.ToString()) > 0;
}
/// <summary>
/// 根据课程编号删除章节信息
/// </summary>
/// <param name="CourseId"></param>
/// <returns></returns>
public bool DeleteByCourseIdRepository(int CourseId)
{
string sql = " DELETE FROM rb_course_chapter WHERE CourseId=" + CourseId;
return base.Execute(sql) > 0;
}
/// <summary>
/// 批量更新编号
/// </summary>
......@@ -136,16 +124,14 @@ namespace Edu.Repository.Course
try
{
StringBuilder builder = new StringBuilder();
//builder.Append("INSERT INTO rb_course_chapter (ChapterId, CurrentHours) VALUES");
//param.ForEach(x =>
//{
// builder.Append($"({x.ChapterId},'{x.CurrentHours}'),");
//});
//builder = builder.Remove(builder.Length - 1, 1);
//builder.Append("ON DUPLICATE KEY UPDATE CurrentHours=VALUES(CurrentHours);");
//flag = Execute(builder.ToString()) > 0;
builder.Append(@" REPLACE INTO rb_course_chapter(ChapterId, CurrentHours) VALUES(@ChapterId,@CurrentHours)");
flag = Execute(builder.ToString(), param) > 0;
foreach (var item in param)
{
if (item.ChapterId > 0)
{
builder.AppendFormat(@";UPDATE rb_course_chapter SET CurrentHours={0} WHERE ChapterId={1} ", item.CurrentHours, item.ChapterId);
}
}
flag = Execute(builder.ToString()) > 0;
}
catch (Exception ex)
{
......@@ -177,8 +163,7 @@ namespace Edu.Repository.Course
public bool DeleteBatchChpterRepository(RB_Course_Chapter_ViewModel model)
{
StringBuilder builder = new StringBuilder();
builder.Append("update rb_course_chapter ");
builder.AppendFormat("set {0}={1}", nameof(RB_Course_Chapter_ViewModel.Status), EnumHelper.ToInt(DateStateEnum.Delete));
builder.Append("DELETE FROM rb_course_chapter ");
builder.AppendFormat(" where {0}={1}", nameof(RB_Course_Chapter_ViewModel.CourseId), model.CourseId);
builder.AppendFormat(" and ({0} like '{1}%' or {2}={3})", nameof(RB_Course_Chapter_ViewModel.ChapterNo), model.ChapterNo, nameof(RB_Course_Chapter_ViewModel.ChapterId), model.ChapterId);
return Execute(builder.ToString()) > 0;
......@@ -253,17 +238,19 @@ namespace Edu.Repository.Course
/// 更新课程等级对应节点
/// </summary>
/// <param name="courseId"></param>
/// <param name="chapterNo"></param>
/// <param name="group_Id"></param>
public void SetInitChapterGradeNo(int courseId, string chapterNo, int group_Id)
public void SetInitChapterGradeNo(int courseId, int group_Id)
{
string sql = $@"UPDATE rb_course_chapter cc
string sql = $@"
UPDATE rb_course_chapter cc
LEFT JOIN (
SELECT c.ChapterId,c.CourseId,c.ChapterNo,c.SortNum,c.CourseRate
,(SELECT COUNT(0) as Num FROM rb_course_chapter c2 WHERE c2.`Status` =0 and c2.CourseId = c.CourseId and c2.CourseRate = c.CourseRate and c2.SortNum <= c.SortNum) AS GrageNum
FROM rb_course_chapter c WHERE c.`Status` =0 and c.CourseId ={courseId}) cc2 on cc.ChapterId =cc2.ChapterId
SELECT c.ChapterId,c.CourseId,c.ChapterNo,c.SortNum,c.CourseRate
,(SELECT COUNT(0) as Num FROM rb_course_chapter c2 WHERE c2.`Status` =0 and c2.CourseId = c.CourseId and c2.CourseRate = c.CourseRate and c2.SortNum <= c.SortNum) AS GrageNum
FROM rb_course_chapter c
WHERE c.`Status` =0 and c.CourseId ={courseId}
) cc2 on cc.ChapterId =cc2.ChapterId
SET cc.ChapterGradeNo = cc2.GrageNum
WHERE cc.Group_Id ={group_Id} and cc.CourseId ={courseId} and cc.ChapterNo >={chapterNo}";
WHERE cc.Group_Id ={group_Id} and cc.CourseId ={courseId}";
Execute(sql);
}
}
......
......@@ -850,8 +850,44 @@ namespace Edu.WebApi.Controllers.Course
[AllowRepeatAttribute]
public ApiResult SetBatchChapterNo()
{
var extModel = Common.Plugin.JsonHelper.DeserializeObject<List<RB_Course_Chapter_ViewModel>>(RequestParm.Msg.ToString());
bool flag = courseModule.SetBatchChapterNoModule(extModel);
bool flag = false;
List<RB_Course_Chapter_ViewModel> list = new List<RB_Course_Chapter_ViewModel>();
if (!string.IsNullOrEmpty(RequestParm.Msg.ToString()))
{
try
{
JArray jarray = JArray.Parse(RequestParm.Msg.ToString());
if (jarray != null && jarray.Count > 0)
{
int index = 1;
foreach (var jItem in jarray)
{
JObject jobj = JObject.Parse(JsonHelper.Serialize(jItem));
var newModel = new RB_Course_Chapter_ViewModel()
{
ChapterNo = index.ToString(),
ChapterId = jobj.GetInt("ChapterId"),
ParentId = jobj.GetInt("ParentId"),
SortNum = index
};
if (newModel.ChapterId > 0)
{
list.Add(newModel);
index++;
}
}
}
}
catch
{
}
}
if (list != null && list.Count > 0)
{
flag = courseModule.SetBatchChapterNoModule(list);
}
return flag ? ApiResult.Success() : ApiResult.Failed();
}
......
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