125 lines
4.6 KiB
C#
125 lines
4.6 KiB
C#
using System;
|
|
using SqlSugar;
|
|
using Infrastructure.Attribute;
|
|
using Infrastructure.Extensions;
|
|
using ZR.Model;
|
|
using ZR.Model.Dto;
|
|
using ZR.Model.MES.wms;
|
|
using ZR.Repository;
|
|
using ZR.Service.Business.IBusinessService;
|
|
using System.Linq;
|
|
using ZR.Service.mes.wms.IService;
|
|
using ZR.Model.MES.wms.Dto;
|
|
using System.Text.Json;
|
|
|
|
namespace ZR.Service.Business
|
|
{
|
|
/// <summary>
|
|
/// 仓库操作日志Service业务层处理
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IWmGoodsActionService), ServiceLifetime = LifeTime.Transient)]
|
|
public class WmGoodsActionService : BaseService<WmGoodsChangeLog>, IWmGoodsActionService
|
|
{
|
|
public WmGoodsChangeLog doConsolidationGoods(WmGoodsConsolidationDto parm)
|
|
{
|
|
List<ResultionPackageCodeDto> list = parm.PackageList;
|
|
|
|
string description = "";
|
|
// 拼箱计数器
|
|
int num = 0;
|
|
int? quantityCount = 0;
|
|
List<string> ids = new();
|
|
// 箱验证
|
|
foreach (ResultionPackageCodeDto package in list)
|
|
{
|
|
num++;
|
|
WmGoodsNowProduction check1 = Context.Queryable<WmGoodsNowProduction>().Where(it => it.PackageCodeClient == package.PatchCode).First();
|
|
if (check1 == null)
|
|
{
|
|
return null;
|
|
}
|
|
if (num == 1)
|
|
{
|
|
description = "主箱:" + package.PatchCode + ",次箱:";
|
|
}
|
|
else
|
|
{
|
|
ids.Add(check1.Id);
|
|
description += package.PatchCode + ",";
|
|
}
|
|
quantityCount += package.Quantity;
|
|
}
|
|
ResultionPackageCodeDto mainPackage = list[0];
|
|
// 短批次
|
|
string shortPatchCode = mainPackage.PatchCode.Split('_')[0];
|
|
// 该批次最后一个拼箱记录
|
|
WmGoodsNowProduction lastConsolidationPackage = Context.Queryable<WmGoodsNowProduction>().Where(it => it.PackageCodeClient.Contains(shortPatchCode + "_4")).OrderBy(it => it.PackageCodeClient, OrderByType.Desc).First();
|
|
string newShortPatchCode = shortPatchCode;
|
|
|
|
int lastCode = 400;
|
|
if (lastConsolidationPackage == null)
|
|
{
|
|
newShortPatchCode += "_401";
|
|
}
|
|
else
|
|
{
|
|
if (int.TryParse(lastConsolidationPackage.PackageCodeClient.Split('_')[1], out lastCode))
|
|
{
|
|
|
|
if (lastCode > 400)
|
|
{
|
|
newShortPatchCode += "_" + (lastCode + 1);
|
|
}
|
|
else
|
|
{
|
|
newShortPatchCode += "_401";
|
|
}
|
|
}
|
|
}
|
|
description += "拼箱结果:" + newShortPatchCode;
|
|
var jsonObject = new
|
|
{
|
|
packageList = list
|
|
};
|
|
// 日志记录
|
|
WmGoodsChangeLog log = new WmGoodsChangeLog();
|
|
log.CreatedBy = parm.CreateBy;
|
|
log.CreatedTime = DateTime.Now.ToLocalTime();
|
|
log.Description = description;
|
|
log.JsonMsg = JsonSerializer.Serialize(jsonObject);
|
|
log.Type = 1;
|
|
Context.Insertable(log).ExecuteReturnEntity();
|
|
// 执行修改
|
|
// 1.主箱查出并修改参数
|
|
WmGoodsNowProduction nowProduction = Context.Queryable<WmGoodsNowProduction>()
|
|
.Where(it => it.PackageCodeClient == mainPackage.PatchCode).First();
|
|
if (nowProduction == null)
|
|
{
|
|
return null;
|
|
}
|
|
nowProduction.UpdatedBy = parm.CreateBy;
|
|
nowProduction.UpdatedTime = DateTime.Now.ToLocalTime();
|
|
nowProduction.PackageCodeClient = newShortPatchCode;
|
|
nowProduction.PackageCodeOriginal = "Code=" + newShortPatchCode
|
|
+ "^ItemNumber=" + nowProduction.Partnumber
|
|
+ "^Order=" + newShortPatchCode.Split('_')[0]
|
|
+ "^Qty=" + quantityCount;
|
|
nowProduction.GoodsNumLogic = quantityCount;
|
|
nowProduction.GoodsNumAction = quantityCount;
|
|
nowProduction.Remark = "拼箱";
|
|
// 修改主箱
|
|
Context.Updateable(nowProduction).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
// TODO修改打印记录
|
|
|
|
// 删除分箱
|
|
Context.Deleteable<WmGoodsNowProduction>().In(ids).ExecuteCommand();
|
|
|
|
return log;
|
|
}
|
|
|
|
public WmGoodsChangeLog doUnpackingGoods(WmGoodsUnpackingDto parm)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
} |