Created
August 13, 2020 21:59
-
-
Save arnaldog/658c5b48e309c1e1ed9e34bf1e7fc3c3 to your computer and use it in GitHub Desktop.
modelo tentativo de vigencias
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
id: 4, | |
name: "Entre pascua y año nuevo con tolerancia" | |
type: "or" // compuesta | |
childs: [ | |
{ | |
id: 1, | |
name: "Tolerancia antes de navidad" | |
fromDate: "navidad" | |
timeUnit: -1 dias | |
class: "ValidityTimeAmounmt" // LeafValidity | |
}, | |
{ | |
id: 2, | |
name: "Tolerancia entre navidad y año nuevo" | |
fromDate: "navidad" | |
untilDate: "año nuevo" | |
class: "RangeValidity" // LeafValidity | |
}, | |
{ | |
id: 3, | |
name: "Tolerancia después de año nuevo" | |
fromDate: "año nuevo" | |
timeUnit: +1 dias | |
class: "ValidityTimeAmount" // LeafValidity | |
} | |
] | |
} | |
interface Validity { | |
fun isValid(dateTime, cb : (Validity) -> Unit )) : Boolean | |
} | |
class OrValidity : Validity { | |
@OneToMany | |
val validities: Validity? = listOf() | |
fun isValid(dateTime) { | |
return validities.reduce(true) { acc, it -> | |
if (it.isSatiesfiedBy(dateTime) or acc) | |
{ | |
cb(this) | |
retrun true | |
} | |
} | |
} | |
} | |
class RangeValidity { | |
fun isValid(dateTime, cb: (Validity) -> Unit ) : Boolean { | |
if (dateTime.between(fromDate, toDate)) { | |
cb(this) | |
return true | |
} | |
} | |
} | |
// type: "or" // compuesta | |
DataOrValidity ( @OneToMany validities: List<Validities> ) { | |
} | |
// type: "and" // compuesta | |
DataAndValidity () | |
Tabla Validity | |
- id | |
- tipo | |
- fromTime | |
- untilTime | |
- timeUnit | |
- timeAmoutn | |
- recurrence | |
Recurrencia "Todos los lunes" | |
Validity : "Entre las 9 y las 10 con tolerancia de 1 hora y despues" | |
Vigencia Final : Recurrencia y validity | |
val recurrencia = Recurrencia.newBuilder( | |
.days([Monday]); | |
val lunes = DateTime.day(Lunes) | |
val proximoLunes = DateTime.day(proximoLunes) | |
recurrencia.isValid(lunes) -> true | |
id | tipo | fromTime | untilTime | amount | recurrence | parent | |
----------------------------------------------------------------------------------------- | |
1 | "OrValidity" | null | null | null | null | null | |
1 | "ValidityTimeAmounmt" | navidad | null | -1 | null | 4 | |
1 | "RangeValidity" | navidad | añonuevo | null | null | 4 | |
1 | "ValidityTimeAmount" | añonuevo | null | 1 | null | 4 | |
Tabla que relaciona validity-con-hijos | |
TablaValidityValidity | |
- parentId | |
- childId | |
parentId | childId | |
------------------------ | |
1 | 2 | |
1 | 3 | |
1 | 4 | |
// Api usage | |
val navidadValidity | |
.save | |
val toleranciaMenor | |
.save | |
val toreanciaMayor | |
.save | |
val validityGuardada = OrValidity(listOf(navidad, toleranmciaMenor, toleranciaMayor)).save() | |
val nuevo = AndValidity(navidad, validityGuardada).save() | |
validityGuardada.isSatiesfiedBy(navidad) { validity -> | |
listOfValidities.forEach { it -> | |
println("la vigencia que hizo match fue $i.class" ) | |
} | |
} | |
// | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment