Попарвил рассчет кода

master
Sipachev Igor 3 years ago
parent 97bb8653d1
commit 420eb3973b
  1. 26
      popup/src/classes/Service/Generators/PersonalIdGenerator.ts

@ -8,11 +8,16 @@ export class PersonalIdGenerator {
* @param 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 day = this.getDayPart(person.birthday.day)
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 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)
},
*/
getYearPart (year: bigint | null) {
if (!year) {
const e = (new Date()).getFullYear()
year = BigInt(randomGenerator.generate(e - 25, e - 55))
}
getYearPart (year: bigint) {
return String(year).substring(2, 4)
}
@ -80,9 +80,11 @@ export class PersonalIdGenerator {
},
* @param country
* @param gender
* @param year
*/
getGenderPart (country: Country, gender: Gender) {
getGenderPart (country: Country, gender: Gender, year: bigint) {
console.log(country, gender)
let tempGender = Gender.MALE
switch (country) {
case Country.POLAND:
console.log(country)
@ -91,7 +93,11 @@ export class PersonalIdGenerator {
: String(2 * randomGenerator.generate(1, 4))
default:
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…
Cancel
Save