质量检验-导出全部数据
This commit is contained in:
@@ -5,6 +5,10 @@ using ZR.Service.mes.qc.IService;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Model.MES.qc;
|
||||
using System.Collections.Generic;
|
||||
using ZR.Model.MES.qc.DTO;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using NPOI.SS.UserModel;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers.mes.qc.FQC
|
||||
{
|
||||
@@ -25,7 +29,7 @@ namespace ZR.Admin.WebApi.Controllers.mes.qc.FQC
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("queryQualityStatisticsTable_first")]
|
||||
public IActionResult GetQualityStatisticsTable_first(DateTime starttime,DateTime endTime,string workorderid,string partnumber,string product_description,string team,int pageNum,int pageSize)
|
||||
public IActionResult GetQualityStatisticsTable_first(DateTime starttime, DateTime endTime, string workorderid, string partnumber, string product_description, string team, int pageNum, int pageSize)
|
||||
{
|
||||
(List<QcQualityStatisticsFirst>, int) list = qcStatistics.GetQualityStatisticsTable_first(starttime, endTime, workorderid, partnumber, product_description, team, pageNum, pageSize);
|
||||
|
||||
@@ -69,11 +73,122 @@ namespace ZR.Admin.WebApi.Controllers.mes.qc.FQC
|
||||
|
||||
|
||||
[HttpGet("delete_statisticsTable")]
|
||||
public IActionResult DeleteStatisticsTable(string workorderid)
|
||||
public IActionResult DeleteStatisticsTable(string workorderid)
|
||||
{
|
||||
int deletenum= qcStatistics.DeleteStatisticsTable(workorderid);
|
||||
int deletenum = qcStatistics.DeleteStatisticsTable(workorderid);
|
||||
return SUCCESS(deletenum);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 导出对应报表
|
||||
/// </summary>
|
||||
/// <param name="starttime">开始时间</param>
|
||||
/// <param name="endTime">结束时间</param>
|
||||
/// <param name="workorderid">工单号</param>
|
||||
/// <param name="partnumber">零件号</param>
|
||||
/// <param name="product_description">产品描述</param>
|
||||
/// <param name="team">班组</param>
|
||||
/// <param name="pageNum">分页开始</param>
|
||||
/// <param name="pageSize">分页结束</param>
|
||||
/// <param name="type">报表类别 1-首检 2-抛光 3-包装 4-全部</param>
|
||||
/// <param name="isShowDetail">是否展示细节,展示细节则根据三行,两行合并规则</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("downloadStatisticsTableExcel")]
|
||||
public IActionResult DownloadStatisticsTableExcel(DateTime starttime, DateTime endTime, string workorderid, string partnumber, string product_description, string team, int pageNum, int pageSize, int type, bool isShowDetail)
|
||||
{
|
||||
try
|
||||
{
|
||||
string fileName = @"导出统计报表-" + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + Guid.NewGuid() + ".xlsx";
|
||||
List<QcQualityStatisticsFirstDto> excelDataList = qcStatistics.DownloadStatisticsTableExcel(starttime, endTime, workorderid, partnumber, product_description, team, pageNum, pageSize, type);
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
var sheet = workbook.CreateSheet();
|
||||
// 标题列
|
||||
var row0 = sheet.CreateRow(0);
|
||||
ICellStyle style = workbook.CreateCellStyle();
|
||||
style.Alignment = HorizontalAlignment.Center;
|
||||
style.VerticalAlignment = VerticalAlignment.Center;
|
||||
string[] titleDict = { "工单号", "零件号", "颜色", "描述", "生产投入数", "班次", "合格数", "合格率", "抛光总数", "打磨总数", "报废总数", "开始时间", "结束时间"};
|
||||
string[] titleDetailDict = { "备注", "缩孔", "针孔" };
|
||||
if(isShowDetail)
|
||||
{
|
||||
titleDict.Concat(titleDetailDict);
|
||||
}
|
||||
for (int i = 0; i < titleDict.Length; i++)
|
||||
{
|
||||
var cell = row0.CreateCell(i);
|
||||
cell.SetCellValue(titleDict[i]);
|
||||
cell.CellStyle = style;
|
||||
}
|
||||
string _lastWorkOrderId = "";
|
||||
int rowIndex = 1;
|
||||
for (int i = 0;i< excelDataList.Count;i++) {
|
||||
var item = excelDataList[i];
|
||||
if (_lastWorkOrderId == item.WorkorderId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var row = sheet.CreateRow(rowIndex);
|
||||
if (!isShowDetail)
|
||||
{
|
||||
|
||||
var cell1 = row.CreateCell(0);
|
||||
cell1.SetCellValue(item.WorkorderId);
|
||||
cell1.CellStyle = style;
|
||||
var cell2 = row.CreateCell(1);
|
||||
cell2.SetCellValue(item.FinishedPartNumber);
|
||||
cell2.CellStyle = style;
|
||||
var cell3 = row.CreateCell(2);
|
||||
cell3.SetCellValue(item.Color);
|
||||
cell3.CellStyle = style;
|
||||
var cell4 = row.CreateCell(3);
|
||||
cell4.SetCellValue(item.ProductDescription);
|
||||
cell4.CellStyle = style;
|
||||
var cell5 = row.CreateCell(4);
|
||||
cell5.SetCellValue(item.RequireNumber.ToString());
|
||||
cell5.CellStyle = style;
|
||||
var cell6 = row.CreateCell(5);
|
||||
cell6.SetCellValue(item.Team);
|
||||
cell6.CellStyle = style;
|
||||
var cell7 = row.CreateCell(6);
|
||||
cell7.SetCellValue(item.RequireNumber.ToString());
|
||||
cell7.CellStyle = style;
|
||||
var cell8 = row.CreateCell(7);
|
||||
cell8.SetCellValue(item.QualifiedRate.ToString());
|
||||
cell8.CellStyle = style;
|
||||
var cell9 = row.CreateCell(8);
|
||||
cell9.SetCellValue(item.PaoguangTotal.ToString());
|
||||
cell9.CellStyle = style;
|
||||
var cell10 = row.CreateCell(9);
|
||||
cell10.SetCellValue(item.DamoTotal.ToString());
|
||||
cell10.CellStyle = style;
|
||||
var cell11 = row.CreateCell(10);
|
||||
cell11.SetCellValue(item.BaofeiTotal.ToString());
|
||||
cell11.CellStyle = style;
|
||||
var cell12 = row.CreateCell(11);
|
||||
cell12.SetCellValue(item.StartTime.ToString());
|
||||
cell12.CellStyle = style;
|
||||
var cell13 = row.CreateCell(12);
|
||||
cell13.SetCellValue(item.EndTime.ToString());
|
||||
cell13.CellStyle = style;
|
||||
}
|
||||
_lastWorkOrderId = item.WorkorderId;
|
||||
rowIndex++;
|
||||
}
|
||||
IWebHostEnvironment webHostEnvironment = (IWebHostEnvironment)App.ServiceProvider.GetService(typeof(IWebHostEnvironment));
|
||||
string fullPath = Path.Combine(webHostEnvironment.WebRootPath, "QualityStatisticsExport", fileName);
|
||||
using (FileStream fs = new(fullPath, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
workbook.Write(fs);
|
||||
}
|
||||
workbook.Dispose();
|
||||
return ExportExcel(fullPath, fileName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ToResponse(new ApiResult(500, e.Message, "Excel导出异常"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1
ZR.Admin.WebApi/wwwroot/.gitignore
vendored
Normal file
1
ZR.Admin.WebApi/wwwroot/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/QualityStatisticsExport
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.MES.qc;
|
||||
using ZR.Model.MES.qc.DTO;
|
||||
|
||||
namespace ZR.Service.mes.qc.IService
|
||||
{
|
||||
@@ -24,5 +25,20 @@ namespace ZR.Service.mes.qc.IService
|
||||
#endregion
|
||||
|
||||
public int DeleteStatisticsTable(string workorderid);
|
||||
|
||||
/// <summary>
|
||||
/// 导出指定的质检报告数据
|
||||
/// </summary>
|
||||
/// <param name="starttime"></param>
|
||||
/// <param name="endTime"></param>
|
||||
/// <param name="workorderid"></param>
|
||||
/// <param name="partnumber"></param>
|
||||
/// <param name="product_description"></param>
|
||||
/// <param name="team"></param>
|
||||
/// <param name="pageNum"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
List<QcQualityStatisticsFirstDto> DownloadStatisticsTableExcel(DateTime starttime, DateTime endTime, string workorderid, string partnumber, string product_description, string team, int pageNum, int pageSize, int type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Mapster;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Security.AccessControl;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Model.mes.md;
|
||||
using ZR.Model.MES.qc;
|
||||
using ZR.Model.MES.qc.DTO;
|
||||
using ZR.Model.MES.qu;
|
||||
using ZR.Service.mes.qc.IService;
|
||||
|
||||
@@ -191,5 +196,71 @@ namespace ZR.Service.mes.qc
|
||||
return num;
|
||||
|
||||
}
|
||||
List<QcQualityStatisticsFirstDto> IQCStatisticsService.DownloadStatisticsTableExcel(DateTime starttime, DateTime endTime, string workorderid, string partnumber, string product_description, string team, int pageNum, int pageSize, int type)
|
||||
{
|
||||
try
|
||||
{
|
||||
pageNum = 1;
|
||||
pageSize = 5000;
|
||||
return type switch
|
||||
{
|
||||
// 首检
|
||||
1 => DoFirstExcel(starttime, endTime, workorderid, partnumber, product_description, team, pageNum, pageSize),
|
||||
// 抛光
|
||||
2 => DoSecondExcel(starttime, endTime, workorderid, partnumber, product_description, team, pageNum, pageSize),
|
||||
// 包装
|
||||
3 => DoThirdExcel(starttime, endTime, workorderid, partnumber, product_description, team, pageNum, pageSize),
|
||||
// 总表
|
||||
4 => DoTotalExcel(starttime, endTime, workorderid, partnumber, product_description, team, pageNum, pageSize),
|
||||
_ => throw new Exception("获取的报表类型错误!" + type),
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
public List<QcQualityStatisticsFirstDto> DoFirstExcel(DateTime starttime, DateTime endTime, string workorderid, string partnumber, string product_description, string team, int pageNum, int pageSize)
|
||||
{
|
||||
|
||||
List<QcQualityStatisticsFirst> list = GetQualityStatisticsTable_first(starttime, endTime, workorderid, partnumber, product_description, team, pageNum, pageSize).Item1;
|
||||
List<QcQualityStatisticsFirstDto> newList = list.Select(item => new QcQualityStatisticsFirstDto()
|
||||
{
|
||||
WorkorderId = item.WorkorderId,
|
||||
FinishedPartNumber = item.FinishedPartNumber,
|
||||
ProductDescription = product_description,
|
||||
Color = item.Color,
|
||||
RequireNumber = item.RequireNumber,
|
||||
Team = item.Team,
|
||||
QualifiedNumber = item.QualifiedNumber,
|
||||
QualifiedRate = item.QualifiedRate ?? 0,
|
||||
PaoguangTotal = item.PaoguangTotal ?? 0,
|
||||
DamoTotal = item.DamoTotal ?? 0,
|
||||
BaofeiTotal = item.BaofeiTotal ?? 0,
|
||||
StartTime = item.StartTime,
|
||||
EndTime = item.EndTime,
|
||||
}).ToList();
|
||||
return newList;
|
||||
}
|
||||
public List<QcQualityStatisticsFirstDto> DoSecondExcel(DateTime starttime, DateTime endTime, string workorderid, string partnumber, string product_description, string team, int pageNum, int pageSize)
|
||||
{
|
||||
List<QcQualityStatisticsAgain> list = GetQualityStatisticsTable_again(starttime, endTime, workorderid, partnumber, product_description, team, pageNum, pageSize).Item1;
|
||||
List<QcQualityStatisticsFirstDto> newList = list.Select(item => new QcQualityStatisticsFirstDto()).ToList();
|
||||
return newList;
|
||||
}
|
||||
|
||||
public List<QcQualityStatisticsFirstDto> DoThirdExcel(DateTime starttime, DateTime endTime, string workorderid, string partnumber, string product_description, string team, int pageNum, int pageSize)
|
||||
{
|
||||
List<QcQualityStatisticsFinal> list = GetQualityStatisticsTable_final(starttime, endTime, workorderid, partnumber, product_description, team, pageNum, pageSize).Item1;
|
||||
List<QcQualityStatisticsFirstDto> newList = list.Select(item => new QcQualityStatisticsFirstDto()).ToList();
|
||||
return newList;
|
||||
}
|
||||
public List<QcQualityStatisticsFirstDto> DoTotalExcel(DateTime starttime, DateTime endTime, string workorderid, string partnumber, string product_description, string team, int pageNum, int pageSize)
|
||||
{
|
||||
List<QcQualityStatisticsTotal> list = GetQualityStatisticsTable_total(starttime, endTime, workorderid, partnumber, product_description, team, pageNum, pageSize).Item1;
|
||||
List<QcQualityStatisticsFirstDto> newList = list.Select(item => new QcQualityStatisticsFirstDto()).ToList();
|
||||
return newList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user