购物网站4:权限设计---部门---员工---身份证---权限组---权限--权限主键

/**
 * 身份证
 */
@Entity
public class IDCard {
 private Integer id;//实体标识,自增长
 /* 18 ,不能为null */
 private String cardno;
 /* 50 不能为null */
 private String address;
 /* 出生日期 */
 private Date birthday;//采用只含有日期部分的类型表示
 /* 所属的员工 */
 private Employee employee;
 
 public IDCard(){}
 
 public IDCard(String cardno, String address, Date birthday) {
  this.cardno = cardno;
  this.address = address;
  this.birthday = birthday;
 }
 @Id @GeneratedValue
 public Integer getId() {
  return id;
 }
 public void setId(Integer id) {
  this.id = id;
 }
 @Column(length=18,nullable=false)
 public String getCardno() {
  return cardno;
 }
 public void setCardno(String cardno) {
  this.cardno = cardno;
 }
 @Column(length=50,nullable=false)
 public String getAddress() {
  return address;
 }
 public void setAddress(String address) {
  this.address = address;
 }
 @Temporal(TemporalType.DATE) @Column(nullable=false)
 public Date getBirthday() {
  return birthday;
 }
 public void setBirthday(Date birthday) {
  this.birthday = birthday;
 }
 @OneToOne(cascade=CascadeType.REFRESH,mappedBy="idCard")
 public Employee getEmployee() {
  return employee;
 }
 public void setEmployee(Employee employee) {
  this.employee = employee;
 }
 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result + ((id == null) ? 0 : id.hashCode());
  return result;
 }
 @Override
 public boolean equals(Object obj) {
  if (this == obj)
   return true;
  if (obj == null)
   return false;
  if (getClass() != obj.getClass())
   return false;
  final IDCard other = (IDCard) obj;
  if (id == null) {
   if (other.id != null)
    return false;
  } else if (!id.equals(other.id))
   return false;
  return true;
 }
 
}

 

 

------------------------------------------------------------------------

 

/**
 * 员工
 */
@Entity
public class Employee {
 /* 主键,20位*/
 private String username;
 /* 20位, 不能为null */
 private String password;
 /* 姓名 10位 不能为null */
 private String realname;
 /* 性别 5位 不能为null */
 private Gender gender;
 /* 学历 10位 */
 private String degree;
 /* 身份证 必须提供 */
 private IDCard idCard ;//一对一,员工作为关系维护端
 /* 毕业院校 20位 */
 private String school;
 /* 联系电话 20 */
 private String phone;
 /* 电子邮件 40 */
 private String email;
 /* 照片 41 */
 private String imageName; //只存放文件名称,而且文件名称采用uuid生成,图片保存在/images/employee/[username]/目录
 /* 员工在职状态 true为在职,false为离职 */
 private Boolean visible = true;
 /* 员工所在部门 */
 private Department department;//双向一对多,多对一
 
 private Set<PrivilegeGroup> groups = new HashSet<PrivilegeGroup>();
 
 @ManyToMany(cascade=CascadeType.REFRESH, fetch=FetchType.EAGER)
 @JoinTable(name="eg", joinColumns=@JoinColumn(name="username"),
   inverseJoinColumns=@JoinColumn(name="group_id"))
 public Set<PrivilegeGroup> getGroups() {
  return groups;
 }

 public void setGroups(Set<PrivilegeGroup> groups) {
  this.groups = groups;
 }
 /**
  * 添加权限组
  * @param group 权限组
  */
 public void addPrivilegeGroup(PrivilegeGroup group){
  this.groups.add(group);
 }
 
 public Employee() {}
 
 public Employee(String username) {
  this.username = username;
 }

 @Transient
 public String getImagePath(){
  if(this.username!=null && this.imageName!=null) return "/images/employee/"+ this.username+ "/"+ this.imageName;
  return null;
 }
 
 @Id @Column(length=20)
 public String getUsername() {
  return username;
 }
 public void setUsername(String username) {
  this.username = username;
 }
 @Column(length=20,nullable=false)
 public String getPassword() {
  return password;
 }
 public void setPassword(String password) {
  this.password = password;
 }
 @Column(length=10,nullable=false)
 public String getRealname() {
  return realname;
 }
 public void setRealname(String realname) {
  this.realname = realname;
 }
 @Enumerated(EnumType.STRING) @Column(length=5,nullable=false)
 public Gender getGender() {
  return gender;
 }
 public void setGender(Gender gender) {
  this.gender = gender;
 }
 @Column(length=10)
 public String getDegree() {
  return degree;
 }
 public void setDegree(String degree) {
  this.degree = degree;
 }
 @OneToOne(cascade=CascadeType.ALL,optional=false)
 @JoinColumn(name="card_id")
 public IDCard getIdCard() {
  return idCard;
 }
 public void setIdCard(IDCard idCard) {
  this.idCard = idCard;
 }
 @Column(length=20,nullable=false)
 public String getSchool() {
  return school;
 }
 public void setSchool(String school) {
  this.school = school;
 }
 @Column(length=20)
 public String getPhone() {
  return phone;
 }
 public void setPhone(String phone) {
  this.phone = phone;
 }
 @Column(length=40)
 public String getEmail() {
  return email;
 }
 public void setEmail(String email) {
  this.email = email;
 }
 @Column(length=41)
 public String getImageName() {
  return imageName;
 }
 public void setImageName(String imageName) {
  this.imageName = imageName;
 }
 @Column(nullable=false)
 public Boolean getVisible() {
  return visible;
 }
 public void setVisible(Boolean visible) {
  this.visible = visible;
 }
 @ManyToOne(cascade=CascadeType.REFRESH)
 @JoinColumn(name="department_id")
 public Department getDepartment() {
  return department;
 }
 public void setDepartment(Department department) {
  this.department = department;
 }

 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result
    + ((username == null) ? 0 : username.hashCode());
  return result;
 }

 @Override
 public boolean equals(Object obj) {
  if (this == obj)
   return true;
  if (obj == null)
   return false;
  if (getClass() != obj.getClass())
   return false;
  final Employee other = (Employee) obj;
  if (username == null) {
   if (other.username != null)
    return false;
  } else if (!username.equals(other.username))
   return false;
  return true;
 }
 
}

 

 

----------------------------------------------------------

 

 

/**
 * 部门
 */
@Entity
public class Department {
 private String departmentid;
 private String name;
 private Set<Employee> employees = new HashSet<Employee>();
 
 public Department(){}
 
 public Department(String departmentid) {
  this.departmentid = departmentid;
 }
 @OneToMany(cascade=CascadeType.REFRESH, mappedBy="department")
 public Set<Employee> getEmployees() {
  return employees;
 }
 public void setEmployees(Set<Employee> employees) {
  this.employees = employees;
 }
 
 @Id @Column(length=36)
 public String getDepartmentid() {
  return departmentid;
 }
 public void setDepartmentid(String departmentid) {
  this.departmentid = departmentid;
 }
 @Column(length=20,nullable=false)
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result
    + ((departmentid == null) ? 0 : departmentid.hashCode());
  return result;
 }
 @Override
 public boolean equals(Object obj) {
  if (this == obj)
   return true;
  if (obj == null)
   return false;
  if (getClass() != obj.getClass())
   return false;
  final Department other = (Department) obj;
  if (departmentid == null) {
   if (other.departmentid != null)
    return false;
  } else if (!departmentid.equals(other.departmentid))
   return false;
  return true;
 }
 
}

 

 

-----------------------------------------------------------

 

/**
 * 权限组
 */
@Entity
public class PrivilegeGroup {
 private String groupid;
 /* 权限组名称 */
 private String name;
 /* 组下的权限 */
 private Set<SystemPrivilege> privileges = new HashSet<SystemPrivilege>();
 
 private Set<Employee> employees = new HashSet<Employee>();
 
 public PrivilegeGroup(){}
 
 public PrivilegeGroup(String groupid) {
  this.groupid = groupid;
 }
 @ManyToMany(mappedBy="groups",cascade=CascadeType.REFRESH)
 public Set<Employee> getEmployees() {
  return employees;
 }
 public void setEmployees(Set<Employee> employees) {
  this.employees = employees;
 }
 @Id @Column(length=36)
 public String getGroupid() {
  return groupid;
 }
 public void setGroupid(String groupid) {
  this.groupid = groupid;
 }
 @Column(length=20,nullable=false)
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 @ManyToMany(cascade=CascadeType.REFRESH, fetch=FetchType.EAGER)
 @JoinTable(name="group_privilege",
   joinColumns=@JoinColumn(name="group_id"),
   inverseJoinColumns={@JoinColumn(name="module", referencedColumnName="module"),
        @JoinColumn(name="privilege",  referencedColumnName="privilege")}
 )
 public Set<SystemPrivilege> getPrivileges() {
  return privileges;
 }
 public void setPrivileges(Set<SystemPrivilege> privileges) {
  this.privileges = privileges;
 }
 /**
  * 添加权限
  * @param privilege
  */
 public void addSystemPrivilege(SystemPrivilege privilege){
  this.privileges.add(privilege);
 }
 
 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result + ((groupid == null) ? 0 : groupid.hashCode());
  return result;
 }
 @Override
 public boolean equals(Object obj) {
  if (this == obj)
   return true;
  if (obj == null)
   return false;
  if (getClass() != obj.getClass())
   return false;
  final PrivilegeGroup other = (PrivilegeGroup) obj;
  if (groupid == null) {
   if (other.groupid != null)
    return false;
  } else if (!groupid.equals(other.groupid))
   return false;
  return true;
 }
 
}

 

 

 

-------------------------------------------------------------------

 

 

/**
 * 系统权限
 */
@Entity
public class SystemPrivilege {
 private SystemPrivilegePK id;
 /* 权限名称 */
 private String name;
 /* 所在的组 */
 private Set<PrivilegeGroup> groups = new HashSet<PrivilegeGroup>();
 
 @ManyToMany(mappedBy="privileges", cascade=CascadeType.REFRESH)
 public Set<PrivilegeGroup> getGroups() {
  return groups;
 }

 public void setGroups(Set<PrivilegeGroup> groups) {
  this.groups = groups;
 }

 public SystemPrivilege(){}
 
 public SystemPrivilege(SystemPrivilegePK id) {
  this.id = id;
 }
 public SystemPrivilege(SystemPrivilegePK id, String name) {
  this.id = id;
  this.name = name;
 }
 public SystemPrivilege(String module, String privilege, String name) {
  this.id = new SystemPrivilegePK(module, privilege);
  this.name = name;
 }
 
 @EmbeddedId
 public SystemPrivilegePK getId() {
  return id;
 }
 public void setId(SystemPrivilegePK id) {
  this.id = id;
 }
 @Column(length=20,nullable=false)
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result + ((id == null) ? 0 : id.hashCode());
  return result;
 }
 @Override
 public boolean equals(Object obj) {
  if (this == obj)
   return true;
  if (obj == null)
   return false;
  if (getClass() != obj.getClass())
   return false;
  final SystemPrivilege other = (SystemPrivilege) obj;
  if (id == null) {
   if (other.id != null)
    return false;
  } else if (!id.equals(other.id))
   return false;
  return true;
 }
 
}

 

 

 

--------------------------------------------------------------

 

@Embeddable
public class SystemPrivilegePK implements Serializable{
 /* 模块 */
 private String module;
 /* 权限值 */
 private String privilege;
 
 public SystemPrivilegePK(){}
 
 public SystemPrivilegePK(String module, String privilege) {
  this.module = module;
  this.privilege = privilege;
 }
 
 @Column(length=20, name="module")
 public String getModule() {
  return module;
 }
 public void setModule(String module) {
  this.module = module;
 }
 @Column(length=20, name="privilege")
 public String getPrivilege() {
  return privilege;
 }
 public void setPrivilege(String privilege) {
  this.privilege = privilege;
 }
 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result + ((module == null) ? 0 : module.hashCode());
  result = prime * result
    + ((privilege == null) ? 0 : privilege.hashCode());
  return result;
 }
 @Override
 public boolean equals(Object obj) {
  if (this == obj)
   return true;
  if (obj == null)
   return false;
  if (getClass() != obj.getClass())
   return false;
  final SystemPrivilegePK other = (SystemPrivilegePK) obj;
  if (module == null) {
   if (other.module != null)
    return false;
  } else if (!module.equals(other.module))
   return false;
  if (privilege == null) {
   if (other.privilege != null)
    return false;
  } else if (!privilege.equals(other.privilege))
   return false;
  return true;
 }
 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值