Merge branch 'develop' into adiDev
# Conflicts: # src/controllers/ReportController.ts
This commit is contained in:
commit
7b9172c93f
9 changed files with 879 additions and 290 deletions
|
|
@ -4707,7 +4707,40 @@ export class CommandController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({
|
||||
where: {
|
||||
orgRevisionIsCurrent: true,
|
||||
orgRevisionIsDraft: false
|
||||
}
|
||||
});
|
||||
const _posMaster = await this.employeePosMasterRepository.findOne({
|
||||
where: {
|
||||
orgRevisionId: orgRevision?.id,
|
||||
id: profile.posmasterIdTemp
|
||||
// current_holderId: profile.id
|
||||
},
|
||||
relations: {
|
||||
orgRoot: true,
|
||||
orgChild1: true,
|
||||
orgChild2: true,
|
||||
orgChild3: true,
|
||||
orgChild4: true,
|
||||
},
|
||||
});
|
||||
let orgShortName = "";
|
||||
if (_posMaster != null) {
|
||||
if (_posMaster.orgChild1Id === null) {
|
||||
orgShortName = _posMaster.orgRoot?.orgRootShortName;
|
||||
} else if (_posMaster.orgChild2Id === null) {
|
||||
orgShortName = _posMaster.orgChild1?.orgChild1ShortName;
|
||||
} else if (_posMaster.orgChild3Id === null) {
|
||||
orgShortName = _posMaster.orgChild2?.orgChild2ShortName;
|
||||
} else if (_posMaster.orgChild4Id === null) {
|
||||
orgShortName = _posMaster.orgChild3?.orgChild3ShortName;
|
||||
} else {
|
||||
orgShortName = _posMaster.orgChild4?.orgChild4ShortName;
|
||||
}
|
||||
}
|
||||
const dest_item = await this.salaryRepo.findOne({
|
||||
where: { profileEmployeeId: item.refId },
|
||||
order: { order: "DESC" },
|
||||
|
|
@ -4723,7 +4756,7 @@ export class CommandController extends Controller {
|
|||
commandId: item.commandId,
|
||||
positionSalaryAmount: item.positionSalaryAmount,
|
||||
mouthSalaryAmount: item.mouthSalaryAmount,
|
||||
posNo: profile.posMasterNoTemp,
|
||||
posNo: `${orgShortName ?? ""} ${profile.posMasterNoTemp ?? ""}`,
|
||||
position: profile.positionTemp,
|
||||
positionType: profile.posTypeNameTemp,
|
||||
positionLevel: profile.posLevelNameTemp,
|
||||
|
|
|
|||
|
|
@ -44,6 +44,9 @@ 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";
|
||||
import { Position } from "../entities/Position";
|
||||
import { PosMaster } from "../entities/PosMaster";
|
||||
|
||||
@Route("api/v1/org/upload")
|
||||
@Tags("UPLOAD")
|
||||
|
|
@ -83,97 +86,120 @@ 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);
|
||||
private positionRepo = AppDataSource.getRepository(Position);
|
||||
private posMasterRepo = AppDataSource.getRepository(PosMaster);
|
||||
/**
|
||||
* @summary ทะเบียนประวัติ ข้าราชการ
|
||||
*/
|
||||
@Post("uploadProfile-Officer")
|
||||
async UploadFileSqlOfficer(@Request() request: { user: Record<string, any> }) {
|
||||
let users = [];
|
||||
const OFFICER = await this.OFFICERRepo.find();
|
||||
// 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 filePath = path.resolve(__dirname, "OFFICER.csv"); // Corrected file path
|
||||
// const readStream = fs.createReadStream(filePath).pipe(csvParser());
|
||||
// let profiles: any = [];
|
||||
let null_: any = null;
|
||||
for await (const item of readStream) {
|
||||
let profile: any;
|
||||
// await Promise.all(
|
||||
// OFFICER.map(async (item) => {
|
||||
for await (const item of OFFICER) {
|
||||
// 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) {
|
||||
profile = null;
|
||||
profile = new Profile();
|
||||
// if (item["FLAG_RETIRE_STATUSxxxx != "" && item["FLAG_RETIRE_STATUSxxxx != null) {
|
||||
// continue;
|
||||
// }
|
||||
// if (item["FLAG_PERSON_TYPExxxx"] != "1") {
|
||||
// if (item["FLAG_PERSON_TYPExxxx != "1") {
|
||||
// continue;
|
||||
// }
|
||||
if (new Date(item["RET_YEAR"]).getFullYear() >= 2567) {
|
||||
continue;
|
||||
}
|
||||
// if (new Date(item.RET_YEAR).getFullYear() >= 2567) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
const existingProfile = await this.profileRepo.findOne({
|
||||
where: { citizenId: item["ID"] },
|
||||
where: { citizenId: item.ID },
|
||||
});
|
||||
if (existingProfile) {
|
||||
profile.id = existingProfile.id;
|
||||
// continue;
|
||||
}
|
||||
|
||||
if (item["TYPE"]) {
|
||||
if (item.MP_CATEGORY) {
|
||||
type_ = await this.posTypeRepo.findOne({
|
||||
where: { posTypeName: item["TYPE"] },
|
||||
where: { posTypeName: item.MP_CATEGORY },
|
||||
});
|
||||
}
|
||||
if (item["LEVEL"]) {
|
||||
if (item.MP_LEVEL) {
|
||||
if (type_ == null) {
|
||||
level_ = await this.posLevelRepo.findOne({
|
||||
where: {
|
||||
posLevelName: item["LEVEL"],
|
||||
posLevelName: item.MP_LEVEL,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
level_ = await this.posLevelRepo.findOne({
|
||||
where: {
|
||||
posLevelName: item["LEVEL"],
|
||||
posLevelName: item.MP_LEVEL,
|
||||
posTypeId: type_.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let dateRetire = new Date(item["BORN"]);
|
||||
profile.citizenId = item["ID"] == "" ? "" : item["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"] == "นางสาว"
|
||||
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"];
|
||||
: 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"] != "นางสาว")
|
||||
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"]);
|
||||
: 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.position = item.WORK_LINE_NAME == "" ? null : item.WORK_LINE_NAME;
|
||||
profile.posTypeId =
|
||||
type_ != null && type_.posTypeName == item["TYPE"] && type_ ? type_.id : null;
|
||||
type_ != null && type_.posTypeName == item.MP_CATEGORY && type_ ? type_.id : null;
|
||||
profile.posLevelId =
|
||||
level_ != null && level_.posLevelName == item["LEVEL"] && level_ ? level_.id : null;
|
||||
profile.relationship =
|
||||
item["สถานภาพ"] == "" ? "" : Extension.CheckRelationship(item["สถานภาพ"]);
|
||||
level_ != null && level_.posLevelName == item.MP_LEVEL && level_ ? level_.id : null;
|
||||
// profile.relationship =
|
||||
// item.สถานภาพ == "" ? "" : Extension.CheckRelationship(item.สถานภาพ);
|
||||
// profile.position =
|
||||
// item.WORK_LINE_NAME == "" ? "" : Extension.CheckRelationship(item.WORK_LINE_NAME);
|
||||
profile.position = item["WORK_LINE_NAME"] == "" ? null : item["WORK_LINE_NAME"];
|
||||
// const level = await this.posLevelRepo.findOne({
|
||||
// where: {
|
||||
// posLevelName: item.MP_LEVEL,
|
||||
// posType: {
|
||||
// posTypeName: item.MP_Type,
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
// profile.posLevelId = level?.id ?? null_;
|
||||
// const type = await this.posTypeRepo.findOne({
|
||||
// where: { posTypeName: item.MP_Type },
|
||||
// });
|
||||
// profile.posTypeId = type?.id ?? null_;
|
||||
profile.amount = item.SALARY == "" ? 0 : Number(Extension.CheckRelationship(item.SALARY));
|
||||
// profile.isLeave =
|
||||
// item["FLAG_RETIRE_STATUSxxxx"] == "" || item["FLAG_RETIRE_STATUSxxxx"] == null ? false : true;
|
||||
// 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;
|
||||
|
|
@ -185,12 +211,15 @@ export class ImportDataController extends Controller {
|
|||
|
||||
// if (profiles.length === BATCH_SIZE) {
|
||||
await this.profileRepo.save(profile);
|
||||
// console.log(profile);
|
||||
// profiles = await [];
|
||||
// if (global.gc) {
|
||||
// global.gc();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
// }),
|
||||
// );
|
||||
// )
|
||||
// );
|
||||
// console.log(rowCount);
|
||||
|
|
@ -209,19 +238,21 @@ export class ImportDataController extends Controller {
|
|||
const readStream = fs.createReadStream(filePath).pipe(csvParser());
|
||||
let profiles: any = [];
|
||||
let null_: any = null;
|
||||
let profileEmp: any;
|
||||
|
||||
for await (const item of readStream) {
|
||||
rowCount++;
|
||||
const profileEmp = new ProfileEmployee();
|
||||
profileEmp = null;
|
||||
profileEmp = new ProfileEmployee();
|
||||
// if (item["FLAG_RETIRE_STATUS"] != "" && item["FLAG_RETIRE_STATUS"] != null) {
|
||||
// continue;
|
||||
// }
|
||||
if (item["FLAG_PERSON_TYPE"] != "6") {
|
||||
continue;
|
||||
}
|
||||
if (new Date(item["RET_YEAR"]).getFullYear() >= 2567) {
|
||||
continue;
|
||||
}
|
||||
// if (new Date(item["RET_YEAR"]).getFullYear() >= 2567) {
|
||||
// continue;
|
||||
// }
|
||||
const existingProfile = await this.profileEmpRepo.findOne({
|
||||
where: { citizenId: item["ID"] },
|
||||
});
|
||||
|
|
@ -261,6 +292,8 @@ export class ImportDataController extends Controller {
|
|||
profileEmp.salaryLevel = item["SALARY_LEVEL_CODE"] == "" ? null : item["SALARY_LEVEL_CODE"];
|
||||
profileEmp.relationship =
|
||||
item["MARRIAGE_STATE"] == "" ? "" : Extension.CheckRelationship(item["MARRIAGE_STATE"]);
|
||||
profileEmp.amount =
|
||||
item["SALARY"] == "" ? 0 : Number(Extension.CheckRelationship(item.SALARY));
|
||||
profileEmp.createdUserId = request.user.sub;
|
||||
profileEmp.createdFullName = request.user.name;
|
||||
profileEmp.lastUpdateUserId = request.user.sub;
|
||||
|
|
@ -296,7 +329,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 +579,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 +886,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 +925,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,18 +1509,32 @@ 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()) },
|
||||
});
|
||||
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.misId = item.MISCODE;
|
||||
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;
|
||||
|
|
@ -1488,79 +1543,383 @@ 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.misId = item1.MISCODE;
|
||||
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.misId = item2.MISCODE;
|
||||
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.misId = item.MISCODE;
|
||||
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();
|
||||
}
|
||||
/**
|
||||
* @summary ทะเบียนประวัติ ข้าราชการ
|
||||
*/
|
||||
@Post("mapposition-Officer")
|
||||
async MapPositionOfficer(@Request() request: { user: Record<string, any> }) {
|
||||
const [officer, total] = await AppDataSource.getRepository(OFFICER)
|
||||
.createQueryBuilder("OFFICER")
|
||||
// .skip(0)
|
||||
// .take(20)
|
||||
.getManyAndCount();
|
||||
let rowCount = 0;
|
||||
let null_: any = null;
|
||||
let type_: any = null;
|
||||
let level_: any = null;
|
||||
const orgRevision = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
});
|
||||
if (orgRevision == null) return new HttpSuccess();
|
||||
for await (const item of officer) {
|
||||
rowCount++;
|
||||
|
||||
const existingProfile = await this.profileRepo.findOne({
|
||||
where: { citizenId: item.ID },
|
||||
});
|
||||
if (existingProfile == null) {
|
||||
continue;
|
||||
}
|
||||
const orgRoot = await this.orgRootRepo.findOne({
|
||||
where: { orgRootName: item.DEPARTMENT_NAME, orgRevisionId: orgRevision.id },
|
||||
});
|
||||
if (orgRoot == null) {
|
||||
continue;
|
||||
}
|
||||
const orgChild1 = await this.orgChild1Repo.findOne({
|
||||
where: {
|
||||
orgChild1Name: item.DIVISION_NAME,
|
||||
orgRoot: { orgRootName: item.DEPARTMENT_NAME },
|
||||
orgRevisionId: orgRevision.id,
|
||||
},
|
||||
});
|
||||
const orgChild2 = await this.orgChild2Repo.findOne({
|
||||
where: {
|
||||
orgChild2Name: item.SECTION_NAME,
|
||||
orgChild1: {
|
||||
orgChild1Name: item.DIVISION_NAME,
|
||||
orgRoot: { orgRootName: item.DEPARTMENT_NAME },
|
||||
},
|
||||
orgRevisionId: orgRevision.id,
|
||||
},
|
||||
});
|
||||
const orgChild3 = await this.orgChild3Repo.findOne({
|
||||
where: {
|
||||
orgChild3Name: item.JOB_NAME,
|
||||
orgChild2: {
|
||||
orgChild2Name: item.SECTION_NAME,
|
||||
orgChild1: {
|
||||
orgChild1Name: item.DIVISION_NAME,
|
||||
orgRoot: { orgRootName: item.DEPARTMENT_NAME },
|
||||
},
|
||||
},
|
||||
orgRevisionId: orgRevision.id,
|
||||
},
|
||||
});
|
||||
let posMaster = new PosMaster();
|
||||
posMaster.orgRootId = orgRoot?.id ?? null_;
|
||||
posMaster.orgChild1Id = orgChild1?.id ?? null_;
|
||||
posMaster.orgChild2Id = orgChild2?.id ?? null_;
|
||||
posMaster.orgChild3Id = orgChild3?.id ?? null_;
|
||||
posMaster.statusReport = "PENDING";
|
||||
posMaster.isCondition = false;
|
||||
posMaster.isStaff = false;
|
||||
posMaster.isDirector = false;
|
||||
posMaster.isSit = false;
|
||||
posMaster.current_holderId = existingProfile.id;
|
||||
posMaster.posMasterNo = item.SALARY == "" ? null_ : Number(item.POS_NUM_CODE);
|
||||
posMaster.orgRevisionId = orgRevision.id;
|
||||
posMaster.posMasterCreatedAt = new Date();
|
||||
posMaster.createdUserId = request.user.sub;
|
||||
posMaster.createdFullName = request.user.name;
|
||||
posMaster.lastUpdateUserId = request.user.sub;
|
||||
posMaster.lastUpdateFullName = request.user.name;
|
||||
posMaster.createdAt = new Date();
|
||||
posMaster.lastUpdatedAt = new Date();
|
||||
await this.posMasterRepo.save(posMaster);
|
||||
posMaster.ancestorDNA = posMaster.id;
|
||||
await this.posMasterRepo.save(posMaster);
|
||||
|
||||
let position = new Position();
|
||||
if (item.MP_CATEGORY) {
|
||||
type_ = await this.posTypeRepo.findOne({
|
||||
where: { posTypeName: item.MP_CATEGORY },
|
||||
});
|
||||
}
|
||||
if (item.MP_LEVEL) {
|
||||
if (type_ == null) {
|
||||
level_ = await this.posLevelRepo.findOne({
|
||||
where: {
|
||||
posLevelName: item.MP_LEVEL,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
level_ = await this.posLevelRepo.findOne({
|
||||
where: {
|
||||
posLevelName: item.MP_LEVEL,
|
||||
posTypeId: type_.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
position.posMasterId = posMaster.id;
|
||||
position.isSpecial = false;
|
||||
position.positionIsSelected = true;
|
||||
position.createdUserId = request.user.sub;
|
||||
position.createdFullName = request.user.name;
|
||||
position.lastUpdateUserId = request.user.sub;
|
||||
position.lastUpdateFullName = request.user.name;
|
||||
position.createdAt = new Date();
|
||||
position.lastUpdatedAt = new Date();
|
||||
position.positionName = item.WORK_LINE_NAME == "" ? null_ : item.WORK_LINE_NAME;
|
||||
position.posTypeId =
|
||||
type_ != null && type_.posTypeName == item.MP_CATEGORY && type_ ? type_.id : null;
|
||||
position.posLevelId =
|
||||
level_ != null && level_.posLevelName == item.MP_LEVEL && level_ ? level_.id : null;
|
||||
await this.positionRepo.save(position);
|
||||
}
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1213,31 +1213,31 @@ export class OrganizationDotnetController extends Controller {
|
|||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgRoot.ancestorDNA ?? null,
|
||||
child1DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild3.ancestorDNA ?? null,
|
||||
child2DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild2.ancestorDNA ?? null,
|
||||
child3DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild3.ancestorDNA ?? null,
|
||||
child4DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild4.ancestorDNA ?? null,
|
||||
commander: fullname,
|
||||
posLevel: profile.posLevel?.posLevelName ?? null,
|
||||
posType: profile.posType?.posTypeName ?? null,
|
||||
|
|
@ -1510,31 +1510,31 @@ export class OrganizationDotnetController extends Controller {
|
|||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgRoot.ancestorDNA ?? null,
|
||||
child1DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild1.ancestorDNA ?? null,
|
||||
child2DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild2.ancestorDNA ?? null,
|
||||
child3DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild3.ancestorDNA ?? null,
|
||||
child4DnaId:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild4.ancestorDNA ?? null,
|
||||
commander: fullname,
|
||||
posLevel: profile.posLevel?.posLevelName ?? null,
|
||||
posType: profile.posType?.posTypeName ?? null,
|
||||
|
|
@ -2276,7 +2276,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgRoot.ancestorDNA ?? null,
|
||||
child1:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
|
|
@ -2294,7 +2294,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild1.ancestorDNA ?? null,
|
||||
child2:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
|
|
@ -2312,7 +2312,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild2.ancestorDNA ?? null,
|
||||
child3:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
|
|
@ -2330,7 +2330,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild3.ancestorDNA ?? null,
|
||||
child4:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
|
|
@ -2348,7 +2348,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild4.ancestorDNA ?? null,
|
||||
posNo: shortName ?? "",
|
||||
};
|
||||
});
|
||||
|
|
@ -2643,7 +2643,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgRoot.ancestorDNA ?? null,
|
||||
child1:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
|
|
@ -2661,7 +2661,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild1.ancestorDNA ?? null,
|
||||
child2:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
|
|
@ -2679,7 +2679,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild2.ancestorDNA ?? null,
|
||||
child3:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
|
|
@ -2697,7 +2697,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild3.ancestorDNA ?? null,
|
||||
child4:
|
||||
profile?.current_holders?.find(
|
||||
(x) =>
|
||||
|
|
@ -2715,7 +2715,7 @@ export class OrganizationDotnetController extends Controller {
|
|||
(x) =>
|
||||
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||
)?.ancestorDNA ?? null,
|
||||
)?.orgChild4.ancestorDNA ?? null,
|
||||
posNo: shortName ?? "",
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4383,7 +4383,9 @@ export class PositionController extends Controller {
|
|||
posTypeId: position.posTypeId,
|
||||
posTypeName: position.posType == null ? null : position.posType.posTypeName,
|
||||
posLevelId: position.posLevelId,
|
||||
posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName,
|
||||
posLevelName: position.posType == null && position.posLevel == null
|
||||
? null
|
||||
: `${position.posType.posTypeShortName} ${position.posLevel.posLevelName}`,
|
||||
// posExecutiveId: position.posExecutiveId,
|
||||
// posExecutiveName:
|
||||
// position.posExecutive == null ? null : position.posExecutive.posExecutiveName,
|
||||
|
|
|
|||
|
|
@ -6641,7 +6641,9 @@ export class ProfileController extends Controller {
|
|||
position: profile.position,
|
||||
leaveDate: profile.dateLeave,
|
||||
posMasterNo: posMaster == null ? null : posMaster.posMasterNo,
|
||||
posLevelName: profile.posLevel == null ? null : profile.posLevel.posLevelName,
|
||||
posLevelName: profile.posType == null && profile.posLevel == null
|
||||
? null
|
||||
: `${profile.posType.posTypeShortName} ${profile.posLevel.posLevelName}`,
|
||||
posLevelRank: profile.posLevel == null ? null : profile.posLevel.posLevelRank,
|
||||
posLevelId: profile.posLevel == null ? null : profile.posLevel.id,
|
||||
posTypeName: profile.posType == null ? null : profile.posType.posTypeName,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,14 @@
|
|||
import { Controller, Get, Route, Security, Tags, SuccessResponse, Response, Path, Query } from "tsoa";
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Path,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
|
|
@ -37,7 +47,7 @@ export class ReportController extends Controller {
|
|||
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
||||
private profileRepository = AppDataSource.getRepository(Profile);
|
||||
private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
|
||||
/**
|
||||
/**
|
||||
* API รายงานสถิติข้อมูลข้าราชการ กทม. สามัญ
|
||||
*
|
||||
* @summary รายงานสถิติข้อมูลข้าราชการ กทม. สามัญ
|
||||
|
|
@ -60,15 +70,15 @@ export class ReportController extends Controller {
|
|||
|
||||
const minAge = ageMin ?? 18;
|
||||
const maxAge = ageMax ?? 60;
|
||||
|
||||
|
||||
if (minAge > maxAge) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ageMin cannot be greater than ageMax");
|
||||
}
|
||||
const yearInAD = year?year:null;
|
||||
const yearInAD = year ? year : null;
|
||||
const currentRevision = await this.orgRevisionRepository.findOne({
|
||||
where:{
|
||||
orgRevisionIsCurrent: true
|
||||
}
|
||||
where: {
|
||||
orgRevisionIsCurrent: true,
|
||||
},
|
||||
});
|
||||
const rawdataProfile = await this.posMasterRepository
|
||||
.createQueryBuilder('posMaster')
|
||||
|
|
@ -87,42 +97,47 @@ export class ReportController extends Controller {
|
|||
.andWhere(`
|
||||
TIMESTAMPDIFF(YEAR, current_holder.birthDate, CURDATE()) >= :minAge
|
||||
AND TIMESTAMPDIFF(YEAR, current_holder.birthDate, CURDATE()) <= :maxAge
|
||||
`, { minAge, maxAge })
|
||||
.orderBy("posType.posTypeName","ASC")
|
||||
.getMany();
|
||||
if(!rawdataProfile){
|
||||
`,
|
||||
{ minAge, maxAge },
|
||||
)
|
||||
.orderBy("posType.posTypeName", "ASC")
|
||||
.getMany();
|
||||
if (!rawdataProfile) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
|
||||
}
|
||||
const mapData = rawdataProfile
|
||||
.map((x) => {
|
||||
const latestEducation = x.current_holder.profileEducations.sort((a:any, b:any) => b.endDate - a.startDate)[0];
|
||||
const mapData = rawdataProfile.map((x) => {
|
||||
const latestEducation = x.current_holder.profileEducations.sort(
|
||||
(a: any, b: any) => b.endDate - a.startDate,
|
||||
)[0];
|
||||
return {
|
||||
name: x.current_holder.firstName + " " + x.current_holder.lastName,
|
||||
affiliation: x.orgRoot.orgRootName??"-",
|
||||
gender: x.current_holder.gender??"-",
|
||||
positionName: x.positions[0]?x.positions[0].positionName:"-",
|
||||
status: x.current_holder.relationship??"-",
|
||||
posType: x.current_holder.posType.posTypeName??"-",
|
||||
posLevel: x.current_holder.posLevel.posLevelName??"-",
|
||||
affiliation: x.orgRoot.orgRootName ?? "-",
|
||||
gender: x.current_holder.gender ?? "-",
|
||||
positionName: x.positions[0] ? x.positions[0].positionName : "-",
|
||||
status: x.current_holder.relationship ?? "-",
|
||||
posType: x.current_holder.posType.posTypeName ?? "-",
|
||||
posLevel: x.current_holder.posLevel.posLevelName ?? "-",
|
||||
degree: latestEducation ? latestEducation.educationLevel : "-",
|
||||
posExecutive: x.positions[0].posExecutive?x.positions[0].posExecutive.posExecutiveName:"-",
|
||||
posExecutive: x.positions[0].posExecutive
|
||||
? x.positions[0].posExecutive.posExecutiveName
|
||||
: "-",
|
||||
currentPreiodPos: "-",
|
||||
levelPeriodPos: "-",
|
||||
};
|
||||
});
|
||||
|
||||
const groupedData = mapData.reduce((acc:any, item) => {
|
||||
const key = `${item.posType} - ${item.affiliation} - ${item.gender} - ${item.degree || 'ไม่พบข้อมูล'} - ${item.status || 'ไม่พบข้อมูล'} - ${item.positionName} - ${item.posLevel} - ${item.posExecutive || 'ไม่พบข้อมูล'} `;
|
||||
const groupedData = mapData.reduce((acc: any, item) => {
|
||||
const key = `${item.posType} - ${item.affiliation} - ${item.gender} - ${item.degree || "ไม่พบข้อมูล"} - ${item.status || "ไม่พบข้อมูล"} - ${item.positionName} - ${item.posLevel} - ${item.posExecutive || "ไม่พบข้อมูล"} `;
|
||||
if (!acc[key]) {
|
||||
acc[key] = {
|
||||
posType: item.posType && item.posType != "" ? item.posType: "-",
|
||||
affiliation: item.affiliation && item.affiliation != "" ? item.affiliation: "-",
|
||||
gender: item.gender && item.gender != "" ? item.gender: "-",
|
||||
degree: item.degree && item.degree != "" ? item.degree: "-",
|
||||
status: item.status && item.status != "" ? item.status: "-",
|
||||
positionName: item.positionName && item.positionName != "" ? item.positionName: "-",
|
||||
posLevel: item.posLevel && item.posLevel != "" ? item.posLevel: "-",
|
||||
posExecutive: item.posExecutive && item.posExecutive != "" ? item.posExecutive: "-",
|
||||
posType: item.posType && item.posType != "" ? item.posType : "-",
|
||||
affiliation: item.affiliation && item.affiliation != "" ? item.affiliation : "-",
|
||||
gender: item.gender && item.gender != "" ? item.gender : "-",
|
||||
degree: item.degree && item.degree != "" ? item.degree : "-",
|
||||
status: item.status && item.status != "" ? item.status : "-",
|
||||
positionName: item.positionName && item.positionName != "" ? item.positionName : "-",
|
||||
posLevel: item.posLevel && item.posLevel != "" ? item.posLevel : "-",
|
||||
posExecutive: item.posExecutive && item.posExecutive != "" ? item.posExecutive : "-",
|
||||
currentPreiodPos: "-",
|
||||
levelPeriodPos: "-",
|
||||
count: 0,
|
||||
|
|
@ -132,22 +147,24 @@ export class ReportController extends Controller {
|
|||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
|
||||
const result = Object.values(groupedData).map((item: any) => ({
|
||||
...item ,
|
||||
count: Extension.ToThaiNumber(item.count.toString()),
|
||||
...item,
|
||||
count: Extension.ToThaiNumber(item.count.toString()),
|
||||
}));
|
||||
return new HttpSuccess({
|
||||
template: "registry-officer",
|
||||
reportName: "xlsx-report",
|
||||
data: {
|
||||
year: year?Extension.ToThaiNumber((year + 543).toString()):Extension.ToThaiNumber(((new Date()).getFullYear()+543).toString()),
|
||||
year: year
|
||||
? Extension.ToThaiNumber((year + 543).toString())
|
||||
: Extension.ToThaiNumber((new Date().getFullYear() + 543).toString()),
|
||||
date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())),
|
||||
list: result
|
||||
list: result,
|
||||
},
|
||||
});
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* API รายงานสถิติข้อมูลลูกจ้างประจำ กทม.
|
||||
*
|
||||
* @summary รายงานสถิติข้อมูลลูกจ้างประจำ กทม.
|
||||
|
|
@ -170,64 +187,73 @@ export class ReportController extends Controller {
|
|||
|
||||
const minAge = ageMin ?? 18;
|
||||
const maxAge = ageMax ?? 60;
|
||||
|
||||
|
||||
if (minAge > maxAge) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ageMin cannot be greater than ageMax");
|
||||
}
|
||||
const yearInAD = year?year:null;
|
||||
const yearInAD = year ? year : null;
|
||||
const currentRevision = await this.orgRevisionRepository.findOne({
|
||||
where:{
|
||||
orgRevisionIsCurrent: true
|
||||
}
|
||||
where: {
|
||||
orgRevisionIsCurrent: true,
|
||||
},
|
||||
});
|
||||
const rawdataProfile = await this.empPosMasterRepository
|
||||
.createQueryBuilder('posMaster')
|
||||
.leftJoinAndSelect('posMaster.current_holder', 'current_holder')
|
||||
.leftJoinAndSelect('posMaster.positions', 'positions')
|
||||
.leftJoinAndSelect('posMaster.orgRoot', 'orgRoot')
|
||||
.leftJoinAndSelect('current_holder.posType', 'posType')
|
||||
.leftJoinAndSelect('current_holder.posLevel', 'posLevel')
|
||||
.leftJoinAndSelect('current_holder.profileEducations', 'profileEducations')
|
||||
.where('posMaster.orgRevisionId = :currentRevisionId', { currentRevisionId: currentRevision?.id })
|
||||
.andWhere(rootId?'posMaster.orgRootId = :rootId': "1=1", { rootId: rootId })
|
||||
.andWhere('posMaster.current_holderId Is Not Null')
|
||||
.andWhere('positions.positionIsSelected = :positionIsSelected', { positionIsSelected: true })
|
||||
.andWhere( yearInAD && yearInAD != null? 'YEAR(current_holder.dateAppoint) = :year': "1=1", { year: yearInAD })
|
||||
.andWhere(`
|
||||
.createQueryBuilder("posMaster")
|
||||
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
|
||||
.leftJoinAndSelect("posMaster.positions", "positions")
|
||||
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
|
||||
.leftJoinAndSelect("current_holder.posType", "posType")
|
||||
.leftJoinAndSelect("current_holder.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("current_holder.profileEducations", "profileEducations")
|
||||
.where("posMaster.orgRevisionId = :currentRevisionId", {
|
||||
currentRevisionId: currentRevision?.id,
|
||||
})
|
||||
.andWhere(rootId ? "posMaster.orgRootId = :rootId" : "1=1", { rootId: rootId })
|
||||
.andWhere("posMaster.current_holderId Is Not Null")
|
||||
.andWhere("positions.positionIsSelected = :positionIsSelected", { positionIsSelected: true })
|
||||
.andWhere(yearInAD && yearInAD != null ? "YEAR(current_holder.dateAppoint) = :year" : "1=1", {
|
||||
year: yearInAD,
|
||||
})
|
||||
.andWhere(
|
||||
`
|
||||
TIMESTAMPDIFF(YEAR, current_holder.birthDate, CURDATE()) >= :minAge
|
||||
AND TIMESTAMPDIFF(YEAR, current_holder.birthDate, CURDATE()) <= :maxAge
|
||||
`, { minAge, maxAge })
|
||||
.orderBy("posType.posTypeName","ASC")
|
||||
.getMany();
|
||||
if(!rawdataProfile){
|
||||
`,
|
||||
{ minAge, maxAge },
|
||||
)
|
||||
.orderBy("posType.posTypeName", "ASC")
|
||||
.getMany();
|
||||
if (!rawdataProfile) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
|
||||
}
|
||||
const mapData = rawdataProfile.map((x) => {
|
||||
const latestEducation = x.current_holder.profileEducations.sort((a:any, b:any) => b.endDate - a.startDate)[0];
|
||||
const latestEducation = x.current_holder.profileEducations.sort(
|
||||
(a: any, b: any) => b.endDate - a.startDate,
|
||||
)[0];
|
||||
return {
|
||||
name: x.current_holder.firstName + " " + x.current_holder.lastName,
|
||||
affiliation: x.orgRoot.orgRootName??"-",
|
||||
gender: x.current_holder.gender??"-",
|
||||
positionName: x.positions[0]?x.positions[0].positionName: "-",
|
||||
status: x.current_holder.relationship??"-",
|
||||
posType: x.current_holder.posType.posTypeName??"-",
|
||||
posLevel: x.current_holder.posLevel.posLevelName??"-",
|
||||
degree: latestEducation ? latestEducation.educationLevel : "-",
|
||||
affiliation: x.orgRoot.orgRootName ?? "-",
|
||||
gender: x.current_holder.gender ?? "-",
|
||||
positionName: x.positions[0] ? x.positions[0].positionName : "-",
|
||||
status: x.current_holder.relationship ?? "-",
|
||||
posType: x.current_holder.posType.posTypeName ?? "-",
|
||||
posLevel: x.current_holder.posLevel.posLevelName ?? "-",
|
||||
degree: latestEducation ? latestEducation.educationLevel : "-",
|
||||
period: "-",
|
||||
};
|
||||
});
|
||||
|
||||
const groupedData = mapData.reduce((acc:any, item) => {
|
||||
const key = `${item.affiliation} - ${item.gender} - ${item.degree || 'ไม่พบข้อมูล'} - ${item.status || 'ไม่พบข้อมูล'} - ${item.posType} - ${item.positionName} - ${item.posLevel}
|
||||
const groupedData = mapData.reduce((acc: any, item) => {
|
||||
const key = `${item.affiliation} - ${item.gender} - ${item.degree || "ไม่พบข้อมูล"} - ${item.status || "ไม่พบข้อมูล"} - ${item.posType} - ${item.positionName} - ${item.posLevel}
|
||||
`;
|
||||
if (!acc[key]) {
|
||||
acc[key] = {
|
||||
affiliation: item.affiliation && item.affiliation != ""?item.affiliation:"-",
|
||||
gender: item.gender && item.gender != ""?item.gender:"-",
|
||||
degree: item.degree && item.degree != ""?item.degree:"-",
|
||||
status: item.status && item.status != ""?item.status:"-",
|
||||
posType: item.posType && item.posType != ""?item.posType:"-",
|
||||
positionName: item.positionName && item.positionName != ""?item.positionName:"-",
|
||||
affiliation: item.affiliation && item.affiliation != "" ? item.affiliation : "-",
|
||||
gender: item.gender && item.gender != "" ? item.gender : "-",
|
||||
degree: item.degree && item.degree != "" ? item.degree : "-",
|
||||
status: item.status && item.status != "" ? item.status : "-",
|
||||
posType: item.posType && item.posType != "" ? item.posType : "-",
|
||||
positionName: item.positionName && item.positionName != "" ? item.positionName : "-",
|
||||
posLevel: Extension.ToThaiNumber(item.posLevel.toString()),
|
||||
period: "-",
|
||||
count: 0,
|
||||
|
|
@ -239,20 +265,21 @@ export class ReportController extends Controller {
|
|||
}, {});
|
||||
|
||||
const result = Object.values(groupedData).map((item: any) => ({
|
||||
...item ,
|
||||
count: Extension.ToThaiNumber(item.count.toString())
|
||||
...item,
|
||||
count: Extension.ToThaiNumber(item.count.toString()),
|
||||
}));
|
||||
|
||||
|
||||
return new HttpSuccess({
|
||||
template: "registry-emp",
|
||||
reportName: "xlsx-report",
|
||||
data: {
|
||||
year: year?Extension.ToThaiNumber((year + 543).toString()):Extension.ToThaiNumber(((new Date()).getFullYear()+543).toString()),
|
||||
year: year
|
||||
? Extension.ToThaiNumber((year + 543).toString())
|
||||
: Extension.ToThaiNumber((new Date().getFullYear() + 543).toString()),
|
||||
date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())),
|
||||
list: result
|
||||
list: result,
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -6467,11 +6494,11 @@ export class ReportController extends Controller {
|
|||
|
||||
@Get("report4/{rootId}")
|
||||
async findReport4(@Path() rootId: string) {
|
||||
const orgRootData = await this.orgRootRepository.findOne({
|
||||
where: { id: rootId }
|
||||
const orgRootData = await this.orgRootRepository.findOne({
|
||||
where: { id: rootId },
|
||||
});
|
||||
if (!orgRootData) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
|
||||
const posMaster = await this.posMasterRepository
|
||||
.createQueryBuilder("posMaster")
|
||||
.leftJoinAndSelect("posMaster.positions", "position")
|
||||
|
|
@ -6481,17 +6508,20 @@ export class ReportController extends Controller {
|
|||
.orderBy("posType.posTypeRank", "ASC")
|
||||
.addOrderBy("posLevel.posLevelRank", "ASC")
|
||||
.getMany();
|
||||
|
||||
const _posMaster = posMaster
|
||||
.map((x) => ({
|
||||
type: [...new Set(x.positions.flatMap((y) => y.posType.posTypeName))].join(","),
|
||||
typeRank: [...new Set(x.positions.flatMap((y) => y.posType.posTypeRank))].join(""),
|
||||
level: [...new Set(x.positions.flatMap((y) => y.posLevel.posLevelName))].join(","),
|
||||
levelRank: [...new Set(x.positions.flatMap((y) => `${y.posType.posTypeRank}${y.posLevel.posLevelRank}`))].join(""),
|
||||
positions: [...new Set(x.positions.flatMap((y) => y.positionName))].join(""),
|
||||
}))
|
||||
|
||||
const groupedData = _posMaster.reduce((acc:any, curr:any) => {
|
||||
const _posMaster = posMaster.map((x) => ({
|
||||
type: [...new Set(x.positions.flatMap((y) => y.posType.posTypeName))].join(","),
|
||||
typeRank: [...new Set(x.positions.flatMap((y) => y.posType.posTypeRank))].join(""),
|
||||
level: [...new Set(x.positions.flatMap((y) => y.posLevel.posLevelName))].join(","),
|
||||
levelRank: [
|
||||
...new Set(
|
||||
x.positions.flatMap((y) => `${y.posType.posTypeRank}${y.posLevel.posLevelRank}`),
|
||||
),
|
||||
].join(""),
|
||||
positions: [...new Set(x.positions.flatMap((y) => y.positionName))].join(""),
|
||||
}));
|
||||
|
||||
const groupedData = _posMaster.reduce((acc: any, curr: any) => {
|
||||
const key = `${curr.type}|${curr.typeRank}|${curr.level}|${curr.levelRank}`;
|
||||
if (!acc[key]) {
|
||||
acc[key] = { ...curr, total: 1 };
|
||||
|
|
@ -6500,7 +6530,7 @@ export class ReportController extends Controller {
|
|||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
|
||||
let result = Object.values(groupedData)
|
||||
.map((x: any) => ({
|
||||
type: x.type,
|
||||
|
|
@ -6522,16 +6552,16 @@ export class ReportController extends Controller {
|
|||
let _total: number = 0;
|
||||
let _reslut = new Array();
|
||||
|
||||
result.forEach((x:any, idx:number) => {
|
||||
result.forEach((x: any, idx: number) => {
|
||||
allTotal += x.total;
|
||||
total += x.total;
|
||||
if(x.type === tmpType) {
|
||||
if (x.type === tmpType) {
|
||||
_reslut.push({
|
||||
...x,
|
||||
type: ""
|
||||
})
|
||||
}else {
|
||||
if(x.type !== tmpType && tmpType != "") {
|
||||
type: "",
|
||||
});
|
||||
} else {
|
||||
if (x.type !== tmpType && tmpType != "") {
|
||||
_total = total - x.total;
|
||||
_reslut.push({
|
||||
type: "",
|
||||
|
|
@ -6540,13 +6570,13 @@ export class ReportController extends Controller {
|
|||
levelRank: "",
|
||||
total: _total,
|
||||
remark: "",
|
||||
})
|
||||
});
|
||||
total = x.total;
|
||||
_total = 0;
|
||||
}
|
||||
_reslut.push({
|
||||
...x
|
||||
})
|
||||
...x,
|
||||
});
|
||||
}
|
||||
tmpType = x.type;
|
||||
});
|
||||
|
|
@ -6558,7 +6588,7 @@ export class ReportController extends Controller {
|
|||
levelRank: "",
|
||||
total: total,
|
||||
remark: "",
|
||||
})
|
||||
});
|
||||
_reslut.push({
|
||||
type: "",
|
||||
typeRank: "",
|
||||
|
|
@ -6568,24 +6598,24 @@ export class ReportController extends Controller {
|
|||
remark: "",
|
||||
});
|
||||
|
||||
return new HttpSuccess({
|
||||
template: "report4",
|
||||
reportName: "report4",
|
||||
data: {
|
||||
return new HttpSuccess({
|
||||
template: "report4",
|
||||
reportName: "report4",
|
||||
data: {
|
||||
dateCurrent: Extension.ToThaiShortDate(new Date()),
|
||||
rootName: orgRootData ? orgRootData.orgRootName : "-",
|
||||
data: _reslut
|
||||
}
|
||||
});
|
||||
data: _reslut,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@Get("report4-employee/{rootId}")
|
||||
async findReportEmp4(@Path() rootId: string) {
|
||||
const orgRootData = await this.orgRootRepository.findOne({
|
||||
where: { id: rootId }
|
||||
const orgRootData = await this.orgRootRepository.findOne({
|
||||
where: { id: rootId },
|
||||
});
|
||||
if (!orgRootData) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
|
||||
const posMaster = await this.empPosMasterRepository
|
||||
.createQueryBuilder("posMaster")
|
||||
.leftJoinAndSelect("posMaster.positions", "position")
|
||||
|
|
@ -6595,17 +6625,20 @@ export class ReportController extends Controller {
|
|||
.orderBy("posType.posTypeRank", "ASC")
|
||||
.addOrderBy("posLevel.posLevelRank", "ASC")
|
||||
.getMany();
|
||||
|
||||
const _posMaster = posMaster
|
||||
.map((x) => ({
|
||||
type: [...new Set(x.positions.flatMap((y) => y.posType.posTypeName))].join(","),
|
||||
typeRank: [...new Set(x.positions.flatMap((y) => y.posType.posTypeRank))].join(""),
|
||||
level: [...new Set(x.positions.flatMap((y) => y.posLevel.posLevelName))].join(","),
|
||||
levelRank: [...new Set(x.positions.flatMap((y) => `${y.posType.posTypeRank}${y.posLevel.posLevelRank}`))].join(""),
|
||||
positions: [...new Set(x.positions.flatMap((y) => y.positionName))].join(""),
|
||||
}))
|
||||
|
||||
const groupedData = _posMaster.reduce((acc:any, curr:any) => {
|
||||
const _posMaster = posMaster.map((x) => ({
|
||||
type: [...new Set(x.positions.flatMap((y) => y.posType.posTypeName))].join(","),
|
||||
typeRank: [...new Set(x.positions.flatMap((y) => y.posType.posTypeRank))].join(""),
|
||||
level: [...new Set(x.positions.flatMap((y) => y.posLevel.posLevelName))].join(","),
|
||||
levelRank: [
|
||||
...new Set(
|
||||
x.positions.flatMap((y) => `${y.posType.posTypeRank}${y.posLevel.posLevelRank}`),
|
||||
),
|
||||
].join(""),
|
||||
positions: [...new Set(x.positions.flatMap((y) => y.positionName))].join(""),
|
||||
}));
|
||||
|
||||
const groupedData = _posMaster.reduce((acc: any, curr: any) => {
|
||||
const key = `${curr.type}|${curr.typeRank}|${curr.level}|${curr.levelRank}`;
|
||||
if (!acc[key]) {
|
||||
acc[key] = { ...curr, total: 1 };
|
||||
|
|
@ -6614,14 +6647,14 @@ export class ReportController extends Controller {
|
|||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
|
||||
let result = Object.values(groupedData)
|
||||
.map((x: any) => ({
|
||||
type: x.type,
|
||||
typeRank: parseInt(x.typeRank),
|
||||
level: x.level,
|
||||
levelRank: parseInt(x.levelRank),
|
||||
|
||||
|
||||
total: x.total,
|
||||
remark: x.positions,
|
||||
}))
|
||||
|
|
@ -6637,16 +6670,16 @@ export class ReportController extends Controller {
|
|||
let _total: number = 0;
|
||||
let _reslut = new Array();
|
||||
|
||||
result.forEach((x:any, idx:number) => {
|
||||
result.forEach((x: any, idx: number) => {
|
||||
allTotal += x.total;
|
||||
total += x.total;
|
||||
if(x.type === tmpType) {
|
||||
if (x.type === tmpType) {
|
||||
_reslut.push({
|
||||
...x,
|
||||
type: ""
|
||||
})
|
||||
}else {
|
||||
if(x.type !== tmpType && tmpType != "") {
|
||||
type: "",
|
||||
});
|
||||
} else {
|
||||
if (x.type !== tmpType && tmpType != "") {
|
||||
_total = total - x.total;
|
||||
_reslut.push({
|
||||
type: "",
|
||||
|
|
@ -6655,13 +6688,13 @@ export class ReportController extends Controller {
|
|||
levelRank: "",
|
||||
total: _total,
|
||||
remark: "",
|
||||
})
|
||||
});
|
||||
total = x.total;
|
||||
_total = 0;
|
||||
}
|
||||
_reslut.push({
|
||||
...x
|
||||
})
|
||||
...x,
|
||||
});
|
||||
}
|
||||
tmpType = x.type;
|
||||
});
|
||||
|
|
@ -6673,7 +6706,7 @@ export class ReportController extends Controller {
|
|||
levelRank: "",
|
||||
total: total,
|
||||
remark: "",
|
||||
})
|
||||
});
|
||||
_reslut.push({
|
||||
type: "",
|
||||
typeRank: "",
|
||||
|
|
@ -6683,15 +6716,14 @@ export class ReportController extends Controller {
|
|||
remark: "",
|
||||
});
|
||||
|
||||
return new HttpSuccess({
|
||||
template: "report4",
|
||||
reportName: "report4",
|
||||
data: {
|
||||
return new HttpSuccess({
|
||||
template: "report4",
|
||||
reportName: "report4",
|
||||
data: {
|
||||
dateCurrent: Extension.ToThaiShortDate(new Date()),
|
||||
rootName: orgRootData ? orgRootData.orgRootName : "-",
|
||||
data: _reslut
|
||||
}
|
||||
});
|
||||
data: _reslut,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,4 +45,11 @@ export class HR_EDUCATION {
|
|||
default: null,
|
||||
})
|
||||
INSTITUE: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
EDUCATION_SEQ: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,4 +67,25 @@ export class IMPORT_ORG {
|
|||
default: null,
|
||||
})
|
||||
MISCODE: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
orgShortname: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
orgRank: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
orgSubRank: string;
|
||||
}
|
||||
|
|
|
|||
133
src/entities/OFFICER.ts
Normal file
133
src/entities/OFFICER.ts
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
import { Entity, Column, PrimaryGeneratedColumn } from "typeorm";
|
||||
|
||||
@Entity("OFFICER")
|
||||
export class OFFICER {
|
||||
@PrimaryGeneratedColumn()
|
||||
id!: number;
|
||||
|
||||
// @Column({
|
||||
// nullable: true,
|
||||
// type: "text",
|
||||
// default: null,
|
||||
// })
|
||||
// RET_YEAR: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
ID: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
MP_CATEGORY: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
MP_LEVEL: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
BORN: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
RANK_NAME: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
FNAME: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
LNAME: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
BEGIN_ENTRY_DATE: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
SEX: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
WORK_LINE_NAME: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
SALARY: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
DEPARTMENT_NAME: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
DIVISION_NAME: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
SECTION_NAME: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
JOB_NAME: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
POS_NUM_CODE: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "text",
|
||||
default: null,
|
||||
})
|
||||
POS_NUM_NAME: string;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue