diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index f1c1ead8..fdb9e668 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -67,6 +67,12 @@ import { HR_DISCIPLINE } from "../entities/HR_DISCIPLINE"; import { HR_INSIGNIA } from "../entities/HR_INSIGNIA"; import { HR_INSIGNIA_EMP } from "../entities/HR_INSIGNIA_EMP"; import { Insignia } from "../entities/Insignia"; +import { ProfileChildren } from "../entities/ProfileChildren"; +import { ProfileChangeName } from "../entities/ProfileChangeName"; +import { HR_CHILDEN } from "../entities/HR_CHILDEN"; +import { HR_CHILDEN_EMP } from "../entities/HR_CHILDEN_EMP"; +import { HR_CHANGENAME } from "../entities/HR_CHANGENAME"; +import { HR_CHANGENAME_EMP } from "../entities/HR_CHANGENAME_EMP"; @Route("api/v1/org/upload") @Tags("UPLOAD") @Security("bearerAuth") @@ -78,6 +84,8 @@ export class ImportDataController extends Controller { private profileFamilyMotherRepository = AppDataSource.getRepository(ProfileFamilyMother); private profileFamilyFatherRepository = AppDataSource.getRepository(ProfileFamilyFather); private salaryRepo = AppDataSource.getRepository(ProfileSalary); + private profileChildrenRepo = AppDataSource.getRepository(ProfileChildren); + private profileChangeNameRepo = AppDataSource.getRepository(ProfileChangeName); private profileRepo = AppDataSource.getRepository(Profile); private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); private posLevelRepo = AppDataSource.getRepository(PosLevel); @@ -90,11 +98,15 @@ export class ImportDataController extends Controller { private HR_EDUCATIONRepo = AppDataSource.getRepository(HR_EDUCATION); private HR_DISCIPLINERepo = AppDataSource.getRepository(HR_DISCIPLINE); private HR_INSIGNIARepo = AppDataSource.getRepository(HR_INSIGNIA); + private HR_CHILDENRepo = AppDataSource.getRepository(HR_CHILDEN); + private HR_CHANGENAMERepo = AppDataSource.getRepository(HR_CHANGENAME); private HR_PERSONAL_OFFICER_ADDRESSRepo = AppDataSource.getRepository( HR_PERSONAL_OFFICER_ADDRESS, ); private HR_DISCIPLINE_EMPRepo = AppDataSource.getRepository(HR_DISCIPLINE_EMP); private HR_INSIGNIA_EMPRepo = AppDataSource.getRepository(HR_INSIGNIA_EMP); + private HR_CHILDEN_EMPRepo = AppDataSource.getRepository(HR_CHILDEN_EMP); + private HR_CHANGENAME_EMPRepo = AppDataSource.getRepository(HR_CHANGENAME_EMP); private HR_EDUCATION_EMPRepo = AppDataSource.getRepository(HR_EDUCATION_EMP); private HR_PERSONAL_EMP_ADDRESSRepo = AppDataSource.getRepository(HR_PERSONAL_EMP_ADDRESS); private HR_PERSONAL_EMP_FAMILYRepo = AppDataSource.getRepository(HR_PERSONAL_EMP_FAMILY); @@ -1248,7 +1260,7 @@ export class ImportDataController extends Controller { } profileSalary.posNoAbb = item.POS_NUM_NAME; profileSalary.posNo = item.POS_NUM_CODE; - profileSalary.positionName = item.WORK_LINE_NAME; + profileSalary.positionName = item.WORK_LINE_NAME_F; var positionType = _null; var positionLevel = _null; if (item.CATEGORY_SAL_CODE == "11") { @@ -1260,7 +1272,7 @@ export class ImportDataController extends Controller { } profileSalary.positionType = positionType; - profileSalary.positionLevel = positionLevel; + profileSalary.positionLevel = item.LEVEL_NAME; profileSalary.orgRoot = item.DEPARTMENT_NAME; profileSalary.orgChild1 = item.DIVISION_NAME; profileSalary.orgChild2 = item.SECTION_NAME; @@ -1975,6 +1987,7 @@ export class ImportDataController extends Controller { .createQueryBuilder("profile") .select(["profile.citizenId", "profile.id"]) .orderBy("profile.citizenId", "ASC") + // .where("profile.citizenId = '3101702379675'") // .skip(0) // .take(20) .getManyAndCount(); @@ -2032,6 +2045,7 @@ export class ImportDataController extends Controller { let districtId = await this.districtIdRepo.findOne({ where: { name: districtRegis_.AMPHUR_NAME, + provinceId: provinceId.id, }, }); if (districtId == null) { @@ -2041,7 +2055,7 @@ export class ImportDataController extends Controller { name: districtRegis_.AMPHUR_NAME, provinceId: provinceId.id, }); - await this.provinceIdRepo.save(provinceId); + await this.districtIdRepo.save(districtId); } _item.registrationDistrictId = districtId ? districtId.id : _null; if (DISTRICT_CODE) { @@ -2056,6 +2070,7 @@ export class ImportDataController extends Controller { let subDistrictId = await this.subDistrictIdRepo.findOne({ where: { name: subDistrictRegis_.DISTRICT_NAME, + districtId: districtId.id, }, }); if (subDistrictId == null) { @@ -2066,7 +2081,7 @@ export class ImportDataController extends Controller { zipCode: existingProfile.ZIPCODE, districtId: districtId.id, }); - await this.provinceIdRepo.save(provinceId); + await this.subDistrictIdRepo.save(subDistrictId); } _item.registrationSubDistrictId = subDistrictId ? subDistrictId.id : _null; } @@ -2106,6 +2121,7 @@ export class ImportDataController extends Controller { let districtId = await this.districtIdRepo.findOne({ where: { name: districtCurr_.AMPHUR_NAME, + provinceId: provinceId.id, }, }); if (districtId == null) { @@ -2115,7 +2131,7 @@ export class ImportDataController extends Controller { name: districtCurr_.AMPHUR_NAME, provinceId: provinceId.id, }); - await this.provinceIdRepo.save(provinceId); + await this.districtIdRepo.save(districtId); } _item.currentDistrictId = districtId ? districtId.id : _null; if (CONTACT_DISTRICT_CODE) { @@ -2130,6 +2146,7 @@ export class ImportDataController extends Controller { let subDistrictId = await this.subDistrictIdRepo.findOne({ where: { name: subDistrictCurr_.DISTRICT_NAME, + districtId: districtId.id, }, }); if (subDistrictId == null) { @@ -2140,7 +2157,7 @@ export class ImportDataController extends Controller { zipCode: existingProfile.CONTACT_ZIPCODE, districtId: districtId.id, }); - await this.provinceIdRepo.save(provinceId); + await this.subDistrictIdRepo.save(subDistrictId); } _item.currentSubDistrictId = subDistrictId ? subDistrictId.id : _null; } @@ -2243,7 +2260,7 @@ export class ImportDataController extends Controller { name: districtRegis_.AMPHUR_NAME, provinceId: provinceId.id, }); - await this.provinceIdRepo.save(provinceId); + await this.districtIdRepo.save(districtId); } _item.registrationDistrictId = districtId ? districtId.id : _null; if (DISTRICT_CODE) { @@ -2268,7 +2285,7 @@ export class ImportDataController extends Controller { zipCode: existingProfile.ZIPCODE, districtId: districtId.id, }); - await this.provinceIdRepo.save(provinceId); + await this.subDistrictIdRepo.save(subDistrictId); } _item.registrationSubDistrictId = subDistrictId ? subDistrictId.id : _null; } @@ -2317,7 +2334,7 @@ export class ImportDataController extends Controller { name: districtCurr_.AMPHUR_NAME, provinceId: provinceId.id, }); - await this.provinceIdRepo.save(provinceId); + await this.districtIdRepo.save(districtId); } _item.currentDistrictId = districtId ? districtId.id : _null; if (CONTACT_DISTRICT_CODE) { @@ -2342,7 +2359,7 @@ export class ImportDataController extends Controller { zipCode: existingProfile.CONTACT_ZIPCODE, districtId: districtId.id, }); - await this.provinceIdRepo.save(provinceId); + await this.subDistrictIdRepo.save(subDistrictId); } _item.currentSubDistrictId = subDistrictId ? subDistrictId.id : _null; } @@ -3027,7 +3044,7 @@ export class ImportDataController extends Controller { let type_: any = null; let level_: any = null; const orgRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true }, + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, // where: { id: "30e594c9-a65b-485e-a4c5-71aa497e6b8a" }, }); if (orgRevision == null) return new HttpSuccess(); @@ -3868,4 +3885,180 @@ export class ImportDataController extends Controller { } return new HttpSuccess(); } + + /** + * @summary เปลี่ยนชื่อ ข้าราชการ + */ + @Post("uploadProfileChangeName-Officer") + async UploadFileSQLChangeName(@Request() request: { user: Record }) { + console.log(">>>>>>>>>>>>>>>>>>>"); + let rowCount = 0; + let _null: any = null; + + const [profiles, total] = await AppDataSource.getRepository(Profile) + .createQueryBuilder("profile") + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + .getManyAndCount(); + + for (const _item of profiles) { + const existingProfile = await this.HR_CHANGENAMERepo.find({ + where: { CIT: _item.citizenId }, + // order: { SEQ: "ASC" }, + }); + + for (const item of existingProfile) { + let EFFECT_DATE = ""; + if (item.EFFECT_DATE) { + const [datePart] = item.EFFECT_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + EFFECT_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + } + rowCount++; + const changeName = new ProfileChangeName(); + changeName.profileId = _item.id; + changeName.prefix = item.NEW_RANK_NAME == "" ? _item.prefix : item.NEW_RANK_NAME; + changeName.firstName = item.NEW_FNAME == "" ? _item.firstName : item.NEW_FNAME; + changeName.lastName = item.NEW_LNAME == "" ? _item.lastName : item.NEW_LNAME; + changeName.createdUserId = request.user.sub; + changeName.createdFullName = request.user.name; + changeName.lastUpdateUserId = request.user.sub; + changeName.lastUpdateFullName = request.user.name; + changeName.createdAt = EFFECT_DATE == "" ? new Date() : new Date(EFFECT_DATE); + changeName.lastUpdatedAt = EFFECT_DATE == "" ? new Date() : new Date(EFFECT_DATE); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.profileChangeNameRepo.save(await changeName); + } + } + return new HttpSuccess(); + } + + /** + * @summary เปลี่ยนชื่อ ลูกจ้างประจำ + */ + @Post("uploadProfileChangeName-Employee") + async UploadFileSQLChangeNameEmp(@Request() request: { user: Record }) { + let rowCount = 0; + let _null: any = null; + + const [profiles, total] = await AppDataSource.getRepository(ProfileEmployee) + .createQueryBuilder("profile") + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + .getManyAndCount(); + + for (const _item of profiles) { + const existingProfile = await this.HR_CHANGENAME_EMPRepo.find({ + where: { CIT: _item.citizenId }, + // order: { SEQ: "ASC" }, + }); + + for (const item of existingProfile) { + let EFFECT_DATE = ""; + if (item.EFFECT_DATE) { + const [datePart] = item.EFFECT_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + EFFECT_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + } + rowCount++; + const changeName = new ProfileChangeName(); + changeName.profileEmployeeId = _item.id; + changeName.prefix = item.NEW_RANK_NAME == "" ? _item.prefix : item.NEW_RANK_NAME; + changeName.firstName = item.NEW_FNAME == "" ? _item.firstName : item.NEW_FNAME; + changeName.lastName = item.NEW_LNAME == "" ? _item.lastName : item.NEW_LNAME; + changeName.createdUserId = request.user.sub; + changeName.createdFullName = request.user.name; + changeName.lastUpdateUserId = request.user.sub; + changeName.lastUpdateFullName = request.user.name; + changeName.createdAt = EFFECT_DATE == "" ? new Date() : new Date(EFFECT_DATE); + changeName.lastUpdatedAt = EFFECT_DATE == "" ? new Date() : new Date(EFFECT_DATE); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.profileChangeNameRepo.save(await changeName); + } + } + return new HttpSuccess(); + } + + /** + * @summary บุตร ข้าราชการ + */ + @Post("uploadProfileChild-Officer") + async UploadFileSQLChild(@Request() request: { user: Record }) { + console.log(">>>>>>>>>>>>>>>>>>>"); + let rowCount = 0; + let _null: any = null; + + const [profiles, total] = await AppDataSource.getRepository(Profile) + .createQueryBuilder("profile") + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + .getManyAndCount(); + + for (const _item of profiles) { + const existingProfile = await this.HR_CHILDENRepo.find({ + where: { CIT: _item.citizenId }, + order: { SEQ: "ASC" }, + }); + + for (const item of existingProfile) { + rowCount++; + const child = new ProfileChildren(); + child.profileId = _item.id; + child.childrenPrefix = item.RANK_NAME; + child.childrenFirstName = item.CHILD_FNAME; + child.childrenLastName = item.CHILD_LNAME; + child.childrenLive = item.LIFE_STATUS == "2" ? false : true; + child.createdUserId = request.user.sub; + child.createdFullName = request.user.name; + child.lastUpdateUserId = request.user.sub; + child.lastUpdateFullName = request.user.name; + child.createdAt = new Date(); + child.lastUpdatedAt = new Date(); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.profileChildrenRepo.save(await child); + } + } + return new HttpSuccess(); + } + + /** + * @summary บุตร ลูกจ้างประจำ + */ + @Post("uploadProfileChild-Employee") + async UploadFileSQLChildEmp(@Request() request: { user: Record }) { + let rowCount = 0; + let _null: any = null; + + const [profiles, total] = await AppDataSource.getRepository(ProfileEmployee) + .createQueryBuilder("profile") + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + .getManyAndCount(); + + for (const _item of profiles) { + const existingProfile = await this.HR_CHILDEN_EMPRepo.find({ + where: { CIT: _item.citizenId }, + order: { SEQ: "ASC" }, + }); + + for (const item of existingProfile) { + rowCount++; + const child = new ProfileChildren(); + child.profileEmployeeId = _item.id; + child.childrenPrefix = item.RANK_NAME; + child.childrenFirstName = item.CHILD_FNAME; + child.childrenLastName = item.CHILD_LNAME; + child.childrenLive = item.LIFE_STATUS == "2" ? false : true; + child.createdUserId = request.user.sub; + child.createdFullName = request.user.name; + child.lastUpdateUserId = request.user.sub; + child.lastUpdateFullName = request.user.name; + child.createdAt = new Date(); + child.lastUpdatedAt = new Date(); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.profileChildrenRepo.save(await child); + } + } + return new HttpSuccess(); + } } diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index 48b8c4ac..f96630b4 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -872,7 +872,7 @@ export class KeycloakController extends Controller { if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server."); const result = await addUserRoles( userId, - list.filter((v) => v.id == "f8619dc2-dc0d-4aab-957f-66bdf905e9d0"), + list.filter((v) => v.id == "8a1a0dc9-304c-4e5b-a90a-65f841048212"), ); if (!result) { @@ -882,7 +882,7 @@ export class KeycloakController extends Controller { _item.keycloak = userId; } const roleKeycloak = await this.roleKeycloakRepo.find({ - where: { id: "f8619dc2-dc0d-4aab-957f-66bdf905e9d0" }, + where: { id: "8a1a0dc9-304c-4e5b-a90a-65f841048212" }, }); if (_item) { _item.roleKeycloaks = Array.from(new Set([..._item.roleKeycloaks, ...roleKeycloak])); diff --git a/src/entities/HR_CHANGENAME.ts b/src/entities/HR_CHANGENAME.ts new file mode 100644 index 00000000..c84d5fbc --- /dev/null +++ b/src/entities/HR_CHANGENAME.ts @@ -0,0 +1,62 @@ +import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; + +@Entity("HR_CHANGENAME") +export class HR_CHANGENAME { + @Column({ + nullable: true, + type: "text", + default: null, + }) + CIT: string; + @PrimaryGeneratedColumn() + id!: number; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + NEW_RANK_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + NEW_FNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + NEW_LNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + LAST_RANK_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + LAST_FNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + LAST_LNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + EFFECT_DATE: string; +} diff --git a/src/entities/HR_CHANGENAME_EMP.ts b/src/entities/HR_CHANGENAME_EMP.ts new file mode 100644 index 00000000..e6393a68 --- /dev/null +++ b/src/entities/HR_CHANGENAME_EMP.ts @@ -0,0 +1,62 @@ +import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; + +@Entity("HR_CHANGENAME_EMP") +export class HR_CHANGENAME_EMP { + @Column({ + nullable: true, + type: "text", + default: null, + }) + CIT: string; + @PrimaryGeneratedColumn() + id!: number; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + NEW_RANK_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + NEW_FNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + NEW_LNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + LAST_RANK_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + LAST_FNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + LAST_LNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + EFFECT_DATE: string; +} diff --git a/src/entities/HR_CHILDEN.ts b/src/entities/HR_CHILDEN.ts new file mode 100644 index 00000000..a27eca8e --- /dev/null +++ b/src/entities/HR_CHILDEN.ts @@ -0,0 +1,48 @@ +import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; + +@Entity("HR_CHILDEN") +export class HR_CHILDEN { + @Column({ + nullable: true, + type: "text", + default: null, + }) + CIT: string; + @PrimaryGeneratedColumn() + id!: number; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + RANK_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + CHILD_FNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + CHILD_LNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + LIFE_STATUS: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SEQ: string; +} diff --git a/src/entities/HR_CHILDEN_EMP.ts b/src/entities/HR_CHILDEN_EMP.ts new file mode 100644 index 00000000..986d7b60 --- /dev/null +++ b/src/entities/HR_CHILDEN_EMP.ts @@ -0,0 +1,48 @@ +import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; + +@Entity("HR_CHILDEN_EMP") +export class HR_CHILDEN_EMP { + @Column({ + nullable: true, + type: "text", + default: null, + }) + CIT: string; + @PrimaryGeneratedColumn() + id!: number; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + RANK_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + CHILD_FNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + CHILD_LNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + LIFE_STATUS: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SEQ: string; +} diff --git a/src/entities/HR_POSITION_EMPLOYEE.ts b/src/entities/HR_POSITION_EMPLOYEE.ts index 08eeced0..8c976d96 100644 --- a/src/entities/HR_POSITION_EMPLOYEE.ts +++ b/src/entities/HR_POSITION_EMPLOYEE.ts @@ -99,6 +99,20 @@ export class HR_POSITION_EMPLOYEE { }) WORK_LINE_NAME: string; + @Column({ + nullable: true, + type: "text", + default: null, + }) + LEVEL_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + WORK_LINE_NAME_F: string; + // @Column({ // nullable: true, // type: "text",