fix:质量检查
This commit is contained in:
parent
dbf8b972bc
commit
19f17b9edb
|
@ -101,7 +101,7 @@ namespace BLL
|
|||
/// <returns>一个质量巡检审批实体</returns>
|
||||
public static Model.Check_CheckControlApprove GetCheckControlApproveByCheckControlId(string CheckControlCode)
|
||||
{
|
||||
return db.Check_CheckControlApprove.FirstOrDefault(x => x.CheckControlCode == CheckControlCode && x.ApproveType != "S" && x.ApproveDate == null);
|
||||
return db.Check_CheckControlApprove.FirstOrDefault(x => x.CheckControlCode == CheckControlCode && x.ApproveType != "S" && x.ApproveDate != null);
|
||||
}
|
||||
/// <summary>
|
||||
/// 修改质量巡检审批信息
|
||||
|
|
|
@ -8,6 +8,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NPOI.SS.UserModel;
|
||||
|
||||
namespace FineUIPro.Web.CQMS.Check
|
||||
{
|
||||
|
@ -693,6 +694,7 @@ namespace FineUIPro.Web.CQMS.Check
|
|||
}
|
||||
if (lists != null)
|
||||
{
|
||||
lists = lists.OrderByDescending(x => x.CheckDate);
|
||||
string projectName = BLL.ProjectService.GetShortNameByProjectId(this.CurrUser.LoginProjectId);
|
||||
newUrl = uploadfilepath.Replace("质量巡检模板", "质量巡检(" + projectName + DateTime.Now.ToString("yyyyMMdd") + ")");
|
||||
if (File.Exists(newUrl))
|
||||
|
@ -729,9 +731,13 @@ namespace FineUIPro.Web.CQMS.Check
|
|||
// 第二步:创建新数据行
|
||||
row = sheet.CreateRow(i);
|
||||
// 添加数据
|
||||
// cell = row.CreateCell(0);
|
||||
// cell.CellStyle = cellStyle;
|
||||
// cell.SetCellValue(item.DocCode);//质量巡检编号
|
||||
|
||||
cell = row.CreateCell(0);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.DocCode);//质量巡检编号
|
||||
cell.SetCellValue(item.CheckDate.HasValue ? string.Format("{0:yyyy-MM-dd}", item.CheckDate) : "");//检查日期
|
||||
|
||||
cell = row.CreateCell(1);
|
||||
cell.CellStyle = cellStyle;
|
||||
|
@ -785,23 +791,99 @@ namespace FineUIPro.Web.CQMS.Check
|
|||
}
|
||||
cell.SetCellValue(t);//问题类别
|
||||
|
||||
cell = row.CreateCell(5);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.CheckSite);//部位
|
||||
|
||||
// cell = row.CreateCell(5);
|
||||
// cell.CellStyle = cellStyle;
|
||||
// cell.SetCellValue(item.CheckSite);//整改前照片
|
||||
//整改前照片
|
||||
var attachFile = Funs.DB.AttachFile
|
||||
.Where(p => p.MenuId == BLL.Const.CheckListMenuId && p.ToKeyId == item.CheckControlCode)
|
||||
.FirstOrDefault();
|
||||
if (attachFile != null)
|
||||
{
|
||||
var photoesUrl = attachFile.AttachUrl;
|
||||
if (photoesUrl != null)
|
||||
{
|
||||
string[] arrUrl = photoesUrl.Split(',');
|
||||
sheet.SetColumnWidth(5, 30 * 256);
|
||||
row.Height = (short)(90 * 20 * arrUrl.Length);
|
||||
foreach (string url in arrUrl)
|
||||
{
|
||||
var oneUrl = Server.MapPath("~/") + url;
|
||||
byte[] bytes = System.IO.File.ReadAllBytes(oneUrl);
|
||||
int pictureIdx = workbook.AddPicture(bytes, PictureType.JPEG);
|
||||
|
||||
cell = row.CreateCell(6);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.CheckDate.HasValue ? string.Format("{0:yyyy-MM-dd}", item.CheckDate) : "");//巡检日期
|
||||
// 第三步:创建画部
|
||||
IDrawing patriarch = sheet.CreateDrawingPatriarch();
|
||||
// 第四步:设置锚点
|
||||
int rowline = 1; // y方向
|
||||
// 参数说明:(在起始单元格的X坐标0-1023,Y的坐标0-255,在终止单元格的X坐标0-1023,Y的坐标0-255,起始单元格列数,行数,终止单元格列数,行数)
|
||||
IClientAnchor anchor = patriarch.CreateAnchor(0, 0, 0, 0, 5, i, 6, i + 1);
|
||||
// 第五步:把图片插到相应的位置+1
|
||||
IPicture pict = patriarch.CreatePicture(anchor, pictureIdx);
|
||||
//就取第一张,如果后期想取全部 那把下面这个跳出语句去掉
|
||||
// break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//整改后照片
|
||||
var attachFile1 = Funs.DB.AttachFile.Where(p =>
|
||||
p.MenuId == BLL.Const.CheckListMenuId && p.ToKeyId == item.CheckControlCode + "r")
|
||||
.FirstOrDefault();
|
||||
if (attachFile1 != null)
|
||||
{
|
||||
var photoesUrl1 = attachFile1.AttachUrl;
|
||||
if (photoesUrl1 != null)
|
||||
{
|
||||
string[] arrUrl = photoesUrl1.Split(',');
|
||||
sheet.SetColumnWidth(6, 30 * 256);
|
||||
row.Height = (short)(90 * 20 * arrUrl.Length);
|
||||
foreach (string url in arrUrl)
|
||||
{
|
||||
var oneUrl = Server.MapPath("~/") + url;
|
||||
byte[] bytes = System.IO.File.ReadAllBytes(oneUrl);
|
||||
int pictureIdx = workbook.AddPicture(bytes, PictureType.JPEG);
|
||||
|
||||
// 第三步:创建画部
|
||||
IDrawing patriarch = sheet.CreateDrawingPatriarch();
|
||||
// 第四步:设置锚点
|
||||
int rowline = 1; // y方向
|
||||
// 参数说明:(在起始单元格的X坐标0-1023,Y的坐标0-255,在终止单元格的X坐标0-1023,Y的坐标0-255,起始单元格列数,行数,终止单元格列数,行数)
|
||||
IClientAnchor anchor = patriarch.CreateAnchor(0, 0, 0, 0, 6, i, 7, i + 1);
|
||||
// 第五步:把图片插到相应的位置+1
|
||||
IPicture pict = patriarch.CreatePicture(anchor, pictureIdx);
|
||||
//就取第一张,如果后期想取全部 那把下面这个跳出语句去掉
|
||||
// break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cell = row.CreateCell(6);
|
||||
// cell.CellStyle = cellStyle;
|
||||
// cell.SetCellValue(item.CheckSite);//整改后照片
|
||||
|
||||
// cell = row.CreateCell(5);
|
||||
// cell.CellStyle = cellStyle;
|
||||
// cell.SetCellValue(item.CheckSite);//部位
|
||||
|
||||
cell = row.CreateCell(7);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.QuestionDef);//问题描述
|
||||
|
||||
cell = row.CreateCell(8);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.RectifyOpinion);//整改意见
|
||||
|
||||
cell = row.CreateCell(9);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.LimitDate.HasValue ? string.Format("{0:yyyy-MM-dd}", item.LimitDate) : "");//整改日期
|
||||
|
||||
cell = row.CreateCell(8);
|
||||
cell = row.CreateCell(10);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(BLL.UserService.GetUserNameByUserId(item.CheckMan));//检查人
|
||||
|
||||
cell = row.CreateCell(9);
|
||||
cell = row.CreateCell(11);
|
||||
cell.CellStyle = cellStyle;
|
||||
string s = string.Empty;
|
||||
if (!string.IsNullOrEmpty(item.State))
|
||||
|
@ -810,7 +892,7 @@ namespace FineUIPro.Web.CQMS.Check
|
|||
}
|
||||
cell.SetCellValue(s);//审批状态
|
||||
|
||||
cell = row.CreateCell(10);
|
||||
cell = row.CreateCell(12);
|
||||
cell.CellStyle = cellStyle;
|
||||
string man = string.Empty;
|
||||
if (!string.IsNullOrEmpty(item.CheckControlCode))
|
||||
|
@ -819,7 +901,7 @@ namespace FineUIPro.Web.CQMS.Check
|
|||
}
|
||||
cell.SetCellValue(man);//办理人
|
||||
|
||||
cell = row.CreateCell(11);
|
||||
cell = row.CreateCell(13);
|
||||
cell.CellStyle = cellStyle;
|
||||
string status = string.Empty;
|
||||
if (!string.IsNullOrEmpty(item.CheckControlCode))
|
||||
|
|
|
@ -488,58 +488,210 @@ namespace FineUIPro.Web.CQMS.Check
|
|||
NPOI.SS.UserModel.IRow row = sheet.GetRow(0);
|
||||
NPOI.SS.UserModel.ICell cell;
|
||||
int i = 2;
|
||||
foreach (var item in lists)
|
||||
|
||||
// 将 lists 转换为 DataTable
|
||||
DataTable tb = LINQToDataTable(lists);
|
||||
// 创建一个列表来存储CheckStatisc对象
|
||||
var checkStatiscList = new List<CheckStatisc>();
|
||||
if (this.rbType.SelectedValue == "0")
|
||||
{
|
||||
// 使用LINQ对DataTable进行分组统计----年份
|
||||
var query = from row1 in tb.AsEnumerable()
|
||||
let checkDate = row1.Field<DateTime>("CheckDate")
|
||||
let state = row1.Field<int>("OK")
|
||||
group row1 by new { checkDate.Year, state }
|
||||
into g
|
||||
select new
|
||||
{
|
||||
Year = g.Key.Year,
|
||||
State = g.Key.state,
|
||||
Count = g.Count()
|
||||
};
|
||||
// 计算每个年份的总记录数
|
||||
var yearlyTotals = query.GroupBy(q => q.Year).ToDictionary(g => g.Key, g => g.Sum(q => q.Count));
|
||||
|
||||
// 创建一个包含年度总数和不同State计数的结果集
|
||||
var result = query.GroupBy(q => q.Year).Select(g => new
|
||||
{
|
||||
Year = g.Key,
|
||||
YearlyTotal = yearlyTotals[g.Key],
|
||||
CompleteNumber = g.Where(q => q.State == 1).Sum(q => q.Count),
|
||||
NCompleteNumber = g.Where(q => q.State == 0).Sum(q => q.Count)
|
||||
}).ToList();
|
||||
// 遍历结果集并创建CheckStatisc对象
|
||||
foreach (var item in result)
|
||||
{
|
||||
var checkStatisc = new CheckStatisc
|
||||
{
|
||||
TypeName = item.Year.ToString(),
|
||||
AllNumber = item.YearlyTotal,
|
||||
CompleteNumber = item.CompleteNumber,
|
||||
NCompleteNumber = item.NCompleteNumber,
|
||||
Probability = ((double)item.CompleteNumber / item.YearlyTotal * 100).ToString("F2") + "%"
|
||||
};
|
||||
|
||||
checkStatiscList.Add(checkStatisc);
|
||||
}
|
||||
}
|
||||
else if (this.rbType.SelectedValue == "1")
|
||||
{
|
||||
// 使用LINQ对DataTable进行分组统计----年月
|
||||
var queryByMonth = from row1 in tb.AsEnumerable()
|
||||
let checkDate = row1.Field<DateTime>("CheckDate")
|
||||
let state = row1.Field<int>("OK")
|
||||
group row1 by new { checkDate.Year, checkDate.Month, state }
|
||||
into g
|
||||
select new
|
||||
{
|
||||
Year = g.Key.Year,
|
||||
Month = g.Key.Month,
|
||||
State = g.Key.state,
|
||||
Count = g.Count()
|
||||
};
|
||||
|
||||
// 计算每个月的总记录数
|
||||
var monthlyTotals = queryByMonth.GroupBy(q => new { q.Year, q.Month }).ToDictionary(
|
||||
g => new { g.Key.Year, g.Key.Month },
|
||||
g => g.Sum(q => q.Count));
|
||||
|
||||
// 创建一个包含月度总数和不同State计数的结果集
|
||||
var resultByMonth = queryByMonth.GroupBy(q => new { q.Year, q.Month }).Select(g => new
|
||||
{
|
||||
Year = g.Key.Year,
|
||||
Month = g.Key.Month,
|
||||
MonthlyTotal = monthlyTotals[g.Key],
|
||||
CompleteNumber = g.Where(q => q.State == 1).Sum(q => q.Count),
|
||||
NCompleteNumber = g.Where(q => q.State == 0).Sum(q => q.Count)
|
||||
}).ToList();
|
||||
|
||||
// 遍历结果集并创建CheckStatisc对象
|
||||
foreach (var item in resultByMonth)
|
||||
{
|
||||
var checkStatisc = new CheckStatisc
|
||||
{
|
||||
TypeName = $"{item.Year}年{item.Month:D2}月",
|
||||
AllNumber = item.MonthlyTotal,
|
||||
CompleteNumber = item.CompleteNumber,
|
||||
NCompleteNumber = item.NCompleteNumber,
|
||||
Probability = ((double)item.CompleteNumber / item.MonthlyTotal * 100).ToString("F2") + "%"
|
||||
};
|
||||
|
||||
checkStatiscList.Add(checkStatisc);
|
||||
}
|
||||
}
|
||||
else if (this.rbType.SelectedValue == "2")
|
||||
{
|
||||
// 使用LINQ对DataTable进行分组统计----专业名称
|
||||
var queryByProfessionalName = from row1 in tb.AsEnumerable()
|
||||
let professionalName = row1.Field<string>("ProfessionalName")
|
||||
let state = row1.Field<int>("OK")
|
||||
group row1 by professionalName
|
||||
into g
|
||||
select new
|
||||
{
|
||||
ProfessionalName = g.Key,
|
||||
TotalCount = g.Count(),
|
||||
CompleteCount = g.Count(q => q.Field<int>("OK") == 1),
|
||||
IncompleteCount = g.Count(q => q.Field<int>("OK") != 0)
|
||||
};
|
||||
|
||||
// 遍历结果集并创建CheckStatisc对象
|
||||
foreach (var item in queryByProfessionalName)
|
||||
{
|
||||
var checkStatisc = new CheckStatisc
|
||||
{
|
||||
TypeName = item.ProfessionalName,
|
||||
AllNumber = item.TotalCount,
|
||||
CompleteNumber = item.CompleteCount,
|
||||
NCompleteNumber = item.IncompleteCount,
|
||||
Probability = ((double)item.CompleteCount / item.TotalCount * 100).ToString("F2") + "%"
|
||||
};
|
||||
|
||||
checkStatiscList.Add(checkStatisc);
|
||||
}
|
||||
}
|
||||
checkStatiscList = checkStatiscList.OrderBy(cs => cs.TypeName).ToList();
|
||||
|
||||
foreach (var item in checkStatiscList)
|
||||
{
|
||||
// 第二步:创建新数据行
|
||||
row = sheet.CreateRow(i);
|
||||
// 添加数据
|
||||
cell = row.CreateCell(0);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(BLL.UnitService.GetUnitNameByUnitId(item.UnitId));//施工单位
|
||||
cell.SetCellValue(item.TypeName);//类型名称
|
||||
|
||||
cell = row.CreateCell(1);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.CheckDate.HasValue ? string.Format("{0:yyyy-MM-dd}", item.CheckDate) : "");
|
||||
cell.SetCellValue(item.AllNumber);//总数
|
||||
|
||||
cell = row.CreateCell(2);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.CheckTypeStr);
|
||||
cell.SetCellValue(item.CompleteNumber);//合格数
|
||||
|
||||
cell = row.CreateCell(3);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.UnitWorkName);
|
||||
cell.SetCellValue(item.NCompleteNumber);//不合格数
|
||||
|
||||
cell = row.CreateCell(4);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.ProfessionalName);
|
||||
|
||||
cell = row.CreateCell(5);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.QuestionTypeStr);
|
||||
|
||||
cell = row.CreateCell(6);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.CheckSite);
|
||||
|
||||
cell = row.CreateCell(7);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.QuestionDef);
|
||||
|
||||
cell = row.CreateCell(8);
|
||||
cell.CellStyle = cellStyle;
|
||||
cell.SetCellValue(item.HandleWay);
|
||||
|
||||
cell = row.CreateCell(9);
|
||||
cell.CellStyle = cellStyle;
|
||||
string s = string.Empty;
|
||||
if (!string.IsNullOrEmpty(item.JointCheckDetailId))
|
||||
{
|
||||
s = ConvertState(item.JointCheckDetailId);
|
||||
}
|
||||
cell.SetCellValue(s);
|
||||
|
||||
cell.SetCellValue(item.Probability);//合格率
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
// foreach (var item in lists)
|
||||
// {
|
||||
// // 第二步:创建新数据行
|
||||
// row = sheet.CreateRow(i);
|
||||
// // 添加数据
|
||||
// cell = row.CreateCell(0);
|
||||
// cell.CellStyle = cellStyle;
|
||||
// cell.SetCellValue(BLL.UnitService.GetUnitNameByUnitId(item.UnitId));//施工单位
|
||||
//
|
||||
// cell = row.CreateCell(1);
|
||||
// cell.CellStyle = cellStyle;
|
||||
// cell.SetCellValue(item.CheckDate.HasValue ? string.Format("{0:yyyy-MM-dd}", item.CheckDate) : "");
|
||||
//
|
||||
// cell = row.CreateCell(2);
|
||||
// cell.CellStyle = cellStyle;
|
||||
// cell.SetCellValue(item.CheckTypeStr);
|
||||
//
|
||||
// cell = row.CreateCell(3);
|
||||
// cell.CellStyle = cellStyle;
|
||||
// cell.SetCellValue(item.UnitWorkName);
|
||||
//
|
||||
// cell = row.CreateCell(4);
|
||||
// cell.CellStyle = cellStyle;
|
||||
// cell.SetCellValue(item.ProfessionalName);
|
||||
//
|
||||
// cell = row.CreateCell(5);
|
||||
// cell.CellStyle = cellStyle;
|
||||
// cell.SetCellValue(item.QuestionTypeStr);
|
||||
//
|
||||
// cell = row.CreateCell(6);
|
||||
// cell.CellStyle = cellStyle;
|
||||
// cell.SetCellValue(item.CheckSite);
|
||||
//
|
||||
// cell = row.CreateCell(7);
|
||||
// cell.CellStyle = cellStyle;
|
||||
// cell.SetCellValue(item.QuestionDef);
|
||||
//
|
||||
// cell = row.CreateCell(8);
|
||||
// cell.CellStyle = cellStyle;
|
||||
// cell.SetCellValue(item.HandleWay);
|
||||
//
|
||||
// cell = row.CreateCell(9);
|
||||
// cell.CellStyle = cellStyle;
|
||||
// string s = string.Empty;
|
||||
// if (!string.IsNullOrEmpty(item.JointCheckDetailId))
|
||||
// {
|
||||
// s = ConvertState(item.JointCheckDetailId);
|
||||
// }
|
||||
// cell.SetCellValue(s);
|
||||
//
|
||||
// i++;
|
||||
// }
|
||||
// 第三步:写入文件流
|
||||
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue