修改数据有误条件
This commit is contained in:
@@ -16,11 +16,13 @@ using Tnb.WarehouseMgr.Entities;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.Logging;
|
||||
using System.Reflection.Emit;
|
||||
using JNPF.VisualDev.Entitys.Dto.VisualDev;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
[OverideVisualDev(ModuleConsts.MODULE_LOCATIONDEFINITION_ID)]
|
||||
public class LocationDefinitionService : ExcelDataImportManager
|
||||
public class LocationDefinitionService : BaseWareHouseService
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IUserManager _userManager;
|
||||
@@ -28,51 +30,50 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_userManager = userManager;
|
||||
OverideFuncs.ImportAsync = DataImport;
|
||||
OverideFuncs.ImportDataAsync = DataImport;
|
||||
}
|
||||
|
||||
private async Task<dynamic> DataImport(IFormFile file)
|
||||
private async Task<dynamic> DataImport(VisualDevImportDataInput input)
|
||||
{
|
||||
int row = 0;
|
||||
try
|
||||
{
|
||||
List<Dictionary<string, object>> dics = await ImportExcelToMemory(file);
|
||||
List<Dictionary<string, object>> dics = input.list;
|
||||
List<BasLocation> locs = new List<BasLocation>();
|
||||
BasLocation loc = new BasLocation();
|
||||
var carryStdDic = await _db.Queryable<WmsCarrystd>().ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
||||
List<string> cCodes = new List<string>();
|
||||
foreach (var d in dics)
|
||||
{
|
||||
var cCode = d["carrystd_id"].ToString() ?? string.Empty;
|
||||
if (cCode == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}行载具规格不可为空", 500);
|
||||
cCodes.Add(cCode);
|
||||
d["create_time"] = DateTime.Now;
|
||||
d.Remove("modify_time");
|
||||
loc = d.Adapt<BasLocation>();
|
||||
locs.Add(loc);
|
||||
}
|
||||
var carryStdDic = await _db.Queryable<WmsCarrystd>().Where(it => cCodes.Contains(it.carrystd_code)).ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
||||
if (carryStdDic?.Count > 0)
|
||||
{
|
||||
string carryStdId = string.Empty;
|
||||
foreach (var d in dics)
|
||||
locs.ForEach(x =>
|
||||
{
|
||||
var stdCodeKey = d["carrystd_id"].ToString();
|
||||
carryStdId = carryStdDic.ContainsKey(stdCodeKey) ? carryStdDic[stdCodeKey]?.ToString() ?? "" : "";
|
||||
d["carrystd_id"] = carryStdId;
|
||||
loc = d.Adapt<BasLocation>();
|
||||
locs.Add(loc);
|
||||
}
|
||||
if (!carryStdDic.Keys.Contains(x.carrystd_id)) throw new AppFriendlyException($"第{locs.IndexOf(x) + 1}行的载具规格有误", 500);
|
||||
x.id = SnowflakeIdHelper.NextId();
|
||||
x.org_id = _userManager.User.OrganizeId;
|
||||
x.is_lock = 0;
|
||||
x.carrystd_id = carryStdDic[x.carrystd_id].ToString() ?? throw new AppFriendlyException($"第{locs.IndexOf(x) + 1}行的载具规格有误", 500);
|
||||
x.create_id = _userManager.UserId;
|
||||
x.create_time = DateTime.Now;
|
||||
x.modify_id = null;
|
||||
x.modify_time = null;
|
||||
x.is_mix = 1;
|
||||
});
|
||||
}
|
||||
locs.ForEach(x =>
|
||||
{
|
||||
x.id = SnowflakeIdHelper.NextId();
|
||||
x.org_id = _userManager.User.OrganizeId;
|
||||
x.is_lock = 0;
|
||||
x.create_id = _userManager.UserId;
|
||||
x.create_time = DateTime.Now;
|
||||
x.modify_id = null;
|
||||
x.modify_time = null;
|
||||
x.is_mix = 1;
|
||||
});
|
||||
|
||||
await _db.Ado.BeginTranAsync();
|
||||
row = await _db.Insertable(locs).ExecuteCommandAsync();
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
Log.Error("导入失败", ex);
|
||||
throw Oops.Bah("导入失败");
|
||||
throw Oops.Bah(ex.Message);
|
||||
}
|
||||
return row > 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user