import
This commit is contained in:
parent
8ab3cb26b5
commit
33ec55250c
3 changed files with 374 additions and 198 deletions
|
|
@ -44,6 +44,7 @@ import { OrgChild3 } from "../entities/OrgChild3";
|
|||
import { OrgChild4 } from "../entities/OrgChild4";
|
||||
import { IMPORT_ORG } from "../entities/IMPORT_ORG";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
import { OFFICER } from "../entities/OFFICER";
|
||||
|
||||
@Route("api/v1/org/upload")
|
||||
@Tags("UPLOAD")
|
||||
|
|
@ -83,118 +84,24 @@ export class ImportDataController extends Controller {
|
|||
private orgChild3Repo = AppDataSource.getRepository(OrgChild3);
|
||||
private orgChild4Repo = AppDataSource.getRepository(OrgChild4);
|
||||
private IMPORT_ORGRepo = AppDataSource.getRepository(IMPORT_ORG);
|
||||
private OFFICERRepo = AppDataSource.getRepository(OFFICER);
|
||||
/**
|
||||
* @summary ทะเบียนประวัติ ข้าราชการ
|
||||
*/
|
||||
@Post("uploadProfile-Officer")
|
||||
async UploadFileSqlOfficer(@Request() request: { user: Record<string, any> }) {
|
||||
let users = [];
|
||||
let rowCount = 0;
|
||||
const filePath = path.resolve(__dirname, "OFFICER.csv"); // Corrected file path
|
||||
const readStream = fs.createReadStream(filePath).pipe(csvParser());
|
||||
let profiles: any = [];
|
||||
const OFFICER = await this.OFFICERRepo.find();
|
||||
let null_: any = null;
|
||||
for await (const item of readStream) {
|
||||
// readStream.map(async (item: any) => {
|
||||
rowCount++;
|
||||
let type_: any = null;
|
||||
let level_: any = null;
|
||||
const profile = new Profile();
|
||||
// if (item["FLAG_RETIRE_STATUSxxxx"] != "" && item["FLAG_RETIRE_STATUSxxxx"] != null) {
|
||||
// continue;
|
||||
// }
|
||||
// if (item["FLAG_PERSON_TYPExxxx"] != "1") {
|
||||
// continue;
|
||||
// }
|
||||
if (new Date(item["RET_YEAR"]).getFullYear() >= 2567) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const existingProfile = await this.profileRepo.findOne({
|
||||
where: { citizenId: item["ID"] },
|
||||
for await (const item of OFFICER) {
|
||||
let existingProfile = await this.profileRepo.findOne({
|
||||
where: { citizenId: item.ID },
|
||||
});
|
||||
if (existingProfile) {
|
||||
profile.id = existingProfile.id;
|
||||
// continue;
|
||||
if (existingProfile == null) {
|
||||
} else {
|
||||
existingProfile.position = item["WORK_LINE_NAME"] == "" ? null_ : item["WORK_LINE_NAME"];
|
||||
await this.profileRepo.save(existingProfile);
|
||||
}
|
||||
|
||||
if (item["TYPE"]) {
|
||||
type_ = await this.posTypeRepo.findOne({
|
||||
where: { posTypeName: item["TYPE"] },
|
||||
});
|
||||
}
|
||||
if (item["LEVEL"]) {
|
||||
if (type_ == null) {
|
||||
level_ = await this.posLevelRepo.findOne({
|
||||
where: {
|
||||
posLevelName: item["LEVEL"],
|
||||
},
|
||||
});
|
||||
} else {
|
||||
level_ = await this.posLevelRepo.findOne({
|
||||
where: {
|
||||
posLevelName: item["LEVEL"],
|
||||
posTypeId: type_.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let dateRetire = new Date(item["BORN"]);
|
||||
profile.citizenId = item["ID"] == "" ? "" : item["ID"];
|
||||
profile.rank =
|
||||
item["RANK_NAME"] == "" ||
|
||||
item["RANK_NAME"] == "นาย" ||
|
||||
item["RANK_NAME"] == "นาง" ||
|
||||
item["RANK_NAME"] == "นางสาว"
|
||||
? null
|
||||
: item["RANK_NAME"];
|
||||
profile.prefix = item["RANK_NAME"] == "" ? null : item["RANK_NAME"];
|
||||
profile.prefixMain =
|
||||
item["RANK_NAME"] == "" ||
|
||||
(item["RANK_NAME"] != "นาย" && item["RANK_NAME"] != "นาง" && item["RANK_NAME"] != "นางสาว")
|
||||
? null
|
||||
: item["RANK_NAME"];
|
||||
profile.firstName = item["FNAME"] == "" ? null : item["FNAME"];
|
||||
profile.lastName = item["LNAME"] == "" ? null : item["LNAME"];
|
||||
profile.gender = item["SEX"] == "1" ? "ชาย" : item["SEX"] == "2" ? "หญิง" : null_;
|
||||
profile.birthDate = item["BORN"] == "" ? null_ : new Date(item["BORN"]);
|
||||
profile.dateAppoint =
|
||||
item["BEGIN_ENTRY_DATE"] == "" ? null_ : new Date(item["BEGIN_ENTRY_DATE"]);
|
||||
profile.dateStart =
|
||||
item["BEGIN_ENTRY_DATE"] == "" ? null_ : new Date(item["BEGIN_ENTRY_DATE"]);
|
||||
profile.dateRetire = dateRetire == null ? null_ : calculateRetireDate(dateRetire);
|
||||
profile.dateRetireLaw = dateRetire == null ? null_ : calculateRetireLaw(dateRetire);
|
||||
profile.position = item["WORK_LINE_NAME"] == "" ? null : item["WORK_LINE_NAME"];
|
||||
profile.posTypeId =
|
||||
type_ != null && type_.posTypeName == item["TYPE"] && type_ ? type_.id : null;
|
||||
profile.posLevelId =
|
||||
level_ != null && level_.posLevelName == item["LEVEL"] && level_ ? level_.id : null;
|
||||
profile.relationship =
|
||||
item["สถานภาพ"] == "" ? "" : Extension.CheckRelationship(item["สถานภาพ"]);
|
||||
// profile.isLeave =
|
||||
// item["FLAG_RETIRE_STATUSxxxx"] == "" || item["FLAG_RETIRE_STATUSxxxx"] == null ? false : true;
|
||||
profile.createdUserId = request.user.sub;
|
||||
profile.createdFullName = request.user.name;
|
||||
profile.lastUpdateUserId = request.user.sub;
|
||||
profile.lastUpdateFullName = request.user.name;
|
||||
profile.createdAt = new Date();
|
||||
profile.lastUpdatedAt = new Date();
|
||||
// profiles.push(profile);
|
||||
console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
|
||||
|
||||
// if (profiles.length === BATCH_SIZE) {
|
||||
await this.profileRepo.save(profile);
|
||||
// profiles = await [];
|
||||
// if (global.gc) {
|
||||
// global.gc();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
// )
|
||||
// );
|
||||
// console.log(rowCount);
|
||||
// await this.profileRepo.save(profiles);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -296,7 +203,7 @@ export class ImportDataController extends Controller {
|
|||
.select(["profile.citizenId", "profile.id"])
|
||||
.orderBy("profile.citizenId", "ASC")
|
||||
// .skip(0)
|
||||
// .take(20)
|
||||
// .take(1000)
|
||||
.getManyAndCount();
|
||||
// for (var i = 1; i <= total / BATCH_SIZE; i++) {
|
||||
// const profiles = await AppDataSource.getRepository(Profile)
|
||||
|
|
@ -546,7 +453,7 @@ export class ImportDataController extends Controller {
|
|||
.select(["profile.citizenId", "profile.id"])
|
||||
.orderBy("profile.citizenId", "ASC")
|
||||
// .skip(0)
|
||||
// .take(20)
|
||||
// .take(1000)
|
||||
.getManyAndCount();
|
||||
// for (var i = 1; i <= total / BATCH_SIZE; i++) {
|
||||
// const profiles = await AppDataSource.getRepository(Profile)
|
||||
|
|
@ -853,7 +760,14 @@ export class ImportDataController extends Controller {
|
|||
profiles.map(async (_item) => {
|
||||
const existingProfile = await this.HR_EDUCATIONRepo.find({
|
||||
where: { CIT: _item.citizenId },
|
||||
select: ["CIT", "EDUCATION_CODE", "START_EDUCATION_YEAR", "EDUCATION_YEAR", "INSTITUE"],
|
||||
select: [
|
||||
"CIT",
|
||||
"EDUCATION_CODE",
|
||||
"START_EDUCATION_YEAR",
|
||||
"EDUCATION_YEAR",
|
||||
"INSTITUE",
|
||||
"EDUCATION_SEQ",
|
||||
],
|
||||
});
|
||||
|
||||
const educationLevel = await this.profileEducationRepo.findOne({
|
||||
|
|
@ -885,6 +799,7 @@ export class ImportDataController extends Controller {
|
|||
education.profileId = _item.id;
|
||||
education.degree = educationCode ? educationCode.EDUCATION_NAME : "";
|
||||
education.institute = item.INSTITUE;
|
||||
education.level = item.EDUCATION_SEQ ? null_ : Number(item.EDUCATION_SEQ);
|
||||
education.startDate = startDate;
|
||||
education.endDate = endDate;
|
||||
education.createdUserId = request.user.sub;
|
||||
|
|
@ -1468,15 +1383,22 @@ export class ImportDataController extends Controller {
|
|||
*/
|
||||
@Post("ImportOrg")
|
||||
async ImportOrg(@Request() request: { user: Record<string, any> }) {
|
||||
const IMPORT_ORG = await this.IMPORT_ORGRepo.find({
|
||||
where: { orgChild1: Not(IsNull()) || Not("") },
|
||||
});
|
||||
const orgRevision = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
});
|
||||
if (orgRevision == null) return new HttpSuccess();
|
||||
//create root
|
||||
const IMPORT_CHILD = await this.IMPORT_ORGRepo.find({
|
||||
where: {
|
||||
orgRoot: Not(""),
|
||||
orgChild1: "",
|
||||
orgChild2: "",
|
||||
orgChild3: "",
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
IMPORT_ORG.map(async (item) => {
|
||||
IMPORT_CHILD.map(async (item) => {
|
||||
const orgRoot = new OrgRoot();
|
||||
orgRoot.orgRootName = item.orgRoot;
|
||||
orgRoot.orgRootShortName = item.orgShortname;
|
||||
|
|
@ -1495,98 +1417,254 @@ export class ImportDataController extends Controller {
|
|||
orgRoot.createdAt = new Date();
|
||||
orgRoot.lastUpdatedAt = new Date();
|
||||
await this.orgRootRepo.save(orgRoot);
|
||||
}),
|
||||
);
|
||||
|
||||
const IMPORT_CHILD1 = await this.IMPORT_ORGRepo.find({
|
||||
where: { orgChild2: Not(IsNull()), orgRoot: item.orgRoot },
|
||||
//create child1
|
||||
const IMPORT_CHILD1 = await this.IMPORT_ORGRepo.find({
|
||||
where: {
|
||||
orgRoot: Not(""),
|
||||
orgChild1: Not(""),
|
||||
orgChild2: "",
|
||||
orgChild3: "",
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
IMPORT_CHILD1.map(async (item) => {
|
||||
const orgChild1 = new OrgChild1();
|
||||
let orgRoot = await this.orgRootRepo.findOne({
|
||||
where: { orgRootName: item.orgRoot },
|
||||
});
|
||||
await Promise.all(
|
||||
IMPORT_CHILD1.map(async (item1) => {
|
||||
const orgChild1 = new OrgChild1();
|
||||
orgChild1.orgRootId = orgRoot.id;
|
||||
orgChild1.orgChild1Name = item1.orgChild1;
|
||||
orgChild1.orgChild1ShortName = item.orgShortname;
|
||||
const rank: any = item.orgRank;
|
||||
orgChild1.orgChild1Rank = rank;
|
||||
orgChild1.orgChild1RankSub = item.orgSubRank;
|
||||
orgChild1.DEPARTMENT_CODE = item.DEPARTMENT_CODE;
|
||||
orgChild1.DIVISION_CODE = item.DIVISION_CODE;
|
||||
orgChild1.SECTION_CODE = item.SECTION_CODE;
|
||||
orgChild1.JOB_CODE = item.JOB_CODE;
|
||||
orgChild1.orgRevisionId = orgRevision.id;
|
||||
orgChild1.createdUserId = request.user.sub;
|
||||
orgChild1.createdFullName = request.user.name;
|
||||
orgChild1.lastUpdateUserId = request.user.sub;
|
||||
orgChild1.lastUpdateFullName = request.user.name;
|
||||
orgChild1.createdAt = new Date();
|
||||
orgChild1.lastUpdatedAt = new Date();
|
||||
await this.orgChild1Repo.save(orgChild1);
|
||||
const IMPORT_CHILD2 = await this.IMPORT_ORGRepo.find({
|
||||
where: {
|
||||
orgChild3: Not(IsNull()),
|
||||
orgRoot: item.orgRoot,
|
||||
orgChild1: item1.orgChild1,
|
||||
},
|
||||
});
|
||||
if (orgRoot == null) {
|
||||
orgRoot = new OrgRoot();
|
||||
orgRoot.orgRootName = item.orgRoot;
|
||||
orgRoot.orgRootShortName = item.orgShortname;
|
||||
const rank: any = item.orgRank;
|
||||
orgRoot.orgRootRank = rank;
|
||||
orgRoot.orgRootRankSub = item.orgSubRank;
|
||||
orgRoot.DEPARTMENT_CODE = item.DEPARTMENT_CODE;
|
||||
orgRoot.DIVISION_CODE = item.DIVISION_CODE;
|
||||
orgRoot.SECTION_CODE = item.SECTION_CODE;
|
||||
orgRoot.JOB_CODE = item.JOB_CODE;
|
||||
orgRoot.orgRevisionId = orgRevision.id;
|
||||
orgRoot.createdUserId = request.user.sub;
|
||||
orgRoot.createdFullName = request.user.name;
|
||||
orgRoot.lastUpdateUserId = request.user.sub;
|
||||
orgRoot.lastUpdateFullName = request.user.name;
|
||||
orgRoot.createdAt = new Date();
|
||||
orgRoot.lastUpdatedAt = new Date();
|
||||
await this.orgRootRepo.save(orgRoot);
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
IMPORT_CHILD2.map(async (item2) => {
|
||||
const orgChild2 = new OrgChild2();
|
||||
orgChild2.orgRootId = orgRoot.id;
|
||||
orgChild2.orgChild1Id = orgChild1.id;
|
||||
orgChild2.orgChild2Name = item2.orgChild2;
|
||||
orgChild2.orgChild2ShortName = item.orgShortname;
|
||||
const rank: any = item.orgRank;
|
||||
orgChild2.orgChild2Rank = rank;
|
||||
orgChild2.orgChild2RankSub = item.orgSubRank;
|
||||
orgChild2.DEPARTMENT_CODE = item.DEPARTMENT_CODE;
|
||||
orgChild2.DIVISION_CODE = item.DIVISION_CODE;
|
||||
orgChild2.SECTION_CODE = item.SECTION_CODE;
|
||||
orgChild2.JOB_CODE = item.JOB_CODE;
|
||||
orgChild2.orgRevisionId = orgRevision.id;
|
||||
orgChild2.createdUserId = request.user.sub;
|
||||
orgChild2.createdFullName = request.user.name;
|
||||
orgChild2.lastUpdateUserId = request.user.sub;
|
||||
orgChild2.lastUpdateFullName = request.user.name;
|
||||
orgChild2.createdAt = new Date();
|
||||
orgChild2.lastUpdatedAt = new Date();
|
||||
await this.orgChild2Repo.save(orgChild2);
|
||||
const IMPORT_CHILD3 = await this.IMPORT_ORGRepo.find({
|
||||
where: {
|
||||
orgRoot: item.orgRoot,
|
||||
orgChild1: item1.orgChild1,
|
||||
orgChild2: item2.orgChild2,
|
||||
},
|
||||
});
|
||||
orgChild1.orgRootId = orgRoot.id;
|
||||
orgChild1.orgChild1Name = item.orgChild1;
|
||||
orgChild1.orgChild1ShortName = item.orgShortname;
|
||||
const rank: any = item.orgRank;
|
||||
orgChild1.orgChild1Rank = rank;
|
||||
orgChild1.orgChild1RankSub = item.orgSubRank;
|
||||
orgChild1.DEPARTMENT_CODE = item.DEPARTMENT_CODE;
|
||||
orgChild1.DIVISION_CODE = item.DIVISION_CODE;
|
||||
orgChild1.SECTION_CODE = item.SECTION_CODE;
|
||||
orgChild1.JOB_CODE = item.JOB_CODE;
|
||||
orgChild1.orgRevisionId = orgRevision.id;
|
||||
orgChild1.createdUserId = request.user.sub;
|
||||
orgChild1.createdFullName = request.user.name;
|
||||
orgChild1.lastUpdateUserId = request.user.sub;
|
||||
orgChild1.lastUpdateFullName = request.user.name;
|
||||
orgChild1.createdAt = new Date();
|
||||
orgChild1.lastUpdatedAt = new Date();
|
||||
await this.orgChild1Repo.save(orgChild1);
|
||||
}),
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
IMPORT_CHILD3.map(async (item) => {
|
||||
const orgChild3 = new OrgChild3();
|
||||
orgChild3.orgRootId = orgRoot.id;
|
||||
orgChild3.orgChild1Id = orgChild1.id;
|
||||
orgChild3.orgChild2Id = orgChild2.id;
|
||||
orgChild3.orgChild3Name = item.orgChild3;
|
||||
orgChild3.orgChild3ShortName = item.orgShortname;
|
||||
const rank: any = item.orgRank;
|
||||
orgChild3.orgChild3Rank = rank;
|
||||
orgChild3.orgChild3RankSub = item.orgSubRank;
|
||||
orgChild3.DEPARTMENT_CODE = item.DEPARTMENT_CODE;
|
||||
orgChild3.DIVISION_CODE = item.DIVISION_CODE;
|
||||
orgChild3.SECTION_CODE = item.SECTION_CODE;
|
||||
orgChild3.JOB_CODE = item.JOB_CODE;
|
||||
orgChild3.orgRevisionId = orgRevision.id;
|
||||
orgChild3.createdUserId = request.user.sub;
|
||||
orgChild3.createdFullName = request.user.name;
|
||||
orgChild3.lastUpdateUserId = request.user.sub;
|
||||
orgChild3.lastUpdateFullName = request.user.name;
|
||||
orgChild3.createdAt = new Date();
|
||||
orgChild3.lastUpdatedAt = new Date();
|
||||
await this.orgChild3Repo.save(orgChild3);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
);
|
||||
//create child2
|
||||
const IMPORT_CHILD2 = await this.IMPORT_ORGRepo.find({
|
||||
where: {
|
||||
orgRoot: Not(""),
|
||||
orgChild1: Not(""),
|
||||
orgChild2: Not(""),
|
||||
orgChild3: "",
|
||||
},
|
||||
});
|
||||
await Promise.all(
|
||||
IMPORT_CHILD2.map(async (item) => {
|
||||
const orgChild2 = new OrgChild2();
|
||||
let orgRoot = await this.orgRootRepo.findOne({
|
||||
where: { orgRootName: item.orgRoot },
|
||||
});
|
||||
if (orgRoot == null) {
|
||||
orgRoot = new OrgRoot();
|
||||
orgRoot.orgRootName = item.orgRoot;
|
||||
orgRoot.orgRootShortName = item.orgShortname;
|
||||
const rank: any = item.orgRank;
|
||||
orgRoot.orgRootRank = rank;
|
||||
orgRoot.orgRootRankSub = item.orgSubRank;
|
||||
orgRoot.DEPARTMENT_CODE = item.DEPARTMENT_CODE;
|
||||
orgRoot.DIVISION_CODE = item.DIVISION_CODE;
|
||||
orgRoot.SECTION_CODE = item.SECTION_CODE;
|
||||
orgRoot.JOB_CODE = item.JOB_CODE;
|
||||
orgRoot.orgRevisionId = orgRevision.id;
|
||||
orgRoot.createdUserId = request.user.sub;
|
||||
orgRoot.createdFullName = request.user.name;
|
||||
orgRoot.lastUpdateUserId = request.user.sub;
|
||||
orgRoot.lastUpdateFullName = request.user.name;
|
||||
orgRoot.createdAt = new Date();
|
||||
orgRoot.lastUpdatedAt = new Date();
|
||||
await this.orgRootRepo.save(orgRoot);
|
||||
}
|
||||
let orgChild1 = await this.orgChild1Repo.findOne({
|
||||
where: { orgChild1Name: item.orgChild1 },
|
||||
});
|
||||
if (orgChild1 == null) {
|
||||
orgChild1 = new OrgChild1();
|
||||
orgChild1.orgRootId = orgRoot.id;
|
||||
orgChild1.orgChild1Name = item.orgChild1;
|
||||
orgChild1.orgChild1ShortName = item.orgShortname;
|
||||
const rank: any = item.orgRank;
|
||||
orgChild1.orgChild1Rank = rank;
|
||||
orgChild1.orgChild1RankSub = item.orgSubRank;
|
||||
orgChild1.DEPARTMENT_CODE = item.DEPARTMENT_CODE;
|
||||
orgChild1.DIVISION_CODE = item.DIVISION_CODE;
|
||||
orgChild1.SECTION_CODE = item.SECTION_CODE;
|
||||
orgChild1.JOB_CODE = item.JOB_CODE;
|
||||
orgChild1.orgRevisionId = orgRevision.id;
|
||||
orgChild1.createdUserId = request.user.sub;
|
||||
orgChild1.createdFullName = request.user.name;
|
||||
orgChild1.lastUpdateUserId = request.user.sub;
|
||||
orgChild1.lastUpdateFullName = request.user.name;
|
||||
orgChild1.createdAt = new Date();
|
||||
orgChild1.lastUpdatedAt = new Date();
|
||||
await this.orgChild1Repo.save(orgChild1);
|
||||
}
|
||||
orgChild2.orgRootId = orgRoot.id;
|
||||
orgChild2.orgChild1Id = orgChild1.id;
|
||||
orgChild2.orgChild2Name = item.orgChild2;
|
||||
orgChild2.orgChild2ShortName = item.orgShortname;
|
||||
const rank: any = item.orgRank;
|
||||
orgChild2.orgChild2Rank = rank;
|
||||
orgChild2.orgChild2RankSub = item.orgSubRank;
|
||||
orgChild2.DEPARTMENT_CODE = item.DEPARTMENT_CODE;
|
||||
orgChild2.DIVISION_CODE = item.DIVISION_CODE;
|
||||
orgChild2.SECTION_CODE = item.SECTION_CODE;
|
||||
orgChild2.JOB_CODE = item.JOB_CODE;
|
||||
orgChild2.orgRevisionId = orgRevision.id;
|
||||
orgChild2.createdUserId = request.user.sub;
|
||||
orgChild2.createdFullName = request.user.name;
|
||||
orgChild2.lastUpdateUserId = request.user.sub;
|
||||
orgChild2.lastUpdateFullName = request.user.name;
|
||||
orgChild2.createdAt = new Date();
|
||||
orgChild2.lastUpdatedAt = new Date();
|
||||
await this.orgChild2Repo.save(orgChild2);
|
||||
}),
|
||||
);
|
||||
|
||||
//create child3
|
||||
const IMPORT_CHILD3 = await this.IMPORT_ORGRepo.find({
|
||||
where: {
|
||||
orgRoot: Not(""),
|
||||
orgChild1: Not(""),
|
||||
orgChild2: Not(""),
|
||||
orgChild3: Not(""),
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
IMPORT_CHILD3.map(async (item) => {
|
||||
const orgChild3 = new OrgChild3();
|
||||
let orgRoot = await this.orgRootRepo.findOne({
|
||||
where: { orgRootName: item.orgRoot },
|
||||
});
|
||||
if (orgRoot == null) {
|
||||
orgRoot = new OrgRoot();
|
||||
orgRoot.orgRootName = item.orgRoot;
|
||||
orgRoot.orgRootShortName = item.orgShortname;
|
||||
const rank: any = item.orgRank;
|
||||
orgRoot.orgRootRank = rank;
|
||||
orgRoot.orgRootRankSub = item.orgSubRank;
|
||||
orgRoot.DEPARTMENT_CODE = item.DEPARTMENT_CODE;
|
||||
orgRoot.DIVISION_CODE = item.DIVISION_CODE;
|
||||
orgRoot.SECTION_CODE = item.SECTION_CODE;
|
||||
orgRoot.JOB_CODE = item.JOB_CODE;
|
||||
orgRoot.orgRevisionId = orgRevision.id;
|
||||
orgRoot.createdUserId = request.user.sub;
|
||||
orgRoot.createdFullName = request.user.name;
|
||||
orgRoot.lastUpdateUserId = request.user.sub;
|
||||
orgRoot.lastUpdateFullName = request.user.name;
|
||||
orgRoot.createdAt = new Date();
|
||||
orgRoot.lastUpdatedAt = new Date();
|
||||
await this.orgRootRepo.save(orgRoot);
|
||||
}
|
||||
let orgChild1 = await this.orgChild1Repo.findOne({
|
||||
where: { orgChild1Name: item.orgChild1 },
|
||||
});
|
||||
if (orgChild1 == null) {
|
||||
orgChild1 = new OrgChild1();
|
||||
orgChild1.orgRootId = orgRoot.id;
|
||||
orgChild1.orgChild1Name = item.orgChild1;
|
||||
orgChild1.orgChild1ShortName = item.orgShortname;
|
||||
const rank: any = item.orgRank;
|
||||
orgChild1.orgChild1Rank = rank;
|
||||
orgChild1.orgChild1RankSub = item.orgSubRank;
|
||||
orgChild1.DEPARTMENT_CODE = item.DEPARTMENT_CODE;
|
||||
orgChild1.DIVISION_CODE = item.DIVISION_CODE;
|
||||
orgChild1.SECTION_CODE = item.SECTION_CODE;
|
||||
orgChild1.JOB_CODE = item.JOB_CODE;
|
||||
orgChild1.orgRevisionId = orgRevision.id;
|
||||
orgChild1.createdUserId = request.user.sub;
|
||||
orgChild1.createdFullName = request.user.name;
|
||||
orgChild1.lastUpdateUserId = request.user.sub;
|
||||
orgChild1.lastUpdateFullName = request.user.name;
|
||||
orgChild1.createdAt = new Date();
|
||||
orgChild1.lastUpdatedAt = new Date();
|
||||
await this.orgChild1Repo.save(orgChild1);
|
||||
}
|
||||
let orgChild2 = await this.orgChild2Repo.findOne({
|
||||
where: { orgChild2Name: item.orgChild2 },
|
||||
});
|
||||
if (orgChild2 == null) {
|
||||
orgChild2 = new OrgChild2();
|
||||
orgChild2.orgRootId = orgRoot.id;
|
||||
orgChild2.orgChild1Id = orgChild1.id;
|
||||
orgChild2.orgChild2Name = item.orgChild2;
|
||||
orgChild2.orgChild2ShortName = item.orgShortname;
|
||||
const rank: any = item.orgRank;
|
||||
orgChild2.orgChild2Rank = rank;
|
||||
orgChild2.orgChild2RankSub = item.orgSubRank;
|
||||
orgChild2.DEPARTMENT_CODE = item.DEPARTMENT_CODE;
|
||||
orgChild2.DIVISION_CODE = item.DIVISION_CODE;
|
||||
orgChild2.SECTION_CODE = item.SECTION_CODE;
|
||||
orgChild2.JOB_CODE = item.JOB_CODE;
|
||||
orgChild2.orgRevisionId = orgRevision.id;
|
||||
orgChild2.createdUserId = request.user.sub;
|
||||
orgChild2.createdFullName = request.user.name;
|
||||
orgChild2.lastUpdateUserId = request.user.sub;
|
||||
orgChild2.lastUpdateFullName = request.user.name;
|
||||
orgChild2.createdAt = new Date();
|
||||
orgChild2.lastUpdatedAt = new Date();
|
||||
await this.orgChild2Repo.save(orgChild2);
|
||||
}
|
||||
|
||||
orgChild3.orgRootId = orgRoot.id;
|
||||
orgChild3.orgChild1Id = orgChild1.id;
|
||||
orgChild3.orgChild2Id = orgChild2.id;
|
||||
orgChild3.orgChild3Name = item.orgChild3;
|
||||
orgChild3.orgChild3ShortName = item.orgShortname;
|
||||
const rank: any = item.orgRank;
|
||||
orgChild3.orgChild3Rank = rank;
|
||||
orgChild3.orgChild3RankSub = item.orgSubRank;
|
||||
orgChild3.DEPARTMENT_CODE = item.DEPARTMENT_CODE;
|
||||
orgChild3.DIVISION_CODE = item.DIVISION_CODE;
|
||||
orgChild3.SECTION_CODE = item.SECTION_CODE;
|
||||
orgChild3.JOB_CODE = item.JOB_CODE;
|
||||
orgChild3.orgRevisionId = orgRevision.id;
|
||||
orgChild3.createdUserId = request.user.sub;
|
||||
orgChild3.createdFullName = request.user.name;
|
||||
orgChild3.lastUpdateUserId = request.user.sub;
|
||||
orgChild3.lastUpdateFullName = request.user.name;
|
||||
orgChild3.createdAt = new Date();
|
||||
orgChild3.lastUpdatedAt = new Date();
|
||||
await this.orgChild3Repo.save(orgChild3);
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue