123 lines
5.4 KiB
C#
123 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Aspose.Cells.Drawing;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Dtos.VisualDev;
|
|
using JNPF.Common.Enums;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.Common.Security;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys;
|
|
using JNPF.VisualDev.Entitys.Dto.VisualDev;
|
|
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;
|
|
|
|
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)))
|
|
{
|
|
var startPointId = input.data[nameof(WmsRoad.startpoint_id)].ToString();
|
|
var 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;
|
|
try
|
|
{
|
|
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();
|
|
//遍历字典,找出需要查询数据库拿的相关字段
|
|
foreach (var d in dics)
|
|
{
|
|
var sCode = d["startpoint_code"].ToString() ?? string.Empty;
|
|
var eCode = d["endpoint_code"].ToString() ?? string.Empty;
|
|
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);
|
|
}
|
|
var points = await _db.Queryable<WmsPointH>().Where(it => pointCodes.Contains(it.point_code)).ToDictionaryAsync(x => x.point_code, x => x.id);
|
|
if (!points.IsNullOrEmpty())
|
|
{
|
|
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() ?? 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.modify_id = null;
|
|
x.modify_time = null;
|
|
});
|
|
}
|
|
row = await _db.Insertable(roads).ExecuteCommandAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw Oops.Bah(ex.Message);
|
|
}
|
|
return row > 0;
|
|
}
|
|
}
|
|
}
|