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.
 
 

114 lines
3.7 KiB

using BWP.B3ButcherManage.BO;
using BWP.B3ExportBase;
using BWP.B3ExportBase.BL;
using BWP.B3ExportBase.BO;
using BWP.B3Frameworks;
using Forks.EnterpriseServices;
using Forks.EnterpriseServices.BusinessInterfaces;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSingSoft.WebPluginFramework;
using TSingSoft.WebPluginFramework.BIPlugins.BLEvents;
namespace BWP.B3ButcherManageExport.BL
{
[BusinessInterface(typeof(StatPayToU8BL))]
public interface IStatPayToU8BL : IExportU8BL
{
void Export(List<long> dmoIDs, long extSystemID, DateTime? date);
}
[LogicName("屠宰场结算单导U8采购入库单")]
[BindToFeature("B3ButcherManageExport.0005")]
[ExportID(B3FrameworksConsts.DmoTypeIDBases.B3ButcherManageExport, B3ButcherManageExportConsts.ExportIDOffsets.StatPayToU8)]
public class StatPayToU8BL : ExportU8BL<StatPay>, IStatPayToU8BL
{
protected override Ufinterface CreateUfinterface(IList<StatPay> dmos)
{
if (string.IsNullOrEmpty(Config.Script))
throw new ApplicationException("脚本为空");
var scriptHelper = new PythonScriptHelper(string.Empty, Config.Script, this);
var inv = StatPayU8s.CreateStoreIn();
new StoreInBodyEntry();
scriptHelper.AddLocalVar("dmos", dmos);
scriptHelper.AddLocalVar("vouchers", inv);
scriptHelper.Execute();
var i = 0;
foreach (var voucher in inv.Bills)
{
//回执文件里 会有这个信息,通过这个voucherid来判断单据是否导出成功
voucher.Head.Id = i.ToString();
BillIDs.Add(i, voucher.B2BillIDs);
i++;
}
return inv;
}
private DateTime _date;
public DateTime Date
{
get { return _date; }
set { _date = value; }
}
public void Export(List<long> dmoIDs, long extSystemID, DateTime? date)
{
_date = date ?? BLContext.Today;
Export(dmoIDs, extSystemID);
}
protected override Action<List<StatPay>> FillDetail
{
get
{
return dmos =>
{
var dmoType = typeof(StatPay_Butcher);
var dom = new DQueryDom(new JoinAlias(dmoType));
dom.Columns.Add(DQSelectColumn.Field("ID"));
foreach (string property in MinDetailProperties)
{
dom.Columns.Add(DQSelectColumn.Field(property));
}
var expressionList = new List<IDQExpression>();
foreach (var dmo in dmos)
expressionList.Add(DQExpression.Value(dmo.ID));
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("StatPay_ID"), expressionList.ToArray()));
var details = new List<StatPay_Butcher>();
details.Clear();
using (IDQDataReader reader = Session.ExecuteReader(dom))
{
while (reader.Read())
{
var detail = new StatPay_Butcher
{
ID = (long)reader[0]
};
int i = 1;
foreach (var property in MinDetailProperties)
{
dmoType.GetProperty(property).SetValue(detail, reader[i++], null);
}
details.Add(detail);
}
}
var groups = details.GroupBy(x => x.StatPay_ID);
foreach (var gDetail in groups)
{
var firstDmo = dmos.FirstOrDefault(x => x.ID == gDetail.Key);
if (firstDmo == null)
continue;
foreach (var billDetail in gDetail)
{
firstDmo.Details.Add(billDetail);
}
}
};
}
}
}
}