shgx_tz_mom/ZR.Service/mes/wms/WmGoodsOutProductionService.cs
2024-04-23 18:54:44 +08:00

205 lines
8.9 KiB
C#

using System;
using SqlSugar;
using Infrastructure.Attribute;
using Infrastructure.Extensions;
using ZR.Model;
using ZR.Model.Dto;
using ZR.Repository;
using System.Linq;
using ZR.Service.mes.wms.IService;
using ZR.Model.MES.wms;
using ZR.Model.MES.wms.Dto;
using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Collections.Generic;
namespace ZR.Service.mes.wms
{
/// <summary>
/// 出库货物记录表Service业务层处理
/// </summary>
[AppService(ServiceType = typeof(IWmGoodsOutProductionService), ServiceLifetime = LifeTime.Transient)]
public class WmGoodsOutProductionService : BaseService<WmGoodsOutRecord>, IWmGoodsOutProductionService
{
/// <summary>
/// 查询出库货物记录表列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public (List<WmGoodsOutProductionDto>,int) GetList(WmGoodsOutProductionQueryDto parm)
{
int total = 0;
var predicate = Expressionable.Create<WmGoodsOutRecord>()
.AndIF(!string.IsNullOrEmpty(parm.Partnumber), wgo => wgo.Partnumber.Contains(parm.Partnumber))
.AndIF(!string.IsNullOrEmpty(parm.PackageCodeClient), wgo => wgo.PackageCodeClient.Contains(parm.PackageCodeClient))
.AndIF(!string.IsNullOrEmpty(parm.LocationCode), wgo => wgo.LocationCode.Contains(parm.LocationCode))
.AndIF(!string.IsNullOrEmpty(parm.FkOutOrderId), wgo => wgo.FkOutOrderId.Contains(parm.FkOutOrderId))
;
var response = Queryable()
.LeftJoin<WmMaterial>((wgo, wml) => wgo.Partnumber == wml.Partnumber)
.Where(predicate.ToExpression())
.Select((wgo, wml) => new WmGoodsOutProductionDto { Description = wml.Description }, true)
.OrderBy(wml=>wml.OutTime,OrderByType.Desc)
.ToPageList(parm.PageNum, parm.PageSize,ref total);
return (response,total);
}
/// <summary>
/// 获取详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public WmGoodsOutRecord GetInfo(string Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
.First();
return response;
}
/// <summary>
/// 添加出库货物记录表
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public WmGoodsOutRecord AddWmGoodsOutProduction(WmGoodsOutRecord model)
{
if(string.IsNullOrEmpty(model.PackageCode))
{
model.PackageCode = "L" + DateTime.Now.ToString("yyMMddHHmmss");
}
if (string.IsNullOrEmpty(model.Id))
{
model.Id= SnowFlakeSingle.Instance.NextId().ToString();//也可以在程序中直接获取ID
}
//2. 根据成品仓库id修改记录
WmGoodsNowProduction updateModel = new WmGoodsNowProduction();
updateModel.Id = model.FkNowProductionId;
updateModel.GoodsNumAction = model.GoodsNumLogic - model.GoodsNumAction;
if (updateModel.GoodsNumAction <= 0)
{
updateModel.GoodsNumAction = 0;
}
if (updateModel.GoodsNumAction == 0)
{
Context.Deleteable<WmGoodsNowProduction>().Where(it => it.Id == updateModel.Id).ExecuteCommand();
}
else
{
Context.Updateable(updateModel).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
}
return Context.Insertable(model).ExecuteReturnEntity();
}
/// <summary>
/// 修改出库货物记录表
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int UpdateWmGoodsOutProduction(WmGoodsOutRecord model)
{
//var response = Update(w => w.Id == model.Id, it => new WmGoodsOutProduction()
//{
// PackageCode = model.PackageCode,
// PackageCodeClient = model.PackageCodeClient,
// PackageCodeOriginal = model.PackageCodeOriginal,
// LocationCode = model.LocationCode,
// Partnumber = model.Partnumber,
// GoodsNumLogic = model.GoodsNumLogic,
// GoodsNumAction = model.GoodsNumAction,
// EntryWarehouseTime = model.EntryWarehouseTime,
// OutTime = model.OutTime,
// Remark = model.Remark,
// UpdatedBy = model.UpdatedBy,
// UpdatedTime = model.UpdatedTime,
// CreatedBy = model.CreatedBy,
// CreatedTime = model.CreatedTime,
//});
//return response;
return Update(model, true);
}
public string DoPatchOutProduction(WmBatchGoodsOutProductionDto parm)
{
int type = parm.Type;
var time = DateTime.Now.ToLocalTime();
if (type == 1)
{
var list = parm.Ids;
for (int i = 0; i < list.Count; i++)
{
WmGoodsNowProduction nowProduction = Context.Queryable<WmGoodsNowProduction>()
.Where(it => it.Id == list[i]).First();
if(nowProduction == null)
{
continue;
}
WmGoodsOutRecord outRecord = new()
{
Id = SnowFlakeSingle.Instance.NextId().ToString(),
FkNowProductionId = nowProduction.Id,
FkOutOrderId = parm.FkOutOrderId,
PackageCode = nowProduction.PackageCode,
PackageCodeClient = nowProduction.PackageCodeClient,
PackageCodeOriginal = nowProduction.PackageCodeOriginal,
LocationCode = nowProduction.LocationCode,
Partnumber = nowProduction.Partnumber,
GoodsNumAction = nowProduction.GoodsNumAction,
GoodsNumLogic = nowProduction.GoodsNumAction,
EntryWarehouseTime = nowProduction.EntryWarehouseTime,
OutTime = time,
Remark = "批量出库",
CreatedBy = "batch",
CreatedTime = time,
};
Context.Insertable(outRecord).ExecuteCommand();
Context.Deleteable<WmGoodsNowProduction>().Where(it => it.Id == nowProduction.Id).ExecuteCommand();
}
}
else if(type == 2)
{
if (parm.PackageCodeClient == "" || parm.PackageCodeClient == null)
{
return "无批次号参数";
}
// 短批次号
string shortPackageCode = parm.PackageCodeClient.Split('_')[0];
List<WmGoodsNowProduction> nowProductionList = Context.Queryable<WmGoodsNowProduction>()
.Where(it => it.PackageCodeClient.Contains(shortPackageCode)).ToList();
for (int i = 0; i < nowProductionList.Count; i++)
{
WmGoodsNowProduction nowProduction = Context.Queryable<WmGoodsNowProduction>()
.Where(it => it.Id == nowProductionList[i].Id).First();
if (nowProduction == null)
{
continue;
}
WmGoodsOutRecord outRecord = new()
{
Id = SnowFlakeSingle.Instance.NextId().ToString(),
FkNowProductionId = nowProduction.Id,
FkOutOrderId = parm.FkOutOrderId,
PackageCode = nowProduction.PackageCode,
PackageCodeClient = nowProduction.PackageCodeClient,
PackageCodeOriginal = nowProduction.PackageCodeOriginal,
LocationCode = nowProduction.LocationCode,
Partnumber = nowProduction.Partnumber,
GoodsNumAction = nowProduction.GoodsNumAction,
GoodsNumLogic = nowProduction.GoodsNumAction,
EntryWarehouseTime = nowProduction.EntryWarehouseTime,
OutTime = time,
Remark = "批量出库",
CreatedBy = "batch",
CreatedTime = time,
};
Context.Insertable(outRecord).ExecuteCommand();
Context.Deleteable<WmGoodsNowProduction>().Where(it => it.Id == nowProduction.Id).ExecuteCommand();
}
}
return "ok";
}
}
}