This commit is contained in:
FanLian
2023-09-06 09:53:16 +08:00
24 changed files with 540 additions and 23 deletions

View File

@@ -3,11 +3,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JNPF;
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.Common.Manager;
using JNPF.Common.Net;
using JNPF.Common.Security;
using JNPF.EventBus;
using JNPF.EventHandler;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.Systems.Entitys.System;
using JNPF.Systems.Interfaces.System;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -33,12 +40,22 @@ namespace Tnb.WarehouseMgr
{
private readonly ISqlSugarClient _db;
private readonly IWareHouseService _wareHouseService;
private readonly ICacheManager _cacheManager;
private readonly IEventPublisher _eventPublisher;
private readonly IUserManager _userManager;
public DeviceProviderService(ISqlSugarRepository<WmsInstockH> repository, IWareHouseService wareHouseService)
public DeviceProviderService(ISqlSugarRepository<WmsInstockH> repository, IWareHouseService wareHouseService,
ICacheManager cacheManager,
IEventPublisher eventPublisher,
IUserManager userManger
)
{
_db = repository.AsSugarClient();
_wareHouseService = wareHouseService;
_cacheManager = cacheManager;
_eventPublisher = eventPublisher;
_userManager = userManger;
}
/// <summary>
@@ -101,7 +118,7 @@ namespace Tnb.WarehouseMgr
/// 任务链状态上报
/// </summary>
/// <returns></returns>
[HttpPost, NonUnify,AllowAnonymous]
[HttpPost, NonUnify, AllowAnonymous]
public async Task<Result> TaskChainCallBack(TaskChainCallBackInput input)
{
try
@@ -110,8 +127,9 @@ namespace Tnb.WarehouseMgr
switch (input.status)
{
case "CREATED": break;
case "ALLOCATED":break;
case "ALLOCATED": break;
case "PROCESSING":
//if (await _cacheManager.GetAsync($"{input.taskChainCode}") == "任务链状态上报,上报状态PROCESSING") break;
if (input.taskChainCode.Trim().IsNullOrEmpty()) break;
var disTasks = await _db.Queryable<WmsDistaskH>().Where(it => it.bill_code.Contains(input.taskChainCode)).ToListAsync();
var eps = await _db.Queryable<EqpEquipment>().Where(it => it.code.Contains(input.deviceID)).ToListAsync();
@@ -127,6 +145,24 @@ namespace Tnb.WarehouseMgr
case "FINISHED": break;
default: break;
}
//写入redis
//await _cacheManager.SetAsync($"{input.taskChainCode}", $"任务链状态上报,上报状态{input.status}");
var opts = App.GetOptions<ConnectionConfigOptions>();
UserAgent userAgent = new(App.HttpContext);
//写系统日志
await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateOpLog", opts, new SysLogEntity
{
Id = SnowflakeIdHelper.NextId(),
Category = 4,
UserId = _userManager.UserId,
UserName = _userManager.User.RealName,
IPAddress = NetHelper.Ip,
RequestURL = App.HttpContext.Request.Path,
RequestMethod = App.HttpContext.Request.Method,
Json = $"任务链状态上报,任务链编号:{input.taskChainCode},上报状态:{input.status},设备编号:{input.deviceID}",
PlatForm = string.Format("{0}-{1}", userAgent.OS.ToString(), userAgent.RawValue),
CreatorTime = DateTime.Now
}));
}
catch (Exception)
{

View File

@@ -360,7 +360,7 @@ namespace Tnb.WarehouseMgr
{
dynamic reqBody = new ExpandoObject();
reqBody.taskChainCode = k;
reqBody.type = (int)EnumTaskChainType.KIVA;
reqBody.type = (int)EnumTaskChainType.AGV;
reqBody.sequential = false;
reqBody.taskChainPriority = 0;
reqBody.taskList = v;

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Aop.Api.Domain;
@@ -10,12 +11,14 @@ using JNPF.Common.Dtos.VisualDev;
using JNPF.Common.Extension;
using JNPF.Common.Security;
using JNPF.FriendlyException;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev;
using JNPF.VisualDev.Entitys;
using JNPF.VisualDev.Interfaces;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using SqlSugar;
using SqlSugar.DbConvert;
using Tnb.BasicData.Entities;
@@ -101,10 +104,15 @@ namespace Tnb.WarehouseMgr
code_batch = os.code_batch,
};
var outStkCarrys = await _wareHouseService.OutStockStrategy(OutStockStrategyInput);
var carryCodesPart = await _db.Queryable<WmsCarryH>().InnerJoin<WmsCarryCode>((a, b) => a.id == b.carry_id).InnerJoin<BasLocation>((a, b, c) => a.location_id == c.id)
.Where((a, b) => outStkCarrys.Select(x => x.id).Contains(b.carry_id))
.Select<WmsCarryCode>()
.ToListAsync();
Expression<Func<WmsCarryH, WmsCarryCode, bool>> whereExp = input.data.ContainsKey(nameof(WmsOutstockH.carry_id))
? (a, b) => a.id == input.data[nameof(WmsOutstockH.carry_id)].ToString()
: (a, b) => outStkCarrys.Select(x => x.id).Contains(b.carry_id);
List<WmsCarryCode>? carryCodesPart = await _db.Queryable<WmsCarryH>().InnerJoin<WmsCarryCode>((a, b) => a.id == b.carry_id).InnerJoin<BasLocation>((a, b, c) => a.location_id == c.id)
.Where(whereExp)
.Select<WmsCarryCode>()
.ToListAsync();
if (carryCodesPart?.Count > 0)
{
var codeQty = carryCodesPart.Sum(x => x.codeqty);
@@ -199,6 +207,37 @@ namespace Tnb.WarehouseMgr
{
ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == input.data[nameof(WmsPointH.location_id)].ToString());
}
else if (input.data.ContainsKey(nameof(WmsOutstockH.station_id)))
{
//多个投料库位
/*
* 潍柴
* 1、那个库位状态是空的出那个
* 1.1、没有空位直接抛异常
*
* 天益
* 2、不管库位是否为空 获取到所有库位 A B
* 2.1 根据这些库位去查任务执行 目的库位是这些库位的未完成任务数。 A 10 B 9
* 2.2 哪个最少给哪个
*/
var org = await _db.Queryable<OrganizeEntity>().FirstAsync(it => it.Id == input.data[nameof(WmsOutstockH.station_id)].ToString());
if (!org?.FeedingLocationId.IsNullOrWhiteSpace() ?? false)
{
var fLocIds = JArray.Parse(org.FeedingLocationId).Values<string>();
var minTaskNumLoc = await _db.Queryable<WmsPretaskH>().Where(it => it.status != WmsWareHouseConst.PRETASK_BILL_STATUS_COMPLE_ID && fLocIds.Contains(it.endlocation_id))
.GroupBy(it => it.endlocation_id)
.Select(it => new
{
it.endlocation_id,
count = SqlFunc.AggregateCount(it.endlocation_id)
})
.MergeTable()
.OrderBy(it => it.count)
.FirstAsync();
ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == minTaskNumLoc.endlocation_id);
}
}
if (sPoint != null && ePoint != null)
{
var points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id);

View File

@@ -83,6 +83,7 @@ namespace Tnb.WarehouseMgr
if (input.data.ContainsKey("tablefield115"))
{
jArr = JArray.Parse(input.data["tablefield115"].ToString()!);
}
//入库取终点 //出库起点
var inStockStrategyInput = new InStockStrategyQuery { warehouse_id = input.data[nameof(InStockStrategyQuery.warehouse_id)].ToString()!, Size = 1 };