|
|
|
@ -1,29 +1,19 @@ |
|
|
|
|
import randomGenerator from './RandomGenerator' |
|
|
|
|
import { Country } from '../../Enum/Country' |
|
|
|
|
import { Gender } from '../../Enum/Gender' |
|
|
|
|
import { Person } from '@/classes/DTO/Person' |
|
|
|
|
|
|
|
|
|
export class PersonalIdGenerator { |
|
|
|
|
/** |
|
|
|
|
* return e.generate = function (e, t) { |
|
|
|
|
var |
|
|
|
|
n = this.getYearPart(), |
|
|
|
|
r = this.getMonthPart(), |
|
|
|
|
i = this.getDayPart(), |
|
|
|
|
o = this.getIdNumPart(), |
|
|
|
|
a = this.getGenderPart(e, t), |
|
|
|
|
l = this.getControlSum(e, n, r, i, o, a); |
|
|
|
|
return "pl" === e ? n + r + i + o + a + l : a + n + r + i + o + l |
|
|
|
|
}, |
|
|
|
|
* @param country |
|
|
|
|
* @param gender |
|
|
|
|
* @param person |
|
|
|
|
*/ |
|
|
|
|
generate (country: Country, gender: Gender) { |
|
|
|
|
const year = this.getYearPart() |
|
|
|
|
const month = this.getMonthPart() |
|
|
|
|
const day = this.getDayPart() |
|
|
|
|
generate (person: Person) { |
|
|
|
|
const year = this.getYearPart(person.birthday.year) |
|
|
|
|
const month = this.getMonthPart(person.birthday.month) |
|
|
|
|
const day = this.getDayPart(person.birthday.day) |
|
|
|
|
const o = this.getIdNumPart() |
|
|
|
|
const a = this.getGenderPart(country, gender) |
|
|
|
|
const l = this.getControlSum(country, year, month, day, o, a) |
|
|
|
|
const a = this.getGenderPart(person.country, person.gender) |
|
|
|
|
const l = this.getControlSum(person.country, year, month, day, o, a) |
|
|
|
|
const l2 = this.getChecksum(a + year + month + day + o) |
|
|
|
|
|
|
|
|
|
return a + year + month + day + o + l2 |
|
|
|
@ -35,9 +25,13 @@ export class PersonalIdGenerator { |
|
|
|
|
return String(Iu.generate(e - 25, e - 55)).substring(2, 4) |
|
|
|
|
}, |
|
|
|
|
*/ |
|
|
|
|
getYearPart () { |
|
|
|
|
getYearPart (year: bigint | null) { |
|
|
|
|
if (!year) { |
|
|
|
|
const e = (new Date()).getFullYear() |
|
|
|
|
return String(randomGenerator.generate(e - 25, e - 55)).substring(2, 4) |
|
|
|
|
year = BigInt(randomGenerator.generate(e - 25, e - 55)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return String(year).substring(2, 4) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -45,8 +39,11 @@ export class PersonalIdGenerator { |
|
|
|
|
return Iu.generate(1, 12).toString().padStart(2, "0") |
|
|
|
|
}, |
|
|
|
|
*/ |
|
|
|
|
getMonthPart () { |
|
|
|
|
return randomGenerator.generate(1, 12).toString().padStart(2, '0') |
|
|
|
|
getMonthPart (month: bigint | null) { |
|
|
|
|
if (!month) { |
|
|
|
|
month = BigInt(randomGenerator.generate(1, 12)) |
|
|
|
|
} |
|
|
|
|
return month.toString().padStart(2, '0') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -54,8 +51,11 @@ export class PersonalIdGenerator { |
|
|
|
|
return Iu.generate(1, 28).toString().padStart(2, "0") |
|
|
|
|
}, |
|
|
|
|
*/ |
|
|
|
|
getDayPart () { |
|
|
|
|
return randomGenerator.generate(1, 28).toString().padStart(2, '0') |
|
|
|
|
getDayPart (day: bigint | null) { |
|
|
|
|
if (!day) { |
|
|
|
|
day = BigInt(randomGenerator.generate(1, 28)) |
|
|
|
|
} |
|
|
|
|
return day.toString().padStart(2, '0') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|