调整,wms通用逻辑代码

This commit is contained in:
alex
2023-06-19 15:01:37 +08:00
parent 076cd0c641
commit 8bcc7958c9
28 changed files with 232 additions and 47 deletions

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.WarehouseMgr.Entities.Attributes
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class CallerAttribute : Attribute
{
public string Name { get; set; }
public CallerAttribute(string name)
{
Name = name;
}
}
}

View File

@@ -11,6 +11,11 @@ namespace Tnb.WarehouseMgr.Entities.Dto
/// </summary>
public class WareHouseUpInput
{
/// <summary>
/// 登录类型
/// </summary>
public string loginType { get; set; }
/// <summary>
/// 需求来源单据Id对应业务主表Id
/// </summary>
@@ -25,5 +30,7 @@ namespace Tnb.WarehouseMgr.Entities.Dto
public List<WmsDistaskCode> distaskCodes { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using JNPF.Common.Contracts;
using JNPF.Common.Security;
using SqlSugar;
namespace Tnb.WarehouseMgr.Entities;
/// <summary>
/// 任务执行主表
/// </summary>
public partial class WmsDistaskH
{
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.WarehouseMgr.Interfaces
{
public interface IPdaStroage
{
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tnb.WarehouseMgr.Entities.Dto;
namespace Tnb.WarehouseMgr.Interfaces
{
public interface IWHStorageService
{
Task Do(WareHouseUpInput input);
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.WarehouseMgr.Interfaces
{
public interface IWmsPdaWHService
{
}
}

View File

@@ -13,6 +13,7 @@ using JNPF.VisualDev;
using Microsoft.AspNetCore.Mvc;
using Tnb.WarehouseMgr.Entities.Attributes;
using Tnb.WarehouseMgr.Entities.Dto;
using Tnb.WarehouseMgr.Interfaces;
namespace Tnb.WarehouseMgr
{
@@ -20,29 +21,27 @@ namespace Tnb.WarehouseMgr
[Route("api/[area]/[controller]/[action]")]
public class BaseWareHouseService : IOverideVisualDevService, IDynamicApiController, ITransient
{
private static Dictionary<string, BaseWareHouseService> _serviceMap = new Dictionary<string, BaseWareHouseService>(StringComparer.OrdinalIgnoreCase);
private static Dictionary<string, IWHStorageService> _stroageMap = new Dictionary<string, IWHStorageService>(StringComparer.OrdinalIgnoreCase);
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
static BaseWareHouseService()
{
var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && u.IsSubclassOf(typeof(BaseWareHouseService))).ToList();
var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(IWHStorageService).IsAssignableFrom(u)).ToList();
foreach (var serviceType in serviceTypes)
{
var bizTypeId = serviceType.GetCustomAttribute<ServiceModuleAttribute>()?.BizTypeId;
if (!bizTypeId.IsNullOrEmpty())
var callerName = serviceType.GetCustomAttribute<CallerAttribute>()?.Name;
if (!callerName.IsNullOrEmpty())
{
_serviceMap[bizTypeId!] = (BaseWareHouseService)App.GetService(serviceType)!;
_stroageMap[callerName!] = (IWHStorageService)Activator.CreateInstance(serviceType)!;
}
}
}
protected async Task DoUpdate(WareHouseUpInput input)
{
if (_serviceMap.ContainsKey(input.bizTypeId))
if (_stroageMap.ContainsKey(input.loginType))
{
await _serviceMap[input.bizTypeId].ModifyAsync(input);
await _stroageMap[input.loginType].Do(input);
}
}

View File

@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using JNPF;
using JNPF.Common.Extension;
using Tnb.WarehouseMgr.Entities.Attributes;
using Tnb.WarehouseMgr.Entities.Dto;
using Tnb.WarehouseMgr.Interfaces;
namespace Tnb.WarehouseMgr
{
[Caller("web")]
public class PcStroageService : IWHStorageService
{
private static Dictionary<string, BaseWareHouseService> _serviceMap = new Dictionary<string, BaseWareHouseService>(StringComparer.OrdinalIgnoreCase);
static PcStroageService()
{
var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && !typeof(IPdaStroage).IsAssignableFrom(u) && u.IsSubclassOf(typeof(BaseWareHouseService))).ToList();
foreach (var serviceType in serviceTypes)
{
var bizTypeId = serviceType.GetCustomAttribute<ServiceModuleAttribute>()?.BizTypeId;
if (!bizTypeId.IsNullOrEmpty())
{
_serviceMap[bizTypeId!] = (BaseWareHouseService)App.GetService(serviceType)!;
}
}
}
public async Task Do(WareHouseUpInput input)
{
if (_serviceMap.ContainsKey(input.bizTypeId))
{
await _serviceMap[input.bizTypeId].ModifyAsync(input);
}
}
}
}

View File

@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using JNPF;
using JNPF.Common.Extension;
using Tnb.WarehouseMgr.Entities.Attributes;
using Tnb.WarehouseMgr.Entities.Dto;
using Tnb.WarehouseMgr.Interfaces;
namespace Tnb.WarehouseMgr
{
[Caller("app")]
public class PdaStroageService : IWHStorageService
{
private static Dictionary<string, BaseWareHouseService> _serviceMap = new Dictionary<string, BaseWareHouseService>(StringComparer.OrdinalIgnoreCase);
static PdaStroageService()
{
var serviceTypes = App.EffectiveTypes.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(IPdaStroage).IsAssignableFrom(u) && u.IsSubclassOf(typeof(BaseWareHouseService))).ToList();
foreach (var serviceType in serviceTypes)
{
var bizTypeId = serviceType.GetCustomAttribute<ServiceModuleAttribute>()?.BizTypeId;
if (!bizTypeId.IsNullOrEmpty())
{
_serviceMap[bizTypeId!] = (BaseWareHouseService)App.GetService(serviceType)!;
}
}
}
public async Task Do(WareHouseUpInput input)
{
if (_serviceMap.ContainsKey(input.bizTypeId))
{
await _serviceMap[input.bizTypeId].ModifyAsync(input);
}
}
}
}

View File

@@ -352,7 +352,16 @@ namespace Tnb.WarehouseMgr
//更任务执行
for (int i = 0, cnt = input.disTaskIds.Count; i < cnt; i++)
{
await _db.Updateable<WmsDistaskH>().SetColumns(it => new WmsDistaskH { status = WmsWareHouseConst.TASK_BILL_STATUS_YXD_ID, device_id = input.EqpIds[i] }).Where(it => input.disTaskIds.Contains(it.id)).ExecuteCommandAsync();
if (input.EqpIds?.Count > 0)
{
await _db.Updateable<WmsDistaskH>().SetColumns(it => new WmsDistaskH { status= WmsWareHouseConst.TASK_BILL_STATUS_YXD_ID, device_id = input.EqpIds[i] }).Where(it => input.disTaskIds.Contains(it.id)).ExecuteCommandAsync();
}
else
{
await _db.Updateable<WmsDistaskH>().SetColumns(it => new WmsDistaskH { status = WmsWareHouseConst.TASK_BILL_STATUS_YXD_ID }).Where(it => input.disTaskIds.Contains(it.id)).ExecuteCommandAsync();
}
//await _db.Updateable<WmsDistaskH>().SetColumns(it => setColVal).Where(it => input.disTaskIds.Contains(it.id)).ExecuteCommandAsync();
}
var preTaskIds = await _db.Queryable<WmsDistaskH>().Where(it => input.disTaskIds.Contains(it.id)).Select(it => it.pretask_id).ToListAsync();
if (preTaskIds.Count > 0)
@@ -366,6 +375,7 @@ namespace Tnb.WarehouseMgr
catch (Exception)
{
await _db.Ado.RollbackTranAsync();
throw;
}
}
/// <summary>
@@ -441,20 +451,21 @@ namespace Tnb.WarehouseMgr
{
foreach (var dt in disTasks)
{
if (_userManager.User.LoginType.Equals("app", StringComparison.OrdinalIgnoreCase))
{
dt.biz_type = $"pda{dt.biz_type}";
}
var disTaskCodes = await _db.Queryable<WmsDistaskCode>().Where(it => it.bill_id == dt.id).ToListAsync();
var upInput = new WareHouseUpInput { bizTypeId = dt.biz_type, requireId = dt.require_id, distaskCodes = disTaskCodes };
if (dt.is_chain == 0)
upInput.loginType = !_userManager.LoginType.IsNullOrEmpty() ? "app" : "web";
if (dt.is_sign == 1) //区分出入库操作
{
await DoUpdate(upInput);
}
else if (dt.is_chain == 1 && dt.chain_type == "3")
{
await DoUpdate(upInput);
if (dt.is_chain == 0)
{
await DoUpdate(upInput);
}
else if (dt.is_chain == 1 && dt.chain_type == "3")
{
await DoUpdate(upInput);
}
}
}
}
@@ -465,6 +476,9 @@ namespace Tnb.WarehouseMgr
await _db.Ado.RollbackTranAsync();
}
}
/// <summary>
/// 生成预任务
/// </summary>

View File

@@ -30,9 +30,9 @@ namespace Tnb.WarehouseMgr
/// </summary>
[OverideVisualDev(ModuleId)]
[ServiceModule(BizTypeId)]
public class WmsPDACarryMoveInStockService : BaseWareHouseService
public class WmsPDACarryMoveInStockService : BaseWareHouseService,IPdaStroage
{
private const string BizTypeId = "pda26121988909861";
private const string BizTypeId = "26121988909861";
private const string ModuleId = "26476127634469";
private readonly ISqlSugarClient _db;
private readonly IRunService _runService;

View File

@@ -30,7 +30,7 @@ namespace Tnb.WarehouseMgr
/// </summary>
[OverideVisualDev(ModuleConsts.MODULE_WMSCARRYMOOUTSTK_ID)]
[ServiceModule(BizTypeId)]
public class WmsPDACarryMoveOutStockService : BaseWareHouseService
public class WmsPDACarryMoveOutStockService : BaseWareHouseService, IPdaStroage
{
private const string BizTypeId = "26122271183141";
private readonly ISqlSugarClient _db;
@@ -133,7 +133,6 @@ namespace Tnb.WarehouseMgr
it => new BasLocation { is_lock = 1 });
}
}
}
await _db.Ado.CommitTranAsync();

View File

@@ -26,7 +26,7 @@ namespace Tnb.WarehouseMgr
/// 载具服务
/// </summary>
[OverideVisualDev(ModuleConsts.MODULE_WMSCARRYREPLACEPDA_ID)]
public class WmsPDACarryReplaceService : BaseWareHouseService, IWmsCarryService
public class WmsPDACarryReplaceService : BaseWareHouseService, IWmsCarryService, IPdaStroage
{
//private const string ModuleId = "26188532491557";
private readonly ISqlSugarClient _db;

View File

@@ -30,11 +30,9 @@ namespace Tnb.WarehouseMgr
/// <summary>
/// 配送申请服务
/// </summary>
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
[Route("api/[area]/[controller]/[action]")]
[OverideVisualDev(ModuleConsts.MODULE_WMSDELIVERYPDA_ID)]
[ServiceModule(BizTypeId)]
public class WmsPDADeliveryService : IOverideVisualDevService, IWmsDeliveryService, IDynamicApiController, ITransient
public class WmsPDADeliveryService : BaseWareHouseService, IPdaStroage
{
private const string BizTypeId = "26125644258853";
private readonly ISqlSugarClient _db;
@@ -148,10 +146,10 @@ namespace Tnb.WarehouseMgr
preTask.create_time = DateTime.Now;
return preTask;
}).ToList();
var isOk = await _wareHouseService.GenPreTask(preTasks,null);
var isOk = await _wareHouseService.GenPreTask(preTasks, null);
if (isOk)
{
if(input.data.ContainsKey(nameof(WmsDelivery.startlocation_id)) && input.data.ContainsKey(nameof(WmsDelivery.endlocation_id)) && input.data[nameof(WmsDelivery.endlocation_id)] != null && input.data[nameof(WmsDelivery.endlocation_id)] != null)
if (input.data.ContainsKey(nameof(WmsDelivery.startlocation_id)) && input.data.ContainsKey(nameof(WmsDelivery.endlocation_id)) && input.data[nameof(WmsDelivery.endlocation_id)] != null && input.data[nameof(WmsDelivery.endlocation_id)] != null)
{
//查询库位表
var location = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == input.data[nameof(WmsDelivery.startlocation_id)].ToString());

View File

@@ -32,9 +32,9 @@ namespace Tnb.WarehouseMgr
[OverideVisualDev(ModuleConsts.MODULE_WMSEMPTYINSTKPDA_ID)]
[ServiceModule(BizTypeId)]
public class WmsPDAEmptyInstockService : BaseWareHouseService
public class WmsPDAEmptyInstockService : BaseWareHouseService, IPdaStroage
{
private const string BizTypeId = "pda26121986416677";
private const string BizTypeId = "26121986416677";
private readonly ISqlSugarClient _db;
private readonly IRunService _runService;
private readonly IVisualDevService _visualDevService;

View File

@@ -32,9 +32,9 @@ namespace Tnb.WarehouseMgr
[OverideVisualDev(ModuleConsts.MODULE_WMSEMPTYOUTSTKPDA_ID)]
[ServiceModule(BizTypeId)]
public class WmsPDAEmptyOutstockService : BaseWareHouseService
public class WmsPDAEmptyOutstockService : BaseWareHouseService, IPdaStroage
{
private const string BizTypeId = "pda26121986416677";
private const string BizTypeId = "26121986416677";
private readonly ISqlSugarClient _db;
private readonly IRunService _runService;
private readonly IVisualDevService _visualDevService;

View File

@@ -30,7 +30,7 @@ namespace Tnb.WarehouseMgr
/// 异常取消
/// </summary>
[OverideVisualDev(ModuleConsts.MODULE_WMSEXCEPTIONCANCELPDA_ID)]
public class WmsPDAExceptionCancelService : BaseWareHouseService
public class WmsPDAExceptionCancelService : BaseWareHouseService, IPdaStroage
{
private readonly ISqlSugarClient _db;
private readonly IRunService _runService;

View File

@@ -31,7 +31,7 @@ namespace Tnb.WarehouseMgr
/// 异常取消
/// </summary>
[OverideVisualDev(ModuleConsts.MODULE_WMSEXCPTIONCOMPLETEPDA_ID)]
public class WmsPDAExceptionCompleteService : BaseWareHouseService
public class WmsPDAExceptionCompleteService : BaseWareHouseService, IPdaStroage
{
private readonly ISqlSugarClient _db;
private readonly IRunService _runService;

View File

@@ -30,7 +30,7 @@ namespace Tnb.WarehouseMgr
/// 异常取消
/// </summary>
[OverideVisualDev(ModuleConsts.MODULE_WMSEXCPTIONREEXCUTEPDA_ID)]
public class WmsPDAExceptionReexcuteService : BaseWareHouseService
public class WmsPDAExceptionReexcuteService : BaseWareHouseService, IPdaStroage
{
private readonly ISqlSugarClient _db;
private readonly IRunService _runService;

View File

@@ -34,9 +34,9 @@ namespace Tnb.WarehouseMgr
/// </summary>
[OverideVisualDev(ModuleConsts.MODULE_WMSINSTOCKPDA_ID)]
[ServiceModule(BizTypeId)]
public class WmsPDAInStockService : BaseWareHouseService
public class WmsPDAInStockService : BaseWareHouseService, IPdaStroage
{
private const string BizTypeId = "pda26191496816421";
private const string BizTypeId = "26191496816421";
private readonly ISqlSugarClient _db;
private readonly IRunService _runService;
private readonly IVisualDevService _visualDevService;

View File

@@ -32,7 +32,7 @@ namespace Tnb.WarehouseMgr
/// </summary>
[OverideVisualDev(ModuleConsts.MODULE_WMSTRANSFER_ID)]
[ServiceModule(BizTypeId)]
public class WmsPDATransferService : BaseWareHouseService
public class WmsPDATransferService : BaseWareHouseService, IPdaStroage
{
private const string BizTypeId = "26585291847957";
private readonly ISqlSugarClient _db;

View File

@@ -25,7 +25,7 @@ namespace Tnb.WarehouseMgr
/// </summary>
[OverideVisualDev(ModuleId)]
public class WmsRouteMgrService : BaseWareHouseService, IWmsRouteMgrService
public class WmsRouteMgrService : BaseWareHouseService, IWmsRouteMgrService,IPdaStroage
{
private const string ModuleId = "26100621140773";
private readonly ISqlSugarClient _db;

View File

@@ -32,7 +32,7 @@ namespace Tnb.WarehouseMgr
/// </summary>
[OverideVisualDev(ModuleConsts.MODULE_WMSTRANSFERPDA_ID)]
[ServiceModule(BizTypeId)]
public class WmsTransferService : BaseWareHouseService
public class WmsTransferService : BaseWareHouseService, IPdaStroage
{
private const string BizTypeId = "26585291847957";
private readonly ISqlSugarClient _db;
@@ -113,7 +113,7 @@ namespace Tnb.WarehouseMgr
preTask.create_time = DateTime.Now;
return preTask;
}).ToList();
var isOk = await _wareHouseService.GenPreTask(preTasks,null);
var isOk = await _wareHouseService.GenPreTask(preTasks, null);
if (isOk)
{
//查询库位表

View File

@@ -14,6 +14,10 @@ public interface IUserManager
/// 用户编号.
/// </summary>
string UserId { get; }
/// <summary>
/// 登录类型
/// </summary>
string LoginType { get; }
/// <summary>
/// 用户角色.

View File

@@ -76,7 +76,7 @@ public class UserManager : IUserManager, IScoped
public UserEntity User
{
get => _repository.GetSingle(u => u.Id == UserId);
}
/// <summary>
@@ -154,6 +154,13 @@ public class UserManager : IUserManager, IScoped
{
get => _user.FindFirst(ClaimConst.CLAINMADMINISTRATOR)?.Value == ((int)AccountType.Administrator).ToString();
}
/// <summary>
/// 登录类型区分Pc、Pda added by ly on 20230619
/// </summary>
public string LoginType
{
get => _user.FindFirst(ClaimConst.LOGINTYPE)?.Value;
}
/// <summary>
/// 获取用户的数据范围.

View File

@@ -47,4 +47,8 @@ public class ClaimConst
/// 单点登录标识.
/// </summary>
public const string OnlineTicket = "OnlineTicket";
/// <summary>
/// 登录类型用于区分Pc或Pda端
/// </summary>
public const string LOGINTYPE = "LoginType";
}

View File

@@ -58,4 +58,8 @@ public class LoginInput
/// 单点登录票据.
/// </summary>
public string online_ticket { get; set; }
/// <summary>
/// 登录类型用于区分Pc Pda
/// </summary>
public string login_type { get; set; }
}

View File

@@ -279,8 +279,7 @@ public class OAuthService : IDynamicApiController, ITransient
public async Task<dynamic> GetCurrentUser(string type)
{
if (type.IsNullOrEmpty()) type = "Web"; // 默认为Web端菜单目录
//modify by ly on 20230616 用于区分pc与 pda
_userManager.User.LoginType = "fadsfadsfadsfasd";
var userId = _userManager.UserId;
@@ -596,7 +595,8 @@ public class OAuthService : IDynamicApiController, ITransient
{ ClaimConst.TENANTID, options.ConfigId },
{ ClaimConst.CONNECTIONCONFIG, options},
{ ClaimConst.SINGLELOGIN, (int)sysConfig.singleLogin },
{ ClaimConst.OnlineTicket, input.online_ticket }
{ ClaimConst.OnlineTicket, input.online_ticket },
{ ClaimConst.LOGINTYPE,input.login_type}
}, tokenTimeout);
// 单点登录标识缓存