物料绑定 导入功能
This commit is contained in:
@ -62,7 +62,7 @@ namespace WCS.BLL.DbModels
|
||||
/// 物料规格
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "mat_spec", Length = 128, IsNullable = true, ColumnDescription = "物料规格")]
|
||||
public string MatSpec { get; set; }
|
||||
public string? MatSpec { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 物料单位
|
||||
@ -94,19 +94,19 @@ namespace WCS.BLL.DbModels
|
||||
/// 单据类型Id
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "order_type_id", IsNullable = true, ColumnDescription = "单据类型Id")]
|
||||
public int OrderTypeId { get; set; }
|
||||
public int? OrderTypeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单据类型名称
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "order_Type_name", Length = 64, IsNullable = true, ColumnDescription = "单据类型名称")]
|
||||
public string OrderTypeName { get; set; }
|
||||
public string? OrderTypeName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单据编号
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "order_number", Length = 64, IsNullable = true, ColumnDescription = "单据编号")]
|
||||
public string OrderNumber { get; set; }
|
||||
public string? OrderNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 站位编号 用于物料批量绑定时区分是哪个工位绑定的明细
|
||||
|
@ -42,7 +42,7 @@ namespace WCS.BLL.Services.Service
|
||||
|| (si.TransStatus == TransStatusEnum.运输中 && si.DestinationLocationId == li.Id))
|
||||
.WhereIF(request.OrderTypeId != null && request.OrderTypeId != 0, (mci, si, li) => mci.OrderTypeId == request.OrderTypeId)
|
||||
.WhereIF(!string.IsNullOrEmpty(request.ShelfCode), (mci, si, li) => si.ShelfCode.Contains(request.ShelfCode))
|
||||
//.WhereIF(!string.IsNullOrEmpty(request.StationCode), (mci, si, li) => mci.StationCode.Contains(request.StationCode))
|
||||
.WhereIF(!string.IsNullOrEmpty(request.StationCode), (mci, si, li) => mci.StationCode.Contains(request.StationCode))
|
||||
.Select((mci, si, li) => new MatDetailCurrentInfoModel()
|
||||
{
|
||||
Id = mci.Id,
|
||||
@ -213,6 +213,26 @@ namespace WCS.BLL.Services.Service
|
||||
};
|
||||
}
|
||||
|
||||
var shelfInfo = await DbHelp.db.Queryable<ShelfInfo>()
|
||||
.Where(t => (t.TransStatus == TransStatusEnum.静止 && t.CurrentLocationId == station.Id) ||
|
||||
t.TransStatus == TransStatusEnum.运输中 && t.DestinationLocationId == station.Id)
|
||||
.Where(t => t.IsEnable)
|
||||
.FirstAsync();
|
||||
if (shelfInfo == null)
|
||||
{
|
||||
return new ResponseCommon<List<string>>()
|
||||
{
|
||||
Code = 200,
|
||||
Message = $"导入失败:当前工位不存在货架,请呼叫货架后再进行操作!",
|
||||
Data = null,
|
||||
};
|
||||
}
|
||||
|
||||
//单据类型校验 物料类型数量较小 不会对内存造成负担
|
||||
var orderTypesInDb = await DbHelp.db.Queryable<OrderTypeInfo>()
|
||||
.ToListAsync();
|
||||
var orderTypeNamesInDb = orderTypesInDb.Select(t => t.OrderTypeName)
|
||||
.ToList();
|
||||
//数量、物料编码等必填项的校验
|
||||
foreach (var matDetailCurrentInfo in lists)
|
||||
{
|
||||
@ -234,10 +254,62 @@ namespace WCS.BLL.Services.Service
|
||||
Data = null,
|
||||
};
|
||||
}
|
||||
}
|
||||
//单据类型校验
|
||||
if (!string.IsNullOrEmpty(matDetailCurrentInfo.单据类型) && !orderTypeNamesInDb.Contains(matDetailCurrentInfo.单据类型))
|
||||
{
|
||||
return new ResponseCommon<List<string>>()
|
||||
{
|
||||
Code = 200,
|
||||
Message = $"导入失败:单据类型[{matDetailCurrentInfo.单据类型}]无效!",
|
||||
Data = null,
|
||||
};
|
||||
}
|
||||
|
||||
//物料编码校验
|
||||
if (!string.IsNullOrEmpty(matDetailCurrentInfo.货架编码) && matDetailCurrentInfo.货架编码 == shelfInfo.ShelfCode)
|
||||
{
|
||||
return new ResponseCommon<List<string>>()
|
||||
{
|
||||
Code = 200,
|
||||
Message = $"导入失败:货架[{matDetailCurrentInfo.货架编码}]不是当前工位的货架!",
|
||||
Data = null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#region 物料编码校验
|
||||
//物料编码校验 物料编码的数据可能比较多 所以有可能会对服务器内存造成负担所以采用以下形式进行校验
|
||||
var matCodes = lists.Select(t => t.物料编码)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
var matBaseInfoInDb = await DbHelp.db.Queryable<MatBaseInfo>()
|
||||
.Where(t => matCodes.Contains(t.MatCode))
|
||||
.Where(t => t.IsEnable == true)
|
||||
.ToListAsync();
|
||||
if (matBaseInfoInDb == null)
|
||||
{
|
||||
return new ResponseCommon<List<string>>()
|
||||
{
|
||||
Code = 200,
|
||||
Message = $"导入失败:请重试!",
|
||||
Data = null,
|
||||
};
|
||||
}
|
||||
//判断如果导入表中的物料编码数量与数据库中有效的编码数量不一致证明中间有无效的物料编码
|
||||
if (matBaseInfoInDb != null && matBaseInfoInDb?.Count < matCodes.Count)
|
||||
{
|
||||
var matCodesInDb = matBaseInfoInDb.Select(t => t.MatName).ToList();
|
||||
matCodes.RemoveAll(t => matCodesInDb.Contains(t));
|
||||
if (matCodes.Count > 0)
|
||||
{
|
||||
return new ResponseCommon<List<string>>()
|
||||
{
|
||||
Code = 200,
|
||||
Message = $"导入失败:以下物料编码无效!\r\n{string.Join(",", matCodes)}",
|
||||
Data = null,
|
||||
};
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
@ -245,19 +317,39 @@ namespace WCS.BLL.Services.Service
|
||||
try
|
||||
{
|
||||
await DbHelp.db.BeginTranAsync();
|
||||
foreach (var mat in lists)
|
||||
foreach (var info in lists)
|
||||
{
|
||||
var matBaseInfo = new MatBaseInfo()
|
||||
var matBaseInfo = matBaseInfoInDb?.Where(t => t.MatCode == info.物料编码).First();
|
||||
var orderType = orderTypesInDb?.Where(t => t.OrderTypeName == info.单据类型).FirstOrDefault();
|
||||
//应该是不能走进的分支
|
||||
if (matBaseInfo == null)
|
||||
{
|
||||
MatCode = mat.物料编码,
|
||||
MatName = mat.名称,
|
||||
MatSpec = mat.规格,
|
||||
MatUnit = mat.单位,
|
||||
MatCustomer = mat.客户,
|
||||
continue;
|
||||
}
|
||||
var matDetailCurrentInfo = new MatDetailCurrentInfo()
|
||||
{
|
||||
|
||||
ShlefId = shelfInfo.Id,
|
||||
ShelfCode = shelfInfo.ShelfCode,
|
||||
ShelfType = shelfInfo.ShelfTypeName,
|
||||
|
||||
MatCode = matBaseInfo.MatCode,
|
||||
MatName = matBaseInfo.MatName,
|
||||
MatSpec = matBaseInfo.MatSpec,
|
||||
MatUnit = matBaseInfo.MatUnit,
|
||||
MatSupplier = matBaseInfo.MatSupplier,
|
||||
MatCustomer = matBaseInfo.MatCustomer,
|
||||
MatQty = info.数量.GetValueOrDefault(),
|
||||
|
||||
OrderTypeId = orderType?.Id,
|
||||
OrderTypeName = orderType?.OrderTypeName,
|
||||
OrderNumber = info.单据编号,
|
||||
StationCode = stationCode,
|
||||
|
||||
ModifyUser = userName,
|
||||
IsEnable = mat.状态 == "启用" ? true : false,
|
||||
|
||||
};
|
||||
await DbHelp.db.Insertable(matBaseInfo).ExecuteCommandAsync();
|
||||
await DbHelp.db.Insertable(matDetailCurrentInfo).ExecuteCommandAsync();
|
||||
}
|
||||
await DbHelp.db.CommitTranAsync();
|
||||
return new ResponseCommon<List<string>>()
|
||||
|
@ -142,10 +142,17 @@ namespace WCS.WebApi.Controllers
|
||||
{
|
||||
await excelFile.CopyToAsync(stream);
|
||||
stream.Position = 0;
|
||||
var list = MiniExcelLibs.MiniExcel.Query<MatDetailCurrentInfoImportModel>(stream, "物料管理", ExcelType.XLSX).ToList();
|
||||
var list = MiniExcelLibs.MiniExcel.Query<MatDetailCurrentInfoImportModel>(stream, "物料绑定", ExcelType.XLSX).ToList();
|
||||
//去除空白行
|
||||
list.RemoveAll(x => string.IsNullOrWhiteSpace(x.物料编码));
|
||||
|
||||
//list.RemoveAll(x => string.IsNullOrWhiteSpace(x.物料编码));
|
||||
if (list == null || list.Count == 0)
|
||||
{
|
||||
return new ResponseCommon()
|
||||
{
|
||||
Code = 201,
|
||||
Message = "导入失败:上传的文件中不存在有效的数据!"
|
||||
};
|
||||
}
|
||||
return await _batchBindMatDetailService.importMatDetailCurrentInfo(list, userName, deviceType, stationCode);
|
||||
}
|
||||
}
|
||||
|
@ -271,6 +271,43 @@ namespace 智慧物流软件系统.Api
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static async Task<T> StationPostImportFileAsync<T>(string localFilePath, HttpMethod method, string requestUrl, string userName, string deviceType,string stationCode)
|
||||
{
|
||||
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, requestUrl);
|
||||
|
||||
using (var content = new MultipartFormDataContent())
|
||||
{
|
||||
var fileContent = new StreamContent(new FileStream(localFilePath, FileMode.Open, FileAccess.Read));
|
||||
fileContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("multipart/form-data");
|
||||
content.Add(fileContent, "excelFile", Path.GetFileName(localFilePath));
|
||||
|
||||
var userNameContent = new StringContent(userName);
|
||||
userNameContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("multipart/form-data");
|
||||
content.Add(userNameContent, "userName");
|
||||
|
||||
var deviceTypeContent = new StringContent(deviceType);
|
||||
deviceTypeContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("multipart/form-data");
|
||||
content.Add(deviceTypeContent, "deviceType");
|
||||
|
||||
var stationCodeContent = new StringContent(stationCode);
|
||||
stationCodeContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("multipart/form-data");
|
||||
content.Add(stationCodeContent, "stationCode");
|
||||
|
||||
httpRequestMessage.Content = content;
|
||||
using (var response = await httpClient.SendAsync(httpRequestMessage))
|
||||
{
|
||||
response.EnsureSuccessStatusCode(); // 确保请求成功
|
||||
var filename = string.Empty;
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return default(T);
|
||||
|
||||
var con = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<T>(con) ?? default(T); ;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 调用接口超时时间10s
|
||||
/// </summary>
|
||||
|
Binary file not shown.
@ -339,8 +339,8 @@ namespace 智慧物流软件系统.ViewModel
|
||||
//已经选择文件 调用接口进行导入数据
|
||||
string path = ofd.FileName;
|
||||
|
||||
var result = await ApiHelp.PostImportFileAsync<ResponseCommon<List<string>>>(path, System.Net.Http.HttpMethod.Post,
|
||||
LocalFile.Config.ApiIpHost + "matBaseInfo/importMatBaseInfo", LocalStatic.CurrentUser, LocalFile.Config.DeviceType);
|
||||
var result = await ApiHelp.StationPostImportFileAsync<ResponseCommon<List<string>>>(path, System.Net.Http.HttpMethod.Post,
|
||||
LocalFile.Config.ApiIpHost + "batchBindMatDetail/importMatDetailCurrentInfos", LocalStatic.CurrentUser, LocalFile.Config.DeviceType,LocalFile.Config.LocationCode);
|
||||
if (result.Code == 200)
|
||||
{
|
||||
Growl.Success("成功导入!");
|
||||
|
Reference in New Issue
Block a user