在
usingAbp.AutoMapper; usingAbp.Modules; usingAbp.Quartz; usingAbp.Reflection.Extensions; usingAbp.Threading.BackgroundWorkers; usingEvaluationSystem.Authorization; usingEvaluationSystem.Pc; usingEvaluationSystem.TimmerManager; usingQuartz; namespaceEvaluationSystem { [DependsOn( typeof(AbpQuartzModule), typeof(EvaluationSystemCoreModule), typeof(AbpAutoMapperModule))] public classEvaluationSystemApplicationModule : AbpModule { public override voidPreInitialize() { Configuration.Authorization.Providers.Add<EvaluationSystemAuthorizationProvider>(); } //LearningMpaAbpApplicationModule.cs public override voidPostInitialize() { //注册后台工作者 循环算分 var workManager = IocManager.Resolve<IBackgroundWorkerManager>(); workManager.Add(IocManager.Resolve<MakeInactiveUsersPassiveWorker>()); workManager.Start(); var _jobManager = IocManager.Resolve<IQuartzScheduleJobManager>(); _jobManager.ScheduleAsync<TimePcSpaceShowJob>( job =>{ job.WithIdentity("TimePcSpaceShowJob", "TimmerManager") .WithDescription("A job to simply write logs."); }, trigger =>{ trigger.StartNow().WithCronSchedule("0 0 1 * * ?"); }); } public override voidInitialize() { var thisAssembly = typeof(EvaluationSystemApplicationModule).GetAssembly(); IocManager.RegisterAssemblyByConvention(thisAssembly); Configuration.Modules.AbpAutoMapper().Configurators.Add( cfg =>{ cfg.CreateMap<Abp.Authorization.Permission, Authorization.Permissions.Dto.FlatPermissionWithLevelDto >(); cfg.CreateMap<EvaluationSystem.ClassInfo.Dto.CreateOrUpdateClassInput, EntityDesign.ClassManage>(); cfg.CreateMap<EntityDesign.ClassManage, EvaluationSystem.ClassInfo.Dto.ClassOutput>(); } ); } } }
任务
TimePcSpaceShowJob
usingAbp.Dependency; usingAbp.Quartz; usingQuartz; usingSystem; usingSystem.Collections.Generic; usingSystem.Text; usingSystem.Threading.Tasks; namespaceEvaluationSystem.TimmerManager { public classTimePcSpaceShowJob : JobBase, ITransientDependency { public overrideTask Execute(IJobExecutionContext context) { returnTask.CompletedTask; } } }
另一种定时任务
MakeInactiveUsersPassiveWorker
usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingAbp.Dependency; usingAbp.Domain.Repositories; usingAbp.Domain.Uow; usingAbp.MultiTenancy; usingAbp.Runtime.Caching; usingAbp.Runtime.Session; usingAbp.Threading.BackgroundWorkers; usingAbp.Threading.Timers; usingAbp.Timing; usingAbp.UI; usingEvaluationSystem.EntityDesign; usingEvaluationSystem.MultiTenancy; usingEvaluationSystem.SchoolTerm; usingMicrosoft.EntityFrameworkCore; namespaceEvaluationSystem.Pc { public classMakeInactiveUsersPassiveWorker : PeriodicBackgroundWorkerBase, ISingletonDependency { private readonly IRepository<Tenant, int>_tenantRepository; private readonlyISchoolTermAppService _iSchoolTermAppService; private readonlyICacheManager _cacheManager; private readonlyAbp.RealTime.IOnlineClientManager _iOnlineClientManager; private readonly IRepository<EntityDesign.ImmeEvalBaseSetting, Guid>_immeEvalBaseSettingRepository; private readonly IRepository<EntityDesign.StudentGetBadge, Guid>_studentGetBadgeRepository; private readonly IRepository<EntityDesign.Canton, Guid>_cantonRepository; private readonly IRepository<EntityDesign.SchoolInformation, Guid>_schoolInformationRepository; private readonly IRepository<EntityDesign.Student, Guid>_studentRepository; private readonly IRepository<EntityDesign.Teacher, Guid>_teacherRepository; private readonly IRepository<EntityDesign.SchoolDepart, Guid>_schoolDepartRepository; private readonly IRepository<EntityDesign.SpaceShow, Guid>_spaceShowRepository; private readonly IRepository<EntityDesign.SpaceShowType, Guid>_spaceShowTypeRepository; private readonly IRepository<EntityDesign.AdminUser, Guid>_adminUserRepository; private readonly IRepository<EntityDesign.DictionaryData, Guid>_dictionaryDataRepository; private readonly IRepository<EntityDesign.PersonQulitativeScore, Guid>_personQulitativeScoreRepository; private readonly IRepository<EntityDesign.ClassManage, Guid>_classManageRepository; private readonly IRepository<EvaluationSystem.EntityDesign.PersonEvaluateTask, Guid>_personEvaluateTaskRepository; private readonly IRepository<EvaluationSystem.EntityDesign.AppraiseLevel, Guid>_appraiseLevelRepository; private readonly IRepository<EvaluationSystem.EntityDesign.Appraise, Guid>_appraiseRepository; private readonly IRepository<EvaluationSystem.EntityDesign.QuotaClass, Guid>_quotaClassRepository; private readonly IRepository<EvaluationSystem.EntityDesign.EvaluateReportArea, Guid>_evaluateReportAreaRepository; private readonly IRepository<EvaluationSystem.EntityDesign.EvaluateReportSchool, Guid>_evaluateReportSchoolRepository; publicMakeInactiveUsersPassiveWorker(AbpTimer timer, ICacheManager cacheManager, Abp.RealTime.IOnlineClientManager iOnlineClientManager, IRepository<EntityDesign.SchoolInformation, Guid>schoolInformationRepository, IRepository<EntityDesign.Student, Guid>studentRepository, ISchoolTermAppService iSchoolTermAppService, IRepository<EntityDesign.Teacher, Guid>teacherRepository, IRepository<EntityDesign.DictionaryData, Guid>dictionaryDataRepository, IRepository<EvaluationSystem.EntityDesign.QuotaClass, Guid>quotaClassRepository, IRepository<EvaluationSystem.EntityDesign.AppraiseLevel, Guid>appraiseLevelRepository, IRepository<EvaluationSystem.EntityDesign.Appraise, Guid>appraiseRepository, IRepository<EntityDesign.Canton, Guid>cantonRepository, IRepository<EntityDesign.ImmeEvalBaseSetting, Guid>immeEvalBaseSettingRepository, IRepository<EntityDesign.PersonQulitativeScore, Guid>personQulitativeScoreRepository, IRepository<EntityDesign.SpaceShow, Guid>spaceShowRepository, IRepository<EntityDesign.ClassManage, Guid>classManageRepository, IRepository<EntityDesign.SpaceShowType, Guid>spaceShowTypeRepository, IRepository<Tenant, int>tenantRepository, IRepository<EvaluationSystem.EntityDesign.EvaluateReportArea, Guid>evaluateReportAreaRepository, IRepository<EvaluationSystem.EntityDesign.EvaluateReportSchool, Guid>evaluateReportSchoolRepository, IRepository<EntityDesign.SchoolDepart, Guid>schoolDepartRepository, IRepository<EntityDesign.StudentGetBadge, Guid>studentGetBadgeRepository, IRepository<EvaluationSystem.EntityDesign.PersonEvaluateTask, Guid>personEvaluateTaskRepository, IRepository<EntityDesign.AdminUser, Guid>adminUserRepository ) : base(timer) { Timer.Period = 1000 * 60 * 60 * 24; //5 seconds (good for tests, but normally will be more) Start(); _cacheManager =cacheManager; _iOnlineClientManager =iOnlineClientManager; _schoolInformationRepository =schoolInformationRepository; _studentRepository =studentRepository; _evaluateReportAreaRepository =evaluateReportAreaRepository; _evaluateReportSchoolRepository =evaluateReportSchoolRepository; _teacherRepository =teacherRepository; _iSchoolTermAppService =iSchoolTermAppService; _personEvaluateTaskRepository =personEvaluateTaskRepository; _dictionaryDataRepository =dictionaryDataRepository; _immeEvalBaseSettingRepository =immeEvalBaseSettingRepository; _personQulitativeScoreRepository =personQulitativeScoreRepository; _cantonRepository =cantonRepository; _classManageRepository =classManageRepository; _spaceShowRepository =spaceShowRepository; _spaceShowTypeRepository =spaceShowTypeRepository; _adminUserRepository =adminUserRepository; _schoolDepartRepository =schoolDepartRepository; _tenantRepository =tenantRepository; _quotaClassRepository =quotaClassRepository; _appraiseRepository =appraiseRepository; _studentGetBadgeRepository =studentGetBadgeRepository; _appraiseLevelRepository =appraiseLevelRepository; } [UnitOfWork] protected override voidDoWork() { var tenants = _tenantRepository.GetAll().Where(x =>x.IsActive); foreach (var tenant intenants) { using(CurrentUnitOfWork.SetTenantId(tenant.Id)) { var immeEvalBaseSetting =_immeEvalBaseSettingRepository.GetAll().FirstOrDefault(); if (immeEvalBaseSetting == null) { throw new UserFriendlyException("请先维护[即时评价基础设置]"); } var team =_iSchoolTermAppService.GetCurrent().Result; var quotaClass = _quotaClassRepository.GetAll().Where(x => x.PId ==Guid.Empty).ToList(); //所有学校 var schools =_schoolInformationRepository.GetAll(); //所有区域分 var cantons =_cantonRepository.GetAll(); //先清空 _evaluateReportAreaRepository.Delete(x => x.TermId ==team.Id); _evaluateReportSchoolRepository.Delete(x => x.TermId ==team.Id); foreach (var canton incantons) { var schoolsTemp = schools.Where(x => x.CanTonId ==canton.Id); var query2 = from p in_personQulitativeScoreRepository.GetAll() join c in_classManageRepository.GetAll() on p.ClassId equals c.Id join schoolInformation inschoolsTemp on c.SchoolId equals schoolInformation.Id join task in_personEvaluateTaskRepository.GetAll() on p.EvaluationTaskId equals task.Id select new{ p, c, schoolInformation, task }; foreach (var v inquotaClass) { decimal lastScore = 0; lastScore = lastScore +immeEvalBaseSetting.StudentBaseScore.GetValueOrDefault(); int score_1 = 0; int count_1 = 0; int score_2 = 0; int count_2 = 0; var listTemp = query2.Where(x => x.p.FirstLevelQuotaId ==v.Id).ToList(); foreach (var item2 inlistTemp) { //定量 if (item2.p.TaskType == 1) { score_1 = score_1 +item2.p.Score; count_1++; }//定性 else if (item2.p.TaskType == 2) { if (item2.p.Level == 1) { score_2 = score_2 +item2.task.ExcellentValue; } else if (item2.p.Level == 2) { score_2 = score_2 +item2.task.GoodValue; } else if (item2.p.Level == 3) { score_2 = score_2 +item2.task.StandardValue; } else if (item2.p.Level == 4) { score_2 = score_2 +item2.task.NeedHelpValue; } count_2++; } } if (count_1 > 0) { lastScore = lastScore + (score_1 / count_1) *immeEvalBaseSetting.QuantifyWeight.GetValueOrDefault(); } if (count_2 > 0) { lastScore = lastScore + (score_2 /count_2); } var studentGetBadge = _studentGetBadgeRepository.GetAll().Count(x =>x.TermId == team.Id && x.FirstLevelQuatoId ==v.Id); var studentGetBadgeScore = Convert.ToInt32(studentGetBadge *immeEvalBaseSetting.BadgeScore); //如果大于每类徽章最高得分,则直接取最高得分 if (studentGetBadgeScore >immeEvalBaseSetting.HighestScore) { studentGetBadgeScore = (int)immeEvalBaseSetting.HighestScore; } lastScore = lastScore +studentGetBadgeScore; _evaluateReportAreaRepository.Insert(newEvaluateReportArea() { AreaId =canton.Id, TermId =team.Id, FirstLevelQuotaId =v.Id, Score =lastScore }); } } //所有学校分 foreach (var school inschools) { var schoolsTemp = schools.Where(x => x.Id ==school.Id); var query2 = from p in_personQulitativeScoreRepository.GetAll() join c in_classManageRepository.GetAll() on p.ClassId equals c.Id join schoolInformation inschoolsTemp on c.SchoolId equals schoolInformation.Id join task in_personEvaluateTaskRepository.GetAll() on p.EvaluationTaskId equals task.Id select new{ p, c, schoolInformation, task }; foreach (var v inquotaClass) { decimal lastScore = 0; lastScore = lastScore +immeEvalBaseSetting.StudentBaseScore.GetValueOrDefault(); int score_1 = 0; int count_1 = 0; int score_2 = 0; int count_2 = 0; var listTemp = query2.Where(x => x.p.FirstLevelQuotaId ==v.Id).ToList(); foreach (var item2 inlistTemp) { //定量 if (item2.p.TaskType == 1) { score_1 = score_1 +item2.p.Score; count_1++; }//定性 else if (item2.p.TaskType == 2) { if (item2.p.Level == 1) { score_2 = score_2 +item2.task.ExcellentValue; } else if (item2.p.Level == 2) { score_2 = score_2 +item2.task.GoodValue; } else if (item2.p.Level == 3) { score_2 = score_2 +item2.task.StandardValue; } else if (item2.p.Level == 4) { score_2 = score_2 +item2.task.NeedHelpValue; } count_2++; } } if (count_1 > 0) { lastScore = lastScore + (score_1 / count_1) *immeEvalBaseSetting.QuantifyWeight.GetValueOrDefault(); } if (count_2 > 0) { lastScore = lastScore + (score_2 /count_2); } var studentGetBadge = _studentGetBadgeRepository.GetAll().Count(x =>x.TermId == team.Id && x.FirstLevelQuatoId ==v.Id); var studentGetBadgeScore = Convert.ToInt32(studentGetBadge *immeEvalBaseSetting.BadgeScore); //如果大于每类徽章最高得分,则直接取最高得分 if (studentGetBadgeScore >immeEvalBaseSetting.HighestScore) { studentGetBadgeScore = (int)immeEvalBaseSetting.HighestScore; } lastScore = lastScore +studentGetBadgeScore; _evaluateReportSchoolRepository.Insert(newEvaluateReportSchool() { SchoolId =school.Id, TermId =team.Id, FirstLevelQuotaId =v.Id, Score =lastScore }); } } CurrentUnitOfWork.SaveChanges(); } } } } }