1.实时导入旧系统绑定关系接口
2.物料基础数据导入优化
This commit is contained in:
@ -78,7 +78,7 @@ namespace WCS.BLL.DbModels
|
||||
/// 物料默认数量
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "mat_default_qty", IsNullable = true, ColumnDescription = "物料默认数量")]
|
||||
public int? MatDefaultQty { get; set; }
|
||||
public int? MatDefaultQty { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
|
@ -133,27 +133,27 @@ namespace WCS.BLL.Services.Service
|
||||
#endregion
|
||||
|
||||
#region 校验导入数据与数据库中数据是否有重复数据
|
||||
duplicates = await DbHelp.db.Queryable<MatBaseInfo>()
|
||||
var duplicatesInDb = await DbHelp.db.Queryable<MatBaseInfo>()
|
||||
.Where(t => matCodes.Contains(t.MatCode))
|
||||
.Select(t => t.MatCode)
|
||||
|
||||
.ToListAsync();
|
||||
|
||||
//有重复的情况
|
||||
if (duplicates.Count > 0)
|
||||
{
|
||||
return new ResponseCommon<List<string>>()
|
||||
{
|
||||
Code = 201,
|
||||
Message = "导入失败:以下物料编码已存在",
|
||||
Data = duplicates
|
||||
};
|
||||
}
|
||||
////有重复的情况
|
||||
//if (duplicates.Count > 0)
|
||||
//{
|
||||
// return new ResponseCommon<List<string>>()
|
||||
// {
|
||||
// Code = 201,
|
||||
// Message = "导入失败:以下物料编码已存在",
|
||||
// Data = duplicates
|
||||
// };
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region 导入数据
|
||||
try
|
||||
{
|
||||
await DbHelp.db.BeginTranAsync();
|
||||
var matBaseInfos = new List<MatBaseInfo>();
|
||||
foreach (var mat in lists)
|
||||
{
|
||||
var matBaseInfo = new MatBaseInfo()
|
||||
@ -166,8 +166,12 @@ namespace WCS.BLL.Services.Service
|
||||
ModifyUser = userName,
|
||||
IsEnable = mat.状态 == "启用" ? true : false,
|
||||
};
|
||||
await DbHelp.db.Insertable(matBaseInfo).ExecuteCommandAsync();
|
||||
matBaseInfos.Add(matBaseInfo);
|
||||
}
|
||||
await DbHelp.db.BeginTranAsync();
|
||||
//删除数据库中重复数据
|
||||
DbHelp.db.Deleteable(duplicatesInDb).ExecuteCommand();
|
||||
await DbHelp.db.Insertable(matBaseInfos).ExecuteCommandAsync();
|
||||
await DbHelp.db.CommitTranAsync();
|
||||
return new ResponseCommon<List<string>>()
|
||||
{
|
||||
|
@ -16,4 +16,14 @@ namespace WCS.Model.ApiModel.BatchBindMatDetail
|
||||
public int? 数量 { get; set; }
|
||||
public string 货架编码 { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 旧系统导入模板
|
||||
/// </summary>
|
||||
public class OldSystemImportModel
|
||||
{
|
||||
public string 货架编号 { get; set; }
|
||||
|
||||
public string 物料批次号 { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace WCS.BLL.DbModels
|
||||
/// <summary>
|
||||
/// 物料默认数量
|
||||
/// </summary>
|
||||
public int MatDefaultQty { get; set; } = 100;
|
||||
public int? MatDefaultQty { get; set; }
|
||||
|
||||
public string MatSupplier { get; set; }
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MiniExcelLibs;
|
||||
using System.Linq.Expressions;
|
||||
using WCS.BLL.DbModels;
|
||||
using WCS.BLL.Services.IService;
|
||||
using WCS.BLL.Services.Service;
|
||||
@ -164,7 +165,7 @@ namespace WCS.WebApi.Controllers
|
||||
stream.Position = 0;
|
||||
var list = MiniExcelLibs.MiniExcel.Query<MatDetailCurrentInfoImportModel>(stream, "物料绑定", ExcelType.XLSX).ToList();
|
||||
//去除空白行
|
||||
//list.RemoveAll(x => string.IsNullOrWhiteSpace(x.物料编码));
|
||||
//infoList.RemoveAll(x => string.IsNullOrWhiteSpace(x.物料编码));
|
||||
if (list == null || list.Count == 0)
|
||||
{
|
||||
return new ResponseCommon()
|
||||
@ -177,5 +178,119 @@ namespace WCS.WebApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入旧系统绑定关系
|
||||
/// </summary>
|
||||
/// <param name="excelFile"></param>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="deviceType"></param>
|
||||
/// <param name="stationCode"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("importOldSystem")]
|
||||
public async Task<ResponseBase> importOldSystem([FromForm] IFormFile excelFile, [FromForm] string userName
|
||||
, [FromForm] string deviceType)
|
||||
{
|
||||
try
|
||||
{
|
||||
//文件校验
|
||||
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 = "导入失败:参数[设备类型]无效!"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
await excelFile.CopyToAsync(stream);
|
||||
stream.Position = 0;
|
||||
var infoList = MiniExcelLibs.MiniExcel.Query<OldSystemImportModel>(stream, "货架管理", ExcelType.XLSX).ToList();
|
||||
//去除空白行
|
||||
infoList.RemoveAll(x => string.IsNullOrWhiteSpace(x.物料批次号));
|
||||
if (infoList == null || infoList.Count == 0)
|
||||
{
|
||||
return new ResponseCommon()
|
||||
{
|
||||
Code = 201,
|
||||
Message = "导入失败:上传的文件中不存在有效的数据!"
|
||||
};
|
||||
}
|
||||
var shelfCodes = infoList.Select(t => t.货架编号).Distinct().ToList();
|
||||
//获取系统中的货架
|
||||
var shelfs = DbHelp.db.Queryable<ShelfInfo>()
|
||||
.LeftJoin<MatDetailCurrentInfo>((si, mci) => mci.ShelfId == si.Id)
|
||||
//.Where((si, mci) => mci.Id == 0)//本系统未采取绑定的才进行绑定
|
||||
.Where((si, mci) => shelfCodes.Contains(si.ShelfCode))
|
||||
.Select((si, mci) => si)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
//var shelfCodesInDb = shelfs.Select(t => t.ShelfCode).Distinct().ToList();
|
||||
|
||||
var matCurrentInfos = new List<MatDetailCurrentInfo>();
|
||||
foreach (var info in infoList)
|
||||
{
|
||||
var shelf = shelfs.Where(t => t.ShelfCode == info.货架编号).FirstOrDefault();
|
||||
//此货架已在新系统绑定的情况
|
||||
if (shelf == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var matCurrentInfo = new MatDetailCurrentInfo()
|
||||
{
|
||||
ShelfId = shelf.Id,
|
||||
ShelfCode = shelf.ShelfCode,
|
||||
ShelfType = shelf.ShelfTypeName,
|
||||
MatCode = info.物料批次号 + "(旧系统)",
|
||||
MatName = info.物料批次号 + "(旧系统)",
|
||||
MatBatch = "",
|
||||
MatQty = 1,
|
||||
ModifyUser = "system"
|
||||
};
|
||||
matCurrentInfos.Add(matCurrentInfo);
|
||||
}
|
||||
|
||||
//删除上一次导入的信息
|
||||
DbHelp.db.Deleteable<MatDetailCurrentInfo>().Where(t => t.MatCode.Contains("(旧系统)")).ExecuteCommand();
|
||||
DbHelp.db.Insertable(matCurrentInfos).ExecuteCommand();
|
||||
|
||||
|
||||
return new ResponseCommon()
|
||||
{
|
||||
Code = 200,
|
||||
Message = "Success"
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
||||
|
||||
return new ResponseCommon()
|
||||
{
|
||||
Code = 201,
|
||||
Message = "失败" + ex.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user