Commit df9ea776 authored by 罗超's avatar 罗超

调整章节内容

parent 8d8aee29
......@@ -17,6 +17,8 @@ namespace Edu.Common.Plugin
/// </summary>
public class WordHelper
{
/// <summary>
/// Spire.Doc解析Word
/// </summary>
......
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Edu.Common.Plugin
{
public class WordToNumHelper
{
/// <summary>
/// 阿拉伯数字转换成中文数字
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public string NumToChinese(string x)
{
string[] pArrayNum = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
//为数字位数建立一个位数组
string[] pArrayDigit = { "", "十", "百", "千" };
//为数字单位建立一个单位数组
string[] pArrayUnits = { "", "万", "亿", "万亿" };
var pStrReturnValue = ""; //返回值
var finger = 0; //字符位置指针
var pIntM = x.Length % 4; //取模
int pIntK;
if (pIntM > 0)
pIntK = x.Length / 4 + 1;
else
pIntK = x.Length / 4;
//外层循环,四位一组,每组最后加上单位: ",万亿,",",亿,",",万,"
for (var i = pIntK; i > 0; i--)
{
var pIntL = 4;
if (i == pIntK && pIntM != 0)
pIntL = pIntM;
//得到一组四位数
var four = x.Substring(finger, pIntL);
var P_int_l = four.Length;
//内层循环在该组中的每一位数上循环
for (int j = 0; j < P_int_l; j++)
{
//处理组中的每一位数加上所在的位
int n = Convert.ToInt32(four.Substring(j, 1));
if (n == 0)
{
if (j < P_int_l - 1 && Convert.ToInt32(four.Substring(j + 1, 1)) > 0 && !pStrReturnValue.EndsWith(pArrayNum[n]))
pStrReturnValue += pArrayNum[n];
}
else
{
if (!(n == 1 && (pStrReturnValue.EndsWith(pArrayNum[0]) | pStrReturnValue.Length == 0) && j == P_int_l - 2))
pStrReturnValue += pArrayNum[n];
pStrReturnValue += pArrayDigit[P_int_l - j - 1];
}
}
finger += pIntL;
//每组最后加上一个单位:",万,",",亿," 等
if (i < pIntK) //如果不是最高位的一组
{
if (Convert.ToInt32(four) != 0)
//如果所有4位不全是0则加上单位",万,",",亿,"等
pStrReturnValue += pArrayUnits[i - 1];
}
else
{
//处理最高位的一组,最后必须加上单位
pStrReturnValue += pArrayUnits[i - 1];
}
}
return pStrReturnValue;
}
/// <summary>
/// 将中文数字替换为阿拉伯数字
/// </summary>
/// <param name="word"></param>
/// <returns></returns>
public static string WordToNumber(string word)
{
string e = "([零一二三四五六七八九十百千万亿])+";
MatchCollection mc = Regex.Matches(word, e);
foreach(Match m in mc)
{
word = word.Replace(m.Value, Word2Number(m.Value));
}
return word;
}
private static string Word2Number(string w)
{
if (w == "")
return w;
string e = "零一二三四五六七八九";
string[] ew = new string[] { "十", "百", "千" };
string ewJoin = "十百千";
string[] ej = new string[] { "万", "亿" };
string rss = "^([" + e + ewJoin + "]+" + ej[1] + ")?([" + e
+ ewJoin + "]+" + ej[0] + ")?([" + e + ewJoin + "]+)?$";
string[] mcollect = Regex.Split(w, rss);
if (mcollect.Length < 4)
return w;
return (
Convert.ToInt64(foh(mcollect[1])) * 100000000 +
Convert.ToInt64(foh(mcollect[2])) * 10000 +
Convert.ToInt64(foh(mcollect[3]))
).ToString();
}
private static int foh(string str)
{
string e = "零一二三四五六七八九";
string[] ew = new string[] { "十", "百", "千" };
string[] ej = new string[] { "万", "亿" };
int a = 0;
if (str.IndexOf(ew[0]) == 0)
a = 10;
str = Regex.Replace(str, e[0].ToString(), "");
if (Regex.IsMatch(str, "([" + e + "])$"))
{
a += e.IndexOf(Regex.Match(str, "([" + e + "])$").Value[0]);
}
if (Regex.IsMatch(str, "([" + e + "])" + ew[0]))
{
a += e.IndexOf(Regex.Match(str, "([" + e + "])" + ew[0]).Value[0]) * 10;
}
if (Regex.IsMatch(str, "([" + e + "])" + ew[1]))
{
a += e.IndexOf(Regex.Match(str, "([" + e + "])" + ew[1]).Value[0]) * 100;
}
if (Regex.IsMatch(str, "([" + e + "])" + ew[2]))
{
a += e.IndexOf(Regex.Match(str, "([" + e + "])" + ew[2]).Value[0]) * 1000;
}
return a;
}
}
}
......@@ -105,12 +105,12 @@ namespace Edu.Model.Entity.Course
/// <summary>
/// 学习课时
/// </summary>
public int StudyHours { get; set; }
public double StudyHours { get; set; }
/// <summary>
/// 学习分钟
/// </summary>
public int StudyMinutes { get; set; }
public double StudyMinutes { get; set; }
/// <summary>
/// 教学重点
......@@ -130,6 +130,6 @@ namespace Edu.Model.Entity.Course
/// <summary>
/// 当前课时(累加计算)
/// </summary>
public int CurrentHours { get; set; }
public double CurrentHours { get; set; }
}
}
......@@ -55,12 +55,12 @@ namespace Edu.Model.ViewModel.Course
/// <summary>
/// 学习课时
/// </summary>
public int StudyHours { get; set; }
public double StudyHours { get; set; }
/// <summary>
/// 学习分钟
/// </summary>
public int StudyMinutes { get; set; }
public double StudyMinutes { get; set; }
/// <summary>
/// 教学重点
......@@ -85,6 +85,7 @@ namespace Edu.Model.ViewModel.Course
/// <summary>
/// 当前课时(累加计算)
/// </summary>
public int CurrentHours { get; set; }
public double CurrentHours { get; set; }
}
}
......@@ -78,6 +78,10 @@ namespace Edu.Model.ViewModel.Course
/// </summary>
public List<RB_Class_LessonPlan_ViewModel> LessonPlanList { get; set; }
public RB_Course_Chapter_ViewModel Chapter { get; set; }
public string CourseName { get; set; }
#region 展示无逻辑
/// <summary>
......
......@@ -17,5 +17,19 @@ namespace Edu.Model.ViewModel.Course
/// 序列号
/// </summary>
public int SerialNumber { get; set; }
/// <summary>
/// 当前单元最大序号
/// </summary>
public int MaxLength { get; set; }
/// <summary>
/// 新的课程编号
/// </summary>
public int NewCourseId { get; set; }
public string CourseName { get; set; }
}
}
......@@ -140,5 +140,16 @@ namespace Edu.Model.ViewModel.Course
/// 随机条数
/// </summary>
public int RandNum { get; set; }
/// <summary>
/// 单元数量
/// </summary>
public int UnitCount { get; set; }
/// <summary>
/// 章节数量
/// </summary>
public int ChapterCount { get; set; }
}
}
\ No newline at end of file
......@@ -2686,6 +2686,16 @@ namespace Edu.Module.Course
return new { mondayList, tuesdayList, wednesdayList, thursdayList, fridayList, saturdayList, sundayList };
}
/// <summary>
/// 查询指定计划的上课课时
/// </summary>
/// <param name="planId"></param>
/// <returns></returns>
public double GetCurrentPlanStudyHoursRepository(int planId)
{
return class_PlanRepository.GetCurrentPlanStudyHoursRepository(planId);
}
/// <summary>
/// 更新历史班号
/// </summary>
......
......@@ -7,8 +7,10 @@ using Edu.Model.ViewModel.User;
using Edu.Repository.Course;
using Edu.Repository.Question;
using Edu.Repository.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using VT.FW.DB;
namespace Edu.Module.Course
......@@ -105,6 +107,11 @@ namespace Edu.Module.Course
#region 课程管理
public List<RB_Course_ViewModel> GetAllCourseChapterCountModule(int groupId,int courseId)
{
return courseRepository.GetCourseAllChapterCount(groupId, courseId) ??new List<RB_Course_ViewModel>();
}
/// <summary>
/// 获取课程列表
/// </summary>
......@@ -463,6 +470,88 @@ namespace Edu.Module.Course
return chapterRepository.GetChapterListRepository(query);
}
public List<ChapterTree_ViewModel> SetImportChapterModule(RB_Course_Chapter_ViewModel query)
{
var result = GetChapterTreeListModule(query);
int maxLength = query.MaxLength;
string[] ids = query.CourseIds.Split(',', System.StringSplitOptions.RemoveEmptyEntries);
foreach (var item in ids)
{
var temp = result.Where(x => x.CourseId.ToString().Equals(item)).ToList();
var array = new List<ChapterTree_ViewModel>();
temp.ForEach(x => {
maxLength++;
x.ChapterNo = maxLength.ToString();
x.ChapterName = FormatNum(x.ChapterName, maxLength);
int pid = GenernalNewChapterNode(x, query);
x.ChapterId = pid;
x.ChildList = x.ChildList != null && x.ChildList.Count > 0 ? ReChangeChapterNo(x.ChildList, maxLength,pid,query) : new List<ChapterTree_ViewModel>();
});
}
SetBatchAllChapterCurrentHoursModule(query.NewCourseId);
return result;
}
public List<ChapterTree_ViewModel> ReChangeChapterNo(List<ChapterTree_ViewModel> list,int parentNo,int parentId, RB_Course_Chapter_ViewModel query)
{
list.ForEach(x =>
{
var oldNo = x.ChapterNo.Split('.');
oldNo[0] = parentNo.ToString();
x.ChapterNo = string.Join(".", oldNo);
x.ChapterName = FormatNum(x.ChapterName, parentNo);
x.ParentId = parentId;
int pid = GenernalNewChapterNode(x, query);
x.ChapterId = pid;
x.ChildList = ReChangeChapterNo(x.ChildList, parentNo, pid, query);
});
return list;
}
public int GenernalNewChapterNode(ChapterTree_ViewModel model, RB_Course_Chapter_ViewModel query)
{
RB_Course_Chapter_ViewModel newModel = new RB_Course_Chapter_ViewModel() {
ChapterContent=model.ChapterContent,
ChapterId=0,
ChapterName=model.ChapterName,
ChapterNo=model.ChapterNo,
CourseId= query.NewCourseId,
CourseRate=model.CourseRate,
CreateBy= query.CreateBy,
CreateTime=DateTime.Now,
CurrentHours=model.CurrentHours,
Group_Id=query.Group_Id,
Objectives=model.Objectives,
OpenStatus=model.OpenStatus,
ParentId=model.ParentId,
Requirement=model.Requirement,
School_Id=query.School_Id,
Status=DateStateEnum.Normal,
StudyHours=model.StudyHours,
StudyMinutes=model.StudyMinutes
};
SetChapterModule(newModel);
return newModel.ChapterId;
}
/// <summary>
/// 重新生成单元标题序号
/// </summary>
/// <returns></returns>
public string FormatNum(string name,int length)
{
Regex regex = new Regex(@"(?<=第)(.*?)(?=单|次|课|章|节)");
string temp = regex.Match(name).Value;
if (!string.IsNullOrEmpty(temp))
{
var newTemp = new WordToNumHelper().NumToChinese(length.ToString());
name = name.Replace(temp,newTemp);
}
return name;
}
/// <summary>
/// 获取课程章节树形列表
/// </summary>
......@@ -471,10 +560,19 @@ namespace Edu.Module.Course
public List<ChapterTree_ViewModel> GetChapterTreeListModule(RB_Course_Chapter_ViewModel query)
{
var list = GetChapterListModule(query);
list.ForEach(x =>
{
x.SerialNumber = int.Parse(x.ChapterNo.Replace(".", ""));
});
List<ChapterTree_ViewModel> treeList = GetChapterChild(list, 0);
return treeList;
}
public RB_Course_Chapter_ViewModel GetMatchHoursChapterModule(int courseId,double currentHours)
{
return chapterRepository.GetMatchHoursChapterRepository(courseId,currentHours);
}
/// <summary>
/// 递归遍历所有章节
/// </summary>
......@@ -485,7 +583,7 @@ namespace Edu.Module.Course
{
List<ChapterTree_ViewModel> resultList = new List<ChapterTree_ViewModel>();
//获取下级节点
var subList = sourceList?.Where(qItem => qItem.ParentId == parentId).OrderBy(qitem =>qitem.SortNum).ToList();
var subList = sourceList?.Where(qItem => qItem.ParentId == parentId).OrderBy(qitem =>qitem.SerialNumber).ToList();
//如果存在下级节点
if (subList != null && subList.Count > 0)
{
......@@ -517,6 +615,70 @@ namespace Edu.Module.Course
return resultList;
}
public bool SetBatchAllChapterCurrentHoursModule(int courseId)
{
RB_Course_Chapter_ViewModel query = new RB_Course_Chapter_ViewModel()
{
CourseId = courseId
};
var result = GetChapterTreeListModule(query);
List<RB_Course_Chapter_ViewModel> list = new List<RB_Course_Chapter_ViewModel>();
var currentHours = 0.00;
result.ForEach(x => {
if (x.ChildList != null && x.ChildList.Count > 0)
{
list.Add(new RB_Course_Chapter_ViewModel()
{
ChapterId = x.ChapterId,
CurrentHours = -1.00
});
x.ChildList.ForEach(y =>
{
if (y.StudyHours > 0)
{
list.Add(new RB_Course_Chapter_ViewModel()
{
ChapterId = y.ChapterId,
CurrentHours = currentHours
});
currentHours += y.StudyHours;
}
else
{
list.Add(new RB_Course_Chapter_ViewModel()
{
ChapterId = y.ChapterId,
CurrentHours = -1.00
});
}
});
}
else
{
if (x.StudyHours > 0)
{
list.Add(new RB_Course_Chapter_ViewModel()
{
ChapterId = x.ChapterId,
CurrentHours = currentHours
});
currentHours += x.StudyHours;
}
else
{
list.Add(new RB_Course_Chapter_ViewModel()
{
ChapterId = x.ChapterId,
CurrentHours = -1
});
}
}
});
return chapterRepository.SetBatchCurrentHoursRepository(list);
}
/// <summary>
/// 新增修改课程章节
/// </summary>
......@@ -526,7 +688,7 @@ namespace Edu.Module.Course
bool flag;
if (model.StudyMinutes > 0)
{
model.StudyHours = model.StudyMinutes / class_ConfigRepository.GetBasicMinutesRepository(model.Group_Id);
model.StudyHours = model.StudyMinutes / Convert.ToDouble(class_ConfigRepository.GetBasicMinutesRepository(model.Group_Id));
}
if (model.ChapterId > 0)
{
......@@ -550,6 +712,7 @@ namespace Edu.Module.Course
model.ChapterId = newId;
flag = newId > 0;
}
SetBatchAllChapterCurrentHoursModule(model.CourseId);
return flag;
}
......@@ -639,7 +802,10 @@ namespace Edu.Module.Course
/// <returns></returns>
public bool BatchRemoveChapterModule(RB_Course_Chapter_ViewModel model)
{
return chapterRepository.DeleteBatchChpterRepository(model);
var flag = chapterRepository.DeleteBatchChpterRepository(model);
SetBatchAllChapterCurrentHoursModule(model.CourseId);
return flag;
}
/// <summary>
......@@ -691,7 +857,10 @@ namespace Edu.Module.Course
/// <returns></returns>
public bool SetBatchChapterNoModule(List<RB_Course_Chapter_ViewModel> chapters)
{
return chapterRepository.SetBatchUpdateChapterNoRepository(chapters);
var flag = chapterRepository.SetBatchUpdateChapterNoRepository(chapters);
//SetBatchAllChapterCurrentHoursModule(chapters[0].CourseId);
return flag;
}
/// <summary>
......
......@@ -535,5 +535,24 @@ GROUP BY A.ClassPlanId,A.ClassId ,A.ClassDate,A.ClassRoomId,A.CompleteProgress
", where.ToString());
return Get<RB_Class_Plan_ViewModel>(builder.ToString()).ToList();
}
/// <summary>
/// 查询指定计划的上课课时
/// </summary>
/// <param name="planId"></param>
/// <returns></returns>
public double GetCurrentPlanStudyHoursRepository(int planId)
{
string sql = @"select
(select SUM(timestampdiff(MINUTE, Concat(SUBSTRING_INDEX(d.ClassDate, ' ', 1), ' ', c.StartTime), Concat(SUBSTRING_INDEX(d.ClassDate, ' ', 1), ' ', c.EndTime))) / 45
from rb_class_time c left
join rb_class_plan d on c.ClassPlanId = d.ClassPlanId
where d.ClassDate < b.ClassDate and c.ClassId = b.ClassId)
from rb_class_plan b where b.ClassPlanId = "+planId+" and b.`Status`= 0";
object obj = ExecuteScalar(sql);
return Convert.IsDBNull(obj)?-1:Convert.ToDouble(obj);
}
}
}
\ No newline at end of file
......@@ -53,6 +53,7 @@ WHERE 1=1
if (!string.IsNullOrEmpty(query.Saleplat))
{
var salePlatList = Common.ConvertHelper.StringToList(query.Saleplat);
string str = "";
if (salePlatList != null && salePlatList.Count > 0)
{
......@@ -143,5 +144,17 @@ WHERE 1=1
}
return GetPage<RB_Course_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString(), parameters).ToList();
}
/// <summary>
/// 查询所有正常课程的章节信息
/// </summary>
/// <returns></returns>
public List<RB_Course_ViewModel> GetCourseAllChapterCount(int groupId,int courseId)
{
StringBuilder sql = new StringBuilder("select CourseId,CourseName,(select Count(0) from rb_course_chapter b where b.CourseId=a.CourseId and ParentId=0 and b.`Status`=0) as UnitCount,(select Count(0) from rb_course_chapter b where b.CourseId=a.CourseId and ParentId>0 and b.`Status`=0) as ChapterCount from rb_course a where Status=0");
sql.AppendFormat(" AND a.{0}={1} ", nameof(RB_Course_ViewModel.Group_Id), groupId);
sql.AppendFormat(" AND a.{0}<>{1} ", nameof(RB_Course_ViewModel.CourseId), courseId);
return Get<RB_Course_ViewModel>(sql.ToString()).ToList();
}
}
}
......@@ -44,7 +44,7 @@ namespace Edu.Repository.Course
builder.AppendFormat(" AND {0} IN({1}) ", nameof(RB_Course_Chapter_ViewModel.CourseId), query.CourseIds);
}
}
builder.AppendFormat(" ORDER BY {0} ",nameof(RB_Course_Chapter_ViewModel.ChapterNo));
//builder.AppendFormat(" ORDER BY {0} ",nameof(RB_Course_Chapter_ViewModel.ChapterNo));
return Get<RB_Course_Chapter_ViewModel>(builder.ToString(), parameters).ToList();
}
......@@ -67,6 +67,18 @@ namespace Edu.Repository.Course
return Execute(builder.ToString()) > 0;
}
public bool SetBatchCurrentHoursRepository(List<RB_Course_Chapter_ViewModel> param)
{
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);");
return Execute(builder.ToString()) > 0;
}
/// <summary>
/// 批量更新课程等级
/// </summary>
......@@ -98,5 +110,27 @@ namespace Edu.Repository.Course
return Execute(builder.ToString()) > 0;
}
/// <summary>
/// 查询符合的课程章节
/// </summary>
/// <param name="courseId"></param>
/// <param name="currentHours"></param>
/// <returns></returns>
public RB_Course_Chapter_ViewModel GetMatchHoursChapterRepository(int courseId, double currentHours)
{
var parameters = new DynamicParameters();
StringBuilder builder = new StringBuilder();
builder.AppendFormat(@"
SELECT *
FROM rb_course_chapter
WHERE 1=1
");
builder.AppendFormat(" AND {0}={1}", nameof(RB_Course_Chapter_ViewModel.Status), EnumHelper.ToInt(DateStateEnum.Normal));
builder.AppendFormat(" AND {0}={1}", nameof(RB_Course_Chapter_ViewModel.CourseId), courseId);
builder.AppendFormat(" AND {0}<={1}", nameof(RB_Course_Chapter_ViewModel.CurrentHours), currentHours);
builder.AppendFormat(" ORDER BY {0} Desc",nameof(RB_Course_Chapter_ViewModel.CurrentHours));
return Get<RB_Course_Chapter_ViewModel>(builder.ToString(), parameters).ToList().FirstOrDefault();
}
}
}
......@@ -1400,6 +1400,26 @@ namespace Edu.WebApi.Controllers.Course
new RB_Class_LessonPlan_ViewModel { CourseName = "理解篇", LessonPlanDetailsList = new List<RB_Class_LessonPlanDetails_ViewModel>(), LessonPlanProjectsList = new List<RB_Class_LessonPlanProjects_ViewModel>() }
};
}
#region 追加章节信息
var hours = classModule.GetCurrentPlanStudyHoursRepository(model.ClassPlanId);
if (hours != -1)
{
var classObj=classModule.GetClassModule(model.ClassId);
var courseOjb = new CourseModule().GetCourseModule(classObj.CouseId);
var chapter = new CourseModule().GetMatchHoursChapterModule(classObj.CouseId,hours);
if (chapter != null && chapter.ChapterId > 0)
{
chapter.CourseName = courseOjb.CourseName;
model.Chapter = chapter;
}
}
#endregion
return ApiResult.Success("", model);
}
......
......@@ -158,6 +158,20 @@ namespace Edu.WebApi.Controllers.Course
#region 课程管理
[HttpPost]
public ApiResult GetAllCourseChapterCount()
{
int groupId = base.UserInfo.Group_Id;
int courseId = base.ParmJObj.GetInt("CourseId", 0);
var list = courseModule.GetAllCourseChapterCountModule(groupId, courseId);
return ApiResult.Success(data: list.Where(x=>x.UnitCount>0).Select(x => new {
x.CourseId,
x.CourseName,
x.UnitCount,
x.ChapterCount
}));
}
/// <summary>
/// 获取课程分页列表
/// </summary>
......@@ -193,6 +207,8 @@ namespace Edu.WebApi.Controllers.Course
return ApiResult.Success(data: pageModel);
}
/// <summary>
/// 获取课程列表
/// </summary>
......@@ -413,6 +429,21 @@ namespace Edu.WebApi.Controllers.Course
#region 课程章节管理
[HttpPost]
public ApiResult SetImportCourseChapter()
{
var query = Common.Plugin.JsonHelper.DeserializeObject<RB_Course_Chapter_ViewModel>(RequestParm.Msg.ToString());
query.Group_Id = base.UserInfo.Group_Id;
query.School_Id = base.UserInfo.School_Id;
query.CreateBy = base.UserInfo.Id;
var q=courseModule.SetImportChapterModule(query);
if (q!=null && q.Count > 0)
{
return ApiResult.Success();
}
return 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