模块管理常规功能自定义系统的设计与实现(25--多个模块之间的关联[1])

时间:2021-10-28 22:19:55

多个模块之间的关联(1)



视频讲解在线观看:视频讲解链接  http://i.youku.com/jfok1972


        现在开始加入第三个模块“客户单位”,顺便先把“客户等级”和“行业”也加进去。加入进去了以后将会完成下图的五个模块的操作。在加入的模块中,“所属行业”的编码是分级的,就象财务里面的科目一样,分为一级,二级,三级等。二级代码必须要有一级的父代码才可以保存。分级代码在导航的时候是做成树状的,下面会具体展示一下。
模块管理常规功能自定义系统的设计与实现(25--多个模块之间的关联[1])

一、客户等级的加入
CREATE TABLE [dbo].[Rate](
	[tf_rateId] [nvarchar](2) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[tf_name] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
 CONSTRAINT [PK_Rate] PRIMARY KEY CLUSTERED 
(
	[tf_rateId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

package com.jfok.server.hibernate.sales;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import com.jfok.server.common.annotation.FieldDefine;
import com.jfok.server.common.annotation.TableDefine;

@Entity
@SuppressWarnings("serial")
@TableDefine(group = "编码设置", id = 7014, title = "客户等级")
public class Rate implements Serializable {

	@Id
	@FieldDefine(title = "编码", number = 10, fieldGroup = "基本信息")
	@Column(nullable = false, length = 2)
	private String tf_rateId;

	@FieldDefine(title = "等级名称", number = 20, nameField = true, fieldGroup = "基本信息")
	@Column(nullable = false, length = 50, unique = true)
	private String tf_name;

	public Rate() {

	}
//getter and setter
}

加入模块后的界面如下:

模块管理常规功能自定义系统的设计与实现(25--多个模块之间的关联[1])

        二、行业的加入。
CREATE TABLE [dbo].[Trade](
	[tf_tradeId] [nvarchar](6) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[tf_name] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
 CONSTRAINT [PK_Trade] PRIMARY KEY CLUSTERED 
(
	[tf_tradeId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

@Entity
@SuppressWarnings("serial")
@TableDefine(group = "编码设置", id = 7016, title = "行业")
public class Trade implements Serializable {

	@Id
	//此处行业编码是分级的,类似于财务里面的科目,每级长为2,共分为3级。
	@FieldDefine(title = "行业编码", number = 10, fieldGroup = "基本信息")
	@Column(nullable = false, length = 6)
	private String tf_tradeId;

	@FieldDefine(title = "行业名称", number = 20, nameField = true, fieldGroup = "基本信息")
	@Column(nullable = false, length = 50, unique = true)
	private String tf_name;

	public Trade() {

	}
//
}

行业的模块数据如下:

模块管理常规功能自定义系统的设计与实现(25--多个模块之间的关联[1])

三、加入客户单位模块。客户单位模块共有三个父模块,可以分别对客户进行导航。客户单位的主键不同于上面的,是自增量型的。
CREATE TABLE [dbo].[Customer](
	[tf_customerId] [int] NOT NULL,
	[tf_cityId] [nvarchar](4) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[tf_rateId] [nvarchar](2) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[tf_tradeId] [nvarchar](6) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[tf_name] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[tf_address] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_linkman] [nvarchar](10) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_linkmanTel] [nvarchar](20) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_taxId] [nvarchar](20) COLLATE Chinese_PRC_CI_AS NULL,
	[tf_remark] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
 CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED 
(
	[tf_customerId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[Customer]  WITH CHECK ADD  CONSTRAINT [FK_Customer_City] FOREIGN KEY([tf_cityId])
REFERENCES [dbo].[City] ([tf_cityId])
ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[Customer]  WITH CHECK ADD  CONSTRAINT [FK_Customer_Rate] FOREIGN KEY([tf_rateId])
REFERENCES [dbo].[Rate] ([tf_rateId])
ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[Customer]  WITH CHECK ADD  CONSTRAINT [FK_Customer_Trade] FOREIGN KEY([tf_tradeId])
REFERENCES [dbo].[Trade] ([tf_tradeId])
ON UPDATE CASCADE

@Entity
@SuppressWarnings("serial")
@JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY)
@org.hibernate.annotations.Entity(dynamicUpdate = true)
@TableDefine(group = "销售系统", id = 6010, title = "客户单位")
public class Customer implements Serializable {

	@Id
	// 使用的hibernate 的自动增量,没有用数据库的自动增量型
	@GeneratedValue(generator = "increment")
	@GenericGenerator(name = "increment", strategy = "increment")
	// 这是客户单位的序号主键,隐藏不要显示
	@FieldDefine(title = "序号", number = 10, fieldGroup = "基本信息", hidden = true)
	@Column(nullable = false)
	private Integer tf_customerId;

	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	@JoinColumn(name = "tf_cityId", nullable = false)
	@FieldDefine(title = "市", number = 20, fieldGroup = "基本信息")
	private City tf_City;

	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	@JoinColumn(name = "tf_tradeId", nullable = false)
	@FieldDefine(title = "行业", number = 30, fieldGroup = "基本信息")
	private Trade tf_Trade;

	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	@JoinColumn(name = "tf_rateId", nullable = false)
	@FieldDefine(title = "等级", number = 40, fieldGroup = "基本信息")
	private Rate tf_Rate;

	@FieldDefine(title = "客户名称", number = 50, nameField = true, fieldGroup = "基本信息", remark = "请输入该单位公章上的全称")
	@Column(nullable = false, length = 50)
	private String tf_name;

	@FieldDefine(title = "单位地址", number = 60, fieldGroup = "附加信息")
	@Column(length = 50)
	private String tf_address;

	@FieldDefine(title = "联系人", number = 70, fieldGroup = "附加信息")
	@Column(length = 10)
	private String tf_linkman;

	@FieldDefine(title = "联系电话", number = 80, fieldGroup = "附加信息")
	@Column(length = 20)
	private String tf_linkmanTel;

	@FieldDefine(title = "税号", number = 90, fieldGroup = "附加信息")
	@Column(length = 20)
	private String tf_taxId;

	@FieldDefine(title = "备注", number = 190, fieldGroup = "附加信息")
	@Column(length = 20)
	private String tf_remark;

	public Customer() {

	}

上面的java代码中可以看到三个父模块的manyToOne的标记配置。界面截图如下:

模块管理常规功能自定义系统的设计与实现(25--多个模块之间的关联[1])

我新增一些客户,下节继续