Example #1
0
        public async Task BirthdayProcessing()
        {
            var users = await _userRepository.CustomFind(x => x.BithDate.Value.Month == DateTime.Now.Month && x.BithDate.Value.Day == DateTime.Now.Day);

            var birthdaySource = await _userPunctuationSourceRepository.GetById(15);

            var punctuationList = new List <UserPunctuation>();

            foreach (var item in users)
            {
                punctuationList.Add(new UserPunctuation
                {
                    CreatedAt         = DateTime.Now,
                    CurrentMonth      = DateTime.Now.Month,
                    CurrentYear       = DateTime.Now.Year,
                    Description       = "PONTUAÇÃO POR ANIVERSÁRIO. PARABÉNS!",
                    OperationType     = 'C',
                    Punctuation       = 5,
                    ReferenceEntityId = 0,
                    User = item,
                    UserPunctuationSource = birthdaySource
                });
            }

            _userPunctuationRepository.SaveMany(punctuationList);

            await _unitOfWork.CommitAsync();
        }
Example #2
0
        public async Task ProcessesAcademyTrainingManagers()
        {
            if (DateTime.Now.Day == 25)
            {
                var userPunctuationList = new List <UserPunctuation>();
                var source = await _userPunctuationSourceRepository.GetById((int)UserPunctuationSourceEnum.TrainingManagers);

                var managers = await _shopUserRepository.CustomFind(x =>
                                                                    x.User.Office.Id == (int)OfficeEnum.Manager &&
                                                                    (x.User.UserStatus.Id == (int)UserStatusEnum.Active || x.User.UserStatus.Id == (int)UserStatusEnum.PasswordExpired),
                                                                    x => x.User,
                                                                    x => x.Shop);

                var lastTraining = await _trainingRepository.CustomFind(x => x.CurrentMonth == DateTime.Now.AddMonths(-1).Month &&
                                                                        x.CurrentYear == DateTime.Now.AddMonths(-1).Year && !x.hasTrainingMaterial && x.trainingKind == 2);

                var trainingValidation = lastTraining.Count() >= 2 ? 1 : 0;

                var trainingUser = await _trainingUserPointsRepository.CustomFind(x =>
                                                                                  x.ResultId == (int)TrainingResultEnum.Approved &&
                                                                                  x.TrainingEndedAt.Month == DateTime.Now.AddMonths(-1).Month &&
                                                                                  x.TrainingEndedAt.Year == DateTime.Now.AddMonths(-1).Year,
                                                                                  x => x.User);

                _logger.Info($"processamento pontuacao gerente treinamento - iniciado processamento");

                foreach (var item in managers)
                {
                    var punctuation = await _userPunctuationRepository.CustomFind(x =>
                                                                                  x.User.Id == item.User.Id &&
                                                                                  x.CurrentMonth == DateTime.Now.AddMonths(-1).Month &&
                                                                                  x.CurrentYear == DateTime.Now.AddMonths(-1).Year &&
                                                                                  x.UserPunctuationSource.Id == (int)UserPunctuationSourceEnum.TrainingManagers);

                    if (!punctuation.Any())
                    {
                        var shopUsers = await _shopUserRepository.CustomFind(x =>
                                                                             x.Shop.Id == item.Shop.Id &&
                                                                             x.User.Office.Id == (int)OfficeEnum.Salesman &&
                                                                             (x.User.UserStatus.Id == (int)UserStatusEnum.Active || x.User.UserStatus.Id == (int)UserStatusEnum.PasswordExpired || (x.User.UserStatus.Id == (int)UserStatusEnum.PreRegistration && (DateTime.Now - x.User.CreatedAt).TotalDays >= 30)),
                                                                             x => x.User);

                        var totalUsers = shopUsers.Select(x => x.User).Count();

                        var trainingUserFiltered = trainingUser.Where(x =>
                                                                      shopUsers.Select(s => s.User.Id).Contains(x.User.Id)).ToList();

                        if (trainingUserFiltered.Any())
                        {
                            var totalUsersTrainingComplete = trainingUserFiltered.
                                                             GroupBy(x => new { x.Id, x.User }).
                                                             Select(x => new
                            {
                                userId = x.Key.User.Id,
                                total  = x.Select(s => s.Id).Count()
                            }).
                                                             GroupBy(x => new { x.userId, x.total }).
                                                             Select(x => new
                            {
                                user  = x.Key.userId,
                                total = x.Sum(y => y.total)
                            }).ToList().
                                                             Count(x => x.total > trainingValidation);

                            if (totalUsers > 0)
                            {
                                var porcentageTrainingCompleted = (totalUsersTrainingComplete * 100) / totalUsers;

                                if (porcentageTrainingCompleted >= 80)
                                {
                                    userPunctuationList.Add(new UserPunctuation
                                    {
                                        CreatedAt         = DateTime.Now,
                                        CurrentMonth      = DateTime.Now.AddMonths(-1).Month,
                                        CurrentYear       = DateTime.Now.AddMonths(-1).Year,
                                        Description       = "PONTUAÇÃO TREINAMENTO GERENTE",
                                        OperationType     = 'C',
                                        Punctuation       = 100,
                                        ReferenceEntityId = 0,
                                        User = item.User,
                                        UserPunctuationSource = source
                                    });

                                    _logger.Info($"processamento pontuacao gerente treinamento - adicionado na fila 100 pontos para usuario {item.User.Id}");
                                }
                            }
                        }
                    }
                }

                if (userPunctuationList.Any())
                {
                    _userPunctuationRepository.SaveMany(userPunctuationList);
                    await _unitOfWork.CommitAsync();

                    _logger.Info($"processamento pontuacao gerente treinamento - concluido processamento");
                }
                else
                {
                    _logger.Info($"processamento pontuacao gerente treinamento - nenhum gerente foi pontuado");
                }
            }
        }