我一直在试图找出建模这个实体的最佳方法,并且我陷入困境。这里是基本的用例/故事:随着时间的推移,我如何模拟一个对象来跟踪设备/资产?
我们有设备到达现场。直到它到达,我们才会知道这些设备是什么。一旦设备到达现场,它必须被记录为已到达以及是否闲置或活动。如果激活,用户必须记下设备执行的工作。当设备离开现场时,必须注意这一点。
我应该能够方便地查询是否有该网站上的任何设备,是什么样的设备先前在现场等
我被陷在日期方面。我试图避免依靠cron作业来运行,并将设备标记为空闲,如果它没有在特定日期标记为闲置的话。感觉应该有办法做到这一点。下面是我想出:
public class Equipment {
public int Id { get; set; }
public Site Site { get; set; }
public DateTime Arrival { get; set; }
public DateTime Departure { get; set; }
public IList<EquipmentUtilization> EquipmentUtilizations { get; set; }
}
public class EquipmentUtilization {
public int Id { get; set; }
public Equipment Equipment { get; set; }
public DateTime ReportDate { get; set; }
public string WorkPerformed { get; set; }
}
的想法是,我可以运行一个查询像Site.Equipment.Where(x=>x.Departure == null)
,看看哪些设备仍然在现场。如果某个特定日期没有EquipmentUtilization,则假定它是空闲的。然后我可以设置一个DateTimeEnumerator:
public class DateTimeEnumerator : System.Collections.IEnumerable
{
private DateTime begin;
private DateTime end;
public DateTimeEnumerator (DateTime begin , DateTime end)
{
this.begin = begin;
this.end = end;
}
public System.Collections.IEnumerator GetEnumerator()
{
for(DateTime date = begin; date < end; date = date.AddDays(1))
{
yield return date;
}
}
}
构建从到达日起至DateTime.Now或DepatureDate日期的列表,如果这是不为空。由于某种原因,这看起来很难看。我应该把DateTime枚举器放在Equipment对象的内部吗?感觉这应该全部在一起或以不同的方式完成,尽管如果我运行它,这确实起作用。建议?