|
@@ -140,47 +140,35 @@ namespace ZR.Admin.WebApi.Controllers.Inspect
|
|
|
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile, [FromForm(Name = "category")] string category)
|
|
|
{
|
|
|
//List<dynamic>? list = new();
|
|
|
- DataSet dataSet = new();
|
|
|
- //读取上传文件内容。
|
|
|
- using (var stream = formFile.OpenReadStream())
|
|
|
- {
|
|
|
- IExcelDataReader? readerData = null;
|
|
|
- //根据excel扩展名选择对应的读取文件流方式
|
|
|
- switch (formFile.FileName.Split('.').Last())
|
|
|
- {
|
|
|
- case "xls": readerData = ExcelReaderFactory.CreateBinaryReader(stream); break;
|
|
|
- case "xlsx": readerData = ExcelReaderFactory.CreateOpenXmlReader(stream); break;
|
|
|
- default: break;
|
|
|
- }
|
|
|
- if (readerData == null)
|
|
|
- {
|
|
|
- return SUCCESS("导入失败。<br/><br/>导入交验单文件错误。文件不是xls文件也不是xlsx文件。");
|
|
|
- }
|
|
|
- //验证交验单表头
|
|
|
- dataSet = readerData.AsDataSet();
|
|
|
- if (!dataSet.Tables[0].Rows[0][0].ToString().Contains("北京七星华创"))
|
|
|
- {
|
|
|
- return SUCCESS($"导入失败。<br/><br/>导入Excel的【{dataSet.Tables[0].TableName}】中<br/>表头为:{dataSet.Tables[0].Rows[0][0]}<br/>请确认文件无误。");
|
|
|
- }
|
|
|
- //通过交验单号,验证是否以存在交验单
|
|
|
- string checkDeliverNo = dataSet.Tables[1].Rows[1][2].ToString().Trim();
|
|
|
- if (string.IsNullOrEmpty( checkDeliverNo))
|
|
|
- {
|
|
|
- return SUCCESS($"导入失败。<br/><br/>导入Excel的【{dataSet.Tables[1].TableName}】中<br/>C列交验单号有误。");
|
|
|
- }
|
|
|
- var response = _SapDeliverRecordService.GetList(
|
|
|
- new SapDeliverRecordQueryDto { DeliverNo = checkDeliverNo });
|
|
|
- if (response.Result.Count>0)
|
|
|
- {
|
|
|
- return SUCCESS($"导入失败。<br/><br/>导入交验单【{checkDeliverNo}】已存在。");
|
|
|
- }
|
|
|
|
|
|
- //MiniExcel读取导入的Excel文件,因不支持xls格式,弃用。
|
|
|
- //var SheetNames = stream.GetSheetNames();
|
|
|
- //list = stream.Query(sheetName: SheetNames[1]).ToList();
|
|
|
+ DataSet dataSet = ExcelReader.ReadExcel(formFile);
|
|
|
|
|
|
+ if (dataSet == null)
|
|
|
+ {
|
|
|
+ return SUCCESS("导入失败。<br/><br/>导入交验单文件错误。文件不是xls文件也不是xlsx文件。");
|
|
|
+ }
|
|
|
+ if (!dataSet.Tables[0].Rows[0][0].ToString().Contains("北京七星华创"))
|
|
|
+ {
|
|
|
+ return SUCCESS($"导入失败。<br/><br/>导入Excel的【{dataSet.Tables[0].TableName}】中<br/>表头为:{dataSet.Tables[0].Rows[0][0]}<br/>请确认文件无误。");
|
|
|
+ }
|
|
|
+ //通过交验单号,验证是否以存在交验单
|
|
|
+ string checkDeliverNo = dataSet.Tables[1].Rows[1][2].ToString().Trim();
|
|
|
+ if (string.IsNullOrEmpty(checkDeliverNo))
|
|
|
+ {
|
|
|
+ return SUCCESS($"导入失败。<br/><br/>导入Excel的【{dataSet.Tables[1].TableName}】中<br/>C列交验单号有误。");
|
|
|
+ }
|
|
|
+ var response = _SapDeliverRecordService.GetList(
|
|
|
+ new SapDeliverRecordQueryDto { DeliverNo = checkDeliverNo });
|
|
|
+ if (response.Result.Count > 0)
|
|
|
+ {
|
|
|
+ return SUCCESS($"导入失败。<br/><br/>导入交验单【{checkDeliverNo}】已存在。");
|
|
|
}
|
|
|
|
|
|
+ //MiniExcel读取导入的Excel文件,因不支持xls格式,弃用。
|
|
|
+ //var SheetNames = stream.GetSheetNames();
|
|
|
+ //list = stream.Query(sheetName: SheetNames[1]).ToList();
|
|
|
+
|
|
|
+
|
|
|
List<SapDeliverRecord> sapDeliverRecords = new();
|
|
|
//实例化交验单表对象
|
|
|
for (int i = 1; i < dataSet.Tables[1].Rows.Count - 1; i++)
|