public dynamic SaveCourse_Look(W_Course_Look_DetailModel Model) { return(Success(mapper.SaveCourse_Look(Model, this.SafeGetStuId, this.System_Station_ID))); }
/// <summary> /// 添加录播的观看视频 /// </summary> /// <param name="Model"></param> /// <returns></returns> public dynamic SaveCourse_Look(W_Course_Look_DetailModel Model, string StuId, int System_Station_ID) { SqlMapper.BeginTransaction(); try { if (Model.CourseChapters_ID <= 0) { throw new ApiException("章节ID不能小于0"); } if (Model.LookType < 0) { throw new ApiException("观看类型LookType不能为空!"); } Model.EndTime = DateTime.Now; Model.AddTime = DateTime.Now; W_Course_Look_Detail OldModel = SqlMapper.QueryForObject <W_Course_Look_Detail>("GetCourse_Look_Detail", new { StuId = StuId, CourseChapters_ID = Model.CourseChapters_ID }); if (OldModel != null) { OldModel.EndTime = OldModel.EndTime.AddSeconds(double.Parse(Model.LookTime.ToString())); if (SqlMapper.Update("UpdateCourse_Look_Detail", new { ID = OldModel.ID, EndTime = OldModel.EndTime }) <= 0) { throw new ApiException("更新最后播放时间出错"); } CourseLookTimeModel LookTimeModel = SqlMapper.QueryForObject <CourseLookTimeModel>("GetCourseLookTimeModel", new { stuid = StuId, CourseChapters_ID = Model.CourseChapters_ID }); int TotalSeconds = 0; //已播放的秒数 int Duration = 0; //视频的时长 if (LookTimeModel != null) { TotalSeconds = LookTimeModel.TotalSeconds; Duration = LookTimeModel.Duration; } else { throw new ApiException("未找到用户的播放记录"); } //未获取到视频播放时长 if (Duration <= 0) { throw new ApiException("视频的时长为0"); } //默认观看6分钟添加记录 int LookDuration = 6; //查询配置信息 视频播放时长 W_Configuration ConfigurationModel = new HConfigurationMapper().GetWConfiguration(System_Station_ID); if (ConfigurationModel != null) { LookDuration = ConfigurationModel.LookDuration; } //判断学生观看视频记录时间是否大于设置的时长 或者 视频时长小于设置的时长的时候判断观看时长和视频时长相差不到10秒的时候执行 if (TotalSeconds >= LookDuration * 60 || (Duration < LookDuration * 60 && (Duration - TotalSeconds) <= 10)) { int counts = SqlMapper.QueryForObject <int>("GetW_Course_LookCounts", new { stuid = StuId, CourseChapters_ID = Model.CourseChapters_ID }); if (counts == 0) { W_Course_Look CourseLook = new W_Course_Look(); CourseLook.CourseChapters_ID = Model.CourseChapters_ID; CourseLook.IP = Model.IP; CourseLook.LookTime = DateTime.Now; CourseLook.LookType = Model.LookType; CourseLook.StuId = StuId; Orm.Insert <W_Course_Look>(CourseLook); } } } else { W_Course_Look_Detail model = new W_Course_Look_Detail(); model.AddTime = Model.AddTime; model.CourseChapters_ID = Model.CourseChapters_ID; model.EndTime = Model.EndTime; model.IP = Model.IP; model.LookType = Model.LookType; model.StuId = StuId; Orm.Insert(model); } SqlMapper.CommitTransaction(); return(true); } catch (Exception ex) { SqlMapper.RollBackTransaction(); throw ex; } }