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("添加失败")); }