資料管理系統設計和實現

xiaozaq發表於2017-11-09

為了方便部門內員工快速掌握相關的業務知識,所以設計實現了一個簡單的線上資料管理系統。

把一些常見的業務知識整理好,釋出在資料管理系統,方便職員遇到問題時查詢資料,找到對應的辦法解決。

主要實現的功能:

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編輯器內容時,發現裡面的內容被轉義了,導致顯示結果不是預期想要的。




相關文章