/// <summary> /// 修改一个ProjectProgressConfig /// </summary> /// <param name="input">实体</param> /// <returns></returns> public async Task Update(ProjectProgressConfig input) { if (input.Id != Guid.Empty) { var dbmodel = await _repository.FirstOrDefaultAsync(x => x.Id == input.Id); if (dbmodel == null) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "该数据不存在。"); } dbmodel.ProjectBaseId = input.ProjectBaseId; dbmodel.FirstAuditKey = input.FirstAuditKey; dbmodel.JiliangKey = input.JiliangKey; dbmodel.JijiaKey = input.JijiaKey; dbmodel.SelfAuditKey = input.SelfAuditKey; dbmodel.SecondAuditKey = input.SecondAuditKey; dbmodel.LastAuditKey = input.LastAuditKey; await _repository.UpdateAsync(dbmodel); } else { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "该数据不存在。"); } }
/// <summary> /// 添加一个ProjectProgressConfig /// </summary> /// <param name="input">实体</param> /// <returns></returns> public async Task Create(CreateProjectProgressConfigInput input) { var newmodel = new ProjectProgressConfig() { ProjectBaseId = input.ProjectBaseId, FirstAuditKey = input.FirstAuditKey, JiliangKey = input.JiliangKey, JijiaKey = input.JijiaKey, SelfAuditKey = input.SelfAuditKey, SecondAuditKey = input.SecondAuditKey, LastAuditKey = input.LastAuditKey }; await _repository.InsertAsync(newmodel); }
/// <summary> /// 当前项目状态完成后修改项目状态和项目进度记录 /// </summary> /// <param name="taskId"></param> /// <param name="processId"></param> private void ChangeProjectStatus(Guid taskId, Guid processId) { var process = _repository.Get(processId); var project = _projectRepository.Get(process.ProjectBaseId); var hours = 0; //定时 var x = _projectProgressConfigRepository.GetAll().ToList(); var config = _projectProgressConfigRepository.GetAll().FirstOrDefault(ite => ite.ProjectBaseId == process.ProjectBaseId); if (config == null) { config = _projectProgressConfigRepository.GetAll().FirstOrDefault(ite => ite.ProjectBaseId.HasValue == false); } if (config == null) { //throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "未找到进度配置。"); config = new ProjectProgressConfig(); config.FirstAuditKey = 10; config.JiliangKey = 20; config.JijiaKey = 20; config.SelfAuditKey = 20; config.SecondAuditKey = 20; config.LastAuditKey = 10; } switch (project.ProjectStatus) { case ProjectStatus.在审: // hours = project.Days * 24 * config.FirstAuditKey / 100; project.ProjectStatus = ProjectStatus.初审; break; case ProjectStatus.初审: hours = project.Days * 24 * config.JiliangKey / 100; project.ProjectStatus = ProjectStatus.计量; process.FirstAuditComplateTime = DateTime.Now; var delayHour = process.FirstAuditComplateTime - process.CreationTime; delayHour = delayHour.Value.Add(new TimeSpan(0 - (project.Days * 24 * config.FirstAuditKey / 100), 0, 0)); process.FirstAduitDelayHour = (int)delayHour.Value.TotalHours; break; case ProjectStatus.计量: hours = project.Days * 24 * config.JijiaKey / 100; project.ProjectStatus = ProjectStatus.记价; process.JiliangComplateTime = DateTime.Now; delayHour = process.JiliangComplateTime - process.FirstAuditComplateTime; delayHour = delayHour.Value.Add(new TimeSpan(0 - (project.Days * 24 * config.JiliangKey / 100), 0, 0)); process.JiliangDelayHour = (int)delayHour.Value.TotalHours; break; case ProjectStatus.记价: hours = project.Days * 24 * config.SelfAuditKey / 100; project.ProjectStatus = ProjectStatus.内核; process.JijiaComplateTime = DateTime.Now; delayHour = process.JijiaComplateTime - process.JiliangComplateTime; delayHour = delayHour.Value.Add(new TimeSpan(0 - (project.Days * 24 * config.JijiaKey / 100), 0, 0)); process.JijiaDelayHour = (int)delayHour.Value.TotalHours; break; case ProjectStatus.内核: hours = project.Days * 24 * config.SecondAuditKey / 100; project.ProjectStatus = ProjectStatus.核; process.SelfAuditComplateTime = DateTime.Now; delayHour = process.SelfAuditComplateTime - process.JijiaComplateTime; delayHour = delayHour.Value.Add(new TimeSpan(0 - (project.Days * 24 * config.SelfAuditKey / 100), 0, 0)); process.SelfAuditDelayHour = (int)delayHour.Value.TotalHours; break; case ProjectStatus.核: hours = project.Days * 24 * config.LastAuditKey / 100; project.ProjectStatus = ProjectStatus.总核; process.SecondAuditComplateTime = DateTime.Now; delayHour = process.SecondAuditComplateTime - process.SelfAuditComplateTime; delayHour = delayHour.Value.Add(new TimeSpan(0 - (project.Days * 24 * config.SecondAuditKey / 100), 0, 0)); process.SecondAuditDelayHour = (int)delayHour.Value.TotalHours; break; case ProjectStatus.总核: process.LastAuditComplateTime = DateTime.Now; delayHour = process.LastAuditComplateTime - process.SecondAuditComplateTime; delayHour = delayHour.Value.Add(new TimeSpan(0 - (project.Days * 24 * config.LastAuditKey / 100), 0, 0)); process.LastAuditDelayHour = (int)delayHour.Value.TotalHours; break; } _projectRepository.Update(project); _repository.Update(process); _backgroudWorkJobWithHangFire.CreatProjectProgressTask(process.Id, taskId, hours); CurrentUnitOfWork.SaveChanges(); }