using System; using System.Collections.Generic; using System.Web.Http; using Model; using BLL; using System.Linq; namespace WebAPI.Controllers.CQMS { /// /// 施工绩效控制器 /// public class PerformanceController : ApiController { #region 根据主键、人员id、项目id获取数据 /// /// 根据主键、人员id、项目id、当前日期 获取数据 /// /// /// /// /// /// [HttpGet] public Model.ResponeData getPerformanceData(string Projectid, string Userid, string PerformanceGid, string Nowdate) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { var responeData = new Model.ResponeData(); try { //根据当前日期 和主键id获取当前是第几周 var TodayDate = Convert.ToDateTime(Nowdate).Date; var childModel3 = db.CQMS_Performance_Child3.FirstOrDefault(x => x.PerformanceGid == PerformanceGid && x.CurrentDate == TodayDate); if (childModel3 == null) { responeData.code = 0; responeData.message = "未查询到数据,请去pc端表单"; return responeData; } var Performance_ChildGid2 = childModel3.Performance_ChildGid2; var NowWeek = db.CQMS_Performance_Child2.FirstOrDefault(x => x.PerformanceGid == PerformanceGid && x.Performance_ChildGid2 == Performance_ChildGid2).NowWeek; //获取数量和本周任务安排 var child2List = Funs.DB.CQMS_Performance_Child2.Where(x => x.PerformanceGid == PerformanceGid && x.NowWeek == NowWeek).OrderBy(x => x.SortIndex).ToList(); List childList3 = new List(); var Onindex = 0; foreach (var item in child2List) { var FModel1Itemize = db.CQMS_Performance_Child1.FirstOrDefault(x => x.Performance_ChildGid1 == item.Performance_ChildGid1); if (FModel1Itemize.Itemize.IndexOf("施工进度")>-1) { FModel1Itemize.Itemize = "施工进度"; } else if (FModel1Itemize.Itemize.IndexOf("HSE管理") > -1) { FModel1Itemize.Itemize = "HSE管理"; } else if (FModel1Itemize.Itemize.IndexOf("质量管理情况") > -1) { FModel1Itemize.Itemize = "质量管理情况"; } else if (FModel1Itemize.Itemize.IndexOf("图纸、材料状态跟踪") > -1) { FModel1Itemize.Itemize = "图纸、材料状态跟踪"; } else if (FModel1Itemize.Itemize.IndexOf("关键事项跟踪") > -1) { FModel1Itemize.Itemize = "关键事项跟踪"; } else if (FModel1Itemize.Itemize.IndexOf("可交付成果") > -1) { FModel1Itemize.Itemize = "可交付成果"; } item.TaskContent = FModel1Itemize.Itemize+"(本周任务安排:"+ item.TaskContent + ")"; var child3Model = db.CQMS_Performance_Child3.FirstOrDefault(x => x.PerformanceGid == PerformanceGid && x.CurrentDate == TodayDate && x.Performance_ChildGid2 == item.Performance_ChildGid2); childList3.Add(child3Model); Onindex += 1; } responeData.data = new { child2List.Count, child2List, childList3 }; //responeData.data = APICheckSpecialService.getCheckSpecialById(CheckSpecialId, state); } catch (Exception ex) { responeData.code = 0; responeData.message = ex.Message; } return responeData; } } #endregion #region 添加当日计划 /// /// 添加实体类 /// public class PerformanceInserModelItem { /// /// 主键id /// public string PerformanceGid { get; set; } /// /// 本日工作计划 /// public string WorkPlan { get; set; } /// /// 本日完成情况 /// public string CompletStatus { get; set; } /// /// 当前日期 /// public DateTime CurrentDate { get; set; } /// /// 本周工作完成情况 /// public string TaskCompletContent { get; set; } } /// /// 添加实体 /// public class AddLists { public List childList { get; set; } } /// /// 添加当日计划 /// /// /// [HttpPost] public Model.ResponeData InsertPerformance([FromBody] AddLists CreateList) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { List AddList = CreateList.childList; var responeData = new Model.ResponeData(); try { if (AddList==null) { responeData.code = 0; responeData.message = "未查询到数据,请重试。"; return responeData; } var cdate = AddList[0].CurrentDate; var PerformanceGid = AddList[0].PerformanceGid; // 根据当前日期 和主键id获取当前是第几周 var TodayDate = Convert.ToDateTime(cdate).Date; var childModel3 = db.CQMS_Performance_Child3.FirstOrDefault(x => x.PerformanceGid == PerformanceGid && x.CurrentDate == TodayDate); if (childModel3 == null) { responeData.code = 0; responeData.message = "未查询到数据,请去pc端表单"; return responeData; } var Performance_ChildGid2 = childModel3.Performance_ChildGid2; var NowWeek = db.CQMS_Performance_Child2.FirstOrDefault(x => x.PerformanceGid == PerformanceGid && x.Performance_ChildGid2 == Performance_ChildGid2).NowWeek; //加载数据。 //判断施工管理工作任务安排有几个(倒序) var child2List = Funs.DB.CQMS_Performance_Child2.Where(x => x.PerformanceGid == PerformanceGid && x.NowWeek == NowWeek).OrderByDescending(x => x.SortIndex).ToList(); var objModel = db.CQMS_Performance_Child3.Where(x => x.PerformanceGid == PerformanceGid && x.CurrentDate == TodayDate); if (child2List != null) { //可交付成果 var Child3Model = objModel.FirstOrDefault(x => x.Performance_ChildGid2 == child2List[0].Performance_ChildGid2); Child3Model.WorkPlan = AddList[AddList.Count-1].WorkPlan; db.SubmitChanges(); //周计划 Model.CQMS_Performance_Child2 Child4Model = child2List[0]; Child4Model.TaskCompletContent = AddList[AddList.Count-1].TaskCompletContent; PerformanceService.UpdateChild2(Child4Model); //关键事项跟踪 Child3Model = objModel.FirstOrDefault(x => x.Performance_ChildGid2 == child2List[1].Performance_ChildGid2); Child3Model.WorkPlan = AddList[AddList.Count - 2].WorkPlan; db.SubmitChanges(); Child4Model = child2List[1]; Child4Model.TaskCompletContent = AddList[AddList.Count - 2].TaskCompletContent; PerformanceService.UpdateChild2(Child4Model); //图纸、材料状态跟踪;统计台账 Child3Model = objModel.FirstOrDefault(x => x.Performance_ChildGid2 == child2List[2].Performance_ChildGid2); Child3Model.WorkPlan = AddList[AddList.Count - 3].WorkPlan; db.SubmitChanges(); Child4Model = child2List[2]; Child4Model.TaskCompletContent = AddList[AddList.Count - 3].TaskCompletContent; PerformanceService.UpdateChild2(Child4Model); //质量管理情况 Child3Model = objModel.FirstOrDefault(x => x.Performance_ChildGid2 == child2List[3].Performance_ChildGid2); Child3Model.WorkPlan = AddList[AddList.Count - 4].WorkPlan; db.SubmitChanges(); Child4Model = child2List[3]; Child4Model.TaskCompletContent = AddList[AddList.Count - 4].TaskCompletContent; PerformanceService.UpdateChild2(Child4Model); //HSE管理 Child3Model = objModel.FirstOrDefault(x => x.Performance_ChildGid2 == child2List[4].Performance_ChildGid2); Child3Model.WorkPlan = AddList[AddList.Count - 5].WorkPlan; db.SubmitChanges(); Child4Model = child2List[4]; Child4Model.TaskCompletContent = AddList[AddList.Count - 5].TaskCompletContent; PerformanceService.UpdateChild2(Child4Model); var Sgcount = Funs.DB.CQMS_Performance.FirstOrDefault(x => x.PerformanceGid == PerformanceGid).SgCount; child2List = Funs.DB.CQMS_Performance_Child2.Where(x => x.PerformanceGid == PerformanceGid && x.NowWeek == NowWeek).OrderBy(x => x.SortIndex).ToList(); for (int i = 0; i < Sgcount; i++) { Child3Model = objModel.FirstOrDefault(x => x.Performance_ChildGid2 == child2List[i].Performance_ChildGid2); Child3Model.WorkPlan = AddList[i].WorkPlan; Child3Model.CompletStatus = AddList[i].CompletStatus; db.SubmitChanges(); Child4Model = child2List[i]; Child4Model.TaskCompletContent = AddList[i].TaskCompletContent; PerformanceService.UpdateChild2(Child4Model); } //if (child2List.Count == 6) //{ // Child3Model = objModel.FirstOrDefault(x => x.Performance_ChildGid2 == child2List[5].Performance_ChildGid2); // Child3Model.WorkPlan = AddList[AddList.Count - 6].WorkPlan; // Child3Model.CompletStatus = AddList[AddList.Count - 6].CompletStatus; // db.SubmitChanges(); // Child4Model = child2List[5]; // Child4Model.TaskCompletContent = AddList[AddList.Count - 6].TaskCompletContent; // PerformanceService.UpdateChild2(Child4Model); //} //else if (child2List.Count == 7) //{ // Child3Model = objModel.FirstOrDefault(x => x.Performance_ChildGid2 == child2List[5].Performance_ChildGid2); // Child3Model.WorkPlan = AddList[AddList.Count - 6].WorkPlan; // Child3Model.CompletStatus = AddList[AddList.Count - 6].CompletStatus; // db.SubmitChanges(); // Child4Model = child2List[5]; // Child4Model.TaskCompletContent = AddList[AddList.Count -6].TaskCompletContent; // PerformanceService.UpdateChild2(Child4Model); // Child3Model = objModel.FirstOrDefault(x => x.Performance_ChildGid2 == child2List[6].Performance_ChildGid2); // Child3Model.WorkPlan = AddList[AddList.Count - 7].WorkPlan; // Child3Model.CompletStatus = AddList[AddList.Count - 7].CompletStatus; // db.SubmitChanges(); // Child4Model = child2List[6]; // Child4Model.TaskCompletContent = AddList[AddList.Count - 7].TaskCompletContent; // PerformanceService.UpdateChild2(Child4Model); //} //else if (child2List.Count == 8) //{ // Child3Model = objModel.FirstOrDefault(x => x.Performance_ChildGid2 == child2List[5].Performance_ChildGid2); // Child3Model.WorkPlan = AddList[AddList.Count - 6].WorkPlan; // Child3Model.CompletStatus = AddList[AddList.Count - 6].CompletStatus; // db.SubmitChanges(); // Child4Model = child2List[5]; // Child4Model.TaskCompletContent = AddList[AddList.Count - 6].TaskCompletContent; // PerformanceService.UpdateChild2(Child4Model); // Child3Model = objModel.FirstOrDefault(x => x.Performance_ChildGid2 == child2List[6].Performance_ChildGid2); // Child3Model.WorkPlan = AddList[AddList.Count - 7].WorkPlan; // Child3Model.CompletStatus = AddList[AddList.Count - 7].CompletStatus; // db.SubmitChanges(); // Child4Model = child2List[6]; // Child4Model.TaskCompletContent = AddList[AddList.Count - 7].CompletStatus; // PerformanceService.UpdateChild2(Child4Model); // Child3Model = objModel.FirstOrDefault(x => x.Performance_ChildGid2 == child2List[7].Performance_ChildGid2); // Child3Model.WorkPlan = AddList[AddList.Count - 8].WorkPlan; // Child3Model.CompletStatus = AddList[AddList.Count - 8].CompletStatus; // db.SubmitChanges(); // Child4Model = child2List[7]; // Child4Model.TaskCompletContent = AddList[AddList.Count - 8].CompletStatus; // PerformanceService.UpdateChild2(Child4Model); //} } responeData.message = "保存成功"; } catch (Exception ex) { responeData.code = 0; responeData.message = ex.Message; } return responeData; } } #endregion } }