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