You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

135 lines
3.7 KiB

using BWP.B3ExportBase;
using BWP.B3ExportBase.BL;
using BWP.B3Frameworks;
using BWP.B3UnitedInfos.BO;
using Forks.EnterpriseServices;
using Forks.EnterpriseServices.BusinessInterfaces;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSingSoft.WebPluginFramework.BIPlugins.BLEvents;
using TSingSoft.WebPluginFramework;
using BWP.B3Frameworks.Utils;
using BWP.B3ExportBase.BO;
using Forks.JsonRpc.Client;
using Newtonsoft.Json;
namespace BWP.B3QingDaoWanFu.BL
{
[BusinessInterface(typeof(GoodsExportBL))]
public interface IGoodsExportBL : IExportBaseBL
{
void Export(List<long> dmoIDs, long extSystemID);
void UpdateOrInsert(Goods goods);
void Stop(string code);
void Start(string code);
void Delete(string code);
}
[LogicName("存货导MES存货")]
[ExportID(B3FrameworksConsts.DmoTypeIDBases.B3QingDaoWanFu, B3QingDaoWanFuConsts.DmoTypeIDOffsets.GoodsExport)]
public class GoodsExportBL : ExportBaseBL<Goods>, IGoodsExportBL
{
const string MethodPath = "/MainSystem/B3ClientService/Rpcs/InterfaceRpc/GoodsRpc/";
protected override void BeforeExport(List<long> dmoIDs)
{
Dmos = new List<Goods>();
var scriptHelper = new PythonScriptHelper(string.Empty, Config.Script, this);
MinDmoProperties = new List<string>();
MinDetailProperties = new List<string>();
LoadFullDom = true;
//在脚本里设置是否载入整张单据 或者部分字段
scriptHelper.Before();
if (LoadFullDom)
{
var list = new List<long>();
var query = new DmoQuery(typeof(Goods));
query.Where.Conditions.EFieldInList("ID", dmoIDs);
foreach (Goods bill in Session.ExecuteList(query))
{
if (list.IndexOf(bill.ID) == -1)
{
list.Add(bill.ID);
Dmos.Add(bill);
}
}
return;
}
LoadMinDmo(Dmos, dmoIDs);
}
private string _serverUrl;
protected string ServerUrl
{
get { return _serverUrl; }
set { _serverUrl = value; }
}
public void Export(List<long> dmoIDs, long extSystemID)
{
if (dmoIDs.Count == 0)
throw new Exception("没有要导出的内容");
ExtSystemID = extSystemID;
_serverUrl = InnerBLUtil.GetDmoPropertyByID<string>(Session, typeof(ExtSystem), "Address", extSystemID);
if (string.IsNullOrEmpty(_serverUrl))
throw new Exception("外部系统地址不能为空");
BeforeExport(dmoIDs);
DoExport(dmoIDs);
}
private void DoExport(List<long> dmoIDs)
{
var scriptHelper = new PythonScriptHelper(string.Empty, Config.Script, this);
var dmos = Dmos.OrderBy(x => x.ID).ToList();
scriptHelper.AddLocalVar("dmos", dmos);
scriptHelper.Execute();
InitRpc();
var json = JsonConvert.SerializeObject(dmos);
RpcFacade.Call<int>(MethodPath + "BatchImport", json);
BIFactory.MsgBuilder.Append("导出成功!");
}
public void UpdateOrInsert(Goods goods)
{
RpcFacade.Call<int>(MethodPath + "UpdateOrInsert", JsonConvert.SerializeObject(goods));
}
public void Stop(string code)
{
RpcFacade.Call<int>(MethodPath + "Stop", code);
}
public void Start(string code)
{
RpcFacade.Call<int>(MethodPath + "Start", code);
}
public void Delete(string code)
{
RpcFacade.Call<int>(MethodPath + "Delete", code);
}
void InitRpc()
{
try
{
RpcFacade.Init(_serverUrl, "B3QingFu");
}
catch (Exception ex)
{
if (ex.Message != "Can only start once")
throw;
}
}
}
}