修改数据有误条件
This commit is contained in:
@@ -25,6 +25,7 @@ using JNPF.Common.Security;
|
||||
using Tnb.BasicData.Entities;
|
||||
using Mapster;
|
||||
using Aop.Api.Domain;
|
||||
using JNPF.VisualDev.Entitys.Dto.VisualDev;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
@@ -32,7 +33,7 @@ namespace Tnb.WarehouseMgr
|
||||
/// 载具台账服务
|
||||
/// </summary>
|
||||
[OverideVisualDev(ModuleConsts.MODULE_WMSCARRY_ID)]
|
||||
public class WmsCarryLedgerService : ExcelDataImportManager, IWmsCarryLedgerService
|
||||
public class WmsCarryLedgerService : BaseWareHouseService, IWmsCarryLedgerService
|
||||
{
|
||||
private const string ModuleId = "";
|
||||
private readonly ISqlSugarClient _db;
|
||||
@@ -45,7 +46,7 @@ namespace Tnb.WarehouseMgr
|
||||
_runService = runService;
|
||||
_visualDevService = visualDevService;
|
||||
_userManager = userManager;
|
||||
OverideFuncs.ImportAsync = DataImport;
|
||||
OverideFuncs.ImportDataAsync = DataImport;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -53,58 +54,52 @@ namespace Tnb.WarehouseMgr
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
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<WmsCarryH> carrys = new List<WmsCarryH>();
|
||||
|
||||
List<string> locCodes = new();
|
||||
List<string> cCodes = new();
|
||||
WmsCarryH carryH = new WmsCarryH();
|
||||
|
||||
string carryStdId = string.Empty;
|
||||
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);
|
||||
if (cCode == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}行载具规格不可为空", 500);
|
||||
locCodes.Add(d["location_code"]?.ToString() ?? string.Empty);
|
||||
cCodes.Add(cCode);
|
||||
d["create_time"] = DateTime.Now;
|
||||
d.Remove("modify_time");
|
||||
carryH = d.Adapt<WmsCarryH>();
|
||||
carrys.Add(carryH);
|
||||
}
|
||||
if (!locCodes.IsNullOrEmpty())
|
||||
var carryStdDic = await _db.Queryable<WmsCarrystd>().Where(it => cCodes.Contains(it.carrystd_code)).ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
||||
var locs = await _db.Queryable<BasLocation>().Where(it => locCodes.Contains(it.location_code)).ToDictionaryAsync(x => x.location_code, x => x.id);
|
||||
carrys.ForEach(x =>
|
||||
{
|
||||
var carryStdDic = await _db.Queryable<WmsCarrystd>().Where(it=>cCodes.Contains(it.carrystd_code)).ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
||||
var locs = await _db.Queryable<BasLocation>().Where(it => locCodes.Contains(it.location_code)).ToDictionaryAsync(x => x.location_code, x => x.id);
|
||||
carrys.ForEach(x =>
|
||||
{
|
||||
x.id = SnowflakeIdHelper.NextId();
|
||||
x.org_id = _userManager.User.OrganizeId;
|
||||
x.status = 1;
|
||||
x.is_lock = 0;
|
||||
x.carrystd_id = carryStdDic[x.carrystd_id].ToString()!;
|
||||
x.carry_status = ((int)EnumCarryStatus.空闲).ToString();
|
||||
x.location_id = locs[x.location_code].ToString();
|
||||
x.out_status = ((int)EnumOutStatus.正常).ToString();
|
||||
x.is_check = 1;
|
||||
x.create_id = _userManager.UserId;
|
||||
x.create_time = DateTime.Now;
|
||||
x.modify_id = null;
|
||||
x.modify_time = null;
|
||||
});
|
||||
}
|
||||
await _db.Ado.BeginTranAsync();
|
||||
if (!carryStdDic.Keys.Contains(x.carrystd_id)) throw new AppFriendlyException($"第{carrys.IndexOf(x) + 1}行的载具规格有误", 500);
|
||||
if (!locs.Keys.Contains(x.location_code)) throw new AppFriendlyException($"第{carrys.IndexOf(x) + 1}行的库位编号有误", 500);
|
||||
x.id = SnowflakeIdHelper.NextId();
|
||||
x.org_id = _userManager.User.OrganizeId;
|
||||
x.status = 1;
|
||||
x.is_lock = 0;
|
||||
x.carrystd_id = carryStdDic[x.carrystd_id].ToString() ?? throw new AppFriendlyException($"第{carrys.IndexOf(x) + 1}行的载具规格有误", 500);
|
||||
x.carry_status = ((int)EnumCarryStatus.空闲).ToString();
|
||||
x.location_id = locs[x.location_code].ToString() ?? throw new AppFriendlyException($"第{carrys.IndexOf(x) + 1}行的库位编号有误", 500);
|
||||
x.out_status = ((int)EnumOutStatus.正常).ToString();
|
||||
x.is_check = 1;
|
||||
x.create_id = _userManager.UserId;
|
||||
x.create_time = DateTime.Now;
|
||||
x.modify_id = null;
|
||||
x.modify_time = null;
|
||||
});
|
||||
row = await _db.Insertable(carrys).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