public class AutoCheckInventory : IScheduleService
{
///
/// 实际运行的Run 方法
///
///
///
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
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
// 添加新行,把新行加入到单据体行集合
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
// "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