2024-07-05 16:49:00 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text.Json;
|
2024-04-18 11:34:49 +08:00
|
|
|
|
using Infrastructure.Attribute;
|
2024-06-07 11:04:26 +08:00
|
|
|
|
using MimeKit.Utils;
|
|
|
|
|
|
using SqlSugar;
|
2024-04-18 11:34:49 +08:00
|
|
|
|
using ZR.Model.MES.wms;
|
|
|
|
|
|
using ZR.Model.MES.wms.Dto;
|
2024-06-07 11:04:26 +08:00
|
|
|
|
using ZR.Service.mes.wms.IService;
|
2024-04-18 11:34:49 +08:00
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
2024-04-18 17:02:17 +08:00
|
|
|
|
List<ResultionPackageCodeDto> list = parm.PackageList;
|
|
|
|
|
|
string description = "";
|
|
|
|
|
|
// 拼箱计数器
|
|
|
|
|
|
int num = 0;
|
|
|
|
|
|
int? quantityCount = 0;
|
2024-04-20 10:46:36 +08:00
|
|
|
|
// 第二箱录入数量(限制只能输入两箱)
|
|
|
|
|
|
int secondNum = parm.secondNum;
|
|
|
|
|
|
int? secondHas = 0;
|
|
|
|
|
|
bool isDelete = false;
|
|
|
|
|
|
string secondId = "";
|
2024-04-18 17:02:17 +08:00
|
|
|
|
// 箱验证
|
|
|
|
|
|
foreach (ResultionPackageCodeDto package in list)
|
|
|
|
|
|
{
|
|
|
|
|
|
num++;
|
2024-04-20 10:46:36 +08:00
|
|
|
|
// 有第二箱录入数量的情况下只能两箱拼
|
|
|
|
|
|
if (num == 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2024-07-05 16:49:00 +08:00
|
|
|
|
WmGoodsNowProduction check1 = Context
|
|
|
|
|
|
.Queryable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.PackageCodeClient == package.PatchCode)
|
|
|
|
|
|
.First();
|
2024-04-18 17:02:17 +08:00
|
|
|
|
if (check1 == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2024-04-20 10:46:36 +08:00
|
|
|
|
|
2024-04-18 17:02:17 +08:00
|
|
|
|
if (num == 1)
|
|
|
|
|
|
{
|
2024-07-05 16:49:00 +08:00
|
|
|
|
description =
|
|
|
|
|
|
"\n主箱:" + package.PatchCode + " 数量:" + package.Quantity + ",\n次箱:";
|
2024-04-20 10:46:36 +08:00
|
|
|
|
quantityCount += package.Quantity;
|
|
|
|
|
|
continue;
|
2024-04-18 17:02:17 +08:00
|
|
|
|
}
|
2024-06-07 11:04:26 +08:00
|
|
|
|
if (num == 2)
|
2024-04-18 17:02:17 +08:00
|
|
|
|
{
|
2024-04-20 10:46:36 +08:00
|
|
|
|
secondId = check1.Id;
|
2024-04-23 11:02:38 +08:00
|
|
|
|
description += package.PatchCode + " 数量:" + package.Quantity + ",";
|
2024-04-18 17:02:17 +08:00
|
|
|
|
}
|
2024-05-10 14:57:47 +08:00
|
|
|
|
// 如果PDA所填合并的数量为正数且比次箱子的总数量小
|
2024-04-20 10:46:36 +08:00
|
|
|
|
if (num == 2 && secondNum < package.Quantity && secondNum > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
isDelete = false;
|
|
|
|
|
|
secondHas = package.Quantity - secondNum;
|
|
|
|
|
|
quantityCount += secondNum;
|
2024-04-23 11:02:38 +08:00
|
|
|
|
description += "\n移动数量" + secondNum;
|
2024-04-20 10:46:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
isDelete = true;
|
|
|
|
|
|
secondHas = 0;
|
|
|
|
|
|
quantityCount += package.Quantity;
|
2024-04-23 11:02:38 +08:00
|
|
|
|
description += "\n移动数量" + package.Quantity;
|
2024-04-20 10:46:36 +08:00
|
|
|
|
}
|
2024-04-18 17:02:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
ResultionPackageCodeDto mainPackage = list[0];
|
|
|
|
|
|
// 短批次
|
|
|
|
|
|
string shortPatchCode = mainPackage.PatchCode.Split('_')[0];
|
|
|
|
|
|
// 该批次最后一个拼箱记录
|
2024-07-05 16:49:00 +08:00
|
|
|
|
WmGoodsNowProduction lastConsolidationPackage = Context
|
|
|
|
|
|
.Queryable<WmGoodsNowProduction>()
|
2024-04-22 11:12:58 +08:00
|
|
|
|
.Where(it => it.PackageCodeClient.Contains(shortPatchCode + "_4"))
|
|
|
|
|
|
.OrderBy(it => it.PackageCodeClient, OrderByType.Desc)
|
|
|
|
|
|
.First();
|
2024-04-19 14:00:33 +08:00
|
|
|
|
string newPatchCode = shortPatchCode;
|
2024-05-10 14:57:47 +08:00
|
|
|
|
// 最终初始编号
|
2024-04-18 17:02:17 +08:00
|
|
|
|
int lastCode = 400;
|
2024-04-22 11:12:58 +08:00
|
|
|
|
// 检测包装是否已打印4XX标签
|
|
|
|
|
|
// 该工单标签最大一个
|
2024-07-05 16:49:00 +08:00
|
|
|
|
var packingrecordExp = Expressionable
|
|
|
|
|
|
.Create<WmPackingrecord>()
|
2024-04-22 11:12:58 +08:00
|
|
|
|
.And(it => it.WorkOrderNum == mainPackage.WorkoderID)
|
|
|
|
|
|
.And(it => it.Machine == "4")
|
|
|
|
|
|
.And(it => !it.PackingCode.Contains("Iminate"))
|
|
|
|
|
|
.ToExpression();
|
2024-07-05 16:49:00 +08:00
|
|
|
|
WmPackingrecord lastPackingrecord = Context
|
|
|
|
|
|
.Queryable<WmPackingrecord>()
|
2024-04-22 11:12:58 +08:00
|
|
|
|
.Where(packingrecordExp)
|
2024-06-07 11:04:26 +08:00
|
|
|
|
.OrderBy(it => it.PackingCode, OrderByType.Desc)
|
2024-04-22 11:12:58 +08:00
|
|
|
|
.First();
|
2024-05-10 14:57:47 +08:00
|
|
|
|
// 优先处理箱打印有历史数据情况
|
|
|
|
|
|
if (lastPackingrecord != null)
|
2024-04-18 17:02:17 +08:00
|
|
|
|
{
|
2024-05-10 14:57:47 +08:00
|
|
|
|
int subIndex = lastPackingrecord.PackingCode.Length - 5;
|
|
|
|
|
|
// XXX 此代码中 AsSpan 方法 .NET Framework 4.7.2 不支持需要更高版本 或替换为 Substring
|
2024-07-05 16:49:00 +08:00
|
|
|
|
if (
|
|
|
|
|
|
int.TryParse(
|
|
|
|
|
|
lastPackingrecord.PackingCode.AsSpan(subIndex).TrimStart('0'),
|
|
|
|
|
|
out int lastPackingrecordCode
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2024-04-22 11:12:58 +08:00
|
|
|
|
{
|
2024-05-10 14:57:47 +08:00
|
|
|
|
if (lastPackingrecordCode > lastCode)
|
2024-04-22 11:12:58 +08:00
|
|
|
|
{
|
2024-05-10 14:57:47 +08:00
|
|
|
|
lastCode = lastPackingrecordCode;
|
2024-04-22 11:12:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-10 14:57:47 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("生成标签数据异常:" + lastPackingrecord.PackingCode);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 其次处理成品库历史最大数字
|
|
|
|
|
|
if (lastConsolidationPackage != null)
|
|
|
|
|
|
{
|
2024-07-05 16:49:00 +08:00
|
|
|
|
if (
|
|
|
|
|
|
int.TryParse(
|
|
|
|
|
|
lastConsolidationPackage.PackageCodeClient.Split('_')[1],
|
|
|
|
|
|
out int lastConsolidationPackageCode
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2024-04-18 17:02:17 +08:00
|
|
|
|
{
|
2024-04-22 11:12:58 +08:00
|
|
|
|
// 取最大值
|
2024-05-10 14:57:47 +08:00
|
|
|
|
if (lastConsolidationPackageCode > lastCode)
|
2024-04-18 17:02:17 +08:00
|
|
|
|
{
|
2024-05-10 14:57:47 +08:00
|
|
|
|
lastCode = lastConsolidationPackageCode;
|
2024-04-18 17:02:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-10 14:57:47 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("生成标签数据异常:" + lastConsolidationPackage.PackageCodeClient);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (lastCode > 400)
|
|
|
|
|
|
{
|
|
|
|
|
|
newPatchCode += "_" + (lastCode + 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
newPatchCode += "_401";
|
2024-04-18 17:02:17 +08:00
|
|
|
|
}
|
2024-04-23 11:02:38 +08:00
|
|
|
|
description += "\n拼箱结果:" + newPatchCode + " 总数量:" + quantityCount;
|
2024-04-19 14:00:33 +08:00
|
|
|
|
DateTime nowTime = DateTime.Now.ToLocalTime();
|
2024-04-18 17:02:17 +08:00
|
|
|
|
var jsonObject = new
|
|
|
|
|
|
{
|
2024-04-19 14:00:33 +08:00
|
|
|
|
packageList = list,
|
2024-04-26 11:22:33 +08:00
|
|
|
|
// 拼箱批次号
|
2024-04-19 14:00:33 +08:00
|
|
|
|
newPatchCode = newPatchCode,
|
2024-04-26 11:22:33 +08:00
|
|
|
|
// 拼箱流水号
|
|
|
|
|
|
serialNumber = newPatchCode.Split("_")[1],
|
|
|
|
|
|
// 拼箱数量
|
2024-04-19 14:00:33 +08:00
|
|
|
|
newQuantityCount = quantityCount,
|
2024-04-26 11:22:33 +08:00
|
|
|
|
// 拼箱班组
|
|
|
|
|
|
Team = "C",
|
|
|
|
|
|
// 拼箱零件号
|
|
|
|
|
|
newPartnumber = mainPackage.PartNumner,
|
|
|
|
|
|
// 拼箱时间
|
2024-04-19 14:00:33 +08:00
|
|
|
|
time = DateUtils.FormatDate(nowTime)
|
2024-04-18 17:02:17 +08:00
|
|
|
|
};
|
|
|
|
|
|
// 日志记录
|
2024-07-05 16:49:00 +08:00
|
|
|
|
WmGoodsChangeLog log =
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
CreatedBy = parm.CreateBy,
|
|
|
|
|
|
CreatedTime = nowTime,
|
|
|
|
|
|
Description = description,
|
|
|
|
|
|
JsonMsg = JsonSerializer.Serialize(jsonObject),
|
|
|
|
|
|
Type = 1
|
|
|
|
|
|
};
|
2024-04-18 17:02:17 +08:00
|
|
|
|
Context.Insertable(log).ExecuteReturnEntity();
|
|
|
|
|
|
// 执行修改
|
|
|
|
|
|
// 1.主箱查出并修改参数
|
2024-07-05 16:49:00 +08:00
|
|
|
|
WmGoodsNowProduction nowProduction = Context
|
|
|
|
|
|
.Queryable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.PackageCodeClient == mainPackage.PatchCode)
|
|
|
|
|
|
.First();
|
2024-04-18 17:02:17 +08:00
|
|
|
|
if (nowProduction == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
nowProduction.UpdatedBy = parm.CreateBy;
|
2024-04-19 14:00:33 +08:00
|
|
|
|
nowProduction.UpdatedTime = nowTime;
|
|
|
|
|
|
nowProduction.PackageCodeClient = newPatchCode;
|
2024-07-05 16:49:00 +08:00
|
|
|
|
nowProduction.PackageCodeOriginal =
|
|
|
|
|
|
"Code="
|
|
|
|
|
|
+ newPatchCode
|
|
|
|
|
|
+ "^ItemNumber="
|
|
|
|
|
|
+ nowProduction.Partnumber
|
|
|
|
|
|
+ "^Order="
|
|
|
|
|
|
+ newPatchCode.Split('_')[0].Substring(2)
|
|
|
|
|
|
+ "^Qty="
|
|
|
|
|
|
+ quantityCount;
|
2024-04-18 17:02:17 +08:00
|
|
|
|
nowProduction.GoodsNumLogic = quantityCount;
|
|
|
|
|
|
nowProduction.GoodsNumAction = quantityCount;
|
2024-04-20 10:46:36 +08:00
|
|
|
|
nowProduction.Remark = "拼箱整箱";
|
2024-04-23 11:02:38 +08:00
|
|
|
|
//TODO 20240422开会讨论结果:拼箱完需要重新扫码入库,原数据删除
|
2024-07-05 16:49:00 +08:00
|
|
|
|
Context
|
|
|
|
|
|
.Deleteable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.Id == nowProduction.Id)
|
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
Context
|
|
|
|
|
|
.Deleteable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.Id == secondId)
|
|
|
|
|
|
.ExecuteCommand();
|
2024-05-10 14:57:47 +08:00
|
|
|
|
//TODO 20240510添加标签记录信息到标签记录信息表
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.BeginTran();
|
2024-07-05 16:49:00 +08:00
|
|
|
|
WmPackageLcl mainPackageLcl =
|
|
|
|
|
|
new()
|
2024-05-10 14:57:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
Id = SnowFlakeSingle.instance.NextId().ToString(),
|
2024-07-05 16:49:00 +08:00
|
|
|
|
Partnumber = nowProduction.Partnumber,
|
|
|
|
|
|
WorkOrderId = newPatchCode.Substring(3, 9),
|
|
|
|
|
|
PackageCode = newPatchCode,
|
|
|
|
|
|
SerialNumber = newPatchCode.Split('_')[1],
|
|
|
|
|
|
LocationCode = nowProduction.LocationCode,
|
|
|
|
|
|
GoodsNum = nowProduction.GoodsNumAction ?? 0,
|
2024-05-10 14:57:47 +08:00
|
|
|
|
Team = "C",
|
|
|
|
|
|
Type = 1,
|
|
|
|
|
|
Status = 0,
|
|
|
|
|
|
CreatedBy = "拼箱",
|
|
|
|
|
|
CreatedTime = nowTime,
|
2024-07-05 16:49:00 +08:00
|
|
|
|
Remark = "拼箱整箱"
|
2024-05-10 14:57:47 +08:00
|
|
|
|
};
|
2024-07-05 16:49:00 +08:00
|
|
|
|
Context.Insertable(mainPackageLcl).ExecuteCommand();
|
|
|
|
|
|
if (!isDelete)
|
|
|
|
|
|
{
|
|
|
|
|
|
WmPackageLcl oddPackageLcl =
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = SnowFlakeSingle.instance.NextId().ToString(),
|
|
|
|
|
|
Partnumber = list[1].PartNumner,
|
|
|
|
|
|
WorkOrderId = list[1].PatchCode.Substring(3, 9),
|
|
|
|
|
|
PackageCode = list[1].PatchCode,
|
|
|
|
|
|
SerialNumber = list[1].PatchCode.Split('_')[1],
|
|
|
|
|
|
LocationCode = "LS",
|
|
|
|
|
|
GoodsNum = secondHas ?? 0,
|
|
|
|
|
|
Team = "C",
|
|
|
|
|
|
Type = 1,
|
|
|
|
|
|
Status = 0,
|
|
|
|
|
|
CreatedBy = "拼箱",
|
|
|
|
|
|
CreatedTime = nowTime,
|
|
|
|
|
|
Remark = "拼箱零头箱"
|
|
|
|
|
|
};
|
2024-05-10 14:57:47 +08:00
|
|
|
|
Context.Insertable(oddPackageLcl).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
Context.Ado.CommitTran();
|
|
|
|
|
|
return log;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
|
throw new Exception("生成打印标签信息异常!" + ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-26 11:22:33 +08:00
|
|
|
|
return log;
|
2024-04-18 17:02:17 +08:00
|
|
|
|
// 修改主箱
|
2024-07-05 16:49:00 +08:00
|
|
|
|
Context
|
|
|
|
|
|
.Updateable(nowProduction)
|
|
|
|
|
|
.IgnoreColumns(ignoreAllNullColumns: true)
|
|
|
|
|
|
.ExecuteCommand();
|
2024-04-20 10:46:36 +08:00
|
|
|
|
// 次箱操作
|
|
|
|
|
|
if (isDelete)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 删除次箱
|
2024-07-05 16:49:00 +08:00
|
|
|
|
Context
|
|
|
|
|
|
.Deleteable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.Id == secondId)
|
|
|
|
|
|
.ExecuteCommand();
|
2024-04-20 10:46:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 修改次箱子
|
2024-07-05 16:49:00 +08:00
|
|
|
|
WmGoodsNowProduction nowProduction2 = Context
|
|
|
|
|
|
.Queryable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.Id == secondId)
|
|
|
|
|
|
.First();
|
2024-04-20 10:46:36 +08:00
|
|
|
|
if (nowProduction2 == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
nowProduction2.UpdatedBy = parm.CreateBy;
|
|
|
|
|
|
nowProduction2.UpdatedTime = nowTime;
|
2024-07-05 16:49:00 +08:00
|
|
|
|
nowProduction2.PackageCodeOriginal =
|
|
|
|
|
|
"Code="
|
|
|
|
|
|
+ nowProduction2.PackageCodeClient
|
|
|
|
|
|
+ "^ItemNumber="
|
|
|
|
|
|
+ nowProduction2.Partnumber
|
|
|
|
|
|
+ "^Order="
|
|
|
|
|
|
+ nowProduction2.PackageCodeClient.Split('_')[0].Substring(2)
|
|
|
|
|
|
+ "^Qty="
|
|
|
|
|
|
+ secondHas;
|
2024-04-20 10:46:36 +08:00
|
|
|
|
nowProduction2.GoodsNumLogic = secondHas;
|
|
|
|
|
|
nowProduction2.GoodsNumAction = secondHas;
|
2024-04-23 11:02:38 +08:00
|
|
|
|
nowProduction2.LocationCode = "LS";
|
2024-04-20 10:46:36 +08:00
|
|
|
|
nowProduction2.Remark = "拼箱零头箱";
|
2024-07-05 16:49:00 +08:00
|
|
|
|
Context
|
|
|
|
|
|
.Updateable(nowProduction2)
|
|
|
|
|
|
.IgnoreColumns(ignoreAllNullColumns: true)
|
|
|
|
|
|
.ExecuteCommand();
|
2024-04-20 10:46:36 +08:00
|
|
|
|
}
|
2024-04-18 17:02:17 +08:00
|
|
|
|
return log;
|
2024-04-18 11:34:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public WmGoodsChangeLog doUnpackingGoods(WmGoodsUnpackingDto parm)
|
|
|
|
|
|
{
|
2024-04-19 14:00:33 +08:00
|
|
|
|
string description = "";
|
|
|
|
|
|
// 待拆箱
|
|
|
|
|
|
ResultionPackageCodeDto mainPackage = parm.Package;
|
|
|
|
|
|
|
|
|
|
|
|
// 验证
|
2024-07-05 16:49:00 +08:00
|
|
|
|
WmGoodsNowProduction mainNowProduction = Context
|
|
|
|
|
|
.Queryable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.PackageCodeClient == mainPackage.PatchCode)
|
|
|
|
|
|
.First();
|
2024-04-19 14:00:33 +08:00
|
|
|
|
if (mainNowProduction == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2024-04-20 10:46:36 +08:00
|
|
|
|
|
2024-04-23 11:02:38 +08:00
|
|
|
|
description += "\n由主箱:" + mainPackage.PatchCode + " 数量:" + mainPackage.Quantity + "拆分:";
|
2024-04-19 14:00:33 +08:00
|
|
|
|
// 短批次
|
|
|
|
|
|
string shortPatchCode = mainPackage.PatchCode.Split('_')[0];
|
|
|
|
|
|
// 该批次最后一个拼箱记录
|
2024-07-05 16:49:00 +08:00
|
|
|
|
WmGoodsNowProduction lastConsolidationPackage = Context
|
|
|
|
|
|
.Queryable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.PackageCodeClient.Contains(shortPatchCode + "_4"))
|
|
|
|
|
|
.OrderBy(it => it.PackageCodeClient, OrderByType.Desc)
|
|
|
|
|
|
.First();
|
2024-04-19 14:00:33 +08:00
|
|
|
|
string newPatchCode1 = shortPatchCode;
|
|
|
|
|
|
string newPatchCode2 = shortPatchCode;
|
2024-04-22 11:12:58 +08:00
|
|
|
|
// 检测包装是否已打印4XX标签
|
|
|
|
|
|
// 该工单标签最大一个
|
2024-07-05 16:49:00 +08:00
|
|
|
|
var packingrecordExp = Expressionable
|
|
|
|
|
|
.Create<WmPackingrecord>()
|
2024-04-22 11:12:58 +08:00
|
|
|
|
.And(it => it.WorkOrderNum == mainPackage.WorkoderID)
|
|
|
|
|
|
.And(it => it.Machine == "4")
|
|
|
|
|
|
.And(it => !it.PackingCode.Contains("Iminate"))
|
|
|
|
|
|
.ToExpression();
|
2024-07-05 16:49:00 +08:00
|
|
|
|
WmPackingrecord lastPackingrecord = Context
|
|
|
|
|
|
.Queryable<WmPackingrecord>()
|
2024-04-22 11:12:58 +08:00
|
|
|
|
.Where(packingrecordExp)
|
|
|
|
|
|
.OrderBy(it => it.PackingCode, OrderByType.Desc)
|
|
|
|
|
|
.First();
|
2024-04-19 14:00:33 +08:00
|
|
|
|
int lastCode = 400;
|
2024-05-10 14:57:47 +08:00
|
|
|
|
// 优先处理箱打印有历史数据情况
|
|
|
|
|
|
if (lastPackingrecord != null)
|
2024-04-19 14:00:33 +08:00
|
|
|
|
{
|
2024-05-10 14:57:47 +08:00
|
|
|
|
int subIndex = lastPackingrecord.PackingCode.Length - 5;
|
|
|
|
|
|
// XXX 此代码中 AsSpan 方法 .NET Framework 4.7.2 不支持需要更高版本 或替换为 Substring
|
2024-07-05 16:49:00 +08:00
|
|
|
|
if (
|
|
|
|
|
|
int.TryParse(
|
|
|
|
|
|
lastPackingrecord.PackingCode.AsSpan(subIndex).TrimStart('0'),
|
|
|
|
|
|
out int lastPackingrecordCode
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2024-04-22 11:12:58 +08:00
|
|
|
|
{
|
2024-05-10 14:57:47 +08:00
|
|
|
|
if (lastPackingrecordCode > lastCode)
|
2024-04-22 11:12:58 +08:00
|
|
|
|
{
|
2024-05-10 14:57:47 +08:00
|
|
|
|
lastCode = lastPackingrecordCode;
|
2024-04-22 11:12:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-10 14:57:47 +08:00
|
|
|
|
else
|
2024-04-19 14:00:33 +08:00
|
|
|
|
{
|
2024-05-10 14:57:47 +08:00
|
|
|
|
throw new Exception("生成标签数据异常:" + lastPackingrecord.PackingCode);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-06-07 11:04:26 +08:00
|
|
|
|
if (lastConsolidationPackage != null)
|
2024-05-10 14:57:47 +08:00
|
|
|
|
{
|
2024-07-05 16:49:00 +08:00
|
|
|
|
if (
|
|
|
|
|
|
int.TryParse(
|
|
|
|
|
|
lastConsolidationPackage.PackageCodeClient.Split('_')[1],
|
|
|
|
|
|
out int lastConsolidationPackageCode
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2024-05-10 14:57:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (lastConsolidationPackageCode > lastCode)
|
2024-04-19 14:00:33 +08:00
|
|
|
|
{
|
2024-05-10 14:57:47 +08:00
|
|
|
|
lastCode = lastConsolidationPackageCode;
|
2024-04-19 14:00:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-10 14:57:47 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("生成标签数据异常:" + lastConsolidationPackage.PackageCodeClient);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (lastCode > 400)
|
|
|
|
|
|
{
|
|
|
|
|
|
newPatchCode1 += "_" + (lastCode + 1);
|
|
|
|
|
|
newPatchCode2 += "_" + (lastCode + 2);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
newPatchCode1 += "_401";
|
|
|
|
|
|
newPatchCode2 += "_402";
|
2024-04-19 14:00:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
int firstNum = parm.firstNum;
|
2024-04-20 10:46:36 +08:00
|
|
|
|
|
2024-04-19 14:00:33 +08:00
|
|
|
|
int? secondNum = mainNowProduction.GoodsNumAction - firstNum;
|
|
|
|
|
|
if (secondNum <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
description += "\n拆箱结果1:" + newPatchCode1 + "数量为" + firstNum + "个";
|
|
|
|
|
|
description += "\n拆箱结果2:" + newPatchCode2 + "数量为" + secondNum + "个";
|
|
|
|
|
|
DateTime nowTime = DateTime.Now.ToLocalTime();
|
|
|
|
|
|
var jsonObject = new
|
|
|
|
|
|
{
|
2024-04-26 11:22:33 +08:00
|
|
|
|
// 主箱信息
|
2024-04-19 14:00:33 +08:00
|
|
|
|
mainPackage = mainPackage,
|
2024-04-26 11:22:33 +08:00
|
|
|
|
// 新标签1
|
2024-04-19 14:00:33 +08:00
|
|
|
|
newPatchCode1 = newPatchCode1,
|
2024-04-26 11:22:33 +08:00
|
|
|
|
// 新流水号1
|
|
|
|
|
|
serialNumber1 = newPatchCode1.Split("_")[1],
|
|
|
|
|
|
// 新标签2
|
2024-04-19 14:00:33 +08:00
|
|
|
|
newPatchCode2 = newPatchCode2,
|
2024-04-26 11:22:33 +08:00
|
|
|
|
// 新流水号2
|
|
|
|
|
|
serialNumber2 = newPatchCode2.Split("_")[1],
|
|
|
|
|
|
// 拆箱1数量
|
2024-04-19 14:00:33 +08:00
|
|
|
|
firstNum = firstNum,
|
2024-04-26 11:22:33 +08:00
|
|
|
|
// 拆箱2数量
|
2024-04-19 14:00:33 +08:00
|
|
|
|
secondNum = secondNum,
|
2024-04-26 11:22:33 +08:00
|
|
|
|
// 班组
|
|
|
|
|
|
Team = "C",
|
|
|
|
|
|
// 全部箱子零件号
|
|
|
|
|
|
newPartnumber = mainPackage.PartNumner,
|
|
|
|
|
|
// 拆箱时间
|
2024-04-19 14:00:33 +08:00
|
|
|
|
time = DateUtils.FormatDate(nowTime)
|
|
|
|
|
|
};
|
|
|
|
|
|
// 日志记录
|
2024-07-05 16:49:00 +08:00
|
|
|
|
WmGoodsChangeLog log =
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
CreatedBy = parm.CreateBy,
|
|
|
|
|
|
CreatedTime = nowTime,
|
|
|
|
|
|
Description = description,
|
|
|
|
|
|
JsonMsg = JsonSerializer.Serialize(jsonObject),
|
|
|
|
|
|
Type = 2
|
|
|
|
|
|
};
|
2024-04-19 14:00:33 +08:00
|
|
|
|
Context.Insertable(log).ExecuteReturnEntity();
|
2024-04-23 11:02:38 +08:00
|
|
|
|
//TODO 20240422开会讨论结果:拆箱完需要重新扫码入库,原主箱数据删除
|
2024-07-05 16:49:00 +08:00
|
|
|
|
Context
|
|
|
|
|
|
.Deleteable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.Id == mainNowProduction.Id)
|
|
|
|
|
|
.ExecuteCommand();
|
2024-05-10 14:57:47 +08:00
|
|
|
|
//TODO 20240510 添加待打印的记录
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.BeginTran();
|
2024-07-05 16:49:00 +08:00
|
|
|
|
WmPackageLcl packageLcl1 =
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = SnowFlakeSingle.instance.NextId().ToString(),
|
|
|
|
|
|
Partnumber = mainNowProduction.Partnumber,
|
|
|
|
|
|
WorkOrderId = jsonObject.newPatchCode1.Substring(3, 9),
|
|
|
|
|
|
PackageCode = jsonObject.newPatchCode1,
|
|
|
|
|
|
SerialNumber = jsonObject.serialNumber1,
|
|
|
|
|
|
LocationCode = mainNowProduction.LocationCode,
|
|
|
|
|
|
GoodsNum = jsonObject.firstNum,
|
|
|
|
|
|
Team = "C",
|
|
|
|
|
|
Type = 2,
|
|
|
|
|
|
Status = 0,
|
|
|
|
|
|
CreatedBy = "拆箱",
|
|
|
|
|
|
CreatedTime = nowTime,
|
|
|
|
|
|
Remark = "拆箱1"
|
|
|
|
|
|
};
|
2024-05-10 14:57:47 +08:00
|
|
|
|
Context.Insertable(packageLcl1).ExecuteCommand();
|
2024-07-05 16:49:00 +08:00
|
|
|
|
WmPackageLcl packageLcl2 =
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = SnowFlakeSingle.instance.NextId().ToString(),
|
|
|
|
|
|
Partnumber = mainNowProduction.Partnumber,
|
|
|
|
|
|
WorkOrderId = jsonObject.newPatchCode2.Substring(3, 9),
|
|
|
|
|
|
PackageCode = jsonObject.newPatchCode2,
|
|
|
|
|
|
SerialNumber = jsonObject.serialNumber2,
|
|
|
|
|
|
LocationCode = "LS",
|
|
|
|
|
|
GoodsNum = jsonObject.secondNum ?? 0,
|
|
|
|
|
|
Team = "C",
|
|
|
|
|
|
Type = 2,
|
|
|
|
|
|
Status = 0,
|
|
|
|
|
|
CreatedBy = "拆箱",
|
|
|
|
|
|
CreatedTime = nowTime,
|
|
|
|
|
|
Remark = "拆箱2"
|
|
|
|
|
|
};
|
2024-05-10 14:57:47 +08:00
|
|
|
|
Context.Insertable(packageLcl2).ExecuteCommand();
|
|
|
|
|
|
Context.Ado.CommitTran();
|
|
|
|
|
|
return log;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
|
throw new Exception("生成打印标签信息异常!" + ex);
|
|
|
|
|
|
}
|
2024-04-26 11:22:33 +08:00
|
|
|
|
return log;
|
2024-04-19 14:00:33 +08:00
|
|
|
|
// 执行修改
|
|
|
|
|
|
// 1.主箱修改为1号分箱参数
|
|
|
|
|
|
WmGoodsNowProduction newPackage1 = mainNowProduction;
|
|
|
|
|
|
newPackage1.UpdatedBy = parm.CreateBy;
|
|
|
|
|
|
newPackage1.UpdatedTime = nowTime;
|
|
|
|
|
|
newPackage1.PackageCodeClient = newPatchCode1;
|
2024-07-05 16:49:00 +08:00
|
|
|
|
newPackage1.PackageCodeOriginal =
|
|
|
|
|
|
"Code="
|
|
|
|
|
|
+ newPatchCode1
|
|
|
|
|
|
+ "^ItemNumber="
|
|
|
|
|
|
+ newPackage1.Partnumber
|
|
|
|
|
|
+ "^Order="
|
|
|
|
|
|
+ newPatchCode1.Split('_')[0].Substring(2)
|
|
|
|
|
|
+ "^Qty="
|
|
|
|
|
|
+ firstNum;
|
2024-04-19 14:00:33 +08:00
|
|
|
|
newPackage1.GoodsNumLogic = firstNum;
|
|
|
|
|
|
newPackage1.GoodsNumAction = firstNum;
|
|
|
|
|
|
newPackage1.Remark = "拆箱";
|
|
|
|
|
|
// 修改主箱
|
2024-07-05 16:49:00 +08:00
|
|
|
|
Context
|
|
|
|
|
|
.Updateable(newPackage1)
|
|
|
|
|
|
.IgnoreColumns(ignoreAllNullColumns: true)
|
|
|
|
|
|
.ExecuteCommand();
|
2024-04-19 14:00:33 +08:00
|
|
|
|
// 2.添加一个分箱
|
|
|
|
|
|
WmGoodsNowProduction newPackage2 = mainNowProduction;
|
|
|
|
|
|
newPackage2.CreatedBy = parm.CreateBy;
|
|
|
|
|
|
newPackage2.CreatedTime = nowTime;
|
|
|
|
|
|
newPackage2.PackageCodeClient = newPatchCode2;
|
2024-07-05 16:49:00 +08:00
|
|
|
|
newPackage2.PackageCodeOriginal =
|
|
|
|
|
|
"Code="
|
|
|
|
|
|
+ newPatchCode2
|
|
|
|
|
|
+ "^ItemNumber="
|
|
|
|
|
|
+ newPackage2.Partnumber
|
|
|
|
|
|
+ "^Order="
|
|
|
|
|
|
+ newPatchCode2.Split('_')[0].Substring(2)
|
|
|
|
|
|
+ "^Qty="
|
|
|
|
|
|
+ secondNum;
|
2024-04-19 14:00:33 +08:00
|
|
|
|
newPackage2.GoodsNumLogic = secondNum;
|
|
|
|
|
|
newPackage2.GoodsNumAction = secondNum;
|
|
|
|
|
|
newPackage2.Remark = "拆箱";
|
|
|
|
|
|
newPackage2.Id = SnowFlakeSingle.Instance.NextId().ToString();
|
2024-04-22 11:12:58 +08:00
|
|
|
|
// 添加分箱
|
|
|
|
|
|
Context.Insertable(newPackage2).ExecuteCommand();
|
2024-04-19 14:00:33 +08:00
|
|
|
|
return log;
|
2024-04-18 11:34:49 +08:00
|
|
|
|
}
|
2024-07-05 16:49:00 +08:00
|
|
|
|
|
2024-04-22 12:25:20 +08:00
|
|
|
|
// 添加包装箱标签记录(暂不使用)
|
2024-07-05 16:49:00 +08:00
|
|
|
|
public void AddPackingrecord(
|
|
|
|
|
|
WmGoodsNowProduction production,
|
|
|
|
|
|
string workOrderId,
|
|
|
|
|
|
bool isFill = false
|
|
|
|
|
|
)
|
2024-04-22 11:12:58 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2024-06-07 11:04:26 +08:00
|
|
|
|
if (int.TryParse(production.PackageCodeClient.Split('_')[1], out int packageNum))
|
|
|
|
|
|
{
|
2024-07-05 16:49:00 +08:00
|
|
|
|
WmPackingrecord packingrecord =
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
PartNum = production.Partnumber,
|
|
|
|
|
|
Machine = "4",
|
|
|
|
|
|
ProductCode = "Iminate_P_0",
|
|
|
|
|
|
PackingCode = workOrderId + packageNum.ToString("00000"),
|
|
|
|
|
|
ScannerContent = production.PackageCodeOriginal,
|
|
|
|
|
|
WorkOrderNum = workOrderId,
|
|
|
|
|
|
BFilled = isFill,
|
|
|
|
|
|
CreateTime = DateTime.Now,
|
|
|
|
|
|
};
|
2024-04-22 11:12:58 +08:00
|
|
|
|
Context.Insertable(packingrecord).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("包装箱标签批次号数量解析失败!");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("包装箱标签插入失败!" + ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-07-05 16:49:00 +08:00
|
|
|
|
|
|
|
|
|
|
public WmGoodsChangeLog DoConsolidationGoods2(WmGoodsConsolidationDto2 parm)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.BeginTran();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
List<ResultionPackageCodeDto> packageList = parm.PackageList;
|
|
|
|
|
|
if (packageList.Count < 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("至少需要两箱才能拼箱!");
|
|
|
|
|
|
}
|
|
|
|
|
|
//提出主箱
|
|
|
|
|
|
ResultionPackageCodeDto mainPackage =
|
|
|
|
|
|
packageList[0] ?? throw new Exception("主箱信息异常!");
|
|
|
|
|
|
int mainPackageActionNum = parm.MainPackageActionNum;
|
|
|
|
|
|
// 结果数判定
|
|
|
|
|
|
if (mainPackageActionNum < mainPackage.Quantity)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("主箱最终零件数需要大于原零件数!");
|
|
|
|
|
|
}
|
|
|
|
|
|
// 拼箱下标计数器
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
// 拼箱结果
|
|
|
|
|
|
string description = "";
|
|
|
|
|
|
// 最终结果总零件数
|
|
|
|
|
|
int quantityCount = 0;
|
|
|
|
|
|
// 主箱最终新标签
|
|
|
|
|
|
string newMainPackageCode = "";
|
|
|
|
|
|
foreach (ResultionPackageCodeDto package in packageList)
|
|
|
|
|
|
{
|
|
|
|
|
|
index++;
|
|
|
|
|
|
// 箱数据
|
|
|
|
|
|
int packageQuantity = package.Quantity ?? 0;
|
|
|
|
|
|
string patchCode = package.PatchCode ?? "";
|
|
|
|
|
|
// 验证箱
|
|
|
|
|
|
WmGoodsNowProduction wmGoodsNowProduction = Context
|
|
|
|
|
|
.Queryable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.PackageCodeClient == patchCode)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
if (wmGoodsNowProduction == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("该箱不在库存中!批次号:" + patchCode);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 第一箱
|
|
|
|
|
|
if (index == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
description = "\n主箱:" + patchCode + "\n原数量:" + packageQuantity;
|
|
|
|
|
|
quantityCount += packageQuantity;
|
|
|
|
|
|
newMainPackageCode = GetNewPackageCode(package);
|
|
|
|
|
|
// 添加打印记录
|
|
|
|
|
|
AddWmPackageLcl(
|
|
|
|
|
|
1,
|
|
|
|
|
|
newMainPackageCode,
|
|
|
|
|
|
wmGoodsNowProduction,
|
|
|
|
|
|
mainPackageActionNum,
|
|
|
|
|
|
parm.CreateBy
|
|
|
|
|
|
);
|
|
|
|
|
|
// 删除数据
|
|
|
|
|
|
Context
|
|
|
|
|
|
.Deleteable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.PackageCodeClient == patchCode)
|
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 已拼完
|
|
|
|
|
|
if (quantityCount >= mainPackageActionNum)
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 未拼完
|
|
|
|
|
|
// 删除数据
|
|
|
|
|
|
Context
|
|
|
|
|
|
.Deleteable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.PackageCodeClient == patchCode)
|
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
if (packageQuantity + quantityCount < mainPackageActionNum)
|
|
|
|
|
|
{
|
|
|
|
|
|
//1.还没够
|
|
|
|
|
|
description += "\n次箱:" + patchCode + "\n原数量:" + packageQuantity;
|
|
|
|
|
|
description += "\n移动数量:" + packageQuantity;
|
|
|
|
|
|
quantityCount += packageQuantity;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 拼完了
|
|
|
|
|
|
else if (packageQuantity + quantityCount == mainPackageActionNum)
|
|
|
|
|
|
{
|
|
|
|
|
|
//2.刚刚好
|
|
|
|
|
|
description += "\n次箱:" + patchCode + "\n原数量:" + packageQuantity;
|
|
|
|
|
|
description += "\n移动数量:" + packageQuantity;
|
|
|
|
|
|
quantityCount += packageQuantity;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (packageQuantity + quantityCount > mainPackageActionNum)
|
|
|
|
|
|
{
|
|
|
|
|
|
//3.超额了
|
|
|
|
|
|
int surplus = mainPackageActionNum - quantityCount;
|
|
|
|
|
|
description += "\n次箱:" + patchCode + "\n原数量:" + packageQuantity;
|
|
|
|
|
|
description += "\n移动数量" + surplus;
|
|
|
|
|
|
quantityCount = mainPackageActionNum;
|
|
|
|
|
|
// 添加记录
|
|
|
|
|
|
string newPackageCode = GetNewPackageCode(package);
|
|
|
|
|
|
AddWmPackageLcl(
|
|
|
|
|
|
1,
|
|
|
|
|
|
newPackageCode,
|
|
|
|
|
|
wmGoodsNowProduction,
|
|
|
|
|
|
(package.Quantity - surplus) ?? 0,
|
|
|
|
|
|
parm.CreateBy
|
|
|
|
|
|
);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
description += "\n拼箱结果:" + newMainPackageCode + "\n总数量:" + quantityCount;
|
|
|
|
|
|
DateTime nowTime = DateTime.Now.ToLocalTime();
|
|
|
|
|
|
var jsonObject = new
|
|
|
|
|
|
{
|
|
|
|
|
|
packageList,
|
|
|
|
|
|
// 拼箱批次号
|
|
|
|
|
|
newPatchCode = newMainPackageCode,
|
|
|
|
|
|
// 拼箱流水号
|
|
|
|
|
|
serialNumber = newMainPackageCode.Split("_")[1],
|
|
|
|
|
|
// 拼箱数量
|
|
|
|
|
|
newQuantityCount = quantityCount,
|
|
|
|
|
|
// 拼箱班组
|
|
|
|
|
|
Team = "C",
|
|
|
|
|
|
// 拼箱零件号
|
|
|
|
|
|
newPartnumber = mainPackage.PartNumner,
|
|
|
|
|
|
// 拼箱时间
|
|
|
|
|
|
time = DateUtils.FormatDate(nowTime)
|
|
|
|
|
|
};
|
|
|
|
|
|
// 日志记录
|
|
|
|
|
|
WmGoodsChangeLog log =
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
CreatedBy = parm.CreateBy,
|
|
|
|
|
|
CreatedTime = nowTime,
|
|
|
|
|
|
Description = description,
|
|
|
|
|
|
JsonMsg = JsonSerializer.Serialize(jsonObject),
|
|
|
|
|
|
Type = 1
|
|
|
|
|
|
};
|
|
|
|
|
|
Context.Insertable(log).ExecuteReturnEntity();
|
|
|
|
|
|
Context.Ado.CommitTran();
|
|
|
|
|
|
return log;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Ado.RollbackTran();
|
|
|
|
|
|
throw new Exception(ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加包装箱标签打印记录
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="type">类别 1-拼箱 2-拆箱</param>
|
|
|
|
|
|
/// <param name="newPackageCode"> 新标签</param>
|
|
|
|
|
|
/// <param name="oldPackageInfo">旧箱数据</param>
|
|
|
|
|
|
/// <param name="GoodsNum">待打印零件数</param>
|
|
|
|
|
|
/// <param name="createdBy">执行人</param>
|
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
|
public void AddWmPackageLcl(
|
|
|
|
|
|
int type,
|
|
|
|
|
|
string newPackageCode,
|
|
|
|
|
|
WmGoodsNowProduction oldPackageInfo,
|
|
|
|
|
|
int GoodsNum,
|
|
|
|
|
|
string createdBy
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
WmPackageLcl packageLcl =
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = SnowFlakeSingle.instance.NextId().ToString(),
|
|
|
|
|
|
Partnumber = oldPackageInfo.Partnumber,
|
|
|
|
|
|
WorkOrderId = oldPackageInfo.PackageCodeClient.Substring(3, 9),
|
|
|
|
|
|
PackageCode = newPackageCode,
|
|
|
|
|
|
SerialNumber = newPackageCode.Split('_')[1] ?? "500",
|
|
|
|
|
|
LocationCode = "LS",
|
|
|
|
|
|
GoodsNum = GoodsNum,
|
|
|
|
|
|
Team = "C",
|
|
|
|
|
|
Type = 1,
|
|
|
|
|
|
Status = 0,
|
|
|
|
|
|
CreatedBy = createdBy,
|
|
|
|
|
|
CreatedTime = DateTime.Now.ToLocalTime(),
|
|
|
|
|
|
Remark = type == 1 ? "PDA拼箱" : "PDA拆箱"
|
|
|
|
|
|
};
|
|
|
|
|
|
Context.Insertable(packageLcl).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("包装箱标签打印记录插入失败!" + ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetNewPackageCode(ResultionPackageCodeDto resultionPackageCode)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
string shortPatchCode = resultionPackageCode.PatchCode.Split('_')[0];
|
|
|
|
|
|
// 该批次最后一个拼箱记录
|
|
|
|
|
|
WmGoodsNowProduction lastConsolidationPackage = Context
|
|
|
|
|
|
.Queryable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.PackageCodeClient.Contains(shortPatchCode + "_4"))
|
|
|
|
|
|
.OrderBy(it => it.PackageCodeClient, OrderByType.Desc)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
string newPatchCode = shortPatchCode;
|
|
|
|
|
|
// 最终初始编号
|
|
|
|
|
|
int lastCode = 400;
|
|
|
|
|
|
// 检测包装是否已打印4XX标签
|
|
|
|
|
|
// 该工单标签最大一个
|
|
|
|
|
|
var packingrecordExp = Expressionable
|
|
|
|
|
|
.Create<WmPackingrecord>()
|
|
|
|
|
|
.And(it => it.WorkOrderNum == resultionPackageCode.WorkoderID)
|
|
|
|
|
|
.And(it => it.Machine == "4")
|
|
|
|
|
|
.And(it => !it.PackingCode.Contains("Iminate"))
|
|
|
|
|
|
.ToExpression();
|
|
|
|
|
|
WmPackingrecord lastPackingrecord = Context
|
|
|
|
|
|
.Queryable<WmPackingrecord>()
|
|
|
|
|
|
.Where(packingrecordExp)
|
|
|
|
|
|
.OrderBy(it => it.PackingCode, OrderByType.Desc)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
// 优先处理箱打印有历史数据情况
|
|
|
|
|
|
if (lastPackingrecord != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
int subIndex = lastPackingrecord.PackingCode.Length - 5;
|
|
|
|
|
|
// XXX 此代码中 AsSpan 方法 .NET Framework 4.7.2 不支持需要更高版本 或替换为 Substring
|
|
|
|
|
|
if (
|
|
|
|
|
|
int.TryParse(
|
|
|
|
|
|
lastPackingrecord.PackingCode.AsSpan(subIndex).TrimStart('0'),
|
|
|
|
|
|
out int lastPackingrecordCode
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (lastPackingrecordCode > lastCode)
|
|
|
|
|
|
{
|
|
|
|
|
|
lastCode = lastPackingrecordCode;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("生成标签数据异常:" + lastPackingrecord.PackingCode);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 其次处理成品库历史最大数字
|
|
|
|
|
|
if (lastConsolidationPackage != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (
|
|
|
|
|
|
int.TryParse(
|
|
|
|
|
|
lastConsolidationPackage.PackageCodeClient.Split('_')[1],
|
|
|
|
|
|
out int lastConsolidationPackageCode
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 取最大值
|
|
|
|
|
|
if (lastConsolidationPackageCode > lastCode)
|
|
|
|
|
|
{
|
|
|
|
|
|
lastCode = lastConsolidationPackageCode;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception(
|
|
|
|
|
|
"生成新标签数据异常:" + lastConsolidationPackage.PackageCodeClient
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (lastCode > 400)
|
|
|
|
|
|
{
|
|
|
|
|
|
newPatchCode += "_" + (lastCode + 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
newPatchCode += "_401";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return newPatchCode;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("生成新标签失败!" + ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-18 11:34:49 +08:00
|
|
|
|
}
|
2024-07-05 16:49:00 +08:00
|
|
|
|
}
|