二开案例.系统集成.使用代理接口保存上机操作日志
【应用场景】
第三方系统,使用代理接口访问星空系统,保存上机操作日志。
【案例演示】
使用代理接口访问星空系统,保存上机操作日志。
【实现步骤】
<1>编写保存上机操作日志的服务类,代码如下。
using Kingdee.BOS;
using Kingdee.BOS.Core.Log;
using Kingdee.BOS.ServiceFacade.KDServiceClient.BusinessData;
using Kingdee.BOS.ServiceFacade.KDServiceClient.User;
using System;
using System.Collections.Generic;
namespace Jac.XkDemo.BOS.ProxyConsole
{
/// <summary>
/// 日志代理类
/// </summary>
public class LogProxy : AbstractXkProxy
{
/// <summary>
/// 写上机操作日志
/// </summary>
/// <param name="log"></param>
public void WriteOperateLog(LogObject log)
{
var logService = new BusinessDataServiceProxy();
logService.HostURL = ServerUrl;
try
{
logService.WriteLog(log);
}
catch (Exception ex)
{
if (ex.Message.Contains("ctx == null"))
{
// ctx == null表示当前用户尚未登录,或者登录太久,会话已失效。
Login();
WriteOperateLog(log);
}
}
}
/// <summary>
/// 批量写上机操作日志
/// </summary>
/// <param name="logs"></param>
public void WriteOperateLog(List<LogObject> logs)
{
var logService = new BusinessDataServiceProxy();
logService.HostURL = ServerUrl;
try
{
logService.BatchWriteLog(logs);
}
catch (Exception ex)
{
if (ex.Message.Contains("ctx == null"))
{
// ctx == null表示当前用户尚未登录,或者登录太久,会话已失效。
Login();
WriteOperateLog(logs);
}
}
}
}
/// <summary>
/// 访问星空的代理类基对象
/// </summary>
public class AbstractXkProxy
{
/// <summary>
/// 用户登录星空系统后的上下文
/// </summary>
public Context Context { get; set; }
/// <summary>
/// 星空系统的访问地址(例如:http://localhost/k3cloud/)
/// </summary>
public string ServerUrl { get; set; }
/// <summary>
/// 数据中中心内码
/// </summary>
public string Dbid { get; set; }
/// <summary>
/// 登录语言(中文2052)
/// </summary>
public int Lcid { get; set; }
/// <summary>
/// 登录账号
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 登录密码
/// </summary>
public string Password { get; set; }
public AbstractXkProxy()
{
}
/// <summary>
/// 初始化星空系统登录信息
/// </summary>
/// <param name="serverUrl"></param>
/// <param name="dbid"></param>
/// <param name="lcid"></param>
/// <param name="userName"></param>
/// <param name="password"></param>
public void Init(string serverUrl, string dbid, int lcid, string userName, string password)
{
ServerUrl = serverUrl;
Dbid = dbid;
Lcid = lcid;
UserName = userName;
Password = password;
}
/// <summary>
/// 登录星空系统
/// </summary>
/// <param name="serverUrl"></param>
/// <param name="dbid"></param>
/// <param name="lcid"></param>
/// <param name="userName"></param>
/// <param name="password"></param>
/// <returns></returns>
public Context Login(string serverUrl, string dbid, int lcid, string userName, string password)
{
ServerUrl = serverUrl;
Dbid = dbid;
Lcid = lcid;
UserName = userName;
Password = password;
return Login();
}
/// <summary>
/// 登录星空系统
/// </summary>
/// <returns></returns>
public Context Login()
{
var userProxy = new UserServiceProxy();
userProxy.HostURL = ServerUrl;
var reuslt = userProxy.ValidateUser(ServerUrl, Dbid, UserName, Password, "", Lcid);
Context = reuslt.IsSuccessByAPI ? reuslt.Context : null;
if (!reuslt.IsSuccessByAPI)
{
throw new Exception("会话失效,重新登录系统失败:" + reuslt.Message);
}
return Context;
}
}
}
<2>编写控制台小程序,使用代理接口访问星空系统,保存上机操作日志,代码如下。
using System;
using Kingdee.BOS.Core.Log;
namespace Jac.XkDemo.BOS.ProxyConsole
{
class Program
{
static void Main(string[] args)
{
// 上机操作日志写入测试
var logProxy = new LogProxy();
logProxy.Init("http://localhost:1600/k3cloud/", "602f2c09aee85f", 2052, "demo", "888888");
var log = new LogObject();
log.OperateName = "保存";
log.ObjectTypeId = "SAL_SaleOrder";
log.Environment = OperatingEnvironment.BizOperate;
log.Description = "上机操作日志写入测试!!!";
log.pkValue = "";
logProxy.WriteOperateLog(log);
//
Console.WriteLine("上机操作日志写入成功!!!");
Console.ReadLine();
}
}
}
<3>运行控制台程序,即可往星空系统写入上机操作日志。
【功能验证】
<1>登录业务站点,打开上机操作日志列表。
---------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.系统集成.使用代理接口保存上机操作日志
本文2024-09-23 04:18:43发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-164497.html