using Newtonsoft.Json;
|
using Rhea.Common;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using Tiger.Business.SqlSugarHepler;
|
using Tiger.IBusiness;
|
using Tiger.Model;
|
using Tiger.Model.Entitys.WMS.DTOS;
|
|
namespace Tiger.Business.WMS.Transaction
|
{
|
public class Resell : WMSTransactionBase, IResell
|
{
|
/// <summary>
|
/// T100接口URL
|
/// </summary>
|
public string t100Url { get; set; } = @"http://172.18.8.11/wstopprd/ws/r/awsp920";
|
/// <summary>
|
/// 事务初始化函数
|
/// </summary>
|
/// <param name="id"></param>
|
/// <param name="userCode"></param>
|
/// <param name="apiHost"></param>
|
/// <param name="orgCode"></param>
|
/// <returns></returns>
|
public IResell Init(string id, string userCode, string apiHost, string orgCode)
|
{
|
TransID = id;
|
UserCode = userCode;
|
ApiHost = apiHost;
|
OrgCode = orgCode;
|
Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]");
|
return this;
|
}
|
|
|
#region Propertys & Variables
|
public string BillCode { get; set; }
|
public string TARGET_ORG { get; set; }
|
public string UserCode { get; set; }
|
public long UserId { get; set; }
|
public string RackCode { get; set; }
|
public string WarehouseCode { get; set; }
|
public string WarehouseName { get; set; }
|
public string OrgCode { get; set; }
|
public WMS_SHELF Shelf { get; set; }
|
|
public ResellPuton ResellPuton1 { get; set; }
|
public BIZ_ERP_SALE_OUT res { get; set; }
|
#endregion
|
|
/// <summary>
|
/// 获取转卖单列表
|
/// </summary>
|
/// <param name="pageIndex"></param>
|
/// <param name="pageSize"></param>
|
/// <returns></returns>
|
public ApiAction<PageAble<BIZ_ERP_SALE_OUT>> GetResellHeaders(int pageIndex, int pageSize, string orgcode, string billcode)
|
{
|
var action = new ApiAction<PageAble<BIZ_ERP_SALE_OUT>>();
|
var query = Biz.Db.Queryable<BIZ_ERP_SALE_OUT>().Where(x =>
|
(x.STATUS == BIZ_ERP_SALE_OUT.STATUSs.INIT.GetValue()
|
|| x.STATUS == BIZ_ERP_SALE_OUT.STATUSs.WORKING.GetValue())
|
&& x.AUTH_ORG == orgcode)
|
.WhereIF(!billcode.IsNullOrEmpty(), x => x.BILLCODE.Contains(billcode))
|
.OrderByDescending(x => x.UPDATE_TIME.ToString("yyyy-MM-dd"))
|
.OrderBy(x => x.CREATE_TIME)
|
.ToPage(pageIndex, pageSize);
|
action.Data = query;
|
return action;
|
}
|
/// <summary>
|
/// 转卖单选择事件
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
public async Task<ApiAction<Resell_Input>> SelectOrder(ResellInput input)
|
{
|
var action = new ApiAction<Resell_Input>();
|
try
|
{
|
//SelectOrderOption = input.AuthOption;
|
res = await Biz.Db.Queryable<BIZ_ERP_SALE_OUT>().Where(x => x.BILLCODE == input.ResellNo).Includes(q => q.DetailsWithGhost, d => d.ItemInfo).IncludesAllFirstLayer().FirstAsync();
|
//验证明细是否正确
|
if (!res.Details.Any())
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = new("WMS.ProdMReq.SelectOrder.DtlsException", input.ResellNo);
|
return action;
|
}
|
BillCode = input.ResellNo;//单号
|
TARGET_ORG = res.TARGET_ORG;//目标据点
|
//OrgCode//原据点
|
//WareHouseCode//扫描仓库
|
action.LocaleMsg = Biz.L("选择多角转卖单成功");
|
action.Data = new Resell_Input
|
{
|
BILLCODE = BillCode,//单据
|
WAREHOUSECODE = "",//原仓库
|
TARGET_WAREHOUSECODE = "",//目标仓库
|
AUTH_ORG = "",//原据点
|
TARGET_ORG = "",//目标据点
|
};
|
}
|
catch (Exception ex)
|
{
|
action.CatchExceptionWithLog(ex, $"多角转卖单选择异常");
|
}
|
return action;
|
}
|
|
/// <summary>
|
/// 扫描物料并复核,如果物料已经完成移库则货架上亮灯提醒储位
|
/// </summary>
|
public async Task<ApiAction> ScanItem(ResellModel input)
|
{
|
var action = new ApiAction();
|
try
|
{
|
if (string.IsNullOrEmpty(input.SN))
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.SnEmptyFailure"); // $"条码不能为空!";
|
return action;
|
}
|
//货架为空则扫描的认为是货架
|
if (string.IsNullOrEmpty(RackCode))
|
{
|
var _action = await ScanShelf(input.SN);
|
action.LocaleMsg = _action.LocaleMsg;
|
action.IsSuccessed = _action.IsSuccessed;
|
if (!action.IsSuccessed)
|
{
|
action.Data = _action.Data;
|
return action;
|
}
|
else
|
{
|
//调用T100接口传入WarehouseCode,修改业务表信息
|
var To100param = new Resell_Input
|
{
|
BILLCODE=BillCode
|
};
|
|
var query = MaterialToErp(To100param);
|
//调用t100或修改业务表时发生错误
|
if(query.IsSuccessed == false)
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = query.LocaleMsg;
|
return action;
|
}
|
//返回信息
|
action.Data = new Resell_Input
|
{
|
BILLCODE=BillCode,//单据
|
WAREHOUSECODE= RackCode,//原仓库
|
TARGET_WAREHOUSECODE="",//目标仓库
|
AUTH_ORG=OrgCode,//原据点
|
TARGET_ORG=TARGET_ORG,//目标据点
|
};
|
}
|
|
}
|
else
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("该单已操作,请退出重新选单!");
|
return action;
|
}
|
}
|
catch (Exception ex)
|
{
|
//取消当前操作
|
|
action.CatchExceptionWithLog(ex, $"扫描物料[{input.SN}]复核异常");
|
}
|
return action;
|
}
|
|
/// <summary>
|
/// 扫描货架或者储位
|
/// </summary>
|
public async Task<ApiAction<ResellPuton>> ScanShelf(string Code)
|
{
|
var action = new ApiAction<ResellPuton>();
|
try
|
{
|
if (Code.IsNullOrEmpty())
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.ShelfCanNotEmpty");
|
return action;
|
}
|
|
ResellPuton1 = new ResellPuton();
|
|
// 查询货架信息
|
var whUnit = await Biz.Db.Queryable<V_WH_UNIT>().Where(t => t.WH_CODE.ToUpper() == Code.ToUpper() && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync();
|
|
// 扫描货架代码,且为智能货架
|
if (whUnit != null && whUnit.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.Smart.GetValue())
|
{
|
ResellPuton1.WarehouseCode = whUnit.WH_CODE;
|
ResellPuton1.RackCode = whUnit.SHELF_CODE;
|
ResellPuton1.ShelfType = whUnit.SHELF_TYPE;
|
ResellPuton1.IsSmartRack = true;
|
Shelf = whUnit.Shelf;
|
|
}
|
// 扫描库位代码
|
else
|
{
|
var nWh_code = await Biz.Db.Queryable<V_WH_UNIT>().Where(t => t.WH_CODE.ToUpper() == Code.ToUpper() && t.AUTH_ORG == OrgCode).FirstAsync();
|
if (nWh_code == null)
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.NotExist", Code);
|
return action;
|
}
|
|
if (nWh_code.IS_ACTIVE == "N")
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L("WMS.CustSupChk.ScanItem.ShelfOrLocationDisabled");
|
return action;
|
}
|
//if (nWh_code.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.Smart.GetValue() || nWh_code.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.QRCode.GetValue())
|
//{
|
// var locationData = Biz.Db.Queryable<WMS_ITEM>().Where(q => q.LOCATION_ID == nWh_code.LOCATION_ID && q.AUTH_ORG == OrgCode).First();
|
// if (!locationData.IsNullOrEmpty())
|
// {
|
// action.IsSuccessed = false;
|
// action.LocaleMsg = Biz.L($"系统当前库位存在料盘,请检查系统库存信息");
|
// return action;
|
|
// }
|
//}
|
|
ResellPuton1.LocationCode = nWh_code.LOCATION_CODE;
|
ResellPuton1.WarehouseCode = nWh_code.WH_CODE;
|
//CustomerSupplyPuton.Capacity = nLocation.MAXSIZE - nUsedCapacity;
|
//CustomerSupplyPuton.LotCount = nLocation.LOTCOUNT;
|
//CustomerSupplyPuton.MaxSize = nLocation.MAXSIZE;
|
ResellPuton1.IsSmartRack = false;
|
ResellPuton1.RackCode = nWh_code.SHELF_CODE;
|
}
|
WarehouseCode = ResellPuton1.WarehouseCode;
|
RackCode = ResellPuton1.RackCode;
|
ResellPuton1.IsScanShelf = true;
|
action.LocaleMsg = Biz.L("扫描成功");
|
action.Data = ResellPuton1;
|
}
|
catch (Exception ex)
|
{
|
//取消当前操作
|
|
action.CatchExceptionWithLog(ex, $"扫描货架或者储位[{Code}]异常");
|
}
|
return action;
|
}
|
/// <summary>
|
/// 领料单过账到T100
|
/// </summary>
|
/// <param name="param">单号</param>
|
/// <returns></returns>
|
public ApiAction MaterialToErp(Resell_Input param)
|
{
|
var action = new ApiAction();
|
List<Tot100pamar> dtl = new List<Tot100pamar>();
|
//foreach (var item in res.Details)
|
{
|
var t100 = new Tot100pamar()
|
{
|
l_seq="1",
|
imaxuc005=OrgCode,
|
imaxuc006=WarehouseCode,
|
imaxuc002=TARGET_ORG,
|
imaxuc003="",
|
};
|
dtl.Add(t100);
|
}
|
|
//Work.DoAsync(() =>
|
{
|
Thread.Sleep(3000);
|
var authOrg = GetAuthOrg(param.BILLCODE);
|
|
#region 创建请求实体
|
|
var model = new BodyDTO<PayLoad<Std_Data<Tot100>>>()
|
{
|
host = new HostDTO(),
|
datakey = new DataKey()
|
{
|
EntId = "88",
|
CompanyId = authOrg
|
},
|
service = new ServiceDTO()
|
{
|
name = "wms_get_cimm202"
|
},
|
payload = new PayLoad<Std_Data<Tot100>>()
|
{
|
std_data = new Std_Data<Tot100>()
|
{
|
parameter = new Tot100()
|
{
|
pamar = dtl
|
}
|
}
|
}
|
};
|
|
#endregion 创建请求实体
|
|
#region 发起请求
|
|
var result = new T100ActionResult<resultStd_inputdata>();
|
try
|
{
|
var requestJson = JsonConvert.SerializeObject(model);
|
var response = HttpHelper.PostAsync(t100Url, requestJson).Result;
|
result = JsonConvert.DeserializeObject<T100ActionResult<resultStd_inputdata>>(response.Message);
|
Logger.Scheduler.Info($"多角转卖对接T100过账提交Json: {requestJson},返回Json: {response.Message}");
|
}
|
catch (Exception ex)
|
{
|
Logger.Default.Info($"多角转卖对接T100过账失败");
|
//return "0";
|
}
|
|
#endregion 发起请求
|
|
var db = Biz.Db;
|
var items = db.Queryable<WMS_ITEM>().Where(i => i.TRANS_NO == param.BILLCODE).ToList();
|
var items_pkg = db.Queryable<WMS_ITEM_PKG>().Where(i => i.TRANS_NO == param.BILLCODE).ToList();
|
var t100_res = result.payload.parameter?.returns;
|
//var wh_id=db.Queryable<WMS_WAREHOUSE>().Where(q=>q.WH_CODE==WarehouseCode).ToString();
|
List<WMS_ITEM_HIS> ItemHistorys = new List<WMS_ITEM_HIS>();
|
if (result.payload.std_data?.execution.code == "0")
|
{
|
if (items.Count > 0 && items_pkg.Count > 0)
|
{
|
|
foreach (var item in items)
|
{
|
item.AUTH_ORG = TARGET_ORG;
|
item.WH_ID = result.payload.parameter?.returns.FirstOrDefault().imaxuc003;
|
item.SOURCE_CODE = "BIZ_ERP_SALE_OUT";
|
|
|
WMS_ITEM_HIS his = new WMS_ITEM_HIS(item, $"多角转卖,销售单[{BillCode}][{string.Join(",", res.Details.Where(s => s.ITEM_CODE == item.ITEM_CODE).Select(q => q.BILLLINE))}]");
|
ItemHistorys.Add(his);
|
}
|
foreach (var item in items_pkg)
|
{
|
item.AUTH_ORG = TARGET_ORG;
|
item.WH_ID = result.payload.parameter?.returns.FirstOrDefault().imaxuc003;
|
item.SOURCE_CODE = "BIZ_ERP_SALE_OUT";
|
}
|
//业务表头
|
res.AUTH_ORG = TARGET_ORG;
|
res.WAREHOUSECODE = WarehouseCode;
|
res.STATUS = BIZ_ERP_SALE_OUT.STATUSs.COMPLETE.GetValue();
|
//业务表明细
|
foreach (var item in res.Details)
|
{
|
item.AUTH_ORG = TARGET_ORG;
|
item.WAREHOUSECODE = WarehouseCode;
|
item.LINESTATUS = BIZ_ERP_SALE_OUT.STATUSs.COMPLETE.GetValue();
|
}
|
//业务表条码
|
foreach (var item in res.SnList)
|
{
|
item.AUTH_ORG = TARGET_ORG;
|
//item.WAREHOUSECODE = WarehouseCode;
|
item.STATUS = WMS_ITEM.STATUSs.InStore.GetValue();
|
}
|
}
|
else
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L($"库存信息不足");
|
}
|
|
}
|
else
|
{
|
action.IsSuccessed = false;
|
action.LocaleMsg = Biz.L($"T100返回了错误[{result.payload.std_data?.execution.description}]");
|
}
|
//保存到数据库
|
var db2 = Biz.Db;
|
var dbTran = db2.UseTran(() =>
|
{
|
// 插入单据表头
|
db2.Updateable(res, UserCode).ExecuteCommand();
|
var x = db2.Storageable(res.Details, UserCode).ToStorage();
|
x.AsInsertable.ExecuteCommand();//不存在插入
|
x.AsUpdateable.IgnoreColumns(z => new { z.CREATE_TIME, z.CREATE_USER }).ExecuteCommand();//存在更新,更新时忽略字段CreationTime、CreatorUserId
|
|
db2.Updateable(res.SnList, UserCode).ExecuteCommand();
|
|
db2.Updateable(items, UserCode).ExecuteCommand();
|
db2.Updateable(items_pkg, UserCode).ExecuteCommand();
|
db2.Insertable(ItemHistorys, UserCode).ExecuteCommand();
|
|
});
|
if (!dbTran.IsSuccess)
|
{
|
Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception");
|
this.Close(!dbTran.IsSuccess);
|
throw dbTran.ErrorException;
|
}
|
}
|
//});
|
return action;
|
}
|
|
/// <summary>
|
/// 根据工单号获取据点名称
|
/// </summary>
|
/// <param name="workOrder"></param>
|
/// <returns></returns>
|
public string GetAuthOrg(string workOrder)
|
{
|
var authOrg = string.Empty;
|
var org = workOrder.Substring(0, 2);
|
switch (org)
|
{
|
#region 循环取值
|
|
case "PH":
|
authOrg = "PHXC";
|
break;
|
|
case "YX":
|
authOrg = "YXYY";
|
break;
|
|
case "XP":
|
authOrg = "XCXP";
|
break;
|
|
case "XN":
|
authOrg = "XCXN";
|
break;
|
|
case "TH":
|
authOrg = "STTH";
|
break;
|
|
case "XC":
|
authOrg = "XCSJ";
|
break;
|
|
case "DG":
|
authOrg = "DGXC";
|
break;
|
|
case "HK":
|
authOrg = "HKXC";
|
break;
|
|
case "TX":
|
authOrg = "TXXC";
|
break;
|
|
case "LR":
|
authOrg = "XCLR";
|
break;
|
|
case "OM":
|
authOrg = "OMKJ";
|
break;
|
|
case "AH":
|
authOrg = "AHXC";
|
break;
|
|
case "YK":
|
authOrg = "XCYK";
|
break;
|
|
case "CC":
|
authOrg = "XCCC";
|
break;
|
|
case "TC":
|
authOrg = "XCTC";
|
break;
|
|
case "TK":
|
authOrg = "STTK";
|
break;
|
|
case "MM":
|
authOrg = "STMM";
|
break;
|
|
default:
|
throw new Exception($"单号前两位:{org}未能找到对应的据点,请确认!");
|
|
#endregion 循环取值
|
}
|
return authOrg;
|
}
|
|
public override bool Close(bool needSaveHistoryLog = false)
|
{
|
//保存操作日志
|
|
this.IsFinished = true;
|
return IsFinished ? base.Close(needSaveHistoryLog) : IsFinished;
|
}
|
}
|
}
|