using System.ComponentModel;
|
using Kingdee.BOS;
|
using Kingdee.BOS.Core;
|
using Kingdee.BOS.ServiceHelper;
|
using System.Data;
|
|
using Newtonsoft.Json.Linq;
|
using System;
|
using Kingdee.BOS.Util;
|
using ZD.Cloud.WebApi;
|
|
namespace Demo.TimedTaskPlugIn.PRD
|
{
|
[Description("采购订单生成提料计划")]
|
[HotUpdate]
|
public class TLPlanTimeTaskByPurchase : Kingdee.BOS.Contracts.IScheduleService
|
{
|
CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/");
|
public Context Context;
|
public void Run(Context ctx, Schedule schedule)
|
{
|
try
|
{
|
Context = ctx;
|
//增加功能 采购订单关闭后 对应的提料计划删除 判断规则相同
|
string sql = @"select distinct c.FID
|
from t_PUR_POOrder a
|
join t_PUR_POOrderEntry b on a.FID = b.FID
|
join Cg_PODemandPlanBillSub c on b.FENTRYID =c.FHPOOrderEntryID
|
join Cg_PODemandPlanBillMain d on c.FID =d.FID
|
where a.FBILLTYPEID in
|
(
|
select FBILLTYPEID from T_BAS_BILLTYPE
|
where FBILLFORMID = 'PUR_PurchaseOrder'
|
and FNUMBER in('CGDD09_SYS','CGDD10_SYS','CGDD06','CGDD08')
|
)
|
and
|
(
|
a.FCLOSESTATUS = 'B' --关闭状态
|
or a.FCANCELSTATUS ='B' --作废状态
|
or b.FMRPCloseStatus ='B' -- 业务关闭
|
or b.FMRPFreezeStatus ='B' -- 业务冻结
|
or b.FMRPTerminateStatus ='B' -- 业务终止
|
)
|
and d.FDOCUMENTSTATUS IN('A','D')";
|
DataTable dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0];
|
if (dt.Rows.Count > 0)
|
{
|
string fid = "";
|
foreach (DataRow dr in dt.Rows)
|
{
|
fid += dr[0] + ",";
|
}
|
fid = fid.Substring(0, fid.Length - 1);
|
sql = $"delete Cg_PODemandPlanBillSub where fid in ({fid})";
|
DBServiceHelper.Execute(Context, sql);
|
sql = $"delete Cg_PODemandPlanBillMain where fid in ({fid})";
|
DBServiceHelper.Execute(Context, sql);
|
}
|
sql = @"/*dialect*/ select count(*) js
|
from t_PUR_POOrder a
|
join t_PUR_POOrderEntry b on a.FID = b.FID
|
where FBILLTYPEID in
|
(
|
select FBILLTYPEID from T_BAS_BILLTYPE
|
where FBILLFORMID = 'PUR_PurchaseOrder'
|
and FNUMBER in('CGDD09_SYS','CGDD10_SYS','CGDD06','CGDD08')
|
)
|
and a.FDOCUMENTSTATUS = 'C' --审核状态
|
and a.FCLOSESTATUS = 'A' --关闭状态
|
and a.FCANCELSTATUS ='A' --作废状态
|
and b.FMRPCloseStatus ='A' -- 业务关闭
|
and b.FMRPFreezeStatus ='A' -- 业务冻结
|
and b.FMRPTerminateStatus ='A' -- 业务终止
|
and FENTRYID not in (select distinct FHPOOrderEntryID from Cg_PODemandPlanBillSub)";
|
int ret = DBServiceHelper.ExecuteScalar<int>(Context, sql, 0);
|
if (ret == 0)
|
return;
|
Extraction();
|
}
|
catch (System.Exception ex)
|
{
|
//LogHelper.Error(ex.Message.ToString());
|
}
|
}
|
|
public void Extraction()
|
{
|
try
|
{
|
//需要生成提料计划所有数据
|
string sql = @"/*dialect*/ SELECT * FROM (
|
select a.FID,b.FENTRYID,B.FSEQ,a.FBILLNO,A.FSUPPLIERID,d.FNUMBER as FSUPPLIERNAME,CONVERT(NVARCHAR(50),T.FDELIVERYDATE,23)FDELIVERYDATE,b.FMATERIALID,c.FNUMBER as FMATERIALNAME,R.FREMAINRECEIVEQTY FQTY
|
from t_PUR_POOrder a
|
join t_PUR_POOrderEntry b on a.FID = b.FID
|
join T_PUR_POORDERENTRY_D T on B.FENTRYID = T.FENTRYID
|
join T_PUR_POORDERENTRY_R R on B.FENTRYID = R.FENTRYID
|
join T_BD_MATERIAL c on b.FMATERIALID = c.FMATERIALID
|
join T_BD_SUPPLIER d on a.FSUPPLIERID=d.FSUPPLIERID
|
where a.FBILLTYPEID in
|
(
|
select FBILLTYPEID from T_BAS_BILLTYPE
|
where FBILLFORMID = 'PUR_PurchaseOrder'
|
and FNUMBER in('CGDD09_SYS','CGDD10_SYS','CGDD06','CGDD08')
|
)
|
and a.FDOCUMENTSTATUS = 'C' --审核状态
|
and a.FCLOSESTATUS = 'A' --关闭状态
|
and a.FCANCELSTATUS ='A' --作废状态
|
and b.FMRPCloseStatus ='A' -- 业务关闭
|
and b.FMRPFreezeStatus ='A' -- 业务冻结
|
and b.FMRPTerminateStatus ='A' -- 业务终止
|
and b.FENTRYID not in (select distinct FHPOOrderEntryID from Cg_PODemandPlanBillSub)
|
)A
|
";
|
//交期和供应商进行分组
|
DataTable purDt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0];
|
sql = @"/*dialect*/ select DISTINCT A.FSUPPLIERID,CONVERT(NVARCHAR(50),T.FDELIVERYDATE,23)FDELIVERYDATE
|
from t_PUR_POOrder a
|
join t_PUR_POOrderEntry b on a.FID = b.FID
|
join T_PUR_POORDERENTRY_D T on B.FENTRYID = T.FENTRYID
|
where a.FBILLTYPEID in
|
(
|
select FBILLTYPEID from T_BAS_BILLTYPE
|
where FBILLFORMID = 'PUR_PurchaseOrder'
|
and FNUMBER in('CGDD09_SYS','CGDD10_SYS','CGDD06','CGDD08')
|
)
|
and a.FDOCUMENTSTATUS = 'C' --审核状态
|
and a.FCLOSESTATUS = 'A' --关闭状态
|
and a.FCANCELSTATUS ='A' --作废状态
|
and b.FMRPCloseStatus ='A' -- 业务关闭
|
and b.FMRPFreezeStatus ='A' -- 业务冻结
|
and b.FMRPTerminateStatus ='A' -- 业务终止
|
and b.FENTRYID not in (select distinct FHPOOrderEntryID from Cg_PODemandPlanBillSub)
|
";
|
DataTable _purDt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0];
|
JArray FinalyResult = new JArray();
|
int tlmmm = 1;
|
if (_purDt.Rows.Count > 0)
|
{
|
foreach (DataRow _dr in _purDt.Rows)
|
{
|
DataRow[] purDtRows = purDt.Select($"FSUPPLIERID = '{_dr[0].ToString()}' AND FDELIVERYDATE = '{_dr[1].ToString()}'");
|
//LogHelper.Info(purDtRows.ToString());
|
JObject model = new JObject();
|
model.Add("FHDate", purDtRows[0]["FDELIVERYDATE"].ToString());
|
model.Add("FSettleCurrId", new JObject() { ["Fnumber"] = "PRE001" });
|
model.Add("FSupplierID", new JObject() { ["Fnumber"] = purDtRows[0]["FSUPPLIERNAME"].ToString() });
|
JArray Fentity = new JArray();
|
foreach (DataRow drN in purDtRows)
|
{
|
JObject FentityModel = new JObject();
|
FentityModel.Add("FHPURCHASEORGID", new JObject() { ["Fnumber"] = "100" });//采购组织
|
FentityModel.Add("FHMaterID", new JObject() { ["Fnumber"] = drN["FMATERIALNAME"].ToString() });//物料
|
FentityModel.Add("FHQty", drN["FQty"].ToString());//数量
|
FentityModel.Add("FPURCHASEORGID", new JObject() { ["Fnumber"] = "100" });//采购组织
|
FentityModel.Add("FHPOOrderInterID", drN["FID"].ToString());// 采购订单内码:FHPOOrderInterID
|
FentityModel.Add("FHPOOrderEntryID", drN["FENTRYID"].ToString()); //采购订单子内码:FHPOOrderEntryID
|
FentityModel.Add("FHPOOrderBillNo", drN["FBILLNO"].ToString()); //采购订单号:FHPOOrderBillNo
|
FentityModel.Add("FHPOOrderFseq", drN["FSEQ"].ToString()); //
|
FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = "Pcs" }); //单位
|
Fentity.Add(FentityModel);
|
}
|
model.Add("FEntity", Fentity);
|
FinalyResult.Add(model);
|
if ((tlmmm >= 20 || tlmmm == _purDt.Rows.Count) && (tlmmm % 20 == 0 || tlmmm == _purDt.Rows.Count))
|
{
|
//LogHelper.Info("提料计划新增批量执行,记录循环的当前条数" + tlmmm);
|
JObject jsonRoot = new JObject()
|
{
|
["Creator"] = "",
|
["NeedUpDateFields"] = new JArray(),
|
["NeedReturnFields"] = new JArray(),
|
["IsDeleteEntry"] = "false",
|
["SubSystemId"] = "",
|
["IsVerifyBaseDataField"] = "false",
|
["Model"] = FinalyResult
|
};
|
CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/");
|
var result = cloudClient.BatchSave("paez_PODemandPlan", jsonRoot.ToString());
|
JObject saveObj = JObject.Parse(result);
|
string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper();
|
if (saveIsSuc != "TRUE")
|
{
|
//LogHelper.Error(jsonRoot.ToString());
|
}
|
FinalyResult = new JArray();
|
}
|
tlmmm++;
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
//LogHelper.Info("提料计划跳出:" + ex.Message.ToString());
|
}
|
}
|
}
|
}
|