2024-08-08 17:14:03 +08:00
|
|
|
|
using Infrastructure.Attribute;
|
2024-11-15 18:51:05 +08:00
|
|
|
|
using Infrastructure.Extensions;
|
2024-08-08 17:14:03 +08:00
|
|
|
|
using SqlSugar;
|
2025-07-28 15:40:59 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
2024-11-25 16:34:07 +08:00
|
|
|
|
using ZR.Model.MES.qc;
|
2024-08-08 17:14:03 +08:00
|
|
|
|
using ZR.Model.MES.wms;
|
|
|
|
|
|
using ZR.Model.MES.wms.Dto;
|
2024-10-25 19:01:06 +08:00
|
|
|
|
using ZR.Service.mes.qc;
|
2024-08-08 17:14:03 +08:00
|
|
|
|
using ZR.Service.mes.wms.IService;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ZR.Service.mes.wms
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 一次合格品仓库Service业务层处理
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[AppService(
|
|
|
|
|
|
ServiceType = typeof(IWmOneTimeInventoryService),
|
|
|
|
|
|
ServiceLifetime = LifeTime.Transient
|
|
|
|
|
|
)]
|
|
|
|
|
|
public class WmOneTimeInventoryService
|
|
|
|
|
|
: BaseService<WmOneTimeInventory>,
|
|
|
|
|
|
IWmOneTimeInventoryService
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 查询一次合格品仓库列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="parm"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2024-11-18 20:13:49 +08:00
|
|
|
|
public WmOneTimeInventoryTableDto GetList(WmOneTimeInventoryQueryDto parm)
|
2024-08-08 17:14:03 +08:00
|
|
|
|
{
|
2024-11-18 20:13:49 +08:00
|
|
|
|
var list = Context
|
|
|
|
|
|
.Queryable<WmMaterial>()
|
|
|
|
|
|
.LeftJoin<WmOneTimeInventory>((m, p) => m.Partnumber == p.Partnumber)
|
|
|
|
|
|
.Distinct()
|
|
|
|
|
|
.WhereIF(
|
|
|
|
|
|
!string.IsNullOrEmpty(parm.Description),
|
|
|
|
|
|
(m, p) => m.Description.Contains(parm.Description)
|
|
|
|
|
|
)
|
|
|
|
|
|
.WhereIF(
|
|
|
|
|
|
!string.IsNullOrEmpty(parm.Partnumber),
|
|
|
|
|
|
(m, p) => m.Partnumber.Contains(parm.Partnumber)
|
|
|
|
|
|
)
|
|
|
|
|
|
.Where((m, p) => m.Status == 1)
|
|
|
|
|
|
.Where((m, p) => m.Type == 1)
|
2024-11-25 16:34:07 +08:00
|
|
|
|
// .WhereIF(string.IsNullOrEmpty(parm.Partnumber), (m, p) => p.Status == 1)
|
2024-11-18 20:13:49 +08:00
|
|
|
|
.OrderBy((m, p) => m.Description)
|
|
|
|
|
|
.Select(
|
|
|
|
|
|
(m, p) =>
|
|
|
|
|
|
new WmOneTimeInventoryDto
|
|
|
|
|
|
{
|
|
|
|
|
|
RealQuantity = 0,
|
2024-11-25 09:58:29 +08:00
|
|
|
|
Partnumber = m.Partnumber,
|
2024-11-18 20:13:49 +08:00
|
|
|
|
Color = m.Color,
|
|
|
|
|
|
Specification = m.Specification,
|
|
|
|
|
|
Description = m.Description,
|
2024-11-25 09:58:29 +08:00
|
|
|
|
Id = p.Id ?? m.Id,
|
2024-11-18 20:13:49 +08:00
|
|
|
|
BlankNum = p.BlankNum,
|
2024-11-25 09:58:29 +08:00
|
|
|
|
Quantity = p.Quantity ?? 0,
|
2024-11-18 20:13:49 +08:00
|
|
|
|
MaxNum = p.MaxNum,
|
|
|
|
|
|
MinNum = p.MinNum,
|
|
|
|
|
|
WarnNum = p.WarnNum,
|
2024-11-25 09:58:29 +08:00
|
|
|
|
Type = p.Type ?? 1,
|
2024-11-18 20:13:49 +08:00
|
|
|
|
Status = p.Status,
|
|
|
|
|
|
Remark = p.Remark,
|
|
|
|
|
|
CreatedBy = p.CreatedBy,
|
|
|
|
|
|
CreatedTime = p.CreatedTime,
|
|
|
|
|
|
UpdatedBy = p.UpdatedBy,
|
|
|
|
|
|
UpdatedTime = p.UpdatedTime,
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
.ToList();
|
2024-11-25 16:34:07 +08:00
|
|
|
|
if (string.IsNullOrEmpty(parm.Partnumber))
|
|
|
|
|
|
{
|
|
|
|
|
|
// 盘点时间
|
|
|
|
|
|
DateTime? checkTime =
|
|
|
|
|
|
Context
|
|
|
|
|
|
.Queryable<WmOneTimeInventory>()
|
|
|
|
|
|
.Where(it => it.Status == 1)
|
|
|
|
|
|
.Select(it => it.CreatedTime)
|
|
|
|
|
|
.First() ?? new DateTime(2024, 11, 16, 12, 0, 0);
|
|
|
|
|
|
list = list.Where(ls =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ls.Status != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
!string.IsNullOrEmpty(ls.Description) && ls.Description.Contains("倒车雷达")
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool bol1 = Context
|
|
|
|
|
|
.Queryable<QcQualityStatisticsFirst>()
|
|
|
|
|
|
.Where(it => it.FinishedPartNumber == ls.Partnumber)
|
|
|
|
|
|
.Where(it => it.StartTime >= checkTime)
|
|
|
|
|
|
.Any();
|
|
|
|
|
|
bool bol2 = Context
|
|
|
|
|
|
.Queryable<WmPolishWorkQualityStatistics>()
|
|
|
|
|
|
.Where(it => it.Partnumber == ls.Partnumber)
|
|
|
|
|
|
.Where(it => it.StartTime >= checkTime)
|
|
|
|
|
|
.Any();
|
|
|
|
|
|
bool bol3 = Context
|
|
|
|
|
|
.Queryable<WmPolishQualityStatistics>()
|
|
|
|
|
|
.Where(it => it.Partnumber == ls.Partnumber)
|
|
|
|
|
|
.Where(it => it.StartTime >= checkTime)
|
|
|
|
|
|
.Any();
|
|
|
|
|
|
bool bol4 = Context
|
|
|
|
|
|
.Queryable<WmGp12QualityStatistics>()
|
|
|
|
|
|
.Where(it => it.Partnumber == ls.Partnumber)
|
|
|
|
|
|
.Where(it => it.StartTime >= checkTime)
|
|
|
|
|
|
.Any();
|
|
|
|
|
|
if (bol1)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (bol2)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (bol3)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (bol4)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.Where(it => !string.IsNullOrEmpty(it.Partnumber))
|
|
|
|
|
|
.DistinctBy(it => it.Partnumber)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
}
|
2024-11-18 20:13:49 +08:00
|
|
|
|
foreach (WmOneTimeInventoryDto item in list)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 获取实际库存
|
2024-11-25 09:58:29 +08:00
|
|
|
|
List<string> partnumbers = new() { item.Partnumber };
|
2024-11-18 20:13:49 +08:00
|
|
|
|
Dictionary<string, int> dict = GetBatchOneTimeRealPartNum(partnumbers);
|
|
|
|
|
|
item.RealQuantity = dict.TryGetValue(item.Partnumber, out int value) ? value : 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
list = list.Where(it => it.RealQuantity != 0 || it.Quantity != 0)
|
|
|
|
|
|
.Where(it => !string.IsNullOrEmpty(it.Partnumber))
|
|
|
|
|
|
.DistinctBy(it => it.Partnumber)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
int total = list.Count;
|
|
|
|
|
|
// 仓库总盘点零件数
|
|
|
|
|
|
int StocktakingTotal =
|
|
|
|
|
|
Context.Queryable<WmOneTimeInventory>().Sum(it => it.Quantity) ?? 0;
|
|
|
|
|
|
// 仓库当前查询盘点零件数
|
|
|
|
|
|
int QuantitySum = list.Sum(it => it.Quantity) ?? 0;
|
|
|
|
|
|
// 仓库当前查询实际零件数
|
|
|
|
|
|
int RealQuantitySum = list.Sum(it => it.RealQuantity);
|
2024-11-25 09:58:29 +08:00
|
|
|
|
WmOneTimeInventoryTableDto response =
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
Total = total,
|
|
|
|
|
|
StocktakingTotal = StocktakingTotal,
|
|
|
|
|
|
QuantitySum = QuantitySum,
|
|
|
|
|
|
RealQuantitySum = RealQuantitySum,
|
|
|
|
|
|
Result = list.Skip((parm.PageNum - 1) * parm.PageSize)
|
|
|
|
|
|
.Take(parm.PageSize)
|
|
|
|
|
|
.ToList(),
|
|
|
|
|
|
};
|
2024-11-18 20:13:49 +08:00
|
|
|
|
return response;
|
|
|
|
|
|
|
|
|
|
|
|
/*List<string> partnumberByDescription = new();
|
2024-08-08 17:14:03 +08:00
|
|
|
|
if (parm != null && !string.IsNullOrEmpty(parm.Description))
|
|
|
|
|
|
{
|
|
|
|
|
|
partnumberByDescription = Context
|
|
|
|
|
|
.Queryable<WmMaterial>()
|
|
|
|
|
|
.Where(it => it.Description.Contains(parm.Description))
|
|
|
|
|
|
.Select(it => it.Partnumber)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
var predicate = Expressionable
|
|
|
|
|
|
.Create<WmOneTimeInventory>()
|
|
|
|
|
|
.AndIF(
|
|
|
|
|
|
!string.IsNullOrEmpty(parm.Description),
|
|
|
|
|
|
it => partnumberByDescription.Contains(it.Partnumber)
|
|
|
|
|
|
)
|
|
|
|
|
|
.AndIF(
|
|
|
|
|
|
!string.IsNullOrEmpty(parm.Partnumber),
|
|
|
|
|
|
it => it.Partnumber.Contains(parm.Partnumber)
|
|
|
|
|
|
)
|
|
|
|
|
|
.AndIF(parm.Status > -1, it => it.Status == parm.Status)
|
|
|
|
|
|
.AndIF(parm.Type > 0, it => it.Type == parm.Type);
|
|
|
|
|
|
|
|
|
|
|
|
var response = Queryable()
|
|
|
|
|
|
.Where(predicate.ToExpression())
|
2024-11-15 18:51:05 +08:00
|
|
|
|
.OrderByDescending(it => it.Quantity)
|
2024-08-08 17:14:03 +08:00
|
|
|
|
.ToPage<WmOneTimeInventory, WmOneTimeInventoryDto>(parm);
|
|
|
|
|
|
if (response.Result.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (WmOneTimeInventoryDto item in response.Result)
|
|
|
|
|
|
{
|
|
|
|
|
|
WmMaterial material = Context
|
|
|
|
|
|
.Queryable<WmMaterial>()
|
|
|
|
|
|
.Where(it => it.Partnumber == item.Partnumber)
|
|
|
|
|
|
.Where(it => it.Type == 1)
|
|
|
|
|
|
.Where(it => it.Status == 1)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
if (material == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.Description = "此零件号不在物料清单内!";
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
item.Color = material.Color;
|
|
|
|
|
|
item.Specification = material.Specification;
|
|
|
|
|
|
item.Description = !string.IsNullOrEmpty(material.Description)
|
|
|
|
|
|
? material.Description
|
|
|
|
|
|
: material.ProductName;
|
2024-10-29 17:35:32 +08:00
|
|
|
|
|
|
|
|
|
|
// 获取实际库存
|
|
|
|
|
|
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;
|
2024-08-08 17:14:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-11-18 20:13:49 +08:00
|
|
|
|
return response;*/
|
2024-08-08 17:14:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-25 16:27:06 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 查询一次合格品仓库列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="parm"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public WmOneTimeInventoryTableDto GetListNew(WmOneTimeInventoryQueryDto parm)
|
|
|
|
|
|
{
|
|
|
|
|
|
var list = Context
|
|
|
|
|
|
.Queryable<WmMaterial>()
|
|
|
|
|
|
.LeftJoin<WmOneTimeInventory>((m, p) => m.Partnumber == p.Partnumber)
|
|
|
|
|
|
.Distinct()
|
2025-04-15 14:34:04 +08:00
|
|
|
|
.Where((m, p) => !m.Description.Contains("倒车雷达"))
|
|
|
|
|
|
.Where((m, p) => !m.Description.Contains("AH8"))
|
2025-03-25 16:27:06 +08:00
|
|
|
|
.WhereIF(
|
|
|
|
|
|
!string.IsNullOrEmpty(parm.Description),
|
|
|
|
|
|
(m, p) => m.Description.Contains(parm.Description)
|
|
|
|
|
|
)
|
|
|
|
|
|
.WhereIF(
|
|
|
|
|
|
!string.IsNullOrEmpty(parm.Partnumber),
|
|
|
|
|
|
(m, p) => m.Partnumber.Contains(parm.Partnumber)
|
|
|
|
|
|
)
|
|
|
|
|
|
.Where((m, p) => m.Status == 1)
|
|
|
|
|
|
.Where((m, p) => m.Type == 1)
|
|
|
|
|
|
// .WhereIF(string.IsNullOrEmpty(parm.Partnumber), (m, p) => p.Status == 1)
|
|
|
|
|
|
.OrderBy((m, p) => m.Description)
|
|
|
|
|
|
.Select(
|
|
|
|
|
|
(m, p) =>
|
|
|
|
|
|
new WmOneTimeInventoryDto
|
|
|
|
|
|
{
|
|
|
|
|
|
RealQuantity = 0,
|
|
|
|
|
|
Partnumber = m.Partnumber,
|
|
|
|
|
|
Color = m.Color,
|
|
|
|
|
|
Specification = m.Specification,
|
|
|
|
|
|
Description = m.Description,
|
|
|
|
|
|
Id = p.Id ?? m.Id,
|
|
|
|
|
|
BlankNum = p.BlankNum,
|
|
|
|
|
|
Quantity = p.Quantity ?? 0,
|
|
|
|
|
|
MaxNum = p.MaxNum,
|
|
|
|
|
|
MinNum = p.MinNum,
|
|
|
|
|
|
WarnNum = p.WarnNum,
|
|
|
|
|
|
Type = p.Type ?? 1,
|
|
|
|
|
|
Status = p.Status,
|
|
|
|
|
|
Remark = p.Remark,
|
|
|
|
|
|
CreatedBy = p.CreatedBy,
|
|
|
|
|
|
CreatedTime = p.CreatedTime,
|
|
|
|
|
|
UpdatedBy = p.UpdatedBy,
|
|
|
|
|
|
UpdatedTime = p.UpdatedTime,
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
//TODO 取出库存表 WmOneTimeInventory 最小CreatedTime时间
|
2025-04-08 18:26:36 +08:00
|
|
|
|
|
2025-03-25 16:27:06 +08:00
|
|
|
|
DateTime minDateTime =
|
|
|
|
|
|
Context
|
|
|
|
|
|
.Queryable<WmOneTimeInventory>()
|
|
|
|
|
|
.OrderBy(it => it.CreatedTime)
|
|
|
|
|
|
.Select(it => it.CreatedTime)
|
|
|
|
|
|
.First() ?? DateTime.Now;
|
|
|
|
|
|
//TODO 根据时间范围取出所有记录数据
|
|
|
|
|
|
List<WmOneTimeRecord> wmOneTimeRecords = Context
|
|
|
|
|
|
.Queryable<WmOneTimeRecord>()
|
|
|
|
|
|
//.Where(it => it.Code == "自动")
|
|
|
|
|
|
.Where(it => it.ActionTime >= minDateTime)
|
|
|
|
|
|
.ToList();
|
2025-03-24 17:11:05 +08:00
|
|
|
|
foreach (WmOneTimeInventoryDto item in list)
|
2025-03-25 16:27:06 +08:00
|
|
|
|
{
|
2025-04-08 18:26:36 +08:00
|
|
|
|
//TODO 20250408 盘点时间修正(三个时间比对)
|
2025-06-16 11:22:40 +08:00
|
|
|
|
WmOneTimeRecord minCheckRecord = wmOneTimeRecords
|
|
|
|
|
|
.Where(o => o.Partnumber == item.Partnumber && o.ChangeType == 3)
|
|
|
|
|
|
.OrderByDescending(o => o.ActionTime)
|
|
|
|
|
|
.FirstOrDefault();
|
2025-04-08 18:26:36 +08:00
|
|
|
|
DateTime minCheckRecordTime = DateTime.MinValue;
|
|
|
|
|
|
int minCheckRecordQuantity = 0;
|
|
|
|
|
|
if (minCheckRecord != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
minCheckRecordTime = minCheckRecord.ActionTime ?? DateTime.MinValue;
|
|
|
|
|
|
}
|
2025-06-16 11:22:40 +08:00
|
|
|
|
|
2025-04-08 18:26:36 +08:00
|
|
|
|
DateTime minCheckInventoryTime = item.CreatedTime ?? minDateTime;
|
|
|
|
|
|
//TODO 20250408修改 最小盘点时间判断/如有盘点记录,则优先取盘点记录数据
|
|
|
|
|
|
DateTime checkTime =
|
|
|
|
|
|
minCheckRecordTime > minCheckInventoryTime
|
|
|
|
|
|
? minCheckRecordTime
|
|
|
|
|
|
: minCheckInventoryTime;
|
|
|
|
|
|
if (checkTime == minCheckRecordTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
// TODO 20250408 如果最早记录是盘点记录,则取盘点变动数量
|
|
|
|
|
|
minCheckRecordQuantity = minCheckRecord.ChangeQuantity ?? 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
minCheckRecordQuantity = item.Quantity.Value;
|
|
|
|
|
|
}
|
2025-07-28 15:40:59 +08:00
|
|
|
|
// 入库数
|
2025-03-25 16:27:06 +08:00
|
|
|
|
int? runum = wmOneTimeRecords
|
|
|
|
|
|
.Where(o =>
|
2025-04-08 18:26:36 +08:00
|
|
|
|
o.ActionTime >= checkTime
|
2025-03-25 16:27:06 +08:00
|
|
|
|
&& o.Partnumber == item.Partnumber
|
|
|
|
|
|
&& o.ChangeType == 1
|
|
|
|
|
|
)
|
2025-07-28 15:40:59 +08:00
|
|
|
|
.WhereIF(parm.EndTime != null, o => o.ActionTime <= parm.EndTime)
|
2025-03-25 16:27:06 +08:00
|
|
|
|
.Select(o => o.ChangeQuantity)
|
|
|
|
|
|
.Sum();
|
2025-07-28 15:40:59 +08:00
|
|
|
|
// 出库数
|
2025-03-25 16:27:06 +08:00
|
|
|
|
int? chunum = wmOneTimeRecords
|
|
|
|
|
|
.Where(o =>
|
2025-04-08 18:26:36 +08:00
|
|
|
|
o.ActionTime >= checkTime
|
2025-03-25 16:27:06 +08:00
|
|
|
|
&& o.Partnumber == item.Partnumber
|
|
|
|
|
|
&& o.ChangeType == 2
|
|
|
|
|
|
)
|
2025-07-28 15:40:59 +08:00
|
|
|
|
.WhereIF(parm.EndTime != null, o => o.ActionTime <= parm.EndTime)
|
2025-03-25 16:27:06 +08:00
|
|
|
|
.Select(o => o.ChangeQuantity)
|
|
|
|
|
|
.Sum();
|
2025-06-16 11:22:40 +08:00
|
|
|
|
|
2025-04-08 18:26:36 +08:00
|
|
|
|
item.RealQuantity = minCheckRecordQuantity + (runum.Value - chunum.Value);
|
|
|
|
|
|
item.CreatedTime = checkTime;
|
2025-03-25 16:27:06 +08:00
|
|
|
|
}
|
2025-06-16 11:22:40 +08:00
|
|
|
|
list = list.WhereIF(
|
|
|
|
|
|
string.IsNullOrEmpty(parm.Partnumber),
|
|
|
|
|
|
it => it.RealQuantity != 0 || it.Quantity != 0
|
|
|
|
|
|
)
|
2025-03-25 16:27:06 +08:00
|
|
|
|
.Where(it => !string.IsNullOrEmpty(it.Partnumber))
|
|
|
|
|
|
.DistinctBy(it => it.Partnumber)
|
2025-03-24 17:11:05 +08:00
|
|
|
|
.OrderBy(it => it.RealQuantity)
|
2025-03-25 16:27:06 +08:00
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
int total = list.Count;
|
|
|
|
|
|
// 仓库总盘点零件数
|
|
|
|
|
|
int StocktakingTotal =
|
|
|
|
|
|
Context.Queryable<WmOneTimeInventory>().Sum(it => it.Quantity) ?? 0;
|
|
|
|
|
|
// 仓库当前查询盘点零件数
|
|
|
|
|
|
int QuantitySum = list.Sum(it => it.Quantity) ?? 0;
|
|
|
|
|
|
// 仓库当前查询实际零件数
|
|
|
|
|
|
int RealQuantitySum = list.Sum(it => it.RealQuantity);
|
|
|
|
|
|
WmOneTimeInventoryTableDto response =
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
Total = total,
|
|
|
|
|
|
StocktakingTotal = StocktakingTotal,
|
|
|
|
|
|
QuantitySum = QuantitySum,
|
|
|
|
|
|
RealQuantitySum = RealQuantitySum,
|
2025-03-24 17:11:05 +08:00
|
|
|
|
MinStocktakingTime = minDateTime,
|
|
|
|
|
|
Result = list.Skip((parm.PageNum - 1) * parm.PageSize)
|
2025-03-25 16:27:06 +08:00
|
|
|
|
.Take(parm.PageSize)
|
|
|
|
|
|
.ToList(),
|
|
|
|
|
|
};
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取详情
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="Id"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public WmOneTimeInventory GetInfo(string Id)
|
2024-08-08 17:14:03 +08:00
|
|
|
|
{
|
|
|
|
|
|
var response = Queryable().Where(x => x.Id == Id).First();
|
|
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加一次合格品仓库
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public WmOneTimeInventory AddWmOneTimeInventory(WmOneTimeInventory model)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context.Insertable(model).ExecuteReturnEntity();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 修改一次合格品仓库
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int UpdateWmOneTimeInventory(WmOneTimeInventory model)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Update(model, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 新增仓库操作记录
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="fkInventoryId">抛光仓库主键</param>
|
|
|
|
|
|
/// <param name="code">同批功能识别编号</param>
|
|
|
|
|
|
/// <param name="partnumber">零件号</param>
|
|
|
|
|
|
/// <param name="type">类别</param>
|
|
|
|
|
|
/// <param name="changeQuantity">操作数字</param>
|
|
|
|
|
|
/// <param name="remark">备注</param>
|
|
|
|
|
|
/// <param name="createdBy">创建人</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int AddOneTimeRecord(
|
|
|
|
|
|
string fkInventoryId,
|
|
|
|
|
|
string code,
|
|
|
|
|
|
string partnumber,
|
|
|
|
|
|
int type,
|
|
|
|
|
|
int? changeQuantity,
|
|
|
|
|
|
DateTime? actionTime,
|
|
|
|
|
|
string remark,
|
|
|
|
|
|
string createdBy
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
WmOneTimeRecord newOneTimeRecord =
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = SnowFlakeSingle.Instance.NextId().ToString(),
|
|
|
|
|
|
FkInventoryId = fkInventoryId,
|
|
|
|
|
|
Code = code,
|
|
|
|
|
|
Partnumber = partnumber,
|
|
|
|
|
|
BlankNum = "",
|
|
|
|
|
|
ChangeType = type,
|
|
|
|
|
|
ChangeQuantity = changeQuantity ?? 0,
|
|
|
|
|
|
ActionTime = actionTime,
|
|
|
|
|
|
Status = 1,
|
|
|
|
|
|
Remark = remark,
|
|
|
|
|
|
CreatedBy = createdBy,
|
|
|
|
|
|
CreatedTime = DateTime.Now.ToLocalTime(),
|
|
|
|
|
|
UpdatedBy = createdBy,
|
|
|
|
|
|
UpdatedTime = DateTime.Now.ToLocalTime(),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return Context.Insertable(newOneTimeRecord).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int DoWmOneTimeWarehousing(WmOneTimeInventory parm)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.BeginTran();
|
|
|
|
|
|
// 零件号检查
|
|
|
|
|
|
string partnumber = parm.Partnumber;
|
|
|
|
|
|
// 检查是否存在库中
|
|
|
|
|
|
WmOneTimeInventory oneTimeInventory = Context
|
|
|
|
|
|
.Queryable<WmOneTimeInventory>()
|
|
|
|
|
|
.Where(it => it.Partnumber == partnumber)
|
|
|
|
|
|
.Where(it => it.Type == parm.Type)
|
|
|
|
|
|
.Where(it => it.Status == 1)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
if (oneTimeInventory == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 为空则新增库
|
|
|
|
|
|
WmOneTimeInventory newWmOneTimeInventory =
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = SnowFlakeSingle.Instance.NextId().ToString(),
|
|
|
|
|
|
BlankNum = "",
|
|
|
|
|
|
Partnumber = partnumber,
|
|
|
|
|
|
Type = parm.Type,
|
|
|
|
|
|
Quantity = parm.Quantity,
|
|
|
|
|
|
MaxNum = 0,
|
|
|
|
|
|
MinNum = 0,
|
|
|
|
|
|
WarnNum = 0,
|
|
|
|
|
|
Status = 1,
|
|
|
|
|
|
Remark = "系统自动创建库",
|
|
|
|
|
|
CreatedBy = parm.CreatedBy,
|
|
|
|
|
|
CreatedTime = DateTime.Now.ToLocalTime(),
|
|
|
|
|
|
UpdatedBy = parm.CreatedBy,
|
|
|
|
|
|
UpdatedTime = DateTime.Now.ToLocalTime(),
|
|
|
|
|
|
};
|
|
|
|
|
|
WmOneTimeInventory addWmOneTimeInventory = Context
|
|
|
|
|
|
.Insertable(newWmOneTimeInventory)
|
|
|
|
|
|
.ExecuteReturnEntity();
|
|
|
|
|
|
string code = !string.IsNullOrEmpty(parm.WorkOrder)
|
|
|
|
|
|
? parm.WorkOrder
|
|
|
|
|
|
: SnowFlakeSingle.Instance.NextId().ToString();
|
|
|
|
|
|
string remark = "初次创建仓库,新增入库数据 " + parm.Remark;
|
|
|
|
|
|
int successNum = AddOneTimeRecord(
|
|
|
|
|
|
addWmOneTimeInventory.Id,
|
|
|
|
|
|
code,
|
|
|
|
|
|
partnumber,
|
|
|
|
|
|
1,
|
|
|
|
|
|
parm.Quantity,
|
|
|
|
|
|
parm.ActionTime,
|
|
|
|
|
|
remark,
|
|
|
|
|
|
parm.CreatedBy
|
|
|
|
|
|
);
|
|
|
|
|
|
if (successNum == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
|
throw new Exception("入库日志添加失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
oneTimeInventory.Quantity += parm.Quantity;
|
|
|
|
|
|
int updateNum = Context.Updateable(oneTimeInventory).ExecuteCommand();
|
|
|
|
|
|
if (updateNum == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
|
throw new Exception("修改一次合格仓库数据失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
// 已有则新增记录
|
|
|
|
|
|
string code = !string.IsNullOrEmpty(parm.WorkOrder)
|
|
|
|
|
|
? parm.WorkOrder
|
|
|
|
|
|
: SnowFlakeSingle.Instance.NextId().ToString();
|
|
|
|
|
|
int successNum = AddOneTimeRecord(
|
|
|
|
|
|
oneTimeInventory.Id,
|
|
|
|
|
|
code,
|
|
|
|
|
|
partnumber,
|
|
|
|
|
|
1,
|
|
|
|
|
|
parm.Quantity,
|
|
|
|
|
|
parm.ActionTime,
|
|
|
|
|
|
parm.Remark,
|
|
|
|
|
|
parm.CreatedBy
|
|
|
|
|
|
);
|
|
|
|
|
|
if (successNum == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
|
throw new Exception("入库日志添加失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Context.Ado.CommitTran();
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
|
throw new Exception(e.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int DoWmOneTimeRetrieval(WmOneTimeInventory parm)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.BeginTran();
|
|
|
|
|
|
// 零件号检查
|
|
|
|
|
|
string partnumber = parm.Partnumber;
|
|
|
|
|
|
// 检查是否存在库中
|
|
|
|
|
|
WmOneTimeInventory oneTimeInventory = Context
|
|
|
|
|
|
.Queryable<WmOneTimeInventory>()
|
|
|
|
|
|
.Where(it => it.Partnumber == partnumber)
|
|
|
|
|
|
.Where(it => it.Type == parm.Type)
|
|
|
|
|
|
.Where(it => it.Status == 1)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
if (oneTimeInventory == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 为空则新增库
|
|
|
|
|
|
WmOneTimeInventory newWmOneTimeInventory =
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = SnowFlakeSingle.Instance.NextId().ToString(),
|
|
|
|
|
|
BlankNum = "",
|
|
|
|
|
|
Partnumber = partnumber,
|
|
|
|
|
|
Type = parm.Type,
|
|
|
|
|
|
Quantity = parm.Quantity * -1,
|
|
|
|
|
|
MaxNum = 0,
|
|
|
|
|
|
MinNum = 0,
|
|
|
|
|
|
WarnNum = 0,
|
|
|
|
|
|
Status = 1,
|
|
|
|
|
|
Remark = "系统自动创建库",
|
|
|
|
|
|
CreatedBy = parm.CreatedBy,
|
|
|
|
|
|
CreatedTime = DateTime.Now.ToLocalTime(),
|
|
|
|
|
|
UpdatedBy = parm.CreatedBy,
|
|
|
|
|
|
UpdatedTime = DateTime.Now.ToLocalTime(),
|
|
|
|
|
|
};
|
|
|
|
|
|
WmOneTimeInventory addWmOneTimeInventory = Context
|
|
|
|
|
|
.Insertable(newWmOneTimeInventory)
|
|
|
|
|
|
.ExecuteReturnEntity();
|
|
|
|
|
|
string code = !string.IsNullOrEmpty(parm.WorkOrder)
|
|
|
|
|
|
? parm.WorkOrder
|
|
|
|
|
|
: SnowFlakeSingle.Instance.NextId().ToString();
|
|
|
|
|
|
string remark = "初次创建仓库,新增手动出库数据" + parm.Remark;
|
|
|
|
|
|
int successNum = AddOneTimeRecord(
|
|
|
|
|
|
addWmOneTimeInventory.Id,
|
|
|
|
|
|
code,
|
|
|
|
|
|
partnumber,
|
|
|
|
|
|
2,
|
|
|
|
|
|
parm.Quantity,
|
|
|
|
|
|
parm.ActionTime,
|
|
|
|
|
|
remark,
|
|
|
|
|
|
parm.CreatedBy
|
|
|
|
|
|
);
|
|
|
|
|
|
if (successNum == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
|
throw new Exception("出库日志添加失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
oneTimeInventory.Quantity -= parm.Quantity;
|
|
|
|
|
|
int updateNum = Context.Updateable(oneTimeInventory).ExecuteCommand();
|
|
|
|
|
|
if (updateNum == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
|
throw new Exception("修改一次合格仓库零件数失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
// 已有则新增记录
|
|
|
|
|
|
string code = !string.IsNullOrEmpty(parm.WorkOrder)
|
|
|
|
|
|
? parm.WorkOrder
|
|
|
|
|
|
: SnowFlakeSingle.Instance.NextId().ToString();
|
|
|
|
|
|
int successNum = AddOneTimeRecord(
|
|
|
|
|
|
oneTimeInventory.Id,
|
|
|
|
|
|
code,
|
|
|
|
|
|
partnumber,
|
|
|
|
|
|
2,
|
|
|
|
|
|
parm.Quantity,
|
|
|
|
|
|
parm.ActionTime,
|
|
|
|
|
|
parm.Remark,
|
|
|
|
|
|
parm.CreatedBy
|
|
|
|
|
|
);
|
|
|
|
|
|
if (successNum == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
|
throw new Exception("出库日志添加失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Context.Ado.CommitTran();
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
|
throw new Exception(e.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-08 18:26:36 +08:00
|
|
|
|
// 盘点
|
2024-08-08 17:14:03 +08:00
|
|
|
|
public int DoWmOneTimeStocktaking(WmOneTimeInventory parm)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (parm.Quantity < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("修改的零件数小于0");
|
|
|
|
|
|
}
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.BeginTran();
|
|
|
|
|
|
// 检查是否存在库中
|
2025-06-16 11:22:40 +08:00
|
|
|
|
/* WmOneTimeInventory oneTImeInventory = Context
|
|
|
|
|
|
.Queryable<WmOneTimeInventory>()
|
|
|
|
|
|
.Where(it => it.Id == parm.Id)
|
|
|
|
|
|
.Where(it => it.Status == 1)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
if (oneTImeInventory == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
|
throw new Exception("盘点记录不存在" + parm.Id);
|
|
|
|
|
|
}
|
|
|
|
|
|
Context.Updateable(parm).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();*/
|
2024-08-08 17:14:03 +08:00
|
|
|
|
// 已有则新增记录
|
2025-04-08 18:26:36 +08:00
|
|
|
|
//TODO 20250408 新逻辑调整 只添加盘点记录 算库存数时自动调整
|
2024-08-08 17:14:03 +08:00
|
|
|
|
string code = !string.IsNullOrEmpty(parm.WorkOrder)
|
|
|
|
|
|
? parm.WorkOrder
|
|
|
|
|
|
: SnowFlakeSingle.Instance.NextId().ToString();
|
|
|
|
|
|
int successNum = AddOneTimeRecord(
|
|
|
|
|
|
parm.Id,
|
|
|
|
|
|
code,
|
|
|
|
|
|
parm.Partnumber,
|
|
|
|
|
|
3,
|
|
|
|
|
|
parm.Quantity,
|
2025-04-08 18:26:36 +08:00
|
|
|
|
parm.ActionTime ?? DateTime.Now,
|
2024-08-08 17:14:03 +08:00
|
|
|
|
parm.Remark,
|
|
|
|
|
|
parm.CreatedBy
|
|
|
|
|
|
);
|
|
|
|
|
|
if (successNum == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
|
throw new Exception("盘点日志添加失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
Context.Ado.CommitTran();
|
|
|
|
|
|
return successNum;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
|
throw new Exception(e.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-08-22 10:43:05 +08:00
|
|
|
|
|
|
|
|
|
|
// 获取仓库零件数量
|
|
|
|
|
|
public int GetPartNumber()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context
|
|
|
|
|
|
.Queryable<WmOneTimeInventory>()
|
|
|
|
|
|
.Where(it => it.Status == 1)
|
|
|
|
|
|
.Sum(it => it.Quantity) ?? 0;
|
|
|
|
|
|
}
|
2024-10-25 19:01:06 +08:00
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
}
|
2025-06-16 11:22:40 +08:00
|
|
|
|
|
2025-04-08 18:26:36 +08:00
|
|
|
|
//导出
|
2024-10-25 19:01:06 +08:00
|
|
|
|
public List<WmOneTimeInventoryExportDto> GetExportList(WmOneTimeInventoryQueryDto parm)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2025-04-08 18:26:36 +08:00
|
|
|
|
/* List<WmMaterial> materials = GetWmMaterialList(parm.Partnumber);
|
2024-10-25 19:01:06 +08:00
|
|
|
|
|
2025-04-08 18:26:36 +08:00
|
|
|
|
// 获取所有partnumber列表
|
|
|
|
|
|
List<string> partnumbers = materials
|
|
|
|
|
|
.Where(it => !string.IsNullOrEmpty(it.Partnumber))
|
|
|
|
|
|
.Select(it => it.Partnumber)
|
|
|
|
|
|
.Distinct()
|
|
|
|
|
|
.ToList();
|
2024-10-25 19:01:06 +08:00
|
|
|
|
|
2025-04-08 18:26:36 +08:00
|
|
|
|
// 批量获取盘点数和现有库存
|
|
|
|
|
|
Dictionary<string, object> stockNumbers = GetBatchOneTimeStockPartNum(partnumbers);
|
|
|
|
|
|
Dictionary<string, int> realNumbers = GetBatchOneTimeRealPartNum(partnumbers);*/
|
2024-10-25 19:01:06 +08:00
|
|
|
|
|
2024-11-15 18:51:05 +08:00
|
|
|
|
// 更新盘点时间
|
2025-04-08 18:26:36 +08:00
|
|
|
|
/*DateTime dateTime = DateTime.Now.ToLocalTime();*/
|
|
|
|
|
|
|
|
|
|
|
|
//TODO 20250408 新导出逻辑
|
2024-11-15 18:51:05 +08:00
|
|
|
|
|
2024-10-25 19:01:06 +08:00
|
|
|
|
// 构建导出数据
|
2025-06-16 11:22:40 +08:00
|
|
|
|
WmOneTimeInventoryQueryDto queryParams = new() { PageSize = 10000, PageNum = 1 };
|
|
|
|
|
|
List<WmOneTimeInventoryExportDto> exportDto = GetListNew(queryParams)
|
|
|
|
|
|
.Result.Select(it =>
|
2024-10-25 19:01:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
return new WmOneTimeInventoryExportDto
|
|
|
|
|
|
{
|
|
|
|
|
|
零件号 = it.Partnumber,
|
|
|
|
|
|
颜色 = it.Color,
|
|
|
|
|
|
规格 = it.Specification,
|
|
|
|
|
|
描述 = it.Description,
|
2025-04-08 18:26:36 +08:00
|
|
|
|
盘点数 = it.Quantity ?? 0,
|
|
|
|
|
|
现有库存 = it.RealQuantity,
|
|
|
|
|
|
盘点时间 = it.CreatedTime,
|
2024-10-25 19:01:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
})
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
return exportDto;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Util 获取指定抛光库零件盘点库存
|
|
|
|
|
|
public Dictionary<string, object> GetBatchOneTimeStockPartNum(List<string> partnumbers)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context
|
|
|
|
|
|
.Queryable<WmOneTimeInventory>()
|
|
|
|
|
|
.Where(it => partnumbers.Contains(it.Partnumber))
|
|
|
|
|
|
.GroupBy(it => it.Partnumber)
|
|
|
|
|
|
.ToDictionary(g => g.Partnumber, g => SqlFunc.AggregateSum(g.Quantity) ?? 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-29 17:35:32 +08:00
|
|
|
|
// Util 获取指定一次合格库零件加报表后库存
|
2024-10-25 19:01:06 +08:00
|
|
|
|
public Dictionary<string, int> GetBatchOneTimeRealPartNum(List<string> partnumbers)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// 盘点时间
|
2024-11-18 20:13:49 +08:00
|
|
|
|
DateTime? checkTime =
|
|
|
|
|
|
Context
|
|
|
|
|
|
.Queryable<WmOneTimeInventory>()
|
|
|
|
|
|
.Where(it => it.Status == 1)
|
|
|
|
|
|
.Select(it => it.CreatedTime)
|
2024-11-20 16:35:02 +08:00
|
|
|
|
.First() ?? new DateTime(2024, 11, 16, 12, 0, 0);
|
2024-11-18 20:13:49 +08:00
|
|
|
|
// DateTime
|
2024-10-25 19:01:06 +08:00
|
|
|
|
CommonFQCService commonFQCService = new();
|
2025-03-25 16:27:06 +08:00
|
|
|
|
// 获取报表数据
|
|
|
|
|
|
// 一次合格计算后库存 = 盘点库存 + 产线合格 + 抛光合格 - gp12投入 - 后道直接出库
|
|
|
|
|
|
//return commonFQCService.GetBatchOneTimePartRealStock(partnumbers, checkTime.Value);
|
|
|
|
|
|
return commonFQCService.GetBatchOneTimePartRealStockNew(
|
|
|
|
|
|
partnumbers,
|
|
|
|
|
|
checkTime.Value
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2024-10-25 19:01:06 +08:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-11-15 18:51:05 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 导入数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="importData"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public (string, object, object) ImportExcel(List<WmOneTimeInventoryExportDto> importList)
|
|
|
|
|
|
{
|
2024-11-18 20:13:49 +08:00
|
|
|
|
List<WmOneTimeInventory> wmOneTimeInventorylist = importList
|
|
|
|
|
|
.Select(it => new WmOneTimeInventory
|
|
|
|
|
|
{
|
|
|
|
|
|
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(wmOneTimeInventorylist)
|
2024-11-15 18:51:05 +08:00
|
|
|
|
.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) // 其余插入
|
2024-11-18 20:13:49 +08:00
|
|
|
|
.WhereColumns(it => it.Partnumber) //如果不是主键可以这样实现(多字段it=>new{it.x1,it.x2})
|
2024-11-15 18:51:05 +08:00
|
|
|
|
.ToStorage();
|
|
|
|
|
|
|
|
|
|
|
|
// 清空全部
|
2024-11-18 20:13:49 +08:00
|
|
|
|
var result = x.AsInsertable.ExecuteCommand(); //不存在则插入;
|
|
|
|
|
|
var result2 = x.AsUpdateable.IgnoreColumns(it => new { it.Id }).ExecuteCommand(); //存在则修改;
|
2024-11-15 18:51:05 +08:00
|
|
|
|
var result3 = x.AsDeleteable.ExecuteCommand(); //盘点数为0的删除;
|
2024-11-18 20:13:49 +08:00
|
|
|
|
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
|
|
|
|
|
|
);
|
|
|
|
|
|
//输出统计
|
2024-11-15 18:51:05 +08:00
|
|
|
|
Console.WriteLine(msg);
|
|
|
|
|
|
|
2024-11-18 20:13:49 +08:00
|
|
|
|
//输出错误信息
|
2024-11-15 18:51:05 +08:00
|
|
|
|
foreach (var item in x.ErrorList)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("零件异常:" + item.Item.Partnumber + " : " + item.StorageMessage);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (msg, x.ErrorList, x.IgnoreList);
|
|
|
|
|
|
}
|
2025-03-25 16:27:06 +08:00
|
|
|
|
|
|
|
|
|
|
public List<ErrorCheckTableDto> CheckErrorTable()
|
|
|
|
|
|
{
|
|
|
|
|
|
List<ErrorCheckTableDto> errorCheckTableDtos = new List<ErrorCheckTableDto>();
|
|
|
|
|
|
|
|
|
|
|
|
// 盘点数据的零件号与物料内零件号不匹配异常进行检查
|
|
|
|
|
|
// 获取物料列表并将零件号提取到 HashSet 中以进行快速查找
|
|
|
|
|
|
HashSet<string> materialPartnumbers =
|
|
|
|
|
|
new(GetWmMaterialList("").Select(m => m.Partnumber));
|
|
|
|
|
|
List<WmOneTimeInventory> oneTimeInventoryList = Context
|
|
|
|
|
|
.Queryable<WmOneTimeInventory>()
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
List<WmPolishInventory> polishInventoryList = Context
|
|
|
|
|
|
.Queryable<WmPolishInventory>()
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
foreach (var inventoryItem in oneTimeInventoryList)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!materialPartnumbers.Contains(inventoryItem.Partnumber))
|
|
|
|
|
|
{
|
|
|
|
|
|
errorCheckTableDtos.Add(
|
|
|
|
|
|
new ErrorCheckTableDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "零件号不存在",
|
|
|
|
|
|
Partnumber = inventoryItem.Partnumber,
|
|
|
|
|
|
Description = "该零件号在物料列表中不存在。",
|
|
|
|
|
|
ErrorMessage = "检测到【一次合格盘点记录】中的零件号不匹配。",
|
|
|
|
|
|
CheckTime = DateTime.Now
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach (var inventoryItem in polishInventoryList)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!materialPartnumbers.Contains(inventoryItem.Partnumber))
|
|
|
|
|
|
{
|
|
|
|
|
|
errorCheckTableDtos.Add(
|
|
|
|
|
|
new ErrorCheckTableDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "零件号不存在",
|
|
|
|
|
|
Partnumber = inventoryItem.Partnumber,
|
|
|
|
|
|
Description = "该零件号在物料列表中不存在。",
|
|
|
|
|
|
ErrorMessage = "检测到【抛光品盘点记录】中的零件号不匹配。",
|
|
|
|
|
|
CheckTime = DateTime.Now
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DateTime minOneTimeStocktakingTime =
|
|
|
|
|
|
oneTimeInventoryList.Min(x => x.CreatedTime) ?? DateTime.Now;
|
|
|
|
|
|
DateTime minPolishStocktakingTime =
|
|
|
|
|
|
polishInventoryList.Min(x => x.CreatedTime) ?? DateTime.Now;
|
|
|
|
|
|
|
|
|
|
|
|
List<WmOneTimeRecord> oneTimeRecordList = Context
|
|
|
|
|
|
.Queryable<WmOneTimeRecord>()
|
|
|
|
|
|
.Where(it => it.ActionTime >= minOneTimeStocktakingTime)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
List<WmPolishRecord> polishRecordList = Context
|
|
|
|
|
|
.Queryable<WmPolishRecord>()
|
|
|
|
|
|
.Where(it => it.ActionTime >= minPolishStocktakingTime)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var recordItem in oneTimeRecordList)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!materialPartnumbers.Contains(recordItem.Partnumber))
|
|
|
|
|
|
{
|
|
|
|
|
|
errorCheckTableDtos.Add(
|
|
|
|
|
|
new ErrorCheckTableDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "零件号不存在",
|
|
|
|
|
|
Partnumber = recordItem.Partnumber,
|
|
|
|
|
|
Description = "该零件号在物料列表中不存在。",
|
|
|
|
|
|
ErrorMessage = "检测到【一次合格品报表】中的零件号不匹配。记录时间:" + recordItem.ActionTime,
|
|
|
|
|
|
CheckTime = DateTime.Now
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var recordItem in polishRecordList)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!materialPartnumbers.Contains(recordItem.Partnumber))
|
|
|
|
|
|
{
|
|
|
|
|
|
errorCheckTableDtos.Add(
|
|
|
|
|
|
new ErrorCheckTableDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "零件号不存在",
|
|
|
|
|
|
Partnumber = recordItem.Partnumber,
|
|
|
|
|
|
Description = "该零件号在物料列表中不存在。",
|
|
|
|
|
|
ErrorMessage = "检测到【抛光品报表】中的零件号不匹配。记录时间:" + recordItem.ActionTime,
|
|
|
|
|
|
CheckTime = DateTime.Now
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//TODO 判断oneTimeRecordList中是否存在oneTimeInventoryList没有的零件号
|
|
|
|
|
|
// 提取 oneTimeInventoryList 中的所有零件号
|
2025-04-08 18:26:36 +08:00
|
|
|
|
HashSet<string> oneTimeInventoryPartnumbers = new HashSet<string>(
|
|
|
|
|
|
oneTimeInventoryList.Select(i => i.Partnumber)
|
|
|
|
|
|
);
|
2025-03-25 16:27:06 +08:00
|
|
|
|
foreach (var recordItem in oneTimeRecordList)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!oneTimeInventoryPartnumbers.Contains(recordItem.Partnumber))
|
|
|
|
|
|
{
|
|
|
|
|
|
errorCheckTableDtos.Add(
|
|
|
|
|
|
new ErrorCheckTableDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "该零件号记录丢失",
|
|
|
|
|
|
Partnumber = recordItem.Partnumber,
|
|
|
|
|
|
Description = "该零件号与盘点数据不匹配。请确认情况,是否未盘点到!",
|
2025-04-08 18:26:36 +08:00
|
|
|
|
ErrorMessage =
|
|
|
|
|
|
$"检测到【一次合格品记录】中的零件号在盘点清单中不存在。记录时间: {recordItem.ActionTime}",
|
2025-03-25 16:27:06 +08:00
|
|
|
|
CheckTime = DateTime.Now
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//TODO 判断polishRecordList中是否存在polishInventoryList没有的零件号
|
2025-04-08 18:26:36 +08:00
|
|
|
|
HashSet<string> polishInventoryPartnumbers = new HashSet<string>(
|
|
|
|
|
|
polishInventoryList.Select(i => i.Partnumber)
|
|
|
|
|
|
);
|
2025-03-25 16:27:06 +08:00
|
|
|
|
foreach (var recordItem in polishRecordList)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!polishInventoryPartnumbers.Contains(recordItem.Partnumber))
|
|
|
|
|
|
{
|
|
|
|
|
|
errorCheckTableDtos.Add(
|
|
|
|
|
|
new ErrorCheckTableDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "该零件号记录丢失",
|
|
|
|
|
|
Partnumber = recordItem.Partnumber,
|
|
|
|
|
|
Description = "该零件号与盘点数据不匹配。请确认情况,是否未盘点到!",
|
2025-04-08 18:26:36 +08:00
|
|
|
|
ErrorMessage =
|
|
|
|
|
|
$"检测到【抛光品记录】中的零件号在盘点清单中不存在。记录时间: {recordItem.ActionTime}",
|
2025-03-25 16:27:06 +08:00
|
|
|
|
CheckTime = DateTime.Now
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return errorCheckTableDtos;
|
|
|
|
|
|
}
|
2024-08-08 17:14:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|