Merge branch 'develop'
* develop: update report import fix issue #1184 รายการปรับระดับชั้นงาน+ย้าย (ตัวย่อระดับชั้นงานแสดงไม่ครบ)
This commit is contained in:
commit
5344845c8c
6 changed files with 576 additions and 361 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();
|
||||
|
|
|
|||
|
|
@ -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,9 +6641,9 @@ export class ProfileController extends Controller {
|
|||
position: profile.position,
|
||||
leaveDate: profile.dateLeave,
|
||||
posMasterNo: posMaster == null ? null : posMaster.posMasterNo,
|
||||
posLevelName: profile.posLevel == null
|
||||
posLevelName: profile.posType == null && profile.posLevel == null
|
||||
? null
|
||||
: `${profile.posType.posTypeShortName ?? ""} ${profile.posLevel.posLevelName ?? ""}`,
|
||||
: `${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,69 +70,79 @@ 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')
|
||||
.leftJoinAndSelect('posMaster.current_holder', 'current_holder')
|
||||
.leftJoinAndSelect('posMaster.positions', 'positions')
|
||||
.leftJoinAndSelect('posMaster.orgRoot', 'orgRoot')
|
||||
.leftJoinAndSelect('positions.posExecutive', 'posExecutive')
|
||||
.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("positions.posExecutive", "posExecutive")
|
||||
.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 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,23 +152,25 @@ 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.toString()):Extension.ToThaiNumber(new Date().getFullYear().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 รายงานสถิติข้อมูลลูกจ้างประจำ กทม.
|
||||
|
|
@ -171,64 +193,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,
|
||||
|
|
@ -240,20 +271,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.toString()):Extension.ToThaiNumber(new Date().getFullYear().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,
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -6468,11 +6500,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")
|
||||
|
|
@ -6482,17 +6514,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 };
|
||||
|
|
@ -6501,7 +6536,7 @@ export class ReportController extends Controller {
|
|||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
|
||||
let result = Object.values(groupedData)
|
||||
.map((x: any) => ({
|
||||
type: x.type,
|
||||
|
|
@ -6523,16 +6558,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: "",
|
||||
|
|
@ -6541,13 +6576,13 @@ export class ReportController extends Controller {
|
|||
levelRank: "",
|
||||
total: _total,
|
||||
remark: "",
|
||||
})
|
||||
});
|
||||
total = x.total;
|
||||
_total = 0;
|
||||
}
|
||||
_reslut.push({
|
||||
...x
|
||||
})
|
||||
...x,
|
||||
});
|
||||
}
|
||||
tmpType = x.type;
|
||||
});
|
||||
|
|
@ -6559,7 +6594,7 @@ export class ReportController extends Controller {
|
|||
levelRank: "",
|
||||
total: total,
|
||||
remark: "",
|
||||
})
|
||||
});
|
||||
_reslut.push({
|
||||
type: "",
|
||||
typeRank: "",
|
||||
|
|
@ -6569,24 +6604,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")
|
||||
|
|
@ -6596,17 +6631,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 };
|
||||
|
|
@ -6615,14 +6653,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,
|
||||
}))
|
||||
|
|
@ -6638,16 +6676,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: "",
|
||||
|
|
@ -6656,13 +6694,13 @@ export class ReportController extends Controller {
|
|||
levelRank: "",
|
||||
total: _total,
|
||||
remark: "",
|
||||
})
|
||||
});
|
||||
total = x.total;
|
||||
_total = 0;
|
||||
}
|
||||
_reslut.push({
|
||||
...x
|
||||
})
|
||||
...x,
|
||||
});
|
||||
}
|
||||
tmpType = x.type;
|
||||
});
|
||||
|
|
@ -6674,7 +6712,7 @@ export class ReportController extends Controller {
|
|||
levelRank: "",
|
||||
total: total,
|
||||
remark: "",
|
||||
})
|
||||
});
|
||||
_reslut.push({
|
||||
type: "",
|
||||
typeRank: "",
|
||||
|
|
@ -6684,15 +6722,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;
|
||||
}
|
||||
|
|
|
|||
91
src/entities/OFFICER.ts
Normal file
91
src/entities/OFFICER.ts
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue