抛光库导入
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MiniExcelLibs;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.MES.wms;
|
||||
using ZR.Model.MES.wms.Dto;
|
||||
using ZR.Model.System;
|
||||
using ZR.Model.System.Dto;
|
||||
using ZR.Service.mes.wms;
|
||||
using ZR.Service.mes.wms.IService;
|
||||
@@ -216,5 +218,38 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
var response = _WmPolishInventoryService.GetPartNumber();
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 抛光导入模板下载
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("importTemplate")]
|
||||
[Log(Title = "抛光模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)]
|
||||
[AllowAnonymous]
|
||||
public IActionResult ImportTemplateExcel()
|
||||
{
|
||||
(string, string) result = DownloadImportTemplate("抛光仓库盘点模板");
|
||||
return ExportExcel(result.Item2, result.Item1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入
|
||||
/// </summary>
|
||||
/// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("importData")]
|
||||
[Log(Title = "抛光盘点导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)]
|
||||
[AllowAnonymous]
|
||||
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
|
||||
{
|
||||
List<WmPolishInventoryExportDto> importList = new();
|
||||
using (var stream = formFile.OpenReadStream())
|
||||
{
|
||||
importList = stream.Query<WmPolishInventoryExportDto>(startCell: "A1").ToList();
|
||||
}
|
||||
|
||||
return SUCCESS(_WmPolishInventoryService.ImportExcel(importList));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ namespace ZR.Model.MES.wms.Dto
|
||||
|
||||
public int? Quantity { get; set; }
|
||||
|
||||
public int RealQuantity { get; set; }
|
||||
|
||||
public int? MaxNum { get; set; }
|
||||
|
||||
public int? MinNum { get; set; }
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using MiniExcelLibs.Attributes;
|
||||
|
||||
namespace ZR.Model.MES.wms.Dto
|
||||
{
|
||||
/// <summary>
|
||||
@@ -59,20 +61,19 @@ namespace ZR.Model.MES.wms.Dto
|
||||
|
||||
public DateTime? UpdatedTime { get; set; }
|
||||
}
|
||||
|
||||
[SugarTable("wm_polish_inventory", "抛光表")]
|
||||
public class WmPolishInventoryExportDto
|
||||
{
|
||||
[SugarColumn(ColumnName = "partnumber")]
|
||||
public string 零件号 { get; set; }
|
||||
|
||||
public string 颜色 { get; set; }
|
||||
|
||||
public string 规格 { get; set; }
|
||||
|
||||
public string 描述 { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "quantity")]
|
||||
public int 盘点数 { get; set; } = 0;
|
||||
|
||||
public int 现有库存 { get; set; } = 0;
|
||||
[SugarColumn(ColumnName = "CREATED_TIME")]
|
||||
public DateTime? 盘点时间 { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1289,16 +1289,14 @@ namespace ZR.Service.mes.qc
|
||||
boardData.StockOneTimeWarehouseCount = oneTimeWarehouseTotal;
|
||||
// 产线合格
|
||||
int productQualifiedTotal =
|
||||
(
|
||||
Context
|
||||
.Queryable<QcQualityStatisticsFirst>()
|
||||
.WhereIF(
|
||||
!string.IsNullOrEmpty(query.Partnumber),
|
||||
it => it.FinishedPartNumber == query.Partnumber
|
||||
)
|
||||
.Where(it => it.StartTime >= boardData.OneTimeStockTime)
|
||||
.Sum(it => it.QualifiedNumber) ?? 0
|
||||
) / 3;
|
||||
Context
|
||||
.Queryable<QcQualityStatisticsFirst>()
|
||||
.WhereIF(
|
||||
!string.IsNullOrEmpty(query.Partnumber),
|
||||
it => it.FinishedPartNumber == query.Partnumber
|
||||
)
|
||||
.Where(it => it.StartTime >= boardData.OneTimeStockTime)
|
||||
.Sum(it => it.QualifiedNumber) ?? 0;
|
||||
// 倒车雷达
|
||||
string[] checkStrArray2 = { "倒车雷达" };
|
||||
var ParkingSensorPartNumberCheck = Expressionable.Create<WmMaterial>();
|
||||
@@ -1306,7 +1304,7 @@ namespace ZR.Service.mes.qc
|
||||
{
|
||||
ParkingSensorPartNumberCheck.Or(it => it.Description.Contains(checkStr));
|
||||
}
|
||||
;
|
||||
;
|
||||
ParkingSensorPartNumberCheck.And(it => it.Type == 1).And(it => it.Status == 1);
|
||||
List<string> ParkingSensorPartNumberList = Context
|
||||
.Queryable<WmMaterial>()
|
||||
@@ -1325,9 +1323,9 @@ namespace ZR.Service.mes.qc
|
||||
.Queryable<QcQualityStatisticsFirst>()
|
||||
.Where(predicateParkingSensor)
|
||||
.Sum(it => it.QualifiedNumber) ?? 0;
|
||||
productParkingSensorbQualifiedTotal = productParkingSensorbQualifiedTotal / 3;
|
||||
// 产线合格 - 倒车雷达
|
||||
productQualifiedTotal -= productParkingSensorbQualifiedTotal;
|
||||
productQualifiedTotal =
|
||||
(productQualifiedTotal - productParkingSensorbQualifiedTotal) / 3;
|
||||
|
||||
// 抛光合格
|
||||
int polishQualifiedTotal =
|
||||
@@ -1350,13 +1348,14 @@ namespace ZR.Service.mes.qc
|
||||
.Where(it => it.StartTime >= boardData.OneTimeStockTime)
|
||||
.Sum(it => it.RequireNumber) ?? 0;
|
||||
// 后道直接出库
|
||||
int afterPolishOutTotal = Context
|
||||
int afterPolishOutTotal =
|
||||
Context
|
||||
.Queryable<WmPolishQualityStatistics>()
|
||||
.WhereIF(
|
||||
!string.IsNullOrEmpty(query.Partnumber),
|
||||
it => it.Partnumber == query.Partnumber
|
||||
)
|
||||
.Where(it =>it.Type == 1)
|
||||
.Where(it => it.Type == 1)
|
||||
.Where(it => it.StartTime >= boardData.OneTimeStockTime)
|
||||
.Sum(it => it.RequireNumber) ?? 0;
|
||||
|
||||
|
||||
@@ -57,5 +57,11 @@ namespace ZR.Service.mes.wms.IService
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetPartNumber();
|
||||
/// <summary>
|
||||
/// 导入Excel
|
||||
/// </summary>
|
||||
/// <param name="users"></param>
|
||||
/// <returns></returns>
|
||||
public (string, object, object) ImportExcel(List<WmPolishInventoryExportDto> users);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,12 @@ namespace ZR.Service.mes.wms
|
||||
item.Description = !string.IsNullOrEmpty(material.Description)
|
||||
? material.Description
|
||||
: material.ProductName;
|
||||
|
||||
// 获取实际库存
|
||||
List<string> partnumbers = new List<string>();
|
||||
partnumbers.Add(item.Partnumber);
|
||||
Dictionary<string, int> dict = GetBatchOneTimeRealPartNum(partnumbers);
|
||||
item.RealQuantity = dict.TryGetValue(item.Partnumber, out int value) ? value : 0;
|
||||
}
|
||||
}
|
||||
return response;
|
||||
@@ -481,7 +487,7 @@ namespace ZR.Service.mes.wms
|
||||
.ToDictionary(g => g.Partnumber, g => SqlFunc.AggregateSum(g.Quantity) ?? 0);
|
||||
}
|
||||
|
||||
// Util 获取指定抛光库零件加报表后库存
|
||||
// Util 获取指定一次合格库零件加报表后库存
|
||||
public Dictionary<string, int> GetBatchOneTimeRealPartNum(List<string> partnumbers)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -2,15 +2,19 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Aliyun.OSS;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Extensions;
|
||||
using JinianNet.JNTemplate;
|
||||
using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar;
|
||||
using ZR.Common;
|
||||
using ZR.Model;
|
||||
using ZR.Model.MES.qc.DTO;
|
||||
using ZR.Model.MES.wms;
|
||||
using ZR.Model.MES.wms.Dto;
|
||||
using ZR.Model.System;
|
||||
using ZR.Repository;
|
||||
using ZR.Service.mes.qc;
|
||||
using ZR.Service.mes.wms.IService;
|
||||
@@ -83,6 +87,12 @@ namespace ZR.Service.mes.wms
|
||||
item.Description = !string.IsNullOrEmpty(material.Description)
|
||||
? material.Description
|
||||
: material.ProductName;
|
||||
// 获取实际库存
|
||||
|
||||
List<string> partnumbers = new List<string>();
|
||||
partnumbers.Add(item.Partnumber);
|
||||
Dictionary<string, int> dict = GetBatchPolishRealPartNum(partnumbers);
|
||||
item.RealQuantity = dict.TryGetValue(item.Partnumber, out int value)? value : 0;
|
||||
}
|
||||
}
|
||||
return response;
|
||||
@@ -518,6 +528,9 @@ namespace ZR.Service.mes.wms
|
||||
Dictionary<string, object> stockNumbers = GetBatchPolishStockPartNum(partnumbers);
|
||||
Dictionary<string, int> realNumbers = GetBatchPolishRealPartNum(partnumbers);
|
||||
|
||||
// 更新盘点时间
|
||||
DateTime dateTime = DateTime.Now.ToLocalTime();
|
||||
|
||||
// 构建导出数据
|
||||
List<WmPolishInventoryExportDto> exportDto = materials
|
||||
.Select(it =>
|
||||
@@ -532,6 +545,7 @@ namespace ZR.Service.mes.wms
|
||||
颜色 = it.Color,
|
||||
规格 = it.Specification,
|
||||
描述 = it.Description,
|
||||
盘点时间 = dateTime,
|
||||
盘点数 = stockNumber,
|
||||
现有库存 = found2 ? realNumber : 0,
|
||||
};
|
||||
@@ -576,5 +590,57 @@ namespace ZR.Service.mes.wms
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入数据
|
||||
/// </summary>
|
||||
/// <param name="importData"></param>
|
||||
/// <returns></returns>
|
||||
public (string, object, object) ImportExcel(List<WmPolishInventoryExportDto> importList)
|
||||
{
|
||||
List<WmPolishInventory> wmPolishInventorylist = importList.Select(it => new WmPolishInventory {
|
||||
Id = SnowFlakeSingle.Instance.NextId().ToString(),
|
||||
Type = 1,
|
||||
Status = 1,
|
||||
MaxNum = 0,
|
||||
MinNum = 0,
|
||||
WarnNum = 0,
|
||||
CreatedBy = "页面导入",
|
||||
Remark = "EXCEL 盘点导入",
|
||||
CreatedTime = it.盘点时间 ?? DateTime.Now.ToLocalTime(),
|
||||
Partnumber = it.零件号,
|
||||
Quantity = it.盘点数
|
||||
}).ToList();
|
||||
var x = Context.Storageable(wmPolishInventorylist)
|
||||
.SplitError(x => x.Item.Partnumber.IsEmpty(), "零件号不能为空")
|
||||
.SplitError(x => x.Item.Quantity.IsEmpty(), "盘点数不能为空")
|
||||
.SplitUpdate(it => it.Any()) // 数据库存在更新
|
||||
.SplitDelete(it => it.Item.Quantity == 0) //盘点数为0的不导入
|
||||
.SplitInsert(it => true) // 其余插入
|
||||
.WhereColumns(it => it.Partnumber)//如果不是主键可以这样实现(多字段it=>new{it.x1,it.x2})
|
||||
.ToStorage();
|
||||
|
||||
// 清空全部
|
||||
var result = x.AsInsertable.ExecuteCommand();//不存在则插入;
|
||||
var result2 = x.AsUpdateable.IgnoreColumns(it => new { it.Id }).ExecuteCommand();//存在则修改;
|
||||
var result3 = x.AsDeleteable.ExecuteCommand(); //盘点数为0的删除;
|
||||
string msg = string.Format(" 插入{0} 更新{1} 错误数据{2} 不计算数据{3} 删除数据{4} 总共{5}",
|
||||
x.InsertList.Count,
|
||||
x.UpdateList.Count,
|
||||
x.ErrorList.Count,
|
||||
x.IgnoreList.Count,
|
||||
x.DeleteList.Count,
|
||||
x.TotalList.Count);
|
||||
//输出统计
|
||||
Console.WriteLine(msg);
|
||||
|
||||
//输出错误信息
|
||||
foreach (var item in x.ErrorList)
|
||||
{
|
||||
Console.WriteLine("零件异常:" + item.Item.Partnumber + " : " + item.StorageMessage);
|
||||
}
|
||||
|
||||
return (msg, x.ErrorList, x.IgnoreList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user