继@CQ周玉立 周玉立同学文档分享Python如何在服务插件中推送云之家消息,改造后实现前台化配置。
基础版本:Python服务插件推送云之家消息 (kingdee.com)
本案例是在一个认款通知单审核后根据前台配置单据寻找对应人员发送云之家消息:
先看结果:
1、 BOS创建单据
注意事项:
单据头必须有云之家用户ID,PS:Python插件里面取了这个参数;
单据体内容是根据业务单据取值区分;
话不多说上插件:
##****************************保存服务插件*******************
#引入clr运行库
import clr
#添加对cloud插件开发的常用组件的引用
clr.AddReference('System')
clr.AddReference('System.Data')
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.BOS.App')
clr.AddReference('Kingdee.BOS.DataEntity')
clr.AddReference('Kingdee.BOS.Contracts')
clr.AddReference('Kingdee.BOS.ServiceHelper')
clr.AddReference('Kingdee.BOS.App.Core')
#导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入)
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Msg import *
from Kingdee.BOS.Contracts import *
from Kingdee.BOS.Orm.DataEntity import *
from Kingdee.BOS.DataEntity import *
from Kingdee.BOS.Core.Bill import *
from Kingdee.BOS.Core.DynamicForm.PlugIn import *
from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import *
from Kingdee.BOS.App.Core import *
from Kingdee.BOS.App.Core.Messages import *
from System import *
from System.Data import *
from Kingdee.BOS.App.Data import *
from System.Collections.Generic import List
from Kingdee.BOS.ServiceHelper import *
def OnPreparePropertys(e):
#把需要字段装进去
e.FieldKeys.Add("FBillNo");
e.FieldKeys.Add("FPAYUNIT");
e.FieldKeys.Add("FSUBSCRIPTIONDATE");
e.FieldKeys.Add("FCOLLECTIONDATE");
e.FieldKeys.Add("FAMOUNTCOLLECTED");
def writeBackWLInfo(billObj):
#循环取出相应字段
formID=str(billObj["BillNo"]);
#raise Exception("-------------------------------");
FSUBSCRIPTIONDATE=str(billObj["FSUBSCRIPTIONDATE"]);
FCOLLECTIONDATE=str(billObj["FCOLLECTIONDATE"]);
billNo1=str(billObj["FPAYUNIT"]["Id"]);
FPAYUNIT=str(billObj["FPAYUNIT"]["Name"]);
FAMOUNTCOLLECTED=str(billObj["FAMOUNTCOLLECTED"]);
#设置发送信息
#msg="单据号:"+formID+" "+""+" 收款时间:"+FCOLLECTIONDATE+" 付款单位:"+FPAYUNIT+" 收款金额汇总:"+str(FAMOUNTCOLLECTED).split('.')[0] + '.' + str(FAMOUNTCOLLECTED).split('.')[1][:2];
msg=" 付款单位:"+FPAYUNIT+" ,打款时间 : "+FCOLLECTIONDATE+" ,打款金额 :"+str(FAMOUNTCOLLECTED).split('.')[0] + '.' + str(FAMOUNTCOLLECTED).split('.')[1][:2] +",请及时处理认款通知单: "+formID ;
#raise Exception(msg);
openid=getXSCKDBillInfo(billNo1);
#判断查询不为空则发送信息
#raise Exception(openid+"-------------------------------");
if str(openid) <>"none":
senmsg(openid,msg);
def EndOperationTransaction(e):
for billObj in e.DataEntitys:
writeBackWLInfo(billObj);
#根据商业单位ID获取openid
def getXSCKDBillInfo(billNo1):
sql=("select top 1 m.FOPENID from XEA_t_Cust100118 t left join XEA_t_Cust_Entry100181 t1 on t.FID=t1.FID left join T_SEC_XTuserMap m on m.FID=t.F_XEA_YZJYHID"
" where t.FDOCUMENTSTATUS='C' and t1.F_XEA_FKDW='{0}'").format(str(billNo1));
try:
ds = DBServiceHelper.ExecuteDataSet(this.Context,sql);
tab = ds.Tables[0];
dataR=tab.Rows[0];
FOPENID=dataR["FOPENID"];
#raise Exception(FOPENID.ToString()+"-------");
#resul =List[object]();
#resul.Add(FOPENID);
#return resul;
return FOPENID;
except Exception as e:
return "none";
#发送信息并传入参数
def senmsg(openid,msg1):
userXunTongService=UserXunTongService();
toUsers=List[str]();
xunTongOpenId=userXunTongService.GetXunTongUser(this.Context,openid);
toUsers.Add(str(xunTongOpenId));
xunTongService=ServiceFactory.GetXunTongService(this.Context);
xunTongService=XunTongService();
msg=XTPlainTextMessage();
msg.Text = ("今收到 [{0}]").format(msg1);
msg.PubAcctCode = "XT-747f6668-6136-4509-989b-c8d5XXXXX";
msg.PubAcctKey = "f5a6a8602933d7c95065276ba9XXXXX";
msg.Users=toUsers;
xtsendResult=xunTongService.AnsySendPlainTextMessage(this.Context, msg);
ss=("结果:{0}").format(xtsendResult.Msg);
-----------------------------------------------------------------------------------------------------------------------------
记得收藏关注,迟早你会需要的
源文件.rar(1.70KB)