资料管理系统设计和实现

78 篇文章 6 订阅

为了方便部门内员工快速掌握相关的业务知识,所以设计实现了一个简单的在线资料管理系统。

把一些常见的业务知识整理好,发布在资料管理系统,方便职员遇到问题时查找资料,找到对应的办法解决。

主要实现的功能:

1.发布的资料可以归类。如:打印机问题,网络问题,电脑问题,电话机问题等等(这些类别可以配置)

2.发布的资料可以包含图片,附件文档等等。

3.权限控制。登录用户才能发布,编辑和删除资料。游客只能查看资料。


主要界面:

游客资料查询界面:


查看内容界面:


登录用户查询界面:


登录用户添加资料和编辑资料页面(可以放图片和上传附件):


主要实现代码:

实体定义:
	<entity entity-name="XnxyBlogKind" package-name="org.apache.ofbiz.xnxy" title="内容类型">
        <field name="kindId" type="id-ne"><description>primary sequenced ID</description></field>
        <field name="name" type="name"></field>
        <prim-key field="kindId"/>
    </entity>
	<entity entity-name="XnxyBlog" package-name="org.apache.ofbiz.xnxy" title="内容表">
        <field name="blogId" type="id-ne"><description>primary sequenced ID</description></field>
        <field name="title" type="name"></field>
        <field name="content" type="very-long"></field>
		<field name="kindId" type="name"></field>
        <prim-key field="blogId"/>
		<!--
		<relation type="one" fk-name="FK_XnxyBlog_XnxyBlogKind" rel-entity-name="XnxyBlogKind">
			<key-map field-name="courseId"/>
		</relation>
		-->
		<relation type="one-nofk" rel-entity-name="XnxyBlogKind" >
			<key-map field-name="kindId"/>
		</relation>
    </entity>

请求映射定义:
    <!-- Request Mappings -->
	<request-map uri="view">
        <security https="false" auth="false"/>
        <response name="success" type="request" value="main"/>
    </request-map>
    <request-map uri="main"><security https="true" auth="true"/><response name="success" type="view" value="main"/></request-map>
	
	<!-- ================ Blog Requests ================= 	-->
    <request-map uri="FindBlog">
        <security https="true" auth="false"/>
        <response name="success" type="view" value="FindBlog"/>
    </request-map>
	<request-map uri="ViewBlog">
        <security https="true" auth="false"/>
        <response name="success" type="view" value="ViewBlog"/>
    </request-map>
    <request-map uri="EditBlog">
        <security https="true" auth="true"/>
        <response name="success" type="view" value="EditBlog"/>
    </request-map>		
    <request-map uri="createBlog">
        <security https="true" auth="true"/>
        <event type="service"  invoke="createXnxyBlog"/>
        <response name="success" type="view" value="EditBlog"/>
        <response name="error" type="view" value="EditBlog"/>
    </request-map>
    <request-map uri="updateBlog">
        <security https="true" auth="true"/>
        <event type="service"  invoke="updateXnxyBlog"/>
        <response name="success" type="view" value="EditBlog"/>
        <response name="error" type="view" value="EditBlog"/>
    </request-map>
	<request-map uri="deleteBlog">  
		<security auth="true"  https="true"/>  
		<event type="service" invoke="deleteXnxyBlog" />  
		<response name="success" type="request-redirect-noparam" value="FindBlog"/>  
	</request-map> 
	

	<!-- View Mappings -->
	<view-map name="main" type="screen" page="component://system/widget/system/SystemScreens.xml#main"/>
	
	<view-map name="FindBlog" type="screen" page="component://system/widget/system/BlogScreens.xml#FindBlog"/>
	<view-map name="EditBlog" type="screen" page="component://system/widget/system/BlogScreens.xml#EditBlog"/>
	<view-map name="ViewBlog" type="screen" page="component://system/widget/system/BlogScreens.xml#ViewBlog"/>

服务定义:
	<service name="createXnxyBlog" default-entity-name="XnxyBlog" engine="entity-auto"  invoke="create" auth="true">  
		<description>Create a XnxyBlog</description>  
		<auto-attributes include="pk" mode="INOUT" optional="true"/>  
		<auto-attributes include="nonpk" mode="IN" optional="true" allow-html="any" /> 
	</service>  
	<service name="updateXnxyBlog" default-entity-name="XnxyBlog" engine="entity-auto" 	invoke="update" auth="true">  
		<description>Update a XnxyBlog</description>  
		<auto-attributes include="pk" mode="IN" optional="false"/>  
		<auto-attributes include="nonpk" mode="IN" optional="true" allow-html="any" />  
	</service>  
	<service name="deleteXnxyBlog" default-entity-name="XnxyBlog" engine="entity-auto"  invoke="delete" auth="true">  
		<description>Delete a XnxyBlog</description>  
		<auto-attributes include="pk" mode="IN" optional="false"/>  
	</service>  

界面和模板定义:
BlogScreens.xml
<?xml version="1.0" encoding="UTF-8"?>
<screens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://ofbiz.apache.org/Widget-Screen" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Screen http://ofbiz.apache.org/dtds/widget-screen.xsd">
	<screen name="FindBlog">
        <section>
            <actions>
				<set field="allowVisitors" value="true"/>
                <set field="titleProperty" value="BlogManange"/>
				<set field="headerItem" value="BlogManange"/>
                <set field="viewIndex" from-field="parameters.VIEW_INDEX" type="Integer"/>
                <property-to-field resource="widget" property="widget.form.defaultViewSize" field="viewSizeDefaultValue"/>
                <set field="viewSize" from-field="parameters.VIEW_SIZE" type="Integer" default-value="${viewSizeDefaultValue}"/>
            </actions>
            <widgets>
                <decorator-screen name="CommonMyDecorator" location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
                        <section>
							
                            <widgets>
                                <decorator-screen name="FindScreenDecorator" location="component://common/widget/CommonScreens.xml">
                                    <decorator-section name="menu-bar">
                                        <container style="button-bar">
                                            <section>
												<condition>  
													<if-empty field="userLogin"/>  
												</condition>  
												 <actions>  
													 
												 </actions>  
												 <widgets>  
													
												 </widgets>  
												 <fail-widgets>  
													 <link target="EditBlog" text="${uiLabelMap.EditBlog}" style="buttontext"/>
												 </fail-widgets>  
											 </section>
                                        </container>
                                    </decorator-section>
                                    <decorator-section name="search-options">
                                        <include-form name="FindBlog" location="component://system/widget/system/BlogForms.xml"/>
                                    </decorator-section>
                                    <decorator-section name="search-results">
                                        <include-form name="ListFindBlog" location="component://system/widget/system/BlogForms.xml"/>
                                    </decorator-section>
                                </decorator-screen>
                            </widgets>
                        </section>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
	<screen name="EditBlog">
        <section>
            <actions>
                <set field="titleProperty" value="TchInfoManange"/>
                <set field="headerItem" value="TchInfoManange"/>
				<entity-one entity-name="XnxyBlog" value-field="blog"/>
            </actions>
            <widgets>
                <decorator-screen name="CommonMyDecorator" location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
						<container style="button-bar">
							<link target="FindBlog" text="${uiLabelMap.CommonBack}" style="buttontext"/>
						</container>
                        <include-form name="EditBlog" location="component://system/widget/system/BlogForms.xml"/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
	<screen name="ViewBlog">
        <section>
            <actions>
				<property-map resource="SYSTEMUiLabels" map-name="uiLabelMap" global="true"/>
                <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/>
                <set field="titleProperty" value="TchInfoManange"/>
                <set field="headerItem" value="TchInfoManange"/>
				<entity-one entity-name="XnxyBlog" value-field="blog"/>
            </actions>
            <widgets>
				<section>
					<condition>  
						<if-empty field="parameters.layeredEnable"/>  
					</condition>   
					<widgets>  
						<decorator-screen name="CommonMyDecorator" location="${parameters.mainDecoratorLocation}">
							<decorator-section name="body">
								<container style="button-bar">
									<link target="FindBlog" text="${uiLabelMap.CommonBack}" style="buttontext"/>
								</container>
								<platform-specific>
									<html><html-template location="component://system/template/system/BlogView.ftl"/></html>
								</platform-specific>  
							</decorator-section>
						</decorator-screen>
					 </widgets>  
					 <fail-widgets>  
						<platform-specific>
							<html><html-template location="component://system/template/system/BlogView.ftl"/></html>
						</platform-specific>  
					 </fail-widgets>  
				
				
				</section>
				
            </widgets>
        </section>
    </screen>
	
</screens>
BlogForms.xml
<?xml version="1.0" encoding="UTF-8"?>

<forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns="http://ofbiz.apache.org/Widget-Form" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Form http://ofbiz.apache.org/dtds/widget-form.xsd">
    
    <form name="FindBlog" target="FindBlog" title="" type="single"
        header-row-style="header-row" default-table-style="basic-table">
		<field name="kindId" title="${uiLabelMap.SystemKindName}">
            <drop-down allow-empty="true" >
				<entity-options entity-name="XnxyBlogKind" key-field-name="kindId" description="${name}">  
					<!--<entity-constraint name="facilityTypeId" value="WAREHOUSE"/>-->  
					<!--<list-options list-name=""  key-name=""/>-->  
				</entity-options>  
            </drop-down>
        </field>
		<field name="title" title="${uiLabelMap.SystemTitle}"><text-find/></field>
		<field name="content" title="${uiLabelMap.SystemContent}"><text-find/></field>
        <field name="submitButton" title="${uiLabelMap.CommonFind}"><submit/></field>
    </form>

    <form name="ListFindBlog" list-name="listIt" title="" type="list" paginate-target="FindBlog"
        odd-row-style="alternate-row" default-table-style="basic-table hover-bar">
        <actions>
            <service service-name="performFind" result-map="result" result-map-list="listIt">
                <field-map field-name="inputFields" from-field="requestParameters"/>
                <field-map field-name="entityName" value="XnxyBlog"/>
                <field-map field-name="viewIndex" from-field="viewIndex"/>
                <field-map field-name="viewSize" from-field="viewSize"/>
				<field-map field-name="noConditionFind" value="Y"/>
            </service>
        </actions>
		<row-actions>
			<entity-one entity-name="XnxyBlogKind" value-field="blogKind">
                <field-map field-name="kindId" from-field="kindId"/>
            </entity-one>
		</row-actions>
		<field name="blogId" title="${uiLabelMap.SystemBlogId}" widget-style="buttontext">
			<hyperlink description="${blogId}" target="ViewBlog" >
                <parameter param-name="blogId" from-field="blogId"/>
            </hyperlink>
		</field>
        <field name="kindId" title="${uiLabelMap.SystemKindName}"><display description="${blogKind.name}"/></field>
		<field name="title" title="${uiLabelMap.SystemTitle}"><display/></field>
		<!--
        <field name="content" title="${uiLabelMap.SystemContent}"><display/></field>
		-->
		<field name="viewLink" title=" " widget-style="buttontext">
            <hyperlink description="${uiLabelMap.CommonView}" target="ViewBlog" also-hidden="false" link-type="layered-modal" >
                <parameter param-name="blogId" from-field="blogId"/>
				<parameter param-name="layeredEnable" from-field="blogId"/>
            </hyperlink>
        </field>
		<field use-when="userLogin != null" name="updateLink" title=" " widget-style="buttontext">
            <hyperlink description="${uiLabelMap.CommonUpdate}" target="EditBlog" >
                <parameter param-name="blogId"/>
            </hyperlink>
        </field>
        <field use-when="userLogin != null" name="deleteLink" title=" " widget-style="buttontext">
            <hyperlink description="${uiLabelMap.CommonDelete}" target="deleteBlog" also-hidden="false">
                <parameter param-name="blogId"/>
            </hyperlink>
        </field>
        
    </form>
	<form name="EditBlog" target="updateBlog" title="" type="single" header-row-style="header-row" 
		default-title-style="treeHeader" default-widget-style="inputBox" default-map-name="blog" default-entity-name="XnxyBlog">
		<alt-target use-when="blog==null" target="createBlog"/>
		<!--<auto-fields-service service-name="updateXnxyBlog" map-name=""/>-->
		<field name="blogId" title="${uiLabelMap.SystemBlogId}" ><hidden/></field>
		<field name="kindId" title="${uiLabelMap.SystemKindName}">
            <drop-down allow-empty="false" >
				<entity-options entity-name="XnxyBlogKind" key-field-name="kindId" description="${name}">  
				</entity-options>  
            </drop-down>
        </field>
        <field name="title" title="${uiLabelMap.SystemTitle}" required-field="true"><text size="100" maxlength="100" /></field>
		<field name="content" title="${uiLabelMap.SystemContent}" widget-style="inputBox" ><textarea cols="50" rows="20" visual-editor-enable="true"/></field>
        <field name="submitButton" title="${uiLabelMap.CommonSubmit}">
			<submit/>
		</field>
    </form>
	<form name="ViewBlog" target="updateBlog" title="" type="single" header-row-style="header-row" 
		default-table-style="basic-table" default-map-name="blog" default-entity-name="XnxyBlog">
		<actions>
            <entity-one entity-name="XnxyBlogKind" value-field="blogKind">
                <field-map field-name="kindId" from-field="blog.kindId"/>
            </entity-one>
        </actions>
		<auto-fields-service service-name="updateXnxyBlog" map-name=""/>
		<field name="blogId" title="${uiLabelMap.SystemBlogId}"><hidden/></field>
		<field name="kindId" title="${uiLabelMap.SystemKindName}">
			<display description="${blogKind.name}"/>
        </field>
        <field name="title" title="${uiLabelMap.SystemTitle}" ><display /></field>
		<field name="content" title="${uiLabelMap.SystemContent}" ><display  /></field>

    </form>
	
</forms>

BlogView.ftl
  
<center>
<h1>${blog.title}</h1>
</center>
<hr/>
<div id="${blog.blogId}_content">
</div>

<script type="text/javascript">    
  
function HTMLEncode(html) {
 var temp = document.createElement("div");
 (temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html);
 var output = temp.innerHTML;
 temp = null;
 return output;
}
function HTMLDecode(text) { 
 var temp = document.createElement("div"); 
 temp.innerHTML = text; 
 var output = temp.innerText || temp.textContent; 
 temp = null; 
 return output; 
} 
jQuery("#${blog.blogId}_content").html(HTMLDecode("${blog.content}"))
//jQuery("#${blog.blogId}_content").html("${blog.content}")
</script> 

主要代码就是以上这些,一些国际化资源文件配置就不写了。

总结

虽然这个系统很简单,但也遇到了几个问题。
1. 富文本编辑器问题。
    ofbiz自带的富文本编辑器是集成的jquery的elrte编辑器。对插入图片和附件功能感觉很弱,不方便使用。
    所以我替换成了ueditor编辑器。替换方法参考: http://blog.csdn.net/xiaozaq/article/details/78467808

2.输入的文本包含大于(>)或小于(<)符号时会报错。
    解决办法:定义服务时,入参配置allow-html="any" 。具体参考: http://blog.csdn.net/xiaozaq/article/details/78474630

3. 显示ueditor编辑器内容时,发现里面的内容被转义了,导致显示结果不是预期想要的。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值