Commit e25383e7 by xin.yang

fix bug

parent e546a966
......@@ -396,13 +396,12 @@ export default {
handleSuccess(res, file) {
if (res.ret == 1) {
this.$Message.success(this.$t("950398"));
this.getCategory();
this.search(1, 10);
this.tosearch();
} else {
if ((res.msg + "").indexOf(",") != -1) {
inittip(res.msg);
} else {
this.$Message.error(this.$t(res.data));
this.$Message.error(this.$t(res.msg));
}
}
},
......
......@@ -16,6 +16,7 @@ using Siger.Middlelayer.Utility.Helpers;
using Siger.Middlelayer.Utility.ImportEntities;
using Siger.Middlelayer.WmsRepository.Entities;
using Siger.Middlelayer.WmsRepository.Repositories.Interface;
using Siger.Middlelayer.Common.Extensions;
namespace Siger.ApiWMS.Controllers
{
......@@ -116,10 +117,19 @@ namespace Siger.ApiWMS.Controllers
var locationTypes = _location_TypeRepository.GetList(q => q.projectid == ProjectId && q.status == (int)RowState.Valid).ToList();
if (!locationTypes.Any())
{
throw new BadRequestException(RequestEnum.LocationTypeNotFound);
return new CommonImportResult(0, string.Join(';', (int)RequestEnum.LocationTypeNotFound));
}
var sonLocationTypes = GetSonTypes(0, locationTypes).Select(q => new Tuple<int, string>(q.id, q.name)).ToList();
var checkResult = excelHelper.CheckExcel(sonLocationTypes);
if (checkResult.Any())
{
return new CommonImportResult(0, string.Join(';', checkResult));
}
var data = excelHelper.ConvertSheetToList(sonLocationTypes);
if (!data.Any())
{
return new CommonImportResult(0, string.Join(';', (int)CommonEnum.NoData));
}
var result = _locationRepository.ImportStorageLocations(data, ProjectId, UserId);
return result;
}
......
......@@ -6,6 +6,7 @@ using System.Reflection;
using System.Text.RegularExpressions;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using Siger.Middlelayer.Common;
using Siger.Middlelayer.Utility.ExcelImport;
using Siger.Middlelayer.Utility.ImportEntities;
using ExcelColumn = Siger.Middlelayer.Utility.ExcelImport.ExcelColumn;
......@@ -117,6 +118,94 @@ namespace Siger.Middlelayer.Utility.Helpers
return collection;
}
public List<string> CheckExcel(List<Tuple<int, string>> locationTypes)
{
if (Sheet == null)
{
throw new ArgumentNullException(nameof(Sheet));
}
var messages = new List<string>();
var columns = new List<string> { "ID", "仓库名称" };
foreach (var item in locationTypes)
{
columns.Add(item.Item2);
}
var endRow = 2;
for (var row = 2; row <= Sheet.Dimension.Rows; row++)
{
var columnValues = new List<string>();
for (var i = 1; i <= columns.Count; i++)
{
var val = Sheet.Cells[row, i];
if (val != null)
{
columnValues.Add(val.Text);
}
}
if (columnValues.All(string.IsNullOrWhiteSpace))
{
endRow = row - 1;
break;
}
endRow = row;
}
IList<int> rows = new List<int>();
for (var i = 2; i <= endRow; i++)
{
rows.Add(i);
}
foreach (var row in rows)
{
var tnew = new ImportStorageLocations();
int i = 1;
foreach (var col in columns)
{
var cell = Sheet.Cells[row, i];
var val = cell == null ? "" : cell.Value?.ToString() ?? "";
if (i == 1)
{
if (string.IsNullOrEmpty(val))
{
messages.Add($"{row},{(int)RequestEnum.PleaseInputNotZeroIntID}");
return messages;
}
tnew.ID = val;
}
if (i == 2)
{
if (string.IsNullOrEmpty(val))
{
messages.Add($"{row},{(int)RequestEnum.PleaseInputStorageName}");
return messages;
}
tnew.StorageName = val;
}
if (i > 2)
{
var typeId = locationTypes.FirstOrDefault(q => q.Item2 == col);
if (string.IsNullOrEmpty(val))
{
messages.Add(typeId != null ? $"{row}, 请填写{typeId.Item2}" : $"{row}, {(int)RequestEnum.LocationImportFormatError}");
return messages;
}
tnew.Locations.Add(new LocationModels
{
LocationType = typeId == null ? 0 : typeId.Item1,
Location = val
});
}
i++;
}
}
return messages;
}
public void Dispose()
{
Sheet?.Dispose();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment