需要帮助设计员工和经理关系

发布于 2024-09-13 14:22:47 字数 788 浏览 4 评论 0原文

我目前正在开发一个包含员工、经理实体的项目。一开始,我理所当然地认为经理必须是公司的员工,所以他们是同一个人,在工资系统中具有相同的EmployeeID。基于这个假设,我让 Manager 类扩展 Employee 类。

后来我的客户告诉我,有时候有些经理并不是公司的员工,但他们仍然有员工向他们汇报,这些经理也应该在系统里。员工和经理之间的继承关系被破坏,现在我有两个独立的类,数据库中有两个表(TAB_EMPLOYEE 和 TAB_MANAGER)。

经理和员工都可以通过用户名和密码访问系统。有一个名为 User 的类,系统应提供为经理和员工创建用户帐户的功能。在前面的情况下,经理扩展了员工,我可以为经理创建一个用户帐户,并为该用户分配两个角色(ROLE_EMPLOYEE、ROLE_MANAGER)。但是现在,如果已经为某个员工创建了一个用户帐户(该员工也是一个经理,所以除了TAB_EMPLOYEE中的一条记录外,TAB_MANAGER中还有一条记录),我该如何为他创建一个作为经理的用户帐户呢?我知道我可以为现有用户分配一个 ROLE_MANAGER (这样该用户就有两个角色:ROLE_EMPLOYEE、ROLE_MANAGER),但是在用户登录后,我必须使用用户名或用户 ID 来加载引用的对象(Employee 和/或经理)。为了做到这一点,我必须选择:

选项 1:在 TAB_EMPLOYEE 和 TAB_MANAGER 表中添加 userid 列。 方案二:在TAB_USER中添加ObjectType、ObjectId两列,ObjectType包含EMPLOYEE或MANAGER,ObjectId包含相关id。

我不确定哪个选项更好,或者还有其他选项可以做到这一点吗?

I am currently working on a project which has Employee, Manager entities. At the very beginning, I took for granted that a manager must be an employee in the company, so they are the same person who have the same EmployeeID in payroll system. Based on this assumption, I let the Manager class extends Employee class.

Later, my client told me that sometimes some managers are not an employee in the company, but they still have employees report to them and these managers should also be in the system. The inheritance relationship between employee and manager is broken and now I have two independent classes with two tables (TAB_EMPLOYEE & TAB_MANAGER) in the database.

Both manager and employee can access to the system with an username and password. There is a class named User and the system should provide functions to create user account for managers and employees. In the previous situation, manager extends employee, I can create an user account for a manager and assign two roles (ROLE_EMPLOYEE, ROLE_MANAGER) to the user. But now, if an user account has already been created for an employee (this employee is also a manager, so besides a record in TAB_EMPLOYEE, there is a record in TAB_MANAGER), how can I create an user account for him as a manager? I know I can just assigned a ROLE_MANAGER to the existing user (so that the user has two roles: ROLE_EMPLOYEE, ROLE_MANAGER), but after the user logged in, I have to use the username or userid to load the referenced objects (Employee and/or Manager). In order to do this, I have to options:

Option 1: Add a userid column in both TAB_EMPLOYEE and TAB_MANAGER tables.
Option 2: Add two columns ObjectType, ObjectId in TAB_USER, ObjectType contains EMPLOYEE or MANAGER, and ObjectId contains the related id.

I am not sure which option is better or is there any other options to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狼性发作 2024-09-20 14:22:47

我会把桌子合并起来,这样就只剩下一张员工桌了。然后我会添加一个一元关系(指向自身的指针)来识别经理。最后我会添加一个标志来识别内部员工(员工)。

I would combine the tables so there is simply a staff table. Then I would add a unary relationship (pointer back to itself) to identify the manager. Lastly I would add a flag to identify internal staff (employees).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文