批量导入
This commit is contained in:
@ -30,5 +30,14 @@ namespace WCS.BLL.Services.IService
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,11 @@ namespace WCS.BLL.Services.Service
|
||||
{
|
||||
public class BatchBindMatDetailService : IBatchBindMatDetailService
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 按照工位号获取绑定明细
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<PageQueryResponse<MatDetailCurrentInfoModel>> GetMatDetailCurrentInfosByStationCode(GetMatDetailCurrentInfosByStationCodeRequest request)
|
||||
{
|
||||
try
|
||||
@ -184,5 +188,100 @@ namespace WCS.BLL.Services.Service
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
@ -1,12 +1,15 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MiniExcelLibs;
|
||||
using WCS.BLL.DbModels;
|
||||
using WCS.BLL.Services.IService;
|
||||
using WCS.BLL.Services.Service;
|
||||
using WCS.DAL.Db;
|
||||
using WCS.DAL.DbModels;
|
||||
using WCS.Model;
|
||||
using WCS.Model.ApiModel;
|
||||
using WCS.Model.ApiModel.BatchBindMatDetail;
|
||||
using WCS.Model.ApiModel.Home;
|
||||
using WCS.Model.ApiModel.MatBaseInfo;
|
||||
using WCS.Model.ApiModel.PDAMatBind;
|
||||
using WCS.Model.ApiModel.User;
|
||||
using WCS.Model.WebSocketModel;
|
||||
@ -95,5 +98,57 @@ namespace WCS.WebApi.Controllers
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@ -32,11 +32,6 @@ namespace 智慧物流软件系统
|
||||
/// </summary>
|
||||
public JsSysConfig Sys { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 货架类的是否软件启动后自检
|
||||
/// </summary>
|
||||
public bool IsBootSelfTest { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 扫码枪Com口列表
|
||||
/// </summary>
|
||||
@ -53,24 +48,16 @@ namespace 智慧物流软件系统
|
||||
/// </summary>
|
||||
public string LocationCode { get; set; }
|
||||
|
||||
|
||||
#region 导入相关配置
|
||||
//点击导入选择文件时 是否自动加载下载导入模板得路径
|
||||
public bool IsLoadingDownloadPath { get; set; } = true;
|
||||
|
||||
public string BatchBindImportTemplatePath { get; set; } = string.Empty;
|
||||
#endregion
|
||||
|
||||
#region 盟讯公司配置
|
||||
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
|
||||
|
||||
#region 金川公司配置
|
||||
@ -84,6 +71,7 @@ namespace 智慧物流软件系统
|
||||
public string RegexMatCode { get; set; }
|
||||
//正则 物料数量
|
||||
public string RegexMatQty { get; set; }
|
||||
|
||||
//正则 物料批次
|
||||
public string RegexMatBatch { get; set; }
|
||||
#endregion
|
||||
|
BIN
货架标准上位机/Resources/物料绑定导入模板.xlsx
Normal file
BIN
货架标准上位机/Resources/物料绑定导入模板.xlsx
Normal file
Binary file not shown.
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -69,5 +70,10 @@ namespace 智慧物流软件系统
|
||||
process?.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyFile(string sourcePath, string destinationPath)
|
||||
{
|
||||
File.Copy(sourcePath, destinationPath, true); // true 表示如果目标文件存在则覆盖它
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,11 @@ using Newtonsoft.Json.Bson;
|
||||
using WCS.Model.ApiModel.LocationInfo;
|
||||
using WCS.Model.ApiModel.MatDetailCurrentInfo;
|
||||
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
|
||||
{
|
||||
@ -29,6 +34,7 @@ namespace 智慧物流软件系统.ViewModel
|
||||
{
|
||||
public BatchBindMatDetailViewModel()
|
||||
{
|
||||
//绑定工位编码
|
||||
StationCode = LocalFile.Config.LocationCode;
|
||||
}
|
||||
|
||||
@ -189,7 +195,7 @@ namespace 智慧物流软件系统.ViewModel
|
||||
MaxPage = Result.Data.MaxPage;
|
||||
TotalCount = Result.Data.TotalCount;
|
||||
}
|
||||
else if(Result != null && !string.IsNullOrEmpty(Result.Message))
|
||||
else if (Result != null && !string.IsNullOrEmpty(Result.Message))
|
||||
{
|
||||
Growl.Warning(Result.Message);
|
||||
}
|
||||
@ -265,6 +271,94 @@ namespace 智慧物流软件系统.ViewModel
|
||||
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
|
||||
|
||||
#region PageOperation 分页操作
|
||||
|
@ -111,6 +111,16 @@
|
||||
Command="{Binding BtnDeleteCommand}"
|
||||
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"
|
||||
FontSize="18"
|
||||
Margin="5"
|
||||
@ -137,19 +147,19 @@
|
||||
<Button MinHeight="40"
|
||||
FontSize="18"
|
||||
Margin="5"
|
||||
Content="呼叫货架"
|
||||
Content="呼叫货架"
|
||||
FontFamily="{StaticResource IconFont}"
|
||||
Command="{Binding BtnImportCommand}"
|
||||
Command="{Binding BtnCallIn}"
|
||||
Foreground="WhiteSmoke"
|
||||
Background="Green"></Button>
|
||||
Background="CadetBlue"></Button>
|
||||
<Button MinHeight="40"
|
||||
FontSize="18"
|
||||
Margin="5"
|
||||
Content="送货架"
|
||||
Content="送货架"
|
||||
FontFamily="{StaticResource IconFont}"
|
||||
Command="{Binding BtnExportCommand}"
|
||||
Command="{Binding BtnSend}"
|
||||
Foreground="WhiteSmoke"
|
||||
Background="DarkOrange"></Button>
|
||||
Background="OrangeRed"></Button>
|
||||
</StackPanel>
|
||||
|
||||
<DataGrid Grid.Row="1"
|
||||
|
@ -113,6 +113,9 @@
|
||||
<None Update="Resources\物料条码.btw">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Resources\物料绑定导入模板.xlsx">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Reference in New Issue
Block a user