用代码写入[上机操作日志]原创
金蝶云社区-山抹微云
山抹微云
15人赞赏了该文章 1,113次浏览 未经作者许可,禁止转载编辑于2021年11月22日 11:41:54

  大家都知道,在操作里,可以选择是否写入日志,如下图,

  image.png

  如果有写入操作日志,则在[上机操作日志]上能查询到,如下图

  image.png

  当我们在二开时候,可能会要遇到非操作却要写入日志的。我的参考函数如下

  

    protected AppLogInfo buildLogInfo(String msg, Long orgId) {

        AppLogInfo logInfo = new AppLogInfo();

        logInfo.setUserID(Long.valueOf(RequestContext.get().getCurrUserId()  ));  ////操作人员

        String appNumber = this.getView().getFormShowParameter().getAppId();   ////操作应用ID

        String appId = " ";

        if (StringUtils.isNotEmpty(appNumber)) {

            AppInfo appInfo = AppMetadataCache.getAppInfo(appNumber);

            if (null != appInfo) {

                appId = appInfo.getId();

            }

        }


        logInfo.setBizAppID(appId);

        logInfo.setBizObjID(this.getView().getEntityId());  ////设置实体ID

        if (orgId != null && Long.compare(0L, orgId) != 0) {

            logInfo.setOrgID(orgId);

        } else {

            logInfo.setOrgID(RequestContext.get().getOrgId());  ////设置组织.

        }


        TimeService timeService = new TimeService();

        logInfo.setOpTime(timeService.getCurrentSystemTime());

        logInfo.setClientType(RequestContext.get().getClient());

        logInfo.setClientIP(RequestContext.get().getLoginIP());

        logInfo.setOpName("ldq");

        logInfo.setOpDescription(msg);

        return logInfo;

    }

调用代码如下

        ILogService logService = (ILogService) ServiceFactory.getService(ILogService.class);

        AppLogInfo logInfo = this.buildLogInfo("开心",  RequestContext.get().getOrgId() );

        logService.addLog(logInfo);

  说明下,我这些代码都是在 继承了AbstractBillPlugIn 这个基类的类里,即表单编辑插件了。

  效果如上图。

  原创不易,如有收获,请点赞支持。

赞 15