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
}
加入模块后的界面如下:
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() {
}
//
}
行业的模块数据如下:
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的标记配置。界面截图如下: