using Apache.NMS.ActiveMQ.Commands;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Rhea.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using Tiger.IBusiness;
using Tiger.Model;
using Tiger.Model.Minsun;
namespace Tiger.Business.WMS
{
public partial class ErpT100 : IErpT100
{
///
/// T100接口URL
///
public static string t100Url { get; set; } = @"http://172.18.8.11/wstopprd/ws/r/awsp920";
public static List curDeliveryNoList { get; set; } = new List();
///
/// 从T100获取二级供应商接口
///
///
///
public static T100ActionResult> GetSecondarySupplyInfo(SupplierInputParameter input)
{
var t100Action = new T100Action>
{
key = Guid.NewGuid().ToString("N"),
type = "sync",
host = new host
{
prod = "WMS",
ip = "",
lang = "zh_CN",
acct = "tiptop",
timestamp = DateTime.Now.ToString("yyyyMMddHHMMssfff"),
},
datakey = input.datakey,
//datakey = new Datakey
//{
// EntId = "88",
// CompanyId = "XCSJ" //据点 DGXC
//},
service = new Service
{
ip = "",
prod = "T100",
id = "topprd",
name = "wms_ge_pmaauc"
},
payload = new PayloadData>
{
std_data = new actionStd_data
{
parameter = input.parameter
}
}
};
var requestJson = JsonConvert.SerializeObject(t100Action);
var response = HttpHelper.PostAsync(t100Url, requestJson).Result;
var result = JsonConvert.DeserializeObject>>(response.Message);
Logger.Interface.Info($"T100获取二级供应商提交Json: {requestJson},返回Json: {response.Message}");
return result;
}
///
/// 生成客供料到货单
///
///
///
public static T100ActionResult> GenerateCustReceipt(CustReceiptInputParameter input)
{
try
{
var t100Action = new T100Action>>
{
key = Guid.NewGuid().ToString("N"),
type = "sync",
host = new host
{
prod = "WMS",
ip = "",
lang = "zh_CN",
acct = "tiptop",
timestamp = DateTime.Now.ToString("yyyyMMddHHMMssfff"),
},
datakey = input.datakey,
//datakey = new Datakey
//{
// EntId = "108", //正式 88
// CompanyId = "XCSJ" //据点 DGXC
//},
service = new Service
{
ip = "",
prod = "T100",
id = "topprd",
name = "wms_gen_apmt520"
},
payload = new PayloadData>>
{
std_data = new actionStd_data>
{
parameter = input.parameter
//parameter = new Parameter
//{
// pmds000 = "2",
// pmdsdocno = "3453",
// pmdsdocdt = "2023-04-26", //当天时间
// pmds002 = "L36783", //用户ID
// pmds003 = "",
// pmds007 = "C0006", //供应商代码
// pmds010 = "测试客供料无采购收货", //送货单号
// pmdsud001 = "CM017", //二级供应编号
// detail = new List
//{
// new Detail
// {
// pmdtseq= "1",
// pmdt001= "",
// pmdt002= "",
// pmdt003= "",
// pmdt004= "",
// pmdt006= itemcode, //"K7015AA016141",
// pmdt020= qty, //"100.00000",
// pmdtud011= "0"
// }
//}
//}
}
}
};
//如果送货单已经在处理,刚不能再重复抛送
if (!curDeliveryNoList.Contains(input.parameter.pmds010) || input.parameter.pmds010.IsNullOrEmpty())
{
if (!input.parameter.pmds010.IsNullOrEmpty())
{
curDeliveryNoList.Add(input.parameter.pmds010);
}
var requestJson = JsonConvert.SerializeObject(t100Action);
var response = HttpHelper.PostAsync(t100Url, requestJson).Result;
var result = JsonConvert.DeserializeObject>>(response.Message);
Logger.Interface.Info($"生成到货单提交Json: {requestJson},返回Json: {response.Message}");
curDeliveryNoList.Remove(input.parameter.pmds010);
Logger.Interface.Info($"操作单号列表移除当前操作单号[{input.parameter.pmds010}]");
return result;
}
else
{
T100ActionResult> ret = new();
ret.payload.std_data.execution.code = "-1";
ret.payload.std_data.execution.description = $"此单[{input.parameter.pmds010}]正在推送到T100,不能重复推送!";
Logger.Interface.Warn($"生成到货单异常,返回: {ret.payload.std_data.execution.description}");
return ret;
}
#region 测试代码
//var result = new T100ActionResult>()
//{
// payload = new()
// {
// std_data = new()
// {
// execution = new()
// {
// code = "0",
// sql_code = "0",
// description = "执行成功!",
// },
// parameter = new()
// {
// docno = $"DGrec-{DateTime.Now:yyMMddHHmm}",
// }
// }
// }
//};
//Logger.Interface.Info($"生成客供料到货单提交Json: {requestJson},返回Json: {{JsonConvert.SerializeObject(result)}}");
#endregion 测试代码
}
catch (System.Exception ex)
{
curDeliveryNoList.Remove(input.parameter.pmds010);
Logger.Interface.Error($"生成到货单异常,返回: {ex.Message}");
}
return new();
}
///
/// 从T100获取二级供应商接口返回iDropdownlist列表
///
///
///
public List GetSecondarySupplyInfoToDDL(SupplierInputParameter input)
{
List iDropdownlists = new List();
var list = GetSecondarySupplyInfo(input).payload.std_data.parameter.@return;
foreach (var item in list)
{
iDropdownlist _iDropdownlist = new()
{
label = item.pmaauc003,
value = $"{item.pmaauc002},{item.pmaauc001}",
};
iDropdownlists.Add(_iDropdownlist);
}
return iDropdownlists;
}
///
/// 生成送检单
///
///
///
public static T100ActionResult> GenerateInspection(InsInputParameter input)
{
var t100Action = new T100Action>
{
key = Guid.NewGuid().ToString("N"),
type = "sync",
host = new host
{
prod = "WMS",
ip = "",
lang = "zh_CN",
acct = "tiptop",
timestamp = DateTime.Now.ToString("yyyyMMddHHMMssfff"),
},
datakey = input.datakey,
//datakey = new Datakey
//{
// EntId = "108", //正式 88
// CompanyId = "XCSJ" //据点 DGXC
//},
service = new Service
{
ip = "",
prod = "T100",
id = "topprd",
name = "wms_gen_aqct300"
},
payload = new PayloadData>
{
std_data = new actionStd_data
{
parameter = input.parameter
}
}
};
var requestJson = JsonConvert.SerializeObject(t100Action);
var response = HttpHelper.PostAsync(t100Url, requestJson).Result;
var result = JsonConvert.DeserializeObject>>(response.Message);
Logger.Interface.Info($"生成送检单提交Json: {requestJson},返回Json: {response.Message}");
#region 测试代码
//var result = new T100ActionResult>()
//{
// payload = new()
// {
// std_data = new()
// {
// execution = new()
// {
// code = "0",
// sql_code = "0",
// description = "执行成功!",
// },
// parameter = new()
// {
// docno = $"DGtest-{DateTime.Now:yyMMddHHmm}",
// }
// }
// }
//};
//Logger.Interface.Info($"生成送检单提交Json: {requestJson},返回Json: {JsonConvert.SerializeObject(result)}");
#endregion 测试代码
return result;
}
///
/// 生成其他入库单
///
///
///
public static T100ActionResult> GenerateOtherIn(OtherInputParameter input)
{
var t100Action = new T100Action>>
{
key = Guid.NewGuid().ToString("N"),
type = "sync",
host = new host
{
prod = "WMS",
ip = "",
lang = "zh_CN",
acct = "tiptop",
timestamp = DateTime.Now.ToString("yyyyMMddHHMMssfff"),
},
datakey = input.datakey,
service = new Service
{
ip = "",
prod = "T100",
id = "topprd",
name = "wms_gen_apmt570"
},
payload = new PayloadData>>
{
std_data = new actionStd_data>
{
parameter = input.parameter
}
}
};
var requestJson = JsonConvert.SerializeObject(t100Action);
var response = HttpHelper.PostAsync(t100Url, requestJson).Result;
var result = JsonConvert.DeserializeObject>>(response.Message);
if (result.payload.std_data.execution.code != "0")
{
throw new Exception($"T100生成入库单失败,失败原因:{result.payload.std_data.execution.description}");
}
Logger.Interface.Info($"生成入库单请求T100,传入参数Json:{requestJson},返回:{response.Message}");
return result;
}
///
/// 根据领料单号拉单身
///
///
///
public T100ActionResult> GetMaterialReqDetail(ReqInputParameter input)
{
var t100Action = new T100Action>
{
key = Guid.NewGuid().ToString("N"),
type = "sync",
host = new host
{
prod = "WMS",
ip = "",
lang = "zh_CN",
acct = "tiptop",
timestamp = DateTime.Now.ToString("yyyyMMddHHMMssfff"),
},
datakey = input.datakey,
service = new Service
{
ip = "",
prod = "T100",
id = "topprd",
name = "wms_erp_wms_getwoissd"
},
payload = new PayloadData>
{
std_data = new actionStd_data
{
parameter = input.parameter
}
}
};
var requestJson = JsonConvert.SerializeObject(t100Action);
var response = HttpHelper.PostAsync(t100Url, requestJson).Result;
var result = JsonConvert.DeserializeObject>>(response.Message);
Logger.Interface.Info($"根据领料单号拉单身提交Json: {requestJson},返回Json: {response.Message}");
return result;
}
///
/// 领料单过账
///
///
///
public static T100ActionResult> MaterialReqToErp(ReqErpInputParameter input)
{
var t100Action = new T100Action>
{
key = Guid.NewGuid().ToString("N"),
type = "sync",
host = new host
{
prod = "WMS",
ip = "",
lang = "zh_CN",
acct = "tiptop",
timestamp = DateTime.Now.ToString("yyyyMMddHHMMssfff"),
},
datakey = input.datakey,
service = new Service
{
ip = "",
prod = "T100",
id = "topprd",
name = "wms_gen_asft310"
},
payload = new PayloadData>
{
std_data = new actionStd_data
{
parameter = input.parameter
}
}
};
var requestJson = JsonConvert.SerializeObject(t100Action);
var response = HttpHelper.PostAsync(t100Url, requestJson).Result;
var result = JsonConvert.DeserializeObject>>(response.Message);
Logger.Interface.Info($"领料单过账提交Json: {requestJson},返回Json: {response.Message}");
if (input.datakey.CompanyId == "DGXC")
{
Logger.Interface.Info($"领料单[{input.parameter.sfdadocno}]过账Json保存到数据库开始");
DbClient db = ApiConfig.IsOldVersion ? Biz.DataSource["WMS57"].Client : Business.Biz.Db;
BIZ_ERP_PROD_OUT entity_h = db.Queryable().Where(x => x.BILLCODE == input.parameter.sfdadocno && x.ERP_BILL_CODE == null).First();
if (entity_h != null)
{
entity_h.COMMIT_JSON = requestJson;
entity_h.COMMIT_MSG = response.Message;
}
//数据库处理操作
var dbTran = db.UseTran(() =>
{
if (entity_h != null)
{
db.Updateable(entity_h).UpdateColumns(q => new { q.COMMIT_JSON, q.COMMIT_MSG }).ExecuteCommand();
}
});
if (!dbTran.IsSuccess)
{
Logger.Interface.Error(dbTran.ErrorException);
throw dbTran.ErrorException;
}
Logger.Interface.Info($"领料单[{input.parameter.sfdadocno}]过账Json保存到数据库结束");
}
return result;
}
}
}