This commit is contained in:
2024-10-25 19:01:06 +08:00
parent 0f3232d32b
commit 58994f4d7a
14 changed files with 414 additions and 10 deletions

View File

@@ -1,12 +1,20 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Aliyun.OSS;
using Infrastructure.Attribute;
using Infrastructure.Extensions;
using Microsoft.AspNetCore.DataProtection.KeyManagement;
using Newtonsoft.Json.Linq;
using SqlSugar;
using ZR.Model;
using ZR.Model.MES.qc.DTO;
using ZR.Model.MES.wms;
using ZR.Model.MES.wms.Dto;
using ZR.Repository;
using ZR.Service.mes.qc;
using ZR.Service.mes.wms.IService;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace ZR.Service.mes.wms
{
@@ -52,12 +60,13 @@ namespace ZR.Service.mes.wms
var response = Queryable()
.Where(predicate.ToExpression())
.OrderByDescending(it => it.UpdatedTime)
.OrderBy(it => it.Partnumber)
.ToPage<WmPolishInventory, WmPolishInventoryDto>(parm);
if (response.Result.Count > 0)
{
foreach (WmPolishInventoryDto item in response.Result)
{
// 获取物料信息
WmMaterial material = Context
.Queryable<WmMaterial>()
.Where(it => it.Partnumber == item.Partnumber)
@@ -472,5 +481,96 @@ namespace ZR.Service.mes.wms
.Where(it => it.Status == 1)
.Sum(it => it.Quantity) ?? 0;
}
// Util 获取物料清单,不包含毛坯
public List<WmMaterial> GetWmMaterialList(string partnumber)
{
// 获取物料信息
return Context
.Queryable<WmMaterial>()
.WhereIF(
!string.IsNullOrEmpty(partnumber),
it => it.Partnumber.Contains(partnumber)
)
.Where(it => !string.IsNullOrEmpty(it.Partnumber))
.Where(it => it.Type == 1)
.Where(it => it.Status == 1)
.Distinct()
.OrderBy(it => it.Description)
.ToList();
}
// 获取Excel导出数据
public List<WmPolishInventoryExportDto> GetExportList(WmPolishInventoryQueryDto parm)
{
try
{
List<WmMaterial> materials = GetWmMaterialList(parm.Partnumber);
// 获取所有partnumber列表
List<string> partnumbers = materials
.Where(it => !string.IsNullOrEmpty(it.Partnumber))
.Select(it => it.Partnumber)
.Distinct()
.ToList();
// 批量获取盘点数和现有库存
Dictionary<string, object> stockNumbers = GetBatchPolishStockPartNum(partnumbers);
Dictionary<string, int> realNumbers = GetBatchPolishRealPartNum(partnumbers);
// 构建导出数据
List<WmPolishInventoryExportDto> exportDto = materials
.Select(it =>
{
bool found1 = stockNumbers.TryGetValue(it.Partnumber, out object value1);
int stockNumber = found1 && value1 != null ? Convert.ToInt32(value1) : 0;
bool found2 = realNumbers.TryGetValue(it.Partnumber, out int realNumber);
return new WmPolishInventoryExportDto
{
= it.Partnumber,
= it.Color,
= it.Specification,
= it.Description,
= stockNumber,
= found2 ? realNumber : 0,
};
})
.ToList();
return exportDto;
}
catch (Exception e)
{
throw;
}
}
// Util 获取指定抛光库零件盘点库存
public Dictionary<string, object> GetBatchPolishStockPartNum(List<string> partnumbers)
{
return Context
.Queryable<WmPolishInventory>()
.Where(it => partnumbers.Contains(it.Partnumber))
.GroupBy(it => it.Partnumber)
.ToDictionary(g => g.Partnumber, g => SqlFunc.AggregateSum(g.Quantity) ?? 0);
}
// Util 获取指定抛光库零件加报表后库存
public Dictionary<string, int> GetBatchPolishRealPartNum(List<string> partnumbers)
{
try
{
// 盘点时间
DateTime checkTime = new(2024, 10, 20, 0, 0, 0);
CommonFQCService commonFQCService = new();
// 获取报表数据
// 抛光计算后库存 = 盘点库存 + 产线抛光 + 后道反抛 + GP12反抛 - 抛光投入
return commonFQCService.GetBatchPolishPartRealStock(partnumbers, checkTime);
}
catch (Exception e)
{
throw;
}
}
}
}