员工限制

发布于 2024-08-03 08:49:04 字数 353 浏览 3 评论 0原文

我正在编写一个 C# 程序来处理调度。现在,每个员工都需要有能力对自己的日程安排进行限制,例如:

Sally 只能在周一、周三、周五上午 9 点至下午 3 点工作

Billy 只能在周二、周四、周日下午 5 点至 9 点

工作 Sally 只能在周一、周三、周五工作上午 9 点至下午 3 点 直到某某日期,然后她可以在不同的时间和日期工作。

这些是我需要应用于每个员工对象的一些限制示例。我想要的是一些关于如何尽可能高效和通用地构建它的建议。显然,我必须能够访问这些数据并能够应用这些限制。例如,当经理试图制定时间表时,他需要能够看到,当他安排莎莉周二下午 4 点时,他们是一个问题。另外我应该如何存储每个员工的这些数据?

I am writing a C# program to handle scheduling. Now each employee needs the ability have limitations on their schedule for ex:

Sally can only work Monday, Wednesday, Friday from 9am-3pm

Billy can only work Tuesday, Thursday, Sunday from 5pm-9pm

Sally can only work Monday, Wednesday, Friday from 9am-3pm
until so and so date and then she can work a different set of times and days.

These are some examples of limitations that I need to apply to each employee object. What I wanted were some suggestions on how to architect this as efficiently and generically as as possible. Obviously I am going to have to be able to access this data and be able to apply these limitations. For example when the manger is trying to make the schedule he needs to able to see that when he schedules Sally on Tuesday at 4 their is an issue. Also how should I store this data of each employee?

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

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

发布评论

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

评论(6

花间憩 2024-08-10 08:49:04

像这样的事情:

public class Employee
{
    public string Name { get; set; }
    // other important info

    private List<WorkTime> _availability = new List<WorkTime>();
    public List<WorkTime> Availability
    {
        get { return _availability; }
        internal set { _availability = value; }
    }
}

public class WorkTime
{
    public DayOfWeek Day { get; private set; }
    public int StartHour { get; private set; }
    public int EndHour { get; private set; }

    public WorkTime(DayOfWeek day, int startHour, int endHour)
    {
        // validation here (e.g. day and time range during store hours, start<end, etc.)

        Day = day;
        StartHour = startHour;
        EndHour = endHour;
    }
}

并使用 LINQ(或 foreach)查询整个员工集合,并查询每个员工的可用性,以找到有时间完成轮班的人员。

创建一些实用函数(扩展)来根据您的业务规则比较 WorkTime 对象也可能很有用(例如,IsAvailable 比较两个 WorkTime 对象,如果它是相同的 DoW 并且至少有 4 小时重叠,则返回 true),

并且您可能会存储这是在数据库中,因此使用类中的属性等字段对表进行建模。

something like this:

public class Employee
{
    public string Name { get; set; }
    // other important info

    private List<WorkTime> _availability = new List<WorkTime>();
    public List<WorkTime> Availability
    {
        get { return _availability; }
        internal set { _availability = value; }
    }
}

public class WorkTime
{
    public DayOfWeek Day { get; private set; }
    public int StartHour { get; private set; }
    public int EndHour { get; private set; }

    public WorkTime(DayOfWeek day, int startHour, int endHour)
    {
        // validation here (e.g. day and time range during store hours, start<end, etc.)

        Day = day;
        StartHour = startHour;
        EndHour = endHour;
    }
}

and use LINQ (or foreach) to query across an employee collection, and into each employee's Availability to find someone with hours to meet some shift.

Might also be useful to create some utility function (extensions) for comparing WorkTime objects based on your business rules (e.g. IsAvailable compares two WorkTime objects and returns true if it's the same DoW and at least 4 hours overlap)

and you'll likely be storing this in a database, so model the tables with fields like the properties in the classes.

月棠 2024-08-10 08:49:04

我会使用策略模式来遵循规则

public interface Rule
{
    bool Satisfies(Employee employee);
}

public class ScheduleRule : Rule
{
    ScheduleRule(Schedule schedule)
    { ... }

    bool Satisfies(Employee employee)
    {
        // Ensure the employee is available
    }
}

public class HolidayRule : Rule
{
    HolidayRule(Datetime date)
    { ... }

    bool Satisfies(Employee employee)
    {
        // Checks if the employee as volunteered for this holiday
    }
}

这种模式允许轻松的扩展性和可维护性。

可用性信息(以及其他与规则相关的信息)可以由员工保存(请参阅 Mike Jacob 的回答)。但是,它可以与员工一起存储或存储在单独的表中。

如果您需要大量与规则相关的信息,您还可以将此可用性信息与员工分开。在这种情况下,Rules 可以针对另一个类:

...
bool Satisfies(RuleInfo info)
...

I would go with Rules using the strategy pattern.

public interface Rule
{
    bool Satisfies(Employee employee);
}

public class ScheduleRule : Rule
{
    ScheduleRule(Schedule schedule)
    { ... }

    bool Satisfies(Employee employee)
    {
        // Ensure the employee is available
    }
}

public class HolidayRule : Rule
{
    HolidayRule(Datetime date)
    { ... }

    bool Satisfies(Employee employee)
    {
        // Checks if the employee as volunteered for this holiday
    }
}

This pattern allows for easy extensibility and maintainability.

The availibility information (and other rule-related information) can be kept with the employee (see Mike Jacob's answer). It can however be stored with the employee or in a seperate table.

You can also keep this availability information apart from the employee if you expect a large amount of information related to rules. In this case, Rules could target another class:

...
bool Satisfies(RuleInfo info)
...
分開簡單 2024-08-10 08:49:04

我建议提供将“休息时间”存储为具有时间范围的特定日期或模式的功能。我曾开发过几个调度系统,这些系统具有非常复杂的方式来处理工会规则和员工可用性,这就是我们的处理方式。

任一员工说我想要 X 天从 y 到 z 休息,这很容易检查,或者他们可以定义他们想要或不想要的模式(例如,我不想周五工作),然后在安排时您可以检查以查看如果将它们应用于特定轮班违反了设定规则(休息日)或是否/不匹配特定模式。

另外我应该如何存储每个员工的这些数据?

有一个表来存储员工的特定例外情况。我想要 X 天从 y 到 z 休息。您为一名员工指定了日期和时间跨度。很简单。

至于模式,您需要提出某种类型的模式。并且有类型什么的。

因此,您可以有一个类似“每周休息模式”的类型,它可以存储一周的全天休息日,可以将其存储为表示休息日的简单字符串:1000001。假设第一位是星期日,这表示想要周末休息。然后,您可以将模式存储为字符串或其他内容,然后根据定义的类型,您将知道如何处理该字符串。

这可能是一个非常复杂或简单的问题,这仅取决于您需要允许多少定制。希望这能为您提供足够的想法来帮助您入门。

自动计划生成要复杂得多,具体取决于您需要支持的例外/规则。

I would suggest giving the ability to store 'time off' as specific dates with time ranges or as a pattern. I have worked on a couple of scheduling systems that had very complex ways of dealing with union rules and employee availablity and this is how we handled it.

Either employee says I want day X from y to z off which is easy to check against or they could define patterns that they wanted or didn't want (eg. I dont want to work fridays) and then when scheduling you could check to see if applying them to a specific shift broke a set rule (day off) or did/didn't match a specific pattern.

Also how should I store this data of each employee?

Have a table for storing employee's specific exceptions. I want day X from y to z off. You have an employee a date and a time span. Pretty simple.

As for the patterns you will need to come up with some type of schema. And have types or something.

So you could have a type like 'weekly off pattern' that would store full days off for a week which could be stored as a simple string representing the days off: 1000001. Assuming the first bit is sunday, this would represent wanting weekends off. You could then store the pattern as string or something and then based on the defined type you would know how to deal with the string.

It can be a very complex or simple problem, it just depends how much customization you need to allow for. Hopefully this gives you enough ideas to get you started.

Automatic schedule generation is A LOT more complicated depending on the exceptions/rules you need to support.

扮仙女 2024-08-10 08:49:04

“尽可能高效和通用地构建它”

这些本身并不相互排斥,但是高效和通用真的很难成功,尤其是在调度系统上。调度是一个不平凡的问题。

你的问题可能最好表述为“我应该读什么书才能开始这方面的工作?”和/或将其设为社区维基。

"architect this as efficiently and generically as as possible"

These aren't mutually exclusive, per-se, however efficient and generic is really hard to pull off, especially on a scheduling system. Scheduling is a non-trivial problem.

Your question would probably better be stated as "What books should I read to get started on this?" and/or make this a community wiki.

·深蓝 2024-08-10 08:49:04

这类似于图形匹配问题,也可以建模为约束满足问题。您可能会发现 Nsolver 有帮助,或者 Cassowary.Net

This is analogous to a graph-matching problem, and can also be modeled as a Constraint Satisfaction Problem. You may find NSolver helpful, or Cassowary.Net

∞觅青森が 2024-08-10 08:49:04

我做过类似的事情,我所做的是创建一个通用接口,然后为不同的场景创建单独的实现。该接口可能有一个检查 IsInSchedule(dateTime)。然后您可以根据需要创建不同的实现。

I've done something similar to this and what i've done is created a common interface and then created separate implementations for different scenarios. The interface might have a check IsInSchedule(dateTime). Then you can create different implementations as needed.

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