导出
This commit is contained in:
parent
146747a1ed
commit
86754175f3
@ -1,10 +1,13 @@
|
||||
using DOAN.Admin.WebApi.Filters;
|
||||
using DOAN.Model;
|
||||
using DOAN.Model.MES;
|
||||
using DOAN.Model.MES.product.Dto;
|
||||
using DOAN.Service.MES.product;
|
||||
using DOAN.Service.MES.product.IService;
|
||||
using DOAN.Service.MES.report.IService;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.HPSF;
|
||||
|
||||
namespace DOAN.WebApi.Controllers
|
||||
{
|
||||
@ -19,7 +22,7 @@ namespace DOAN.WebApi.Controllers
|
||||
public ReportController(IProPlanAchievementrateVersion2Service ProPlanAchievementrateService, IReportService ReportService)
|
||||
{
|
||||
_ProPlanAchievementrateVersion2Service = ProPlanAchievementrateService;
|
||||
_ReportService=ReportService;
|
||||
_ReportService = ReportService;
|
||||
}
|
||||
/// <summary>
|
||||
/// 月生产数据统计列表
|
||||
@ -27,9 +30,9 @@ namespace DOAN.WebApi.Controllers
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("listMonth")]
|
||||
public IActionResult QueryMonthProuct([FromQuery] MonthProuctDto parm)
|
||||
public IActionResult QueryMonthProduct([FromQuery] MonthProductDto parm)
|
||||
{
|
||||
var response = _ProPlanAchievementrateVersion2Service.GetQueryMonthProucth(parm);
|
||||
var response = _ProPlanAchievementrateVersion2Service.GetQueryMonthProduct(parm);
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
@ -65,5 +68,17 @@ namespace DOAN.WebApi.Controllers
|
||||
var response = _ReportService.ProductionCompletionRate(DateTime.Today);
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
[HttpGet("exportMonthProduct")]
|
||||
[Log(Title = "工单导出", BusinessType = BusinessType.EXPORT)]
|
||||
[AllowAnonymous]
|
||||
public IActionResult ExportMonthProduct([FromQuery] MonthProductDto parm)
|
||||
{
|
||||
var (fileBytes, fileName) = _ProPlanAchievementrateVersion2Service.ExportMonthProduct(parm);
|
||||
|
||||
string contnetType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||||
return File(fileBytes,contnetType,fileName);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,8 @@
|
||||
"dbConfigs": [
|
||||
{
|
||||
// "Conn": "Data Source=139.224.232.211;User ID=root;Password=doantech123;Initial Catalog=GXAssembly;Port=3308",
|
||||
//"Conn": "Data Source=118.25.48.201;User ID=root;Password=123456;Initial Catalog=gxassembly;Port=3306;AllowLoadLocalInfile=true",
|
||||
//阿里云
|
||||
//"Conn": "Data Source=47.101.40.214;User ID=root;Password=Rizo123456@;Initial Catalog=gxassembly;Port=3306;AllowLoadLocalInfile=true",
|
||||
"Conn": "Data Source=192.168.1.48;User ID=root;Password=123456;Initial Catalog=GXAssembly;Port=3306;AllowLoadLocalInfile=true",
|
||||
// "Conn": "Data Source=127.0.0.1;User ID=root;Password=123456;Initial Catalog=GXAssembly;Port=3306",
|
||||
//"Conn": "Data Source=192.168.50.163;User ID=root;Password=123456;Initial Catalog=GXAssembly;Port=3306",
|
||||
|
||||
BIN
DOAN.Admin.WebApi/wwwroot/ImportTemplate/MonthProductData.xlsx
Normal file
BIN
DOAN.Admin.WebApi/wwwroot/ImportTemplate/MonthProductData.xlsx
Normal file
Binary file not shown.
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace DOAN.Model.MES
|
||||
{
|
||||
public class MonthProuctDto //: PagerInfo
|
||||
public class MonthProductDto //: PagerInfo
|
||||
{
|
||||
public DateTime SearchYearMonth { get; set; }
|
||||
}
|
||||
|
||||
@ -47,6 +47,8 @@ namespace DOAN.Service.MES.product.IService
|
||||
|
||||
byte[] ExportData(DateTime exportDate);
|
||||
|
||||
List<MonthProuctModel> GetQueryMonthProucth(MonthProuctDto parm);
|
||||
List<MonthProuctModel> GetQueryMonthProduct(MonthProductDto parm);
|
||||
|
||||
(byte[] fileBytes, string fileName) ExportMonthProduct(MonthProductDto parm);
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ using NPOI.HSSF.Record;
|
||||
using JinianNet.JNTemplate;
|
||||
using DOAN.Model.MES;
|
||||
using DOAN.Model.MES.report;
|
||||
using NPOI.POIFS.Crypt.Dsig;
|
||||
namespace DOAN.Service.MES.product
|
||||
{
|
||||
/// <summary>
|
||||
@ -71,7 +72,7 @@ namespace DOAN.Service.MES.product
|
||||
SqlFunc.AggregateSum(w.DeliveryNum) == 0
|
||||
? 0
|
||||
: SqlFunc.Round<decimal>(
|
||||
(decimal)SqlFunc.AggregateSum(r.FinishedNum??0) / (decimal)SqlFunc.AggregateSum(w.DeliveryNum) * 100,
|
||||
(decimal)SqlFunc.AggregateSum(r.FinishedNum ?? 0) / (decimal)SqlFunc.AggregateSum(w.DeliveryNum) * 100,
|
||||
0
|
||||
),
|
||||
RecordDate = parm.GenarateDate,
|
||||
@ -572,7 +573,7 @@ namespace DOAN.Service.MES.product
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public List<MonthProuctModel> GetQueryMonthProucth(MonthProuctDto parm)
|
||||
public List<MonthProuctModel> GetQueryMonthProduct(MonthProductDto parm)
|
||||
{
|
||||
(DateTime FirstDay, DateTime LastDay) Handlemonth = GetFirstAndLastDayOfMonth(parm.SearchYearMonth);
|
||||
var predicate = Expressionable.Create<ProPlanAchievementrateVersion2>()
|
||||
@ -580,7 +581,7 @@ namespace DOAN.Service.MES.product
|
||||
|
||||
var response = Context.Queryable<ProPlanAchievementrateVersion2>()
|
||||
.Where(predicate.ToExpression())
|
||||
.GroupBy(it => new { it.Project,it.RecordDate })
|
||||
.GroupBy(it => new { it.Project, it.RecordDate })
|
||||
.Select(it => new ProPlanAchievementrateVersion2()
|
||||
{
|
||||
Project = it.Project,
|
||||
@ -588,6 +589,7 @@ namespace DOAN.Service.MES.product
|
||||
SummaryPlanNum = SqlFunc.AggregateSum(it.SummaryPlanNum ?? 0),
|
||||
RecordDate = it.RecordDate
|
||||
})
|
||||
.OrderBy(it => it.Project)
|
||||
.ToList();
|
||||
|
||||
var monthProuctModelList = response.GroupBy(it => it.Project)
|
||||
@ -599,9 +601,9 @@ namespace DOAN.Service.MES.product
|
||||
DayIndex = it2.RecordDate?.Day ?? 0,
|
||||
SummaryActualNum = it2.SummaryActualNum,
|
||||
SummaryPlanNum = it2.SummaryPlanNum,
|
||||
}).OrderBy(t=>t.DayIndex).ToList(),
|
||||
}).OrderBy(t => t.DayIndex).ToList(),
|
||||
|
||||
}).OrderBy(t=>t.Project).ToList();
|
||||
}).OrderBy(t => t.Project).ToList();
|
||||
|
||||
monthProuctModelList.ForEach(t =>
|
||||
{
|
||||
@ -611,5 +613,67 @@ namespace DOAN.Service.MES.product
|
||||
});
|
||||
return monthProuctModelList;
|
||||
}
|
||||
|
||||
public (byte[] fileBytes, string fileName) ExportMonthProduct(MonthProductDto parm)
|
||||
{
|
||||
string templatePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "ImportTemplate", "MonthProductData.xlsx");
|
||||
if (!File.Exists(templatePath))
|
||||
{
|
||||
throw new CustomException("Excel 模板文件不存在");
|
||||
}
|
||||
List<MonthProuctModel> list = GetQueryMonthProduct(parm);
|
||||
if(list.Count==0)
|
||||
{
|
||||
throw new CustomException("没有数据可以导出");
|
||||
}
|
||||
|
||||
int lastDay = DateTime.DaysInMonth(parm.SearchYearMonth.Year, parm.SearchYearMonth.Month);
|
||||
|
||||
using (FileStream fileStream = new FileStream(templatePath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
IWorkbook workbook = new XSSFWorkbook(fileStream);
|
||||
ISheet sheet = workbook.GetSheet("Sheet1");
|
||||
if (sheet == null)
|
||||
{
|
||||
throw new CustomException("未找到 Sheet1,请检查 Excel 模板");
|
||||
}
|
||||
int dataRowIndex = 3;
|
||||
if (sheet.GetRow(1) != null)
|
||||
{
|
||||
sheet.GetRow(1).CreateCell(0).SetCellValue(parm.SearchYearMonth.ToString("yyyy-MM"));
|
||||
}
|
||||
IRow headerRow = sheet.GetRow(dataRowIndex-1) ?? sheet.CreateRow(dataRowIndex);
|
||||
for(int i = 1; i <= lastDay; i++)
|
||||
{
|
||||
//headerRow.CreateCell(i).SetCellValue(i.ToString());
|
||||
headerRow.CopyCell(0,i).SetCellValue(i.ToString());
|
||||
}
|
||||
headerRow.CopyCell(0, lastDay + 1).SetCellValue("计划数");
|
||||
headerRow.CopyCell(0, lastDay + 2).SetCellValue("实际数");
|
||||
headerRow.CopyCell(0, lastDay + 3).SetCellValue("完成率%");
|
||||
|
||||
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
IRow dataRow = sheet.GetRow(dataRowIndex) ?? sheet.CreateRow(dataRowIndex);
|
||||
dataRow.CreateCell(0).SetCellValue(item.Project); // A列
|
||||
for (int i = 1; i <= lastDay; i++)
|
||||
{
|
||||
var dayProduct=item.DayProuctModels.FirstOrDefault(t=>t.DayIndex==i);
|
||||
dataRow.CreateCell(i).SetCellValue(dayProduct?.SummaryActualNum ?? 0);
|
||||
}
|
||||
|
||||
dataRow.CreateCell(lastDay+1).SetCellValue(item.SummaryPlanNum ?? 0); // B列
|
||||
dataRow.CreateCell(lastDay+2).SetCellValue(item.SummaryActualNum ?? 0); // C列
|
||||
dataRow.CreateCell(lastDay+3).SetCellValue((double)item.SummaryPlanAchievementRate); // D列
|
||||
dataRowIndex++;
|
||||
}
|
||||
|
||||
var memoryStream = new MemoryStream();
|
||||
workbook.Write(memoryStream);
|
||||
return (memoryStream.ToArray(), "月生产数据统计.xlsx");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user