2023-10-26

This commit is contained in:
2023-10-26 19:48:06 +08:00
parent 5fb9c49964
commit a2acdd4259
6 changed files with 355 additions and 101 deletions
@@ -893,21 +893,42 @@ namespace FineUIPro.Web.CQMS.ManageReport
{
projectStartDate = project.StartDate.Value;
}
//所有集合
List<Model.Comprehensive_NCRManagement> totalManagementList = BLL.NCRManagementService.GetNCRManagementListByDate(this.CurrUser.LoginProjectId, startDate, endDate);
List<string> unitNames = (from x in totalManagementList select x.ReceiveUnit).Distinct().ToList();
foreach (var item in unitNames)
var units = from x in Funs.DB.Project_ProjectUnit
join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId
where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitType == BLL.Const.ProjectUnitType_2
orderby y.UnitCode
select new { x.UnitId, y.UnitName };
var db = Funs.DB;
foreach (var item in units)
{
//当期集合
List<Model.Comprehensive_NCRManagement> managementList = BLL.NCRManagementService.GetNCRManagementListByUnitNameAndDate(this.CurrUser.LoginProjectId, item, startDate, endDate);
//累计集合
List<Model.Comprehensive_NCRManagement> sumManagementList = BLL.NCRManagementService.GetNCRManagementListByUnitNameAndDate(this.CurrUser.LoginProjectId, item, projectStartDate, DateTime.Now);
var query = from c in db.Comprehensive_NCRManagement
join u in db.Base_Unit on c.ReceiveUnit equals u.UnitId into unitJoin
from u in unitJoin.DefaultIfEmpty()
where c.ProjectId == this.CurrUser.LoginProjectId && c.ReceiveUnit == item.UnitId
select new
{
c.NCRManagementId,
c.ProjectId,
u.UnitId,
u.UnitName,
c.IssuedDate,
c.Status
};
var AllList = query.ToList();
var unitNCRStatic = query
.Where(x => (x.IssuedDate >= Convert.ToDateTime(startDate) && x.IssuedDate <= Convert.ToDateTime(endDate)));
Model.NCRReportStatisc NCRStatisc = new Model.NCRReportStatisc();
NCRStatisc.Num = i;
NCRStatisc.WorkName = BLL.UnitService.getUnitNamesUnitIds(item);
NCRStatisc.CurrentPeriodOkNum = managementList.Count(x => x.Status == "3");
NCRStatisc.OKNum = sumManagementList.Count(x => x.Status == "3");
NCRStatisc.CheckNum = sumManagementList.Count;
NCRStatisc.WorkName = item.UnitName;
NCRStatisc.CurrentPeriodOkNum = unitNCRStatic.Count(x => x.Status == "3");
NCRStatisc.OKNum = AllList.Count(x => x.Status == "3");
NCRStatisc.CheckNum = AllList.Count();
if (NCRStatisc.CheckNum != 0)//被除数不能为零
{
NCRStatisc.OKRate = Math.Round((double)NCRStatisc.OKNum / (double)NCRStatisc.CheckNum * 100, 2) + "%";//保留两位小数、后四舍五入
@@ -1177,6 +1198,7 @@ namespace FineUIPro.Web.CQMS.ManageReport
DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
DateTime projectStartDate = Convert.ToDateTime("2015-01-01");
Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
List<Model.CQMSConstructSolutionStatisc> StatisticsList = new List<Model.CQMSConstructSolutionStatisc>();
var unitList = UnitService.GetUnitListByProjectId(this.CurrUser.LoginProjectId).Select(x => x.UnitId).ToList();
if (project != null)
{
@@ -1186,50 +1208,128 @@ namespace FineUIPro.Web.CQMS.ManageReport
}
}
int i = 1;
var q = from x in db.Solution_CQMSConstructSolution
where x.CompileDate >= Convert.ToDateTime(startDate) && x.CompileDate <= Convert.ToDateTime(endDate) && unitList.Contains(x.UnitId) && x.ProjectId == this.CurrUser.LoginProjectId
group x by new { x.UnitId, State = x.State == "3", ProjectId = x.ProjectId == project.ProjectId }
into g
select new
{
UnitName = BLL.UnitService.GetUnitNameByUnitId(g.Key.UnitId),
Count = g.Key.UnitId.Count(),
};
var units = from x in Funs.DB.Project_ProjectUnit
join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId
where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitType == BLL.Const.ProjectUnitType_2
orderby y.UnitCode
select new { x.UnitId, y.UnitName };
var total = from x in db.Solution_CQMSConstructSolution
where x.CompileDate >= projectStartDate && x.CompileDate <= DateTime.Now && unitList.Contains(x.UnitId) && x.ProjectId == this.CurrUser.LoginProjectId
group x by new { x.UnitId, ProjectId = x.ProjectId == project.ProjectId }
into g
select new
{
UnitName = BLL.UnitService.GetUnitNameByUnitId(g.Key.UnitId),
Count = g.Key.UnitId.Count(),
};
var result = q.ToList().Select((item, index) => new
foreach (var item in units)
{
Index = index + 1,
item.UnitName,
item.Count,
AllCount = (int)total.ToList().Where(x => x.UnitName == item.UnitName).Select(x => x.Count).FirstOrDefault()
});
if (result.Count() > 0) //增加总计
var query = from c in db.Solution_CQMSConstructSolution
join u in db.Base_Unit on c.UnitId equals u.UnitId into unitJoin
from u in unitJoin.DefaultIfEmpty()
where c.ProjectId == this.CurrUser.LoginProjectId && c.UnitId == item.UnitId
select new
{
c.ConstructSolutionId,
c.ProjectId,
u.UnitId,
u.UnitName,
c.State,
c.CompileDate
};
var AllList = query.ToList();
var unitNCRStatic = query
.Where(x => (x.CompileDate >= Convert.ToDateTime(startDate) && x.CompileDate <= Convert.ToDateTime(endDate)));
Model.CQMSConstructSolutionStatisc NCRStatisc = new Model.CQMSConstructSolutionStatisc();
NCRStatisc.Num = i;
NCRStatisc.UnitName = item.UnitName;
NCRStatisc.CheckNum = unitNCRStatic.Count(x => x.State == "3");
NCRStatisc.AllNum = AllList.Count();
StatisticsList.Add(NCRStatisc);
i++;
}
if (StatisticsList.Count() > 0) //增加总计
{
int totalCount = result.Sum(item => item.Count);
int totalAllCount = result.Sum(item => item.AllCount);
result = result.Concat(new[]
Model.CQMSConstructSolutionStatisc StatisticsLast = new Model.CQMSConstructSolutionStatisc();
StatisticsLast.Num = StatisticsList.Count() + 1;
StatisticsLast.UnitName = "合计";
foreach (Model.CQMSConstructSolutionStatisc item in StatisticsList)
{
new
{
Index = result.Count() + 1,
UnitName = "合计",
Count = totalCount,
AllCount= totalAllCount
}
});
StatisticsLast.CheckNum += item.CheckNum;
StatisticsLast.AllNum += item.AllNum;
}
StatisticsList.Add(StatisticsLast);
}
else
{
Model.CQMSConstructSolutionStatisc StatisticsLast = new Model.CQMSConstructSolutionStatisc();
StatisticsLast.Num = 0;
StatisticsLast.UnitName = "合计";
StatisticsLast.CheckNum = 0;
StatisticsLast.AllNum = 0;
StatisticsList.Add(StatisticsLast);
}
this.gvConstructionStatistics.DataSource = result;
//var q = from x in db.Solution_CQMSConstructSolution
// join y in units on x.UnitId equals y.UnitId
// where x.CompileDate >= Convert.ToDateTime(startDate) && x.CompileDate <= Convert.ToDateTime(endDate) && unitList.Contains(x.UnitId) &&x.ProjectId==this.CurrUser.LoginProjectId
// group x by new { x.UnitId, State = x.State == "3", ProjectId = x.ProjectId == project.ProjectId }
// into g
// select new
// {
// UnitName=BLL.UnitService.GetUnitNameByUnitId(g.Key.UnitId),
// Count = g.Key.UnitId.Count(),
// };
//var total = from x in db.Solution_CQMSConstructSolution
// join y in units on x.UnitId equals y.UnitId
// where x.CompileDate >= projectStartDate && x.CompileDate <= DateTime.Now && unitList.Contains(x.UnitId) && x.ProjectId == this.CurrUser.LoginProjectId
// group x by new { x.UnitId, ProjectId = x.ProjectId == project.ProjectId }
// into g
// select new
// {
// UnitName = BLL.UnitService.GetUnitNameByUnitId(g.Key.UnitId),
// Count = g.Key.UnitId.Count(),
// };
//var total = from x in units
// join y in db.Solution_CQMSConstructSolution on x.UnitId equals y.UnitId into unitJoin
// from u in unitJoin.DefaultIfEmpty()
// where u.ProjectId == this.CurrUser.LoginProjectId
// select new
// {
// UnitName= x.UnitName,
// u.ConstructSolutionId,
// u.CompileDate
// };
//var result = total.ToList().Select((item, index) => new
//{
// Index = index + 1,
// item.UnitName,
// Count = (int)total.ToList().Where(x => x.UnitName == item.UnitName && x.CompileDate >= Convert.ToDateTime(startDate) && x.CompileDate <= Convert.ToDateTime(endDate)).Count(),
// AllCount = (int)total.ToList().Where(x => x.UnitName == item.UnitName).Count()
//});
//if (result.Count()>0) //增加总计
//{
// int totalCount = result.Sum(item => item.Count);
// int totalAllCount = result.Sum(item => item.AllCount);
// result = result.Concat(new[]
// {
// new
// {
// Index = result.Count() + 1,
// UnitName = "合计",
// Count = totalCount,
// AllCount= totalAllCount
// }
// });
//}
this.gvConstructionStatistics.DataSource = StatisticsList;
this.gvConstructionStatistics.DataBind();
}