352 lines
12 KiB
C#
352 lines
12 KiB
C#
using Infrastructure.Attribute;
|
||
using SqlSugar;
|
||
using System;
|
||
using System.Linq;
|
||
using System.Text.RegularExpressions;
|
||
using ZR.Model.MES.pro;
|
||
using ZR.Model.MES.wms;
|
||
using ZR.Model.MES.wms.Dto;
|
||
using ZR.Service.mes.wms.IService;
|
||
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
|
||
{
|
||
|
||
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)
|
||
{
|
||
for (int i = 0; i < wmgoods.packagelist.Count(); i++)
|
||
{
|
||
|
||
ResultionPackageCodeDto resultionPackage = ResolutionPackage(wmgoods.packagelist[i]);
|
||
// XXX 入库时查出此批次号箱已入库,则跳过
|
||
bool hasWarehouse = Context.Queryable<WmGoodsNowProduction>().Where(it => it.PackageCodeClient == resultionPackage.PatchCode).Any();
|
||
if (hasWarehouse)
|
||
{
|
||
continue;
|
||
}
|
||
WmGoodsNowProduction wmGood = new WmGoodsNowProduction();
|
||
wmGood.Id = SnowFlakeSingle.Instance.NextId().ToString();
|
||
|
||
string flow = resultionPackage.PatchCode.Split('_')[1];
|
||
int flow_num = 0;
|
||
try
|
||
{
|
||
flow_num = Convert.ToInt32(flow);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
flow_num = -1;
|
||
}
|
||
|
||
wmGood.PackageCode = Getpack_no(resultionPackage.WorkoderID, flow_num.ToString("000"));
|
||
|
||
wmGood.PackageCodeClient = resultionPackage.PatchCode;
|
||
wmGood.Partnumber = resultionPackage.PartNumner;
|
||
wmGood.PackageCodeOriginal = resultionPackage.originalCode;
|
||
|
||
wmGood.LocationCode = wmgoods.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) {
|
||
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();
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
}
|
||
|
||
});
|
||
|
||
|
||
int result = Context.Insertable(preparegoodsList).ExecuteCommand();
|
||
return result;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 获取mes的箱子码
|
||
/// </summary>
|
||
/// <param name="workordorid">工单</param>
|
||
/// <param name="flow">序号</param>
|
||
/// <returns></returns>
|
||
private string Getpack_no(string workordorid, string flow)
|
||
{
|
||
|
||
|
||
WmPackingrecord record = Context.Queryable<WmPackingrecord>()
|
||
.Where(it => it.WorkOrderNum == workordorid)
|
||
.Where(it => it.PackingCode.EndsWith(flow))
|
||
.First();
|
||
|
||
|
||
if (record == null)
|
||
{
|
||
return null;
|
||
}
|
||
|
||
return record.ProductCode;
|
||
}
|
||
|
||
//3 判断箱子是否满
|
||
public bool isFullPackage(string production_packcode)
|
||
{
|
||
ResultionPackageCodeDto Identity = ResolutionPackage(production_packcode);
|
||
if (Identity == null)
|
||
{
|
||
return false;
|
||
}
|
||
string packingCode = Identity.PatchCode.Split('_')[1];
|
||
|
||
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 2 判断是否为成品箱子码
|
||
/// </summary>
|
||
/// <param name="production_packcode"></param>
|
||
/// <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>()
|
||
.Where(it => it.WorkOrderNum == Identity.WorkoderID)
|
||
.Where(it => it.PackingCode.EndsWith(packingCode))
|
||
.Any();
|
||
if (!isExist)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
|
||
return 1;
|
||
|
||
}
|
||
//1 判断是否为库位码
|
||
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();
|
||
|
||
}
|
||
|
||
|
||
//获取库位已经存在的货物
|
||
public List<WmGoodsNowProduction> Getpackagelist(string location)
|
||
{
|
||
return Context.Queryable<WmGoodsNowProduction>().Where(it => it.LocationCode == location).ToList();
|
||
|
||
}
|
||
|
||
|
||
|
||
//解析外箱标签码
|
||
public ResultionPackageCodeDto ResolutionPackage(string code)
|
||
{
|
||
MaterialUtils materialToos = new MaterialUtils();
|
||
return materialToos.ResolutionPackage(code);
|
||
/*// 初步进行解析检测,增加解析成功率
|
||
string[] splitstr = code.Split('^');
|
||
if (splitstr.Length < 1)
|
||
{
|
||
return null;
|
||
}
|
||
// 第一类
|
||
if (splitstr[0].Contains("Code="))
|
||
{
|
||
return ResolutionPackagecode1(code);
|
||
}
|
||
// 第二类
|
||
if (splitstr[3].Contains("Cd="))
|
||
{
|
||
return ResolutionPackagecode2(code);
|
||
}
|
||
// 解析失败
|
||
return null;*/
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 判断箱子是否在成品库中
|
||
/// </summary>
|
||
/// <param name="PatchCode"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="NotImplementedException"></exception>
|
||
public bool IsExistedWarehouse(string originalCode)
|
||
{
|
||
ResultionPackageCodeDto resultionPackage = ResolutionPackage(originalCode);
|
||
|
||
return Context.Queryable<WmGoodsNowProduction>().Where(it => it.PackageCodeClient == resultionPackage.PatchCode).Any();
|
||
}
|
||
|
||
|
||
// 检查是否可入库(返回ok 可入库,其余返回情况)【使用中接口】
|
||
public string checkWarehousing(string production_packcode, string location, bool isStrict)
|
||
{
|
||
try
|
||
{
|
||
if (string.IsNullOrEmpty(production_packcode))
|
||
{
|
||
return "扫描结果为空!";
|
||
}
|
||
// 1.判断能否解析
|
||
ResultionPackageCodeDto resultionPackage = ResolutionPackage(production_packcode);
|
||
if (resultionPackage == null)
|
||
{
|
||
return "标签解析异常!";
|
||
}
|
||
|
||
|
||
// 2.判断是否已入库
|
||
bool isExistedWarehouse = Context.Queryable<WmGoodsNowProduction>().Where(it => it.PackageCodeClient == resultionPackage.PatchCode).Any();
|
||
if (isExistedWarehouse)
|
||
{
|
||
return "该箱号已入库!";
|
||
}
|
||
// 提取库位信息
|
||
WmInfo wmInfo = Context.Queryable<WmInfo>().Where(it => it.Location == location).First();
|
||
if (wmInfo == null)
|
||
{
|
||
return "库位参数异常";
|
||
}
|
||
if (isStrict && wmInfo.Remark != "临时")
|
||
{
|
||
// 3. 提取流水号
|
||
string package_no = resultionPackage.PatchCode.Split("_")[1];
|
||
|
||
// 3.1 isStrict = TRUE 时判断是否是满箱标签
|
||
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 => it.BFilled == true)
|
||
.First();
|
||
if (recourd == null)
|
||
{
|
||
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();
|
||
// XXX 添加校验,如果是编号为4号的打印机打出来的就跳过GP12,满箱与测试标签校验
|
||
if (recourd.Machine != "4")
|
||
{
|
||
// 其余不变
|
||
if (inspect == null)
|
||
{
|
||
return "GP12 异常错误 GP12无此箱记录 ";
|
||
}
|
||
if (inspect.Result == 2)
|
||
{
|
||
return "该箱号GP12 检验不合格,不得入库";
|
||
}
|
||
if (inspect.Result == 0 || inspect.Result == null)
|
||
{
|
||
return "该箱号GP12 未检验,不得入库";
|
||
}
|
||
}
|
||
|
||
// 4.isStrict = TRUE时判断能否追溯
|
||
string flow = resultionPackage.PatchCode.Split('_')[1];
|
||
int flow_num = 0;
|
||
try
|
||
{
|
||
flow_num = Convert.ToInt32(flow);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
flow_num = -1;
|
||
}
|
||
//mes追溯码
|
||
string PackageCode = Getpack_no(resultionPackage.WorkoderID, flow_num.ToString("000"));
|
||
if (PackageCode == null)
|
||
{
|
||
return "该标签可能为测试标签,不可追溯!请入临时仓库!";
|
||
}
|
||
}
|
||
return "ok";
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
return "标签存在异常!";
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
}
|