using Apache.NMS.ActiveMQ.Commands;
|
using Newtonsoft.Json;
|
using Rhea.Common;
|
using System;
|
using System.Collections.Generic;
|
using System.DirectoryServices.ActiveDirectory;
|
using System.Linq;
|
using System.Security.Cryptography;
|
using System.Text;
|
using System.Threading.Tasks;
|
using Tiger.IBusiness;
|
using Tiger.Model;
|
using Tiger.Model.Entitys.WMS.Api;
|
using Tiger.Model.Minsun;
|
|
namespace Tiger.Business.WMS
|
{
|
/// <summary>
|
/// 补印条码
|
/// </summary>
|
public class RePrintBarcode : IRePrintBarcode
|
{
|
#region Propertys & Variables
|
public static string UserCode { get; set; }
|
public static long UserId { get; set; }
|
public static string OrgCode { get; set; }
|
public static List<Inventory> invs { get; set; } = new();
|
public static Inventory CurInv { get; set; }
|
#endregion
|
/// <summary>
|
/// 补印条码
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
public ApiAction<ReprintReturnEntitys> ScanItem(ReprintEntitys input)
|
{
|
var action = new ApiAction<ReprintReturnEntitys>();
|
try
|
{
|
if (input.SN.IsNullOrEmpty())
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("条码不能为空");
|
return action;
|
}
|
|
UserCode = input.AuthOption.UserId;
|
OrgCode = input.AuthOption.OrgCode;
|
|
//解析条码
|
Result<Inventory> result = WMS_ITEM_Biz.WmsItem.Get(input.SN, input.AuthOption, true);
|
if (!result.IsSuccessed)
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = result.LocaleMsg;
|
return action;
|
}
|
CurInv = result.Data;
|
|
if (!CurInv.isExists)
|
{
|
//action.IsSuccessed = false;
|
//action.LocaleMsg = Biz.L($"条码不存在");
|
action.Data = new ReprintReturnEntitys()
|
{
|
Barcode = CurInv.Barcode.SN,
|
MaterialCode = CurInv.Barcode.ItemCode,
|
MaterialName = CurInv.Barcode.ItemName,
|
MaterialStandard = CurInv.Barcode.ItemName,
|
DateCode = (DateTime)CurInv.Barcode.ProdDate,
|
ScanQty = (decimal)CurInv.Barcode.Qty,
|
Unit = CurInv.Barcode.Unit,
|
VenderSName = ""
|
};
|
action.LocaleMsg = Biz.L($"条码[{input.SN}]信息返回成功,如果数量不对请输入数量打印");
|
return action;
|
|
}
|
var suppEnt = Biz.Db.Queryable<BAS_SUPPLIER>().Where(x => x.SUPP_CODE == CurInv.Items[0].SUPP_CODE).First();
|
action.Data = new ReprintReturnEntitys()
|
{
|
Barcode = CurInv.CurPkg.SN,
|
MaterialCode = CurInv.ItemInfo.ITEM_CODE,
|
MaterialName = CurInv.ItemInfo.ITEM_NAME,
|
MaterialStandard = CurInv.ItemInfo.SPEC,
|
DateCode = CurInv.CurPkg.PRINT_DATE,
|
ScanQty = CurInv.CurPkg.QTY,
|
Unit = CurInv.ItemInfo.UNIT,
|
VenderSName = suppEnt?.SUPP_NAME_CN
|
};
|
action.LocaleMsg = Biz.L($"条码[{input.SN}]信息返回成功,如果数量不对请输入数量打印");
|
}
|
catch (Exception ex)
|
{
|
action.CatchExceptionWithLog(ex, $"补印异常");
|
}
|
|
return action;
|
|
}
|
|
/// <summary>
|
/// 供应商退料
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
public ApiAction<ReturnBarcodeReponse> ReturnBarcodeRecord(ReturnBarcodeInput input)
|
{
|
var action = new ApiAction<ReturnBarcodeReponse>();
|
try
|
{
|
DbClient db = Biz.DataSource["XCSJ"].Client;
|
var findBarcode = db.Queryable<WMS_BARCODE>().Where(t => t.BARCODE.ToUpper() == input.Barcode.ToUpper()).First(); //await _barcodeRepository.FirstOrDefaultAsync(t => t.Barcode.ToUpper() == input.Barcode.ToUpper());
|
if (findBarcode == null)
|
{
|
action.IsSuccessed = false;
|
action.Message = $"条码信息有误";
|
return action;
|
}
|
|
//克隆对象
|
var deserializeSettings = new JsonSerializerSettings { ObjectCreationHandling = ObjectCreationHandling.Replace };
|
var nReturnBarcodeNo = $"{input.Barcode}-T";
|
|
//条码一
|
var nReturnBarcode1 = JsonConvert.DeserializeObject<WMS_BARCODE>(JsonConvert.SerializeObject(findBarcode), deserializeSettings);
|
nReturnBarcode1.BARCODE = nReturnBarcodeNo;
|
//nReturnBarcode1.BarcodeStatus = (int)Domain.InvStorageInfoSides.BarcodeStatus.Outstock; //出库状态
|
nReturnBarcode1.PACKQTY = input.Qty;
|
nReturnBarcode1.CURRENTQTY = input.Qty;
|
nReturnBarcode1.INITIALQTY = input.Qty;
|
nReturnBarcode1.Id = Guid.NewGuid().ToString();
|
|
//生成barcode操作
|
//await _barcodeRepository.InsertAsync(nReturnBarcode1);
|
findBarcode.BARCODESTATUS = WMS_BARCODE.InvStorageInfoSides.BarcodeStatus.InValid.GetValue(); //(int)Domain.InvStorageInfoSides.BarcodeStatus.InValid;//状态为无效
|
//await _barcodeRepository.UpdateAsync(findBarcode);
|
|
//新增SRMSNList
|
var nBarcodeList = new WMS_SRMSNList()
|
{
|
|
SOURCETYPE = "WMS",
|
MATERIALCODE = findBarcode.MATERIALCODE,
|
DeliveryNo = findBarcode.SOURCECODE,
|
SmallBarcode = nReturnBarcodeNo,
|
BigBarcode = findBarcode.CARTON,
|
OuterBarcode = findBarcode.PALLET,
|
IncludeQty = input.Qty,
|
production_date = DateTime.Now
|
};
|
//await _wms_srmsnlistRepository.InsertAsync(nBarcodeList);
|
|
//var nWorkShopLotInfo = db.Queryable<WMS_WORKSHOPLOTINFO>() //await _workShopLotInfoRepository.FirstOrDefaultAsync(t => t.Barcode.ToUpper() == input.Barcode.ToUpper());
|
//if (nWorkShopLotInfo == null)
|
//{
|
// throw new UserFriendlyException("扫描的条码不在线边仓中,无法进行退料");
|
//}
|
//var _nWorkShopLotInfo = JsonConvert.DeserializeObject<Domain.InvWorkShopLotInfo>(JsonConvert.SerializeObject(nWorkShopLotInfo), deserializeSettings);
|
//_nWorkShopLotInfo.Barcode = nReturnBarcodeNo;
|
//_nWorkShopLotInfo.LastQty = input.Qty;
|
//_nWorkShopLotInfo.Id = new Guid();
|
//await _workShopLotInfoRepository.InsertAsync(_nWorkShopLotInfo);
|
|
//获取供应商信息
|
var vender = db.Queryable<MesVender>().Where(t => t.VenderCode == findBarcode.SUPPLIERCODE).First(); //await _venderRepository.FirstOrDefaultAsync(t => t.VenderCode == findBarcode.SupplierCode);
|
|
DbClient _db = Biz.DataSource["XCSJ"].Client;
|
//保存到数据库
|
var dbTran = _db.UseTran(() =>
|
{
|
_db.Insertable(nReturnBarcode1).ExecuteCommand();
|
_db.Updateable(findBarcode).ExecuteCommand();
|
//_db.Utilities.PageEach(pkgs, 1000, pageList =>
|
//{
|
// var x = _db.Storageable(pageList, "SRM")
|
// .WhereColumns(t => new { t.SN, t.GHOST_ROW })
|
// .ToStorage();
|
// x.BulkCopy();
|
// x.BulkUpdate(); //.IgnoreColumns(x => x.ID);
|
//});
|
//_db.Fastest<WMS_ITEM_HIS>().BulkCopy(hiss);//插入
|
});
|
if (!dbTran.IsSuccess)
|
{
|
Logger.Scheduler.Error($"退料异常,错误:[{dbTran.ErrorException.Message}]");
|
}
|
|
action.Data = new ReturnBarcodeReponse
|
{
|
Barcode = nReturnBarcodeNo,
|
VenderSName = vender != null ? vender.VenderName : ""
|
};
|
}
|
catch (Exception ex)
|
{
|
Logger.Scheduler.Error($"退料异常,错误:[{ex.Message}]");
|
}
|
return action;
|
}
|
|
|
/// <summary>
|
/// 退料扫描
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
public ApiAction<RePrintScanReponse> ScanReprintBarcode(IncomingInventoryInput input)
|
{
|
var action = new ApiAction<RePrintScanReponse>();
|
try
|
{
|
DbClient db = Biz.DataSource["XCSJ"].Client;
|
if (input.Barcode.IsNullOrEmpty())
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("请输入或扫描正确的条码");
|
return action;
|
}
|
|
var nDisassembleBarcode = iWMS.SplitFullBarcode(input.Barcode).Data; //await _commonService.SplitFullBarcode(input.Barcode, true);
|
WMS_PO_H nOrderHeader = null;
|
List<WMS_PO_D> nOrderDetails = new List<WMS_PO_D>();
|
if (nDisassembleBarcode.OrderNo != null)
|
{
|
//验证订单是否存在
|
nOrderHeader = db.Queryable<WMS_PO_H>().Where(x => x.BILLCODE == nDisassembleBarcode.OrderNo).First(); //await _headerRepository.FirstOrDefaultAsync(x => x.BillCode.ToUpper() == nDisassembleBarcode.OrderNo.ToUpper());
|
//if (nOrderHeader == null)
|
// throw new UserFriendlyException("条码对应的采购订单不存在");
|
|
if (nOrderHeader != null && nDisassembleBarcode.MaterialCode != null)
|
{
|
//一个订单中存在多行相同物料的情况()
|
nOrderDetails = db.Queryable<WMS_PO_D>().Where(x => x.BILLCODE == nOrderHeader.BILLCODE && x.MATERIALCODE == nDisassembleBarcode.MaterialCode).ToList(); //await _detailRepository.GetAll().Where(x => x.BillCode.ToUpper() == nOrderHeader.BillCode.ToUpper() && x.MaterialCode.ToUpper() == nDisassembleBarcode.MaterialCode.ToUpper()).AsNoTracking().ToListAsync();
|
//if (!nOrderDetails.Any())
|
// throw new UserFriendlyException("条码对应的订单没有该物料的采购信息");
|
|
}
|
|
}
|
var t = 1;
|
//定义条码值
|
var nTempResult = new RePrintScanTempOutput
|
{
|
BillCode = nOrderHeader != null ? nOrderHeader.BILLCODE : "",
|
BillLine = nOrderDetails.Count > 0 ? nOrderDetails.First().BILLLINE : 0, //存在多行相同物料时,这个字段为null,但目前后续的表结构不支持这么操作
|
MaterialCode = nDisassembleBarcode.MaterialCode,
|
MaterialName = nDisassembleBarcode.MaterialName,
|
MaterialStandard = nDisassembleBarcode.MaterialStandard,
|
SupplierCode = nOrderHeader != null ? nOrderHeader.SUPPLIERCODE : "",
|
Barcode = nDisassembleBarcode.Barcode, //批次号即为条码
|
DateCode = nDisassembleBarcode.LotDate,
|
LotNo = nDisassembleBarcode.Barcode,
|
StateFlag = nDisassembleBarcode.StateFlag,
|
ScanQty = nDisassembleBarcode.LotQty, //批次数量
|
Unit = nDisassembleBarcode.Unit
|
};
|
|
|
action.Data = new RePrintScanReponse
|
{
|
ActionType = "SUCCESS",
|
ErrorMessage = "验证通过",
|
Result = nTempResult
|
};
|
}
|
catch (Exception ex)
|
{
|
action.CatchExceptionWithLog(ex, $"退料打印异常");
|
}
|
|
return action;
|
}
|
|
/// <summary>
|
/// 新系统退料扫描
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
public ApiAction<RePrintScanReponse> ScanReprintBarcodeNew(IncomingInventoryInput input)
|
{
|
var action = new ApiAction<RePrintScanReponse>();
|
try
|
{
|
DbClient db = Biz.Db;
|
if (input.Barcode.IsNullOrEmpty())
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("请输入或扫描正确的条码");
|
return action;
|
}
|
//解析条码
|
Result<Inventory> result = WMS_ITEM_Biz.WmsItem.Get(input.Barcode, new AuthOption { ByOrg = true, CurOrg = "DGXC", UserId = "admin" }, false);
|
if (!result.IsSuccessed)
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = result.LocaleMsg;
|
return action;
|
}
|
var CurInv = result.Data;
|
var newItem = CurInv.isExists ? CurInv.Items[0] : new WMS_ITEM()
|
{
|
AUTH_ORG = "DGXC",
|
SN = CurInv.Barcode.SN,
|
ITEM_CODE = CurInv.Barcode.ItemCode,
|
STATUS = WMS_ITEM.STATUSs.Returned.GetValue(),
|
QTY = input.Qty,
|
PROD_DATE = (DateTime)CurInv.Barcode.ProdDate,
|
FIRST_IN_DATE = DateTime.Now,
|
TRANS_CODE = "供应商退料",
|
TRANS_LINE = "",
|
TRANS_NO = CurInv.Barcode.OrderNo,
|
SUPP_CODE = CurInv.Barcode.SupplierCode,
|
CARTON_NO = "",
|
PALLET_NO = "",
|
IS_LOCKED = "N",
|
SOURCE_CODE = "供应商退料",
|
SOURCE_LINE = "",
|
SOURCE_ORDER = CurInv.Barcode.OrderNo,
|
CREATE_USER = "供应商退料",
|
UPDATE_USER = "供应商退料",
|
};
|
newItem.TRANS_CODE = "供应商退料";
|
newItem.TRANS_LINE = "";
|
newItem.SOURCE_CODE = "供应商退料";
|
newItem.SOURCE_LINE = "";
|
newItem.SOURCE_ORDER = CurInv.Barcode.OrderNo;
|
var strSn = newItem.SN.Split("_");
|
var cutSerial = strSn.Length == 1 ? "1" : $"{Convert.ToInt32(strSn[1].Substring(2)) + 1}";
|
var orglSn = strSn[0];
|
var _sn = $"{orglSn}_CT{cutSerial}";
|
newItem.SN = _sn;
|
newItem.QTY = input.Qty;
|
var item = db.Queryable<WMS_ITEM>().Where(x => x.SN == _sn).First();
|
newItem.ID = item != null ? item.ID : newItem.ID;
|
|
var oPkg = db.Queryable<WMS_ITEM_PKG>().Where(x => x.SN == _sn).First();
|
var pkg = CurInv.isExists ? CurInv.CurPkg : new WMS_ITEM_PKG()
|
{
|
AUTH_ORG = "DGXC",
|
SN = _sn,
|
PARENT_SN = "",
|
PKG_TYPE = CurInv.Barcode.SN.StartsWith("P") ? WMS_ITEM_PKG.PKG_TYPEs.Pallet.GetValue() : (CurInv.Barcode.SN.StartsWith("C") ? WMS_ITEM_PKG.PKG_TYPEs.Carton.GetValue() : WMS_ITEM_PKG.PKG_TYPEs.OnePiece.GetValue()),
|
ITEM_CODE = CurInv.Barcode.ItemCode,
|
QTY = input.Qty,
|
TRANS_CODE = "供应商退料",
|
TRANS_NO = CurInv.Barcode.OrderNo,
|
SUPP_CODE = CurInv.Barcode.SupplierCode,
|
};
|
pkg.ID = oPkg != null ? oPkg.ID : pkg.ID;
|
pkg.SN = _sn;
|
pkg.TRANS_CODE = "供应商退料";
|
pkg.TRANS_NO = CurInv.Barcode.OrderNo;
|
pkg.QTY = input.Qty;
|
|
action.Data = new RePrintScanReponse
|
{
|
ActionType = "SUCCESS",
|
ErrorMessage = "验证通过",
|
Result = new RePrintScanTempOutput
|
{
|
BillCode = "",
|
BillLine = 0, //存在多行相同物料时,这个字段为null,但目前后续的表结构不支持这么操作
|
MaterialCode = !CurInv.isExists ? CurInv.Barcode.ItemCode : CurInv.ItemInfo?.ITEM_CODE,
|
MaterialName = !CurInv.isExists ? CurInv.Barcode.ItemName : CurInv.ItemInfo?.ITEM_NAME,
|
MaterialStandard = !CurInv.isExists ? CurInv.Barcode.ItemName : CurInv.ItemInfo?.ITEM_NAME,
|
SupplierCode = !CurInv.isExists ? CurInv.Barcode.SupplierCode : CurInv.Items[0].SUPP_CODE,
|
Barcode = _sn, //批次号即为条码
|
DateCode = !CurInv.isExists ? (DateTime)CurInv.Barcode.ProdDate : CurInv.Items[0].PROD_DATE,
|
LotNo = _sn,
|
StateFlag = "",
|
ScanQty = input.Qty, //批次数量
|
Unit = !CurInv.isExists ? CurInv.Barcode.Unit : CurInv.ItemInfo?.UNIT
|
}
|
};
|
DbClient _db = Biz.Db;
|
//保存到数据库
|
var dbTran = _db.UseTran(() =>
|
{
|
_db.Storageable(newItem, "Supplier").ExecuteCommand();
|
_db.Insertable(new WMS_ITEM_HIS(newItem, "供应商退料打印"), "Supplier").ExecuteCommand();
|
_db.Storageable(pkg, "Supplier").ExecuteCommand();
|
|
//_db.Fastest<WMS_ITEM_HIS>().BulkCopy(hiss);//插入
|
});
|
if (!dbTran.IsSuccess)
|
{
|
Logger.Scheduler.Error($"退料异常,错误:[{dbTran.ErrorException.Message}]");
|
}
|
|
}
|
catch (Exception ex)
|
{
|
action.CatchExceptionWithLog(ex, $"退料打印异常");
|
}
|
|
return action;
|
}
|
}
|
}
|