在 Jhipster 设计中计算属性的最佳实践

Best practice to calculate an atribute in Jhipster design

假设您创建了一个 Jhipster 赛车应用程序,其中我们有一个 Race class (id, raceName, date, List -Participant-, averageTime),它由 Participant 对象(具有 id 和每场比赛的比赛时间(以秒为单位)。您想计算比赛的平均时间 class 随着时间的发布(当他们越过终点线时)以及每次咨询比赛时。为此,您会将计算此类平均值的方法放在哪里?

我看到 3 个选项:

  1. 在您的 angular class 视图中,当您显示 Race 组件时,您可以在每次显示时携带数据并计算它。
  2. 比赛服务实施中的某处。
  3. 在实例化 Race 对象时使用 @Transient 的领域模型

如果您看到其他选项或最佳做法,请告诉我。谢谢

entity Race { raceName String, time Instant, averageTime Double }

entity Participant { racingTime Integer }

relationship OneToMany { Race{participant(id)} to Participant{race(id)} }

// SET PAGINATION OPTIONS: paginate all with pagination // paginate ChatMessage with infinite-scroll // paginate all with infinite-scroll

// SET SERVICE OPTIONS: service all with serviceImpl //service all with serviceClass

// DTO: dto all with mapstruct

// FILTERING: filter *

我的偏好是在服务层执行此操作,作为从域模型到 DTO 转换的一部分。您可以在计算平均值的 Race 域模型中实现 @Transient getter,并且(我认为)mapstruct 可以将其映射到 DTO。或者您可以在服务方法中设置额外的 DTO 字段。 还有 您可以在映射器中进行计算。