|
|
@ -1,29 +1,19 @@ |
|
|
|
import randomGenerator from './RandomGenerator' |
|
|
|
import randomGenerator from './RandomGenerator' |
|
|
|
import { Country } from '../../Enum/Country' |
|
|
|
import { Country } from '../../Enum/Country' |
|
|
|
import { Gender } from '../../Enum/Gender' |
|
|
|
import { Gender } from '../../Enum/Gender' |
|
|
|
|
|
|
|
import { Person } from '@/classes/DTO/Person' |
|
|
|
|
|
|
|
|
|
|
|
export class PersonalIdGenerator { |
|
|
|
export class PersonalIdGenerator { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* return e.generate = function (e, t) { |
|
|
|
* @param person |
|
|
|
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 |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
generate (country: Country, gender: Gender) { |
|
|
|
generate (person: Person) { |
|
|
|
const year = this.getYearPart() |
|
|
|
const year = this.getYearPart(person.birthday.year) |
|
|
|
const month = this.getMonthPart() |
|
|
|
const month = this.getMonthPart(person.birthday.month) |
|
|
|
const day = this.getDayPart() |
|
|
|
const day = this.getDayPart(person.birthday.day) |
|
|
|
const o = this.getIdNumPart() |
|
|
|
const o = this.getIdNumPart() |
|
|
|
const a = this.getGenderPart(country, gender) |
|
|
|
const a = this.getGenderPart(person.country, person.gender) |
|
|
|
const l = this.getControlSum(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) |
|
|
|
|
|
|
|
|
|
|
|
return a + year + month + day + o + l2 |
|
|
|
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) |
|
|
|
return String(Iu.generate(e - 25, e - 55)).substring(2, 4) |
|
|
|
}, |
|
|
|
}, |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
getYearPart () { |
|
|
|
getYearPart (year: bigint | null) { |
|
|
|
|
|
|
|
if (!year) { |
|
|
|
const e = (new Date()).getFullYear() |
|
|
|
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") |
|
|
|
return Iu.generate(1, 12).toString().padStart(2, "0") |
|
|
|
}, |
|
|
|
}, |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
getMonthPart () { |
|
|
|
getMonthPart (month: bigint | null) { |
|
|
|
return randomGenerator.generate(1, 12).toString().padStart(2, '0') |
|
|
|
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") |
|
|
|
return Iu.generate(1, 28).toString().padStart(2, "0") |
|
|
|
}, |
|
|
|
}, |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
getDayPart () { |
|
|
|
getDayPart (day: bigint | null) { |
|
|
|
return randomGenerator.generate(1, 28).toString().padStart(2, '0') |
|
|
|
if (!day) { |
|
|
|
|
|
|
|
day = BigInt(randomGenerator.generate(1, 28)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return day.toString().padStart(2, '0') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|