Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
@@ -176,5 +176,9 @@ public class ModuleConsts
|
||||
/// 模块标识-路段管理
|
||||
/// </summary>
|
||||
public const string MODULE_WMSROAD_ID = "26100621140773";
|
||||
/// <summary>
|
||||
/// 模块标识-点位管理
|
||||
/// </summary>
|
||||
public const string MODULE_WMSPOINT_ID = "26099196480805";
|
||||
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.Common.Const;
|
||||
using JNPF.Common.Security;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Entities.Exceptions
|
||||
@@ -17,28 +20,37 @@ namespace Tnb.WarehouseMgr.Entities.Exceptions
|
||||
public string UserName { get; set; }
|
||||
public string RequestURL { get; set; }
|
||||
public string RequestMethod { get; set; }
|
||||
public ConnectionConfigOptions options { get; set; }
|
||||
public ClaimsPrincipal UserIdentity { get; set; }
|
||||
public ConnectionConfigOptions? options { get; set; }
|
||||
|
||||
public TimedTaskException(string message,
|
||||
string method,
|
||||
string userId,
|
||||
string userName,
|
||||
string requestUrl,
|
||||
string requestMethod,
|
||||
ConnectionConfigOptions options,
|
||||
ClaimsPrincipal userIdentity,
|
||||
Exception innerException) : base(message, innerException)
|
||||
{
|
||||
this.Method = method;
|
||||
this.UserId = userId;
|
||||
this.UserName = userName;
|
||||
this.UserId = userIdentity.FindFirst(ClaimConst.CLAINMUSERID)?.Value ?? string.Empty;
|
||||
this.UserName = userIdentity.FindFirst(ClaimConst.CLAINMREALNAME)?.Value ?? string.Empty;
|
||||
this.options = userIdentity.FindFirst(ClaimConst.CONNECTIONCONFIG)?.ToObject<ConnectionConfigOptions>() ?? null;
|
||||
this.RequestURL = requestUrl;
|
||||
this.RequestMethod = requestMethod;
|
||||
this.options = options;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TimedTaskExceptionExtensions
|
||||
{
|
||||
public static TimedTaskException ToTimedTaskException(this Exception exception, TimedTaskErrorInfo exceptionInfo)
|
||||
{
|
||||
TimedTaskException ex = new(exception.Message, exceptionInfo.RequestURL, exceptionInfo.RequestMethod, exceptionInfo.userIdentity, exception);
|
||||
return ex;
|
||||
}
|
||||
}
|
||||
|
||||
public class TimedTaskErrorInfo
|
||||
{
|
||||
public string RequestURL { get; set; }
|
||||
public string RequestMethod { get; set; }
|
||||
public ClaimsPrincipal userIdentity { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.FriendlyException;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
public class ExcelDataImportManager : BaseWareHouseService
|
||||
{
|
||||
/// <summary>
|
||||
/// 解析Excel到内存
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
protected Task<List<Dictionary<string, object>>> ImportExcelToMemory(IFormFile file)
|
||||
{
|
||||
int rowIndex = 1;
|
||||
List<Dictionary<string, object>>? dics = new();
|
||||
IWorkbook? workbook = null;
|
||||
try
|
||||
{
|
||||
using (Stream stream = file.OpenReadStream())
|
||||
{
|
||||
// 2007版本
|
||||
if (file.Name.IndexOf(".xlsx") > 0)
|
||||
{
|
||||
workbook = new XSSFWorkbook(stream);
|
||||
}
|
||||
else if (file.Name.IndexOf(".xls") > 0)
|
||||
{
|
||||
workbook = new HSSFWorkbook(stream);
|
||||
}
|
||||
|
||||
ISheet? sheet = workbook?.GetSheetAt(0);
|
||||
if (workbook == null || sheet == null) throw Oops.Bah("无导入数据");
|
||||
if (sheet?.LastRowNum <= 1) throw Oops.Bah("无导入数据");
|
||||
|
||||
ICellStyle style = workbook.CreateCellStyle();
|
||||
IFont font = workbook.CreateFont();
|
||||
font.Color = IndexedColors.Black.Index; // 将字体颜色设置为黑色
|
||||
style.SetFont(font);
|
||||
var nameRow = sheet?.GetRow(0);
|
||||
if (nameRow != null)
|
||||
{
|
||||
Dictionary<string, object> dic = new Dictionary<string, object>();
|
||||
List<string> columns = new List<string>();
|
||||
columns = nameRow.Cells.Select(x => x.StringCellValue).ToList();
|
||||
columns.ForEach(x =>
|
||||
{
|
||||
var strings = x.Split(new char[2] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
x = strings[1];
|
||||
});
|
||||
if (columns?.Count > 0)
|
||||
{
|
||||
for (rowIndex = 1; rowIndex <= sheet?.LastRowNum; rowIndex++)
|
||||
{
|
||||
var row = sheet?.GetRow(rowIndex);
|
||||
if (row != null)
|
||||
{
|
||||
foreach (var col in columns)
|
||||
{
|
||||
ICell cell = row.GetCell(columns.IndexOf(col));
|
||||
dic.Add(col, cell.StringCellValue);
|
||||
}
|
||||
dics.Add(dic);
|
||||
}
|
||||
}
|
||||
if (dics == null) throw new AppFriendlyException("输入的数据为空", 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//return Task.FromResult(dics);
|
||||
throw;
|
||||
}
|
||||
return Task.FromResult(dics);
|
||||
}
|
||||
|
||||
public async Task<dynamic?> GenImportTemplate(params string[] fields)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,16 @@ 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
|
||||
{
|
||||
/// <summary>
|
||||
/// 库位定义业务类
|
||||
/// </summary>
|
||||
[OverideVisualDev(ModuleConsts.MODULE_LOCATIONDEFINITION_ID)]
|
||||
public class LocationDefinitionService : ExcelDataImportManager
|
||||
public class LocationDefinitionService : BaseWareHouseService
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IUserManager _userManager;
|
||||
@@ -28,51 +33,59 @@ 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);
|
||||
if (carryStdDic?.Count > 0)
|
||||
List<string> cStdCodes = new List<string>();
|
||||
//遍历字典,找出需要查询数据库拿的相关字段
|
||||
foreach (var d in dics)
|
||||
{
|
||||
string carryStdId = string.Empty;
|
||||
foreach (var d in dics)
|
||||
{
|
||||
var stdCodeKey = d["carrystd_id"].ToString();
|
||||
carryStdId = carryStdDic.ContainsKey(stdCodeKey) ? carryStdDic[stdCodeKey]?.ToString() ?? "" : "";
|
||||
d["carrystd_id"] = carryStdId;
|
||||
loc = d.Adapt<BasLocation>();
|
||||
locs.Add(loc);
|
||||
}
|
||||
var LCode = d["location_code"].ToString() ?? string.Empty;
|
||||
if (LCode == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据库位编号不可为空", 500);
|
||||
var isType = d["is_type"].ToString() ?? string.Empty;
|
||||
if (isType == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据库位类型不可为空", 500);
|
||||
var floor = d["floor"].ToString() ?? string.Empty;
|
||||
if (floor == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据楼层不可为空", 500);
|
||||
var layers = d["layers"].ToString() ?? string.Empty;
|
||||
var locLine = d["loc_line"].ToString() ?? string.Empty;
|
||||
var locColumn = d["loc_column"].ToString() ?? string.Empty;
|
||||
if (locLine == string.Empty || locColumn == string.Empty || layers == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据行列层不可为空", 500);
|
||||
var isSign = d["is_sign"].ToString() ?? string.Empty;
|
||||
if(isSign==string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据自动签收不可为空", 500);
|
||||
var cStdCode = d["carrystd_id"].ToString() ?? string.Empty;
|
||||
cStdCodes.Add(cStdCode);
|
||||
d["create_time"] = DateTime.Now;
|
||||
d.Remove("modify_time");
|
||||
loc = d.Adapt<BasLocation>();
|
||||
locs.Add(loc);
|
||||
}
|
||||
var carryStdDic = await _db.Queryable<WmsCarrystd>().Where(it => cStdCodes.Contains(it.carrystd_code)).ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
||||
locs.ForEach(x =>
|
||||
{
|
||||
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;
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ using JNPF.FriendlyException;
|
||||
using JNPF.Logging;
|
||||
using JNPF.Message.Interfaces.Message;
|
||||
using JNPF.Systems.Entitys.System;
|
||||
using Mapster;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
@@ -35,7 +36,7 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
protected override Task ExecuteAsync(CancellationToken stoppingToken) => Task.Run(() =>
|
||||
{
|
||||
//_eventPublisher = App.GetRequiredService<IEventPublisher>();
|
||||
_eventPublisher = App.GetRequiredService<IEventPublisher>();
|
||||
List<string> toUserIds = new List<string>() { "25398501929509" };
|
||||
//生成任务执行
|
||||
CancellationTokenSource genTaskCTS = new();
|
||||
@@ -64,19 +65,21 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
await action(cts).Catch(async ex =>
|
||||
{
|
||||
if (ex is TimedTaskException timedTaskEx)
|
||||
if (ex is TimedTaskException timedTaskEx and not null)
|
||||
{
|
||||
//await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateExLog", options, new SysLogEntity
|
||||
//{
|
||||
// Id = SnowflakeIdHelper.NextId(),
|
||||
// Category = 4,
|
||||
// IPAddress = NetHelper.Ip,
|
||||
// RequestURL = httpRequest.Path,
|
||||
// RequestMethod = httpRequest.Method,
|
||||
// Json = timedTaskEx + "\n" + context.Exception.StackTrace + "\n" + context.Exception.TargetSite.GetParameters().ToString(),
|
||||
// PlatForm = string.Format("{0}-{1}", userAgent.OS.ToString(), userAgent.RawValue),
|
||||
// CreatorTime = DateTime.Now
|
||||
//}));
|
||||
await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateExLog", timedTaskEx.options!, new SysLogEntity
|
||||
{
|
||||
Id = SnowflakeIdHelper.NextId(),
|
||||
Category = 4,
|
||||
UserId = timedTaskEx.UserId,
|
||||
UserName = timedTaskEx.UserName,
|
||||
IPAddress = NetHelper.Ip,
|
||||
RequestURL = timedTaskEx.RequestURL,
|
||||
RequestMethod = timedTaskEx.RequestMethod,
|
||||
Json = timedTaskEx + "\n" + timedTaskEx.InnerException?.StackTrace + "\n" + timedTaskEx?.TargetSite?.GetParameters().ToString(),
|
||||
//PlatForm = string.Format("{0}-{1}", userAgent.OS.ToString(), userAgent.RawValue),
|
||||
CreatorTime = DateTime.Now
|
||||
}));
|
||||
}
|
||||
});
|
||||
await Task.Delay(1000);
|
||||
|
||||
@@ -9,13 +9,16 @@ using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Threading.Tasks;
|
||||
using Aliyun.Credentials.Http;
|
||||
using Aop.Api.Domain;
|
||||
using Aspose.Cells.Drawing;
|
||||
using JNPF;
|
||||
using JNPF.Common.Const;
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Enums;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.Common.Manager;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
@@ -59,12 +62,15 @@ namespace Tnb.WarehouseMgr
|
||||
private readonly IDictionaryDataService _dictionaryDataService;
|
||||
private readonly IBillRullService _billRullService;
|
||||
private readonly IUserManager _userManager;
|
||||
public WareHouseService(ISqlSugarRepository<WmsInstockH> repository, IDictionaryDataService dictionaryDataService, IBillRullService billRullService, IUserManager userManager)
|
||||
private readonly ICacheManager _cacheManager;
|
||||
|
||||
public WareHouseService(ISqlSugarRepository<WmsInstockH> repository, IDictionaryDataService dictionaryDataService, IBillRullService billRullService, IUserManager userManager, ICacheManager cacheManager)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_dictionaryDataService = dictionaryDataService;
|
||||
_billRullService = billRullService;
|
||||
_userManager = userManager;
|
||||
_cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -221,6 +227,12 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
CancellationTokenSource agvCts = new();
|
||||
|
||||
//获取用户登录令牌
|
||||
var aToken = await _cacheManager.GetAsync("AsscessToken");
|
||||
if (aToken.IsNullOrWhiteSpace()) return;
|
||||
var curUser = await GetUserIdentity(aToken);
|
||||
|
||||
var db = _db.CopyNew();
|
||||
try
|
||||
{
|
||||
@@ -366,9 +378,18 @@ namespace Tnb.WarehouseMgr
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("生成预任务执行时出现错误", ex);
|
||||
var opts = curUser.FindFirst(ClaimConst.CONNECTIONCONFIG)?.Value;
|
||||
|
||||
TimedTaskErrorInfo ei = new()
|
||||
{
|
||||
RequestURL = App.HttpContext?.Request?.Path,
|
||||
RequestMethod = App.HttpContext?.Request?.Method,
|
||||
userIdentity = curUser,
|
||||
};
|
||||
var timedTaskEx = ex.ToTimedTaskException(ei);
|
||||
await db.Ado.RollbackTranAsync();
|
||||
cts?.Cancel();
|
||||
throw;
|
||||
throw timedTaskEx;
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -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,53 @@ 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>();
|
||||
|
||||
Dictionary<string, object>? locs = null;
|
||||
List<string> locCodes = new();
|
||||
List<string> cCodes = new();
|
||||
List<string> cStdCodes = 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);
|
||||
locCodes.Add(d["location_code"]?.ToString() ?? string.Empty);
|
||||
cCodes.Add(cCode);
|
||||
var cStdCode = d["carrystd_id"].ToString() ?? string.Empty;
|
||||
locCodes.Add(d["location_code"].ToString() ?? string.Empty);
|
||||
cStdCodes.Add(cStdCode);
|
||||
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 => cStdCodes.Contains(it.carrystd_code)).ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
||||
if (locCodes?.Count > 0)
|
||||
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);
|
||||
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();
|
||||
if (locs != null && x.location_code != null && x.location_code != string.Empty)
|
||||
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.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;
|
||||
}
|
||||
|
||||
84
WarehouseMgr/Tnb.WarehouseMgr/WmsPointService.cs
Normal file
84
WarehouseMgr/Tnb.WarehouseMgr/WmsPointService.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.VisualDev;
|
||||
using JNPF.VisualDev.Entitys.Dto.VisualDev;
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData.Entities;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
/// <summary>
|
||||
/// 点位管理业务类
|
||||
/// </summary>
|
||||
[OverideVisualDev(ModuleConsts.MODULE_WMSPOINT_ID)]
|
||||
public class WmsPointService : BaseWareHouseService
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IUserManager _userManager;
|
||||
public WmsPointService(ISqlSugarRepository<WmsPointH> repository, IUserManager userManager)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_userManager = userManager;
|
||||
OverideFuncs.ImportDataAsync = DataImport;
|
||||
}
|
||||
|
||||
private async Task<dynamic> DataImport(VisualDevImportDataInput input)
|
||||
{
|
||||
int row = 0;
|
||||
try
|
||||
{
|
||||
List<Dictionary<string, object>> dics = input.list;
|
||||
List<WmsPointH> points = new List<WmsPointH>();
|
||||
WmsPointH pt = new WmsPointH();
|
||||
List<string> aCodes = new List<string>();
|
||||
//遍历字典,找出需要查询数据库拿的相关字段
|
||||
foreach (var d in dics)
|
||||
{
|
||||
var pCode = d["point_code"].ToString() ?? string.Empty;
|
||||
var pName = d["point_name"].ToString() ?? string.Empty;
|
||||
var aCode = d["area_code"].ToString() ?? string.Empty;
|
||||
var floor = d["floor"].ToString() ?? string.Empty;
|
||||
if (pCode == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据点位编号不可为空", 500);
|
||||
if (pName == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据点位名称不可为空", 500);
|
||||
if (floor == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据楼层不可为空", 500);
|
||||
aCodes.Add(aCode);
|
||||
d["create_time"] = DateTime.Now;
|
||||
d.Remove("modify_time");
|
||||
pt = d.Adapt<WmsPointH>();
|
||||
points.Add(pt);
|
||||
}
|
||||
var areas = await _db.Queryable<WmsAreaH>().Where(it => aCodes.Contains(it.code)).ToDictionaryAsync(x => x.code, x => x.id);
|
||||
points.ForEach(x =>
|
||||
{
|
||||
if (!areas.Keys.Contains(x.area_code)) throw new AppFriendlyException($"第{points.IndexOf(x) + 1}个数据的管理区编号有误", 500);
|
||||
x.id = SnowflakeIdHelper.NextId();
|
||||
x.org_id = _userManager.User.OrganizeId;
|
||||
x.is_lock = 0;
|
||||
x.status = 1;
|
||||
x.point_x = 0;
|
||||
x.point_y = 0;
|
||||
x.point_z = 0;
|
||||
x.area_id = areas[x.area_code].ToString() ?? throw new AppFriendlyException($"第{points.IndexOf(x) + 1}个数据的管理区编号编号有误", 500);
|
||||
x.create_id = _userManager.UserId;
|
||||
x.modify_id = null;
|
||||
x.modify_time = null;
|
||||
});
|
||||
row = await _db.Insertable(points).ExecuteCommandAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw Oops.Bah(ex.Message);
|
||||
}
|
||||
return row > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ using JNPF.VisualDev.Interfaces;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.SS.Formula;
|
||||
using SqlSugar;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
@@ -31,7 +32,7 @@ namespace Tnb.WarehouseMgr
|
||||
/// </summary>
|
||||
[OverideVisualDev(ModuleId)]
|
||||
|
||||
public class WmsRouteMgrService : ExcelDataImportManager, IWmsRouteMgrService
|
||||
public class WmsRouteMgrService : BaseWareHouseService, IWmsRouteMgrService
|
||||
{
|
||||
private const string ModuleId = "26100621140773";//26100621140773
|
||||
private readonly ISqlSugarClient _db;
|
||||
@@ -44,7 +45,7 @@ namespace Tnb.WarehouseMgr
|
||||
_db = repository.AsSugarClient();
|
||||
_runService = runService;
|
||||
_visualDevService = visualDevService;
|
||||
_userManager = userManager;
|
||||
_userManager = userManager;
|
||||
OverideFuncs.CreateAsync = Create;
|
||||
OverideFuncs.ImportDataAsync = DataImport;
|
||||
}
|
||||
@@ -70,22 +71,24 @@ namespace Tnb.WarehouseMgr
|
||||
int row = 0;
|
||||
try
|
||||
{
|
||||
List<Dictionary<string, object>> dics = input.list;
|
||||
List<Dictionary<string, object>> dics = input.list;
|
||||
List<WmsRoad> roads = new List<WmsRoad>();
|
||||
List<string> pointCodes = new List<string>();
|
||||
|
||||
List<string> locCodes = new();
|
||||
WmsRoad road = new WmsRoad();
|
||||
|
||||
string carryStdId = string.Empty;
|
||||
//遍历字典,找出需要查询数据库拿的相关字段
|
||||
foreach (var d in dics)
|
||||
{
|
||||
var sCode = d["startpoint_code"]?.ToString() ?? string.Empty;
|
||||
var sCode = d["startpoint_code"].ToString() ?? string.Empty;
|
||||
var eCode = d["endpoint_code"].ToString() ?? string.Empty;
|
||||
if (sCode.IsEmpty() || eCode.IsEmpty())
|
||||
throw new AppFriendlyException($"第{dics.IndexOf(d) + 2}行数据有误", 500);
|
||||
var dis = d["distance"].ToString() ?? string.Empty;
|
||||
if(sCode == eCode) throw new AppFriendlyException("起始点位不能等于终止点位", 500);
|
||||
if (dis.IsEmpty())
|
||||
throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据距离不可为空", 500);
|
||||
pointCodes.Add(sCode);
|
||||
pointCodes.Add(eCode);
|
||||
d["create_time"] = DateTime.Now;
|
||||
d.Remove("modify_time");
|
||||
road = d.Adapt<WmsRoad>();
|
||||
roads.Add(road);
|
||||
}
|
||||
@@ -94,27 +97,24 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
roads.ForEach(x =>
|
||||
{
|
||||
if (!points.Keys.Contains(x.startpoint_code) ) throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的起始点位编号有误", 500);
|
||||
if (!points.Keys.Contains(x.endpoint_code)) throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的终止点位编号有误", 500);
|
||||
x.id = SnowflakeIdHelper.NextId();
|
||||
x.org_id = _userManager.User.OrganizeId;
|
||||
x.startpoint_id = points[x.startpoint_code].ToString()!;
|
||||
x.endpoint_id = points[x.endpoint_code].ToString()!;
|
||||
x.startpoint_id = points[x.startpoint_code].ToString() ?? throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的起始点位编号有误", 500);
|
||||
x.endpoint_id = points[x.endpoint_code].ToString() ?? throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的终止点位编号有误", 500);
|
||||
x.road_code = $"{x.startpoint_code}-{x.endpoint_code}";
|
||||
x.status = 1;
|
||||
x.create_id = _userManager.UserId;
|
||||
x.create_time = DateTime.Now;
|
||||
x.modify_id = null;
|
||||
x.modify_time = null;
|
||||
});
|
||||
}
|
||||
await _db.Ado.BeginTranAsync();
|
||||
row = await _db.Insertable(roads).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;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF;
|
||||
using JNPF.Common.Const;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Enums;
|
||||
@@ -17,6 +18,7 @@ using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.SS.Formula;
|
||||
using SqlSugar;
|
||||
using TencentCloud.Common;
|
||||
using Tnb.BasicData.Entities;
|
||||
using Tnb.Common.Utils;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
@@ -24,6 +26,7 @@ using Tnb.WarehouseMgr.Entities.Attributes;
|
||||
using Tnb.WarehouseMgr.Entities.Consts;
|
||||
using Tnb.WarehouseMgr.Entities.Dto;
|
||||
using Tnb.WarehouseMgr.Entities.Enums;
|
||||
using Tnb.WarehouseMgr.Entities.Exceptions;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
using UAParser;
|
||||
|
||||
@@ -223,8 +226,15 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
JNPF.Logging.Log.Error("齐套分拣执行时出现错误", ex);
|
||||
await curDb.Ado.RollbackTranAsync();
|
||||
TimedTaskErrorInfo ei = new()
|
||||
{
|
||||
RequestURL = App.HttpContext?.Request?.Path,
|
||||
RequestMethod = App.HttpContext?.Request?.Method,
|
||||
userIdentity = curUser,
|
||||
};
|
||||
var timedTaskEx = ex.ToTimedTaskException(ei);
|
||||
cts?.Cancel();
|
||||
throw;
|
||||
throw timedTaskEx;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ using Tnb.WarehouseMgr.Entities.Dto;
|
||||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||||
using Tnb.WarehouseMgr.Entities.Dto.Outputs;
|
||||
using Tnb.WarehouseMgr.Entities.Enums;
|
||||
using Tnb.WarehouseMgr.Entities.Exceptions;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
@@ -164,8 +165,15 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
JNPF.Logging.Log.Error("齐套出库,新增时出现错误", ex);
|
||||
await curDb.Ado.RollbackTranAsync();
|
||||
TimedTaskErrorInfo ei = new()
|
||||
{
|
||||
RequestURL = App.HttpContext?.Request?.Path,
|
||||
RequestMethod = App.HttpContext?.Request?.Method,
|
||||
userIdentity = curUser,
|
||||
};
|
||||
var timedTaskEx = ex.ToTimedTaskException(ei);
|
||||
cts?.Cancel();
|
||||
throw;
|
||||
throw timedTaskEx;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -265,8 +273,15 @@ namespace Tnb.WarehouseMgr
|
||||
catch (Exception ex)
|
||||
{
|
||||
JNPF.Logging.Log.Error("齐套出库,待配送时出现错误", ex);
|
||||
TimedTaskErrorInfo ei = new()
|
||||
{
|
||||
RequestURL = App.HttpContext?.Request?.Path,
|
||||
RequestMethod = App.HttpContext?.Request?.Method,
|
||||
userIdentity = curUser,
|
||||
};
|
||||
var timedTaskEx = ex.ToTimedTaskException(ei);
|
||||
cts?.Cancel();
|
||||
throw;
|
||||
throw timedTaskEx;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -798,7 +798,7 @@ namespace JNPF.VisualDev
|
||||
{
|
||||
VisualDevImportDataOutput result = new VisualDevImportDataOutput();
|
||||
var overideSvc = OverideVisualDevManager.GetOrDefault(modelId);
|
||||
if (overideSvc != null && overideSvc.OverideFuncs.CreateAsync != null)
|
||||
if (overideSvc != null && overideSvc.OverideFuncs.ImportDataAsync != null)
|
||||
{
|
||||
await overideSvc.OverideFuncs.ImportDataAsync(list);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user