批量导入

This commit is contained in:
hehaibing-1996
2025-01-20 17:45:05 +08:00
parent 43e0f9f130
commit ee7ee7a672
11 changed files with 310 additions and 29 deletions

View File

@ -30,5 +30,14 @@ namespace WCS.BLL.Services.IService
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
public Task<ResponseCommon<object>> deleteMatDetailCurrentInfo(DeleteInfosRequest request); public Task<ResponseCommon<object>> deleteMatDetailCurrentInfo(DeleteInfosRequest request);
/// <summary>
/// 批量导入物料绑定关系
/// </summary>
/// <param name="lists"></param>
/// <param name="userName"></param>
/// <param name="deviceType"></param>
/// <returns></returns>
public Task<ResponseCommon<List<string>>> importMatDetailCurrentInfo(List<MatDetailCurrentInfoImportModel> lists, string userName, string deviceType,string stationCode);
} }
} }

View File

@ -27,7 +27,11 @@ namespace WCS.BLL.Services.Service
{ {
public class BatchBindMatDetailService : IBatchBindMatDetailService public class BatchBindMatDetailService : IBatchBindMatDetailService
{ {
/// <summary>
/// 按照工位号获取绑定明细
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<PageQueryResponse<MatDetailCurrentInfoModel>> GetMatDetailCurrentInfosByStationCode(GetMatDetailCurrentInfosByStationCodeRequest request) public async Task<PageQueryResponse<MatDetailCurrentInfoModel>> GetMatDetailCurrentInfosByStationCode(GetMatDetailCurrentInfosByStationCodeRequest request)
{ {
try try
@ -184,5 +188,100 @@ namespace WCS.BLL.Services.Service
return response; return response;
} }
} }
/// <summary>
/// 批量导入物料绑定关系
/// </summary>
/// <param name="lists"></param>
/// <param name="userName"></param>
/// <param name="deviceType"></param>
/// <returns></returns>
public async Task<ResponseCommon<List<string>>> importMatDetailCurrentInfo(List<MatDetailCurrentInfoImportModel> lists, string userName, string deviceType, string stationCode)
{
#region
//工位校验 工位是否有货架校验
var station = await DbHelp.db.Queryable<LocationInfo>()
.Where(t => t.LocationCode == stationCode || t.IsEnable == true)
.FirstAsync();
if (station == null)
{
return new ResponseCommon<List<string>>()
{
Code = 200,
Message = $"导入失败:工位[{stationCode}]不存在或已被禁用!",
Data = null,
};
}
//数量、物料编码等必填项的校验
foreach (var matDetailCurrentInfo in lists)
{
if (matDetailCurrentInfo. == null || matDetailCurrentInfo. <= 0)
{
return new ResponseCommon<List<string>>()
{
Code = 200,
Message = $"导入失败:数量应该大于0!",
Data = null,
};
}
if (string.IsNullOrEmpty(matDetailCurrentInfo.))
{
return new ResponseCommon<List<string>>()
{
Code = 200,
Message = $"导入失败:物料编码必填!",
Data = null,
};
}
}
//单据类型校验
//物料编码校验
#endregion
#region
try
{
await DbHelp.db.BeginTranAsync();
foreach (var mat in lists)
{
var matBaseInfo = new MatBaseInfo()
{
MatCode = mat.,
MatName = mat.,
MatSpec = mat.,
MatUnit = mat.,
MatCustomer = mat.,
ModifyUser = userName,
IsEnable = mat. == "启用" ? true : false,
};
await DbHelp.db.Insertable(matBaseInfo).ExecuteCommandAsync();
}
await DbHelp.db.CommitTranAsync();
return new ResponseCommon<List<string>>()
{
Code = 200,
Message = "导入数据成功",
Data = null
};
}
catch (Exception ex)
{
await DbHelp.db.RollbackTranAsync();
var ErrList = new List<string>
{
ex.Message
};
return new ResponseCommon<List<string>>()
{
Code = 200,
Message = "导入失败",
Data = ErrList
};
}
#endregion
}
} }
} }

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace WCS.Model.ApiModel.BatchBindMatDetail
{
public class MatDetailCurrentInfoImportModel
{
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public int? { get; set; }
public string { get; set; }
}
}

View File

@ -1,12 +1,15 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using WCS.BLL.DbModels; using WCS.BLL.DbModels;
using WCS.BLL.Services.IService; using WCS.BLL.Services.IService;
using WCS.BLL.Services.Service;
using WCS.DAL.Db; using WCS.DAL.Db;
using WCS.DAL.DbModels; using WCS.DAL.DbModels;
using WCS.Model; using WCS.Model;
using WCS.Model.ApiModel; using WCS.Model.ApiModel;
using WCS.Model.ApiModel.BatchBindMatDetail; using WCS.Model.ApiModel.BatchBindMatDetail;
using WCS.Model.ApiModel.Home; using WCS.Model.ApiModel.Home;
using WCS.Model.ApiModel.MatBaseInfo;
using WCS.Model.ApiModel.PDAMatBind; using WCS.Model.ApiModel.PDAMatBind;
using WCS.Model.ApiModel.User; using WCS.Model.ApiModel.User;
using WCS.Model.WebSocketModel; using WCS.Model.WebSocketModel;
@ -95,5 +98,57 @@ namespace WCS.WebApi.Controllers
return await _batchBindMatDetailService.GetMatDetailCurrentInfosByStationCode(request); return await _batchBindMatDetailService.GetMatDetailCurrentInfosByStationCode(request);
} }
[HttpPost("importMatDetailCurrentInfos")]
public async Task<ResponseBase> importMatDetailCurrentInfos([FromForm] IFormFile excelFile, [FromForm] string userName
, [FromForm] string deviceType, [FromForm] string stationCode)
{
//文件校验
if (excelFile == null || excelFile.Length == 0)
{
return new ResponseCommon()
{
Code = 201,
Message = "导入失败:文件无有效内容!"
};
}
//输入数据校验
if (string.IsNullOrEmpty(userName))
{
return new ResponseCommon()
{
Code = 201,
Message = "导入失败:参数[用户名]无效,请登录后重试!"
};
}
if (string.IsNullOrEmpty(deviceType))
{
return new ResponseCommon()
{
Code = 201,
Message = "导入失败:参数[设备类型]无效!"
};
}
if (string.IsNullOrEmpty(stationCode))
{
return new ResponseCommon()
{
Code = 201,
Message = "导入失败:参数[工位]无效,请联系相关人员维护工位编码!"
};
}
using (var stream = new MemoryStream())
{
await excelFile.CopyToAsync(stream);
stream.Position = 0;
var list = MiniExcelLibs.MiniExcel.Query<MatDetailCurrentInfoImportModel>(stream, "物料管理", ExcelType.XLSX).ToList();
//去除空白行
list.RemoveAll(x => string.IsNullOrWhiteSpace(x.));
return await _batchBindMatDetailService.importMatDetailCurrentInfo(list, userName, deviceType, stationCode);
}
}
} }
} }

View File

@ -32,11 +32,6 @@ namespace 智慧物流软件系统
/// </summary> /// </summary>
public JsSysConfig Sys { get; set; } public JsSysConfig Sys { get; set; }
/// <summary>
/// 货架类的是否软件启动后自检
/// </summary>
public bool IsBootSelfTest { get; set; }
/// <summary> /// <summary>
/// 扫码枪Com口列表 /// 扫码枪Com口列表
/// </summary> /// </summary>
@ -53,24 +48,16 @@ namespace 智慧物流软件系统
/// </summary> /// </summary>
public string LocationCode { get; set; } public string LocationCode { get; set; }
#region
//点击导入选择文件时 是否自动加载下载导入模板得路径
public bool IsLoadingDownloadPath { get; set; } = true;
public string BatchBindImportTemplatePath { get; set; } = string.Empty;
#endregion
#region #region
public bool IsMx { get; set; } public bool IsMx { get; set; }
/// <summary>
///MX-获取要料单接口地址
/// </summary>
public string GetPickOrderUrl { get; set; }
/// <summary>
///MX-获取要料明细接口地址
/// </summary>
public string RecommendedBarCode { get; set; }
/// <summary>
///MX-首盘发料明细接口地址
/// </summary>
public string FirstSendRecommendedBarCode { get; set; }
/// <summary>
///MX-后续发料明细接口地址
/// </summary>
public string ElectronicSiloPush { get; set; }
#endregion #endregion
#region #region
@ -84,6 +71,7 @@ namespace 智慧物流软件系统
public string RegexMatCode { get; set; } public string RegexMatCode { get; set; }
//正则 物料数量 //正则 物料数量
public string RegexMatQty { get; set; } public string RegexMatQty { get; set; }
//正则 物料批次 //正则 物料批次
public string RegexMatBatch { get; set; } public string RegexMatBatch { get; set; }
#endregion #endregion

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -69,5 +70,10 @@ namespace 智慧物流软件系统
process?.Close(); process?.Close();
} }
} }
public static void CopyFile(string sourcePath, string destinationPath)
{
File.Copy(sourcePath, destinationPath, true); // true 表示如果目标文件存在则覆盖它
}
} }
} }

View File

@ -22,6 +22,11 @@ using Newtonsoft.Json.Bson;
using WCS.Model.ApiModel.LocationInfo; using WCS.Model.ApiModel.LocationInfo;
using WCS.Model.ApiModel.MatDetailCurrentInfo; using WCS.Model.ApiModel.MatDetailCurrentInfo;
using WCS.Model.ApiModel.BatchBindMatDetail; using WCS.Model.ApiModel.BatchBindMatDetail;
using Microsoft.Win32;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using TouchSocket.Core;
using System.Text.RegularExpressions;
namespace .ViewModel namespace .ViewModel
{ {
@ -29,6 +34,7 @@ namespace 智慧物流软件系统.ViewModel
{ {
public BatchBindMatDetailViewModel() public BatchBindMatDetailViewModel()
{ {
//绑定工位编码
StationCode = LocalFile.Config.LocationCode; StationCode = LocalFile.Config.LocationCode;
} }
@ -189,7 +195,7 @@ namespace 智慧物流软件系统.ViewModel
MaxPage = Result.Data.MaxPage; MaxPage = Result.Data.MaxPage;
TotalCount = Result.Data.TotalCount; TotalCount = Result.Data.TotalCount;
} }
else if(Result != null && !string.IsNullOrEmpty(Result.Message)) else if (Result != null && !string.IsNullOrEmpty(Result.Message))
{ {
Growl.Warning(Result.Message); Growl.Warning(Result.Message);
} }
@ -265,6 +271,94 @@ namespace 智慧物流软件系统.ViewModel
return true; return true;
}); });
} }
/// <summary>
/// 下载导入模板
/// </summary>
public ICommand DownloadImportTemplateCommand { get => new DelegateCommand(DownloadImportTemplate); }
public void DownloadImportTemplate()
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Title = "选择保存导入模板路径";//窗口标题
saveFileDialog.Filter = "Excel 文件 (*.xlsx)|*.xlsx|All files (*.*)|*.*"; // 设置文件过滤器
saveFileDialog.ValidateNames = true;
saveFileDialog.FileName = "物料绑定导入模板.xlsx";// 设置默认文件名
if (saveFileDialog.ShowDialog() == true)
{
try
{
// 文件保存路径
var destinationPath = saveFileDialog.FileName;
// 文件源路径
var sourcePath = Path.Combine(LocalFile.ResourcesDir, "物料绑定导入模板.xlsx");
Folder.CopyFile(sourcePath, destinationPath);
if (File.Exists(destinationPath) && LocalFile.Config.IsLoadingDownloadPath)
{
LocalFile.Config.BatchBindImportTemplatePath = destinationPath;
LocalFile.SaveConfig();
}
Growl.Success("下载成功!");
}
catch (Exception ex)
{
Growl.Warning($"操作失败:{ex.Message}");
}
}
}
public ICommand BtnImportCommand { get => new DelegateCommand(BtnImport); }
public async void BtnImport()
{
try
{
#region
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "选择模板";
ofd.Filter = ".xlsx文件(*.xlsx)|*.xlsx";
ofd.Multiselect = false;
if (!string.IsNullOrEmpty(LocalFile.Config.BatchBindImportTemplatePath))
{
string pattern = @"^(.*?)\\[^\\]+$";
Match match = Regex.Match(LocalFile.Config.BatchBindImportTemplatePath, pattern);
if (match.Success)
{
ofd.InitialDirectory = match.Groups[1].Value;
}
}
if (ofd.ShowDialog() != true)
{
return;
}
#endregion
//已经选择文件 调用接口进行导入数据
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);
if (result.Code == 200)
{
Growl.Success("成功导入!");
CurrentPage = 0;
}
else
{
if (result.Data != null && result.Data.Count > 0)
HandyControl.Controls.MessageBox.Show(result.Message + "\t\n" + String.Join("\t\n", result.Data));
else
HandyControl.Controls.MessageBox.Show(result.Message);
}
}
catch (Exception ex)
{
Growl.Error("导入失败:" + ex.Message);
}
}
#endregion #endregion
#region PageOperation #region PageOperation

View File

@ -111,6 +111,16 @@
Command="{Binding BtnDeleteCommand}" Command="{Binding BtnDeleteCommand}"
Style="{StaticResource ButtonDanger}"></Button> Style="{StaticResource ButtonDanger}"></Button>
<TextBlock VerticalAlignment="Bottom"
Margin="25 5 5 5"
Foreground="Blue"
TextDecorations="Underline"
Text="下载导入模板">
<TextBlock.InputBindings>
<MouseBinding Gesture="LeftClick" Command="{Binding DownloadImportTemplateCommand}" />
</TextBlock.InputBindings>
</TextBlock>
<Button MinHeight="40" <Button MinHeight="40"
FontSize="18" FontSize="18"
Margin="5" Margin="5"
@ -137,19 +147,19 @@
<Button MinHeight="40" <Button MinHeight="40"
FontSize="18" FontSize="18"
Margin="5" Margin="5"
Content="&#xe613;呼叫货架" Content="呼叫货架&#xe6a9;"
FontFamily="{StaticResource IconFont}" FontFamily="{StaticResource IconFont}"
Command="{Binding BtnImportCommand}" Command="{Binding BtnCallIn}"
Foreground="WhiteSmoke" Foreground="WhiteSmoke"
Background="Green"></Button> Background="CadetBlue"></Button>
<Button MinHeight="40" <Button MinHeight="40"
FontSize="18" FontSize="18"
Margin="5" Margin="5"
Content="&#xe866;送货架" Content="送货架&#xe622;"
FontFamily="{StaticResource IconFont}" FontFamily="{StaticResource IconFont}"
Command="{Binding BtnExportCommand}" Command="{Binding BtnSend}"
Foreground="WhiteSmoke" Foreground="WhiteSmoke"
Background="DarkOrange"></Button> Background="OrangeRed"></Button>
</StackPanel> </StackPanel>
<DataGrid Grid.Row="1" <DataGrid Grid.Row="1"

View File

@ -113,6 +113,9 @@
<None Update="Resources\物料条码.btw"> <None Update="Resources\物料条码.btw">
<CopyToOutputDirectory>Never</CopyToOutputDirectory> <CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None> </None>
<None Update="Resources\物料绑定导入模板.xlsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>