Попарвил рассчет кода
This commit is contained in:
parent
97bb8653d1
commit
420eb3973b
@ -8,11 +8,16 @@ export class PersonalIdGenerator {
|
|||||||
* @param person
|
* @param person
|
||||||
*/
|
*/
|
||||||
generate (person: Person) {
|
generate (person: Person) {
|
||||||
const year = this.getYearPart(person.birthday.year)
|
let fullYear = person.birthday.year
|
||||||
|
if (!fullYear) {
|
||||||
|
const e = (new Date()).getFullYear()
|
||||||
|
fullYear = BigInt(randomGenerator.generate(e - 5, e - 55))
|
||||||
|
}
|
||||||
|
const year = this.getYearPart(fullYear)
|
||||||
const month = this.getMonthPart(person.birthday.month)
|
const month = this.getMonthPart(person.birthday.month)
|
||||||
const day = this.getDayPart(person.birthday.day)
|
const day = this.getDayPart(person.birthday.day)
|
||||||
const o = this.getIdNumPart()
|
const o = this.getIdNumPart()
|
||||||
const a = this.getGenderPart(person.country, person.gender)
|
const a = this.getGenderPart(person.country, person.gender, fullYear)
|
||||||
const l = this.getControlSum(person.country, year, month, day, o, a)
|
const l = this.getControlSum(person.country, year, month, day, o, a)
|
||||||
const l2 = this.getChecksum(a + year + month + day + o)
|
const l2 = this.getChecksum(a + year + month + day + o)
|
||||||
|
|
||||||
@ -25,12 +30,7 @@ export class PersonalIdGenerator {
|
|||||||
return String(Iu.generate(e - 25, e - 55)).substring(2, 4)
|
return String(Iu.generate(e - 25, e - 55)).substring(2, 4)
|
||||||
},
|
},
|
||||||
*/
|
*/
|
||||||
getYearPart (year: bigint | null) {
|
getYearPart (year: bigint) {
|
||||||
if (!year) {
|
|
||||||
const e = (new Date()).getFullYear()
|
|
||||||
year = BigInt(randomGenerator.generate(e - 25, e - 55))
|
|
||||||
}
|
|
||||||
|
|
||||||
return String(year).substring(2, 4)
|
return String(year).substring(2, 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,9 +80,11 @@ export class PersonalIdGenerator {
|
|||||||
},
|
},
|
||||||
* @param country
|
* @param country
|
||||||
* @param gender
|
* @param gender
|
||||||
|
* @param year
|
||||||
*/
|
*/
|
||||||
getGenderPart (country: Country, gender: Gender) {
|
getGenderPart (country: Country, gender: Gender, year: bigint) {
|
||||||
console.log(country, gender)
|
console.log(country, gender)
|
||||||
|
let tempGender = Gender.MALE
|
||||||
switch (country) {
|
switch (country) {
|
||||||
case Country.POLAND:
|
case Country.POLAND:
|
||||||
console.log(country)
|
console.log(country)
|
||||||
@ -91,7 +93,11 @@ export class PersonalIdGenerator {
|
|||||||
: String(2 * randomGenerator.generate(1, 4))
|
: String(2 * randomGenerator.generate(1, 4))
|
||||||
default:
|
default:
|
||||||
console.log(gender, Gender.MALE === gender)
|
console.log(gender, Gender.MALE === gender)
|
||||||
return Gender.MALE === gender ? '3' : '4'
|
if (Gender.RANDOM === gender) {
|
||||||
|
tempGender = randomGenerator.generate(1, 999) > 500 ? Gender.FEMALE : Gender.MALE
|
||||||
|
}
|
||||||
|
console.log(year, 'year', typeof year)
|
||||||
|
return Gender.MALE === tempGender ? (year > 2000 ? '3' : '5') : (year < 2000 ? '4' : '6')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user