Wms路径算法代码提交,根据dijkstra
This commit is contained in:
@@ -17,22 +17,17 @@ public partial class WmsInstockD : BaseEntity<string>
|
||||
/// <summary>
|
||||
/// 所属组织ID
|
||||
/// </summary>
|
||||
public string org_id { get; set; } = string.Empty;
|
||||
public string? org_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 入库单ID
|
||||
/// </summary>
|
||||
public string bill_id { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 行号
|
||||
/// </summary>
|
||||
public int bill_line { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 执行状态
|
||||
/// </summary>
|
||||
public int line_status { get; set; }
|
||||
public string line_status { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 物品ID
|
||||
@@ -52,7 +47,7 @@ public partial class WmsInstockD : BaseEntity<string>
|
||||
/// <summary>
|
||||
/// 单位代码
|
||||
/// </summary>
|
||||
public string unit_code { get; set; } = string.Empty;
|
||||
public string? unit_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 入库需求数量
|
||||
@@ -67,12 +62,12 @@ public partial class WmsInstockD : BaseEntity<string>
|
||||
/// <summary>
|
||||
/// 原因
|
||||
/// </summary>
|
||||
public string reason { get; set; } = string.Empty;
|
||||
public string? reason { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 入库仓库ID
|
||||
/// </summary>
|
||||
public string warehouse_id { get; set; } = string.Empty;
|
||||
public string? warehouse_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 不含税单价
|
||||
@@ -162,12 +157,12 @@ public partial class WmsInstockD : BaseEntity<string>
|
||||
/// <summary>
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
public string create_id { get; set; } = string.Empty;
|
||||
public string? create_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime create_time { get; set; } = DateTime.Now;
|
||||
public DateTime? create_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户
|
||||
@@ -184,4 +179,9 @@ public partial class WmsInstockD : BaseEntity<string>
|
||||
/// </summary>
|
||||
public string? code_batch { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 打印模板ID
|
||||
/// </summary>
|
||||
public string? print_id { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// 齐套搭配方案服务接口
|
||||
/// </summary>
|
||||
public interface IWmsCollocationSchemeSevice
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// 入库申请服务接口
|
||||
/// </summary>
|
||||
public interface IWmsInStockService
|
||||
{
|
||||
}
|
||||
}
|
||||
20
WarehouseMgr/Tnb.WarehouseMgr/BaseService.cs
Normal file
20
WarehouseMgr/Tnb.WarehouseMgr/BaseService.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Aspose.Cells.Drawing;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.VisualDev;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
public class BaseService : IOverideVisualDevService, IDynamicApiController, ITransient
|
||||
{
|
||||
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,16 @@ using Aspose.Cells.Drawing;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.Extras.CollectiveOAuth.Config;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.OpenXmlFormats.Wordprocessing;
|
||||
using Polly.Timeout;
|
||||
using Spire.Pdf.Widget;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData.Entities;
|
||||
using Tnb.BasicData.Entities.Enums;
|
||||
using Tnb.Common.Utils;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
|
||||
@@ -54,7 +60,7 @@ namespace Tnb.WarehouseMgr
|
||||
carry_id = a.id,
|
||||
carry_name = a.carry_name,
|
||||
location_id = b.id,
|
||||
|
||||
|
||||
location_name = b.location_name,
|
||||
warehouse_id = c.id,
|
||||
warehouse_name = c.whname,
|
||||
@@ -159,5 +165,90 @@ namespace Tnb.WarehouseMgr
|
||||
.ToListAsync();
|
||||
return items;
|
||||
}
|
||||
/// <summary>
|
||||
/// 路径算法
|
||||
/// </summary>
|
||||
/// <param name="pStartId"></param>
|
||||
/// <param name="pEndId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task PathAlgorithms(string pStartId, string pEndId)
|
||||
{
|
||||
var roads = await _db.Queryable<WmsRoad>().ToListAsync();
|
||||
await LocPathCalcAlgorithms(pStartId, pEndId, roads);
|
||||
}
|
||||
private async Task LocPathCalcAlgorithms(string pStartId, string pEndId, List<WmsRoad> roads)
|
||||
{
|
||||
var points = await _db.Queryable<WmsPointH>().ToListAsync();
|
||||
var startObj = points.Find(x => x.id == pStartId);
|
||||
var endObj = points.Find(x => x.id == pEndId);
|
||||
var sIndex = points.IndexOf(startObj);
|
||||
var eIndex = points.IndexOf(endObj);
|
||||
var vexs = points.Select(p => p.id).ToArray();
|
||||
EData[] edges = new EData[roads.Count];
|
||||
for (int i = 0; i < edges.Length; i++)
|
||||
{
|
||||
var start = roads[i].startpoint_id;
|
||||
var end = roads[i].endpoint_id;
|
||||
var weight = roads[i].distance;
|
||||
edges[i] = new EData(start, end, weight);
|
||||
}
|
||||
Dijkstra<WmsPointH> pG = new(vexs, edges);
|
||||
int[] prev = new int[pG.mVexs.Length];
|
||||
int[] dist = new int[pG.mVexs.Length];
|
||||
List<WmsPointH> vertexs = new() { startObj };
|
||||
pG.CalcDijkstra(sIndex, prev, dist);
|
||||
var pointIds = points.Select(p => p.id).ToList();
|
||||
List<string> result = new();
|
||||
GetPoints(pointIds, prev, result, eIndex);
|
||||
var shortestPathPoints = points.FindAll(x => result.Contains(x.id));
|
||||
shortestPathPoints.Add(points.Find(x => x.id == pStartId));
|
||||
List<WmsPointH> results = new() { startObj };
|
||||
var isVisited = shortestPathPoints.ToDictionary(x => x.id, x => false);
|
||||
isVisited[pStartId] = true;
|
||||
MatchPoint(results, roads, shortestPathPoints, isVisited, pStartId, pEndId);
|
||||
results.Add(endObj);
|
||||
string str = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取匹配的最短路径节点
|
||||
/// </summary>
|
||||
/// <param name="results"></param>
|
||||
/// <param name="roads"></param>
|
||||
/// <param name="shortestPathPoints"></param>
|
||||
/// <param name="isVisited"></param>
|
||||
/// <param name="pStartId"></param>
|
||||
/// <param name="pEndId"></param>
|
||||
private void MatchPoint(List<WmsPointH> results, List<WmsRoad> roads, List<WmsPointH> shortestPathPoints, Dictionary<string, bool> isVisited, string pStartId, string pEndId)
|
||||
{
|
||||
var sRoads = roads.Where(x => x.startpoint_id == pStartId).ToList();
|
||||
for (int j = 0; j < sRoads.Count; j++)
|
||||
{
|
||||
var sPoint = shortestPathPoints.Find(x => x.id == sRoads[j].endpoint_id);
|
||||
if (sPoint != null && isVisited.ContainsKey(sPoint.id) && !isVisited[sPoint.id] && sPoint.id != pEndId)
|
||||
{
|
||||
var code = sPoint.point_code;
|
||||
results.Add(sPoint);
|
||||
isVisited[sPoint.id] = true;
|
||||
MatchPoint(results, roads, shortestPathPoints, isVisited, sPoint.id, pEndId);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据终止节点获取最短路径顶点
|
||||
/// </summary>
|
||||
/// <param name="pointIds"></param>
|
||||
/// <param name="prev"></param>
|
||||
/// <param name="result"></param>
|
||||
/// <param name="eIdx"></param>
|
||||
private static void GetPoints(List<string> pointIds, int[] prev, List<string> result, int eIdx)
|
||||
{
|
||||
var index = eIdx;
|
||||
while (index != 0)
|
||||
{
|
||||
result.Add(pointIds[index]);
|
||||
index = prev[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
82
WarehouseMgr/Tnb.WarehouseMgr/WmsCollocationSchemeSevice.cs
Normal file
82
WarehouseMgr/Tnb.WarehouseMgr/WmsCollocationSchemeSevice.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Aspose.Cells.Drawing;
|
||||
using JNPF.Common.Dtos.VisualDev;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.VisualDev;
|
||||
using JNPF.VisualDev.Entitys;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
/// <summary>
|
||||
/// 齐套配套方案服务
|
||||
/// </summary>
|
||||
[OverideVisualDev(ModuleId)]
|
||||
public class WmsCollocationSchemeSevice : BaseService, IWmsCollocationSchemeSevice
|
||||
{
|
||||
private const string ModuleId = "26167204892965";
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IRunService _runService;
|
||||
private readonly IVisualDevService _visualDevService;
|
||||
private readonly ISqlSugarRepository<WmsCollocationSchemeH> _repository;
|
||||
|
||||
|
||||
|
||||
public WmsCollocationSchemeSevice(
|
||||
ISqlSugarRepository<WmsCollocationSchemeH> repository,
|
||||
IRunService runService,
|
||||
IVisualDevService visualDevService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_db = repository.AsSugarClient();
|
||||
_runService = runService;
|
||||
_visualDevService = visualDevService;
|
||||
OverideFuncs.CreateAsync = Create;
|
||||
}
|
||||
|
||||
private async Task<dynamic> Create(VisualDevModelDataCrInput input)
|
||||
{
|
||||
string materialCode = "";
|
||||
int seq = 0;
|
||||
|
||||
if (input.data.ContainsKey(nameof(WmsCollocationSchemeH.material_code)))
|
||||
{
|
||||
materialCode = input.data[nameof(WmsCollocationSchemeH.material_code)]?.ToString();
|
||||
}
|
||||
if (input.data.ContainsKey(nameof(WmsCollocationSchemeH.seq)) && input.data[nameof(WmsCollocationSchemeH.seq)] != null)
|
||||
{
|
||||
seq = input.data[nameof(WmsCollocationSchemeH.seq)].ParseToInt();
|
||||
}
|
||||
if (!materialCode.IsNullOrEmpty() && seq > 0)
|
||||
{
|
||||
var item = await _repository.GetFirstAsync(it => it.material_code == materialCode && it.seq == seq);
|
||||
if (item != null)
|
||||
{
|
||||
throw new AppFriendlyException($"物料+顺序【{materialCode}{seq}】,在数据库中已存在", 500);
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
|
||||
await _runService.Create(templateEntity, input);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,7 @@ namespace Tnb.WarehouseMgr
|
||||
/// <summary>
|
||||
/// 投料记录
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
|
||||
public class WmsFeedingService : IWmsFeedingService, IDynamicApiController, ITransient
|
||||
public class WmsFeedingService : BaseService, IWmsFeedingService
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
private static Dictionary<string, object> dicMaterial = new Dictionary<string, object>();
|
||||
|
||||
36
WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs
Normal file
36
WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
/// <summary>
|
||||
/// 入库申请服务
|
||||
/// </summary>
|
||||
public class WmsInStockService : BaseService, IWmsInStockService
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
|
||||
public WmsInStockService(ISqlSugarRepository<WmsInstockH> repository)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据入库申请单ID获取申请单明细信息
|
||||
/// </summary>
|
||||
/// <param name="billId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<dynamic> GetInStockDetailsListById([FromRoute] string billId)
|
||||
{
|
||||
var items = await _db.Queryable<WmsInstockD>().Where(it => it.bill_id == billId).ToListAsync();
|
||||
return items;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user