Beispiel #1
0
        public async Task <IResultModel> Add(JobAddModel model)
        {
            var entity = _mapper.Map <JobEntity>(model);

            entity.JobKey = $"{model.JobGroup}.{model.Code}";
            entity.Status = JobStatus.Stop;

            if (await _jobRepository.ExistsAsync(m => m.JobKey == entity.JobKey))
            {
                return(ResultModel.Failed($"当前任务组{entity.JobGroup}已存在任务编码${entity.Code}"));
            }

            //是否立即启动
            if (model.Start)
            {
                var result = await AddJob(entity);

                if (!result.Successful)
                {
                    return(result);
                }

                entity.Status = JobStatus.Running;
            }

            return(ResultModel.Result(await _jobRepository.InsertAsync(entity)));
        }
Beispiel #2
0
        public async Task <IResultModel> Add(JobAddModel model)
        {
            var entity = _mapper.Map <JobEntity>(model);

            entity.JobKey  = $"{model.Group}.{model.Code}";
            entity.Status  = JobStatus.Pause;//默认添加后暂停,需要手动启动
            entity.EndDate = entity.EndDate.AddDays(1);

            if (await _repository.Exists(entity))
            {
                return(ResultModel.Failed($"当前任务组{entity.Group}已存在任务编码${entity.Code}"));
            }

            using (var tran = _repository.BeginTransaction())
            {
                if (await _repository.AddAsync(entity, tran))
                {
                    var result = await AddJob(entity);

                    if (!result.Successful)
                    {
                        return(result);
                    }

                    tran.Commit();

                    return(ResultModel.Success());
                }
            }

            return(ResultModel.Failed("添加失败"));
        }
Beispiel #3
0
        public async Task <IResultModel> Add(JobAddModel model)
        {
            var entity = _mapper.Map <JobEntity>(model);

            entity.JobKey  = $"{model.Group}.{model.Code}";
            entity.Status  = JobStatus.Pause;//Ĭ�����Ӻ���ͣ����Ҫ�ֶ�����
            entity.EndDate = entity.EndDate.AddDays(1);

            if (await _repository.Exists(entity))
            {
                return(ResultModel.Failed($"��ǰ������{entity.Group}�Ѵ����������${entity.Code}"));
            }

            using (var uow = _dbContext.NewUnitOfWork())
            {
                if (await _repository.AddAsync(entity, uow))
                {
                    var result = await AddJob(entity);

                    if (!result.Successful)
                    {
                        return(result);
                    }

                    uow.Commit();

                    return(ResultModel.Success());
                }
            }

            return(ResultModel.Failed("����ʧ��"));
        }
        public async Task <IResultModel> Add(JobAddModel model)
        {
            var entity = _mapper.Map <JobEntity>(model);

            entity.JobKey  = $"{model.Group}.{model.Code}";
            entity.Status  = JobStatus.Stop;
            entity.EndDate = entity.EndDate.AddDays(1);
            entity.JobType = JobType.Normal;

            if (await _repository.Exists(entity))
            {
                return(ResultModel.Failed($"当前任务组{entity.Group}已存在任务编码${entity.Code}"));
            }

            //是否立即启动
            if (model.Start)
            {
                var result = await AddJob(entity);

                if (!result.Successful)
                {
                    return(result);
                }

                entity.Status = JobStatus.Running;
            }

            return(ResultModel.Result(await _repository.AddAsync(entity)));
        }
Beispiel #5
0
        public async Task <IResultModel> Add(JobAddModel model)
        {
            var entity = _mapper.Map <JobEntity>(model);
            //if (await _repository.Exists(entity))
            //{
            //return ResultModel.HasExists;
            //}

            var result = await _repository.AddAsync(entity);

            return(ResultModel.Result(result));
        }
 public Task <IResultModel> Add(JobAddModel model)
 {
     return(_service.Add(model));
 }