Ejemplo n.º 1
0
        /// <summary>
        /// 添加一个UserCourseComment
        /// </summary>
        /// <param name="input">实体</param>
        /// <returns></returns>

        public async Task Create(CreateUserCourseCommentInput input)
        {
            var model = await _courseRepository.FirstOrDefaultAsync(x => x.Id == input.CourseId && x.Status == -1);

            if (model == null)
            {
                throw new UserFriendlyException((int)ErrorCode.CodeValErr, "课程不存在!");
            }
            var userId   = (await base.GetCurrentUserAsync()).Id;
            var newmodel = new UserCourseComment()
            {
                UserId   = userId,
                CourseId = input.CourseId,
                Comment  = input.Comment
            };
            await _repository.InsertAsync(newmodel);

            //送积分
            var set = await _courseSettingAppService.GetSetVal(model.LearnType, model.IsSpecial);

            if (set.CommentScore > 0)
            {
                await _trainScoreRecordAppService.Create(new CreateUserTrainScoreRecordInput()
                {
                    FromId     = input.CourseId,
                    FromType   = TrainScoreFromType.CourseComment,
                    BusinessId = newmodel.Id,
                    Score      = set.CommentScore,
                    UserId     = userId
                });
            }
        }
Ejemplo n.º 2
0
        public async void AddJoinScore(string guid)
        {
            var fileId = Guid.Empty;

            if (!Guid.TryParse(guid, out fileId))
            {
                return;
            }
            var train = _repository.Get(fileId);

            if (train != null && train.JoinScore > 0)
            {
                var arr = train.JoinUser.Split(',');
                foreach (var item in arr)
                {
                    var id = Convert.ToInt64(item.Replace("u_", ""));
                    if (_trainLeaveRepository.GetAll().Any(x => x.TrainId == train.Id && x.StartTime == train.StartTime && x.EndTime == train.EndTime && x.Status != -1 && x.UserId == id))
                    {
                        continue;
                    }
                    await _trainScoreRecordAppService.Create(new CreateUserTrainScoreRecordInput()
                    {
                        FromId   = train.Id,
                        FromType = TrainScoreFromType.TrainLearn,
                        Score    = train.JoinScore.Value,
                        UserId   = id
                    });
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 添加一个TrainUserExperience
        /// </summary>
        /// <param name="input">实体</param>
        /// <returns></returns>

        public async Task UpdateUse(TrainUserExperienceUseInput input)
        {
            if (input.Guids.Count > 0)
            {
                foreach (var item in input.Guids)
                {
                    var model = _repository.GetAll().FirstOrDefault(x => x.Id == item);
                    if (model != null)
                    {
                        model.IsUse = true;
                        await _repository.UpdateAsync(model);

                        var train = _trainRepository.GetAll().FirstOrDefault(x => x.Id == model.TrainId);
                        if (train != null && train.ExperienceScore > 0)
                        {
                            await _trainScoreRecordAppService.Create(new CreateUserTrainScoreRecordInput()
                            {
                                FromId   = train.Id,
                                FromType = TrainScoreFromType.TrainExperience,
                                Score    = train.ExperienceScore.Value,
                                UserId   = model.UserId
                            });
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 添加一个UserCourseRecordDetail
        /// </summary>
        /// <param name="input">实体</param>
        /// <returns></returns>

        public async Task Create(CreateUserCourseRecordDetailInput input)
        {
            var user = await base.GetCurrentUserAsync();

            var chkCreate = false;
            //查询出课程
            var couser = await _couserRepository.FirstOrDefaultAsync(x => x.Id == input.CourseId && x.Status == -1);

            if (couser == null)
            {
                throw new UserFriendlyException((int)ErrorCode.CodeValErr, "课程不存在!");
            }
            //判断修习时长是否超过课程时长
            if (input.LearningTime > couser.LearnTime)
            {
                throw new UserFriendlyException((int)ErrorCode.CodeValErr, "修习时长不能超过课程总时长!");
            }
            //查询出上一条观看记录
            var model = await _repository.GetAll().Where(x => x.UserId == user.Id && x.CourseId == input.CourseId)
                        .OrderByDescending(x => x.LastModificationTime ?? x.CreationTime).FirstOrDefaultAsync();

            if (model == null)
            {
                //判断第一次修习时长是否大于1分钟
                if (input.LearningTime > 1)
                {
                    throw new UserFriendlyException((int)ErrorCode.CodeValErr, "初次记录修习时长不得高于1分钟!");
                }
                chkCreate = true;
            }
            else
            {
                //判断当前时间-上一条观看时间是否小于1分钟
                if (DateTime.Now - (model.LastModificationTime ?? model.CreationTime) < TimeSpan.FromSeconds(50))
                {
                    throw new UserFriendlyException((int)ErrorCode.CodeValErr, "请勿短时间内多次上传课时!");
                }
                //判断本次上传修习时长-上一条观看记录修习时长是否大于1分钟
                if (input.LearningTime - model.LearningTime > 1)
                {
                    throw new UserFriendlyException((int)ErrorCode.CodeValErr, "单次记录修习时长不得高于1分钟!");
                }
                //判断当前时间与上一条观看时间是否在同一天
                if (!DateTime.Now.Date.Equals(model.CreationTime.Date))
                {
                    chkCreate = true;
                }
            }
            if (chkCreate)
            {
                //创建新的修习记录
                model = new UserCourseRecordDetail()
                {
                    CourseId     = input.CourseId,
                    LearningTime = input.LearningTime,
                    UserId       = user.Id
                };
                await _repository.InsertAsync(model);
            }
            else
            {
                //更新修习时长
                model.LearningTime = input.LearningTime;
                await _repository.UpdateAsync(model);
            }
            var record = await _courseRecordRepository.GetAll()
                         .Where(x => !x.IsDeleted && x.CourseId == model.CourseId && x.UserId == model.UserId)
                         .FirstOrDefaultAsync();

            if (record != null)
            {
                //更新总时长
                record.LearnTime = model.LearningTime;
                //判断课程的修习状态进行完成操作
                if (record.IsComplete == null)
                {
                    var set = await _courseSettingAppService.Get();

                    //判断当前观看比率是否大于set的观看比率
                    if (Convert.ToDecimal(model.LearningTime) / Convert.ToDecimal(couser.LearnTime) * 100 >=
                        set.ViewingRatio)
                    {
                        //无计时或尚未超出规定学习时间
                        if (couser.ComplateTime == null || couser.ComplateTime > DateTime.Now)
                        {
                            //查询set并送出积分
                            var setScore = await _courseSettingAppService.GetSetVal(couser.LearnType, couser.IsSpecial);

                            if (setScore.ClassHourScore > 0)
                            {
                                await _trainScoreRecordAppService.Create(new CreateUserTrainScoreRecordInput()
                                {
                                    FromType = TrainScoreFromType.CourseLearn,
                                    FromId   = record.CourseId,
                                    Score    = setScore.ClassHourScore,
                                    UserId   = user.Id
                                });
                            }
                            //更新课程观看状态
                            record.IsComplete = true;
                        }
                        else
                        {
                            //有计时并且超时当时完成的需要恢复之前扣除的积分
                            //恢复积分
                            var oldscore =
                                await _trainScoreRecordRepository.FirstOrDefaultAsync(x => x.BusinessId == record.Id);

                            if (oldscore != null)
                            {
                                await _trainScoreRecordAppService.Create(new CreateUserTrainScoreRecordInput()
                                {
                                    FromId   = model.Id,
                                    FromType = TrainScoreFromType.CourseLearn,
                                    Score    = oldscore.Score,
                                    UserId   = user.Id
                                });
                            }
                        }
                    }
                }
                await _courseRecordRepository.UpdateAsync(record);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 修改一个UserCourseExperience
        /// </summary>
        /// <param name="input">实体</param>
        /// <returns></returns>
        public async Task Update(UpdateUserCourseExperienceInput input)
        {
            if (input.InStanceId != Guid.Empty)
            {
                var dbmodel = await _repository.FirstOrDefaultAsync(x => x.Id == input.InStanceId);

                if (dbmodel == null)
                {
                    throw new UserFriendlyException((int)ErrorCode.CodeValErr, "该数据不存在!");
                }
                var logModel = new UserCourseExperience();
                if (input.IsUpdateForChange)
                {
                    logModel = dbmodel.DeepClone <UserCourseExperience>();
                }
                var dbexp = string.IsNullOrEmpty(dbmodel.ExperienceId)
                    ? new List <string>()
                    : dbmodel.ExperienceId.Split(',').ToList();
                if (string.IsNullOrEmpty(input.ExperienceId))
                {
                    throw new UserFriendlyException((int)ErrorCode.CodeValErr, "请至少选择一条心得体会汇总!");
                }
                var inputexp = input.ExperienceId.Split(',').ToList();
                var newexp   = inputexp.Except(dbexp).ToList();
                dbexp.AddRange(newexp);
                dbmodel.ExperienceId = string.Join(",", dbexp);
                await _repository.UpdateAsync(dbmodel);

                if (input.IsUpdateForChange)
                {
                    var flowModel = _workFlowCacheManager.GetWorkFlowModelFromCache(input.FlowId);
                    if (flowModel == null)
                    {
                        throw new UserFriendlyException((int)ErrorCode.CodeValErr, "流程不存在");
                    }
                    var logs = GetChangeModel(logModel).GetColumnAllLogs(GetChangeModel(dbmodel));
                    await _projectAuditManager.InsertAsync(logs, input.InStanceId.ToString(),
                                                           flowModel.TitleField.Table);
                }
                //采纳心得体会加积分
                var course = _courseRepository.Get(dbmodel.CourseId);
                var set    = await _courseSettingAppService.GetSetVal(course.LearnType, course.IsSpecial);

                newexp.ForEach(async x =>
                {
                    var exp   = _experienceRepository.Get(Guid.Parse(x));
                    exp.IsUse = true;
                    _experienceRepository.Update(exp);
                    if (set.ExperienceScore > 0)
                    {
                        await _trainScoreRecordAppService.Create(new CreateUserTrainScoreRecordInput()
                        {
                            FromId   = dbmodel.CourseId,
                            FromType = TrainScoreFromType.CourseExperience,
                            Score    = set.ExperienceScore,
                            UserId   = exp.CreatorUserId ?? 0
                        });
                    }
                });
            }
            else
            {
                throw new UserFriendlyException((int)ErrorCode.CodeValErr, "该数据不存在!");
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 执行减扣积分的后台任务
        /// </summary>
        /// <param name="courseId"></param>
        public async Task DeductionScore(Guid courseId)
        {
            //当用户必修课程在规定时间内没有修习完成,则需要扣除积分
            var course = await _courseRepository.GetAsync(courseId);

            if (course != null && course.LearnType != CourseLearnType.Selected && course.ComplateTime < DateTime.Now)
            {
                var chooseUserId = new List <long>();
                var failRecord   = new List <UserCourseRecord>();
                switch (course.LearnType)
                {
                case CourseLearnType.Must:
                    chooseUserId = course.LearnUser.Replace("u_", "").Split(",").Select(long.Parse).ToList();
                    break;

                case CourseLearnType.MustAll:
                    chooseUserId = UserManager.Users.Select(x => x.Id).ToList();
                    break;
                }
                //查询有课程记录的人
                var learnRecord = await _repository.GetAll()
                                  .Where(x => !x.IsDeleted && chooseUserId.Contains(x.UserId) && x.CourseId == courseId)
                                  .ToListAsync();

                //将所有人分为两组,有记录但未完成课程的人,无记录的人
                //未完成记录
                failRecord.AddRange(learnRecord.Where(x => x.IsComplete == null));
                //无记录的人
                var noRecordUserId = chooseUserId.Except(learnRecord.Select(x => x.UserId)).ToList();
                //将有课程记录但未完成的人标记为失败
                failRecord.ToList().ForEach(async x =>
                {
                    x.IsComplete = false;
                    await _repository.UpdateAsync(x);
                });
                //将没有课程记录的人增加课程记录并标记为失败
                noRecordUserId.ForEach(async x =>
                {
                    var norecord = new UserCourseRecord()
                    {
                        CourseId   = course.Id,
                        UserId     = x,
                        IsComplete = false,
                        Score      = 0,
                        LearnTime  = 0
                    };
                    await _repository.InsertAsync(norecord);
                    //加入失败记录
                    failRecord.Add(norecord);
                });
                //扣除积分
                var setScore = await _courseSettingAppService.GetSetVal(course.LearnType, course.IsSpecial);

                failRecord.ForEach(async x =>
                {
                    if (setScore.ClassHourScore > 0)
                    {
                        await _trainScoreRecordAppService.Create(new CreateUserTrainScoreRecordInput()
                        {
                            FromType   = TrainScoreFromType.CourseLearn,
                            FromId     = course.Id,
                            Score      = -setScore.ClassHourScore,
                            UserId     = x.UserId,
                            BusinessId = x.Id
                        });
                    }
                });
            }
            else
            {
                //关闭当前任务
                RecurringJob.RemoveIfExists($"usercoursefail-{courseId}");
            }
        }