更改导入接口
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using DingTalk.Api.Request;
|
||||||
using JNPF.Common.Configuration;
|
using JNPF.Common.Configuration;
|
||||||
using JNPF.Common.Core.Manager;
|
using JNPF.Common.Core.Manager;
|
||||||
using JNPF.Common.Extension;
|
using JNPF.Common.Extension;
|
||||||
@@ -24,7 +25,10 @@ using Tnb.WarehouseMgr.Entities;
|
|||||||
|
|
||||||
namespace Tnb.WarehouseMgr
|
namespace Tnb.WarehouseMgr
|
||||||
{
|
{
|
||||||
public class WmsImportAndExportService
|
/// <summary>
|
||||||
|
/// 导入和导出接口服务提供类
|
||||||
|
/// </summary>
|
||||||
|
public class WmsImportAndExportService : BaseWareHouseService
|
||||||
{
|
{
|
||||||
private readonly ISqlSugarClient _db;
|
private readonly ISqlSugarClient _db;
|
||||||
private readonly IUserManager _userManager;
|
private readonly IUserManager _userManager;
|
||||||
@@ -34,18 +38,37 @@ namespace Tnb.WarehouseMgr
|
|||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 载具导入模板
|
||||||
|
/// </summary>
|
||||||
|
/// <param name=""></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<dynamic> CarryImportTemplate()
|
||||||
|
{
|
||||||
|
int row = 0;
|
||||||
|
Dictionary<string,string> dic = new Dictionary<string,string>();
|
||||||
|
dic.Add("carry_code","载具编号");
|
||||||
|
dic.Add("carry_name","载具名称" );
|
||||||
|
dic.Add("carrystd_id","载具规格" );
|
||||||
|
//headers = _db.DbMaintenance.GetColumnInfosByTableName("wms_carry_h").FindAll(x=>!x.IsNullable).ToDictionary(x => x.DbColumnName ,x => x.ColumnDescription);
|
||||||
|
FileStreamResult fileStreamResult = WmsTemplate(dic, "载具台账");
|
||||||
|
|
||||||
|
return fileStreamResult;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 载具导入
|
/// 载具导入
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="file"></param>
|
/// <param name="file"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
public async Task<dynamic> CarryImport(IFormFile file)
|
public async Task<dynamic> CarryImport(IFormFile file)
|
||||||
{
|
{
|
||||||
int row = 0;
|
int row = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<Dictionary<string, string>> dics = WmsImport(file);
|
List<Dictionary<string, string>> dics = WmsImportExcelToMemory(file);
|
||||||
List<WmsCarryH> carrys = new List<WmsCarryH>();
|
List<WmsCarryH> carrys = new List<WmsCarryH>();
|
||||||
var carryStdDic = await _db.Queryable<WmsCarrystd>().ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
var carryStdDic = await _db.Queryable<WmsCarrystd>().ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
||||||
List<string> locCodes = new();
|
List<string> locCodes = new();
|
||||||
@@ -62,12 +85,15 @@ namespace Tnb.WarehouseMgr
|
|||||||
carryH = d.Adapt<WmsCarryH>();
|
carryH = d.Adapt<WmsCarryH>();
|
||||||
carrys.Add(carryH);
|
carrys.Add(carryH);
|
||||||
}
|
}
|
||||||
var locs = await _db.Queryable<BasLocation>().Where(it => locCodes.Contains(it.location_code)).ToDictionaryAsync(x => x.location_code, x => x.id);
|
if (locCodes != null)
|
||||||
foreach (var loc in locCodes)
|
|
||||||
{
|
{
|
||||||
var c = carrys.Find(x => x.location_code == loc);
|
var locs = await _db.Queryable<BasLocation>().Where(it => locCodes.Contains(it.location_code)).ToDictionaryAsync(x => x.location_code, x => x.id);
|
||||||
if (c != null)
|
foreach (var loc in locCodes)
|
||||||
c.location_id = locs[loc].ToString();
|
{
|
||||||
|
var c = carrys.Find(x => x.location_code == loc);
|
||||||
|
if (c != null)
|
||||||
|
c.location_id = locs[loc].ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
carrys.ForEach(x =>
|
carrys.ForEach(x =>
|
||||||
{
|
{
|
||||||
@@ -83,14 +109,14 @@ namespace Tnb.WarehouseMgr
|
|||||||
return false;
|
return false;
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
return row>0;
|
return row > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WMS导入
|
/// WMS导入
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static List<Dictionary<string, string>> WmsImport(IFormFile file)
|
private static List<Dictionary<string, string>> WmsImportExcelToMemory(IFormFile file)
|
||||||
{
|
{
|
||||||
int rowIndex = 1;
|
int rowIndex = 1;
|
||||||
List<Dictionary<string, string>> dics = new List<Dictionary<string, string>>();
|
List<Dictionary<string, string>> dics = new List<Dictionary<string, string>>();
|
||||||
@@ -155,22 +181,26 @@ namespace Tnb.WarehouseMgr
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// WMS导入模板
|
/// WMS导入模板
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dics"></param>
|
/// <param name="dic"></param>
|
||||||
/// <param name="sheetName"></param>
|
/// <param name="sheetName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static dynamic WmsTemplate(List<Dictionary<string, string>> dics, string sheetName)
|
private static dynamic WmsTemplate(Dictionary<string, string> dic, string sheetName)
|
||||||
{
|
{
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
ISheet sheet = workbook.CreateSheet(sheetName);
|
ISheet sheet = workbook.CreateSheet(sheetName);
|
||||||
IRow nRow = sheet.CreateRow(0);
|
IRow nRow = sheet.CreateRow(0);
|
||||||
IRow dRow = sheet.CreateRow(1);
|
IRow dRow = sheet.CreateRow(1);
|
||||||
|
dRow.Hidden = true;
|
||||||
for (int i = 0; i < dics?.Count; i++)
|
dic.Remove("id");
|
||||||
|
dic.Remove("create_id");
|
||||||
|
dic.Remove("create_time");
|
||||||
|
//sheet.SetColumnHidden(1, true);
|
||||||
|
for (int i = 0; i < dic?.Count; i++)
|
||||||
{
|
{
|
||||||
ICell cell1 = nRow.CreateCell(i);
|
ICell cell1 = nRow.CreateCell(i);
|
||||||
cell1.SetCellValue(dics[i].Keys.ToString());
|
cell1.SetCellValue(dic.Values.GetIndex(i));
|
||||||
ICell cell2 = dRow.CreateCell(i);
|
ICell cell2 = dRow.CreateCell(i);
|
||||||
cell2.SetCellValue(dics[i].Values.ToString());
|
cell2.SetCellValue(dic.Keys.GetIndex(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryStream ms = new MemoryStream();
|
MemoryStream ms = new MemoryStream();
|
||||||
|
|||||||
Reference in New Issue
Block a user