跟我一起学extjs5(33--单个模块的设计[1建立表和bean])

跟我一起学extjs5(33--单个模块的设计[1建立表和bean])


        现在开始进入这个系统的第一个核心部分,就是如何对模块的功能进行设计。请看下图,一个最简单的模块包括的内容有:模块属性,字段属性,列表定义和表单定义。

        在上面的定义中,一个模块可以有n个字段组成,可以有若干个列表方案和表单方案;每一个列表和表单可以有若干个组组成,每个组下面又有若干个字段。这样的设计也符合这个教程的前20节中设计出来的功能。现在要做的就是把这些功能做成前后台交互的。
        先开始模块字段和列表方案的定义。以上各个方案的定义也都是放在数据库中的,因此先要建立好各个表和java bean。
        建立模块字段的表 _ModuleField。
CREATE TABLE [dbo].[_ModuleField](
	[tf_fieldId] [int] NOT NULL,
	[tf_moduleId] [nvarchar](10) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[tf_fieldOrder] [int] NULL,
	[tf_title] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[tf_fieldName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[tf_fieldType] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[tf_fieldGroup] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_fieldLen] [int] NULL,
	[tf_propertyTypeId] [int] NULL,
	[tf_isHidden] [bit] NULL,
	[tf_isReadonly] [bit] NULL,
	[tf_isRequired] [bit] NULL,
	[tf_isDisable] [bit] NULL,
	[tf_isUserDefine] [bit] NULL,
	[tf_userDefine] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_allowGroup] [bit] NULL,
	[tf_allowSummary] [bit] NULL,
	[tf_otherSetting] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_defaultValue] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_remark] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_fieldRelation] [nvarchar](20) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_newNeedSelected] [bit] NULL,
	[tf_showNavigatorTree] [bit] NULL,
	[tf_DBFieldName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_DBformula] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_divisor] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_denominator] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_allowNew] [bit] NULL,
	[tf_allowEdit] [bit] NULL,
	[tf_allowInsertExcel] [bit] NULL,
	[tf_allowEditExcel] [bit] NULL,
	[tf_haveAttachment] [bit] NULL,
	[tf_isChartCategory] [bit] NULL,
	[tf_isChartNumeric] [bit] NULL,
 CONSTRAINT [PK___ModuleField__4D94879B] PRIMARY KEY CLUSTERED 
(
	[tf_fieldId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [_ModuleField_ix1] UNIQUE NONCLUSTERED 
(
	[tf_moduleId] ASC,
	[tf_title] ASC,
	[tf_fieldName] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

        模块字段的:java bean
package com.jfok.server.hibernate.system;

import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import com.jfok.server.common.annotation.FieldDefine;
import com.jfok.server.common.annotation.TableDefine;

/**
 * 每个模块的各个字段
 * 
 * @author jfok
 * 
 */
@JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY)
@SuppressWarnings("serial")
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true)
@TableDefine(group = "系统模块", id = 9903, title = "模块字段")
public class _ModuleField implements Serializable, _IModuleControlInterface {

	public static final String FIELDID = "tf_fieldId";
	public static final String FIELDNAME = "tf_fieldName";
	public static final String MANYTOONE = "ManyToOne";
	public static final String ONETOONE = "OneToOne";
	public static final String ONETOMANY = "OneToMany";

	@Id
	@FieldDefine(title = "字段序号", number = 10)
	@Column(nullable = false)
	private Integer tf_fieldId;

	@JsonIgnore
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	@JoinColumn(name = "tf_moduleId", nullable = false)
	@FieldDefine(title = "所属模块", number = 20)
	private _Module tf_Module;

	@JsonIgnore
	@FieldDefine(title = "顺序号", number = 30)
	private Integer tf_fieldOrder;

	@FieldDefine(title = "字段描述", number = 40, nameField = true)
	@Column(length = 50, nullable = false)
	private String tf_title;

	@FieldDefine(title = "字段名", number = 50)
	@Column(length = 50, nullable = false)
	private String tf_fieldName;

	@FieldDefine(title = "类型", number = 60)
	@Column(length = 50, nullable = false)
	private String tf_fieldType;

	@JsonProperty("l")
	@FieldDefine(title = "长度", number = 70)
	private Integer tf_fieldLen;

	@FieldDefine(title = "字段分组", number = 75)
	private String tf_fieldGroup;

	// 字段的关联类型 ,ManyToOne,OneToOne,OneToMany
	@JsonIgnore
	@FieldDefine(title = "关联类型", number = 80)
	@Column(length = 20)
	private String tf_fieldRelation;

	@JsonIgnore
	@FieldDefine(title = "表字段实名", remark = "数据表中的实际字段名", number = 90)
	@Column(length = 50)
	private String tf_DBfieldName;

	@JsonIgnore
	@FieldDefine(title = "字段公式", remark = "公式字段的具体内容", number = 100)
	private String tf_DBformula;

	@JsonIgnore
	@FieldDefine(title = "百分比分子", number = 105, remark = "如果这个字段是二个字段的比值,设置分子字段和分母字段,可以在汇总的时候也得出正确的比值")
	@Column(length = 50)
	private String tf_divisor;

	@JsonIgnore
	@FieldDefine(title = "百分比分母", number = 106)
	@Column(length = 50)
	private String tf_denominator;

	@FieldDefine(title = "缺省值", number = 110)
	@Column(length = 50)
	private String tf_defaultValue;

	// @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	// @JoinColumn(name = "tf_propertyTypeId")
	// @FieldDefine(title = "字段列表属性", number = 120)
	// private _PropertyType tf_PropertyType;

	@FieldDefine(title = "禁用", number = 130)
	private Boolean tf_isDisable;

	@FieldDefine(title = "隐藏", number = 140)
	private Boolean tf_isHidden;

	@JsonIgnore(false)
	@FieldDefine(title = "必填", number = 150)
	private Boolean tf_isRequired;

	@FieldDefine(title = "可新增", number = 160)
	private Boolean tf_allowNew;

	@FieldDefine(title = "可修改", number = 170)
	private Boolean tf_allowEdit;

	@JsonIgnore
	@FieldDefine(title = "可导航", remark = "选中才可以在导航树中显示", number = 180)
	private Boolean tf_showNavigatorTree;

	@FieldDefine(title = "可分组", number = 190)
	private Boolean tf_allowGroup; // 是否允许分组

	@FieldDefine(title = "小计", number = 200)
	private Boolean tf_allowSummary; // 是否可以小计及总计

	@FieldDefine(title = "新增选中", remark = "在新增一条记录时,是否必须在导航树中选择此字段的值", number = 210)
	private Boolean tf_newNeedSelected;

	@FieldDefine(title = "字段附件", remark = "可以增加针对此字段的附件", number = 212)
	private Boolean tf_haveAttachment;

	@JsonIgnore
	@FieldDefine(title = "自定义", number = 220)
	private Boolean tf_isUserDefine;

	@FieldDefine(title = "其他设置", number = 230)
	private String tf_otherSetting;

	@JsonIgnore
	@FieldDefine(title = "Excel导入", remark = "Excel导入新增时加入此字段可新增", number = 240)
	private Boolean tf_allowInsertExcel;

	@JsonIgnore
	@FieldDefine(title = "Excel修改", remark = "Excel修改后再导入时此字段可更新", number = 250)
	private Boolean tf_allowEditExcel;

	@FieldDefine(title = "图表项目", remark = "此字段可以作为图表分析中的一个项目", number = 260)
	private Boolean tf_isChartCategory;

	@FieldDefine(title = "图表数据", remark = "此字段可以作为图表分析中的一个数据", number = 270)
	private Boolean tf_isChartNumeric;

	@FieldDefine(title = "备注", number = 800)
	private String tf_remark;

	// 如果是一个manytoone的字段,那么显示实际ID的字段 _
	@Transient
	private String manytoone_IdName;

	// 如果是一个manytoone的字段,那么显示实际title的字段 _
	@Transient
	private String manytoone_TitleName;

	public _ModuleField() {

	}
    //getter and setter
}

        在上面的这个java类中,对模块字段设置了许多的属性可供定义,这个可以根据软件的扩充自己进行加入和处理。在这个例子中,我只能讲一下最简单的一些属性的应用。

        建立模块列表方案表,列表方案分组表和列表方案分组的字段表。
CREATE TABLE [dbo].[_ModuleGridScheme](
	[tf_gridSchemeId] [int] NOT NULL,
	[tf_moduleId] [nvarchar](10) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[tf_schemeOrder] [int] NOT NULL,
	[tf_schemeName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[tf_isSystemScheme] [bit] NULL,
	[tf_isAllowEditInGrid] [bit] NULL,
	[tf_autoShowFilterEditor] [bit] NULL,
	[tf_dblClickAction] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_defaultSort] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_otherSetting] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
 CONSTRAINT [PK___ModuleGridSchem__33D4B598] PRIMARY KEY CLUSTERED 
(
	[tf_gridSchemeId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [_ModuleGridScheme_ix1] UNIQUE NONCLUSTERED 
(
	[tf_moduleId] ASC,
	[tf_schemeOrder] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


GO
ALTER TABLE [dbo].[_ModuleGridScheme]  WITH CHECK ADD  CONSTRAINT [_ModuleGridScheme_fk1] FOREIGN KEY([tf_moduleId])
REFERENCES [dbo].[_Module] ([tf_moduleId])
ON UPDATE CASCADE
ON DELETE CASCADE

CREATE TABLE [dbo].[_ModuleGridSchemeGroup](
	[tf_gridGroupId] [int] NOT NULL,
	[tf_gridSchemeId] [int] NOT NULL,
	[tf_gridGroupOrder] [int] NOT NULL,
	[tf_gridGroupName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[tf_isShowHeaderSpans] [bit] NULL,
	[tf_isLocked] [bit] NULL,
	[tf_otherSetting] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
 CONSTRAINT [PK___ModuleGridSchem__534D60F1] PRIMARY KEY CLUSTERED 
(
	[tf_gridGroupId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


GO
ALTER TABLE [dbo].[_ModuleGridSchemeGroup]  WITH CHECK ADD  CONSTRAINT [_ModuleGridSchemeGroup_fk1] FOREIGN KEY([tf_gridSchemeId])
REFERENCES [dbo].[_ModuleGridScheme] ([tf_gridSchemeId])
ON UPDATE CASCADE
ON DELETE CASCADE

CREATE TABLE [dbo].[_ModuleGridSchemeGroupField](
	[tf_gridFieldId] [int] NOT NULL,
	[tf_gridGroupId] [int] NOT NULL,
	[tf_gridFieldOrder] [int] NOT NULL,
	[tf_fieldId] [int] NOT NULL,
	[tf_columnWidth] [int] NULL,
	[tf_isLocked] [bit] NULL,
	[tf_isAllowTotal] [bit] NULL,
	[tf_isAllowSort] [bit] NULL,
	[tf_ishidden] [bit] NULL,
	[tf_notExportExcel] [bit] NULL,
	[tf_additionType] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_otherSetting] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
 CONSTRAINT [PK___ModuleGridSchem__72C60C4A] PRIMARY KEY CLUSTERED 
(
	[tf_gridFieldId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [_ModuleGridSchemeGroupField_ix1] UNIQUE NONCLUSTERED 
(
	[tf_gridGroupId] ASC,
	[tf_fieldId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


GO
ALTER TABLE [dbo].[_ModuleGridSchemeGroupField]  WITH CHECK ADD  CONSTRAINT [_ModuleGridSchemeGroupField_fk1] FOREIGN KEY([tf_gridGroupId])
REFERENCES [dbo].[_ModuleGridSchemeGroup] ([tf_gridGroupId])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[_ModuleGridSchemeGroupField]  WITH CHECK ADD  CONSTRAINT [FK__ModuleGridSchemeGroupField__ModuleField] FOREIGN KEY([tf_fieldId])
REFERENCES [dbo].[_ModuleField] ([tf_fieldId])
ON UPDATE CASCADE
ON DELETE CASCADE

       三个表对应的java bean如下:

package com.jfok.server.hibernate.system;

import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.GenericGenerator;
import com.jfok.server.common.annotation.FieldDefine;
import com.jfok.server.common.annotation.TableDefine;

/**
 * 模块的列表方案,一个模块可以有多个列表方案,可以显示不同的字段,有不同的属性
 * 
 * @author jfok
 * 
 */

@SuppressWarnings("serial")
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true)
@TableDefine(group = "系统模块", id = 9904, title = "模块列表方案", shortname = "列表方案")
public class _ModuleGridScheme implements _IModuleControlInterface, Serializable {

	@Id
	@GeneratedValue(generator = "increment")
	@GenericGenerator(name = "increment", strategy = "increment")
	@FieldDefine(title = "ID号", number = 10, hidden = true)
	private Integer tf_gridSchemeId;

	@JsonIgnore
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
	@JoinColumn(name = "tf_moduleId", nullable = false)
	@FieldDefine(title = "模块", number = 20)
	private _Module tf_Module;

	@FieldDefine(title = "顺序号", number = 30)
	@Column(nullable = false)
	private Integer tf_schemeOrder;

	@FieldDefine(title = "方案名称", nameField = true, number = 40)
	@Column(length = 50, nullable = false)
	private String tf_schemeName;

	@FieldDefine(title = "系统方案", number = 50)
	private Boolean tf_isSystemScheme;

	@FieldDefine(title = "可编辑", number = 60)
	private Boolean tf_isAllowEditInGrid;

	@FieldDefine(title = "双击操作", number = 70)
	private String tf_dblClickAction;

	@FieldDefine(title = "排序字段", number = 80)
	private String tf_defaultSort; // 默认排序字段,如为null则为数据库默认排序

	@FieldDefine(title = "附加设置", number = 90)
	private String tf_otherSetting;


	@OneToMany(targetEntity = _ModuleGridSchemeGroup.class, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinColumn(name = "tf_gridSchemeId")
	@OrderBy("tf_gridGroupOrder")	
	private List<_ModuleGridSchemeGroup> moduleGridSchemeGroups;

	public _ModuleGridScheme() {

	}
  //setter and getter
}

package com.jfok.server.hibernate.system;

import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.GenericGenerator;

import com.jfok.server.common.annotation.FieldDefine;
import com.jfok.server.common.annotation.TableDefine;

/**
 * 每一个模块列表方案之中显示字段分组
 * 
 * @author jfok
 * 
 */

@SuppressWarnings("serial")
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true)
@TableDefine(group = "系统模块", id = 9905, title = "模块列表字段分组", shortname = "列表字段分组")
public class _ModuleGridSchemeGroup implements _IModuleControlInterface, Serializable {

	public static final String GRIDGROUPID = "tf_gridGroupId";

	@Id
	@GeneratedValue(generator = "increment")
	@GenericGenerator(name = "increment", strategy = "increment")
	@FieldDefine(title = "ID号", number = 10, hidden = true)
	private Integer tf_gridGroupId;

	@JsonIgnore
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
	@JoinColumn(name = "tf_gridSchemeId", nullable = false)
	@FieldDefine(title = "模块列表方案", number = 20)
	private _ModuleGridScheme tf_ModuleGridScheme;

	@FieldDefine(title = "顺序号", number = 30)
	@Column(nullable = false)
	private Integer tf_gridGroupOrder;

	@FieldDefine(title = "分组名称", nameField = true, number = 40)
	@Column(length = 50, nullable = false)
	private String tf_gridGroupName;

	@FieldDefine(title = "表头分组", number = 50)
	private Boolean tf_isShowHeaderSpans;

	@FieldDefine(title = "锁定", number = 60)
	private Boolean tf_isLocked;

	@FieldDefine(title = "其他设置", number = 90)
	private String tf_otherSetting;

	@OneToMany(targetEntity = _ModuleGridSchemeGroupField.class, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinColumn(name = "tf_gridGroupId")
	@OrderBy("tf_gridFieldOrder")
	private List<_ModuleGridSchemeGroupField> moduleGridSchemeGroupFields;

	public _ModuleGridSchemeGroup() {

	}
//setter and getter
}

package com.jfok.server.hibernate.system;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.hibernate.annotations.GenericGenerator;
import com.jfok.server.common.annotation.FieldDefine;
import com.jfok.server.common.annotation.TableDefine;

/**
 * 每一个模块列表字段分组下面显示的字段
 * 
 * @author jfok
 * 
 */
@JsonSerialize(include=JsonSerialize.Inclusion.NON_EMPTY )
@SuppressWarnings("serial")
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true)
@TableDefine(group = "系统模块", id = 9906, title = "模块列表字段", shortname = "列表字段")
public class _ModuleGridSchemeGroupField implements _IModuleControlInterface, Serializable {

	@Id
	@GeneratedValue(generator = "increment")
	@GenericGenerator(name = "increment", strategy = "increment")
	@FieldDefine(title = "ID号", hidden = true, number = 10)
	private Integer tf_gridFieldId;

	@JsonIgnore
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	@JoinColumn(name = "tf_gridGroupId", nullable = false)
	@FieldDefine(title = "模块列表字段分组", number = 20)
	private _ModuleGridSchemeGroup tf_ModuleGridSchemeGroup;

	@JsonIgnore
	@FieldDefine(title = "顺序号", number = 30)
	@Column(nullable = false)
	private Integer tf_gridFieldOrder;

	@JsonIgnore
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	@JoinColumn(name = "tf_fieldId", nullable = false)
	@FieldDefine(title = "模块字段", nameField = true, number = 40)
	private _ModuleField tf_ModuleField;

	@Column(insertable = false, updatable = false)
	private Integer tf_fieldId;

	@FieldDefine(title = "列宽度", number = 50)
	private Integer tf_columnWidth;

	@FieldDefine(title = "锁定列", number = 60)
	private Boolean tf_isLocked;

	@FieldDefine(title = "附加类型", number = 70)
	private String tf_additionType;

	@FieldDefine(title = "附加设置", number = 80)
	private String tf_otherSetting;

	@FieldDefine(title = "隐藏列", number = 90)
	private Boolean tf_ishidden;

	@JsonIgnore
	@FieldDefine(title = "Excel不导出", number = 100)
	private Boolean tf_notExportExcel;

	public _ModuleGridSchemeGroupField() {

	}
//getter and setter
}

       





郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。