diff --git a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIStatiscialAnalysisController.cs b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIStatiscialAnalysisController.cs index 0ef5734..89bd6d9 100644 --- a/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIStatiscialAnalysisController.cs +++ b/APT.MicroApi/APT.SC.WebApi/Controllers/Api/BIController/BIStatiscialAnalysisController.cs @@ -111,7 +111,26 @@ namespace APT.SC.WebApi.Controllers.Api.BIController public int teamUndoneCount { get; set; } public double teamDoneRate { get; set; } public double teamOverDoneRate { get; set; } + public string month { get; set; } + public string name { get; set; } + } + public class LoginInfo + { + public string NAME { get; set; } + public DateTime? CREATE_TIME { get; set; } + public string FROM { get; set; } + public string VERSION { get; set; } + public int QTY { get; set; } + } + public class DepartmentInfo + { + public Guid? parent_departmentId { get; set; } + public Guid departmentId { get; set; } + public int departmentType { get; set; } + public string departmentName { get; set; } + public int num { get; set; } + public List deptInfos { get; set; } } /// /// @@ -7149,5 +7168,377 @@ namespace APT.SC.WebApi.Controllers.Api.BIController return completions; }); } + + /// + /// 部门完成情况、模块完成情况统计 + /// + /// + /// + [HttpPost, Route("GetDepartMouldInfos")] + public JsonActionResult GetDepartMouldInfos([FromBody] KeywordFilter filter) + { + return SafeExecute(() => + { + //首页待办增加数量统计字段 + dynamic ret = new System.Dynamic.ExpandoObject(); + if (string.IsNullOrEmpty(filter.Parameter1) || string.IsNullOrEmpty(filter.Parameter2)) + { + throw new Exception("请先选择时间段"); + } + var newFilter = new BaseFilter(filter.OrgId); + newFilter.SelectField = new List { "ID", "CODE", "NAME" }; + var formInfo = this.GetEntities(t => t.ENABLE_STATUS == 0, newFilter); + DateTime startTime = Convert.ToDateTime(filter.Parameter1); + DateTime endTime = Convert.ToDateTime(filter.Parameter2); + var diffTime = startTime.AddMonths(11).Date; + if (diffTime < endTime.Date) + { + throw new Exception("查询时间不能超过12个月!"); + } + var result = GetEntities(s => !s.IS_DELETED && s.CREATE_DATE >= startTime && s.CREATE_DATE <= endTime, new BaseFilter(filter.OrgId)).ToList(); + var userIds = result.Select(t => t.USER_ID).Distinct().ToList(); + var userInfos = GetEntities(s => userIds.Contains(s.ID) && s.ENABLE_STATUS == 0, newFilter); + if (result.Any()) + { + List departSummary = new List(); + List mouldSummary = new List(); + newFilter.SelectField = new List { "ID", "PARENT_ID", "NAME", "Nav_Parent", "DEPARTMENT_TYPE" }; + var departmentInfos = this.GetEntities(t => !t.IS_DELETED && t.ENABLE_STATUS == 0, newFilter).ToList(); + var companyIds = departmentInfos.Where(t => t.DEPARTMENT_TYPE == 3).Select(m => m.ID).ToList(); + //按部门 + var departGroupYear = result.Where(t => t.DEPT_DEPARTMENT_ID != null && !companyIds.Contains((Guid)t.DEPT_DEPARTMENT_ID)).ToList(); + //分组 + if (departGroupYear.Any()) + { + var groupYearDepart = departGroupYear.GroupBy(t => t.DEPT_DEPARTMENT_ID).ToList(); + groupYearDepart.ForEach(t => + { + T_BI_SYSTEM_RUN_SUMMARY sum = new T_BI_SYSTEM_RUN_SUMMARY(); + sum.DEPARTMENT_ID = t.Key.Value; + sum.ORG_ID = filter.OrgId; + var depart = departmentInfos.FirstOrDefault(m => m.ID == t.Key.Value); + sum.DEPARTMENT_NAME = depart?.NAME; + sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastYear; + sum.TOTAL_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value).Count(); + sum.FINISH_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 1).Count(); + sum.OVER_FINISH_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 2).Count(); + sum.UNFINISH_QTY = t.Where(m => m.DEPT_DEPARTMENT_ID == t.Key.Value && m.NOTICE_STATUS == 0).Count(); + sum.DEPARTMENT_TYPE = FMDepartmentType.部门; + var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100; + sum.FINISH_RATE = temp.ToString("0"); + var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100; + sum.NORMAL_FINISH_RATE = temp2.ToString("0"); + departSummary.Add(sum); + }); + ret.departData = departSummary; + } + //按模块 + var mouldGroupYear = departGroupYear.Where(t => t.MOUDLE_NAME != null).ToList(); + if (mouldGroupYear.Any()) + { + //分组 + var groupYearMould = mouldGroupYear.GroupBy(t => t.MOUDLE_NAME).ToList(); + groupYearMould.ForEach(t => + { + T_BI_MOULD_RUN_SUMMARY sum = new T_BI_MOULD_RUN_SUMMARY(); + sum.MOUDLE_NAME = t.Key; + sum.ORG_ID = filter.OrgId; + sum.TYPE = MS.Domain.Enums.BI.BIEnums.FilterTimeType.LastYear; + sum.TOTAL_QTY = t.Where(m => m.MOUDLE_NAME == t.Key).Count(); + sum.FINISH_QTY = t.Where(m => m.MOUDLE_NAME == t.Key && m.NOTICE_STATUS == 1).Count(); + sum.OVER_FINISH_QTY = t.Where(m => m.MOUDLE_NAME == t.Key && m.NOTICE_STATUS == 2).Count(); + sum.UNFINISH_QTY = sum.TOTAL_QTY - sum.FINISH_QTY - sum.OVER_FINISH_QTY; + var temp = sum.TOTAL_QTY == 0 ? 0 : (double)(sum.FINISH_QTY + sum.OVER_FINISH_QTY) / sum.TOTAL_QTY * 100; + sum.FINISH_RATE = temp.ToString("0"); + var temp2 = sum.TOTAL_QTY == 0 ? 0 : (double)sum.FINISH_QTY / sum.TOTAL_QTY * 100; + sum.NORMAL_FINISH_RATE = temp2.ToString("0"); + mouldSummary.Add(sum); + }); + ret.mouldData = mouldSummary; + } + } + return ret; + }); + } + /// + /// 个人登录情况统计 + /// + /// + /// + [HttpPost, Route("GetLoginInfos")] + public JsonActionResult GetLoginInfos([FromBody] KeywordFilter filter) + { + return SafeExecute(() => + { + //表格 + List completionSorts = new List(); + dynamic ret = new System.Dynamic.ExpandoObject(); + var dt = DateTime.Now.AddMonths(-1); + var startTime = DateTime.Parse(dt.Year.ToString() + "-" + dt.Month + "-" + dt.Day + " 00:00:00"); + var endTime = DateTime.Parse(DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + " 23:59:59"); + var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value; + var userID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value; + var newfilter = new BaseFilter(orgId); + newfilter.SelectField = new List { "ID", "USER_ID", "DEPARTMENT_ID", "FROM", "VERSION", "CREATE_TIME" }; + if (!string.IsNullOrEmpty(filter.Keyword)) + { + userID = this.GetEntity(t => !t.IS_DELETED && t.ENABLE_STATUS == 0 && t.NAME == filter.Keyword).ID; + } + var loginInfos = this.GetEntities(t => !t.IS_DELETED && t.CREATE_TIME >= startTime && t.CREATE_TIME <= endTime && t.USER_ID == userID, newfilter); + //表格 + var loginInfoTable = loginInfos.OrderByDescending(m => m.CREATE_TIME).Take(30); + if (loginInfoTable != null && loginInfoTable.Any()) + { + foreach (var depart in loginInfoTable) + { + LoginInfo info = new LoginInfo(); + info.CREATE_TIME = depart?.CREATE_TIME; + info.FROM = depart.FROM; + info.VERSION = depart.VERSION; + completionSorts.Add(info); + } + } + ret.retDetailData = completionSorts; + //走势图(近一个月) + List completionSorts1 = new List(); + for (DateTime date = startTime; date <= DateTime.Now; date = date.AddDays(1)) + { + var dayEnd = DateTime.Parse(date.Year.ToString() + "-" + date.Month + "-" + date.Day + " 23:59:59"); + var ksJantask = loginInfos.Where(t => t.CREATE_TIME >= date && t.CREATE_TIME <= dayEnd).ToList(); + if (ksJantask.Any()) + { + LoginInfo run = new LoginInfo(); + run.CREATE_TIME = date; + run.QTY = ksJantask.Count(); + completionSorts1.Add(run); + } + else + { + LoginInfo run = new LoginInfo(); + run.CREATE_TIME = date; + run.QTY = 0; + completionSorts1.Add(run); + } + } + ret.retChartData = completionSorts1; + //饼图(近一个月) + ret.groupData = loginInfos.GroupBy(t => t.FROM).Select(m => new LoginInfo + { + FROM = m.Key, + QTY = m.Where(p => p.FROM == m.Key).Count(), + }).ToList(); + return ret; + }); + } + + /// + /// 组织完成情况统计 + /// + /// + /// + [HttpPost, Route("GetDepartmentAnalysis")] + public JsonActionResult GetDepartmentAnalysis([FromBody] KeywordFilter filter) + { + return SafeExecute(() => + { + //表格 + dynamic ret = new System.Dynamic.ExpandoObject(); + var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value; + T_FM_DEPARTMENT departInfo = null; + Expression> express = t => !t.IS_DELETED && (t.NOTICE_STATUS == 0 || t.NOTICE_STATUS == 1 || t.NOTICE_STATUS == 2); + if (string.IsNullOrEmpty(filter.Keyword)) + { + //未选中组织,默认全公司 + } + else + { + departInfo = this.GetEntity(filter.Keyword); + if (departInfo != null && departInfo.IS_DELETED == false) + { + //部门 + if (departInfo.DEPARTMENT_TYPE == 0) + { + express = express.And(t => t.DEPT_DEPARTMENT_ID == departInfo.ID); + } + else if (departInfo.DEPARTMENT_TYPE == 1) + { + express = express.And(t => t.SHOP_DEPARTMENT_ID == departInfo.ID); + } + else if (departInfo.DEPARTMENT_TYPE == 2) + { + express = express.And(t => t.CLASS_DEPARTMENT_ID == departInfo.ID); + } + } + } + var dt = DateTime.Parse(DateTime.Now.Year + "-01-01 00:00:00"); + if (string.IsNullOrEmpty(filter.Parameter1)) + { + //未选择年份,默认当前年度 + } + else + { + dt = DateTime.Parse(filter.Parameter1 + "-01-01 00:00:00"); + } + express = express.And(t => t.CREATE_DATE.Value.Year == dt.Year); + var result = this.GetEntities(express, filter); + if (result != null && result.Any()) + { + //总数 + ret.TotalCount = result.Count(); + //未完成数 + var UnfinishCount = result.Count(t => t.NOTICE_STATUS == 0); + ret.UnfinishCount = UnfinishCount; + //超时完成数 + var OverfinishCount = result.Count(t => t.NOTICE_STATUS == 2); + //及时完成数 + var FinishCount = result.Count(t => t.NOTICE_STATUS == 1); + //总完成数 + ret.finishCount = FinishCount + OverfinishCount; + //完成率 + ret.FinishRate = ret.TotalCount == 0 ? 0 : (double)ret.finishCount / ret.TotalCount * 100; + //及时完成率 + ret.NormalFinishRate = ret.TotalCount == 0 ? 0 : (double)FinishCount / ret.TotalCount * 100; + //未完成弹窗 + ret.UnfinishData = result.Where(t => t.NOTICE_STATUS == 0).ToList(); + //走势图(近一个月) + List completionSorts = new List(); + var dtEnd = dt.AddYears(1); + for (DateTime date = dt; date < dtEnd; date = date.AddMonths(1)) + { + var dayEnd = date.AddMonths(1); + var taskTotal = result.Where(t => t.CREATE_DATE >= date && t.CREATE_DATE < dayEnd).ToList(); + var taskFinish = taskTotal.Count(t => t.NOTICE_STATUS == 1 || t.NOTICE_STATUS == 2); + var normalFinish = taskTotal.Count(t => t.NOTICE_STATUS == 1); + if (taskTotal.Any()) + { + GroupbyDepartmentCompletion run = new GroupbyDepartmentCompletion(); + run.month = date.Year.ToString() + "-" + date.Month.ToString(); + run.teamDoneRate = taskTotal.Count() == 0 ? 0 : (double)taskFinish / taskTotal.Count() * 100; + run.teamOverDoneRate = taskTotal.Count() == 0 ? 0 : (double)normalFinish / taskTotal.Count() * 100; + completionSorts.Add(run); + } + else + { + GroupbyDepartmentCompletion run = new GroupbyDepartmentCompletion(); + run.month = date.Year.ToString() + "-" + date.Month.ToString(); + run.teamDoneRate = 0; + run.teamOverDoneRate = 0; + completionSorts.Add(run); + } + } + ret.LineChart = completionSorts; + //按人分组 + var groupTask = result.GroupBy(t => t.USER_NAME).Select(m => new GroupbyDepartmentCompletion + { + name = m.Key, + teamDoneRate = m.Count(p => p.USER_NAME == m.Key) == 0 ? 0 : m.Count(p => p.USER_NAME == m.Key && (p.NOTICE_STATUS == 1 || p.NOTICE_STATUS == 2)) / m.Count(p => p.USER_NAME == m.Key) * 100, + teamOverDoneRate = m.Count(p => p.USER_NAME == m.Key) == 0 ? 0 : m.Count(p => p.USER_NAME == m.Key && (p.NOTICE_STATUS == 1)) / m.Count(p => p.USER_NAME == m.Key) * 100 + }).ToList(); + if (groupTask.Count > 20) + { + //柱状图(前八) + ret.BarAsc = groupTask.OrderByDescending(t => t.teamOverDoneRate).Take(8).ToList(); + //柱状图(后八) + ret.BarDesc = groupTask.OrderBy(t => t.teamOverDoneRate).Take(8).ToList(); + } + else + { + ret.BarAsc = groupTask.OrderByDescending(t => t.teamOverDoneRate).ToList(); + } + ret.UserCount = groupTask.Count; + } + else + { + ret.TotalCount = 0; + ret.UnfinishCount = 0; + ret.FinishRate = 0; + ret.NormalFinishRate = 0; + ret.LineChart = new List(); + ret.BarAsc = new List(); + ret.BarDesc = new List(); + ret.UserCount = 0; + } + return ret; + }); + } + + /// + /// 组织部门树 + /// + /// + /// + [HttpPost, Route("GetDepartmentEntities")] + public JsonActionResult GetDepartmentEntities([FromBody] KeywordFilter filter) + { + return SafeExecute(() => + { + //表格 + DepartmentInfo ret = new DepartmentInfo(); + var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId.Value; + var departInfos = this.GetEntities(t => !t.IS_DELETED, new BaseFilter(orgId)); + var company = departInfos.FirstOrDefault(t => t.DEPARTMENT_TYPE == 3); + if (company != null) + { + //公司 + ret.departmentId = company.ID; + ret.departmentName = company.NAME; + ret.parent_departmentId = null; + ret.departmentType = company.DEPARTMENT_TYPE; + ret.num = company.NUM; + //部门 + var deptInfos = departInfos.Where(t => t.PARENT_ID == company.ID).OrderBy(m => m.NUM).ToList(); + if (deptInfos != null && deptInfos.Any()) + { + List deptLists = new List(); + foreach (var dept in deptInfos) + { + DepartmentInfo deptList = new DepartmentInfo(); + deptList.departmentId = dept.ID; + deptList.departmentName = dept.NAME; + deptList.parent_departmentId = company.ID; + deptList.departmentType = dept.DEPARTMENT_TYPE; + deptList.num = dept.NUM; + //车间 + var shopInfos = departInfos.Where(t => t.PARENT_ID == dept.ID).OrderBy(m => m.NUM).ToList(); + if (shopInfos != null && shopInfos.Any()) + { + List shopLists = new List(); + foreach (var shop in shopInfos) + { + DepartmentInfo shopList = new DepartmentInfo(); + shopList.departmentId = shop.ID; + shopList.departmentName = shop.NAME; + shopList.parent_departmentId = dept.ID; + shopList.departmentType = shop.DEPARTMENT_TYPE; + shopList.num = shop.NUM; + //班组 + var classInfos = departInfos.Where(t => t.PARENT_ID == shop.ID).OrderBy(m => m.NUM).ToList(); + if (classInfos != null && classInfos.Any()) + { + List classLists = new List(); + foreach (var item in classInfos) + { + DepartmentInfo classList = new DepartmentInfo(); + classList.departmentId = item.ID; + classList.departmentName = item.NAME; + classList.parent_departmentId = shop.ID; + classList.departmentType = item.DEPARTMENT_TYPE; + classList.num = item.NUM; + classLists.Add(classList); + } + shopList.deptInfos = classLists; + } + shopLists.Add(shopList); + } + deptList.deptInfos = shopLists; + } + deptLists.Add(deptList); + } + ret.deptInfos = deptLists; + } + } + return ret; + }); + } } }