|
@@ -119,6 +119,76 @@ namespace wispro.sp.api.Controllers
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void _SaveProjectWorkContent(spDbContext dbContext,ProjectContents saveObj)
|
|
|
+ {
|
|
|
+ if (saveObj.ProjectContentRecord.Id == 0)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(saveObj.ProjectContentRecord.ProjectNo))
|
|
|
+ {
|
|
|
+ throw new ApplicationException("没有选择专案!");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ saveObj.ProjectContentRecord.Project = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ var currentUser = Context.Staffs.FirstOrDefault(s => s.Name == User.Identity.Name);
|
|
|
+ saveObj.ProjectContentRecord.StaffId = currentUser.Id;
|
|
|
+
|
|
|
+ Context.ProjectContentRecords.Add(saveObj.ProjectContentRecord);
|
|
|
+ Context.SaveChanges();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var temObj = Context.ProjectContentRecords.FirstOrDefault(p => p.Id == saveObj.ProjectContentRecord.Id);
|
|
|
+ temObj.CaseCoefficient = saveObj.ProjectContentRecord.CaseCoefficient;
|
|
|
+ temObj.Point = saveObj.ProjectContentRecord.Point;
|
|
|
+ temObj.ReviewerId = saveObj.ProjectContentRecord.ReviewerId;
|
|
|
+ //temObj.StaffId = saveObj.ProjectContentRecord.StaffId;
|
|
|
+ temObj.State = saveObj.ProjectContentRecord.State;
|
|
|
+ dbContext.SaveChanges();
|
|
|
+ saveObj.ProjectContentRecord = temObj;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (var temContent in saveObj.ProjectWorkContents)
|
|
|
+ {
|
|
|
+ switch (temContent.modifyState)
|
|
|
+ {
|
|
|
+ case ModifyState.Deleted:
|
|
|
+ dbContext.Database.ExecuteSqlRaw($"Delete from ProjectWorkContent where id={temContent.Id}");
|
|
|
+
|
|
|
+ break;
|
|
|
+ case ModifyState.Modified:
|
|
|
+ var modifyContent = Context.ProjectWorkContents.FirstOrDefault(p => p.Id == temContent.Id);
|
|
|
+ if (modifyContent != null)
|
|
|
+ {
|
|
|
+ modifyContent.Content = temContent.Content;
|
|
|
+ modifyContent.ActualPerformance = temContent.ActualPerformance;
|
|
|
+ modifyContent.DifficultFactor = temContent.DifficultFactor;
|
|
|
+ modifyContent.FinalPerformance = temContent.FinalPerformance;
|
|
|
+ modifyContent.TakeTime = temContent.TakeTime;
|
|
|
+ modifyContent.TimeSpan = temContent.TimeSpan;
|
|
|
+ modifyContent.WorkDate = temContent.WorkDate;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ModifyState.New:
|
|
|
+ var newContent = new ProjectWorkContent();
|
|
|
+ newContent.Content = temContent.Content;
|
|
|
+ newContent.ActualPerformance = temContent.ActualPerformance;
|
|
|
+ newContent.DifficultFactor = temContent.DifficultFactor;
|
|
|
+ newContent.FinalPerformance = temContent.FinalPerformance;
|
|
|
+ newContent.TakeTime = temContent.TakeTime;
|
|
|
+ newContent.TimeSpan = temContent.TimeSpan;
|
|
|
+ newContent.WorkDate = temContent.WorkDate;
|
|
|
+ newContent.ContentRecordId = saveObj.ProjectContentRecord.Id;
|
|
|
+
|
|
|
+ Context.ProjectWorkContents.Add(newContent);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ dbContext.SaveChanges();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public ApiSaveResponse SaveProjectWorkContent(ProjectContents saveObj)
|
|
|
{
|
|
|
ApiSaveResponse ret = new ApiSaveResponse();
|
|
@@ -128,78 +198,93 @@ namespace wispro.sp.api.Controllers
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- if (saveObj.ProjectContentRecord.Id == 0)
|
|
|
+ _SaveProjectWorkContent(Context, saveObj);
|
|
|
+
|
|
|
+ t.Commit();
|
|
|
+ }
|
|
|
+ catch(Exception ex)
|
|
|
+ {
|
|
|
+ t.Rollback();
|
|
|
+ ret.Success = false;
|
|
|
+ ret.ErrorMessage = ex.Message;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ApiSaveResponse ReviewProjectWorkContent(List<ProjectContents> saveObjs)
|
|
|
+ {
|
|
|
+ ApiSaveResponse ret = new ApiSaveResponse();
|
|
|
+ ret.Success = true;
|
|
|
+ var Reviewer = Context.Staffs.FirstOrDefault(p=>p.Name == User.Identity.Name);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ using (var t = Context.Database.BeginTransaction())
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ foreach (var saveObj in saveObjs)
|
|
|
{
|
|
|
- if(string.IsNullOrEmpty(saveObj.ProjectContentRecord.ProjectNo))
|
|
|
+ if (Reviewer.Id != saveObj.ProjectContentRecord.ReviewerId )
|
|
|
{
|
|
|
ret.Success = false;
|
|
|
- ret.ErrorMessage = "没有选择专案!";
|
|
|
- return ret;
|
|
|
+ ret.ErrorMessage = "只有指定审核人员才能操作!";
|
|
|
}
|
|
|
- else
|
|
|
+
|
|
|
+ saveObj.ProjectContentRecord.ReviewerId = Reviewer.Id;
|
|
|
+ PerformanceItem item = new PerformanceItem();
|
|
|
+
|
|
|
+ if (saveObj.ProjectContentRecord.State == 2)
|
|
|
{
|
|
|
- saveObj.ProjectContentRecord.Project = null;
|
|
|
+ item = Context.PerformanceItems.FirstOrDefault(p=>
|
|
|
+ p.CaseNo == saveObj.ProjectContentRecord.ProjectNo &&
|
|
|
+ p.ItemStaffs.Where(s=>s.DoPersonId == saveObj.ProjectContentRecord.StaffId).Count()>0 &&
|
|
|
+ p.CalMonthId == saveObj.ProjectContentRecord.CalMonthId);
|
|
|
}
|
|
|
|
|
|
- var currentUser = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
|
|
|
- saveObj.ProjectContentRecord.StaffId = currentUser.Id;
|
|
|
-
|
|
|
- Context.ProjectContentRecords.Add(saveObj.ProjectContentRecord);
|
|
|
- Context.SaveChanges();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var temObj = Context.ProjectContentRecords.FirstOrDefault(p => p.Id == saveObj.ProjectContentRecord.Id);
|
|
|
- temObj.CaseCoefficient = saveObj.ProjectContentRecord.CaseCoefficient;
|
|
|
- temObj.Point = saveObj.ProjectContentRecord.Point;
|
|
|
- temObj.ReviewerId = saveObj.ProjectContentRecord.ReviewerId;
|
|
|
- //temObj.StaffId = saveObj.ProjectContentRecord.StaffId;
|
|
|
- temObj.State = saveObj.ProjectContentRecord.State;
|
|
|
- Context.SaveChanges();
|
|
|
- saveObj.ProjectContentRecord = temObj;
|
|
|
- }
|
|
|
+ saveObj.ProjectContentRecord.State = 2;
|
|
|
|
|
|
- foreach (var temContent in saveObj.ProjectWorkContents)
|
|
|
- {
|
|
|
- switch (temContent.modifyState)
|
|
|
+ _SaveProjectWorkContent(Context, saveObj);
|
|
|
+
|
|
|
+ if(saveObj.ProjectContentRecord.Project == null)
|
|
|
{
|
|
|
- case ModifyState.Deleted:
|
|
|
- Context.Database.ExecuteSqlRaw($"Delete from ProjectWorkContent where id={temContent.Id}");
|
|
|
-
|
|
|
- break;
|
|
|
- case ModifyState.Modified:
|
|
|
- var modifyContent = Context.ProjectWorkContents.FirstOrDefault(p => p.Id == temContent.Id);
|
|
|
- if (modifyContent != null)
|
|
|
- {
|
|
|
- modifyContent.Content = temContent.Content;
|
|
|
- modifyContent.ActualPerformance = temContent.ActualPerformance;
|
|
|
- modifyContent.DifficultFactor = temContent.DifficultFactor;
|
|
|
- modifyContent.FinalPerformance = temContent.FinalPerformance;
|
|
|
- modifyContent.TakeTime = temContent.TakeTime;
|
|
|
- modifyContent.TimeSpan = temContent.TimeSpan;
|
|
|
- modifyContent.WorkDate = temContent.WorkDate;
|
|
|
- }
|
|
|
- break;
|
|
|
- case ModifyState.New:
|
|
|
- var newContent = new ProjectWorkContent();
|
|
|
- newContent.Content = temContent.Content;
|
|
|
- newContent.ActualPerformance = temContent.ActualPerformance;
|
|
|
- newContent.DifficultFactor = temContent.DifficultFactor;
|
|
|
- newContent.FinalPerformance = temContent.FinalPerformance;
|
|
|
- newContent.TakeTime = temContent.TakeTime;
|
|
|
- newContent.TimeSpan = temContent.TimeSpan;
|
|
|
- newContent.WorkDate = temContent.WorkDate;
|
|
|
- newContent.ContentRecordId = saveObj.ProjectContentRecord.Id;
|
|
|
-
|
|
|
- Context.ProjectWorkContents.Add(newContent);
|
|
|
- break;
|
|
|
+ saveObj.ProjectContentRecord.Project = Context.ProjectInfos.Include(p=>p.Customer)
|
|
|
+ .FirstOrDefault(p=>p.CaseNo == saveObj.ProjectContentRecord.ProjectNo);
|
|
|
+ }
|
|
|
+
|
|
|
+ item.CalMonthId = saveObj.ProjectContentRecord.CalMonthId.Value;
|
|
|
+ item.CaseCoefficient = saveObj.ProjectContentRecord.CaseCoefficient;
|
|
|
+ item.CaseName = saveObj.ProjectContentRecord.Project.CaseName;
|
|
|
+ item.CaseNo = saveObj.ProjectContentRecord.ProjectNo;
|
|
|
+ item.Type = "专案";
|
|
|
+ item.CustomerId = saveObj.ProjectContentRecord.Project.CustomerId;
|
|
|
+ item.BasePoint = saveObj.ProjectContentRecord.Point;
|
|
|
+
|
|
|
+ if (item.Id == 0)
|
|
|
+ {
|
|
|
+ Context.PerformanceItems.Add(item);
|
|
|
+ Context.SaveChanges();
|
|
|
+
|
|
|
+ ItemStaff itemStaff = new ItemStaff();
|
|
|
+ itemStaff.DoPersonId = saveObj.ProjectContentRecord.StaffId;
|
|
|
+ itemStaff.ItemId = item.Id;
|
|
|
+ itemStaff.PerformancePoint = saveObj.ProjectContentRecord.Point;
|
|
|
+ Context.ItemStaffs.Add(itemStaff);
|
|
|
+ Context.SaveChanges();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ item.BasePoint = saveObj.ProjectContentRecord.Point;
|
|
|
+ item.CaseCoefficient = saveObj.ProjectContentRecord.CaseCoefficient;
|
|
|
+ Context.SaveChanges();
|
|
|
}
|
|
|
- Context.SaveChanges();
|
|
|
}
|
|
|
|
|
|
t.Commit();
|
|
|
}
|
|
|
- catch(Exception ex)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
t.Rollback();
|
|
|
ret.Success = false;
|
|
@@ -273,5 +358,116 @@ namespace wispro.sp.api.Controllers
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
|
+
|
|
|
+ public List<ProjectInfo> GetWaitingReviewProject()
|
|
|
+ {
|
|
|
+ var user = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
|
|
|
+
|
|
|
+ var retList = Context.ProjectContentRecords
|
|
|
+ .Include(p=>p.Project).ThenInclude(p=>p.Customer)
|
|
|
+ .Where(p => p.State == 0 && p.CalMonth.Status == 0 && p.ReviewerId == user.Id).Select(p=>p.Project).Distinct().ToList();
|
|
|
+
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ProjectContents> GetProjectCanReviewWorkContent(string projectNo, int Year, int month)
|
|
|
+ {
|
|
|
+ var pcrList = Context.ProjectContentRecords
|
|
|
+ .Include(p => p.CalMonth)
|
|
|
+ .Include(p => p.Reviewer)
|
|
|
+ .Include(p => p.Staff)
|
|
|
+ .Include(p => p.Project).ThenInclude(p => p.Customer)
|
|
|
+ .Include(p => p.ProjectWorkContents)
|
|
|
+ .Where(p => p.ProjectNo == projectNo && p.CalMonth.Year == Year && p.CalMonth.Month == month && p.State >0).ToList();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ List<ProjectContents> retList = new List<ProjectContents>();
|
|
|
+ foreach (var retObj in pcrList)
|
|
|
+ {
|
|
|
+ ProjectContents ret = new ProjectContents();
|
|
|
+
|
|
|
+ ret.ProjectContentRecord = retObj;
|
|
|
+ ret.ProjectWorkContents = new List<ViewProjectWorkContent>();
|
|
|
+
|
|
|
+ foreach (var wContent in retObj.ProjectWorkContents)
|
|
|
+ {
|
|
|
+ ViewProjectWorkContent tem = new ViewProjectWorkContent();
|
|
|
+ tem.modifyState = ModifyState.UnChanged;
|
|
|
+ tem.Id = wContent.Id;
|
|
|
+ tem.Content = wContent.Content;
|
|
|
+ tem.ActualPerformance = wContent.ActualPerformance;
|
|
|
+ tem.ContentRecordId = wContent.ContentRecordId;
|
|
|
+ tem.FinalPerformance = wContent.FinalPerformance;
|
|
|
+ tem.TakeTime = wContent.TakeTime;
|
|
|
+ tem.TimeSpan = wContent.TimeSpan;
|
|
|
+ tem.WorkDate = wContent.WorkDate;
|
|
|
+
|
|
|
+ ret.ProjectWorkContents.Add(tem);
|
|
|
+ }
|
|
|
+
|
|
|
+ ret.ProjectContentRecord.ProjectWorkContents = null;
|
|
|
+
|
|
|
+ retList.Add(ret);
|
|
|
+ }
|
|
|
+
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+ public List<ProjectContents> GetProjectWorkContentRecord(string projectNo,int Year,int month,int? state)
|
|
|
+ {
|
|
|
+ var pcrList = new List<ProjectContentRecord>();
|
|
|
+ if (!state.HasValue)
|
|
|
+ {
|
|
|
+ pcrList = Context.ProjectContentRecords
|
|
|
+ .Include(p => p.CalMonth)
|
|
|
+ .Include(p => p.Reviewer)
|
|
|
+ .Include(p=>p.Staff)
|
|
|
+ .Include(p => p.Project).ThenInclude(p => p.Customer)
|
|
|
+ .Include(p => p.ProjectWorkContents)
|
|
|
+ .Where(p => p.ProjectNo == projectNo && p.CalMonth.Year == Year && p.CalMonth.Month == month).ToList();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pcrList = Context.ProjectContentRecords
|
|
|
+ .Include(p => p.CalMonth)
|
|
|
+ .Include(p => p.Reviewer)
|
|
|
+ .Include(p => p.Staff)
|
|
|
+ .Include(p => p.Project).ThenInclude(p => p.Customer)
|
|
|
+ .Include(p => p.ProjectWorkContents)
|
|
|
+ .Where(p => p.ProjectNo == projectNo && p.CalMonth.Year == Year && p.CalMonth.Month == month && p.State == state.Value).ToList();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<ProjectContents> retList = new List<ProjectContents>();
|
|
|
+ foreach(var retObj in pcrList)
|
|
|
+ {
|
|
|
+ ProjectContents ret = new ProjectContents();
|
|
|
+
|
|
|
+ ret.ProjectContentRecord = retObj;
|
|
|
+ ret.ProjectWorkContents = new List<ViewProjectWorkContent>();
|
|
|
+
|
|
|
+ foreach (var wContent in retObj.ProjectWorkContents)
|
|
|
+ {
|
|
|
+ ViewProjectWorkContent tem = new ViewProjectWorkContent();
|
|
|
+ tem.modifyState = ModifyState.UnChanged;
|
|
|
+ tem.Id = wContent.Id;
|
|
|
+ tem.Content = wContent.Content;
|
|
|
+ tem.ActualPerformance = wContent.ActualPerformance;
|
|
|
+ tem.ContentRecordId = wContent.ContentRecordId;
|
|
|
+ tem.FinalPerformance = wContent.FinalPerformance;
|
|
|
+ tem.TakeTime = wContent.TakeTime;
|
|
|
+ tem.TimeSpan = wContent.TimeSpan;
|
|
|
+ tem.WorkDate = wContent.WorkDate;
|
|
|
+
|
|
|
+ ret.ProjectWorkContents.Add(tem);
|
|
|
+ }
|
|
|
+
|
|
|
+ ret.ProjectContentRecord.ProjectWorkContents = null;
|
|
|
+
|
|
|
+ retList.Add(ret);
|
|
|
+ }
|
|
|
+
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
}
|
|
|
}
|