using Admin.NET.Core.Service;
|
using Admin.NET.Application.Entity;
|
using Microsoft.AspNetCore.Http;
|
using System.Security.AccessControl;
|
using Furion.DatabaseAccessor;
|
using AngleSharp.Dom;
|
using Org.BouncyCastle.Asn1.X509;
|
using System.Web;
|
using System.Text;
|
using System.Data;
|
using Mapster;
|
|
namespace Admin.NET.Application;
|
/// <summary>
|
/// 库位信息服务
|
/// </summary>
|
[ApiDescriptionSettings(ApplicationConst.WmsBaseGroupName, Order = 100)]
|
public class WmsPlaceService : IDynamicApiController, ITransient
|
{
|
private readonly SqlSugarRepository<WmsBasePlace> _rep;
|
private readonly SqlSugarRepository<WmsBaseArea> _repWmsArea;
|
private readonly SqlSugarRepository<WmsBaseContainer> _repWmsContainer;
|
private readonly SqlSugarRepository<WmsBaseContainerType> _repWmsContainerType;
|
private readonly SqlSugarRepository<WmsBasePlace> _repWmsPlace;
|
private readonly SqlSugarRepository<WmsContainerPlace> _repWmsContainerPlace;
|
private readonly SqlSugarRepository<WmsStockQuan> _repWmsStockQuan;
|
private readonly SqlSugarRepository<WmsTask> _wmsTaskRep;
|
private readonly SqlSugarRepository<v_empty_place> _v_empty_placeRep;
|
|
|
public WmsPlaceService(
|
SqlSugarRepository<WmsBasePlace> rep
|
, SqlSugarRepository<WmsBaseArea> repWmsArea
|
, SqlSugarRepository<WmsBaseContainer> repWmsContainer
|
, SqlSugarRepository<WmsBaseContainerType> repWmsContainerType
|
, SqlSugarRepository<WmsContainerPlace> repWmsContainerPlace
|
, SqlSugarRepository<WmsStockQuan> repWmsStockQuan,
|
SqlSugarRepository<v_empty_place> v_empty_placeRep
|
,
|
SqlSugarRepository<WmsTask> wmsTaskRep
|
)
|
{
|
_rep = rep;
|
_repWmsArea = repWmsArea;
|
_repWmsContainer = repWmsContainer;
|
_repWmsContainerType = repWmsContainerType;
|
_repWmsStockQuan = repWmsStockQuan;
|
_repWmsContainerPlace = repWmsContainerPlace;
|
_wmsTaskRep = wmsTaskRep;
|
_v_empty_placeRep = v_empty_placeRep;
|
}
|
|
/// <summary>
|
/// 分页查询库位信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "Page")]
|
public async Task<SqlSugarPagedList<WmsPlaceOutput>> Page(WmsPlaceInput input)
|
{
|
var query = _rep.AsQueryable()
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
|
u.PlaceCode.Contains(input.SearchKey.Trim())
|
|| u.PlaceName.Contains(input.SearchKey.Trim())
|
|| u.PlaceAlias.Contains(input.SearchKey.Trim())
|
)
|
.WhereIF(input.IsDisabled != null, u => u.IsDisabled == input.IsDisabled)
|
.WhereIF(input.IsVirtually != null, u => u.IsVirtually == input.IsVirtually)
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PlaceCodeForpda), u => u.PlaceCode == input.PlaceCodeForpda) //ly-pda容器下架 精准查询
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PlaceCode), u => u.PlaceCode.Contains(input.PlaceCode.Trim()))
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PlaceName), u => u.PlaceName.Contains(input.PlaceName.Trim()))
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PlaceAlias), u => u.PlaceAlias.Contains(input.PlaceAlias.Trim()))
|
.WhereIF(input.PlaceType > 0, u => u.PlaceType == input.PlaceType)
|
.WhereIF(input.StockUnit > 0, u => u.StockUnit == input.StockUnit)
|
.WhereIF(input.PlaceStatus > 0, u => u.PlaceStatus == input.PlaceStatus)
|
.WhereIF(input.AreaId > 0, u => u.AreaId == input.AreaId)
|
.WhereIF(!string.IsNullOrWhiteSpace(input.AreaCode), u => u.AreaCode == input.AreaCode) // 下架单-精准查询
|
.Select<WmsPlaceOutput>();
|
return await query.OrderBuilder(input, "", "Id").ToPagedListAsync(input.Page, input.PageSize);
|
}
|
|
/// <summary>
|
/// 增加库位信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "Add")]
|
[UnitOfWork]
|
public async Task<long> Add(AddWmsPlaceInput input)
|
{
|
|
var placeEntity = input.Adapt<WmsBasePlace>();
|
if (placeEntity.IsVirtually == null)
|
{
|
placeEntity.IsVirtually = false;
|
}
|
//验重
|
await CheckExisit(placeEntity);
|
//ly - 所在库区
|
var Info = await _repWmsArea.GetFirstAsync(u => u.Id == input.AreaId);
|
placeEntity.Id = Yitter.IdGenerator.YitIdHelper.NextId();
|
placeEntity.AreaName = Info.AreaName;
|
placeEntity.AreaCode = Info.AreaCode;
|
//库位类型名称
|
placeEntity.PlaceTypeName = placeEntity.PlaceType.ToString();
|
if (Info == null)
|
{
|
throw Oops.Oh(errorMessage: @$"所在库区不存在!");
|
}
|
if (Info.IsDisabled == true)
|
{
|
throw Oops.Oh($"不能使用已禁用的库区");
|
}
|
|
|
|
|
|
try
|
{
|
|
|
#region 事务内执行操作
|
//新增虚拟容器、绑定虚拟库位
|
await DOVirtually(placeEntity);
|
await _rep.InsertAsync(placeEntity);
|
#endregion
|
|
}
|
catch (Exception)
|
{
|
|
throw;
|
}
|
|
return placeEntity.Id;
|
}
|
|
/// <summary>
|
/// 删除库位信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "Delete")]
|
public async Task Delete(DeleteWmsPlaceInput input)
|
{
|
var entity = await _rep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
|
//库位被绑定不能删除
|
var entityWmsContainerPlace = await _repWmsContainerPlace.GetFirstAsync(u => u.PlaceId == entity.Id);
|
if (entityWmsContainerPlace != null)
|
{
|
throw Oops.Oh("存在绑定关系,不可删除");
|
}
|
|
//await _rep.FakeDeleteAsync(entity); //假删除
|
await _rep.DeleteAsync(entity); //真删除
|
}
|
|
/// <summary>
|
/// 更新库位信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "Update")]
|
public async Task Update(UpdateWmsPlaceInput input)
|
{
|
var entity = input.Adapt<WmsBasePlace>();
|
//验重 - ly-0612 不要需要
|
//update by liuwq 20240616
|
await CheckExisit(entity, true);
|
//ly - 所在库区
|
var Info = await _repWmsArea.GetFirstAsync(u => u.Id == input.AreaId);
|
if (Info == null)
|
{
|
throw Oops.Oh(errorMessage: @$"所在库区不存在!");
|
}
|
if (Info.IsDisabled == true)
|
{
|
throw Oops.Oh($"不能使用已禁用的库区");
|
}
|
entity.AreaName = Info.AreaName;
|
entity.AreaCode = Info.AreaCode;
|
//库位类型
|
entity.PlaceTypeName = entity.PlaceType.ToString();
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
}
|
|
/// <summary>
|
/// 获取库位信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpGet]
|
[ApiDescriptionSettings(Name = "Detail")]
|
public async Task<WmsBasePlace> Detail([FromQuery] QueryByIdWmsPlaceInput input)
|
{
|
return await _rep.GetFirstAsync(u => u.Id == input.Id);
|
}
|
|
|
|
|
/// <summary>
|
/// 获取库位信息列表
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpGet]
|
[ApiDescriptionSettings(Name = "List")]
|
public async Task<List<WmsPlaceOutput>> List([FromQuery] WmsPlaceInput input)
|
{
|
return await _rep.AsQueryable().Select<WmsPlaceOutput>().ToListAsync();
|
}
|
|
|
|
/// <summary>
|
/// 获取推荐库位信息列表
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "RecommendPlaceList")]
|
public async Task<List<WmsPlaceOutput>> RecommendPlaceList([FromQuery] WmsPlaceInput input)
|
{
|
|
if (string.IsNullOrWhiteSpace(input.AreaCode))
|
{
|
throw Oops.Oh($"库区不能为空");
|
}
|
|
|
|
var handle = FindEmptyPlaceServiceFactory.GetHandle(MaterialClassifyFlagEnum.物料, _v_empty_placeRep, _rep, _wmsTaskRep);
|
var emptyPlaceList = await handle.MainFindMultiEmptyLocation(new FindEmptyPlaceInput() { AreaList = new List<string>() { input.AreaCode } });
|
|
|
var returnPlaceCodeList = emptyPlaceList.Take(10).ToList();
|
|
if (returnPlaceCodeList?.Count <= 0)
|
{
|
throw Oops.Oh($"库区{input.AreaCode}没有可推荐库位!");
|
}
|
return returnPlaceCodeList.Adapt<List<WmsPlaceOutput>>();
|
}
|
|
/// <summary>
|
/// 找到原来集合中不存在在活跃任务调度库位
|
/// </summary>
|
/// <param name="originalSet"></param>
|
/// <param name="targetSet"></param>
|
static List<WmsPlaceOutput> RemoveElementsInTargetSet(List<WmsPlaceOutput> originalSet, List<string> targetSet)
|
{
|
// 创建一个临时集合来保存需要删除的元素
|
var elementsToRemove = new List<WmsPlaceOutput>();
|
|
|
|
|
// 遍历原始集合,查找需要删除的元素
|
foreach (var item in originalSet)
|
{
|
// update by liuwq 20240717
|
if (targetSet.Contains(item.PlaceCode))
|
// if (!targetSet.Contains(item.PlaceCode))
|
{
|
elementsToRemove.Add(item);
|
}
|
}
|
|
// 从原始集合中移除需要删除的元素
|
foreach (var item in elementsToRemove)
|
{
|
originalSet.Remove(item);
|
}
|
|
// return elementsToRemove;
|
//update by liuwq
|
return originalSet;
|
}
|
|
|
#region 导入
|
|
/// <summary>
|
/// Excel模板导入库位表功能
|
/// </summary>
|
/// <param name="file">Excel模板文件</param>
|
/// <returns>导入的记录数</returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "ImportExcel")]
|
[Description("WmsPlace/ImportExcel")]
|
public async Task<int> ImportExcelAsync(IFormFile file)
|
{
|
int _HeadStartLine = 2;//第1行是说明,第2行是列名
|
int _DataStartLine = 3;//第3行开始是数据
|
DataTable importDataTable = ExcelUtil.ImportExcelToDataTable(file, _HeadStartLine, _DataStartLine);
|
var addList = await CommonImport(importDataTable, _DataStartLine);
|
|
await _rep.InsertRangeAsync(addList);
|
return addList.Count;
|
}
|
|
|
|
/// <summary>
|
/// DataTable转换实体对象列表
|
/// </summary>
|
/// <param name="dataTable"></param>
|
/// <param name="dataStartLine">模版列名开始行</param>
|
/// <returns></returns>
|
private async Task<List<WmsBasePlace>> CommonImport(DataTable dataTable, int dataStartLine)
|
{
|
var details = new List<WmsBasePlace>();
|
int index = dataStartLine;//模版列名开始行
|
foreach (System.Data.DataRow row in dataTable.Rows)
|
{
|
|
|
index++;
|
//导入模版定制化代码(替换模版使用)
|
|
var addItem = new WmsBasePlace();
|
#region 定义变量
|
var _PlaceCode = "";//库位编码
|
var _PlaceName = "";//库位名称
|
var _PlaceAlias = "";//库位别名
|
var _PlaceType = "";//库位类型
|
// var _PlaceTypeName = "";//库位类型名称
|
//var _StockUnit = "";//存放单位
|
//var _StockUnitName = "";//存放单位名称
|
var _PlaceStatus = "";//库位属性
|
//var _IsActivateWCS = "";//是否激活与任务调度
|
//var _Environment = "";//库存环境
|
|
|
//var _AreaId = "";//所在库区
|
var _AreaCode = "";//库区编号
|
//var _AreaName = "";//库区名称
|
var _VerificationCode = "";//检验码
|
var _RowNo = "";//排
|
var _ColumnNo = "";//列
|
var _LayerNo = "";//层
|
var _LaneNo = "";//巷道
|
var _Xzb = "";//库位X坐标
|
var _Yzb = "";//库位Y坐标
|
var _Zzb = "";//库位Z坐标
|
var _Length = "";//库位长度
|
var _Width = "";//库位宽度
|
var _Height = "";//库位高度
|
var _MaxWeight = "";//最大承重
|
var _InSequence = "";//上架顺序
|
var _OutSequence = "";//下架顺序
|
var _IsVirtually = "";//是否虚拟
|
var _IsDisabled = "";//是否禁用
|
// var _BindContainerCount = "";//绑定容器数
|
#endregion
|
|
|
#region 取值
|
_PlaceCode = row["库位编号"]?.ToString();
|
_PlaceName = row["库位名称"]?.ToString();
|
_PlaceAlias = row["库位别名"]?.ToString();
|
_PlaceType = row["库位类型"]?.ToString();
|
// _PlaceTypeName = row["库位类型名称"]?.ToString();
|
//_StockUnit = row["存放单位"]?.ToString();
|
//_StockUnitName = row["存放单位名称"]?.ToString();
|
_PlaceStatus = row["库位属性"]?.ToString();
|
// _IsActivateWCS = row["是否激活与任务调度"]?.ToString();
|
//_Environment = row["库存环境"]?.ToString();
|
//_AreaId = row["所在库区"]?.ToString();
|
_AreaCode = row["库区编号"]?.ToString();
|
//_AreaName = row["库区名称"]?.ToString();
|
_VerificationCode = row["检验码"]?.ToString();
|
_RowNo = row["排"]?.ToString();
|
_ColumnNo = row["列"]?.ToString();
|
_LayerNo = row["层"]?.ToString();
|
_LaneNo = row["巷道"]?.ToString();
|
_Xzb = row["库位X坐标"]?.ToString();
|
_Yzb = row["库位Y坐标"]?.ToString();
|
_Zzb = row["库位Z坐标"]?.ToString();
|
_Length = row["库位长度"]?.ToString();
|
_Width = row["库位宽度"]?.ToString();
|
_Height = row["库位高度"]?.ToString();
|
_MaxWeight = row["最大承重"]?.ToString();
|
_InSequence = row["上架顺序"]?.ToString();
|
_OutSequence = row["下架顺序"]?.ToString();
|
_IsVirtually = row["是否虚拟"]?.ToString();
|
_IsDisabled = row["是否禁用"]?.ToString();
|
//_BindContainerCount = row["绑定容器数"]?.ToString();
|
#endregion
|
|
|
#region 验证
|
|
if (string.IsNullOrEmpty(_PlaceCode))
|
{
|
throw Oops.Oh($"第{index}行[库位编码]{_PlaceCode}不能为空!");
|
}
|
|
if (!string.IsNullOrEmpty(_PlaceCode))
|
{
|
var isExist = await _rep.AsQueryable().FirstAsync(p => p.PlaceCode == _PlaceCode || p.PlaceName == _PlaceName);
|
if (isExist != null) throw Oops.Oh("该库位编号" + _PlaceCode + "已经存在不可重复添加!");
|
addItem.PlaceCode = (string)(_PlaceCode.Trim());
|
}
|
|
if (string.IsNullOrEmpty(_PlaceName))
|
{
|
throw Oops.Oh($"第{index}行[库位名称]{_PlaceName}不能为空!");
|
}
|
|
if (!string.IsNullOrEmpty(_PlaceName))
|
{
|
addItem.PlaceName = (string)(_PlaceName.Trim());
|
}
|
if (!string.IsNullOrEmpty(_PlaceAlias))
|
{
|
addItem.PlaceAlias = (string)(_PlaceAlias.Trim());
|
}
|
|
if (string.IsNullOrEmpty(_PlaceType))
|
{
|
throw Oops.Oh($"第{index}行[库位类型]{_PlaceType}不能为空!");
|
}
|
|
if (!string.IsNullOrEmpty(_PlaceType))
|
{
|
Admin.NET.Application.PlaceTypeEnum enumPlaceType = default(Admin.NET.Application.PlaceTypeEnum);
|
|
if (!Enum.TryParse<Admin.NET.Application.PlaceTypeEnum>(_PlaceType, out enumPlaceType) && !string.IsNullOrEmpty(_PlaceType))
|
{
|
throw Oops.Oh($"第{index}行[库位类型]{_PlaceType}值不正确!");
|
}
|
else
|
{
|
addItem.PlaceType = enumPlaceType;
|
addItem.PlaceTypeName = enumPlaceType.GetDescription();
|
}
|
|
}
|
//if (!string.IsNullOrEmpty(_PlaceTypeName))
|
//{
|
// addItem.PlaceTypeName = (string)(_PlaceTypeName.Trim());
|
//}
|
|
//if (string.IsNullOrEmpty(_StockUnit))
|
//{
|
// throw Oops.Oh($"第{index}行[存放单位]{_StockUnit}不能为空!");
|
//}
|
|
//if (!string.IsNullOrEmpty(_StockUnit))
|
//{
|
// Admin.NET.Application.StockUnitEnum enumStockUnit = default(Admin.NET.Application.StockUnitEnum);
|
|
// if (!Enum.TryParse<Admin.NET.Application.StockUnitEnum>(_StockUnit, out enumStockUnit) && !string.IsNullOrEmpty(_StockUnit))
|
// {
|
// throw Oops.Oh($"第{index}行[存放单位]{_StockUnit}值不正确!");
|
// }
|
// else
|
// {
|
// addItem.StockUnit = enumStockUnit;
|
// }
|
|
//}
|
//if (!string.IsNullOrEmpty(_StockUnitName))
|
//{
|
// addItem.StockUnitName = (string)(_StockUnitName.Trim());
|
//}
|
|
if (string.IsNullOrEmpty(_PlaceStatus))
|
{
|
throw Oops.Oh($"第{index}行[库位属性]{_PlaceStatus}不能为空!");
|
}
|
|
if (!string.IsNullOrEmpty(_PlaceStatus))
|
{
|
Admin.NET.Application.PlaceStatusEnum enumPlaceStatus = default(Admin.NET.Application.PlaceStatusEnum);
|
|
if (!Enum.TryParse<Admin.NET.Application.PlaceStatusEnum>(_PlaceStatus, out enumPlaceStatus) && !string.IsNullOrEmpty(_PlaceStatus))
|
{
|
throw Oops.Oh($"第{index}行[库位属性]{_PlaceStatus}值不正确!");
|
}
|
else
|
{
|
addItem.PlaceStatus = enumPlaceStatus;
|
}
|
|
}
|
//if (!string.IsNullOrEmpty(_IsActivateWCS))
|
//{
|
// if (!_IsActivateWCS.Equals("是") && !_IsActivateWCS.Equals("否"))
|
// {
|
// throw Oops.Oh($"第{index}行[是否激活与任务调度]{_IsActivateWCS}值不正确!");
|
// }
|
// else
|
// {
|
// bool outIsActivateWCS = _IsActivateWCS.Equals("是") ? true : false;
|
// addItem.IsActivateWCS = outIsActivateWCS;
|
// }
|
//}
|
|
//if (!string.IsNullOrEmpty(_Environment))
|
//{
|
// addItem.Environment = (string)(_Environment.Trim());
|
//}
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(_AreaCode))
|
{
|
throw Oops.Oh($"第{index}行[库区编号]{_AreaCode}不能为空!");
|
}
|
|
var wmsAreaInfo = await _repWmsArea.GetFirstAsync(u => u.AreaCode == _AreaCode.Trim() && u.IsDelete == false);
|
|
if (wmsAreaInfo == null)
|
{
|
throw Oops.Oh(errorMessage: @$"库区{_AreaCode}不存在!");
|
}
|
if (wmsAreaInfo.IsDisabled == true)
|
{
|
throw Oops.Oh($"不能使用已禁用的仓库");
|
}
|
|
addItem.AreaCode = wmsAreaInfo.AreaCode;
|
addItem.AreaId = wmsAreaInfo.Id;
|
addItem.AreaName = wmsAreaInfo.AreaName;
|
//if (string.IsNullOrEmpty(_AreaId))
|
//{
|
// throw Oops.Oh($"第{index}行[所在库区]{_AreaId}不能为空!");
|
//}
|
|
//if (!string.IsNullOrEmpty(_AreaId))
|
//{
|
// if (!long.TryParse(_AreaId, out long outAreaId) && !string.IsNullOrEmpty(_AreaId))
|
// {
|
// throw Oops.Oh($"第{index}行[所在库区]{_AreaId}值不正确!");
|
// }
|
// if (outAreaId <= 0 && !string.IsNullOrEmpty(_AreaId))
|
// {
|
// throw Oops.Oh($"第{index}行[所在库区]{_AreaId}值不能小于等于0!");
|
// }
|
// else
|
// {
|
// addItem.AreaId = outAreaId;
|
// }
|
|
//}
|
|
//if (!string.IsNullOrEmpty(_AreaCode))
|
//{
|
// addItem.AreaCode = (string)(_AreaCode.Trim());
|
//}
|
//if (!string.IsNullOrEmpty(_AreaName))
|
//{
|
// addItem.AreaName = (string)(_AreaName.Trim());
|
//}
|
if (!string.IsNullOrEmpty(_VerificationCode))
|
{
|
addItem.VerificationCode = (string)(_VerificationCode.Trim());
|
}
|
if (!string.IsNullOrEmpty(_RowNo))
|
{
|
if (!int.TryParse(_RowNo, out int outRowNo) && !string.IsNullOrEmpty(_RowNo))
|
{
|
throw Oops.Oh($"第{index}行[排]{_RowNo}值不正确!");
|
}
|
if (outRowNo <= 0 && !string.IsNullOrEmpty(_RowNo))
|
{
|
throw Oops.Oh($"第{index}行[排]{_RowNo}值不能小于等于0!");
|
}
|
else
|
{
|
addItem.RowNo = outRowNo;
|
}
|
|
}
|
if (!string.IsNullOrEmpty(_ColumnNo))
|
{
|
if (!int.TryParse(_ColumnNo, out int outColumnNo) && !string.IsNullOrEmpty(_ColumnNo))
|
{
|
throw Oops.Oh($"第{index}行[列]{_ColumnNo}值不正确!");
|
}
|
if (outColumnNo <= 0 && !string.IsNullOrEmpty(_ColumnNo))
|
{
|
throw Oops.Oh($"第{index}行[列]{_ColumnNo}值不能小于等于0!");
|
}
|
else
|
{
|
addItem.ColumnNo = outColumnNo;
|
}
|
|
}
|
if (!string.IsNullOrEmpty(_LayerNo))
|
{
|
if (!int.TryParse(_LayerNo, out int outLayerNo) && !string.IsNullOrEmpty(_LayerNo))
|
{
|
throw Oops.Oh($"第{index}行[层]{_LayerNo}值不正确!");
|
}
|
if (outLayerNo <= 0 && !string.IsNullOrEmpty(_LayerNo))
|
{
|
throw Oops.Oh($"第{index}行[层]{_LayerNo}值不能小于等于0!");
|
}
|
else
|
{
|
addItem.LayerNo = outLayerNo;
|
}
|
|
}
|
if (!string.IsNullOrEmpty(_LaneNo))
|
{
|
if (!int.TryParse(_LaneNo, out int outLaneNo) && !string.IsNullOrEmpty(_LaneNo))
|
{
|
throw Oops.Oh($"第{index}行[巷道]{_LaneNo}值不正确!");
|
}
|
if (outLaneNo <= 0 && !string.IsNullOrEmpty(_LaneNo))
|
{
|
throw Oops.Oh($"第{index}行[巷道]{_LaneNo}值不能小于等于0!");
|
}
|
else
|
{
|
addItem.LaneNo = outLaneNo;
|
}
|
|
}
|
if (!string.IsNullOrEmpty(_Xzb))
|
{
|
addItem.Xzb = (string)(_Xzb.Trim());
|
}
|
if (!string.IsNullOrEmpty(_Yzb))
|
{
|
addItem.Yzb = (string)(_Yzb.Trim());
|
}
|
if (!string.IsNullOrEmpty(_Zzb))
|
{
|
addItem.Zzb = (string)(_Zzb.Trim());
|
}
|
if (!string.IsNullOrEmpty(_Length))
|
{
|
if (!decimal.TryParse(_Length, out decimal outLength) && !string.IsNullOrEmpty(_Length))
|
{
|
throw Oops.Oh($"第{index}行[库位长度]{_Length}值不正确!");
|
}
|
if (outLength <= 0 && !string.IsNullOrEmpty(_Length))
|
{
|
throw Oops.Oh($"第{index}行[库位长度]{_Length}值不能小于等于0!");
|
}
|
else
|
{
|
addItem.Length = outLength;
|
}
|
|
}
|
if (!string.IsNullOrEmpty(_Width))
|
{
|
if (!decimal.TryParse(_Width, out decimal outWidth) && !string.IsNullOrEmpty(_Width))
|
{
|
throw Oops.Oh($"第{index}行[库位宽度]{_Width}值不正确!");
|
}
|
if (outWidth <= 0 && !string.IsNullOrEmpty(_Width))
|
{
|
throw Oops.Oh($"第{index}行[库位宽度]{_Width}值不能小于等于0!");
|
}
|
else
|
{
|
addItem.Width = outWidth;
|
}
|
|
}
|
if (!string.IsNullOrEmpty(_Height))
|
{
|
if (!decimal.TryParse(_Height, out decimal outHeight) && !string.IsNullOrEmpty(_Height))
|
{
|
throw Oops.Oh($"第{index}行[库位高度]{_Height}值不正确!");
|
}
|
if (outHeight <= 0 && !string.IsNullOrEmpty(_Height))
|
{
|
throw Oops.Oh($"第{index}行[库位高度]{_Height}值不能小于等于0!");
|
}
|
else
|
{
|
addItem.Height = outHeight;
|
}
|
|
}
|
if (!string.IsNullOrEmpty(_MaxWeight))
|
{
|
if (!decimal.TryParse(_MaxWeight, out decimal outMaxWeight) && !string.IsNullOrEmpty(_MaxWeight))
|
{
|
throw Oops.Oh($"第{index}行[最大承重]{_MaxWeight}值不正确!");
|
}
|
if (outMaxWeight <= 0 && !string.IsNullOrEmpty(_MaxWeight))
|
{
|
throw Oops.Oh($"第{index}行[最大承重]{_MaxWeight}值不能小于等于0!");
|
}
|
else
|
{
|
addItem.MaxWeight = outMaxWeight;
|
}
|
|
}
|
if (!string.IsNullOrEmpty(_InSequence))
|
{
|
if (!int.TryParse(_InSequence, out int outInSequence) && !string.IsNullOrEmpty(_InSequence))
|
{
|
throw Oops.Oh($"第{index}行[上架顺序]{_InSequence}值不正确!");
|
}
|
if (outInSequence <= 0 && !string.IsNullOrEmpty(_InSequence))
|
{
|
throw Oops.Oh($"第{index}行[上架顺序]{_InSequence}值不能小于等于0!");
|
}
|
else
|
{
|
addItem.InSequence = outInSequence;
|
}
|
|
}
|
if (!string.IsNullOrEmpty(_OutSequence))
|
{
|
if (!int.TryParse(_OutSequence, out int outOutSequence) && !string.IsNullOrEmpty(_OutSequence))
|
{
|
throw Oops.Oh($"第{index}行[下架顺序]{_OutSequence}值不正确!");
|
}
|
if (outOutSequence <= 0 && !string.IsNullOrEmpty(_OutSequence))
|
{
|
throw Oops.Oh($"第{index}行[下架顺序]{_OutSequence}值不能小于等于0!");
|
}
|
else
|
{
|
addItem.OutSequence = outOutSequence;
|
}
|
|
}
|
if (!string.IsNullOrEmpty(_IsVirtually))
|
{
|
if (!_IsVirtually.Equals("是") && !_IsVirtually.Equals("否"))
|
{
|
throw Oops.Oh($"第{index}行[是否虚拟]{_IsVirtually}值不正确!");
|
}
|
else
|
{
|
bool outIsVirtually = _IsVirtually.Equals("是") ? true : false;
|
addItem.IsVirtually = outIsVirtually;
|
}
|
}
|
|
|
if (string.IsNullOrEmpty(_IsDisabled))
|
{
|
throw Oops.Oh($"第{index}行[是否禁用]{_IsDisabled}不能为空!");
|
}
|
|
if (!string.IsNullOrEmpty(_IsDisabled))
|
{
|
if (!_IsDisabled.Equals("是") && !_IsDisabled.Equals("否"))
|
{
|
throw Oops.Oh($"第{index}行[是否禁用]{_IsDisabled}值不正确!");
|
}
|
else
|
{
|
bool outIsDisabled = _IsDisabled.Equals("是") ? true : false;
|
addItem.IsDisabled = outIsDisabled;
|
}
|
}
|
|
//if (!string.IsNullOrEmpty(_BindContainerCount))
|
//{
|
// if (!int.TryParse(_BindContainerCount, out int outBindContainerCount) && !string.IsNullOrEmpty(_BindContainerCount))
|
// {
|
// throw Oops.Oh($"第{index}行[绑定容器数]{_BindContainerCount}值不正确!");
|
// }
|
// if (outBindContainerCount <= 0 && !string.IsNullOrEmpty(_BindContainerCount))
|
// {
|
// throw Oops.Oh($"第{index}行[绑定容器数]{_BindContainerCount}值不能小于等于0!");
|
// }
|
// else
|
// {
|
// addItem.BindContainerCount = outBindContainerCount;
|
// }
|
|
//}
|
#endregion
|
|
|
details.Add(addItem);
|
}
|
//验重
|
await CheckExisitForImport(details);
|
return details;
|
}
|
|
/// <summary>
|
/// 根据版本下载库位表的Excel导入模板
|
/// </summary>
|
/// <returns>下载的模板文件</returns>
|
[HttpGet]
|
[ApiDescriptionSettings(Name = "DownloadExcelTemplate")]
|
[Description("WmsPlace/DownloadExcelTemplate")]
|
public IActionResult DownloadExcelTemplate()
|
{
|
string _path = TemplateConst.EXCEL_TEMPLATEFILE_导入模版路径 + $"\\库位信息{TemplateConst.EXCEL_TEMPLATEFILE_导入模版名称后缀}.xlsx";
|
var fileName = HttpUtility.UrlEncode($"导入模板(库位信息).xlsx", Encoding.GetEncoding("UTF-8"));
|
return new FileStreamResult(new FileStream(_path, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName };
|
}
|
|
|
|
|
|
///// <summary>
|
///// DataTable转换实体对象列表
|
///// </summary>
|
///// <param name="dataTable"></param>
|
///// <param name="dataStartLine">模版列名开始行</param>
|
///// <returns></returns>
|
//private async Task<List<WmsBasePlace>> CommonImport(DataTable dataTable, int dataStartLine)
|
//{
|
// var details = new List<WmsBasePlace>();
|
// int index = dataStartLine;//模版列名开始行
|
// foreach (System.Data.DataRow row in dataTable.Rows)
|
// {
|
|
|
// index++;
|
// //导入模版定制化代码(替换模版使用)
|
|
// var addItem = new WmsBasePlace();
|
// #region 定义变量
|
// var _PlaceCode = "";//库位编码
|
// var _PlaceName = "";//库位名称
|
// var _PlaceAlias = "";//库位别名
|
// var _PlaceType = "";//库位类型
|
// // var _PlaceTypeName = "";//库位类型名称
|
// //var _StockUnit = "";//存放单位
|
// //var _StockUnitName = "";//存放单位名称
|
// var _PlaceStatus = "";//库位属性
|
// //var _IsActivateWCS = "";//是否激活与任务调度
|
// //var _Environment = "";//库存环境
|
// var _AreaId = "";//所在库区
|
// var _AreaCode = "";//库区编号
|
// var _AreaName = "";//库区名称
|
// var _VerificationCode = "";//检验码
|
// var _RowNo = "";//排
|
// var _ColumnNo = "";//列
|
// var _LayerNo = "";//层
|
// var _LaneNo = "";//巷道
|
// var _Xzb = "";//库位X坐标
|
// var _Yzb = "";//库位Y坐标
|
// var _Zzb = "";//库位Z坐标
|
// var _Length = "";//库位长度
|
// var _Width = "";//库位宽度
|
// var _Height = "";//库位高度
|
// var _MaxWeight = "";//最大承重
|
// var _InSequence = "";//上架顺序
|
// var _OutSequence = "";//下架顺序
|
// var _IsVirtually = "";//是否虚拟
|
// var _IsDisabled = "";//是否禁用
|
// // var _BindContainerCount = "";//绑定容器数
|
// #endregion
|
|
|
// #region 取值
|
// _PlaceCode = row["库位编号"]?.ToString();
|
// _PlaceName = row["库位名称"]?.ToString();
|
// _PlaceAlias = row["库位别名"]?.ToString();
|
// _PlaceType = row["库位类型"]?.ToString();
|
// // _PlaceTypeName = row["库位类型名称"]?.ToString();
|
// //_StockUnit = row["存放单位"]?.ToString();
|
// //_StockUnitName = row["存放单位名称"]?.ToString();
|
// _PlaceStatus = row["库位属性"]?.ToString();
|
// // _IsActivateWCS = row["是否激活与任务调度"]?.ToString();
|
// //_Environment = row["库存环境"]?.ToString();
|
// _AreaId = row["所在库区"]?.ToString();
|
// _AreaCode = row["库区编号"]?.ToString();
|
// _AreaName = row["库区名称"]?.ToString();
|
// _VerificationCode = row["检验码"]?.ToString();
|
// _RowNo = row["排"]?.ToString();
|
// _ColumnNo = row["列"]?.ToString();
|
// _LayerNo = row["层"]?.ToString();
|
// _LaneNo = row["巷道"]?.ToString();
|
// _Xzb = row["库位X坐标"]?.ToString();
|
// _Yzb = row["库位Y坐标"]?.ToString();
|
// _Zzb = row["库位Z坐标"]?.ToString();
|
// _Length = row["库位长度"]?.ToString();
|
// _Width = row["库位宽度"]?.ToString();
|
// _Height = row["库位高度"]?.ToString();
|
// _MaxWeight = row["最大承重"]?.ToString();
|
// _InSequence = row["上架顺序"]?.ToString();
|
// _OutSequence = row["下架顺序"]?.ToString();
|
// _IsVirtually = row["是否虚拟"]?.ToString();
|
// _IsDisabled = row["是否禁用"]?.ToString();
|
// //_BindContainerCount = row["绑定容器数"]?.ToString();
|
// #endregion
|
|
|
// #region 验证
|
|
// if (string.IsNullOrEmpty(_PlaceCode))
|
// {
|
// throw Oops.Oh($"第{index}行[库位编码]{_PlaceCode}不能为空!");
|
// }
|
|
// if (!string.IsNullOrEmpty(_PlaceCode))
|
// {
|
// var isExist = await _repWmsPlace.AsQueryable().FirstAsync(p => p.PlaceCode == _PlaceCode || p.PlaceName == _PlaceName);
|
// if (isExist != null) throw Oops.Oh("该库位编号" + _PlaceCode + "已经存在不可重复添加!");
|
// addItem.PlaceCode = (string)(_PlaceCode.Trim());
|
// }
|
|
// if (string.IsNullOrEmpty(_PlaceName))
|
// {
|
// throw Oops.Oh($"第{index}行[库位名称]{_PlaceName}不能为空!");
|
// }
|
|
// if (!string.IsNullOrEmpty(_PlaceName))
|
// {
|
// addItem.PlaceName = (string)(_PlaceName.Trim());
|
// }
|
// if (!string.IsNullOrEmpty(_PlaceAlias))
|
// {
|
// addItem.PlaceAlias = (string)(_PlaceAlias.Trim());
|
// }
|
|
// if (string.IsNullOrEmpty(_PlaceType))
|
// {
|
// throw Oops.Oh($"第{index}行[库位类型]{_PlaceType}不能为空!");
|
// }
|
|
// if (!string.IsNullOrEmpty(_PlaceType))
|
// {
|
// Admin.NET.Application.PlaceTypeEnum enumPlaceType = default(Admin.NET.Application.PlaceTypeEnum);
|
|
// if (!Enum.TryParse<Admin.NET.Application.PlaceTypeEnum>(_PlaceType, out enumPlaceType) && !string.IsNullOrEmpty(_PlaceType))
|
// {
|
// throw Oops.Oh($"第{index}行[库位类型]{_PlaceType}值不正确!");
|
// }
|
// else
|
// {
|
// addItem.PlaceType = enumPlaceType;
|
// addItem.PlaceName = enumPlaceType.GetConfigValue<string>();
|
// }
|
|
// }
|
// //if (!string.IsNullOrEmpty(_PlaceTypeName))
|
// //{
|
// // addItem.PlaceTypeName = (string)(_PlaceTypeName.Trim());
|
// //}
|
|
// //if (string.IsNullOrEmpty(_StockUnit))
|
// //{
|
// // throw Oops.Oh($"第{index}行[存放单位]{_StockUnit}不能为空!");
|
// //}
|
|
// //if (!string.IsNullOrEmpty(_StockUnit))
|
// //{
|
// // Admin.NET.Application.StockUnitEnum enumStockUnit = default(Admin.NET.Application.StockUnitEnum);
|
|
// // if (!Enum.TryParse<Admin.NET.Application.StockUnitEnum>(_StockUnit, out enumStockUnit) && !string.IsNullOrEmpty(_StockUnit))
|
// // {
|
// // throw Oops.Oh($"第{index}行[存放单位]{_StockUnit}值不正确!");
|
// // }
|
// // else
|
// // {
|
// // addItem.StockUnit = enumStockUnit;
|
// // }
|
|
// //}
|
// //if (!string.IsNullOrEmpty(_StockUnitName))
|
// //{
|
// // addItem.StockUnitName = (string)(_StockUnitName.Trim());
|
// //}
|
|
// if (string.IsNullOrEmpty(_PlaceStatus))
|
// {
|
// throw Oops.Oh($"第{index}行[库位属性]{_PlaceStatus}不能为空!");
|
// }
|
|
// if (!string.IsNullOrEmpty(_PlaceStatus))
|
// {
|
// Admin.NET.Application.PlaceStatusEnum enumPlaceStatus = default(Admin.NET.Application.PlaceStatusEnum);
|
|
// if (!Enum.TryParse<Admin.NET.Application.PlaceStatusEnum>(_PlaceStatus, out enumPlaceStatus) && !string.IsNullOrEmpty(_PlaceStatus))
|
// {
|
// throw Oops.Oh($"第{index}行[库位属性]{_PlaceStatus}值不正确!");
|
// }
|
// else
|
// {
|
// addItem.PlaceStatus = enumPlaceStatus;
|
// }
|
|
// }
|
// //if (!string.IsNullOrEmpty(_IsActivateWCS))
|
// //{
|
// // if (!_IsActivateWCS.Equals("是") && !_IsActivateWCS.Equals("否"))
|
// // {
|
// // throw Oops.Oh($"第{index}行[是否激活与任务调度]{_IsActivateWCS}值不正确!");
|
// // }
|
// // else
|
// // {
|
// // bool outIsActivateWCS = _IsActivateWCS.Equals("是") ? true : false;
|
// // addItem.IsActivateWCS = outIsActivateWCS;
|
// // }
|
// //}
|
|
// //if (!string.IsNullOrEmpty(_Environment))
|
// //{
|
// // addItem.Environment = (string)(_Environment.Trim());
|
// //}
|
|
// if (string.IsNullOrEmpty(_AreaId))
|
// {
|
// throw Oops.Oh($"第{index}行[所在库区]{_AreaId}不能为空!");
|
// }
|
|
// if (!string.IsNullOrEmpty(_AreaId))
|
// {
|
// if (!long.TryParse(_AreaId, out long outAreaId) && !string.IsNullOrEmpty(_AreaId))
|
// {
|
// throw Oops.Oh($"第{index}行[所在库区]{_AreaId}值不正确!");
|
// }
|
// if (outAreaId <= 0 && !string.IsNullOrEmpty(_AreaId))
|
// {
|
// throw Oops.Oh($"第{index}行[所在库区]{_AreaId}值不能小于等于0!");
|
// }
|
// else
|
// {
|
// addItem.AreaId = outAreaId;
|
// }
|
|
// }
|
// if (!string.IsNullOrEmpty(_AreaCode))
|
// {
|
// addItem.AreaCode = (string)(_AreaCode.Trim());
|
// }
|
// if (!string.IsNullOrEmpty(_AreaName))
|
// {
|
// addItem.AreaName = (string)(_AreaName.Trim());
|
// }
|
// if (!string.IsNullOrEmpty(_VerificationCode))
|
// {
|
// addItem.VerificationCode = (string)(_VerificationCode.Trim());
|
// }
|
// if (!string.IsNullOrEmpty(_RowNo))
|
// {
|
// if (!int.TryParse(_RowNo, out int outRowNo) && !string.IsNullOrEmpty(_RowNo))
|
// {
|
// throw Oops.Oh($"第{index}行[排]{_RowNo}值不正确!");
|
// }
|
// if (outRowNo <= 0 && !string.IsNullOrEmpty(_RowNo))
|
// {
|
// throw Oops.Oh($"第{index}行[排]{_RowNo}值不能小于等于0!");
|
// }
|
// else
|
// {
|
// addItem.RowNo = outRowNo;
|
// }
|
|
// }
|
// if (!string.IsNullOrEmpty(_ColumnNo))
|
// {
|
// if (!int.TryParse(_ColumnNo, out int outColumnNo) && !string.IsNullOrEmpty(_ColumnNo))
|
// {
|
// throw Oops.Oh($"第{index}行[列]{_ColumnNo}值不正确!");
|
// }
|
// if (outColumnNo <= 0 && !string.IsNullOrEmpty(_ColumnNo))
|
// {
|
// throw Oops.Oh($"第{index}行[列]{_ColumnNo}值不能小于等于0!");
|
// }
|
// else
|
// {
|
// addItem.ColumnNo = outColumnNo;
|
// }
|
|
// }
|
// if (!string.IsNullOrEmpty(_LayerNo))
|
// {
|
// if (!int.TryParse(_LayerNo, out int outLayerNo) && !string.IsNullOrEmpty(_LayerNo))
|
// {
|
// throw Oops.Oh($"第{index}行[层]{_LayerNo}值不正确!");
|
// }
|
// if (outLayerNo <= 0 && !string.IsNullOrEmpty(_LayerNo))
|
// {
|
// throw Oops.Oh($"第{index}行[层]{_LayerNo}值不能小于等于0!");
|
// }
|
// else
|
// {
|
// addItem.LayerNo = outLayerNo;
|
// }
|
|
// }
|
// if (!string.IsNullOrEmpty(_LaneNo))
|
// {
|
// if (!int.TryParse(_LaneNo, out int outLaneNo) && !string.IsNullOrEmpty(_LaneNo))
|
// {
|
// throw Oops.Oh($"第{index}行[巷道]{_LaneNo}值不正确!");
|
// }
|
// if (outLaneNo <= 0 && !string.IsNullOrEmpty(_LaneNo))
|
// {
|
// throw Oops.Oh($"第{index}行[巷道]{_LaneNo}值不能小于等于0!");
|
// }
|
// else
|
// {
|
// addItem.LaneNo = outLaneNo;
|
// }
|
|
// }
|
// if (!string.IsNullOrEmpty(_Xzb))
|
// {
|
// addItem.Xzb = (string)(_Xzb.Trim());
|
// }
|
// if (!string.IsNullOrEmpty(_Yzb))
|
// {
|
// addItem.Yzb = (string)(_Yzb.Trim());
|
// }
|
// if (!string.IsNullOrEmpty(_Zzb))
|
// {
|
// addItem.Zzb = (string)(_Zzb.Trim());
|
// }
|
// if (!string.IsNullOrEmpty(_Length))
|
// {
|
// if (!decimal.TryParse(_Length, out decimal outLength) && !string.IsNullOrEmpty(_Length))
|
// {
|
// throw Oops.Oh($"第{index}行[库位长度]{_Length}值不正确!");
|
// }
|
// if (outLength <= 0 && !string.IsNullOrEmpty(_Length))
|
// {
|
// throw Oops.Oh($"第{index}行[库位长度]{_Length}值不能小于等于0!");
|
// }
|
// else
|
// {
|
// addItem.Length = outLength;
|
// }
|
|
// }
|
// if (!string.IsNullOrEmpty(_Width))
|
// {
|
// if (!decimal.TryParse(_Width, out decimal outWidth) && !string.IsNullOrEmpty(_Width))
|
// {
|
// throw Oops.Oh($"第{index}行[库位宽度]{_Width}值不正确!");
|
// }
|
// if (outWidth <= 0 && !string.IsNullOrEmpty(_Width))
|
// {
|
// throw Oops.Oh($"第{index}行[库位宽度]{_Width}值不能小于等于0!");
|
// }
|
// else
|
// {
|
// addItem.Width = outWidth;
|
// }
|
|
// }
|
// if (!string.IsNullOrEmpty(_Height))
|
// {
|
// if (!decimal.TryParse(_Height, out decimal outHeight) && !string.IsNullOrEmpty(_Height))
|
// {
|
// throw Oops.Oh($"第{index}行[库位高度]{_Height}值不正确!");
|
// }
|
// if (outHeight <= 0 && !string.IsNullOrEmpty(_Height))
|
// {
|
// throw Oops.Oh($"第{index}行[库位高度]{_Height}值不能小于等于0!");
|
// }
|
// else
|
// {
|
// addItem.Height = outHeight;
|
// }
|
|
// }
|
// if (!string.IsNullOrEmpty(_MaxWeight))
|
// {
|
// if (!decimal.TryParse(_MaxWeight, out decimal outMaxWeight) && !string.IsNullOrEmpty(_MaxWeight))
|
// {
|
// throw Oops.Oh($"第{index}行[最大承重]{_MaxWeight}值不正确!");
|
// }
|
// if (outMaxWeight <= 0 && !string.IsNullOrEmpty(_MaxWeight))
|
// {
|
// throw Oops.Oh($"第{index}行[最大承重]{_MaxWeight}值不能小于等于0!");
|
// }
|
// else
|
// {
|
// addItem.MaxWeight = outMaxWeight;
|
// }
|
|
// }
|
// if (!string.IsNullOrEmpty(_InSequence))
|
// {
|
// if (!int.TryParse(_InSequence, out int outInSequence) && !string.IsNullOrEmpty(_InSequence))
|
// {
|
// throw Oops.Oh($"第{index}行[上架顺序]{_InSequence}值不正确!");
|
// }
|
// if (outInSequence <= 0 && !string.IsNullOrEmpty(_InSequence))
|
// {
|
// throw Oops.Oh($"第{index}行[上架顺序]{_InSequence}值不能小于等于0!");
|
// }
|
// else
|
// {
|
// addItem.InSequence = outInSequence;
|
// }
|
|
// }
|
// if (!string.IsNullOrEmpty(_OutSequence))
|
// {
|
// if (!int.TryParse(_OutSequence, out int outOutSequence) && !string.IsNullOrEmpty(_OutSequence))
|
// {
|
// throw Oops.Oh($"第{index}行[下架顺序]{_OutSequence}值不正确!");
|
// }
|
// if (outOutSequence <= 0 && !string.IsNullOrEmpty(_OutSequence))
|
// {
|
// throw Oops.Oh($"第{index}行[下架顺序]{_OutSequence}值不能小于等于0!");
|
// }
|
// else
|
// {
|
// addItem.OutSequence = outOutSequence;
|
// }
|
|
// }
|
// if (!string.IsNullOrEmpty(_IsVirtually))
|
// {
|
// if (!_IsVirtually.Equals("是") && !_IsVirtually.Equals("否"))
|
// {
|
// throw Oops.Oh($"第{index}行[是否虚拟]{_IsVirtually}值不正确!");
|
// }
|
// else
|
// {
|
// bool outIsVirtually = _IsVirtually.Equals("是") ? true : false;
|
// addItem.IsVirtually = outIsVirtually;
|
// }
|
// }
|
|
|
// if (string.IsNullOrEmpty(_IsDisabled))
|
// {
|
// throw Oops.Oh($"第{index}行[是否禁用]{_IsDisabled}不能为空!");
|
// }
|
|
// if (!string.IsNullOrEmpty(_IsDisabled))
|
// {
|
// if (!_IsDisabled.Equals("是") && !_IsDisabled.Equals("否"))
|
// {
|
// throw Oops.Oh($"第{index}行[是否禁用]{_IsDisabled}值不正确!");
|
// }
|
// else
|
// {
|
// bool outIsDisabled = _IsDisabled.Equals("是") ? true : false;
|
// addItem.IsDisabled = outIsDisabled;
|
// }
|
// }
|
|
// //if (!string.IsNullOrEmpty(_BindContainerCount))
|
// //{
|
// // if (!int.TryParse(_BindContainerCount, out int outBindContainerCount) && !string.IsNullOrEmpty(_BindContainerCount))
|
// // {
|
// // throw Oops.Oh($"第{index}行[绑定容器数]{_BindContainerCount}值不正确!");
|
// // }
|
// // if (outBindContainerCount <= 0 && !string.IsNullOrEmpty(_BindContainerCount))
|
// // {
|
// // throw Oops.Oh($"第{index}行[绑定容器数]{_BindContainerCount}值不能小于等于0!");
|
// // }
|
// // else
|
// // {
|
// // addItem.BindContainerCount = outBindContainerCount;
|
// // }
|
|
// //}
|
// #endregion
|
|
|
// details.Add(addItem);
|
// }
|
// //验重
|
// await CheckExisitForImport(details);
|
// return details;
|
//}
|
|
///// <summary>
|
///// 根据版本下载库位表的Excel导入模板
|
///// </summary>
|
///// <returns>下载的模板文件</returns>
|
//[HttpGet]
|
//[ApiDescriptionSettings(Name = "DownloadExcelTemplate")]
|
//[Description("WmsPlace/DownloadExcelTemplate")]
|
//public IActionResult DownloadExcelTemplate()
|
//{
|
// string _path = TemplateConst.EXCEL_TEMPLATEFILE_导入模版路径 + $"\\库位表{TemplateConst.EXCEL_TEMPLATEFILE_导入模版名称后缀}.xlsx";
|
// var fileName = HttpUtility.UrlEncode($"导入模板(库位表).xlsx", Encoding.GetEncoding("UTF-8"));
|
// return new FileStreamResult(new FileStream(_path, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName };
|
//}
|
|
#endregion
|
|
|
|
/// <summary>
|
/// 根据组合校验和单独校验验证数据是否已存在-导入时验证
|
/// </summary>
|
/// <param name="inputs"></param>
|
/// <returns></returns>
|
private async Task CheckExisitForImport(List<WmsBasePlace> inputs)
|
{
|
if (inputs?.Count <= 0)
|
{
|
throw Oops.Oh($"导入数据不能为空");
|
}
|
//根据组合校验验证表格中中是否已存在相同数据
|
|
|
|
|
|
|
|
|
//根据单独校验验证表格中中是否已存在相同数据
|
|
|
|
}
|
|
#region 私有方法
|
|
|
/// <summary>
|
/// //新增虚拟容器、绑定虚拟库位
|
/// </summary>
|
/// <param name="placeEntity"></param>
|
/// <returns></returns>
|
private async Task DOVirtually(WmsBasePlace placeEntity)
|
{
|
WmsContainerPlace addContainerPlace = null;
|
WmsBaseContainer addVirtuallyContainer = null;
|
//如果是虚拟库位,自动创建虚拟库位容器、绑定库位关系
|
if (placeEntity.IsVirtually == true)
|
{
|
//创建虚拟库位容器
|
//获取虚拟容器类型
|
var containerType = await _repWmsContainerType.GetFirstAsync(u => u.TypeCode == OperationsContainerTypeEnum.VIR.ToString());
|
|
if (containerType == null)
|
{
|
throw Oops.Oh(errorMessage: @$"{OperationsContainerTypeEnum.VIR.ToString()}虚拟容器类型不存在!");
|
}
|
if (containerType.IsDisabled == true)
|
{
|
throw Oops.Oh($"不能使用已禁用的容器类型");
|
}
|
|
var wmsContainer = await _repWmsContainer.GetFirstAsync(x => x.ContainerCode == placeEntity.PlaceCode && x.IsDelete == false);
|
if (wmsContainer == null)
|
{
|
addVirtuallyContainer = new WmsBaseContainer()
|
{
|
ContainerCode = placeEntity.PlaceCode,//虚拟容器编号跟虚拟库位编号保持一致
|
ContainerName = placeEntity.PlaceName,//虚拟容器名称跟虚拟库位名称保持一致
|
IsVirtually = true,
|
ContainerTypeId = containerType.Id,
|
ContainerTypeCode = containerType.TypeCode,
|
ContainerTypeName = containerType.TypeName
|
};
|
}
|
|
//虚拟容器绑定虚拟库位
|
|
var wmsContainerPlace = await _repWmsContainerPlace.GetFirstAsync(x => x.ContainerCode == placeEntity.PlaceCode && x.PlaceCode == placeEntity.PlaceCode && x.IsDelete == false);
|
if (wmsContainerPlace == null)
|
{
|
addContainerPlace = new WmsContainerPlace()
|
{
|
ContainerId = 0,
|
ContainerCode = placeEntity.PlaceCode,
|
ContainerName = placeEntity.PlaceCode,
|
PlaceId = placeEntity.Id,
|
PlaceCode = placeEntity.PlaceCode,
|
PlaceName = placeEntity.PlaceName
|
};
|
}
|
}
|
|
if (addVirtuallyContainer != null)//新增容器
|
{
|
await _repWmsContainer.InsertAsync(addVirtuallyContainer);
|
}
|
if (addContainerPlace != null)//新增容器库位绑定关系
|
{
|
await _repWmsContainerPlace.InsertAsync(addContainerPlace);
|
}
|
}
|
|
/// <summary>
|
/// 根据联合主键验证数据是否已存在-数据库
|
/// </summary>
|
/// <param name="input"></param>
|
/// <param name="isEdit"></param>
|
/// <returns></returns>
|
private async Task CheckExisit(WmsBasePlace input, bool isEdit = false)
|
{
|
//输出数据已存在错误
|
ErrorCodeItemMetadataAttribute metadata = ErrorCodeEnum.D1006.GetErrorCodeItemMetadata();
|
|
WmsBasePlace _existItem = null;
|
if (!isEdit)//新增
|
{
|
_existItem = await _rep.GetFirstAsync(u => u.PlaceCode.Equals(input.PlaceCode));
|
if (_existItem != null) throw Oops.Oh($"库位编号[{input.PlaceCode}]{metadata.ErrorMessage}");
|
|
_existItem = await _rep.GetFirstAsync(u => u.PlaceName.Equals(input.PlaceName));
|
if (_existItem != null) throw Oops.Oh($"库位名称[{input.PlaceName}]{metadata.ErrorMessage}");
|
|
|
//不同库区 可以存在相同的 巷道、排、列、层
|
_existItem = await _rep.GetFirstAsync(u => u.AreaCode.Equals(input.AreaCode.Trim()) && u.LaneNo.Equals(input.LaneNo) && u.RowNo.Equals(input.RowNo) && u.ColumnNo.Equals(input.ColumnNo) && u.LayerNo.Equals(input.LayerNo));
|
if (_existItem != null) throw Oops.Oh($"库位[{input.LaneNo + "巷道" + input.RowNo + "排" + input.ColumnNo + "列" + input.LayerNo + "层" + input.AreaName + "已存在"}]{metadata.ErrorMessage}");
|
|
|
}
|
else//编辑
|
{
|
//当前编辑数据以外是否存在重复
|
_existItem = await _rep.GetFirstAsync(u => u.Id != input.Id && u.PlaceCode.Equals(input.PlaceCode));
|
if (_existItem != null) throw Oops.Oh($"库位编号[{input.PlaceCode}]{metadata.ErrorMessage}");
|
|
_existItem = await _rep.GetFirstAsync(u => u.Id != input.Id && u.PlaceName.Equals(input.PlaceName));
|
if (_existItem != null) throw Oops.Oh($"库位名称[{input.PlaceName}]{metadata.ErrorMessage}");
|
|
_existItem = await _rep.GetFirstAsync(u => u.Id != input.Id && u.AreaCode.Equals(input.AreaCode.Trim()) && u.LaneNo.Equals(input.LaneNo) && u.RowNo.Equals(input.RowNo) && u.ColumnNo.Equals(input.ColumnNo) && u.LayerNo.Equals(input.LayerNo));
|
if (_existItem != null) throw Oops.Oh($"库位[{input.AreaCode + "库区" + input.LaneNo + "巷道" + input.RowNo + "排" + input.ColumnNo + "列" + input.LayerNo + "层" + input.AreaName + "已存在"}]{metadata.ErrorMessage}");
|
}
|
|
}
|
|
|
#endregion
|
|
|
|
///// <summary>
|
///// 根据库区 排获取库位信息
|
///// </summary>
|
///// <param name="input"></param>
|
///// <returns></returns>
|
//[HttpGet("GetPalceList")]
|
//public async Task<PalceInfoOtput> GetPalceList([FromQuery] PlaceInput input)
|
//{
|
// var places = await _rep.AsQueryable()
|
// .WhereIF(!string.IsNullOrWhiteSpace(input.PlaceNo), u => u.PlaceNo.Contains(input.PlaceNo.Trim()))
|
// .WhereIF(!string.IsNullOrWhiteSpace(input.AreaCode), u => u.AreaCode == input.AreaCode.Trim())
|
// .WhereIF(input.Aisle > 0, u => u.Aisle == input.Aisle)
|
// .WhereIF(input.RowNo > 0, u => u.RowNo == input.RowNo)
|
// .WhereIF(input.ColumnNo > 0, u => u.ColumnNo == input.ColumnNo)
|
// .WhereIF(input.LayerNo > 0, u => u.LayerNo == input.LayerNo)
|
// .Where(x => !x.IsDelete).ToListAsync();
|
|
// var aisleNos = places.OrderBy(x => x.Aisle).Select(x => x.Aisle).Distinct().ToList();//获取巷道列表
|
// var locationDataList = new List<LocationAisleData>();
|
// //巷道
|
// foreach (var aisle in aisleNos)
|
// {
|
// var aisleData = new LocationAisleData();
|
// aisleData.Aisle = aisle;
|
// aisleData.locationRownoData = new List<LocationRownoData>();
|
// //排
|
// var rowNos = places.Where(p => p.Aisle == aisle).OrderBy(n => n.RowNo).Select(n => n.RowNo).Distinct().ToList();
|
// foreach (var row in rowNos)
|
// {
|
// var rownoData = new LocationRownoData();
|
// rownoData.Rowno = row;
|
// rownoData.locationLayerData = new List<LocationLayerData>();
|
// //层
|
// var layerNo = places.Where(p => p.Aisle == aisle && p.RowNo == row).OrderByDescending(n => n.LayerNo).Select(n => n.LayerNo).Distinct();
|
// foreach (var lay in layerNo)
|
// {
|
// var layerData = new LocationLayerData();
|
// layerData.Layer = (int)lay;
|
// layerData.locationColumnNoData = new List<FoamingPalceDetail>();
|
// //列
|
// var columnNos = places.Where(p => p.Aisle == aisle && p.RowNo == row).OrderBy(n => n.ColumnNo).Select(n => n.ColumnNo).Distinct();
|
// foreach (var col in columnNos)
|
// {
|
// var wareLocationMdoel = places.Where(p => p.Aisle == aisle && p.RowNo == row && p.LayerNo == lay && p.ColumnNo == col).FirstOrDefault();
|
// if (wareLocationMdoel != null)
|
// {
|
// var locationDetail = new FoamingPalceDetail()
|
// {
|
// Id = wareLocationMdoel.Id,
|
// RowNo = wareLocationMdoel.RowNo,
|
// ColumnNo = wareLocationMdoel.ColumnNo,
|
// LayerNo = (int)wareLocationMdoel.LayerNo,
|
// PlaceCode = wareLocationMdoel.PlaceNo,
|
// Islock = wareLocationMdoel.Islock == 1 ? YesNoEnum.Y : YesNoEnum.N,
|
// EmptyContainer = wareLocationMdoel.EmptyContainer == 1 ? YesNoEnum.Y : YesNoEnum.N,
|
// PlaceStatus = (PlaceStatus)Enum.Parse(typeof(PlaceStatus), wareLocationMdoel.PlaceStatus.ToString())
|
// };
|
// layerData.locationColumnNoData.Add(locationDetail);
|
// }
|
// else
|
// {
|
// layerData.locationColumnNoData.Add(null);
|
// }
|
// }
|
// rownoData.locationLayerData.Add(layerData);
|
// }
|
// aisleData.locationRownoData.Add(rownoData);
|
// }
|
// locationDataList.Add(aisleData);
|
// }
|
|
// return new PalceInfoOtput()
|
// {
|
// countNum = places.Count,
|
// cunhuoNum = places.Where(n => n.PlaceStatus == (int)PlaceStatus.CUNHUO && n.IsDelete == false).Count(),
|
// emptyNum = places.Where(n => n.PlaceStatus == (int)PlaceStatus.KONGXIAN && n.IsDelete == false).Count(),
|
// DaiRuNum = places.Where(n => n.PlaceStatus == (int)PlaceStatus.DAIRU && n.IsDelete == false).Count(),
|
// DaichuNum = places.Where(n => n.PlaceStatus == (int)PlaceStatus.DAICHU && n.IsDelete == false).Count(),
|
// emptyContainerNum = places.Where(p => p.EmptyContainer == (int)YesNoEnum.Y && p.PlaceStatus == (int)PlaceStatus.CUNHUO && p.IsDelete == false).Count(),
|
// materialNum = places.Where(p => p.EmptyContainer == (int)YesNoEnum.N && p.PlaceStatus == (int)PlaceStatus.CUNHUO && p.IsDelete == false).Count(),
|
// lockNum = places.Where(p => p.Islock == (int)YesNoEnum.Y && p.IsDelete == false).Count(),
|
// PalceDetails = locationDataList,
|
// };
|
//}
|
/// <summary>
|
/// 批量增加货位基础信息
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "BatchAdd")]
|
public async Task BatchAdd(AddPlaceInput input)
|
{
|
List<WmsBasePlace> places = new List<WmsBasePlace>();
|
for (int aisle = 1; aisle <= 3; aisle++)//巷道
|
{
|
for (int row = 1; row <= 2; row++)//排
|
{
|
for (int column = 1; column <= 20; column++)//列
|
{
|
for (int layer = 1; layer <= 10; layer++)//层
|
{
|
WmsBasePlace place = new WmsBasePlace();
|
place.PlaceCode = aisle + "-" + row + "-" + column + "-" + layer;
|
place.PlaceName = aisle + "-" + row + "-" + column + "-" + layer;
|
place.AreaCode = "";
|
//place.StorageTypeNo = ((int)PlaceType.YUANLIAOKUWEI).ToString();
|
place.PlaceStatus = PlaceStatusEnum.正常;
|
//place.AreaCode = GlobalArea.GGHC;
|
place.RowNo = row;
|
place.ColumnNo = column;
|
place.LayerNo = layer;
|
//place.DeepcellNo = 0;
|
//place.GoodsShelfNo = "";
|
place.LaneNo = aisle;
|
place.IsVirtually = false;
|
//place.Line = 0;
|
//place.Islock = (int)YesNoEnum.N;
|
//place.EmptyContainer = (int)YesNoEnum.Y;
|
//place.PositionnoForSrm = "";
|
place.AreaCode = input.AreaCode;
|
place.AreaId = input.AreaId;
|
place.AreaName = input.AreaName;
|
place.Xzb = "";
|
place.Yzb = "";
|
place.Zzb = "";
|
place.Length = new decimal(100);
|
place.Width = new decimal(100);
|
place.Height = new decimal(000);
|
//place.MaxWeight = 630;
|
//place.HeightLevel = (int)Heightlevel.DI;
|
//place.Priority = (int)PlacePriority.GAO;
|
places.Add(place);
|
}
|
}
|
}
|
}
|
|
await _rep.InsertRangeAsync(places);
|
}
|
|
}
|