|
@@ -10,6 +10,9 @@ using ZR.Service.Business.IBusinessService;
|
|
|
using ZR.Admin.WebApi.Extensions;
|
|
|
using ZR.Admin.WebApi.Filters;
|
|
|
using ZR.Common;
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
+using MiniExcelLibs;
|
|
|
+using ZR.Service.Business;
|
|
|
|
|
|
namespace ZR.Admin.WebApi.Controllers
|
|
|
{
|
|
@@ -119,7 +122,84 @@ namespace ZR.Admin.WebApi.Controllers
|
|
|
return ToResponse(response);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 导入
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("importData")]
|
|
|
+ [Log(Title = "交验单导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = false)]
|
|
|
+ [ActionPermissionFilter(Permission = "business:sapdeliverrecord:import")]
|
|
|
+ public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
|
|
|
+ {
|
|
|
+ List<dynamic>? list = new();
|
|
|
+ //读取上传文件内容。
|
|
|
+ using (var stream = formFile.OpenReadStream())
|
|
|
+ {
|
|
|
+ //list = stream.Query<SapDeliverRecord>(startCell:"A6").ToList();
|
|
|
+ list = stream.Query().ToList();
|
|
|
|
|
|
+ //var test= stream.Query(sheetName:"sheet1");
|
|
|
+ }
|
|
|
+ string deliverNo = list[2].M;
|
|
|
+ if (string.IsNullOrEmpty(deliverNo))
|
|
|
+ {
|
|
|
+ return SUCCESS("未找到交验单编号,导入文件格式错误");
|
|
|
+ }
|
|
|
+ deliverNo = deliverNo.Replace("编号", "").Replace(":", "").Replace(":", "");
|
|
|
+ string checkName = list[3].A;
|
|
|
+ checkName = string.IsNullOrEmpty(checkName) ? "" : checkName.Replace("送检人员", "").Replace(":", "").Replace(":", "");
|
|
|
+ List<SapDeliverRecord> sapDeliverRecords = new();
|
|
|
+ for (int i = 6; i < list.Count; i++)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty($"{list[i].A}"))
|
|
|
+ {
|
|
|
+ break;//序号一列出现空,即交验单内容结束
|
|
|
+ }
|
|
|
+ SapDeliverRecord sapDeliverRecord = new()
|
|
|
+ {
|
|
|
+ DeliverNo = deliverNo,
|
|
|
+ CheckName = checkName,
|
|
|
+ BomNo = list[i].B,
|
|
|
+ RowNo = Convert.ToInt32(list[i].D),
|
|
|
+ MaterialCode = $"MAT{list[i].F}",//非空 模拟数据
|
|
|
+ MaterialName = list[i].E,
|
|
|
+ MaterialSpec = list[i].F,
|
|
|
+ Category = (i % 2) > 0 ? "外协件" : "外购件",//非空 模拟数据
|
|
|
+ KeyFlag = (i % 2) > 0,//非空 模拟数据
|
|
|
+ Qty = Convert.ToInt32(list[i].H),
|
|
|
+ SpotCheckQty = Convert.ToInt32(list[i].I),
|
|
|
+ CheckQty = Convert.ToInt32(list[i].M),
|
|
|
+ CheckResult = "OK",//非空 模拟数据
|
|
|
+ InstoreResult = 99,//非空 模拟数据
|
|
|
+
|
|
|
+ CreateBy=HttpContext.GetName(),
|
|
|
+ CreateTime = DateTime.Now,
|
|
|
+ Remark = "导入数据"
|
|
|
+ };
|
|
|
+ sapDeliverRecords.Add(sapDeliverRecord);
|
|
|
+ }
|
|
|
+ string msg = _SapDeliverRecordService.ImportDatas(sapDeliverRecords);
|
|
|
+
|
|
|
+ //TODO 业务逻辑,自行插入数据到db
|
|
|
+ return SUCCESS(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 用户导入模板下载 //这里是根据对象字段自动生成的模板,不符合实际使用需要。
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("importTemplate")]
|
|
|
+ [Log(Title = "交验单模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = false, IsSaveResponseData = false)]
|
|
|
+ [AllowAnonymous]
|
|
|
+ public IActionResult ImportTemplateExcel()
|
|
|
+ {
|
|
|
+ List<SapDeliverRecordImportTemplete> list = new();
|
|
|
+ MemoryStream stream = new();
|
|
|
+
|
|
|
+ var fileInfo = DownloadImportTemplate(list, stream, "交验单");
|
|
|
+ return ExportExcel(fileInfo.Item1, fileInfo.Item2);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
}
|