From 9ba22d74e4aa2b8a1025f48cf353b5edd0b32eee Mon Sep 17 00:00:00 2001 From: Leo Date: Sat, 2 Sep 2023 21:32:46 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E6=96=B9=E6=B8=85=E5=8D=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=9F=A5=E8=AF=A2=E6=97=A5=E5=BF=97=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/FormulaController.cs | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/FactorySystemApi/Controllers/FormulaController.cs b/FactorySystemApi/Controllers/FormulaController.cs index 1337332..ac36be9 100644 --- a/FactorySystemApi/Controllers/FormulaController.cs +++ b/FactorySystemApi/Controllers/FormulaController.cs @@ -465,6 +465,79 @@ namespace FactorySystemApi.Controllers }, apiResult, Request); } + /// + /// 导出申请配方记录 + /// + /// + /// + [HttpPost] + public ApiResult ExportFormulaApplyHistory(Dictionary inParam) + { + ApiResult apiResult = new ApiResult(); + string rootPath = System.Web.Hosting.HostingEnvironment.MapPath("/"); + string savePath = "/File/Temp/配方清单/查询记录_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"; + + return ExceptionHelper.TryReturnException(() => + { + if (inParam != null && inParam.ContainsKey("applyHistory")) + { + inParam.TryGetValue("applyHistory", out object applyHistory); + List> hisList = JsonConvert.DeserializeObject>>(JsonConvert.SerializeObject(applyHistory)); + DataTable dataList = new DataTable(); + + if (hisList != null && hisList.Count > 0) + { + dataList.Columns.Add("申请日期"); + dataList.Columns.Add("申请人"); + dataList.Columns.Add("试验号"); + dataList.Columns.Add("产品名称"); + dataList.Columns.Add("申请数量"); + dataList.Columns.Add("备注"); + + foreach (Dictionary his in hisList) + { + DataRow row = dataList.NewRow(); + + string applyTime = his["FApplyTime"] != null ? his["FApplyTime"].ToString() : ""; + string userName = his["FUserName"] != null ? his["FUserName"].ToString() : ""; + string testCode = his["FTestCode"] != null ? his["FTestCode"].ToString() : ""; + string formulaName = his["FFormulaName"] != null ? his["FFormulaName"].ToString() : ""; + string applyNumber = his["FApplyNumber"] != null ? his["FApplyNumber"].ToString() : ""; + string remark = his["FRemark"] != null ? his["FRemark"].ToString() : ""; + + row["申请日期"] = applyTime; + row["申请人"] = userName; + row["试验号"] = testCode; + row["产品名称"] = formulaName; + row["申请数量"] = applyNumber; + row["备注"] = remark; + + dataList.Rows.Add(row); + } + + if (dataList != null && dataList.Rows.Count > 0) + { + NPOIHelper.ExportDTtoExcel(dataList, "sheet1", rootPath + savePath); + apiResult.Data = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, "").Trim('/') + savePath; + } + else + { + apiResult.Data = ""; + } + } + else + { + apiResult.Data = ""; + } + } + else + { + apiResult.Data = ""; + } + }, apiResult, Request); + + } + #region 内部方法 ///