1. 程式人生 > >K3/cloud執行計劃插件示例

K3/cloud執行計劃插件示例

from tar data wid type 多條 root ali 合同

public class AutoCheckInventory : IScheduleService

{

/// <summary>
/// 實際運行的Run 方法
/// </summary>
/// <param name="ctx"></param>
/// <param name="schedule"></param>
public void Run(Context ctx, Schedule schedule)
{
//string clientPath = ConfigurationManager.AppSettings["clienpath"].ToString().Trim();
//ApiClient client;
//庫存小於預警值發送消息
//GetPositionInventory(ctx);
CustomerFeeNote(ctx);
}

public void CustomerFeeNote(Context ctx)
{
//獲取客戶繳費通知書的數據(提前10天)
string Sql = "";
Sql = "select a.FBILLNO,a.F_DEV_SINER,a.F_DEV_SIGNDATE,a.F_DEV_CUSTOMER,a.F_DEV_ADDR,a.F_DEV_CONTACTS,a.F_DEV_PHONE," +
"a.F_DEV_HOUSE,a.F_DEV_STARTDATE,a.F_DEV_STOPDATE,a.F_DEV_LEASE,a.F_DEV_YEARRENT,a.F_DEV_MONTHRENT,a.F_DEV_TOTALRENT," +
"a.F_DEV_PURPOSE,a.F_DEV_PROPERTYFEE,a.F_DEV_DEPOSIT,a.F_DEV_HOUSEAREA,a.F_DEV_CONTRACT," +
"b.F_DEV_RENTSTARTDATE,b.F_DEV_RENTSTOPDATE,b.F_DEV_RENTPAYABLE,b.F_DEV_PAYDATE,b.F_DEV_EXPLAIN,b.FEntryID " +
"from Dev_t_Cust_Entry105108 a left join Dev_t_Cust_Entry105110 b on a.FID = b.FID "+
"where DATEDIFF(DAY,GETDATE(),b.F_DEV_PAYDATE) = 10 and a.F_DEV_CONTRACTCANCEL <> ‘是‘ ";
DataSet ds = new DataSet();
ds = Kingdee.BOS.ServiceHelper.DBServiceHelper.ExecuteDataSet(ctx, Sql);
ds.Tables[0].TableName = "RentInfo";
//string sqlhouse = "";
//sqlhouse =
//自動生成客戶繳費通知書
Customer_Payment_Notice(ds, ctx);
//發送消息至簽訂人消息列表
foreach (DataRow dr in ds.Tables[0].Rows)
{
SendMessage(ctx, "客戶繳費通知書生成提醒", "客戶繳費通知書:" + dr["FBILLNO"].ToString()+"已經生成!", DateTime.Now,Convert.ToInt64(dr["F_DEV_SINER"].ToString()));

}

//獲取客戶繳費通知書的數據(提前5天)發送消息
string Sql1 = "";
Sql1 = "select a.FBILLNO,a.F_DEV_SINER,a.F_DEV_SIGNDATE,a.F_DEV_CUSTOMER,a.F_DEV_ADDR,a.F_DEV_CONTACTS,a.F_DEV_PHONE," +
"a.F_DEV_HOUSE,a.F_DEV_STARTDATE,a.F_DEV_STOPDATE,a.F_DEV_LEASE,a.F_DEV_YEARRENT,a.F_DEV_MONTHRENT,a.F_DEV_TOTALRENT," +
"a.F_DEV_PURPOSE,a.F_DEV_PROPERTYFEE,a.F_DEV_DEPOSIT," +
"b.F_DEV_RENTSTARTDATE,b.F_DEV_RENTSTOPDATE,b.F_DEV_RENTPAYABLE,b.F_DEV_PAYDATE,b.F_DEV_EXPLAIN,b.FEntryID " +
"from Dev_t_Cust_Entry105108 a left join Dev_t_Cust_Entry105110 b on a.FID = b.FID " +
"where DATEDIFF(DAY,GETDATE(),b.F_DEV_PAYDATE) = 5 and a.F_DEV_CONTRACTCANCEL <> ‘是‘ ";
DataSet ds1 = new DataSet();
ds1 = Kingdee.BOS.ServiceHelper.DBServiceHelper.ExecuteDataSet(ctx, Sql1);
foreach (DataRow dr1 in ds1.Tables[0].Rows)
{
SendMessage(ctx, "客戶繳費通知書生成提醒", "客戶繳費通知書:" + dr1["FBILLNO"].ToString()+"已經生成,請確認!", DateTime.Now, Convert.ToInt64(dr1["F_DEV_SINER"].ToString()));
}
}

public void Customer_Payment_Notice(DataSet ds, Context ctx)
{
DataSet dstemp = new DataSet();
DataTable dtTemp = new DataTable();
string result = "";

//自動生成客戶繳費通知書
if (ds != null && ds.Tables["RentInfo"].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables["RentInfo"].Rows.Count; i++)
{
try
{
//獲取房源數據
string sqlhouse = "select b.fentryid,b.F_DEV_HOUSEBASE from Dev_t_Cust_Entry105108 a left join Dev_t_Cust_Entry100007 b on a.fid = b.fid where a.fbillno = ‘" + ds.Tables["RentInfo"].Rows[i]["FBILLNO"].ToString() + "‘";
DataSet dshouse = new DataSet();
dshouse = Kingdee.BOS.ServiceHelper.DBServiceHelper.ExecuteDataSet(ctx, sqlhouse);
dshouse.Tables[0].TableName = "HouseInfo";

// 開始構建Web API參數對象
// 參數根對象:包含Creator、NeedUpDateFields、Model這三個子參數
// using Newtonsoft.Json.Linq; // (需引用Newtonsoft.Json.dll)
JObject jsonRoot = new JObject();

// Creator: 創建用戶
jsonRoot.Add("CREATOR", "administrator");

// NeedUpDateFields: 哪些字段需要更新?為空則表示參數中全部字段,均需要更新
jsonRoot.Add("NEEDUPDATEFIELDS", new JArray(""));
jsonRoot.Add("NEEDRETURNFIELDS", new JArray(""));
jsonRoot.Add("ISDELETEENTRY", "TRUE");
jsonRoot.Add("SUBSYSTEMID", "");

// Model: 單據詳細數據參數
JObject model = new JObject();
jsonRoot.Add("Model", model);

// 開始設置單據字段值
// 必須設置的字段:主鍵、單據類型、主業務組織,各必錄且沒有設置默認值的字段
// 特別註意:字段Key大小寫是敏感的,建議從BOS設計器中,直接復制字段的標識屬性過來

// 單據主鍵:必須填寫,系統據此判斷是新增還是修改單據;新增單據,填0
model.Add("FID", "0");
model.Add("FDATE", DateTime.Now.ToString("yyyy-MM-dd"));

// 采購組織:必須填寫,是基礎資料字段
JObject basedata = new JObject();
//basedata.Add("FNumber", "100");
//model.Add("FSTOCKORGID", basedata);

// 單據類型:必須填寫,是基礎資料字段
// 基礎資料類型字段填值,必須再構建一個JObject對象,設置基礎資料編碼

// 單據編號:可以忽略,由系統根據編碼規則自動生成

//簽訂人
if (ds.Tables["RentInfo"].Rows[i]["F_DEV_SINER"].ToString() != "" && ds.Tables["RentInfo"].Rows[i]["F_DEV_SINER"].ToString() != "0" && ds.Tables["RentInfo"].Rows[i]["F_DEV_SINER"].ToString() != null)
{
dtTemp = GetSignerInfor(ds.Tables["RentInfo"].Rows[i]["F_DEV_SINER"].ToString(), ctx);
basedata = new JObject();
basedata.Add("FName", dtTemp.Rows[0]["FNAME"].ToString());
model.Add("F_DEV_BASE2", basedata);
}

//簽訂日期
model.Add("F_DEV_DATE", ds.Tables["RentInfo"].Rows[i]["F_DEV_SIGNDATE"].ToString());

//客源
if (ds.Tables["RentInfo"].Rows[i]["F_DEV_CUSTOMER"].ToString() != "" && ds.Tables["RentInfo"].Rows[i]["F_DEV_CUSTOMER"].ToString() != "0" && ds.Tables["RentInfo"].Rows[i]["F_DEV_CUSTOMER"].ToString() != null)
{
dtTemp = GetCustomerInfor(ds.Tables["RentInfo"].Rows[i]["F_DEV_CUSTOMER"].ToString(), ctx);
basedata = new JObject();
basedata.Add("FNumber", dtTemp.Rows[0]["FNUMBER"].ToString());
model.Add("F_DEV_BASE", basedata);
}


//聯系地址
model.Add("F_DEV_TEXT7", ds.Tables["RentInfo"].Rows[i]["F_DEV_ADDR"].ToString());

//聯系人
model.Add("F_DEV_TEXT71", ds.Tables["RentInfo"].Rows[i]["F_DEV_CONTACTS"].ToString());

//聯系電話
model.Add("F_DEV_TEXT711", ds.Tables["RentInfo"].Rows[i]["F_DEV_PHONE"].ToString());

//房源
//if (ds.Tables[0].Rows[i]["F_DEV_HOUSE"].ToString() != "" && ds.Tables[0].Rows[i]["F_DEV_HOUSE"].ToString() != "0" && ds.Tables[0].Rows[i]["F_DEV_HOUSE"].ToString() != null)
//{
// dtTemp = GetHouseInfor(ds.Tables[0].Rows[i]["F_DEV_HOUSE"].ToString(), ctx);
// basedata = new JObject();
// basedata.Add("FNumber", dtTemp.Rows[0]["FNUMBER"].ToString());
// model.Add("F_DEV_BASE1", basedata);
//}

//合同號
model.Add("F_DEV_CONTRACTNO", ds.Tables["RentInfo"].Rows[i]["F_DEV_CONTRACT"].ToString());
//總面積
model.Add("F_DEV_HOUSEAREA", ds.Tables["RentInfo"].Rows[i]["F_DEV_HOUSEAREA"].ToString());
// 開始構建單據體參數:集合參數JArray

JArray entryRows = new JArray();
// 把單據體行集合,添加到model中,以單據體Key為標識
string entityKey = "FEntity1";
model.Add(entityKey, entryRows);


// 通過循環創建單據體行:此處只創建一行,根據具體情況修改
for (int j = 0; j < 1; j++)
{
// 添加新行,把新行加入到單據體行集合
JObject entryRow = new JObject();
entryRows.Add(entryRow);


// 給新行,設置關鍵字段值
// 單據體主鍵:必須填寫,系統據此判斷是新增還是修改行
entryRow.Add("FEntryID", "0");

//開始日期
entryRow.Add("F_DEV_DATE9", ds.Tables["RentInfo"].Rows[i]["F_DEV_RENTSTARTDATE"].ToString());

//結束日期
entryRow.Add("F_DEV_DATE10", ds.Tables["RentInfo"].Rows[i]["F_DEV_RENTSTOPDATE"].ToString());

//說明
entryRow.Add("F_DEV_TEXT2", ds.Tables["RentInfo"].Rows[i]["F_DEV_EXPLAIN"].ToString());

//應付租金
entryRow.Add("F_DEV_DECIMAL9", ds.Tables["RentInfo"].Rows[i]["F_DEV_RENTPAYABLE"].ToString());

//應付日期
entryRow.Add("F_DEV_DATE11", ds.Tables["RentInfo"].Rows[i]["F_DEV_PAYDATE"].ToString());

// 創建Link行集合
JArray linkRows = new JArray();

// 添加到單據體行中:Link子單據體標識 = 關聯主單據體標識(POOrderEntry) + _Link
string linkEntityKey = string.Format("{0}_Link", entityKey);
entryRow.Add(linkEntityKey, linkRows);

// 創建Link行:
// 如有多條源單行,則分別創建Link行記錄各條源單行信息
JObject linkRow = new JObject();
linkRows.Add(linkRow);

// 填寫Link行上的字段值
// 特別說明:Link子單據體上字段的標識,必須在前面增加子單據體標識

// FFlowId : 業務流程圖,可選
string fldFlowIdKey = string.Format("{0}_FFlowId", linkEntityKey);
linkRow.Add(fldFlowIdKey, "");

// FFlowLineId :業務流程圖路線,可選
string fldFlowLineIdKey = string.Format("{0}_FFlowLineId", linkEntityKey);
linkRow.Add(fldFlowLineIdKey, "");

// FRuleId :兩單之間的轉換規則內碼,必填
// 可以通過如下SQL語句到數據庫獲取
// select FID, *
// from T_META_CONVERTRULE
// where FSOURCEFORMID = ‘Dev_RentContract‘
// and FTARGETFORMID = ‘Dev_RentPaymentNotice‘
// and FDEVTYPE = 0;
string fldRuleIdKey = string.Format("{0}_FRuleId", linkEntityKey);
linkRow.Add(fldRuleIdKey, "16e9262b-d238-4c7b-b487-3154e44a74e9");

// FSTableName :必填,源單單據體表格編碼,通過如下語句獲取:
// SELECT FTableNumber
// FROM t_bf_tabledefine
// WHERE fformid = ‘PUR_Requisition‘
// AND fentitykey = ‘FEntity‘
// 如果如上語句未返回結果,請到K/3 Cloud中,手工選單一次,後臺會自動產生表格編碼
string fldSTableNameKey = string.Format("{0}_FSTableName", linkEntityKey);
linkRow.Add(fldSTableNameKey, "Dev_t_Cust_Entry105109");

//通過收料單號獲取收料單內碼和單據體分錄內碼
//string BillNo = ds.Tables[0].Rows[i]["F_DEV_SOURCEBILLNO"].ToString();
//string MatId = ds.Tables["InStockMatInfo"].Rows[i]["F_DEV_MATID"].ToString();
//string StockId = ds.Tables["InStockMatInfo"].Rows[i]["F_Dev_StockID"].ToString();
//string Position = ds.Tables["InStockMatInfo"].Rows[i]["F_Dev_Position"].ToString();
//dtTemp = GetData.GetReceiveInfo(BillNo, MatId, StockId, Position);
//// FSBillId :必填,源單單據內碼
//string fldSBillIdKey = string.Format("{0}_FSBillId", linkEntityKey);
//linkRow.Add(fldSBillIdKey, dtTemp.Rows[0]["FID"].ToString());

// FSId : 必填,源單單據體行內碼。如果源單主關聯實體是單據頭,則此屬性也填寫源單單據內碼
string fldSIdKey = string.Format("{0}_FSId", linkEntityKey);
linkRow.Add(fldSIdKey, ds.Tables["RentInfo"].Rows[i]["FEntryID"].ToString());

//// FEntity_Link_FBaseQty :數量實際攜帶值,下推後,用戶可以手工修改數量值;此字段存儲最終的數量值
//// 可選字段:
//// 在保存時,系統會自動把單據體上數量值,更新到此字段;因此,這個字段可以不用填寫(即使填寫了,也會被覆蓋)
//string fldBaseQtyKey = string.Format("{0}_FBaseUnitQty", linkEntityKey);
//linkRow.Add(fldBaseQtyKey, 10);
}
//生成房源信息
entryRows = new JArray();
// 把單據體行集合,添加到model中,以單據體Key為標識
entityKey = "F_Dev_Entity";
model.Add(entityKey, entryRows);
// 通過循環創建單據體行:此處只創建一行,根據具體情況修改
string F_DEV_HOUSEBASE;
for (int k = 0; k < dshouse.Tables["HouseInfo"].Rows.Count; k++)
{
// 添加新行,把新行加入到單據體行集合
JObject entryRow = new JObject();
entryRows.Add(entryRow);
// 給新行,設置關鍵字段值
// 單據體主鍵:必須填寫,系統據此判斷是新增還是修改行
entryRow.Add("FEntryID", "0");
//房源
basedata = new JObject();
//basedata.Add("FNumber", "GTA0K1T");
F_DEV_HOUSEBASE = dshouse.Tables[0].Rows[k]["F_DEV_HOUSEBASE"].ToString();
dtTemp = GetHouseInfor(F_DEV_HOUSEBASE, ctx);
basedata.Add("FNumber", dtTemp.Rows[0]["FNUMBER"].ToString());
entryRow.Add("F_DEV_HOUSE", basedata);
}
// 調用Web API接口服務,保存客戶繳費通知書
result = Save("Dev_RentPaymentNotice", jsonRoot.ToString());
//result = client.Execute<string>(
// "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save",
// new object[] { "Dev_STK_InStock", jsonRoot.ToString() });
try
{
JObject jo = (JObject)JsonConvert.DeserializeObject(result);
string number = jo["Result"]["Number"].ToString();

if (number != "")
{
string autrjson = "{\"CreateOrgId\":0,\"Numbers\":[\"" + number + "\"]}";
result = Audit("Dev_RentPaymentNotice", autrjson);
}
}
catch (Exception exp)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("程序運行遇到了未知的錯誤:");
sb.Append("錯誤提示:").AppendLine(exp.Message);
sb.Append("錯誤堆棧:").AppendLine(exp.StackTrace);
throw new Exception(sb.ToString() + result.ToString());
}
}
catch (Exception exp)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("程序運行遇到了未知的錯誤:");
sb.Append("錯誤提示:").AppendLine(exp.Message);
sb.Append("錯誤堆棧:").AppendLine(exp.StackTrace);
throw new Exception(sb.ToString() + result.ToString());
}
}
}
}

}

插件註冊截圖:

紅框部分為:

K3.DEV.XZGT.PlanedTask.AutoCheckInventory,K3.DEV.XZGT.PlanedTask

技術分享圖片

K3/cloud執行計劃插件示例