`
brandNewUser
  • 浏览: 453115 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ApacheOFBiz的相关介绍以及使用总结(三)

阅读更多
Ofbiz中还提供了一些基础性服务,可以直接用来使用,下面就简单介绍说明一下。
 

ofbiz邮件发送服务

 
ofbiz中提供发送邮件相关功能:sendMailFromScreen
 
context.get(“userLogin”),可以拿到当前登录用户的所有信息,其中的属性 userLoginId用户登录ID,可以用于获取用户登录的相应信息。
 


 
 
发送邮件的过程中出现了错误,提示进行连接inform@xxx.com,怀疑是由于连接的问题。
 
可以参考页面:
 
 
来实现我们的页面内容及其形式。
 

邮件发送服务

 
邮件发送服务的基本设置,需要修改配置文件:framework/common/config/general.properties,
 
# -- general default 'fromEmailAddress' can be overridden in: EmailTemplateSetting
defaultFromEmailAddress=inform@xxx.com
#defaultFromEmailAddress=xxx@163.com

# -- The default domainname used in the notification emails links
# as 'baseUrl' and 'baseSecureUrl' are set in the url.properties file. 

# -- mail notifications enabled (Y|N)
mail.notifications.enabled=Y

# -- redirect all mail notifications to this address for testing
#mail.notifications.redirectTo=

# -- the default mail server to use
mail.smtp.relay.host=smtp.mxhichina.com: inform@xxx.com
#mail.smtp.relay.host=smtp.xxx.com

# -- SMTP Auth settings
mail.smtp.auth.user=inform@xxx.com
mail.smtp.auth.password=xxx@

#mail.smtp.auth.user=xxx@163.com
#mail.smtp.auth.password=xxx

# -- Additional Required Fields needed for Gmail and other non traditional smtp servers
# -- These added fields also work for Yahoo business mail for instance
# -- Gmail smtp port can be either 465 or 587
mail.smtp.port=25
 
 
由于阿里提供的邮箱不能支持,因此暂时选择使用163的邮箱来进行邮件发送(在注释中)。
 
可以通过ofbiz中的“服务引擎工具->运行任务”来进行邮件发送的测试:
 


 
 
发送邮件的服务名称为:sendMail,提交任务完成后,会启动发送邮件的过程:
 


 
 
此时,需要提供的参数主要有:sendFrom, sendTo, subject, body。
 
如果服务器设置得没有问题,发送邮件就会成功,页面中会有如下的提示:
 


 
 
 
如何在我们自己的服务中调用sendMail服务
 
我们在自己的服务中如何调用sendMail服务,可以自定义一个服务,跟以前一样,类似如下的方式:
 
public static Map<String, Object> sendNotifyEmail(DispatchContext dispatchContext, Map<String, Object> sendMailContext) {
        LocalDispatcher dispatcher = dispatchContext.getDispatcher();

        sendMailContext.put("sendFrom", "xxx@163.com");
        sendMailContext.put("sendTo", "xxx@xxx.com");
        sendMailContext.put("subject", "Test to xxx");
        sendMailContext.put("body", "bodyUrl");
        Map<String, Object> sendMailResult;
        try {
            sendMailResult = dispatcher.runSync("sendMail", sendMailContext);
        } catch (GenericServiceException e) {
            Debug.logError(e, module);
            return ServiceUtil.returnError(e.getMessage());
        }

        return Collections.emptyMap();
    }
 
 
核心就是使用 dispatcher.runSync(“sendMail”, sendMailContext),同步地调用发送邮件服务。
 

如何定时调用sendMail服务

 
如果需要定时调用发送邮件服务,可以使用“服务引擎工具->任务计划”:
 
新建一个任务计划,后续需要继续添加服务需要的参数:
 


 
 
就可以每天执行一次,直到执行到结束日期,或计数次数为止。
 
任务提交后,就可以在任务列表中查看刚才新建的服务:
 


 
 
定时的任务执行完成后,就可以在任务列表中看到其状态。
 


 
 

Ofbiz中的参照实现

 
一般在选择学员时,为了关联相应的数据,我们采用的是使用 drop-down方式,这样能够保证数据能够关联成功,但是如果学员数据比较多,这种方式就变得不可取了。
 
而ofbiz中已经提供了相应的了参照实现,其具体形式为:
 


 
通过阅读源代码,可以找到其中使用的参照类型:
 
<lookup target-form-name="LookupEmplPosition"/>
 
其中的target-form就是在对话框中显示的表单数据,定义在LookupForms.xml中:
 
<form name="LookupEmplPosition" type="single" target="LookupEmplPosition"
        header-row-style="header-row" default-table-style="basic-table">
        <auto-fields-entity entity-name="EmplPosition" default-field-type="hidden"/>
        <field name="emplPositionId" title="${uiLabelMap.HumanResEmplPositionId}"><text-find/></field>
        <field name="statusId">
            <drop-down allow-empty="true">
                <entity-options description="${description}" key-field-name="statusId" entity-name="StatusItem"></entity-options>
            </drop-down>
        </field>
        <field name="emplPositionTypeId">
            <drop-down allow-empty="true">
                <entity-options description="${description}" key-field-name="emplPositionTypeId" entity-name="EmplPositionType"></entity-options>
            </drop-down>
        </field>
        <field name="partyId"><lookup  target-form-name="LookupPartyName"/></field>
        <field name="budgetId"><lookup  target-form-name="LookupBudget"/></field>
        <field name="budgetItemSeqId"><lookup  target-form-name="LookupBudgetItem"/></field>
        <field name="noConditionFind"><hidden value="Y"/><!-- if this isn't there then with all fields empty no query will be done --></field>
        <field name="submitButton" title="${uiLabelMap.CommonFind}" widget-style="smallSubmit"><submit button-type="button"/></field>
    </form>
 
 
可以找出其中的target=”LookupEmplPosition”,在controller.xml中找到对应的request-map,来确定其基本位置:
 
<request-map uri="LookupEmplPosition">
    <security auth="true" https="true"/><response name="success" type="view" value="LookupEmplPosition"/>
</request-map>
 
 
对应的view-map:
 
    <view-map name="LookupEmplPosition"  type="screen" page="component://humanres/widget/LookupScreens.xml#LookupEmplPosition"/>
 
 
找到对应的Screen,突然发现ofbiz默认每个模块都会有对应LookupScreens.xml,说明这还是一种比较通用的需求。
 
<screen name="LookupEmplPosition">
        <section>
            <actions>
                <property-map resource="HumanResUiLabels" map-name="uiLabelMap" global="true"/>
                <set field="title" value="${uiLabelMap.HumanResLookupEmplPositionByName}"/>
                <set field="queryString" from-field="result.queryString"/>
                <set field="viewIndex" from-field="parameters.VIEW_INDEX" type="Integer" default-value="0"/>
                <property-to-field resource="widget" property="widget.form.defaultViewSize" field="viewSizeDefaultValue"/>
                <set field="viewSize" from-field="parameters.VIEW_SIZE" type="Integer" default-value="${viewSizeDefaultValue}"/>
                <set field="entityName" value="EmplPosition"/>
                <set field="searchFields" value="[emplPositionId, partyId, emplPositionTypeId]"/>
            </actions>
            <widgets>
                <decorator-screen name="LookupDecorator" location="component://common/widget/CommonScreens.xml">
                    <decorator-section name="search-options">
                        <include-form name="LookupEmplPosition" location="component://humanres/widget/forms/LookupForms.xml"/>
                    </decorator-section>
                    <decorator-section name="search-results">
                        <include-form name="ListEmplPositions" location="component://humanres/widget/forms/LookupForms.xml"/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
 
 
查询后的结果还需要能够设置到调出参照之前的表单中,例如下面的 雇员职位编号,就有这个功能,其表现形式为一个大按钮:
 


 
 
可以查看到该按钮是一个hyberlink:
 
<field name="emplPositionId" widget-style="buttontext">
            <hyperlink also-hidden="false" target-type="plain" description="${emplPositionId}" target="javascript:set_value('${emplPositionId}')"/>
        </field>
 
 
这可以帮助我们在选择对应的按钮之后,将设置的值返回回去,填充对应的表单。
 

Ofbiz中导出excel/pdf文件 

<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->

在原有的ofbiz程序中,已经有了相关导出excel文件的示例,可以参考其实现,其导出格式为csv文件。
 
“设备”管理中的“场所管理应用程序”:
 
 
参考其中的功能:打印,导出,导出所有的应用程序。
 
比如打印这个功能:
 
 
<request-map uri="ListGlAccountOrgCsv.csv">
        <security https="true" auth="true"/>
        <response name="success" type="view" value="ListGlAccountOrgCsv"/>
    </request-map>
 
 
type仍然为view,其value为ListGlAccountOrgCsv,
 
在view-map查找这个属性,可以看到其中的设置为:
 
 
<view-map name="ListGlAccountOrgPdf" type="screenfop" page="component://accounting/widget/GlSetupScreens.xml#ListGlAccountOrgPdf" content-type="application/pdf" encoding="none"/>
    <view-map name="ListGlAccountOrgCsv" type="screencsv" page="component://accounting/widget/GlSetupScreens.xml#ListGlAccountOrgCsv" content-type="text/csv" encoding="none"/>
 
 
可以注意到其中不仅可以支持csv文件,还可以支持pdf。
 
在具体的GlSetupScreens.xml文件中,可以看到csv的写法:
 
<screen name="ListGlAccountOrgCsv">
        <section>
            <actions>
                <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="AccountingUiLabels" map-name="uiLabelMap" global="true"/>
                <set field="organizationPartyId" from-field="parameters.organizationPartyId"/>
            </actions>
            <widgets>
                    <include-form name="ListGlAccountOrgCsv" location="component://accounting/widget/GlSetupForms.xml"/>           
            </widgets>
        </section>
    </screen>
 
 
此外,其中pdf的写法:
 
<screen name="ListGlAccountOrgPdf">
        <section>
            <actions>
                <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="AccountingUiLabels" map-name="uiLabelMap" global="true"/>
                <set field="organizationPartyId" from-field="parameters.organizationPartyId"/>
                <entity-condition entity-name="GlAccountOrganizationAndClass" list="glAccountOrgAndClassList">
                    <condition-expr field-name="organizationPartyId" from-field="organizationPartyId"/>
                    <order-by field-name="glAccountId"/>
                </entity-condition>
            </actions>
            <widgets>
                <platform-specific>
                    <xsl-fo>
                        <html-template location="component://accounting/webapp/accounting/reports/ChartOfAccount.fo.ftl"/>
                    </xsl-fo>
                </platform-specific>
            </widgets>
        </section>
    </screen>
 
 
可以注意的是,pdf是根据ftl后缀名的文件来进行的,也就是说需要写一个freemarker文件来根据html的样式来导出对应格式的文件。
 
关于csv文件,以及pdf文件的链接地址写法:
 
<link text="${uiLabelMap.AccountingExportAsCsv}" style="button" target="ListGlAccountOrgCsv.csv">
                            <parameter param-name="organizationPartyId"/>
                        </link>
                        <link text="${uiLabelMap.AccountingExportAsPdf}" style="button" target="ListGlAccountOrgPdf.pdf" target-window="_BLANK">
                            <parameter param-name="organizationPartyId"/>
                        </link>
 
 
 
如果是csv文件,直接下载;如果是pdf文件,声明在另一个blank窗口打开该文件 

 

 
 
  • 大小: 27.2 KB
  • 大小: 36.7 KB
  • 大小: 95.9 KB
  • 大小: 194.2 KB
  • 大小: 68.1 KB
  • 大小: 103.9 KB
  • 大小: 38.6 KB
  • 大小: 4.6 KB
  • 大小: 41.1 KB
分享到:
评论

相关推荐

    Apache OFBiz Cookbook

    - **定义**:Apache OFBiz(Open For Business)是一款开源的企业级应用框架,它集成了ERP(企业资源规划)、CRM(客户关系管理)以及E-commerce(电子商务)等多种功能。其设计目标是为了提供一个灵活且可扩展的...

    Apache OFBiz Development The Beginner's Tutorial

    ### Apache OFBiz 开发入门教程知识点汇总 #### Apache OFBiz 概述 - **社区驱动的开源项目**:Apache OFBiz 是一个完全免费且由社区维护的开源项目。 - **功能强大**:作为最佳电子商务与企业资源规划(ERP)软件...

    Apache.OFBiz.Development

    11. 扩展和重构OFBiz:包括了将现有的BeanShell脚本转换为Java事件,以及使用了哪种扩展策略来优化OFBiz的开发。 12. 测试与备份:介绍了如何保存测试的快照点,备份Derby数据库文件和Web服务器工作文件,以便快速...

    开源ERP-apache-ofbiz-17.12.07.zip

    Apache OFBiz 是用于企业流程自动化的开源产品,包括 ERP(企业资源规划)、CRM(客户关系管理)、电子商务/电子商务、SCM(供应链管理)、MRP(制造资源规划)、MMS / EAM(维护管理系统/企业资产管理)的框架组件...

    Apache OFBiz Datamodel 2

    Apache OFBiz Datamodel 2

    apache-ofbiz-16.11.02源码+ofbiz菜鸟笔记+Apache+OFBiz+开发初学者指南

    apache-ofbiz-16.11.02.zip,ofbiz菜鸟笔记,Apache+OFBiz+开发初学者指南.chm

    Apache OFBiz Development The Beginners Tutorial

    学习Opentaps和Ofbiz的经典入门!

    Apache OFBiz Datamodel 4

    本篇文章将详细介绍 Apache OFBiz Datamodel 4 的主要概念和关键组件。 #### 二、Datamodel 构建元素解析 **1. InvoiceTypeAttr** - **定义**: `InvoiceTypeAttr` 代表发票类型属性,用于定义特定类型的发票具有...

    Apache+OFBiz+开发初学者指南

    在学习Apache OFBiz的过程中,你可以参考提供的"Apache+OFBiz+开发初学者指南.chm"文件,这可能包含了OFBiz的基础知识、安装指南、开发环境的搭建以及基本操作的示例。同时,"OFBiz其它资源.txt"文件可能包含了一些...

    Apache OFBiz Datamodel 3

    ### Apache OFBiz Datamodel 3 #### 概述 Apache OFBiz Datamodel 3 是一个高级的数据模型系统,主要用于管理电子商务、供应链管理等业务场景下的数据流与数据结构。OFBiz 本身是一款开源的企业级应用框架及应用...

    Getting Started with Apache OFBiz Manufacturing.pdf )

    本部分将详细介绍如何通过五个简单的步骤开始使用 Apache OFBiz 进行制造管理和 MRP 实施。 ##### 步骤一:理解您的制造流程 在开始使用 OFBiz 之前,首先需要对您的制造流程有深入的理解。这包括识别关键的制造...

    opentaps (from apache ofbiz) 架构图 (chart of architecture)

    本篇文章将深入探讨OpenTaps和Apache OfBiz的架构,以及它们如何协同工作。 **1. Apache OfBiz概述** Apache OfBiz是基于Java的开源企业应用框架,由Apache软件基金会维护。OfBiz提供了全面的业务组件和服务,支持...

    ofbiz资料大全

    Apache+OFBiz+开发初学者指南.rar OFBiz开发快速入门.rar OFBiz-技术文档.rar OFBiz API中文版.rar Apache OFBiz Cookbook Sep 2010.rar Opentaps widget使用说明.rar OFBiz.Development.2008.rar Groovy中文...

    ofbiz:Apache OFBiz-主要开发已移至ofbiz-frameworks存储库

    ApacheOFBiz:registered: 欢迎使用ApacheOFBiz:registered: ! 一个功能强大的顶级Apache软件项目。 OFBiz是用Java编写的企业资源计划(ERP)系统,并包含大量库,实体,服务和功能,以运行您的业务的各个方面。 ...

    Apache OFBiz E-Business Solutions.pdf

    Apache OFBiz是一种开源的电子商务解决方案,其全称为Open For Business。它是一个功能强大的企业级电子商务平台,能够在组织内部构建稳健的电子商业系统。本文档涵盖的内容以OFBiz 9.04版本为核心,详细介绍了OFBiz...

    CVE-2021-26295 Apache OFBiz 反序列化漏洞.md

    CVE-2021-26295 Apache OFBiz 反序列化漏洞

    Apache OFBiz企业流程自动化 v18.12.06.zip

    Apache OFBiz企业流程自动化 v18.12.06.zip

Global site tag (gtag.js) - Google Analytics