156 lines
6.6 KiB
C#
156 lines
6.6 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Dtos.VisualDev;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.Common.Security;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys;
|
|
using JNPF.VisualDev.Entitys.Dto.VisualDev;
|
|
using JNPF.VisualDev.Interfaces;
|
|
using Mapster;
|
|
using SqlSugar;
|
|
using Tnb.WarehouseMgr.Entities;
|
|
using Tnb.WarehouseMgr.Interfaces;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
/// <summary>
|
|
/// 路径管理业务类
|
|
/// </summary>
|
|
[OverideVisualDev(ModuleId)]
|
|
|
|
public class WmsRouteMgrService : BaseWareHouseService, IWmsRouteMgrService
|
|
{
|
|
private const string ModuleId = "26100621140773";//26100621140773
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IRunService _runService;
|
|
private readonly IVisualDevService _visualDevService;
|
|
private readonly IUserManager _userManager;
|
|
|
|
public WmsRouteMgrService(ISqlSugarRepository<WmsRoad> repository, IRunService runService, IVisualDevService visualDevService, IUserManager userManager)
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
_runService = runService;
|
|
_visualDevService = visualDevService;
|
|
_userManager = userManager;
|
|
OverideFuncs.CreateAsync = Create;
|
|
OverideFuncs.ImportDataAsync = DataImport;
|
|
}
|
|
|
|
private async Task<dynamic> Create(VisualDevModelDataCrInput input)
|
|
{
|
|
if (input.data.ContainsKey(nameof(WmsRoad.startpoint_id)) && input.data.ContainsKey(nameof(WmsRoad.endpoint_id)))
|
|
{
|
|
string? startPointId = input.data[nameof(WmsRoad.startpoint_id)].ToString();
|
|
string? endPointId = input.data[nameof(WmsRoad.endpoint_id)].ToString();
|
|
if (string.Equals(startPointId, endPointId, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
throw new AppFriendlyException("起始点位不能等于终止点位", 500);
|
|
}
|
|
}
|
|
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
|
|
await _runService.Create(templateEntity, input);
|
|
return await Task.FromResult(true);
|
|
}
|
|
|
|
private async Task<dynamic> DataImport(VisualDevImportDataInput input)
|
|
{
|
|
int row = 0;
|
|
List<Dictionary<string, object>> errorlist = new();
|
|
VisualDevImportDataOutput result = new();
|
|
try
|
|
{
|
|
List<Dictionary<string, object>> dics = input.list;
|
|
List<WmsRoad> roads = new();
|
|
List<string> pointCodes = new();
|
|
List<string> locCodes = new();
|
|
WmsRoad road = new();
|
|
//遍历字典,找出需要查询数据库拿的相关字段
|
|
foreach (Dictionary<string, object> d in dics)
|
|
{
|
|
if (d.Select(x => x.Value.ToString()).ToList().Find(v => v != "" && v != string.Empty && v != null) == null)
|
|
{
|
|
continue;
|
|
}
|
|
string sCode = d["startpoint_code"]?.ToString() ?? string.Empty;
|
|
string eCode = d["endpoint_code"]?.ToString() ?? string.Empty;
|
|
string 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);
|
|
}
|
|
Dictionary<string, object> points = await _db.Queryable<WmsPointH>().Where(it => pointCodes.FindAll(x => x.ToString().IsNotEmptyOrNull() && x.ToString() != "").Contains(it.point_code)).ToDictionaryAsync(x => x.point_code, x => x.id);
|
|
if (!points.IsNullOrEmpty())
|
|
{
|
|
string orgId = _userManager.User.OrganizeId;
|
|
string userId = _userManager.UserId;
|
|
foreach (WmsRoad r in roads)
|
|
{
|
|
if (!points.ContainsKey(r.startpoint_code))
|
|
{
|
|
throw new AppFriendlyException($"第{roads.IndexOf(r) + 1}个数据的起始点位编号有误", 500);
|
|
}
|
|
|
|
if (!points.ContainsKey(r.endpoint_code))
|
|
{
|
|
throw new AppFriendlyException($"第{roads.IndexOf(r) + 1}个数据的终止点位编号有误", 500);
|
|
}
|
|
|
|
r.id = SnowflakeIdHelper.NextId();
|
|
r.org_id = orgId;
|
|
r.startpoint_id = points[r.startpoint_code]?.ToString() ?? throw new AppFriendlyException($"第{roads.IndexOf(r) + 1}个数据的起始点位编号有误", 500);
|
|
r.endpoint_id = points[r.endpoint_code]?.ToString() ?? throw new AppFriendlyException($"第{roads.IndexOf(r) + 1}个数据的终止点位编号有误", 500);
|
|
r.road_code = $"{r.startpoint_code}-{r.endpoint_code}";
|
|
r.status = 1;
|
|
r.create_id = userId;
|
|
r.modify_id = null;
|
|
r.modify_time = null;
|
|
}
|
|
}
|
|
if (roads.Count > 1000)
|
|
{
|
|
row = await _db.Fastest<WmsRoad>().BulkCopyAsync(roads);
|
|
}
|
|
else if (roads.Count > 400)
|
|
{
|
|
_db.Utilities.PageEach(roads, 100, async pageList =>
|
|
{
|
|
row = await _db.Insertable(pageList).ExecuteCommandAsync();
|
|
});
|
|
}
|
|
else
|
|
{
|
|
row = await _db.Insertable(roads).ExecuteCommandAsync();
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw Oops.Bah(ex.Message);
|
|
}
|
|
result = new VisualDevImportDataOutput()
|
|
{
|
|
snum = row,
|
|
fnum = 0,
|
|
failResult = errorlist,
|
|
resultType = errorlist.Count < 1 ? 0 : 1
|
|
};
|
|
return result;
|
|
}
|
|
|
|
}
|
|
}
|