2024-06-07 11:04:26 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
2024-07-11 10:41:17 +08:00
|
|
|
|
using Infrastructure.Attribute;
|
|
|
|
|
|
using JinianNet.JNTemplate;
|
|
|
|
|
|
using SqlSugar;
|
2024-05-13 17:32:20 +08:00
|
|
|
|
using ZR.Model;
|
|
|
|
|
|
using ZR.Model.MES.wms;
|
2024-06-07 11:04:26 +08:00
|
|
|
|
using ZR.Model.MES.wms.Dto;
|
2024-05-13 17:32:20 +08:00
|
|
|
|
using ZR.Repository;
|
|
|
|
|
|
using ZR.Service.mes.wms.IService;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ZR.Service.mes.wms
|
|
|
|
|
|
{
|
2025-03-28 17:29:12 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 毛坯库存表Service业务层处理
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[AppService(
|
|
|
|
|
|
ServiceType = typeof(IWmBlankInventoryService),
|
|
|
|
|
|
ServiceLifetime = LifeTime.Transient
|
|
|
|
|
|
)]
|
|
|
|
|
|
public class WmBlankInventoryService : BaseService<WmBlankInventory>, IWmBlankInventoryService
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 查询毛坯库存表列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="parm"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public PagedInfo<WmBlankInventoryDto> GetList(WmBlankInventoryQueryDto parm)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<string> blankNums = Context
|
|
|
|
|
|
.Queryable<WmMaterial>()
|
|
|
|
|
|
.Where(it => it.Type == 2)
|
|
|
|
|
|
.Where(it => it.Status == 1).WhereIF(!string.IsNullOrEmpty(parm.Description), it => it.Description.Contains(parm.Description) || it.ProductName.Contains(parm.Description)).Select(o => o.BlankNum).ToList();
|
2024-05-13 17:32:20 +08:00
|
|
|
|
|
2025-03-28 17:29:12 +08:00
|
|
|
|
var predicate = Expressionable
|
|
|
|
|
|
.Create<WmBlankInventory>()
|
|
|
|
|
|
.AndIF(
|
|
|
|
|
|
!string.IsNullOrEmpty(parm.BlankNum),
|
|
|
|
|
|
it => it.BlankNum.Contains(parm.BlankNum)
|
|
|
|
|
|
)
|
|
|
|
|
|
.AndIF(
|
|
|
|
|
|
!string.IsNullOrEmpty(parm.Description),
|
|
|
|
|
|
it => blankNums.Contains(it.BlankNum)
|
|
|
|
|
|
)
|
|
|
|
|
|
.AndIF(parm.Status > -1, it => it.Status == parm.Status)
|
|
|
|
|
|
.AndIF(parm.Type > 0, it => it.Type == parm.Type);
|
2024-05-13 17:32:20 +08:00
|
|
|
|
|
2025-03-28 17:29:12 +08:00
|
|
|
|
var response = Queryable()
|
|
|
|
|
|
.Where(predicate.ToExpression())
|
2024-05-13 17:32:20 +08:00
|
|
|
|
|
2025-03-28 17:29:12 +08:00
|
|
|
|
.OrderByDescending(it => it.UpdatedTime)
|
|
|
|
|
|
.ToPage<WmBlankInventory, WmBlankInventoryDto>(parm);
|
|
|
|
|
|
if (response.Result.Count > 0)
|
|
|
|
|
|
{
|
2024-05-13 17:32:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-03-28 17:29:12 +08:00
|
|
|
|
foreach (WmBlankInventoryDto item in response.Result)
|
|
|
|
|
|
{
|
|
|
|
|
|
WmMaterial material = Context
|
|
|
|
|
|
.Queryable<WmMaterial>()
|
|
|
|
|
|
.Where(it => it.BlankNum == item.BlankNum)
|
|
|
|
|
|
.Where(it => it.Type == 2)
|
|
|
|
|
|
.Where(it => it.Status == 1)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
if (material == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.Description = "此毛坯号不在物料清单内!";
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
item.Color = material.Color;
|
|
|
|
|
|
item.Unit = material.Unit;
|
|
|
|
|
|
item.Version = material.Version;
|
|
|
|
|
|
item.Specification = material.Specification;
|
|
|
|
|
|
item.Description = !string.IsNullOrEmpty(material.Description)
|
|
|
|
|
|
? material.Description
|
|
|
|
|
|
: material.ProductName;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
2024-05-13 17:32:20 +08:00
|
|
|
|
|
2025-03-28 17:29:12 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取详情
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="Id"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public WmBlankInventory GetInfo(string Id)
|
|
|
|
|
|
{
|
|
|
|
|
|
var response = Queryable().Where(x => x.Id == Id).First();
|
2024-07-11 10:41:17 +08:00
|
|
|
|
|
2025-03-28 17:29:12 +08:00
|
|
|
|
return response;
|
|
|
|
|
|
}
|
2024-05-14 10:16:18 +08:00
|
|
|
|
|
2025-03-28 17:29:12 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加毛坯库存表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public WmBlankInventory AddWmBlankInventory(WmBlankInventory model)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool hasRecord = Context
|
|
|
|
|
|
.Queryable<WmBlankInventory>()
|
|
|
|
|
|
.Where(it => it.BlankNum == model.BlankNum)
|
|
|
|
|
|
.Where(it => it.Type == model.Type)
|
|
|
|
|
|
.Any();
|
|
|
|
|
|
if (hasRecord)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("毛坯仓库已有相同类别的毛坯号记录");
|
|
|
|
|
|
}
|
|
|
|
|
|
model.Id = SnowFlakeSingle.Instance.NextId().ToString();
|
|
|
|
|
|
return Context.Insertable(model).ExecuteReturnEntity();
|
|
|
|
|
|
}
|
2024-08-22 10:43:05 +08:00
|
|
|
|
|
2025-03-28 17:29:12 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 修改毛坯库存表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int UpdateWmBlankInventory(WmBlankInventory model)
|
|
|
|
|
|
{
|
|
|
|
|
|
//var response = Update(w => w.Id == model.Id, it => new WmBlankInventory()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// BlankNum = model.BlankNum,
|
|
|
|
|
|
// Quantity = model.Quantity,
|
|
|
|
|
|
// MaxNum = model.MaxNum,
|
|
|
|
|
|
// MinNum = model.MinNum,
|
|
|
|
|
|
// WarnNum = model.WarnNum,
|
|
|
|
|
|
// Type = model.Type,
|
|
|
|
|
|
// Status = model.Status,
|
|
|
|
|
|
// Remark = model.Remark,
|
|
|
|
|
|
// CreatedBy = model.CreatedBy,
|
|
|
|
|
|
// CreatedTime = model.CreatedTime,
|
|
|
|
|
|
// UpdatedBy = model.UpdatedBy,
|
|
|
|
|
|
// UpdatedTime = model.UpdatedTime,
|
|
|
|
|
|
//});
|
|
|
|
|
|
//return response;
|
|
|
|
|
|
return Update(model, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int SynchronousMaterial(WmBlankInventory parm)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
int num = 0;
|
|
|
|
|
|
List<WmMaterial> materials = Context
|
|
|
|
|
|
.Queryable<WmMaterial>()
|
|
|
|
|
|
.Where(it => it.Type == 2)
|
|
|
|
|
|
.Where(it => !string.IsNullOrEmpty(it.BlankNum))
|
|
|
|
|
|
.OrderBy(it => it.BlankNum)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
var uniqueBlankNums = materials.Select(m => m.BlankNum).Distinct().ToList();
|
|
|
|
|
|
var wmBlankInventories = Context
|
|
|
|
|
|
.Queryable<WmBlankInventory>()
|
|
|
|
|
|
.Where(it => uniqueBlankNums.Contains(it.BlankNum))
|
|
|
|
|
|
.ToList()
|
|
|
|
|
|
.GroupBy(it => it.BlankNum)
|
|
|
|
|
|
.ToDictionary(g => g.Key, g => g.FirstOrDefault());
|
|
|
|
|
|
foreach (WmMaterial item in materials)
|
|
|
|
|
|
{
|
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
if (
|
|
|
|
|
|
!wmBlankInventories.TryGetValue(item.BlankNum, out WmBlankInventory wmBlank)
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 没有找到匹配的BlankNum,添加两种类型的库存
|
|
|
|
|
|
result += AddBlankInventory(
|
|
|
|
|
|
item.BlankNum,
|
|
|
|
|
|
1,
|
|
|
|
|
|
parm.CreatedBy,
|
|
|
|
|
|
parm.CreatedTime
|
|
|
|
|
|
);
|
|
|
|
|
|
result += AddBlankInventory(
|
|
|
|
|
|
item.BlankNum,
|
|
|
|
|
|
2,
|
|
|
|
|
|
parm.CreatedBy,
|
|
|
|
|
|
parm.CreatedTime
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 找到了匹配的BlankNum,根据Type添加库存
|
|
|
|
|
|
if (wmBlank.Type == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
result = AddBlankInventory(
|
|
|
|
|
|
item.BlankNum,
|
|
|
|
|
|
2,
|
|
|
|
|
|
parm.CreatedBy,
|
|
|
|
|
|
parm.CreatedTime
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
result = AddBlankInventory(
|
|
|
|
|
|
item.BlankNum,
|
|
|
|
|
|
1,
|
|
|
|
|
|
parm.CreatedBy,
|
|
|
|
|
|
parm.CreatedTime
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (result > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
num++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return num;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("同步异常:" + ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 自动添加毛坯库存记录
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="blankNum"></param>
|
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int AddBlankInventory(
|
|
|
|
|
|
string blankNum,
|
|
|
|
|
|
int type,
|
|
|
|
|
|
string createBy = "",
|
|
|
|
|
|
DateTime? createTime = null
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool hasRecord = Context
|
|
|
|
|
|
.Queryable<WmBlankInventory>()
|
|
|
|
|
|
.Where(it => it.BlankNum == blankNum)
|
|
|
|
|
|
.Where(it => it.Type == type)
|
|
|
|
|
|
.Any();
|
|
|
|
|
|
if (hasRecord)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
WmBlankInventory wmBlank =
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = SnowFlakeSingle.Instance.NextId().ToString(),
|
|
|
|
|
|
FkPaintId = string.Empty,
|
|
|
|
|
|
BlankNum = blankNum,
|
|
|
|
|
|
Quantity = 0,
|
|
|
|
|
|
MaxNum = 0,
|
|
|
|
|
|
MinNum = 0,
|
|
|
|
|
|
WarnNum = 0,
|
|
|
|
|
|
Type = type,
|
|
|
|
|
|
Status = 1,
|
|
|
|
|
|
Remark = string.Empty,
|
|
|
|
|
|
CreatedBy = createBy,
|
|
|
|
|
|
CreatedTime = createTime,
|
|
|
|
|
|
UpdatedBy = createBy,
|
|
|
|
|
|
UpdatedTime = createTime,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return Context.Insertable(wmBlank).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取毛坯仓库零件数量
|
|
|
|
|
|
public int GetPartNumber()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context
|
|
|
|
|
|
.Queryable<WmBlankInventory>()
|
|
|
|
|
|
.Where(it => it.Status == 1)
|
|
|
|
|
|
.Sum(it => it.Quantity) ?? 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-07-11 10:41:17 +08:00
|
|
|
|
}
|