463 lines
18 KiB
C#
463 lines
18 KiB
C#
using System;
|
||
using System.Linq;
|
||
using Infrastructure.Attribute;
|
||
using SqlSugar;
|
||
using ZR.Model;
|
||
using ZR.Model.MES.wms;
|
||
using ZR.Model.MES.wms.Dto;
|
||
using ZR.Repository;
|
||
using ZR.Service.mes.wms.IService;
|
||
|
||
namespace ZR.Service.mes.wms
|
||
{
|
||
/// <summary>
|
||
/// 成品库当前货物表Service业务层处理
|
||
/// </summary>
|
||
[AppService(
|
||
ServiceType = typeof(IWmGoodsNowProductionService),
|
||
ServiceLifetime = LifeTime.Transient
|
||
)]
|
||
public class WmGoodsNowProductionService
|
||
: BaseService<WmGoodsNowProduction>,
|
||
IWmGoodsNowProductionService
|
||
{
|
||
/// <summary>
|
||
/// 查询成品库当前货物表列表
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
public PagedInfo<WmGoodsNowProductionDto> GetList(WmGoodsNowProductionQueryDto parm)
|
||
{
|
||
List<string> partnumberByDescription = new();
|
||
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<WmGoodsNowProduction>()
|
||
.AndIF(
|
||
partnumberByDescription.Count > 0,
|
||
it => partnumberByDescription.Contains(it.Partnumber)
|
||
)
|
||
.AndIF(
|
||
!string.IsNullOrEmpty(parm.Partnumber),
|
||
it => it.Partnumber.Contains(parm.Partnumber)
|
||
)
|
||
.AndIF(
|
||
!string.IsNullOrEmpty(parm.PackageCodeClient),
|
||
it => it.PackageCodeClient.Contains(parm.PackageCodeClient)
|
||
)
|
||
.AndIF(
|
||
parm.EntryWarehouseTimeStart != null,
|
||
it => it.EntryWarehouseTime > parm.EntryWarehouseTimeStart
|
||
)
|
||
.AndIF(
|
||
parm.EntryWarehouseTimeEnd != null,
|
||
it => it.EntryWarehouseTime < parm.EntryWarehouseTimeEnd
|
||
)
|
||
.AndIF(
|
||
!string.IsNullOrEmpty(parm.PackageCodeClient),
|
||
it => it.PackageCodeClient.Contains(parm.PackageCodeClient)
|
||
)
|
||
.AndIF(
|
||
!string.IsNullOrEmpty(parm.LocationCode),
|
||
it => it.LocationCode.Contains(parm.LocationCode)
|
||
);
|
||
var response = Context
|
||
.Queryable<WmGoodsNowProduction>()
|
||
.Where(predicate.ToExpression())
|
||
.OrderByDescending(x => x.EntryWarehouseTime)
|
||
.ToPage<WmGoodsNowProduction, WmGoodsNowProductionDto>(parm);
|
||
|
||
foreach (WmGoodsNowProductionDto item in response.Result)
|
||
{
|
||
WmMaterial material = Context
|
||
.Queryable<WmMaterial>()
|
||
.Where(it => it.Partnumber == item.Partnumber)
|
||
.Where(it => it.Type == 1)
|
||
.First();
|
||
if (material == null)
|
||
{
|
||
item.Description = "此零件号不在物料清单内!";
|
||
continue;
|
||
}
|
||
item.Description = !string.IsNullOrEmpty(material.Description)
|
||
? material.Description
|
||
: material.ProductName;
|
||
}
|
||
return response;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 批量查看
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="NotImplementedException"></exception>
|
||
public (List<WmGoods_nodeDto>, int) QuerypatchsearchList(WmGoodsNowProductionQueryDto parm)
|
||
{
|
||
List<WmGoods_nodeDto> list = null;
|
||
int total = 0;
|
||
var predicate = Expressionable
|
||
.Create<WmGoodsNowProduction>()
|
||
.AndIF(
|
||
!string.IsNullOrEmpty(parm.Partnumber),
|
||
it => it.Partnumber.Contains(parm.Partnumber)
|
||
)
|
||
.AndIF(
|
||
!string.IsNullOrEmpty(parm.PackageCodeClient),
|
||
it => it.PackageCodeClient.Contains(parm.PackageCodeClient)
|
||
);
|
||
|
||
List<WmGoodsNowProduction> rawdatas = Queryable()
|
||
.Where(predicate.ToExpression())
|
||
.ToPageList(parm.PageNum, parm.PageSize, ref total);
|
||
if (rawdatas != null && rawdatas.Count > 0)
|
||
{
|
||
//todo 对字段进行拆分
|
||
|
||
List<WmGoods_nodeDto> WmGoods_nodeDto_list = rawdatas
|
||
.Select(p => new WmGoods_nodeDto()
|
||
{
|
||
Id = p.Id,
|
||
PackageCode = p.PackageCode,
|
||
PackageCodeClient_short_parent = p.PackageCodeClient.Split("_")[0],
|
||
PackageCodeClient_son = p.PackageCodeClient,
|
||
PackageCodeOriginal = p.PackageCodeClient,
|
||
LocationCode = p.LocationCode,
|
||
Partnumber = p.Partnumber,
|
||
Pack_num = 1,
|
||
GoodsNumLogic = p.GoodsNumLogic,
|
||
GoodsNumAction = p.GoodsNumAction,
|
||
EntryWarehouseTime = p.EntryWarehouseTime,
|
||
Remark = p.Remark,
|
||
})
|
||
.ToList();
|
||
//todo 分组 聚合 生成父节点
|
||
|
||
List<WmGoods_nodeDto> WmGoods_nodeDto_list_parent = WmGoods_nodeDto_list
|
||
.GroupBy(p => p.PackageCodeClient_short_parent)
|
||
.Select(group => new WmGoods_nodeDto()
|
||
{
|
||
PackageCodeClient_short_parent = "",
|
||
PackageCodeClient_son = group.Key,
|
||
GoodsNumLogic = group.Sum(group => group.GoodsNumLogic),
|
||
GoodsNumAction = group.Sum(group => group.GoodsNumAction),
|
||
Partnumber = group.Max(group => group.Partnumber),
|
||
Pack_num = group.Count()
|
||
})
|
||
.ToList();
|
||
|
||
//todo 合并
|
||
|
||
list = WmGoods_nodeDto_list.Concat(WmGoods_nodeDto_list_parent).ToList();
|
||
}
|
||
return (list, total);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 移动端 货物查看 根据Query零件号与批次号查看信息
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
public (List<WmGoodShortPackageCodeDto>, int) QueryshortPatch(CommonQueryDto parm)
|
||
{
|
||
// 结果集
|
||
List<WmGoodShortPackageCodeDto> resultList = new();
|
||
string _parm = parm.Query;
|
||
bool isLocation = false;
|
||
if (!string.IsNullOrEmpty(_parm))
|
||
{
|
||
isLocation = Context
|
||
.Queryable<WmInfo>()
|
||
.Where(it => it.Location.ToLower() == _parm.ToLower())
|
||
.Any();
|
||
}
|
||
// 全数据处理
|
||
var predicate = Expressionable
|
||
.Create<WmGoodsNowProduction>()
|
||
.AndIF(isLocation, it => it.LocationCode.ToLower() == _parm.ToLower())
|
||
.OrIF(
|
||
!string.IsNullOrEmpty(_parm) && !isLocation,
|
||
it => it.Partnumber.Contains(_parm)
|
||
)
|
||
.OrIF(
|
||
!string.IsNullOrEmpty(_parm) && !isLocation,
|
||
it => it.PackageCodeClient.Contains(_parm)
|
||
);
|
||
|
||
// 使用子查询方式处理分组聚合
|
||
// 先获取基础数据,然后在内存中进行分组处理
|
||
var dataList = Context
|
||
.Queryable<WmGoodsNowProduction>()
|
||
.Where(predicate.ToExpression())
|
||
.ToList();
|
||
|
||
// 在内存中进行分组聚合处理
|
||
var groupData = dataList
|
||
.GroupBy(it =>
|
||
{
|
||
// 处理PackageCodeClient,截取下划线前的部分
|
||
if (it.PackageCodeClient.Contains("_"))
|
||
{
|
||
return it.PackageCodeClient.Split('_')[0];
|
||
}
|
||
return it.PackageCodeClient;
|
||
})
|
||
.Select(g => new WmGoodShortPackageCodeDto
|
||
{
|
||
ShortPackageCode = g.Key,
|
||
Partnumber = g.Max(it => it.Partnumber),
|
||
EntryWarehouseTime = g.Max(it => it.EntryWarehouseTime),
|
||
PackageNumber = g.Count(),
|
||
LocationCode = isLocation?g.Max(it => it.LocationCode) : "",
|
||
PartnumberNumber = g.Sum(it => it.GoodsNumAction)
|
||
});
|
||
|
||
// 获取总数
|
||
int sum = groupData.Count();
|
||
|
||
// 分页处理
|
||
resultList = groupData
|
||
.OrderByDescending(it => it.ShortPackageCode)
|
||
.Skip((parm.PageNum - 1) * parm.PageSize)
|
||
.Take(parm.PageSize)
|
||
.ToList();
|
||
|
||
return (resultList, sum);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 移动端 短批次号详情
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
public (List<WmGoodsNowProductionDto>, int) Patchsearchdetail(
|
||
WmGoodsNowProductionQueryDto parm
|
||
)
|
||
{
|
||
var predicate = Expressionable
|
||
.Create<WmGoodsNowProduction>()
|
||
.AndIF(
|
||
!string.IsNullOrEmpty(parm.PackageCodeClient),
|
||
it => it.PackageCodeClient.Contains(parm.PackageCodeClient)
|
||
)
|
||
.AndIF(
|
||
!string.IsNullOrEmpty(parm.LocationCode),
|
||
it => it.LocationCode == parm.LocationCode
|
||
);
|
||
|
||
var response = Queryable()
|
||
.Where(predicate.ToExpression())
|
||
.OrderBy(it => it.PackageCodeClient)
|
||
.Select(it => new WmGoodsNowProductionDto
|
||
{
|
||
PackageCodeClient = it.PackageCodeClient,
|
||
LocationCode = it.LocationCode,
|
||
Partnumber = it.Partnumber,
|
||
GoodsNumAction = it.GoodsNumAction,
|
||
EntryWarehouseTime = it.EntryWarehouseTime,
|
||
Remark = (!string.IsNullOrEmpty(it.Remark) ? it.Remark : "无备注"),
|
||
})
|
||
.ToList();
|
||
foreach (WmGoodsNowProductionDto item in response)
|
||
{
|
||
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.Description = !string.IsNullOrEmpty(material.Description)
|
||
? material.Description
|
||
: material.ProductName;
|
||
}
|
||
return (response, response.Count);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取详情
|
||
/// </summary>
|
||
/// <param name="Id"></param>
|
||
/// <returns></returns>
|
||
public WmGoodsNowProduction GetInfo(string Id)
|
||
{
|
||
var response = Queryable().Where(x => x.Id == Id).First();
|
||
|
||
return response;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加成品库当前货物表
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
/// <returns></returns>
|
||
public WmGoodsNowProduction AddWmGoodsNowProduction(WmGoodsNowProduction model)
|
||
{
|
||
if (string.IsNullOrEmpty(model.Id))
|
||
{
|
||
model.Id = SnowFlakeSingle.Instance.NextId().ToString(); //也可以在程序中直接获取ID
|
||
}
|
||
if (string.IsNullOrEmpty(model.PackageCode))
|
||
{
|
||
model.PackageCode = model.PackageCodeClient;
|
||
}
|
||
if (string.IsNullOrEmpty(model.PackageCodeOriginal))
|
||
{
|
||
model.PackageCodeOriginal = model.PackageCodeClient;
|
||
}
|
||
bool hasRecord = Context
|
||
.Queryable<WmGoodsNowProduction>()
|
||
.Where(it => it.PackageCodeClient == model.PackageCodeClient)
|
||
.Any();
|
||
if (hasRecord)
|
||
{
|
||
throw new Exception("成品仓库已有相同批次号记录");
|
||
}
|
||
return Context.Insertable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改成品库当前货物表
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
/// <returns></returns>
|
||
public int UpdateWmGoodsNowProduction(WmGoodsNowProduction model)
|
||
{
|
||
//var response = Update(w => w.Id == model.Id, it => new WmGoodsNowProduction()
|
||
//{
|
||
// PackageCode = model.PackageCode,
|
||
// PackageCodeClient = model.PackageCodeClient,
|
||
// PackageCodeOriginal = model.PackageCodeOriginal,
|
||
// LocationCode = model.LocationCode,
|
||
// Partnumber = model.Partnumber,
|
||
// GoodsNumLogic = model.GoodsNumLogic,
|
||
// GoodsNumAction = model.GoodsNumAction,
|
||
// EntryWarehouseTime = model.EntryWarehouseTime,
|
||
// Remark = model.Remark,
|
||
// UpdatedBy = model.UpdatedBy,
|
||
// UpdatedTime = model.UpdatedTime,
|
||
// CreatedBy = model.CreatedBy,
|
||
// CreatedTime = model.CreatedTime,
|
||
//});
|
||
//return response;
|
||
return Update(model, true);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改实际库存
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <param name="stack_num"></param>
|
||
/// <returns></returns>
|
||
public int ModifyInventoryQuantity(string id, int stack_num)
|
||
{
|
||
return Context
|
||
.Updateable<WmGoodsNowProduction>()
|
||
.SetColumns(it => it.GoodsNumAction == stack_num)
|
||
.Where(it => it.Id == id)
|
||
.ExecuteCommand();
|
||
}
|
||
|
||
public PagedInfo<WmGoodsNowProductionDictDto> GetDictData(WmGoodsNowProductionDictDto parm)
|
||
{
|
||
var predicate = Expressionable
|
||
.Create<WmGoodsNowProduction>()
|
||
.AndIF(!string.IsNullOrEmpty(parm.Query), it => it.Partnumber.Contains(parm.Query))
|
||
.Or(it => it.PackageCodeClient.Contains(parm.Query))
|
||
// .Or(it => it.LocationCode.Contains(parm.Query))
|
||
;
|
||
|
||
var response = Queryable()
|
||
.Where(predicate.ToExpression())
|
||
.Select(it => new WmGoodsNowProductionDictDto
|
||
{
|
||
Id = it.Id,
|
||
PackageCodeClient = it.PackageCodeClient,
|
||
LocationCode = it.LocationCode,
|
||
Partnumber = it.Partnumber,
|
||
Description = string.Empty,
|
||
GoodsNumAction = it.GoodsNumAction,
|
||
GoodsNumLogic = it.GoodsNumLogic,
|
||
Label = string.Empty,
|
||
})
|
||
.ToPage(parm);
|
||
|
||
foreach (WmGoodsNowProductionDictDto item in response.Result)
|
||
{
|
||
WmMaterial material = Context
|
||
.Queryable<WmMaterial>()
|
||
.Where(it => it.Partnumber == item.Partnumber)
|
||
.First();
|
||
if (material == null)
|
||
{
|
||
item.Description = "此零件号不在物料清单内!";
|
||
}
|
||
else
|
||
{
|
||
item.Description = !string.IsNullOrEmpty(material.Description)
|
||
? material.Description
|
||
: material.ProductName;
|
||
}
|
||
string label =
|
||
"批次号:"
|
||
+ item.PackageCodeClient
|
||
+ " 零件号:"
|
||
+ item.Partnumber
|
||
+ " 描述:"
|
||
+ item.Description;
|
||
var value = new
|
||
{
|
||
Id = item.Id,
|
||
PackageCodeClient = item.PackageCodeClient,
|
||
LocationCode = item.LocationCode,
|
||
Partnumber = item.Partnumber,
|
||
Description = item.Description,
|
||
GoodsNumAction = item.GoodsNumAction,
|
||
GoodsNumLogic = item.GoodsNumLogic,
|
||
};
|
||
item.Value = value;
|
||
item.Label = label;
|
||
}
|
||
return response;
|
||
}
|
||
|
||
public int BatchUpdateLocationCode(BatchUpdateLocationCodeDto parm)
|
||
{
|
||
try
|
||
{
|
||
List<WmGoodsNowProduction> updateList = new List<WmGoodsNowProduction>();
|
||
foreach (string id in parm.Ids)
|
||
{
|
||
WmGoodsNowProduction nowProduction =
|
||
new()
|
||
{
|
||
Id = id,
|
||
LocationCode = parm.LocationCode,
|
||
UpdatedBy = parm.UpdatedBy,
|
||
UpdatedTime = parm.UpdatedTime,
|
||
};
|
||
updateList.Add(nowProduction);
|
||
}
|
||
return Context
|
||
.Updateable(updateList)
|
||
.IgnoreColumns(ignoreAllNullColumns: true)
|
||
.ExecuteCommand();
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
throw new Exception(e.Message);
|
||
}
|
||
}
|
||
}
|
||
}
|