成品仓库记录

This commit is contained in:
2024-08-05 17:25:52 +08:00
parent 73fce84068
commit 2c3082fa01
10 changed files with 973 additions and 427 deletions

View File

@@ -10,7 +10,7 @@ namespace ZR.Service.Utils
//解析外箱标签码
public ResultionPackageCodeDto ResolutionPackage(string code)
{
if (code.Contains("^"))
if (code.Contains('^'))
{
// 初步进行解析检测,增加解析成功率
string[] splitstr = code.Split('^');

View File

@@ -0,0 +1,21 @@
using ZR.Model;
using ZR.Model.MES.wms;
using ZR.Model.MES.wms.Dto;
namespace ZR.Service.mes.wms.IService
{
/// <summary>
/// 成品库数据变动表service接口
/// </summary>
public interface IWmGoodsRecordService : IBaseService<WmGoodsRecord>
{
PagedInfo<WmGoodsRecordDto> GetList(WmGoodsRecordQueryDto parm);
WmGoodsRecord GetInfo(string Id);
WmGoodsRecord AddWmGoodsRecord(WmGoodsRecord parm);
int UpdateWmGoodsRecord(WmGoodsRecord parm);
}
}

View File

@@ -1,8 +1,8 @@
using Infrastructure.Attribute;
using SqlSugar;
using System;
using System;
using System.Linq;
using System.Text.RegularExpressions;
using Infrastructure.Attribute;
using SqlSugar;
using ZR.Model.MES.wms;
using ZR.Model.MES.wms.Dto;
using ZR.Service.mes.wms.IService;
@@ -10,30 +10,66 @@ using ZR.Service.Utils;
namespace ZR.Service.mes.wms
{
[AppService(ServiceType = typeof(IWMentryWarehousing_productService), ServiceLifetime = LifeTime.Transient)]
public class WMentryWarehousing_productService : BaseService<WmInfo>, IWMentryWarehousing_productService
[AppService(
ServiceType = typeof(IWMentryWarehousing_productService),
ServiceLifetime = LifeTime.Transient
)]
public class WMentryWarehousing_productService
: BaseService<WmInfo>,
IWMentryWarehousing_productService
{
private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
//货物入库
public int IntoProductwarehouse(WmgoodsDto wmgoods, string createName)
{
List<WmGoodsNowProduction> preparegoodsList = new List<WmGoodsNowProduction>();
if (wmgoods.packagelist != null && wmgoods.packagelist.Count() > 0)
try
{
for (int i = 0; i < wmgoods.packagelist.Count(); i++)
Context.Ado.BeginTran();
List<WmGoodsNowProduction> preparegoodsList = new();
string location = wmgoods.location;
if (string.IsNullOrEmpty(wmgoods.location))
{
ResultionPackageCodeDto resultionPackage = ResolutionPackage(wmgoods.packagelist[i]);
// XXX 入库时查出此批次号箱已入库,则跳过
bool hasWarehouse = Context.Queryable<WmGoodsNowProduction>().Where(it => it.PackageCodeClient == resultionPackage.PatchCode).Any();
location = "LS";
}
string[] packageArray = wmgoods.packagelist;
if (packageArray == null || packageArray.Length <= 0)
{
Context.Ado.RollbackTran();
throw new Exception("无入库箱,请检查传入数据!");
}
// 统计记录
List<string> partnumbers = new();
int totalPackage = 0;
int totalPartnumber = 0;
List<string> packageCodeRemark = new();
for (int i = 0; i < packageArray.Length; i++)
{
// 解析箱标签
ResultionPackageCodeDto resultionPackage = ResolutionPackage(packageArray[i]);
if (resultionPackage == null)
{
Context.Ado.RollbackTran();
throw new Exception("其中一箱外标签解析失败,第" + (i + 1) + "箱");
}
// 入库时查出此批次号箱已入库,则报警提示
bool hasWarehouse = Context
.Queryable<WmGoodsNowProduction>()
.Where(it => it.PackageCodeClient == resultionPackage.PatchCode)
.Any();
if (hasWarehouse)
{
continue;
Context.Ado.RollbackTran();
throw new Exception("箱" + resultionPackage.PatchCode + "已在库中,不可重复入库!");
}
WmGoodsNowProduction wmGood = new WmGoodsNowProduction();
wmGood.Id = SnowFlakeSingle.Instance.NextId().ToString();
// 通过校验,插入入库数据
totalPackage++;
totalPartnumber += resultionPackage.Quantity ?? 0;
packageCodeRemark.Add(resultionPackage.PatchCode);
WmGoodsNowProduction wmGood = new WmGoodsNowProduction
{
Id = SnowFlakeSingle.Instance.NextId().ToString()
};
string flow = resultionPackage.PatchCode.Split('_')[1];
int flow_num = 0;
try
@@ -44,63 +80,89 @@ namespace ZR.Service.mes.wms
{
flow_num = -1;
}
wmGood.PackageCode = Getpack_no(resultionPackage.WorkoderID, flow_num.ToString("000"));
wmGood.PackageCode =
Getpack_no(resultionPackage.WorkoderID, flow_num.ToString("000"))
?? "Iminate";
wmGood.PackageCodeClient = resultionPackage.PatchCode;
wmGood.Partnumber = resultionPackage.PartNumner;
if (!partnumbers.Contains(wmGood.Partnumber))
{
partnumbers.Add(wmGood.Partnumber);
}
wmGood.PackageCodeOriginal = resultionPackage.originalCode;
wmGood.LocationCode = wmgoods.location;
wmGood.LocationCode = location;
string workorder_id = resultionPackage.WorkoderID;
//wmGood.GoodsNumLogic = Context.Queryable<WmPackingrecord>()
// .Where(it => it.WorkOrderNum == workorder_id)
// .Count();
wmGood.GoodsNumLogic = (resultionPackage.Quantity) ?? 0;
wmGood.GoodsNumAction = wmGood.GoodsNumLogic;
wmGood.EntryWarehouseTime = DateTime.Now;
wmGood.CreatedBy = createName;
wmGood.CreatedTime = DateTime.Now;
preparegoodsList.Add(wmGood);
}
}
// 修改入库检验 为入库完成 WmFgentryInspect
UseTran2(() =>
{
if (preparegoodsList != null && preparegoodsList.Count() > 0)
// 修改入库检验 为入库完成 WmFgentryInspect
if (preparegoodsList != null && preparegoodsList.Count > 0)
{
foreach (var preparegood in preparegoodsList)
{
if (!string.IsNullOrEmpty(preparegood.PackageCode))
{
Context.Updateable<WmFgentryInspect>()
.SetColumns(it => it.Bitwm == 1)
.Where(it => it.Packcode == preparegood.PackageCode)
.ExecuteCommand();
Context
.Updateable<WmFgentryInspect>()
.SetColumns(it => it.Bitwm == 1)
.Where(it => it.Packcode == preparegood.PackageCode)
.ExecuteCommand();
}
}
}
});
int result = Context.Insertable(preparegoodsList).ExecuteCommand();
return result;
int result = Context.Insertable(preparegoodsList).ExecuteCommand();
if (result == 0)
{
Context.Ado.RollbackTran();
throw new Exception("入库记录插入失败");
}
packageCodeRemark.Sort();
// 插入记录
WmGoodsRecord record =
new()
{
Id = SnowFlakeSingle.Instance.NextId().ToString(),
FkInventoryId = SnowFlakeSingle.Instance.NextId().ToString(),
Code = "PDA_IN",
Partnumber = string.Join(',', partnumbers),
BlankNum = "",
ChangeType = 1,
ChangeQuantity = totalPartnumber,
ActionTime = DateTime.Now,
Status = 1,
Remark =
"PDA入库"
+ "\n仓库号:"
+ location
+ "\n总箱数:"
+ totalPackage
+ "\n总零件数:"
+ totalPartnumber
+ "\n涉及批次号:\n"
+ string.Join(',', packageCodeRemark),
CreatedBy = createName,
CreatedTime = DateTime.Now,
};
int recordNum = Context.Insertable(record).ExecuteCommand();
if (recordNum == 0)
{
Context.Ado.RollbackTran();
throw new Exception("操作记录插入失败");
}
Context.Ado.CommitTran();
return result;
}
catch (Exception e)
{
Context.Ado.RollbackTran();
throw new Exception(e.Message);
}
}
/// <summary>
/// 获取mes的箱子码
/// </summary>
@@ -109,14 +171,12 @@ namespace ZR.Service.mes.wms
/// <returns></returns>
private string Getpack_no(string workordorid, string flow)
{
WmPackingrecord record = Context.Queryable<WmPackingrecord>()
WmPackingrecord record = Context
.Queryable<WmPackingrecord>()
.Where(it => it.WorkOrderNum == workordorid)
.Where(it => it.PackingCode.EndsWith(flow))
.First();
if (record == null)
{
return null;
@@ -135,15 +195,13 @@ namespace ZR.Service.mes.wms
}
string packingCode = Identity.PatchCode.Split('_')[1];
bool isExist = Context.Queryable<WmPackingrecord>()
bool isExist = Context
.Queryable<WmPackingrecord>()
.Where(it => it.WorkOrderNum == Identity.WorkoderID)
.Where(it => it.PackingCode.EndsWith(packingCode))
.Where(it => it.BFilled == true)
.Any();
return isExist;
}
@@ -154,31 +212,24 @@ namespace ZR.Service.mes.wms
/// <returns></returns>
public int isProductionPackage(string production_packcode)
{
Regex r = new Regex("Code=BNW\\d{9}_\\d{0,3}");
//todo 不是箱子
if (!r.IsMatch(production_packcode))
{
return 2;
}
ResultionPackageCodeDto Identity = ResolutionPackage(production_packcode);
if (Identity == null)
{
return 0;
}
string packingCode = Identity.PatchCode.Split('_')[1];
bool isExist = Context.Queryable<WmPackingrecord>()
bool isExist = Context
.Queryable<WmPackingrecord>()
.Where(it => it.WorkOrderNum == Identity.WorkoderID)
.Where(it => it.PackingCode.EndsWith(packingCode))
.Any();
@@ -187,29 +238,30 @@ namespace ZR.Service.mes.wms
return 0;
}
return 1;
}
//1 判断是否为库位码
bool IWMentryWarehousing_productService.IsProductionLoacation(string production_location_code)
bool IWMentryWarehousing_productService.IsProductionLoacation(
string production_location_code
)
{
return Context.Queryable<WmInfo>().Where(it => it.WarehouseNum == 1)
.Where(it => it.Location.Equals(production_location_code)).Any();
return Context
.Queryable<WmInfo>()
.Where(it => it.WarehouseNum == 1)
.Where(it => it.Location.Equals(production_location_code))
.Any();
}
//获取库位已经存在的货物
public List<WmGoodsNowProduction> Getpackagelist(string location)
{
return Context.Queryable<WmGoodsNowProduction>().Where(it => it.LocationCode == location).ToList();
return Context
.Queryable<WmGoodsNowProduction>()
.Where(it => it.LocationCode == location)
.ToList();
}
//解析外箱标签码
public ResultionPackageCodeDto ResolutionPackage(string code)
{
@@ -222,7 +274,8 @@ namespace ZR.Service.mes.wms
return null;
}
string SerialNumber = packageCodeDto.PatchCode.Split('_')[1] ?? "000";
WmPackageLcl packageLcl = Context.Queryable<WmPackageLcl>()
WmPackageLcl packageLcl = Context
.Queryable<WmPackageLcl>()
.Where(it => it.WorkOrderId == packageCodeDto.WorkoderID)
.Where(it => it.SerialNumber == SerialNumber)
.OrderByDescending(it => it.CreatedTime)
@@ -268,7 +321,6 @@ namespace ZR.Service.mes.wms
return null;*/
}
/// <summary>
/// 判断箱子是否在成品库中
/// </summary>
@@ -279,10 +331,12 @@ namespace ZR.Service.mes.wms
{
ResultionPackageCodeDto resultionPackage = ResolutionPackage(originalCode);
return Context.Queryable<WmGoodsNowProduction>().Where(it => it.PackageCodeClient == resultionPackage.PatchCode).Any();
return Context
.Queryable<WmGoodsNowProduction>()
.Where(it => it.PackageCodeClient == resultionPackage.PatchCode)
.Any();
}
// 检查是否可入库(返回ok 可入库,其余返回情况)【使用中接口】
public string checkWarehousing(string production_packcode, string location, bool isStrict)
{
@@ -299,21 +353,29 @@ namespace ZR.Service.mes.wms
return "标签解析异常!";
}
// 2.1判断是否已入库
bool isExistedWarehouse = Context.Queryable<WmGoodsNowProduction>().Where(it => it.PackageCodeClient == resultionPackage.PatchCode).Any();
bool isExistedWarehouse = Context
.Queryable<WmGoodsNowProduction>()
.Where(it => it.PackageCodeClient == resultionPackage.PatchCode)
.Any();
if (isExistedWarehouse)
{
return "该箱号已入库!";
}
// 2.2判断是否有出库记录
bool isoutWarehouse = Context.Queryable<WmGoodsOutRecord>().Where(it => it.PackageCodeClient == resultionPackage.PatchCode).Any();
bool isoutWarehouse = Context
.Queryable<WmGoodsOutRecord>()
.Where(it => it.PackageCodeClient == resultionPackage.PatchCode)
.Any();
if (isoutWarehouse)
{
return "该箱号已有出库记录,需要删除后再入库!";
}
// 提取库位信息
WmInfo wmInfo = Context.Queryable<WmInfo>().Where(it => it.Location == location).First();
WmInfo wmInfo = Context
.Queryable<WmInfo>()
.Where(it => it.Location == location)
.First();
if (wmInfo == null)
{
return "库位参数异常";
@@ -324,11 +386,14 @@ namespace ZR.Service.mes.wms
string package_no = resultionPackage.PatchCode.Split("_")[1];
// 3.1 isStrict = TRUE 时判断是否是满箱标签
WmPackingrecord recourd = Context.Queryable<WmPackingrecord>()
WmPackingrecord recourd = Context
.Queryable<WmPackingrecord>()
.Where(it => it.WorkOrderNum == resultionPackage.WorkoderID)
// .Where(it => it.PackingCode.EndsWith(packingCode))
// .Where(it => packingCode == int.Parse(it.PackingCode.Substring(7)).ToString())
.Where(it => package_no == int.Parse(SqlFunc.Right(it.PackingCode, 5)).ToString())
.Where(it =>
package_no == int.Parse(SqlFunc.Right(it.PackingCode, 5)).ToString()
)
.Where(it => it.BFilled == true)
.First();
if (recourd == null)
@@ -336,11 +401,12 @@ namespace ZR.Service.mes.wms
return "该标签不为满箱标签!请入临时仓库!";
}
//3.2 GP12检测
var inspect = Context.Queryable<WmFgentryInspect>()
.Where(it => it.Workorder == resultionPackage.WorkoderID)
.Where(it => it.Packcode.EndsWith(package_no))
.OrderByDescending(it => it.CreatedTime)
.First();
var inspect = Context
.Queryable<WmFgentryInspect>()
.Where(it => it.Workorder == resultionPackage.WorkoderID)
.Where(it => it.Packcode.EndsWith(package_no))
.OrderByDescending(it => it.CreatedTime)
.First();
// XXX 添加校验如果是编号为4号的打印机打出来的就跳过GP12满箱与测试标签校验
if (recourd.Machine != "4")
{
@@ -371,7 +437,10 @@ namespace ZR.Service.mes.wms
flow_num = -1;
}
//mes追溯码
string PackageCode = Getpack_no(resultionPackage.WorkoderID, flow_num.ToString("000"));
string PackageCode = Getpack_no(
resultionPackage.WorkoderID,
flow_num.ToString("000")
);
if (PackageCode == null)
{
return "该标签可能为测试标签,不可追溯!请入临时仓库!";
@@ -383,8 +452,6 @@ namespace ZR.Service.mes.wms
{
return "标签存在异常!" + e.Message;
}
}
}
}

View File

@@ -0,0 +1,96 @@
using Infrastructure.Attribute;
using SqlSugar;
using System;
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(IWmGoodsRecordService), ServiceLifetime = LifeTime.Transient)]
public class WmGoodsRecordService : BaseService<WmGoodsRecord>, IWmGoodsRecordService
{
/// <summary>
/// 查询成品库数据变动表列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public PagedInfo<WmGoodsRecordDto> GetList(WmGoodsRecordQueryDto parm)
{
var predicate = Expressionable.Create<WmGoodsRecord>()
.AndIF(parm.ChangeType > 0, it => it.ChangeType == parm.ChangeType)
.AndIF(!string.IsNullOrEmpty(parm.Partnumber), it => it.Partnumber.Contains(parm.Partnumber))
.AndIF(!string.IsNullOrEmpty(parm.Code), it => it.Code.Contains(parm.Code))
.AndIF(!string.IsNullOrEmpty(parm.Remark), it => it.Remark.Contains(parm.Remark))
.AndIF(!string.IsNullOrEmpty(parm.CreatedBy), it => it.CreatedBy.Contains(parm.CreatedBy))
// 当天0点
.AndIF(parm.StartActionTime > DateTime.MinValue, it => it.ActionTime >= parm.StartActionTime.Value.ToLocalTime())
// 当天23点59分59秒
.AndIF(parm.EndActionTime > DateTime.MinValue, it => it.ActionTime <= parm.EndActionTime.Value.ToLocalTime())
;
var response = Queryable()
.Where(predicate.ToExpression())
.ToPage<WmGoodsRecord, WmGoodsRecordDto>(parm);
return response;
}
/// <summary>
/// 获取详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public WmGoodsRecord GetInfo(string Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
.First();
return response;
}
/// <summary>
/// 添加成品库数据变动表
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public WmGoodsRecord AddWmGoodsRecord(WmGoodsRecord model)
{
return Context.Insertable(model).ExecuteReturnEntity();
}
/// <summary>
/// 修改成品库数据变动表
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int UpdateWmGoodsRecord(WmGoodsRecord model)
{
//var response = Update(w => w.Id == model.Id, it => new WmGoodsRecord()
//{
// Code = model.Code,
// Partnumber = model.Partnumber,
// BlankNum = model.BlankNum,
// ChangeType = model.ChangeType,
// ChangeQuantity = model.ChangeQuantity,
// ActionTime = model.ActionTime,
// Status = model.Status,
// Remark = model.Remark,
// CreatedBy = model.CreatedBy,
// CreatedTime = model.CreatedTime,
// UpdatedBy = model.UpdatedBy,
// UpdatedTime = model.UpdatedTime,
//});
//return response;
return Update(model, true);
}
}
}

File diff suppressed because it is too large Load Diff