ABP集成Quartz

摘要:
在usingAbp.AutoMapper;usingAbp.Modules;usingAbp.Quartz;usingAbp.Reflection.Extensions;usingAbp.Threading.BackgroundWorkers;usingEvaluationSystem.Authorization;usingEvaluationSystem.Pc;usingEvaluationSy

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();
                }
            }

        }
    }
}

免责声明:文章转载自《ABP集成Quartz》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇程序集、应用程序配置及App.config和YourSoft.exe.config .Sqlserver常用函数之ident_current下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

静态文件cdn自解析生成相对路径

一、场景和目标:用户上传一个包含 index.html 的静态资源压缩包,资源内所有文件都是相互依赖的,不需要用户对内部文件内容做任何特殊处理,仅通过服务端逻辑处理达到用户访问 http://xxx.xxx/guid/index.html 时就可以得到这个资源的所有数据并正常浏览。 二、技术:nodejs、expressnpm 包:decompress、r...

实现定时任务Quartz替代Timer

Quartz.net 简介 Quartz.NET是一个开源的作业调度框架,非常适合在平时的工作中,定时轮询数据库同步,定时邮件通知,定时处理数据等。 Quartz.NET允许开发人员根据时间间隔(或天)来调度作业。它实现了作业和触发器的多对多关系,还能把多个作业与不同的触发器关联。整合了 Quartz.NET的应用程序可以重用来自不同事件的作业,还可以为一...

ASP.NET Core使用Quartz定时调度

在应用程序开发过程中,经常会需要定时任务调度功能,本篇博客介绍Asp.net Core如何使用Quartz完成定时调度 一、Quartz使用步骤 创建调度器scheduler,并开启 创建Job作业 创建tigger触发器 把作业和触发器放入调度器中 二、Quartz的API IScheduler - 与 scheduler 进行交互的主要接口 IJ...

Quartz中时间表达式的设置-----corn表达式

Quartz中时间表达式的设置-----corn表达式 时间格式: <!-- s m h d m w(?) y(?) -->,   分别相应: 秒>分>小时>日>月>周>年,  举例: 1.每天什么时候运行:        <value>0 59 23 * * ?</value>...

基础概念总结(spring security、Quartz、JUnit测试)

1、Spring Security 的大体框架和原理 (1)在web.xml中配置过滤器,这样就可以控制这个项目的每个请求。 (2)在applicationContext.xml配置,其中http标签配置如何截用户请求,和配置用户认证(固定用户、使用数据库管理用户)。 (3)过滤器最上层为HttpSessionContextIntegrationFilt...

《Excel VBA编程开发》附加内容1:VBA生成GUID

  1.1 VBA生成GUID 全局唯一标识符(GUID,Globally Unique Identifier)是一种由算法生成的二进制长度为128位的数字标识符。GUID主要用于在拥有多个节点、多台计算机的网络或系统中。在理想情况下,任何计算机和计算机集群都不会生成两个相同的GUID。GUID 的总数达到了2^128(3.4×10^38)个,所以随机生成...