2024-10-18 11:33:04 +07:00
import { Controller , Post , Route , Security , Tags , Request , UploadedFile } from "tsoa" ;
2024-06-06 11:15:26 +07:00
import { AppDataSource } from "../database/data-source" ;
2025-03-17 15:42:48 +07:00
import { In , IsNull , LessThanOrEqual , Not } from "typeorm" ;
2024-06-06 11:15:26 +07:00
import HttpSuccess from "../interfaces/http-success" ;
import { UseInterceptors } from "@nestjs/common" ;
2024-06-10 17:11:54 +07:00
import { Profile } from "../entities/Profile" ;
2024-07-26 14:41:41 +07:00
import { ProfileEmployee } from "../entities/ProfileEmployee" ;
2024-06-10 17:11:54 +07:00
import { ProfileSalary } from "../entities/ProfileSalary" ;
import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple" ;
import { ProfileFamilyMother } from "../entities/ProfileFamilyMother" ;
import { ProfileFamilyFather } from "../entities/ProfileFamilyFather" ;
2024-07-26 14:41:41 +07:00
import { ProfileEducation } from "../entities/ProfileEducation" ;
2024-06-12 14:44:18 +07:00
import { PosLevel } from "../entities/PosLevel" ;
import { PosType } from "../entities/PosType" ;
2024-07-26 14:41:41 +07:00
import { FileInterceptor } from "@nestjs/platform-express" ;
import * as xlsx from "xlsx" ;
2024-07-25 16:20:48 +07:00
import Extension from "../interfaces/extension" ;
2024-10-18 11:33:04 +07:00
import { calculateRetireDate , calculateRetireLaw } from "../interfaces/utils" ;
2024-07-26 14:44:33 +07:00
import * as fs from "fs" ;
import * as path from "path" ;
const { createConnection } = require ( "typeorm" ) ;
import csvParser from "csv-parser" ;
import { HR_PERSONAL_OFFICER_FAMILY } from "../entities/HR_PERSONAL_OFFICER_FAMILY" ;
const BATCH_SIZE = 1000 ;
// import { EducationMis } from "../entities/EducationMis";
2024-07-25 16:20:48 +07:00
import { EducationMis } from "../entities/EducationMis" ;
2024-07-26 14:41:41 +07:00
import { ProvinceImport } from "../entities/ProvinceImport" ;
import { AmphurImport } from "../entities/AmphurImport" ;
import { SubDistrictImport } from "../entities/SubDistrictImport" ;
import { Province } from "../entities/Province" ;
import { District } from "../entities/District" ;
import { SubDistrict } from "../entities/SubDistrict" ;
2024-07-26 15:52:32 +07:00
import { HR_EDUCATION } from "../entities/HR_EDUCATION" ;
import { HR_PERSONAL_OFFICER_ADDRESS } from "../entities/HR_PERSONAL_OFFICER_ADDRESS" ;
import { HR_EDUCATION_EMP } from "../entities/HR_EDUCATION_EMP" ;
import { HR_PERSONAL_EMP_ADDRESS } from "../entities/HR_PERSONAL_EMP_ADDRESS" ;
import { HR_PERSONAL_EMP_FAMILY } from "../entities/HR_PERSONAL_EMP_FAMILY" ;
2025-01-31 17:35:56 +07:00
import { OrgRoot } from "../entities/OrgRoot" ;
import { OrgChild1 } from "../entities/OrgChild1" ;
import { OrgChild2 } from "../entities/OrgChild2" ;
import { OrgChild3 } from "../entities/OrgChild3" ;
import { OrgChild4 } from "../entities/OrgChild4" ;
import { IMPORT_ORG } from "../entities/IMPORT_ORG" ;
import { OrgRevision } from "../entities/OrgRevision" ;
2025-02-12 10:43:01 +07:00
import { OFFICER } from "../entities/OFFICER" ;
2025-02-14 09:58:51 +07:00
import { Position } from "../entities/Position" ;
import { PosMaster } from "../entities/PosMaster" ;
2025-02-21 19:10:27 +07:00
import { positionOfficer } from "../entities/positionOfficer" ;
2025-03-03 14:52:29 +07:00
import { PosExecutive } from "../entities/PosExecutive" ;
import { EducationLevel } from "../entities/EducationLevel" ;
import { HR_FUND_COURSE_CODE } from "../entities/HR_FUND_COURSE_CODE" ;
import { HR_MAJOR_CODE } from "../entities/HR_MAJOR_CODE" ;
2025-02-26 15:54:09 +07:00
// import { uuidv7 } from "uuidv7";
2025-03-04 15:29:08 +07:00
import { ProfileSalaries } from "../entities/ProfileSalaries" ;
2025-03-25 09:36:38 +07:00
import { HR_POSITION_OFFICER } from "../entities/HR_POSITION_OFFICER" ;
2024-06-06 11:20:37 +07:00
@Route ( "api/v1/org/upload" )
@Tags ( "UPLOAD" )
2024-06-06 11:15:26 +07:00
@Security ( "bearerAuth" )
export class ImportDataController extends Controller {
2025-01-06 23:58:24 +07:00
private profileEducationRepo = AppDataSource . getRepository ( ProfileEducation ) ;
2024-06-10 17:11:54 +07:00
private profileFamilyCoupleRepository = AppDataSource . getRepository ( ProfileFamilyCouple ) ;
private profileFamilyMotherRepository = AppDataSource . getRepository ( ProfileFamilyMother ) ;
private profileFamilyFatherRepository = AppDataSource . getRepository ( ProfileFamilyFather ) ;
2025-01-08 14:15:28 +07:00
private salaryRepo = AppDataSource . getRepository ( ProfileSalary ) ;
2024-06-10 17:11:54 +07:00
private profileRepo = AppDataSource . getRepository ( Profile ) ;
private profileEmpRepo = AppDataSource . getRepository ( ProfileEmployee ) ;
2024-06-12 14:44:18 +07:00
private posLevelRepo = AppDataSource . getRepository ( PosLevel ) ;
private posTypeRepo = AppDataSource . getRepository ( PosType ) ;
2025-02-21 19:10:27 +07:00
private positionOfficerRepo = AppDataSource . getRepository ( positionOfficer ) ;
2025-03-04 15:29:08 +07:00
private ProfileSalariesRepo = AppDataSource . getRepository ( ProfileSalaries ) ;
2024-07-26 14:44:33 +07:00
private HR_PERSONAL_OFFICER_FAMILYRepo = AppDataSource . getRepository ( HR_PERSONAL_OFFICER_FAMILY ) ;
2024-07-26 15:52:32 +07:00
private HR_EDUCATIONRepo = AppDataSource . getRepository ( HR_EDUCATION ) ;
private HR_PERSONAL_OFFICER_ADDRESSRepo = AppDataSource . getRepository (
HR_PERSONAL_OFFICER_ADDRESS ,
) ;
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 ) ;
2024-07-26 14:44:33 +07:00
2024-07-25 16:20:48 +07:00
private educationMisRepo = AppDataSource . getRepository ( EducationMis ) ;
2025-03-03 14:52:29 +07:00
private educationLevelRepo = AppDataSource . getRepository ( EducationLevel ) ;
private HR_MAJOR_CODERepo = AppDataSource . getRepository ( HR_MAJOR_CODE ) ;
private HR_FUND_COURSE_CODERepo = AppDataSource . getRepository ( HR_FUND_COURSE_CODE ) ;
2025-03-25 09:36:38 +07:00
private HR_POSITION_OFFICERRepo = AppDataSource . getRepository ( HR_POSITION_OFFICER ) ;
2024-07-26 14:41:41 +07:00
private provincsRepo = AppDataSource . getRepository ( ProvinceImport ) ;
private amphurRepo = AppDataSource . getRepository ( AmphurImport ) ;
private subDistrictRepo = AppDataSource . getRepository ( SubDistrictImport ) ;
private provinceIdRepo = AppDataSource . getRepository ( Province ) ;
private districtIdRepo = AppDataSource . getRepository ( District ) ;
private subDistrictIdRepo = AppDataSource . getRepository ( SubDistrict ) ;
2025-01-31 17:35:56 +07:00
private orgRevisionRepo = AppDataSource . getRepository ( OrgRevision ) ;
private orgRootRepo = AppDataSource . getRepository ( OrgRoot ) ;
private orgChild1Repo = AppDataSource . getRepository ( OrgChild1 ) ;
private orgChild2Repo = AppDataSource . getRepository ( OrgChild2 ) ;
private orgChild3Repo = AppDataSource . getRepository ( OrgChild3 ) ;
private orgChild4Repo = AppDataSource . getRepository ( OrgChild4 ) ;
private IMPORT_ORGRepo = AppDataSource . getRepository ( IMPORT_ORG ) ;
2025-02-12 10:43:01 +07:00
private OFFICERRepo = AppDataSource . getRepository ( OFFICER ) ;
2025-02-14 09:58:51 +07:00
private positionRepo = AppDataSource . getRepository ( Position ) ;
private posMasterRepo = AppDataSource . getRepository ( PosMaster ) ;
2025-03-03 14:52:29 +07:00
private posExecutiveRepo = AppDataSource . getRepository ( PosExecutive ) ;
2024-06-06 11:15:26 +07:00
/ * *
2024-07-25 16:20:48 +07:00
* @summary ท ะ เ บ ี ย น ป ร ะ ว ั ต ิ ข ้ า ร า ช ก า ร
2024-06-06 11:15:26 +07:00
* /
2024-07-25 16:20:48 +07:00
@Post ( "uploadProfile-Officer" )
2024-07-26 14:44:33 +07:00
async UploadFileSqlOfficer ( @Request ( ) request : { user : Record < string , any > } ) {
2025-02-12 10:43:01 +07:00
const OFFICER = await this . OFFICERRepo . find ( ) ;
2025-02-14 09:58:51 +07:00
// 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 = [];
2025-03-10 09:52:50 +07:00
let _null : any = null ;
2025-02-14 09:58:51 +07:00
let profile : any ;
// await Promise.all(
// OFFICER.map(async (item) => {
2025-02-12 10:43:01 +07:00
for await ( const item of OFFICER ) {
2025-02-14 09:58:51 +07:00
// readStream.map(async (item: any) => {
rowCount ++ ;
let type_ : any = null ;
let level_ : any = null ;
profile = null ;
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) {
// return;
// }
const existingProfile = await this . profileRepo . findOne ( {
2025-02-17 14:46:25 +07:00
where : { citizenId : item.id.toString ( ) } ,
2024-07-31 09:43:23 +07:00
} ) ;
2025-02-14 09:58:51 +07:00
if ( existingProfile ) {
profile . id = existingProfile . id ;
// continue;
2024-07-26 14:44:33 +07:00
}
2025-02-14 09:58:51 +07:00
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 ,
} ,
} ) ;
}
}
let dateRetire = new Date ( item . BORN ) ;
2025-02-17 14:46:25 +07:00
profile . citizenId = item . id . toString ( ) == "" ? "" : item . id . toString ( ) ;
2025-02-14 09:58:51 +07:00
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 ;
2025-03-10 09:52:50 +07:00
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 ) ;
2025-02-14 09:58:51 +07:00
profile . position = item . WORK_LINE_NAME == "" ? null : item . WORK_LINE_NAME ;
profile . posTypeId =
type_ != null && type_ . posTypeName == item . MP_CATEGORY && type_ ? type_.id : null ;
profile . posLevelId =
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,
// },
// },
// });
2025-03-10 09:52:50 +07:00
// profile.posLevelId = level?.id ?? _null;
2025-02-14 09:58:51 +07:00
// const type = await this.posTypeRepo.findOne({
// where: { posTypeName: item.MP_Type },
// });
2025-03-10 09:52:50 +07:00
// profile.posTypeId = type?.id ?? _null;
2025-03-03 14:52:29 +07:00
profile . amount = item . SALARY == "" ? 0 : Number ( item . SALARY ) ;
2025-02-14 09:58:51 +07:00
// 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 ) ;
// console.log(profile);
// profiles = await [];
// if (global.gc) {
// global.gc();
// }
// }
2024-07-26 14:44:33 +07:00
}
2025-02-14 09:58:51 +07:00
// }),
// );
// )
// );
// console.log(rowCount);
// await this.profileRepo.save(profiles);
2024-07-25 16:27:43 +07:00
return new HttpSuccess ( ) ;
2024-06-10 17:11:54 +07:00
}
2024-07-25 16:20:48 +07:00
/ * *
* @summary ท ะ เ บ ี ย น ป ร ะ ว ั ต ิ ล ู ก จ ้ า ง ป ร ะ จ ำ
* /
@Post ( "uploadProfile-Employee" )
2024-07-26 14:44:33 +07:00
async UploadFileSQL ( @Request ( ) request : { user : Record < string , any > } ) {
let users = [ ] ;
let rowCount = 0 ;
const filePath = path . resolve ( __dirname , "EMP.csv" ) ; // Corrected file path
const readStream = fs . createReadStream ( filePath ) . pipe ( csvParser ( ) ) ;
2024-06-10 17:11:54 +07:00
let profiles : any = [ ] ;
2025-03-10 09:52:50 +07:00
let _null : any = null ;
2025-02-14 09:58:51 +07:00
let profileEmp : any ;
2024-07-26 14:44:33 +07:00
for await ( const item of readStream ) {
rowCount ++ ;
2025-02-14 09:58:51 +07:00
profileEmp = null ;
profileEmp = new ProfileEmployee ( ) ;
2024-08-01 16:49:26 +07:00
// if (item["FLAG_RETIRE_STATUS"] != "" && item["FLAG_RETIRE_STATUS"] != null) {
// continue;
// }
2025-02-17 17:14:24 +07:00
// if (item["FLAG_PERSON_TYPE"] != "6") {
// continue;
// }
2025-02-14 09:58:51 +07:00
// if (new Date(item["RET_YEAR"]).getFullYear() >= 2567) {
// continue;
// }
2024-07-26 14:44:33 +07:00
const existingProfile = await this . profileEmpRepo . findOne ( {
where : { citizenId : item [ "ID" ] } ,
} ) ;
if ( existingProfile ) {
2024-09-18 19:18:16 +07:00
profileEmp . id = existingProfile . id ;
// continue;
2024-07-26 14:44:33 +07:00
}
2024-09-18 19:18:16 +07:00
let dateRetire = new Date ( item [ "MP_FORCE_DATE" ] ) ;
2024-07-26 14:59:34 +07:00
2024-07-26 14:44:33 +07:00
profileEmp . citizenId = item [ "ID" ] == "" ? "" : item [ "ID" ] ;
profileEmp . employeeClass =
item [ "FLAG_PERSON_TYPE" ] == "6" ? "PERM" : item [ "FLAG_PERSON_TYPE" ] == "7" ? "TEMP" : "" ;
2024-11-22 12:18:12 +07:00
profileEmp . rank =
item [ "RANK_NAME" ] == "" ||
item [ "RANK_NAME" ] == "นาย" ||
item [ "RANK_NAME" ] == "นาง" ||
item [ "RANK_NAME" ] == "นางสาว"
? null
: item [ "RANK_NAME" ] ;
2024-07-26 14:44:33 +07:00
profileEmp . prefix = item [ "RANK_NAME" ] == "" ? null : item [ "RANK_NAME" ] ;
2024-11-22 12:18:12 +07:00
profileEmp . prefixMain =
item [ "RANK_NAME" ] == "" ||
( item [ "RANK_NAME" ] != "นาย" && item [ "RANK_NAME" ] != "นาง" && item [ "RANK_NAME" ] != "นางสาว" )
? null
: item [ "RANK_NAME" ] ;
2024-07-26 14:44:33 +07:00
profileEmp . firstName = item [ "FNAME" ] == "" ? null : item [ "FNAME" ] ;
profileEmp . lastName = item [ "LNAME" ] == "" ? null : item [ "LNAME" ] ;
2025-03-10 09:52:50 +07:00
profileEmp . gender = item [ "SEX" ] == "1" ? "ชาย" : item [ "SEX" ] == "2" ? "หญิง" : _null ;
profileEmp . birthDate = item [ "BORN" ] == "" ? _null : new Date ( item [ "BORN" ] ) ;
2024-07-26 14:44:33 +07:00
profileEmp . dateAppoint =
2025-03-10 09:52:50 +07:00
item [ "BEGIN_ENTRY_DATE" ] == "" ? _null : new Date ( item [ "BEGIN_ENTRY_DATE" ] ) ;
profileEmp . dateStart = item [ "MP_FORCE_DATE" ] == "" ? _null : new Date ( item [ "MP_FORCE_DATE" ] ) ;
profileEmp . dateRetire = dateRetire == null ? _null : calculateRetireDate ( dateRetire ) ;
profileEmp . dateRetireLaw = dateRetire == null ? _null : calculateRetireLaw ( dateRetire ) ;
2024-07-26 14:44:33 +07:00
profileEmp . position = item [ "WORK_LINE_NAME" ] == "" ? null : item [ "WORK_LINE_NAME" ] ;
profileEmp . salaryLevel = item [ "SALARY_LEVEL_CODE" ] == "" ? null : item [ "SALARY_LEVEL_CODE" ] ;
profileEmp . relationship =
item [ "MARRIAGE_STATE" ] == "" ? "" : Extension . CheckRelationship ( item [ "MARRIAGE_STATE" ] ) ;
2025-02-14 09:58:51 +07:00
profileEmp . amount =
item [ "SALARY" ] == "" ? 0 : Number ( Extension . CheckRelationship ( item . SALARY ) ) ;
2024-07-26 14:44:33 +07:00
profileEmp . createdUserId = request . user . sub ;
profileEmp . createdFullName = request . user . name ;
profileEmp . lastUpdateUserId = request . user . sub ;
profileEmp . lastUpdateFullName = request . user . name ;
2024-08-30 21:02:14 +07:00
profileEmp . createdAt = new Date ( ) ;
profileEmp . lastUpdatedAt = new Date ( ) ;
2024-09-18 19:18:16 +07:00
// profiles.push(profileEmp);
2024-07-26 14:44:33 +07:00
console . log ( ">>>>>>>>>>>>>>>>>>>" + rowCount ) ;
2024-09-18 19:18:16 +07:00
// if (profiles.length === BATCH_SIZE) {
await this . profileEmpRepo . save ( profileEmp ) ;
// profiles = await [];
// if (global.gc) {
// global.gc();
// }
// }
2024-07-26 14:44:33 +07:00
}
2024-09-18 19:18:16 +07:00
// console.log(rowCount);
// await this.profileEmpRepo.save(profiles);
2024-07-25 16:27:43 +07:00
return new HttpSuccess ( ) ;
2024-06-10 17:11:54 +07:00
}
2024-07-25 16:20:48 +07:00
/ * *
* @summary เ ง ิ น เ ด ื อ น ข ้ า ร า ช ก า ร
* /
@Post ( "uploadProfileSalary-Officer" )
2024-07-26 14:44:33 +07:00
async UploadFileSQLSalary ( @Request ( ) request : { user : Record < string , any > } ) {
let rowCount = 0 ;
2025-03-10 09:52:50 +07:00
let _null : any = null ;
2025-02-24 11:04:17 +07:00
let sqlStatements : string [ ] = [ ] ;
2024-07-26 14:44:33 +07:00
2024-07-31 09:43:23 +07:00
const [ profiles , total ] = await AppDataSource . getRepository ( Profile )
2024-07-26 14:44:33 +07:00
. createQueryBuilder ( "profile" )
2024-07-31 09:43:23 +07:00
. select ( [ "profile.citizenId" , "profile.id" ] )
. orderBy ( "profile.citizenId" , "ASC" )
2025-02-24 11:04:17 +07:00
// .where("profile.citizenId = '3101702379675'")
2025-03-24 21:57:50 +07:00
// .where({
// citizenId: In([
// // "1100600109451",
// // "1209900075508",
// // "1739900231556",
// // "1809900305214",
// // "1920600228762",
// // "3101600963742",
// // "3102401171243",
// // "3120100454406",
// // "3180100306172",
// // "3700100094722",
// // "3809900116957",
// "3940900213929",
// ]),
// })
. skip ( 0 )
. take ( 10000 )
2024-07-26 14:44:33 +07:00
. getManyAndCount ( ) ;
2025-02-24 11:04:17 +07:00
var _profiles : ProfileSalary [ ] = [ ] ;
2025-02-26 15:45:45 +07:00
const filePath = path . join ( __dirname , "salaryProfile1.csv" ) ;
2025-02-24 11:04:17 +07:00
// CSV Header
2025-02-26 15:45:45 +07:00
let csvData = ` "id","createdAt","createdUserId","lastUpdatedAt","lastUpdateUserId","createdFullName","lastUpdateFullName","profileId","profileEmployeeId","order","commandNo","commandYear","commandDateSign","commandDateAffect","commandCode","commandName","posNoAbb","posNo","positionName","positionType","positionLevel","positionCee","orgRoot","orgChild1","orgChild2","orgChild3","orgChild4","positionExecutive","amount","amountSpecial","positionSalaryAmount","mouthSalaryAmount","remark","dateGovernment","isGovernment","commandId","refId" \ n ` ;
2024-07-26 14:44:33 +07:00
2025-02-24 11:04:17 +07:00
fs . appendFile ( filePath , csvData , ( err ) = > {
if ( err ) {
console . error ( "Error writing CSV file:" , err ) ;
} else {
console . log ( "Salary profiles successfully written to salaryProfile.csv" ) ;
}
} ) ;
2024-07-31 09:43:23 +07:00
await Promise . all (
profiles . map ( async ( _item ) = > {
2025-02-21 19:10:27 +07:00
const existingProfile = await this . positionOfficerRepo . find ( {
where : { citizenId : _item.citizenId , flag_person_type : "1" } ,
order : {
mp_pos_date : "ASC" ,
order_move_position : "ASC" ,
} ,
2024-07-31 09:43:23 +07:00
} ) ;
2025-02-24 11:04:17 +07:00
let order = 1 ;
2024-07-31 09:43:23 +07:00
await Promise . all (
existingProfile . map ( async ( item ) = > {
rowCount ++ ;
2025-02-21 19:10:27 +07:00
const profileSalary : any = new ProfileSalary ( ) ;
2024-07-31 09:43:23 +07:00
profileSalary . profileId = _item . id ;
2025-02-24 11:04:17 +07:00
profileSalary . order = order ;
order = order + 1 ;
2025-02-21 19:10:27 +07:00
profileSalary . commandNo = item . mp_command_num ;
2025-02-24 11:04:17 +07:00
profileSalary . commandYear = item . cur_year > 2500 ? item . cur_year - 543 : item.cur_year ;
2025-02-26 15:45:45 +07:00
profileSalary . commandDateSign =
item . mp_command_date == null
2025-03-10 09:52:50 +07:00
? _null
2025-02-26 15:45:45 +07:00
: new Date ( item . mp_command_date . setDate ( item . mp_command_date . getDate ( ) + 1 ) )
. toISOString ( )
. replace ( "T" , " " )
. substring ( 0 , 19 ) ;
profileSalary . commandDateAffect =
item . mp_pos_date == null
2025-03-10 09:52:50 +07:00
? _null
2025-02-26 15:45:45 +07:00
: new Date ( item . mp_pos_date . setDate ( item . mp_pos_date . getDate ( ) + 1 ) )
. toISOString ( )
. replace ( "T" , " " )
. substring ( 0 , 19 ) ;
2025-02-24 11:04:17 +07:00
if (
[
"0" ,
"11" ,
"22" ,
"31" ,
"39" ,
"45" ,
"46" ,
"47" ,
"49" ,
"50" ,
"51" ,
"60" ,
"61" ,
"62" ,
"99" ,
] . includes ( item . flag_to_name_code )
) {
profileSalary . commandCode = "0" ;
profileSalary . commandName = "อื่น ๆ" ;
} else if ( [ "1" , "58" ] . includes ( item . flag_to_name_code ) ) {
profileSalary . commandCode = "1" ;
profileSalary . commandName = "บรรจุและแต่งตั้งผู้สอบแข่งขันได้" ;
} else if ( [ "23" ] . includes ( item . flag_to_name_code ) ) {
profileSalary . commandCode = "2" ;
profileSalary . commandName = "บรรจุและแต่งตั้งผู้ได้รับคัดเลือก" ;
} else if ( [ "3" , "6" , "34" , "36" , "37" ] . includes ( item . flag_to_name_code ) ) {
profileSalary . commandCode = "3" ;
profileSalary . commandName = "แต่งตั้ง ย้าย" ;
2025-03-03 14:52:29 +07:00
} else if ( [ "10" , "55" , "56" ] . includes ( item . flag_to_name_code ) ) {
2025-02-24 11:04:17 +07:00
profileSalary . commandCode = "4" ;
profileSalary . commandName = "เลื่อน" ;
} else if ( [ "14" ] . includes ( item . flag_to_name_code ) ) {
profileSalary . commandCode = "5" ;
profileSalary . commandName = "เลื่อนเงินเดือนตามปกติ" ;
} else if (
[ "8" , "20" , "24" , "25" , "43" , "44" , "52" , "66" , "67" ] . includes ( item . flag_to_name_code )
) {
profileSalary . commandCode = "6" ;
profileSalary . commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ" ;
} else if ( [ "-" ] . includes ( item . flag_to_name_code ) ) {
profileSalary . commandCode = "7" ;
profileSalary . commandName = "เงินพิเศษอื่น ๆ" ;
} else if ( [ "38" , "40" , "53" , "54" ] . includes ( item . flag_to_name_code ) ) {
profileSalary . commandCode = "8" ;
profileSalary . commandName = "ปรับโครงสร้าง" ;
} else if ( [ "12" ] . includes ( item . flag_to_name_code ) ) {
profileSalary . commandCode = "9" ;
profileSalary . commandName = "พ้นทดลองปฏิบัติราชการ" ;
} else if ( [ "2" , "18" ] . includes ( item . flag_to_name_code ) ) {
profileSalary . commandCode = "10" ;
profileSalary . commandName = "บรรจุกลับ" ;
} else if ( [ "4" , "32" , "33" ] . includes ( item . flag_to_name_code ) ) {
profileSalary . commandCode = "11" ;
profileSalary . commandName = "รับโอน" ;
} else if ( [ "5" ] . includes ( item . flag_to_name_code ) ) {
profileSalary . commandCode = "12" ;
profileSalary . commandName = "ให้โอน" ;
} else if ( [ "15" , "95" ] . includes ( item . flag_to_name_code ) ) {
profileSalary . commandCode = "13" ;
profileSalary . commandName = "แก้ไขคำสั่ง" ;
} else if ( [ "19" ] . includes ( item . flag_to_name_code ) ) {
profileSalary . commandCode = "14" ;
profileSalary . commandName = "ยกเลิกคำสั่ง" ;
} else if ( [ "27" , "35" ] . includes ( item . flag_to_name_code ) ) {
profileSalary . commandCode = "15" ;
profileSalary . commandName = "ลาออกจากราชการ" ;
} else if (
[ "13" , "17" , "21" , "28" , "29" , "30" , "59" ] . includes ( item . flag_to_name_code )
) {
profileSalary . commandCode = "16" ;
profileSalary . commandName = "พ้นจากราชการ" ;
} else if ( [ "7" , "9" , "16" , "26" , "63" , "68" ] . includes ( item . flag_to_name_code ) ) {
profileSalary . commandCode = "17" ;
profileSalary . commandName = "รักษาราชการ, ช่วยราชการ" ;
}
2025-03-03 14:52:29 +07:00
if ( item . flag_to_name_code == null && item . flag_to_name == "ลาศึกษาต่อ" ) {
profileSalary . commandCode = "0" ;
profileSalary . commandName = "อื่น ๆ" ;
} else if (
2025-02-26 15:45:45 +07:00
item . flag_to_name_code == null &&
( item . flag_to_name == "เลื่อน 1 ขั้นและเลื่อนระดับ" ||
2025-03-03 14:52:29 +07:00
item . flag_to_name == "เลื่อน 0.5 ขั้นและเลื่อนระดับ" )
2025-02-24 11:04:17 +07:00
) {
2025-03-03 14:52:29 +07:00
profileSalary . commandCode = "4" ;
profileSalary . commandName = "เลื่อน" ;
2025-02-26 15:45:45 +07:00
} else if ( item . flag_to_name_code == null && item . flag_to_name == "เลื่อนเงินเดือน" ) {
2025-02-24 11:04:17 +07:00
profileSalary . commandCode = "5" ;
profileSalary . commandName = "เลื่อนเงินเดือนตามปกติ" ;
} else if (
2025-02-26 15:45:45 +07:00
item . flag_to_name_code == null &&
( item . flag_to_name == "ปรับตามบัญชีเงินเดือนใหม่" ||
item . flag_to_name == "เลื่อนเงินเดือน" ||
item . flag_to_name == "ปรับเงินเดือนตาม กพ." )
2025-02-24 11:04:17 +07:00
) {
profileSalary . commandCode = "6" ;
profileSalary . commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ" ;
} else if (
2025-02-26 15:45:45 +07:00
item . flag_to_name_code == null &&
item . flag_to_name == "แต่งตั้งตามการปรับปรุงโครงฯ"
2025-02-24 11:04:17 +07:00
) {
profileSalary . commandCode = "8" ;
profileSalary . commandName = "ปรับโครงสร้าง" ;
} else if (
2025-02-26 15:45:45 +07:00
item . flag_to_name_code == null &&
item . flag_to_name == "พ้นทดลองปฏิบัติราชการ"
2025-02-24 11:04:17 +07:00
) {
profileSalary . commandCode = "9" ;
profileSalary . commandName = "พ้นทดลองปฏิบัติราชการ" ;
2025-02-26 15:45:45 +07:00
} else if ( item . flag_to_name_code == null && item . flag_to_name == "ให้โอนมา" ) {
2025-02-24 11:04:17 +07:00
profileSalary . commandCode = "11" ;
profileSalary . commandName = "รับโอน" ;
} else if (
2025-02-26 15:45:45 +07:00
item . flag_to_name_code == null &&
item . flag_to_name == "โอนไปปฏิบัติราชการที่อื่น"
2025-02-24 11:04:17 +07:00
) {
profileSalary . commandCode = "12" ;
profileSalary . commandName = "ให้โอน" ;
2025-02-26 15:45:45 +07:00
} else if ( item . flag_to_name_code == null && item . flag_to_name == "ยกเลิกคำสั่ง" ) {
2025-02-24 11:04:17 +07:00
profileSalary . commandCode = "14" ;
profileSalary . commandName = "ยกเลิกคำสั่ง" ;
2025-02-26 15:45:45 +07:00
} else if ( item . flag_to_name_code == null && item . flag_to_name == "รักษาการในตำแหน่ง" ) {
2025-02-24 11:04:17 +07:00
profileSalary . commandCode = "17" ;
profileSalary . commandName = "รักษาราชการ, ช่วยราชการ" ;
}
2025-02-26 15:45:45 +07:00
if (
( profileSalary . commandCode == null || profileSalary . commandCode == undefined ) &&
( profileSalary . commandName == null || profileSalary . commandName == undefined )
) {
if (
[
"อื่นๆ" ,
"กลับไปปฏิบัติงานทางต้นสังกัด" ,
"เปลี่ยนประเภทข้าราชการ" ,
"โอนสับเปลี่ยน" ,
"เข้ารับฝึกอบรม" ,
"ดูงาน" ,
"ศึกษาต่อ" ,
"ขยายเวลาเข้ารับการฝึกอบรม" ,
"ขยายเวลาศึกษาต่อ" ,
"รายงานตัวกลับเข้าปฏิบัติราชการ" ,
"ไม่ได้เลื่อนขั้น" ,
"ตัดเงินเดือน" ,
"ลดขั้นเงินเดือน" ,
"ให้ข้าราชการกลับเข้ารับราชการ" ,
"ไม่ระบุ" ,
] . includes ( item . flag_to_name )
) {
profileSalary . commandCode = "0" ;
profileSalary . commandName = "อื่น ๆ" ;
} else if (
[
"บรรจุและแต่งตั้งผู้สอบแข่งขันได้" ,
"ทดลองปฎิบัติราชการ" ,
"ทดลองปฏิบัติราชการและปรับวุฒิ" ,
"บรรจุใหม่" ,
] . includes ( item . flag_to_name )
) {
profileSalary . commandCode = "1" ;
profileSalary . commandName = "บรรจุและแต่งตั้งผู้สอบแข่งขันได้" ;
} else if ( [ "บรรจุและแต่งตั้งผู้ได้รับการคัดเลือก" ] . includes ( item . flag_to_name ) ) {
profileSalary . commandCode = "2" ;
profileSalary . commandName = "บรรจุและแต่งตั้งผู้ได้รับคัดเลือก" ;
} else if (
[
"แต่งตั้ง (ย้ายสับเปลี่ยน)" ,
"แต่งตั้ง (ย้าย)" ,
"แต่งตั้ง" ,
"เปลี่ยนสายงาน" ,
"เปลี่ยนตำแหน่ง" ,
"ตัดโอนตำแหน่ง" ,
] . includes ( item . flag_to_name )
) {
profileSalary . commandCode = "3" ;
profileSalary . commandName = "แต่งตั้ง ย้าย" ;
2025-03-03 14:52:29 +07:00
} else if (
[ "เลื่อนและแต่งตั้ง" , "เลื่อนระดับ" , "เลื่อนเงินเดือนและระดับ" ] . includes (
item . flag_to_name ,
)
) {
2025-02-26 15:45:45 +07:00
profileSalary . commandCode = "4" ;
profileSalary . commandName = "เลื่อน" ;
} else if ( [ "เลื่อนขั้นเงินเดือน" , "เลื่อนเงินเดือน" ] . includes ( item . flag_to_name ) ) {
profileSalary . commandCode = "5" ;
profileSalary . commandName = "เลื่อนเงินเดือนตามปกติ" ;
} else if (
[
"ปรับเงินเดือนตามคุณวุฒิ" ,
"ได้รับเงินตอบแทนพิเศษ" ,
"เงินเพิ่มการครองชีพชั่วคราว" ,
"เลื่อนขั้นเงินเดือนกรณีพิเศษ" ,
"ปรับอัตราเงินเดือนตามบัญชีอัตราเงินเดือนใหม่ ท้าย พ.ร.บ. เงินเดือนและเงินประจำตำ" ,
"ปรับอัตราเงินเดือนตามพระราชกฤษฎีกา การปรับอัตราเงินเดือนของข้าราชการ" ,
"เลื่อนขั้นเงินเดือน (เพิ่มเติม)" ,
"ปรับอัตราเงินเดือน" ,
"ให้ข้าราชการได้รับเงินเดือนตามคุณวุฒิ" ,
] . includes ( item . flag_to_name )
) {
profileSalary . commandCode = "6" ;
profileSalary . commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ" ;
} else if ( [ "--" ] . includes ( item . flag_to_name ) ) {
profileSalary . commandCode = "7" ;
profileSalary . commandName = "เงินพิเศษอื่น ๆ" ;
} else if (
[ "ปรับโครงสร้าง" , "แต่งตั้ง (จัดคนลงกรอบ)" , "แต่งตั้งตามแผนอัตรากำลังฯ" ] . includes (
item . flag_to_name ,
)
) {
profileSalary . commandCode = "8" ;
profileSalary . commandName = "ปรับโครงสร้าง" ;
} else if ( [ "พ้นทดลองปฏิบัติราชการ" ] . includes ( item . flag_to_name ) ) {
profileSalary . commandCode = "9" ;
profileSalary . commandName = "พ้นทดลองปฏิบัติราชการ" ;
} else if (
[
"บรรจุกลับ" ,
"บรรจุกลับข้าราชการ" ,
"บรรจุและแต่งตั้งผู้ไปรับราชการทหารกลับเข้ารับราชการ" ,
] . includes ( item . flag_to_name )
) {
profileSalary . commandCode = "10" ;
profileSalary . commandName = "บรรจุกลับ" ;
} else if (
[
"รับโอนข้าราชการตามกฎหมายอื่น" ,
"รับโอนข้าราชการตามกฎหมายอื่น ผู้สอบแข่งขันได้" ,
"รับโอนข้าราชการตามกฏหมายอื่น โดยการคัดเลือก" ,
] . includes ( item . flag_to_name )
) {
profileSalary . commandCode = "11" ;
profileSalary . commandName = "รับโอน" ;
} else if ( [ "ให้โอน" ] . includes ( item . flag_to_name ) ) {
profileSalary . commandCode = "12" ;
profileSalary . commandName = "ให้โอน" ;
} else if ( [ "แก้ไขคำสั่ง" ] . includes ( item . flag_to_name ) ) {
profileSalary . commandCode = "13" ;
profileSalary . commandName = "แก้ไขคำสั่ง" ;
} else if ( [ "ยกเลิกคำสั่ง" ] . includes ( item . flag_to_name ) ) {
profileSalary . commandCode = "14" ;
profileSalary . commandName = "ยกเลิกคำสั่ง" ;
} else if (
[
"ลาออกจากราชการ" ,
"พ้นจากราชการ/ลาออกจากราชการตามมาตรการพัฒนาและบริหารกำลังคน" ,
] . includes ( item . flag_to_name )
) {
profileSalary . commandCode = "15" ;
profileSalary . commandName = "ลาออกจากราชการ" ;
} else if (
[
"พ้นจากราชการ/เพื่อไปปฏิบัติราชการทหาร" ,
"เกษียณ" ,
"ไม่พ้นทดลองปฏิบัติราชการ" ,
"พ้นจากราชการ/ให้ออก" ,
"พ้นจากราชการ/ไล่ออก" ,
"พ้นจากราชการ/เสียชีวิต" ,
"พ้นจากราชการ/ปลดออก" ,
] . includes ( item . flag_to_name )
) {
profileSalary . commandCode = "16" ;
profileSalary . commandName = "พ้นจากราชการ" ;
} else if (
[
"แต่งตั้งข้าราชการรักษาราชการแทน" ,
"ช่วยราชการ" ,
"รักษาการ" ,
"รักษาราชการแทน" ,
"มอบหมายให้ปฏิบัติหน้าที่" ,
"มอบหมายข้าราชการปฏิบัติหน้าที่แทน" ,
] . includes ( item . flag_to_name )
) {
profileSalary . commandCode = "17" ;
profileSalary . commandName = "รักษาราชการ, ช่วยราชการ" ;
} else {
profileSalary . commandCode = "0" ;
profileSalary . commandName = item . flag_to_name ;
}
}
2025-02-21 19:10:27 +07:00
profileSalary . posNoAbb = item . pos_num_name ;
profileSalary . posNo = item . pos_num_code ;
profileSalary . positionName = item . work_line_name ;
var positionType = "" ;
var positionLevel = "" ;
if ( item . mp_cee == "21" ) {
positionType = "ทั่วไป" ;
positionLevel = "ปฏิบัติงาน" ;
} else if ( item . mp_cee == "22" ) {
positionType = "ทั่วไป" ;
positionLevel = "ชำนาญงาน" ;
} else if ( item . mp_cee == "23" ) {
positionType = "ทั่วไป" ;
positionLevel = "อาวุโส" ;
} else if ( item . mp_cee == "24" ) {
positionType = "ทั่วไป" ;
positionLevel = "อาวุโสเฉพาะสายงานที่กำหนด" ;
} else if ( item . mp_cee == "25" ) {
positionType = "ทั่วไป" ;
positionLevel = "ทักษะพิเศษ" ;
} else if ( item . mp_cee == "26" ) {
positionType = "วิชาการ" ;
positionLevel = "ปฏิบัติการ" ;
} else if ( item . mp_cee == "27" ) {
positionType = "วิชาการ" ;
positionLevel = "ชำนาญการ" ;
} else if ( item . mp_cee == "28" ) {
positionType = "วิชาการ" ;
positionLevel = "ชำนาญการพิเศษ" ;
} else if ( item . mp_cee == "29" ) {
positionType = "วิชาการ" ;
positionLevel = "เชี่ยวชาญ" ;
} else if ( item . mp_cee == "30" ) {
positionType = "วิชาการ" ;
positionLevel = "ทรงคุณวุฒิ" ;
} else if ( item . mp_cee == "31" ) {
positionType = "วิชาการ" ;
positionLevel = "ทรงคุณวุฒิเฉพาะสายงานที่กำหนด" ;
} else if ( item . mp_cee == "32" ) {
positionType = "อำนวยการ" ;
positionLevel = "ต้น" ;
} else if ( item . mp_cee == "33" ) {
positionType = "อำนวยการ" ;
positionLevel = "สูง" ;
} else if ( item . mp_cee == "34" ) {
positionType = "บริหาร" ;
positionLevel = "ต้น" ;
} else if ( item . mp_cee == "35" ) {
positionType = "บริหาร" ;
positionLevel = "สูง" ;
2025-02-24 11:04:17 +07:00
} else {
profileSalary . positionCee = item . mp_cee ;
2025-02-21 11:49:04 +07:00
}
2025-02-24 11:04:17 +07:00
profileSalary . positionType = positionType ;
profileSalary . positionLevel = positionLevel ;
2025-02-21 19:10:27 +07:00
profileSalary . orgRoot = item . department_name ;
profileSalary . orgChild1 = item . division_name ;
profileSalary . orgChild2 = item . section_name ;
profileSalary . orgChild3 = item . job_name ;
if ( item . department_code == "50" ) {
profileSalary . orgRoot = item . division_name ;
profileSalary . orgChild1 = item . section_name ;
profileSalary . orgChild2 = item . job_name ;
}
profileSalary . positionExecutive = item . admin_name ;
profileSalary . amount = item . salary ;
profileSalary . remark = item . remark ;
2025-02-26 15:45:45 +07:00
profileSalary . refId = item . id ;
profileSalary . isEntry = false ;
2025-02-21 19:10:27 +07:00
const sal_pos_amount_1 : any =
item . sal_pos_amount_1 == null || item . sal_pos_amount_1 == ""
2025-03-10 09:52:50 +07:00
? _null
2025-02-21 19:10:27 +07:00
: Number ( item . sal_pos_amount_1 ) ;
const sal_pos_amount_2 : any =
item . sal_pos_amount_2 == null || item . sal_pos_amount_2 == ""
2025-03-10 09:52:50 +07:00
? _null
2025-02-21 19:10:27 +07:00
: Number ( item . sal_pos_amount_2 ) ;
profileSalary . positionSalaryAmount = sal_pos_amount_1 ? ? sal_pos_amount_2 ;
const special_amt : any =
2025-03-10 09:52:50 +07:00
item . special_amt == null || item . special_amt == "" ? _null : Number ( item . special_amt ) ;
2025-02-21 19:10:27 +07:00
profileSalary . amountSpecial = special_amt ;
2024-07-31 09:43:23 +07:00
profileSalary . createdUserId = request . user . sub ;
profileSalary . createdFullName = request . user . name ;
profileSalary . lastUpdateUserId = request . user . sub ;
profileSalary . lastUpdateFullName = request . user . name ;
2025-02-26 15:45:45 +07:00
profileSalary . createdAt = new Date ( ) . toISOString ( ) . split ( "T" ) [ 0 ] ;
profileSalary . lastUpdatedAt = new Date ( ) . toISOString ( ) . split ( "T" ) [ 0 ] ;
2025-02-26 15:54:09 +07:00
// const result = uuidv7();
// profileSalary.id = result;
2025-02-24 11:04:17 +07:00
// console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
// // Generate SQL INSERT Statement using TypeORM QueryBuilder but don't execute it
// const queryBuilder = AppDataSource.createQueryBuilder()
// .insert()
// .into(ProfileSalary)
// .values(profileSalary);
// const sql = queryBuilder.getSql();
// sqlStatements.push(sql);
// _profiles.push(profileSalary);
2025-02-21 19:10:27 +07:00
// save to file
2025-02-24 11:04:17 +07:00
// Define the output file path
// CSV Header
// let csvData = `"id","createdAt","createdUserId","lastUpdatedAt","lastUpdateUserId","createdFullName","lastUpdateFullName","profileId","profileEmployeeId","order","commandNo","commandYear","commandDateSign","commandDateAffect","commandCode","commandName","posNoAbb","posNo","positionName","positionType","positionLevel","positionCee","orgRoot","orgChild1","orgChild2","orgChild3","orgChild4","positionExecutive","amount","amountSpecial","positionSalaryAmount","mouthSalaryAmount","remark","dateGovernment","isGovernment","commandId"\n`;
// Loop through each salary profile and format data as CSV
// _profiles.forEach((profile) => {
2025-02-26 15:45:45 +07:00
console . log ( profileSalary . commandDateSign ) ;
csvData = ` " ${ profileSalary . id || "NULL" } "," ${ profileSalary . createdAt || "NULL" } "," ${ profileSalary . createdUserId || "NULL" } "," ${ profileSalary . lastUpdatedAt || "NULL" } "," ${ profileSalary . lastUpdateUserId || "NULL" } "," ${ profileSalary . createdFullName || "NULL" } "," ${ profileSalary . lastUpdateFullName || "NULL" } "," ${ profileSalary . profileId || "NULL" } "," ${ profileSalary . profileEmployeeId || "NULL" } "," ${ profileSalary . order || "NULL" } "," ${ profileSalary . commandNo || "NULL" } "," ${ profileSalary . commandYear || "NULL" } "," ${ profileSalary . commandDateSign || "NULL" } "," ${ profileSalary . commandDateAffect || "NULL" } "," ${ profileSalary . commandCode || "NULL" } "," ${ profileSalary . commandName || "NULL" } "," ${ profileSalary . posNoAbb || "NULL" } "," ${ profileSalary . posNo || "NULL" } "," ${ profileSalary . positionName || "NULL" } "," ${ profileSalary . positionType || "NULL" } "," ${ profileSalary . positionLevel || "NULL" } "," ${ profileSalary . positionCee || "NULL" } "," ${ profileSalary . orgRoot || "NULL" } "," ${ profileSalary . orgChild1 || "NULL" } "," ${ profileSalary . orgChild2 || "NULL" } "," ${ profileSalary . orgChild3 || "NULL" } "," ${ profileSalary . orgChild4 || "NULL" } "," ${ profileSalary . positionExecutive || "NULL" } "," ${ profileSalary . amount || 0 } "," ${ profileSalary . amountSpecial || 0 } "," ${ profileSalary . positionSalaryAmount || 0 } "," ${ profileSalary . mouthSalaryAmount || 0 } "," ${ profileSalary . remark || "NULL" } "," ${ profileSalary . dateGovernment || "NULL" } "," ${ profileSalary . isGovernment || "NULL" } "," ${ profileSalary . commandId || "NULL" } "," ${ profileSalary . refId || "NULL" } " \ n ` ;
2025-02-24 11:04:17 +07:00
// });
// Write the CSV data to the file
fs . appendFile ( filePath , csvData . replace ( '"NULL"' , "NULL" ) , ( err ) = > {
if ( err ) {
console . error ( "Error writing CSV file:" , err ) ;
} else {
console . log (
"Salary profiles successfully written to salaryProfile.csv: " + rowCount ,
) ;
}
} ) ;
2025-02-21 19:10:27 +07:00
// await this.salaryRepo.save(profileSalary);
2024-07-31 09:43:23 +07:00
} ) ,
) ;
2025-02-24 11:04:17 +07:00
order = 1 ;
2024-07-31 09:43:23 +07:00
} ) ,
) ;
2025-02-24 11:04:17 +07:00
// // console.log(rowCount);
// // Define the output file path
// const filePath = path.join(__dirname, "salaryProfile.csv");
// // CSV Header
// let csvData = `"id","createdAt","createdUserId","lastUpdatedAt","lastUpdateUserId","createdFullName","lastUpdateFullName","profileId","profileEmployeeId","order","commandNo","commandYear","commandDateSign","commandDateAffect","commandCode","commandName","posNoAbb","posNo","positionName","positionType","positionLevel","positionCee","orgRoot","orgChild1","orgChild2","orgChild3","orgChild4","positionExecutive","amount","amountSpecial","positionSalaryAmount","mouthSalaryAmount","remark","dateGovernment","isGovernment","commandId"\n`;
// // Loop through each salary profile and format data as CSV
// _profiles.forEach((profile) => {
// csvData += `"${profile.id || "NULL"}","${profile.createdAt?.toISOString()?.split("T")[0] || "NULL"}","${profile.createdUserId || "NULL"}","${profile.lastUpdatedAt?.toISOString()?.split("T")[0] || "NULL"}","${profile.lastUpdateUserId || "NULL"}","${profile.createdFullName || "NULL"}","${profile.lastUpdateFullName || "NULL"}","${profile.profileId || "NULL"}","${profile.profileEmployeeId || "NULL"}","${profile.order || "NULL"}","${profile.commandNo || "NULL"}","${profile.commandYear || "NULL"}","${profile.commandDateSign?.toISOString()?.split("T")[0] || "NULL"}","${profile.commandDateAffect?.toISOString()?.split("T")[0] || "NULL"}","${profile.commandCode || "NULL"}","${profile.commandName || "NULL"}","${profile.posNoAbb || "NULL"}","${profile.posNo || "NULL"}","${profile.positionName || "NULL"}","${profile.positionType || "NULL"}","${profile.positionLevel || "NULL"}","${profile.positionCee || "NULL"}","${profile.orgRoot || "NULL"}","${profile.orgChild1 || "NULL"}","${profile.orgChild2 || "NULL"}","${profile.orgChild3 || "NULL"}","${profile.orgChild4 || "NULL"}","${profile.positionExecutive || "NULL"}","${profile.amount || 0}","${profile.amountSpecial || 0}","${profile.positionSalaryAmount || 0}","${profile.mouthSalaryAmount || 0}","${profile.remark || "NULL"}","${profile.dateGovernment?.toISOString()?.split("T")[0] || "NULL"}","${profile.isGovernment || "NULL"}","${profile.commandId || "NULL"}"\n`;
// });
// // Write the CSV data to the file
// fs.writeFile(filePath, csvData, (err) => {
// if (err) {
// console.error("Error writing CSV file:", err);
// } else {
// console.log("Salary profiles successfully written to salaryProfile.csv");
// }
// });
2024-07-31 09:43:23 +07:00
return new HttpSuccess ( ) ;
2024-06-10 17:11:54 +07:00
}
2024-07-25 16:20:48 +07:00
/ * *
* @summary เ ง ิ น เ ด ื อ น ล ู ก จ ้ า ง ป ร ะ จ ำ
* /
@Post ( "uploadProfileSalary-Employee" )
2024-07-26 14:44:33 +07:00
async UploadFileSQLSalaryEmp ( @Request ( ) request : { user : Record < string , any > } ) {
let rowCount = 0 ;
2025-03-10 09:52:50 +07:00
let _null : any = null ;
2024-07-26 14:44:33 +07:00
2024-07-31 09:43:23 +07:00
const [ profiles , total ] = await AppDataSource . getRepository ( ProfileEmployee )
2024-07-26 14:44:33 +07:00
. createQueryBuilder ( "profile" )
2024-07-31 09:43:23 +07:00
. select ( [ "profile.citizenId" , "profile.id" ] )
. orderBy ( "profile.citizenId" , "ASC" )
2025-02-21 19:10:27 +07:00
. skip ( 0 )
. take ( 10000 )
2024-07-26 14:44:33 +07:00
. getManyAndCount ( ) ;
2024-07-31 09:43:23 +07:00
await Promise . all (
profiles . map ( async ( _item ) = > {
2025-02-21 19:10:27 +07:00
const existingProfile = await this . positionOfficerRepo . find ( {
where : { citizenId : _item.citizenId , flag_person_type : "7" } ,
2024-07-31 09:43:23 +07:00
} ) ;
await Promise . all (
existingProfile . map ( async ( item ) = > {
rowCount ++ ;
2025-02-21 19:10:27 +07:00
const profileSalary : any = new ProfileSalary ( ) ;
profileSalary . profileId = _item . id ;
profileSalary . order = item . order_move_position ; ///
profileSalary . commandNo = item . mp_command_num ;
profileSalary . commandYear = item . cur_year ;
profileSalary . commandDateSign = item . mp_command_date ;
profileSalary . commandDateAffect = item . mp_pos_date ;
profileSalary . commandCode = item . flag_to_name_code ;
profileSalary . commandName = item . flag_to_name ;
profileSalary . posNoAbb = item . pos_num_name ;
profileSalary . posNo = item . pos_num_code ;
profileSalary . positionName = item . work_line_name ;
profileSalary . positionCee = item . mp_cee ;
profileSalary . positionType = item . mp_cee ;
profileSalary . positionLevel = item . mp_cee ;
profileSalary . orgRoot = item . department_name ;
profileSalary . orgChild1 = item . division_name ;
profileSalary . orgChild2 = item . section_name ;
profileSalary . orgChild3 = item . job_name ;
if ( item . department_code == "50" ) {
profileSalary . orgRoot = item . division_name ;
profileSalary . orgChild1 = item . section_name ;
profileSalary . orgChild2 = item . job_name ;
}
profileSalary . positionExecutive = item . admin_name ;
profileSalary . amount = item . salary ;
profileSalary . remark = item . remark ;
const sal_pos_amount_1 : any =
item . sal_pos_amount_1 == null || item . sal_pos_amount_1 == ""
2025-03-10 09:52:50 +07:00
? _null
2025-02-21 19:10:27 +07:00
: Number ( item . sal_pos_amount_1 ) ;
const sal_pos_amount_2 : any =
item . sal_pos_amount_2 == null || item . sal_pos_amount_2 == ""
2025-03-10 09:52:50 +07:00
? _null
2025-02-21 19:10:27 +07:00
: Number ( item . sal_pos_amount_2 ) ;
profileSalary . positionSalaryAmount = sal_pos_amount_1 ? ? sal_pos_amount_2 ;
const special_amt : any =
2025-03-10 09:52:50 +07:00
item . special_amt == null || item . special_amt == "" ? _null : Number ( item . special_amt ) ;
2025-02-21 19:10:27 +07:00
profileSalary . amountSpecial = special_amt ;
profileSalary . commandId ;
2024-07-31 09:43:23 +07:00
profileSalary . createdUserId = request . user . sub ;
profileSalary . createdFullName = request . user . name ;
profileSalary . lastUpdateUserId = request . user . sub ;
profileSalary . lastUpdateFullName = request . user . name ;
2025-02-21 19:10:27 +07:00
profileSalary . createdAt = new Date ( ) ;
profileSalary . lastUpdatedAt = new Date ( ) ;
2024-07-31 09:43:23 +07:00
console . log ( ">>>>>>>>>>>>>>>>>>>" + rowCount ) ;
2025-02-21 19:10:27 +07:00
// save to file
// await this.salaryRepo.save(profileSalary);
2024-07-31 09:43:23 +07:00
} ) ,
) ;
} ) ,
) ;
console . log ( rowCount ) ;
2024-07-25 16:27:43 +07:00
return new HttpSuccess ( ) ;
2024-06-10 17:11:54 +07:00
}
2024-07-25 16:20:48 +07:00
/ * *
* @summary ค ร อ บ ค ร ั ว ข ้ า ร า ช ก า ร
* /
@Post ( "uploadProfileFamily-Officer" )
2024-07-26 14:44:33 +07:00
async UploadFileSQLFamily ( @Request ( ) request : { user : Record < string , any > } ) {
let rowCount = 0 ;
2024-07-25 16:20:48 +07:00
let fathers : any = [ ] ;
let mothers : any = [ ] ;
let couples : any = [ ] ;
2024-07-31 09:43:23 +07:00
const [ profiles , total ] = await AppDataSource . getRepository ( Profile )
2024-07-26 14:44:33 +07:00
. createQueryBuilder ( "profile" )
2024-07-31 09:43:23 +07:00
. select ( [ "profile.citizenId" , "profile.id" ] )
. orderBy ( "profile.citizenId" , "ASC" )
// .skip(0)
2025-02-12 10:43:01 +07:00
// .take(1000)
2024-07-26 14:44:33 +07:00
. getManyAndCount ( ) ;
2024-07-31 09:43:23 +07:00
// for (var i = 1; i <= total / BATCH_SIZE; i++) {
// const profiles = await AppDataSource.getRepository(Profile)
// .createQueryBuilder("profile")
// .select(["profile.citizenId", "profile.id"])
// .orderBy("profile.citizenId", "ASC")
// .skip((i - 1) * BATCH_SIZE)
// .take(BATCH_SIZE)
// .getMany();
2024-07-26 14:44:33 +07:00
2024-07-31 09:43:23 +07:00
await Promise . all (
profiles . map ( async ( _item ) = > {
const existingProfile = await this . HR_PERSONAL_OFFICER_FAMILYRepo . findOne ( {
where : { CIT : _item.citizenId } ,
select : [
"CIT" ,
"FATHER_RANK_NAME" ,
"FATHER_FNAME" ,
"FATHER_LNAME" ,
"MOTHER_RANK_NAME" ,
"MOTHER_FNAME" ,
"MOTHER_LNAME" ,
"SPOUSE_RANK_NAME" ,
"SPOUSE_FNAME" ,
"SPOUSE_LNAME" ,
"SPOUSE_ID" ,
"MARRIAGE_STATE" ,
] ,
} ) ;
if ( ! existingProfile ) {
return ;
}
rowCount ++ ;
const profileFather = new ProfileFamilyFather ( ) ;
const profileMother = new ProfileFamilyMother ( ) ;
const profileCouple = new ProfileFamilyCouple ( ) ;
profileFather . profileId = _item . id ;
profileFather . fatherPrefix = existingProfile . FATHER_RANK_NAME ;
profileFather . fatherFirstName = existingProfile . FATHER_FNAME ;
profileFather . fatherLastName = existingProfile . FATHER_LNAME ;
profileFather . createdUserId = request . user . sub ;
profileFather . createdFullName = request . user . name ;
profileFather . lastUpdateUserId = request . user . sub ;
profileFather . lastUpdateFullName = request . user . name ;
2024-08-30 21:02:14 +07:00
profileFather . createdAt = new Date ( ) ;
profileFather . lastUpdatedAt = new Date ( ) ;
2024-07-31 09:43:23 +07:00
profileMother . profileId = _item . id ;
profileMother . motherPrefix = existingProfile . MOTHER_RANK_NAME ;
profileMother . motherFirstName = existingProfile . MOTHER_FNAME ;
profileMother . motherLastName = existingProfile . MOTHER_LNAME ;
profileMother . createdUserId = request . user . sub ;
profileMother . createdFullName = request . user . name ;
profileMother . lastUpdateUserId = request . user . sub ;
profileMother . lastUpdateFullName = request . user . name ;
2024-08-30 21:02:14 +07:00
profileMother . createdAt = new Date ( ) ;
profileMother . lastUpdatedAt = new Date ( ) ;
2024-07-31 09:43:23 +07:00
profileCouple . profileId = _item . id ;
profileCouple . couplePrefix = existingProfile . SPOUSE_RANK_NAME ;
profileCouple . coupleFirstName = existingProfile . SPOUSE_FNAME ;
profileCouple . coupleLastName = existingProfile . SPOUSE_LNAME ;
profileCouple . coupleCitizenId = existingProfile . SPOUSE_ID ;
2024-08-05 20:58:44 +07:00
profileCouple . relationship =
existingProfile . MARRIAGE_STATE == "1"
? "โสด"
: existingProfile . MARRIAGE_STATE == "2"
? "สมรส"
: existingProfile . MARRIAGE_STATE == "3"
? "หย่าร้าง"
: existingProfile . MARRIAGE_STATE == "4"
? "หม้าย"
: "-" ;
2024-07-31 09:43:23 +07:00
// profileCouple.coupleLive = existingProfile.LIFE_SPOUSE;
profileCouple . createdUserId = request . user . sub ;
profileCouple . createdFullName = request . user . name ;
profileCouple . lastUpdateUserId = request . user . sub ;
profileCouple . lastUpdateFullName = request . user . name ;
2024-08-30 21:02:14 +07:00
profileCouple . createdAt = new Date ( ) ;
profileCouple . lastUpdatedAt = new Date ( ) ;
2024-07-31 09:43:23 +07:00
// fathers.push(profileFather);
// mothers.push(profileMother);
// couples.push(profileCouple);
console . log ( ">>>>>>>>>>>>>>>>>>>" + rowCount ) ;
// if (fathers.length === BATCH_SIZE) {
await this . profileFamilyFatherRepository . save ( profileFather ) ;
// fathers = await [];
// }
// if (mothers.length === BATCH_SIZE) {
await this . profileFamilyMotherRepository . save ( profileMother ) ;
// mothers = await [];
// }
// if (couples.length === BATCH_SIZE) {
await this . profileFamilyCoupleRepository . save ( profileCouple ) ;
// couples = await [];
// }
} ) ,
) ;
2024-07-26 14:44:33 +07:00
// }
2024-08-05 10:16:26 +07:00
// console.log(rowCount);
2024-07-25 16:20:48 +07:00
2024-07-31 09:43:23 +07:00
// await Promise.all([
// this.profileFamilyFatherRepository.save(fathers),
// this.profileFamilyMotherRepository.save(mothers),
// this.profileFamilyCoupleRepository.save(couples),
// ]);
2024-07-25 16:20:48 +07:00
2024-07-25 16:27:43 +07:00
return new HttpSuccess ( ) ;
2024-06-10 17:11:54 +07:00
}
2024-07-25 16:20:48 +07:00
/ * *
* @summary ค ร อ บ ค ร ั ว ล ู ก จ ้ า ง ป ร ะ จ ำ
* /
@Post ( "uploadProfileFamily-Employee" )
2024-07-26 14:44:33 +07:00
async UploadFileSQLFamilyEmp ( @Request ( ) request : { user : Record < string , any > } ) {
let rowCount = 0 ;
2024-07-25 16:20:48 +07:00
let fathers : any = [ ] ;
let mothers : any = [ ] ;
let couples : any = [ ] ;
2024-06-10 17:11:54 +07:00
2024-07-31 09:43:23 +07:00
const [ profiles , total ] = await AppDataSource . getRepository ( ProfileEmployee )
2024-07-26 14:44:33 +07:00
. createQueryBuilder ( "profile" )
2024-07-31 09:43:23 +07:00
. select ( [ "profile.citizenId" , "profile.id" ] )
. orderBy ( "profile.citizenId" , "ASC" )
// .skip(0)
// .take(20)
2024-07-26 14:44:33 +07:00
. getManyAndCount ( ) ;
2024-07-31 09:43:23 +07:00
// for (var i = 1; i <= total / BATCH_SIZE; i++) {
// const profiles = await AppDataSource.getRepository(ProfileEmployee)
// .createQueryBuilder("profile")
// .select(["profile.citizenId", "profile.id"])
// .orderBy("profile.citizenId", "ASC")
// .skip((i - 1) * BATCH_SIZE)
// .take(BATCH_SIZE)
// .getMany();
2024-07-26 14:44:33 +07:00
2024-07-31 09:43:23 +07:00
await Promise . all (
profiles . map ( async ( _item ) = > {
2024-08-01 16:49:26 +07:00
const existingProfile = await this . HR_PERSONAL_EMP_FAMILYRepo . findOne ( {
2024-07-31 09:43:23 +07:00
where : { CIT : _item.citizenId } ,
select : [
"CIT" ,
"FATHER_RANK_NAME" ,
"FATHER_FNAME" ,
"FATHER_LNAME" ,
"MOTHER_RANK_NAME" ,
"MOTHER_FNAME" ,
"MOTHER_LNAME" ,
"SPOUSE_RANK_NAME" ,
"SPOUSE_FNAME" ,
"SPOUSE_LNAME" ,
"SPOUSE_ID" ,
"MARRIAGE_STATE" ,
] ,
} ) ;
if ( ! existingProfile ) {
return ;
}
rowCount ++ ;
const profileFather = new ProfileFamilyFather ( ) ;
const profileMother = new ProfileFamilyMother ( ) ;
const profileCouple = new ProfileFamilyCouple ( ) ;
profileFather . profileEmployeeId = _item . id ;
profileFather . fatherPrefix = existingProfile . FATHER_RANK_NAME ;
profileFather . fatherFirstName = existingProfile . FATHER_FNAME ;
profileFather . fatherLastName = existingProfile . FATHER_LNAME ;
profileFather . createdUserId = request . user . sub ;
profileFather . createdFullName = request . user . name ;
profileFather . lastUpdateUserId = request . user . sub ;
profileFather . lastUpdateFullName = request . user . name ;
2024-08-30 21:02:14 +07:00
profileFather . createdAt = new Date ( ) ;
profileFather . lastUpdatedAt = new Date ( ) ;
2024-07-31 09:43:23 +07:00
profileMother . profileEmployeeId = _item . id ;
profileMother . motherPrefix = existingProfile . MOTHER_RANK_NAME ;
profileMother . motherFirstName = existingProfile . MOTHER_FNAME ;
profileMother . motherLastName = existingProfile . MOTHER_LNAME ;
profileMother . createdUserId = request . user . sub ;
profileMother . createdFullName = request . user . name ;
profileMother . lastUpdateUserId = request . user . sub ;
profileMother . lastUpdateFullName = request . user . name ;
2024-08-30 21:02:14 +07:00
profileMother . createdAt = new Date ( ) ;
profileMother . lastUpdatedAt = new Date ( ) ;
2024-07-31 09:43:23 +07:00
profileCouple . profileEmployeeId = _item . id ;
profileCouple . couplePrefix = existingProfile . SPOUSE_RANK_NAME ;
profileCouple . coupleFirstName = existingProfile . SPOUSE_FNAME ;
profileCouple . coupleLastName = existingProfile . SPOUSE_LNAME ;
profileCouple . coupleCitizenId = existingProfile . SPOUSE_ID ;
2024-08-05 20:58:44 +07:00
profileCouple . relationship =
existingProfile . MARRIAGE_STATE == "1"
? "โสด"
: existingProfile . MARRIAGE_STATE == "2"
? "สมรส"
: existingProfile . MARRIAGE_STATE == "3"
? "หย่าร้าง"
: existingProfile . MARRIAGE_STATE == "4"
? "หม้าย"
: "-" ;
2024-07-31 09:43:23 +07:00
// profileCouple.coupleLive = existingProfile.LIFE_SPOUSE;
profileCouple . createdUserId = request . user . sub ;
profileCouple . createdFullName = request . user . name ;
profileCouple . lastUpdateUserId = request . user . sub ;
profileCouple . lastUpdateFullName = request . user . name ;
2024-08-30 21:02:14 +07:00
profileCouple . createdAt = new Date ( ) ;
profileCouple . lastUpdatedAt = new Date ( ) ;
2024-07-31 09:43:23 +07:00
// fathers.push(profileFather);
// mothers.push(profileMother);
// couples.push(profileCouple);
console . log ( ">>>>>>>>>>>>>>>>>>>" + rowCount ) ;
// if (fathers.length === BATCH_SIZE) {
await this . profileFamilyFatherRepository . save ( profileFather ) ;
// fathers = await [];
// }
// if (mothers.length === BATCH_SIZE) {
await this . profileFamilyMotherRepository . save ( profileMother ) ;
// mothers = await [];
// }
// if (couples.length === BATCH_SIZE) {
await this . profileFamilyCoupleRepository . save ( profileCouple ) ;
// couples = await [];
// }
} ) ,
) ;
// }
2024-08-05 10:16:26 +07:00
// console.log(rowCount);
2024-07-25 16:20:48 +07:00
2024-07-31 09:43:23 +07:00
// await Promise.all([
// this.profileFamilyFatherRepository.save(fathers),
// this.profileFamilyMotherRepository.save(mothers),
// this.profileFamilyCoupleRepository.save(couples),
// ]);
2024-07-25 16:20:48 +07:00
2024-07-25 16:27:43 +07:00
return new HttpSuccess ( ) ;
2024-06-12 14:44:18 +07:00
}
2024-07-25 16:20:48 +07:00
2024-07-26 14:41:41 +07:00
/ * *
* @summary Import Education
* /
@Post ( "ImportEducation" )
@UseInterceptors ( FileInterceptor ( "file" ) )
async UploadFileSQLEducationCode (
@UploadedFile ( ) file : Express.Multer.File ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const workbook = xlsx . read ( file . buffer , { type : "buffer" } ) ;
2024-07-26 14:59:34 +07:00
const sheetName = workbook . SheetNames [ 0 ] ;
2024-07-26 14:41:41 +07:00
const sheet = workbook . Sheets [ sheetName ] ;
const getExcel = xlsx . utils . sheet_to_json ( sheet ) ;
let educationMis_ : any = [ ] ;
2024-07-26 14:59:34 +07:00
2024-07-26 14:41:41 +07:00
await Promise . all (
getExcel . map ( async ( item : any ) = > {
const educationMis = new EducationMis ( ) ;
educationMis . EDUCATION_CODE = item . EDUCATION_CODE ;
educationMis . EDUCATION_NAME = item . EDUCATION_NAME ;
educationMis . EDUCATION_ABB_NAME = item . EDUCATION_ABB_NAME ;
educationMis . createdUserId = request . user . sub ;
educationMis . createdFullName = request . user . name ;
educationMis . lastUpdateUserId = request . user . sub ;
2024-07-26 14:59:34 +07:00
educationMis . lastUpdateFullName = request . user . name ;
2024-08-30 21:02:14 +07:00
educationMis . createdAt = new Date ( ) ;
educationMis . lastUpdatedAt = new Date ( ) ;
2024-07-26 14:41:41 +07:00
educationMis_ . push ( educationMis ) ;
} ) ,
) ;
await this . educationMisRepo . save ( educationMis_ ) ;
return new HttpSuccess ( educationMis_ ) ;
}
/ * *
* @summary ป ร ะ ว ั ต ิ ก า ร ศ ึ ก ษ า ข ้ า ร า ช ก า ร
* /
@Post ( "uploadProfileEducation-Officer" )
2024-07-26 15:52:32 +07:00
async UploadFileSQLEducation ( @Request ( ) request : { user : Record < string , any > } ) {
let rowCount = 0 ;
2024-07-26 14:41:41 +07:00
let educations : any = [ ] ;
2025-03-10 09:52:50 +07:00
let _null : any = null ;
2024-07-31 09:43:23 +07:00
const [ profiles , total ] = await AppDataSource . getRepository ( Profile )
2024-07-26 15:52:32 +07:00
. createQueryBuilder ( "profile" )
2024-07-31 09:43:23 +07:00
. select ( [ "profile.citizenId" , "profile.id" ] )
. orderBy ( "profile.citizenId" , "ASC" )
// .skip(0)
// .take(20)
2024-07-26 15:52:32 +07:00
. getManyAndCount ( ) ;
2024-07-31 09:43:23 +07:00
// for (var i = 1; i <= 2; i++) {
// const profiles = await AppDataSource.getRepository(Profile)
// .createQueryBuilder("profile")
// .select(["profile.citizenId", "profile.id"])
// .orderBy("profile.citizenId", "ASC")
// .skip((i - 1) * 5)
// .take(5)
// .getMany();
2024-07-26 15:52:32 +07:00
2025-03-03 14:52:29 +07:00
for ( const _item of profiles ) {
const existingProfile = await this . HR_EDUCATIONRepo . find ( {
where : { CIT : _item.citizenId } ,
2025-03-11 10:03:55 +07:00
// select: [
// "CIT",
// "EDUCATION_CODE",
// "START_EDUCATION_YEAR",
// "EDUCATION_YEAR",
// "INSTITUE",
// "EDUCATION_SEQ",
// ],
order : { EDUCATION_SEQ : "ASC" } ,
2025-03-03 14:52:29 +07:00
} ) ;
2024-07-31 09:43:23 +07:00
2025-03-03 14:52:29 +07:00
const educationLevel = await this . profileEducationRepo . findOne ( {
select : [ "id" , "level" , "profileId" ] ,
where : { profileId : _item.id } ,
order : { level : "DESC" } ,
} ) ;
2024-07-31 09:43:23 +07:00
2025-03-03 14:52:29 +07:00
// educations = await [];
for ( const item of existingProfile ) {
rowCount ++ ;
const education = new ProfileEducation ( ) ;
const educationCode = await this . educationMisRepo . findOne ( {
where : { EDUCATION_CODE : item.EDUCATION_CODE } ,
} ) ;
const hrMajorCode = await this . HR_MAJOR_CODERepo . findOne ( {
where : { MAJOR_CODE : item.MAJOR_CODE } ,
} ) ;
const hrFundCourseCode = await this . HR_FUND_COURSE_CODERepo . findOne ( {
where : { FUND_COURSE_CODE : item.FUND_COURSE_CODE } ,
} ) ;
2024-07-31 09:43:23 +07:00
2025-03-03 14:52:29 +07:00
let startDate = item . START_EDUCATION_YEAR
? Extension . ConvertToDateTimeV2 ( item . START_EDUCATION_YEAR )
2025-03-10 09:52:50 +07:00
: _null ;
// startDate = startDate ? new Date(startDate, 0, 1) : _null;
2025-03-03 14:52:29 +07:00
let endDate = item . EDUCATION_YEAR
? Extension . ConvertToDateTimeV2 ( item . EDUCATION_YEAR )
2025-03-10 09:52:50 +07:00
: _null ;
// endDate = endDate ? new Date(endDate, 0, 1) : _null;
2025-03-11 10:03:55 +07:00
if ( item . FLAG_EDUCATION == "1" ) {
const checkData = await this . HR_EDUCATIONRepo . find ( {
where : { CIT : _item.citizenId , FLAG_EDUCATION : "1" } ,
order : { EDUCATION_SEQ : "DESC" } ,
} ) ;
if ( ( checkData . length > 1 && checkData [ 0 ] . id == item . id ) || checkData . length == 1 ) {
education . isEducation = true ;
const findIsHigh = await this . HR_EDUCATIONRepo . findOne ( {
where : { CIT : _item.citizenId , FLAG_EDUCATION : "3" } ,
} ) ;
if ( findIsHigh == null ) {
education . isHigh = true ;
}
}
} else if ( item . FLAG_EDUCATION == "2" ) {
} else if ( item . FLAG_EDUCATION == "3" ) {
const checkData = await this . HR_EDUCATIONRepo . find ( {
where : { CIT : _item.citizenId , FLAG_EDUCATION : "3" } ,
order : { EDUCATION_SEQ : "DESC" } ,
} ) ;
if ( ( checkData . length > 1 && checkData [ 0 ] . id == item . id ) || checkData . length == 1 ) {
education . isHigh = true ;
const findIsEducation = await this . HR_EDUCATIONRepo . findOne ( {
where : { CIT : _item.citizenId , FLAG_EDUCATION : "1" } ,
} ) ;
if ( findIsEducation == null ) {
education . isEducation = true ;
}
}
}
2025-03-03 14:52:29 +07:00
education . level = educationLevel == null ? 1 : educationLevel.level + 1 ;
education . profileId = _item . id ;
2025-03-10 09:52:50 +07:00
education . degree = educationCode ? educationCode.EDUCATION_NAME : _null ;
education . field = hrMajorCode ? hrMajorCode.MAJOR_NAME : _null ;
education . educationLevel = hrFundCourseCode ? hrFundCourseCode.FUND_COURSE_NAME : _null ;
education . educationLevelId = hrFundCourseCode ? hrFundCourseCode.refId : _null ;
2025-03-03 14:52:29 +07:00
education . institute = item . INSTITUE ;
2025-03-10 09:52:50 +07:00
education . level = item . EDUCATION_SEQ ? Number ( item . EDUCATION_SEQ ) : _null ;
2025-03-03 14:52:29 +07:00
education . startDate = startDate ;
education . endDate = endDate ;
education . createdUserId = request . user . sub ;
education . createdFullName = request . user . name ;
education . lastUpdateUserId = request . user . sub ;
education . lastUpdateFullName = request . user . name ;
education . createdAt = new Date ( ) ;
education . lastUpdatedAt = new Date ( ) ;
// await educations.push(await education);
console . log ( ">>>>>>>>>>>>>>>>>>>" + rowCount ) ;
await this . profileEducationRepo . save ( await education ) ;
}
// await this.profileEducationRepo.save(educations);
// educations = await [];
}
2024-07-31 09:43:23 +07:00
// }
2024-08-05 10:16:26 +07:00
// console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
2025-01-06 23:58:24 +07:00
// await this.profileEducationRepo.save(educations);
2024-07-26 14:41:41 +07:00
return new HttpSuccess ( ) ;
}
2024-07-26 14:59:34 +07:00
2024-07-26 14:41:41 +07:00
/ * *
* @summary ป ร ะ ว ั ต ิ ก า ร ศ ึ ก ษ า ล ู ก จ ้ า ง ป ร ะ จ ำ
* /
@Post ( "uploadProfileEducation-Employee" )
2024-07-26 15:52:32 +07:00
async UploadFileSQLEducationEmp ( @Request ( ) request : { user : Record < string , any > } ) {
let rowCount = 0 ;
2024-07-26 14:41:41 +07:00
let educations : any = [ ] ;
2025-03-10 09:52:50 +07:00
let _null : any = null ;
2024-07-31 09:43:23 +07:00
const [ profiles , total ] = await AppDataSource . getRepository ( ProfileEmployee )
2024-07-26 15:52:32 +07:00
. createQueryBuilder ( "profile" )
2024-07-31 09:43:23 +07:00
. select ( [ "profile.citizenId" , "profile.id" ] )
. orderBy ( "profile.citizenId" , "ASC" )
// .skip(0)
// .take(20)
2024-07-26 15:52:32 +07:00
. getManyAndCount ( ) ;
2024-07-31 09:43:23 +07:00
// for (var i = 1; i <= total / BATCH_SIZE; i++) {
// const profiles = await AppDataSource.getRepository(ProfileEmployee)
// .createQueryBuilder("profile")
// .select(["profile.citizenId", "profile.id"])
// .orderBy("profile.citizenId", "ASC")
// .skip((i - 1) * BATCH_SIZE)
// .take(BATCH_SIZE)
// .getMany();
2024-07-26 15:52:32 +07:00
2024-07-31 09:43:23 +07:00
await Promise . all (
profiles . map ( async ( _item ) = > {
const existingProfile = await this . HR_EDUCATION_EMPRepo . find ( {
where : { CIT : _item.citizenId } ,
2025-02-17 22:34:41 +07:00
select : [
"CIT" ,
"EDUCATION_CODE" ,
"START_EDUCATION_YEAR" ,
"EDUCATION_YEAR" ,
"INSTITUE" ,
"EDUCATION_SEQ" ,
] ,
2024-07-31 09:43:23 +07:00
} ) ;
2025-01-06 23:58:24 +07:00
const educationLevel = await this . profileEducationRepo . findOne ( {
select : [ "id" , "level" , "profileId" ] ,
where : { profileEmployeeId : _item.id } ,
order : { level : "DESC" } ,
} ) ;
2024-07-31 09:43:23 +07:00
educations = await [ ] ;
await Promise . all (
existingProfile . map ( async ( item ) = > {
rowCount ++ ;
const education = new ProfileEducation ( ) ;
const educationCode = await this . educationMisRepo . findOne ( {
where : { EDUCATION_CODE : item.EDUCATION_CODE } ,
} ) ;
let startDate = item . START_EDUCATION_YEAR
2024-08-05 20:58:44 +07:00
? Extension . ConvertToDateTimeV2 ( item . START_EDUCATION_YEAR )
2025-03-10 09:52:50 +07:00
: _null ;
// startDate = startDate ? new Date(startDate, 0, 1) : _null;
2024-07-31 09:43:23 +07:00
let endDate = item . EDUCATION_YEAR
2024-08-05 20:58:44 +07:00
? Extension . ConvertToDateTimeV2 ( item . EDUCATION_YEAR )
2025-03-10 09:52:50 +07:00
: _null ;
// endDate = endDate ? new Date(endDate, 0, 1) : _null;
2024-07-31 09:43:23 +07:00
2025-01-06 23:58:24 +07:00
education . level = educationLevel == null ? 1 : educationLevel.level + 1 ;
2024-07-31 09:43:23 +07:00
education . profileEmployeeId = _item . id ;
education . degree = educationCode ? educationCode . EDUCATION_NAME : "" ;
education . institute = item . INSTITUE ;
2025-03-10 09:52:50 +07:00
education . level = item . EDUCATION_SEQ ? _null : Number ( item . EDUCATION_SEQ ) ;
2024-07-31 09:43:23 +07:00
education . startDate = startDate ;
education . endDate = endDate ;
education . createdUserId = request . user . sub ;
education . createdFullName = request . user . name ;
education . lastUpdateUserId = request . user . sub ;
education . lastUpdateFullName = request . user . name ;
2024-08-30 21:02:14 +07:00
education . createdAt = new Date ( ) ;
education . lastUpdatedAt = new Date ( ) ;
2024-08-05 10:16:26 +07:00
// educations.push(education);
console . log ( ">>>>>>>>>>>>>>>>>>>" + rowCount ) ;
2025-01-06 23:58:24 +07:00
await this . profileEducationRepo . save ( education ) ;
2024-07-31 09:43:23 +07:00
} ) ,
) ;
2025-01-06 23:58:24 +07:00
// await this.profileEducationRepo.save(educations);
2024-07-31 09:43:23 +07:00
} ) ,
) ;
// }
2024-08-05 10:16:26 +07:00
// console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
2025-01-06 23:58:24 +07:00
// await this.profileEducationRepo.save(educations);
2024-07-26 14:41:41 +07:00
return new HttpSuccess ( ) ;
}
/ * *
* @summary Import Province
* /
@Post ( "ImportProvince" )
@UseInterceptors ( FileInterceptor ( "file" ) )
async ImportProvince (
@UploadedFile ( ) file : Express.Multer.File ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const workbook = xlsx . read ( file . buffer , { type : "buffer" } ) ;
2024-07-26 14:59:34 +07:00
const sheetName = workbook . SheetNames [ 0 ] ;
2024-07-26 14:41:41 +07:00
const sheet = workbook . Sheets [ sheetName ] ;
const getExcel = xlsx . utils . sheet_to_json ( sheet ) ;
let provinces_ : any = [ ] ;
await Promise . all (
getExcel . map ( async ( item : any ) = > {
const prov = new ProvinceImport ( ) ;
prov . PROVINCE_CODE = item . PROVINCE_CODE ;
prov . PROVINCE_NAME = item . PROVINCE_NAME ;
prov . createdUserId = request . user . sub ;
prov . createdFullName = request . user . name ;
prov . lastUpdateUserId = request . user . sub ;
2024-07-26 14:59:34 +07:00
prov . lastUpdateFullName = request . user . name ;
2024-08-30 21:02:14 +07:00
prov . createdAt = new Date ( ) ;
prov . lastUpdatedAt = new Date ( ) ;
2024-07-26 14:41:41 +07:00
provinces_ . push ( prov ) ;
} ) ,
) ;
await this . provincsRepo . save ( provinces_ ) ;
return new HttpSuccess ( provinces_ ) ;
}
/ * *
* @summary Import Amphur
* /
@Post ( "ImportAmphur" )
@UseInterceptors ( FileInterceptor ( "file" ) )
async ImportAmphur (
@UploadedFile ( ) file : Express.Multer.File ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const workbook = xlsx . read ( file . buffer , { type : "buffer" } ) ;
2024-07-26 14:59:34 +07:00
const sheetName = workbook . SheetNames [ 0 ] ;
2024-07-26 14:41:41 +07:00
const sheet = workbook . Sheets [ sheetName ] ;
const getExcel = xlsx . utils . sheet_to_json ( sheet ) ;
let amphur_ : any = [ ] ;
await Promise . all (
getExcel . map ( async ( item : any ) = > {
const amh = new AmphurImport ( ) ;
amh . PROVINCE_CODE = item . PROVINCE_CODE ;
amh . AMPHUR_CODE = item . AMPHUR_CODE ;
amh . AMPHUR_NAME = item . AMPHUR_NAME ;
amh . createdUserId = request . user . sub ;
amh . createdFullName = request . user . name ;
amh . lastUpdateUserId = request . user . sub ;
2024-07-26 14:59:34 +07:00
amh . lastUpdateFullName = request . user . name ;
2024-08-30 21:02:14 +07:00
amh . createdAt = new Date ( ) ;
amh . lastUpdatedAt = new Date ( ) ;
2024-07-26 14:41:41 +07:00
amphur_ . push ( amh ) ;
} ) ,
) ;
await this . amphurRepo . save ( amphur_ ) ;
return new HttpSuccess ( amphur_ ) ;
}
/ * *
* @summary Import SubDistrict
* /
@Post ( "ImportSubDistrict" )
@UseInterceptors ( FileInterceptor ( "file" ) )
async ImportSubDistrict (
@UploadedFile ( ) file : Express.Multer.File ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const workbook = xlsx . read ( file . buffer , { type : "buffer" } ) ;
2024-07-26 14:59:34 +07:00
const sheetName = workbook . SheetNames [ 0 ] ;
2024-07-26 14:41:41 +07:00
const sheet = workbook . Sheets [ sheetName ] ;
const getExcel = xlsx . utils . sheet_to_json ( sheet ) ;
let subDistrict_ : any = [ ] ;
await Promise . all (
getExcel . map ( async ( item : any ) = > {
const subD = new SubDistrictImport ( ) ;
subD . PROVINCE_CODE = item . PROVINCE_CODE ;
subD . AMPHUR_CODE = item . AMPHUR_CODE ;
subD . DISTRICT_CODE = item . DISTRICT_CODE ;
subD . DISTRICT_NAME = item . DISTRICT_NAME ;
subD . createdUserId = request . user . sub ;
subD . createdFullName = request . user . name ;
subD . lastUpdateUserId = request . user . sub ;
2024-07-26 14:59:34 +07:00
subD . lastUpdateFullName = request . user . name ;
2024-08-30 21:02:14 +07:00
subD . createdAt = new Date ( ) ;
subD . lastUpdatedAt = new Date ( ) ;
2024-07-26 14:41:41 +07:00
subDistrict_ . push ( subD ) ;
} ) ,
) ;
await this . subDistrictRepo . save ( subDistrict_ ) ;
return new HttpSuccess ( subDistrict_ ) ;
}
/ * *
* @summary ท ี ่ อ ย ู ่ ต า ม ท ะ เ บ ี ย น บ ้ า น - ป ั จ จ ุ บ ั น ข ้ า ร า ช ก า ร
* /
@Post ( "uploadProfileAddress-Officer" )
2024-07-26 15:52:32 +07:00
async UploadFileSQLAddress ( @Request ( ) request : { user : Record < string , any > } ) {
let rowCount = 0 ;
2025-03-10 09:52:50 +07:00
let _null : any = null ;
2024-07-31 09:43:23 +07:00
const [ profiles , total ] = await AppDataSource . getRepository ( Profile )
2024-07-26 15:52:32 +07:00
. createQueryBuilder ( "profile" )
2024-07-31 09:43:23 +07:00
. select ( [ "profile.citizenId" , "profile.id" ] )
. orderBy ( "profile.citizenId" , "ASC" )
// .skip(0)
// .take(20)
2024-07-26 15:52:32 +07:00
. getManyAndCount ( ) ;
2025-03-07 11:15:50 +07:00
const meta = {
createdUserId : request.user.sub ,
createdFullName : request.user.name ,
lastUpdateUserId : request.user.sub ,
lastUpdateFullName : request.user.name ,
createdAt : new Date ( ) ,
lastUpdatedAt : new Date ( ) ,
} ;
for ( const _item of profiles ) {
const existingProfile = await this . HR_PERSONAL_OFFICER_ADDRESSRepo . findOne ( {
where : { CIT : _item.citizenId } ,
} ) ;
2024-07-26 15:52:32 +07:00
2025-03-07 11:15:50 +07:00
if ( ! existingProfile ) {
continue ;
}
let PROVINCE_CODE = Number ( existingProfile . PROVINCE_CODE ) . toString ( ) ;
let DISTRICT_CODE = Number ( existingProfile . DISTRICT_CODE ) . toString ( ) ;
let AMPHUR_CODE = Number ( existingProfile . AMPHUR_CODE ) . toString ( ) ;
let CONTACT_PROVINCE_CODE = Number ( existingProfile . CONTACT_PROVINCE_CODE ) . toString ( ) ;
let CONTACT_DISTRICT_CODE = Number ( existingProfile . CONTACT_DISTRICT_CODE ) . toString ( ) ;
let CONTACT_AMPHUR_CODE = Number ( existingProfile . CONTACT_AMPHUR_CODE ) . toString ( ) ;
rowCount ++ ;
//registration address
if ( PROVINCE_CODE ) {
let provinceRegis_ = await this . provincsRepo . findOne ( {
where : { PROVINCE_CODE : PROVINCE_CODE } ,
} ) ;
if ( provinceRegis_ ) {
let provinceId = await this . provinceIdRepo . findOne ( {
2024-07-31 09:43:23 +07:00
where : {
2025-03-07 11:15:50 +07:00
name : provinceRegis_.PROVINCE_NAME ,
2024-07-31 09:43:23 +07:00
} ,
} ) ;
2025-03-07 11:15:50 +07:00
if ( provinceId == null ) {
provinceId = new Province ( ) ;
Object . assign ( provinceId , {
. . . meta ,
name : provinceRegis_.PROVINCE_NAME ,
2024-07-26 14:41:41 +07:00
} ) ;
2025-03-07 11:15:50 +07:00
await this . provinceIdRepo . save ( provinceId ) ;
2024-07-26 14:41:41 +07:00
}
2025-03-10 09:52:50 +07:00
_item . registrationProvinceId = provinceId ? provinceId.id : _null ;
2025-03-07 11:15:50 +07:00
if ( AMPHUR_CODE ) {
let districtRegis_ = await this . amphurRepo . findOne ( {
2024-07-31 09:43:23 +07:00
where : {
2025-03-07 11:15:50 +07:00
AMPHUR_CODE : AMPHUR_CODE ,
PROVINCE_CODE : provinceRegis_.PROVINCE_CODE ,
2024-07-31 09:43:23 +07:00
} ,
2024-07-26 14:41:41 +07:00
} ) ;
2025-03-07 11:15:50 +07:00
if ( districtRegis_ ) {
let districtId = await this . districtIdRepo . findOne ( {
where : {
name : districtRegis_.AMPHUR_NAME ,
} ,
} ) ;
if ( districtId == null ) {
districtId = new District ( ) ;
Object . assign ( districtId , {
. . . meta ,
name : districtRegis_.AMPHUR_NAME ,
provinceId : provinceId.id ,
} ) ;
await this . provinceIdRepo . save ( provinceId ) ;
}
2025-03-10 09:52:50 +07:00
_item . registrationDistrictId = districtId ? districtId.id : _null ;
2025-03-07 11:15:50 +07:00
if ( DISTRICT_CODE ) {
let subDistrictRegis_ = await this . subDistrictRepo . findOne ( {
where : {
DISTRICT_CODE : DISTRICT_CODE ,
AMPHUR_CODE : districtRegis_.AMPHUR_CODE ,
PROVINCE_CODE : provinceRegis_.PROVINCE_CODE ,
} ,
} ) ;
if ( subDistrictRegis_ ) {
let subDistrictId = await this . subDistrictIdRepo . findOne ( {
where : {
name : subDistrictRegis_.DISTRICT_NAME ,
} ,
} ) ;
if ( subDistrictId == null ) {
subDistrictId = new SubDistrict ( ) ;
Object . assign ( subDistrictId , {
. . . meta ,
name : subDistrictRegis_.DISTRICT_NAME ,
zipCode : existingProfile.ZIPCODE ,
districtId : districtId.id ,
} ) ;
await this . provinceIdRepo . save ( provinceId ) ;
}
2025-03-10 09:52:50 +07:00
_item . registrationSubDistrictId = subDistrictId ? subDistrictId.id : _null ;
2025-03-07 11:15:50 +07:00
}
}
}
2024-07-26 14:41:41 +07:00
}
2024-07-31 09:43:23 +07:00
}
2025-03-07 11:15:50 +07:00
}
//current address
if ( CONTACT_PROVINCE_CODE ) {
let provinceCurr_ = await this . provincsRepo . findOne ( {
where : { PROVINCE_CODE : CONTACT_PROVINCE_CODE } ,
} ) ;
if ( provinceCurr_ ) {
let provinceId = await this . provinceIdRepo . findOne ( {
2024-07-31 09:43:23 +07:00
where : {
2025-03-07 11:15:50 +07:00
name : provinceCurr_.PROVINCE_NAME ,
2024-07-31 09:43:23 +07:00
} ,
} ) ;
2025-03-07 11:15:50 +07:00
if ( provinceId == null ) {
provinceId = new Province ( ) ;
Object . assign ( provinceId , {
. . . meta ,
name : provinceCurr_.PROVINCE_NAME ,
2024-07-26 14:41:41 +07:00
} ) ;
2025-03-07 11:15:50 +07:00
await this . provinceIdRepo . save ( provinceId ) ;
2024-07-26 14:41:41 +07:00
}
2025-03-10 09:52:50 +07:00
_item . currentProvinceId = provinceId ? provinceId.id : _null ;
2025-03-07 11:15:50 +07:00
if ( CONTACT_AMPHUR_CODE ) {
let districtCurr_ = await this . amphurRepo . findOne ( {
2024-07-26 14:59:34 +07:00
where : {
2025-03-07 11:15:50 +07:00
AMPHUR_CODE : CONTACT_AMPHUR_CODE ,
PROVINCE_CODE : provinceCurr_.PROVINCE_CODE ,
2024-07-26 14:59:34 +07:00
} ,
2024-07-26 14:41:41 +07:00
} ) ;
2025-03-07 11:15:50 +07:00
if ( districtCurr_ ) {
let districtId = await this . districtIdRepo . findOne ( {
where : {
name : districtCurr_.AMPHUR_NAME ,
} ,
} ) ;
if ( districtId == null ) {
districtId = new District ( ) ;
Object . assign ( districtId , {
. . . meta ,
name : districtCurr_.AMPHUR_NAME ,
provinceId : provinceId.id ,
} ) ;
await this . provinceIdRepo . save ( provinceId ) ;
}
2025-03-10 09:52:50 +07:00
_item . currentDistrictId = districtId ? districtId.id : _null ;
2025-03-07 11:15:50 +07:00
if ( CONTACT_DISTRICT_CODE ) {
let subDistrictCurr_ = await this . subDistrictRepo . findOne ( {
where : {
DISTRICT_CODE : CONTACT_DISTRICT_CODE ,
AMPHUR_CODE : districtCurr_.AMPHUR_CODE ,
PROVINCE_CODE : provinceCurr_.PROVINCE_CODE ,
} ,
} ) ;
if ( subDistrictCurr_ ) {
let subDistrictId = await this . subDistrictIdRepo . findOne ( {
where : {
name : subDistrictCurr_.DISTRICT_NAME ,
} ,
} ) ;
if ( subDistrictId == null ) {
subDistrictId = new SubDistrict ( ) ;
Object . assign ( subDistrictId , {
. . . meta ,
name : subDistrictCurr_.DISTRICT_NAME ,
zipCode : existingProfile.CONTACT_ZIPCODE ,
districtId : districtId.id ,
} ) ;
await this . provinceIdRepo . save ( provinceId ) ;
}
2025-03-10 09:52:50 +07:00
_item . currentSubDistrictId = subDistrictId ? subDistrictId.id : _null ;
2025-03-07 11:15:50 +07:00
}
}
}
2024-07-26 14:41:41 +07:00
}
2024-07-31 09:43:23 +07:00
}
2025-03-07 11:15:50 +07:00
}
_item . registrationAddress = existingProfile . H_NUMBER ;
_item . registrationZipCode = existingProfile . ZIPCODE ;
_item . currentAddress = existingProfile . CONTACT_H_NUMBER ;
_item . currentZipCode = existingProfile . CONTACT_ZIPCODE ;
_item . createdUserId = request . user . sub ;
_item . createdFullName = request . user . name ;
_item . lastUpdateUserId = request . user . sub ;
_item . lastUpdateFullName = request . user . name ;
_item . createdAt = new Date ( ) ;
_item . lastUpdatedAt = new Date ( ) ;
console . log ( ">>>>>>>>>>>>>>>>>>>" + rowCount ) ;
await this . profileRepo . save ( _item ) ;
}
2024-07-26 14:41:41 +07:00
return new HttpSuccess ( ) ;
}
2024-07-26 14:59:34 +07:00
2024-07-26 14:41:41 +07:00
/ * *
* @summary ท ี ่ อ ย ู ่ ต า ม ท ะ เ บ ี ย น บ ้ า น - ป ั จ จ ุ บ ั น ล ู ก จ ้ า ง ป ร ะ จ ำ
* /
@Post ( "uploadProfileAddress-Employee" )
2024-07-26 15:52:32 +07:00
async UploadFileSQLAddressEmp ( @Request ( ) request : { user : Record < string , any > } ) {
let rowCount = 0 ;
let profileDatas : any = [ ] ;
2025-03-10 09:52:50 +07:00
let _null : any = null ;
2024-07-31 09:43:23 +07:00
const [ profiles , total ] = await AppDataSource . getRepository ( ProfileEmployee )
2024-07-26 15:52:32 +07:00
. createQueryBuilder ( "profile" )
2024-07-31 09:43:23 +07:00
. select ( [ "profile.citizenId" , "profile.id" ] )
. orderBy ( "profile.citizenId" , "ASC" )
// .skip(0)
// .take(20)
2024-07-26 15:52:32 +07:00
. getManyAndCount ( ) ;
2024-07-31 09:43:23 +07:00
// for (var i = 1; i <= total / BATCH_SIZE; i++) {
// const profiles = await AppDataSource.getRepository(ProfileEmployee)
// .createQueryBuilder("profile")
// .orderBy("profile.citizenId", "ASC")
// .skip((i - 1) * BATCH_SIZE)
// .take(BATCH_SIZE)
// .getMany();
// profileDatas = await [];
await Promise . all (
profiles . map ( async ( _item ) = > {
const existingProfile = await this . HR_PERSONAL_EMP_ADDRESSRepo . findOne ( {
where : { CIT : _item.citizenId } ,
} ) ;
2024-07-26 15:52:32 +07:00
2024-07-31 09:43:23 +07:00
if ( ! existingProfile ) {
return ;
}
2024-07-26 15:52:32 +07:00
2024-07-31 09:43:23 +07:00
rowCount ++ ;
let provinceRegis_ : any = null ;
let districtRegis_ : any = null ;
let subDistrictRegis_ : any = null ;
let provinceCurr_ : any = null ;
let districtCurr_ : any = null ;
let subDistrictCurr_ : any = null ;
//registration address
if ( existingProfile . PROVINCE_CODE ) {
provinceRegis_ = await this . provincsRepo . findOne ( {
where : { PROVINCE_CODE : existingProfile.PROVINCE_CODE } ,
} ) ;
if ( provinceRegis_ ) {
let provinceId = await this . provinceIdRepo . findOne ( {
where : {
name : provinceRegis_.PROVINCE_NAME ,
} ,
2024-07-26 14:41:41 +07:00
} ) ;
2025-03-10 09:52:50 +07:00
_item . registrationProvinceId = provinceId ? provinceId.id : _null ;
2024-07-26 14:41:41 +07:00
}
2024-07-31 09:43:23 +07:00
}
2024-08-05 10:16:26 +07:00
if ( existingProfile . AMPHUR_CODE && provinceRegis_ ) {
2024-07-31 09:43:23 +07:00
districtRegis_ = await this . amphurRepo . findOne ( {
where : {
AMPHUR_CODE : existingProfile.AMPHUR_CODE ,
PROVINCE_CODE : provinceRegis_.PROVINCE_CODE ,
} ,
} ) ;
if ( districtRegis_ ) {
let districtId = await this . districtIdRepo . findOne ( {
2024-07-26 14:59:34 +07:00
where : {
2024-07-31 09:43:23 +07:00
name : districtRegis_.AMPHUR_NAME ,
2024-07-26 14:59:34 +07:00
} ,
2024-07-26 14:41:41 +07:00
} ) ;
2025-03-10 09:52:50 +07:00
_item . registrationDistrictId = districtId ? districtId.id : _null ;
2024-07-26 14:41:41 +07:00
}
2024-07-31 09:43:23 +07:00
}
2024-08-05 10:16:26 +07:00
if ( existingProfile . DISTRICT_CODE && districtRegis_ && provinceRegis_ ) {
2024-07-31 09:43:23 +07:00
subDistrictRegis_ = await this . subDistrictRepo . findOne ( {
where : {
DISTRICT_CODE : existingProfile.DISTRICT_CODE ,
AMPHUR_CODE : districtRegis_.AMPHUR_CODE ,
PROVINCE_CODE : provinceRegis_.PROVINCE_CODE ,
} ,
} ) ;
if ( subDistrictRegis_ ) {
let subDistrictId = await this . subDistrictIdRepo . findOne ( {
2024-07-26 14:59:34 +07:00
where : {
2024-07-31 09:43:23 +07:00
name : subDistrictRegis_.DISTRICT_NAME ,
2024-07-26 14:59:34 +07:00
} ,
2024-07-26 14:41:41 +07:00
} ) ;
2025-03-10 09:52:50 +07:00
_item . registrationSubDistrictId = subDistrictId ? subDistrictId.id : _null ;
2024-07-26 14:41:41 +07:00
}
2024-07-31 09:43:23 +07:00
}
//current address
if ( existingProfile . CONTACT_PROVINCE_CODE ) {
provinceCurr_ = await this . provincsRepo . findOne ( {
where : { PROVINCE_CODE : existingProfile.CONTACT_PROVINCE_CODE } ,
} ) ;
if ( provinceCurr_ ) {
let provinceId = await this . provinceIdRepo . findOne ( {
where : {
name : provinceCurr_.PROVINCE_NAME ,
} ,
2024-07-26 14:41:41 +07:00
} ) ;
2025-03-10 09:52:50 +07:00
_item . currentProvinceId = provinceId ? provinceId.id : _null ;
2024-07-26 14:41:41 +07:00
}
2024-07-31 09:43:23 +07:00
}
2024-08-05 10:16:26 +07:00
if ( existingProfile . CONTACT_AMPHUR_CODE && provinceCurr_ ) {
2024-07-31 09:43:23 +07:00
districtCurr_ = await this . amphurRepo . findOne ( {
where : {
AMPHUR_CODE : existingProfile.CONTACT_AMPHUR_CODE ,
PROVINCE_CODE : provinceCurr_.PROVINCE_CODE ,
} ,
} ) ;
if ( districtCurr_ ) {
let districtId = await this . districtIdRepo . findOne ( {
2024-07-26 14:59:34 +07:00
where : {
2024-07-31 09:43:23 +07:00
name : districtCurr_.AMPHUR_NAME ,
2024-07-26 14:59:34 +07:00
} ,
2024-07-26 14:41:41 +07:00
} ) ;
2025-03-10 09:52:50 +07:00
_item . currentDistrictId = districtId ? districtId.id : _null ;
2024-07-26 14:41:41 +07:00
}
2024-07-31 09:43:23 +07:00
}
2024-08-05 10:16:26 +07:00
if ( existingProfile . CONTACT_DISTRICT_CODE && districtCurr_ && provinceCurr_ ) {
2024-07-31 09:43:23 +07:00
subDistrictCurr_ = await this . subDistrictRepo . findOne ( {
where : {
DISTRICT_CODE : existingProfile.CONTACT_DISTRICT_CODE ,
AMPHUR_CODE : districtCurr_.AMPHUR_CODE ,
PROVINCE_CODE : provinceCurr_.PROVINCE_CODE ,
} ,
} ) ;
if ( subDistrictCurr_ ) {
let subDistrictId = await this . subDistrictIdRepo . findOne ( {
2024-07-26 14:59:34 +07:00
where : {
2024-07-31 09:43:23 +07:00
name : subDistrictCurr_.DISTRICT_NAME ,
2024-07-26 14:59:34 +07:00
} ,
2024-07-26 14:41:41 +07:00
} ) ;
2025-03-10 09:52:50 +07:00
_item . currentSubDistrictId = subDistrictId ? subDistrictId.id : _null ;
2024-07-26 14:41:41 +07:00
}
2024-07-31 09:43:23 +07:00
}
_item . registrationAddress = existingProfile . H_NUMBER ;
_item . registrationZipCode = existingProfile . ZIPCODE ;
_item . currentAddress = existingProfile . CONTACT_H_NUMBER ;
_item . currentZipCode = existingProfile . CONTACT_ZIPCODE ;
2024-08-05 10:16:26 +07:00
_item . createdUserId = request . user . sub ;
_item . createdFullName = request . user . name ;
2024-07-31 09:43:23 +07:00
_item . lastUpdateUserId = request . user . sub ;
_item . lastUpdateFullName = request . user . name ;
2024-08-30 21:02:14 +07:00
_item . createdAt = new Date ( ) ;
_item . lastUpdatedAt = new Date ( ) ;
2024-07-31 09:43:23 +07:00
// profileDatas.push(_item);
2024-08-05 10:16:26 +07:00
console . log ( ">>>>>>>>>>>>>>>>>>>" + rowCount ) ;
2024-07-31 09:43:23 +07:00
await this . profileEmpRepo . save ( _item ) ;
} ) ,
) ;
// await this.profileEmpRepo.save(profileDatas);
// }
2024-08-05 10:16:26 +07:00
// console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
return new HttpSuccess ( ) ;
}
/ * *
* @summary ท ะ เ บ ี ย น ป ร ะ ว ั ต ิ ข ้ า ร า ช ก า ร
* /
@Post ( "cleardataupload" )
async ClearDataUpload ( @Request ( ) request : { user : Record < string , any > } ) {
const profileOff = await this . profileRepo . find ( {
select : [ "citizenId" ] ,
} ) ;
const profileEmp = await this . profileEmpRepo . find ( {
select : [ "citizenId" ] ,
} ) ;
const _profileOff = profileOff . map ( ( x ) = > x . citizenId ) ;
const _profileEmp = profileEmp . map ( ( x ) = > x . citizenId ) ;
const allId = _profileOff . concat ( _profileEmp ) ;
for ( var i = 1 ; i <= 1000 ; i ++ ) {
2025-02-21 19:10:27 +07:00
const positionOfficer = await this . positionOfficerRepo . find ( {
where : { citizenId : Not ( In ( allId ) ) } ,
2024-08-05 10:16:26 +07:00
take : 1000 ,
skip : 0 ,
} ) ;
2025-02-21 19:10:27 +07:00
this . positionOfficerRepo . remove ( positionOfficer ) ;
2024-08-05 10:16:26 +07:00
// const HR_PERSONAL_OFFICER_FAMILY = await this.HR_PERSONAL_OFFICER_FAMILYRepo.find({
// where: { CIT: Not(In(allId)) },
// take: 1000,
// skip: 0,
// });
// this.HR_PERSONAL_OFFICER_FAMILYRepo.remove(HR_PERSONAL_OFFICER_FAMILY);
// const HR_EDUCATION = await this.HR_EDUCATIONRepo.find({
// where: { CIT: Not(In(allId)) },
// take: 1000,
// skip: 0,
// });
// this.HR_EDUCATIONRepo.remove(HR_EDUCATION);
// const HR_PERSONAL_OFFICER_ADDRESS = await this.HR_PERSONAL_OFFICER_ADDRESSRepo.find({
// where: { CIT: Not(In(allId)) },
// take: 1000,
// skip: 0,
// });
// this.HR_PERSONAL_OFFICER_ADDRESSRepo.remove(HR_PERSONAL_OFFICER_ADDRESS);
// const HR_EDUCATION_EMP = await this.HR_EDUCATION_EMPRepo.find({
// where: { CIT: Not(In(allId)) },
// take: 1000,
// skip: 0,
// });
// this.HR_EDUCATION_EMPRepo.remove(HR_EDUCATION_EMP);
// const HR_PERSONAL_EMP_ADDRESS = await this.HR_PERSONAL_EMP_ADDRESSRepo.find({
// where: { CIT: Not(In(allId)) },
// take: 1000,
// skip: 0,
// });
// this.HR_PERSONAL_EMP_ADDRESSRepo.remove(HR_PERSONAL_EMP_ADDRESS);
// const HR_PERSONAL_EMP_FAMILY = await this.HR_PERSONAL_EMP_FAMILYRepo.find({
// where: { CIT: Not(In(allId)) },
// take: 1000,
// skip: 0,
// });
// this.HR_PERSONAL_EMP_FAMILYRepo.remove(HR_PERSONAL_EMP_FAMILY);
}
2024-07-26 14:41:41 +07:00
return new HttpSuccess ( ) ;
}
2025-01-31 17:35:56 +07:00
/ * *
* @summary Import Org
* /
@Post ( "ImportOrg" )
async ImportOrg ( @Request ( ) request : { user : Record < string , any > } ) {
const orgRevision = await this . orgRevisionRepo . findOne ( {
2025-03-24 21:57:50 +07:00
// where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
where : { id : "30e594c9-a65b-485e-a4c5-71aa497e6b8a" } ,
2025-01-31 17:35:56 +07:00
} ) ;
if ( orgRevision == null ) return new HttpSuccess ( ) ;
2025-02-12 10:43:01 +07:00
//create root
const IMPORT_CHILD = await this . IMPORT_ORGRepo . find ( {
where : {
orgRoot : Not ( "" ) ,
orgChild1 : "" ,
orgChild2 : "" ,
orgChild3 : "" ,
} ,
} ) ;
2025-03-03 14:52:29 +07:00
let order = 1 ;
for ( const item of IMPORT_CHILD ) {
const orgRoot = new OrgRoot ( ) ;
orgRoot . orgRootOrder = order ;
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 ) ;
order ++ ;
}
2025-02-12 10:43:01 +07:00
2025-03-03 14:52:29 +07:00
//create child1
const IMPORT_CHILD1 = await this . IMPORT_ORGRepo . find ( {
where : {
orgRoot : Not ( "" ) ,
orgChild1 : Not ( "" ) ,
orgChild2 : "" ,
orgChild3 : "" ,
} ,
} ) ;
for ( const item of IMPORT_CHILD1 ) {
const orgChild1 = new OrgChild1 ( ) ;
let orgRoot = await this . orgRootRepo . findOne ( {
2025-03-24 21:57:50 +07:00
where : { orgRootName : item.orgRoot , orgRevisionId : orgRevision.id } ,
2025-03-03 14:52:29 +07:00
relations : [ "orgChild1s" ] ,
} ) ;
if ( orgRoot == null ) {
orgRoot = new OrgRoot ( ) ;
orgRoot . orgRootOrder = order ;
order = order + 1 ;
2025-01-31 17:35:56 +07:00
orgRoot . orgRootName = item . orgRoot ;
2025-02-10 16:16:20 +07:00
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 ;
2025-01-31 17:35:56 +07:00
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 ) ;
2025-03-03 14:52:29 +07:00
}
2025-02-12 10:43:01 +07:00
2025-03-03 14:52:29 +07:00
orgChild1 . orgChild1Order =
orgRoot == null || orgRoot . orgChild1s == null || orgRoot . orgChild1s . length == 0
? 1
: orgRoot . orgChild1s . length + 1 ;
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 ) ;
}
//create child2
const IMPORT_CHILD2 = await this . IMPORT_ORGRepo . find ( {
2025-02-12 10:43:01 +07:00
where : {
orgRoot : Not ( "" ) ,
orgChild1 : Not ( "" ) ,
2025-03-03 14:52:29 +07:00
orgChild2 : Not ( "" ) ,
2025-02-12 10:43:01 +07:00
orgChild3 : "" ,
} ,
} ) ;
2025-03-03 14:52:29 +07:00
for ( const item of IMPORT_CHILD2 ) {
const orgChild2 = new OrgChild2 ( ) ;
let orgRoot = await this . orgRootRepo . findOne ( {
2025-03-24 21:57:50 +07:00
where : { orgRootName : item.orgRoot , orgRevisionId : orgRevision.id } ,
2025-03-03 14:52:29 +07:00
relations : [ "orgChild1s" ] ,
} ) ;
if ( orgRoot == null ) {
orgRoot = new OrgRoot ( ) ;
orgRoot . orgRootOrder = order ;
order = order + 1 ;
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 ( {
2025-03-24 21:57:50 +07:00
where : {
orgChild1Name : item.orgChild1 ,
orgRootId : orgRoot.id ,
orgRevisionId : orgRevision.id ,
} ,
2025-03-03 14:52:29 +07:00
relations : [ "orgChild2s" ] ,
} ) ;
if ( orgChild1 == null ) {
orgChild1 = new OrgChild1 ( ) ;
2025-02-12 10:43:01 +07:00
orgChild1 . orgRootId = orgRoot . id ;
2025-03-03 14:52:29 +07:00
orgChild1 . orgChild1Order =
orgRoot == null || orgRoot . orgChild1s == null || orgRoot . orgChild1s . length == 0
? 1
: orgRoot . orgChild1s . length + 1 ;
2025-02-12 10:43:01 +07:00
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 ) ;
2025-03-03 14:52:29 +07:00
}
orgChild2 . orgChild2Order =
orgChild1 == null || orgChild1 . orgChild2s == null || orgChild1 . orgChild2s . length == 0
? 1
: orgChild1 . orgChild2s . length + 1 ;
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 ) ;
}
2025-02-12 10:43:01 +07:00
2025-03-03 14:52:29 +07:00
//create child3
const IMPORT_CHILD3 = await this . IMPORT_ORGRepo . find ( {
2025-02-12 10:43:01 +07:00
where : {
orgRoot : Not ( "" ) ,
orgChild1 : Not ( "" ) ,
orgChild2 : Not ( "" ) ,
2025-03-03 14:52:29 +07:00
orgChild3 : Not ( "" ) ,
2025-02-12 10:43:01 +07:00
} ,
} ) ;
2025-03-03 14:52:29 +07:00
for ( const item of IMPORT_CHILD3 ) {
const orgChild3 = new OrgChild3 ( ) ;
let orgRoot = await this . orgRootRepo . findOne ( {
2025-03-24 21:57:50 +07:00
where : { orgRootName : item.orgRoot , orgRevisionId : orgRevision.id } ,
2025-03-03 14:52:29 +07:00
relations : [ "orgChild1s" ] ,
} ) ;
if ( orgRoot == null ) {
orgRoot = new OrgRoot ( ) ;
orgRoot . orgRootOrder = order ;
order = order + 1 ;
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 ( {
2025-03-24 21:57:50 +07:00
where : {
orgChild1Name : item.orgChild1 ,
orgRootId : orgRoot.id ,
orgRevisionId : orgRevision.id ,
} ,
2025-03-03 14:52:29 +07:00
relations : [ "orgChild2s" ] ,
} ) ;
if ( orgChild1 == null ) {
orgChild1 = new OrgChild1 ( ) ;
orgChild1 . orgChild1Order =
orgRoot == null || orgRoot . orgChild1s == null || orgRoot . orgChild1s . length == 0
? 1
: orgRoot . orgChild1s . length + 1 ;
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 ( {
2025-03-24 21:57:50 +07:00
where : {
orgChild2Name : item.orgChild2 ,
orgChild1Id : orgChild1.id ,
orgRootId : orgRoot.id ,
orgRevisionId : orgRevision.id ,
} ,
2025-03-03 14:52:29 +07:00
relations : [ "orgChild3s" ] ,
} ) ;
if ( orgChild2 == null ) {
orgChild2 = new OrgChild2 ( ) ;
orgChild2 . orgChild2Order =
orgChild1 == null || orgChild1 . orgChild2s == null || orgChild1 . orgChild2s . length == 0
? 1
: orgChild1 . orgChild2s . length + 1 ;
2025-02-12 10:43:01 +07:00
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 ) ;
2025-03-03 14:52:29 +07:00
}
orgChild3 . orgChild3Order =
orgChild2 == null || orgChild2 . orgChild3s == null || orgChild2 . orgChild3s . length == 0
? 1
: orgChild2 . orgChild3s . length + 1 ;
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 ) ;
}
2025-01-31 17:35:56 +07:00
return new HttpSuccess ( ) ;
}
2025-02-14 09:58:51 +07:00
/ * *
* @summary ท ะ เ บ ี ย น ป ร ะ ว ั ต ิ ข ้ า ร า ช ก า ร
* /
@Post ( "mapposition-Officer" )
async MapPositionOfficer ( @Request ( ) request : { user : Record < string , any > } ) {
2025-03-15 03:45:37 +07:00
const officer = await AppDataSource . getRepository ( Profile )
2025-03-17 15:42:48 +07:00
. createQueryBuilder ( "profile" )
2025-03-24 21:57:50 +07:00
. leftJoinAndSelect ( "profile.next_holders" , "posMaster" )
2025-03-17 15:42:48 +07:00
// .where({citizenId: "1720700018869"})
. where ( "posMaster.id IS NULL" )
. getMany ( ) ;
2025-03-13 14:53:55 +07:00
let rowCount = 0 ;
2025-03-10 09:52:50 +07:00
let _null : any = null ;
2025-02-14 09:58:51 +07:00
let type_ : any = null ;
let level_ : any = null ;
const orgRevision = await this . orgRevisionRepo . findOne ( {
2025-03-24 21:57:50 +07:00
// where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
where : { id : "30e594c9-a65b-485e-a4c5-71aa497e6b8a" } ,
2025-02-14 09:58:51 +07:00
} ) ;
if ( orgRevision == null ) return new HttpSuccess ( ) ;
2025-03-15 03:45:37 +07:00
for await ( const _item of officer ) {
2025-02-14 09:58:51 +07:00
rowCount ++ ;
2025-03-12 22:44:45 +07:00
console . log ( rowCount ) ;
2025-03-15 03:45:37 +07:00
const item = await AppDataSource . getRepository ( OFFICER )
. createQueryBuilder ( "OFFICER" )
2025-03-17 15:42:48 +07:00
. where ( { CIT : _item.citizenId } )
2025-03-15 03:45:37 +07:00
. getOne ( ) ;
2025-02-14 09:58:51 +07:00
2025-03-15 03:45:37 +07:00
if ( item == null ) {
2025-02-14 09:58:51 +07:00
continue ;
}
2025-03-13 14:53:55 +07:00
let posMaster = new PosMaster ( ) ;
2025-03-17 15:42:48 +07:00
let orgRoot = ( await this . orgRootRepo . findOne ( {
where : {
DEPARTMENT_CODE : item.DEPARTMENT_CODE ,
DIVISION_CODE : item.DIVISION_CODE ,
SECTION_CODE : item.SECTION_CODE ,
JOB_CODE : item.JOB_CODE ,
orgRevisionId : orgRevision.id ,
} ,
} ) ) as OrgRoot ;
2025-03-13 14:53:55 +07:00
if ( orgRoot != null ) {
posMaster . orgRootId = orgRoot . id ? ? _null ;
} else {
let orgChild1 = await this . orgChild1Repo . findOne ( {
2025-03-12 22:44:45 +07:00
where : {
2025-03-13 14:53:55 +07:00
DEPARTMENT_CODE : item.DEPARTMENT_CODE ,
DIVISION_CODE : item.DIVISION_CODE ,
SECTION_CODE : item.SECTION_CODE ,
JOB_CODE : item.JOB_CODE ,
2025-03-12 22:44:45 +07:00
orgRevisionId : orgRevision.id ,
2025-02-14 09:58:51 +07:00
} ,
2025-03-13 14:53:55 +07:00
} ) ;
if ( orgChild1 != null ) {
posMaster . orgRootId = orgChild1 . orgRootId ? ? _null ;
posMaster . orgChild1Id = orgChild1 . id ? ? _null ;
2025-03-17 15:42:48 +07:00
} else {
2025-03-13 14:53:55 +07:00
let orgChild2 = await this . orgChild2Repo . findOne ( {
where : {
DEPARTMENT_CODE : item.DEPARTMENT_CODE ,
DIVISION_CODE : item.DIVISION_CODE ,
SECTION_CODE : item.SECTION_CODE ,
JOB_CODE : item.JOB_CODE ,
orgRevisionId : orgRevision.id ,
2025-02-14 09:58:51 +07:00
} ,
2025-03-13 14:53:55 +07:00
} ) ;
if ( orgChild2 != null ) {
posMaster . orgRootId = orgChild2 . orgRootId ? ? _null ;
posMaster . orgChild1Id = orgChild2 . orgChild1Id ? ? _null ;
posMaster . orgChild2Id = orgChild2 . id ? ? _null ;
} else {
let orgChild3 = await this . orgChild3Repo . findOne ( {
where : {
DEPARTMENT_CODE : item.DEPARTMENT_CODE ,
DIVISION_CODE : item.DIVISION_CODE ,
SECTION_CODE : item.SECTION_CODE ,
JOB_CODE : item.JOB_CODE ,
orgRevisionId : orgRevision.id ,
2025-03-12 22:44:45 +07:00
} ,
2025-03-13 14:53:55 +07:00
} ) ;
if ( orgChild3 != null ) {
posMaster . orgRootId = orgChild3 . orgRootId ? ? _null ;
posMaster . orgChild1Id = orgChild3 . orgChild1Id ? ? _null ;
posMaster . orgChild2Id = orgChild3 . orgChild2Id ? ? _null ;
posMaster . orgChild3Id = orgChild3 . id ? ? _null ;
} else {
let orgChild4 = await this . orgChild4Repo . findOne ( {
where : {
DEPARTMENT_CODE : item.DEPARTMENT_CODE ,
DIVISION_CODE : item.DIVISION_CODE ,
SECTION_CODE : item.SECTION_CODE ,
JOB_CODE : item.JOB_CODE ,
orgRevisionId : orgRevision.id ,
} ,
} ) ;
if ( orgChild4 != null ) {
posMaster . orgRootId = orgChild4 . id ? ? _null ;
posMaster . orgChild1Id = orgChild4 . id ? ? _null ;
posMaster . orgChild2Id = orgChild4 . id ? ? _null ;
posMaster . orgChild3Id = orgChild4 . id ? ? _null ;
posMaster . orgChild4Id = orgChild4 . id ? ? _null ;
}
}
}
}
2025-03-12 22:44:45 +07:00
}
2025-02-14 09:58:51 +07:00
posMaster . statusReport = "PENDING" ;
posMaster . isCondition = false ;
posMaster . isStaff = false ;
posMaster . isDirector = false ;
posMaster . isSit = false ;
2025-03-24 21:57:50 +07:00
posMaster . next_holderId = _item . id ;
posMaster . posMasterNo =
item . POS_NUM_CODE == "" || item . POS_NUM_CODE == null ? _null : Number ( item . POS_NUM_CODE ) ;
2025-02-14 09:58:51 +07:00
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 ( ) ;
2025-03-03 14:52:29 +07:00
const posExecutive = await this . posExecutiveRepo . findOne ( {
where : {
posExecutiveName : item.ADMIN_NAME ,
} ,
} ) ;
if ( posExecutive == null && item . ADMIN_NAME != "" && item . ADMIN_NAME != null ) {
const posExecutiveOrder = await this . posExecutiveRepo . findOne ( {
where : { posExecutivePriority : Not ( IsNull ( ) ) } ,
order : { posExecutivePriority : "DESC" } ,
} ) ;
let posExecutive = new PosExecutive ( ) ;
posExecutive . posExecutivePriority =
2025-03-10 09:52:50 +07:00
posExecutiveOrder == null ? _null : posExecutiveOrder.posExecutivePriority + 1 ;
2025-03-03 14:52:29 +07:00
posExecutive . posExecutiveName = item . ADMIN_NAME ;
posExecutive . createdUserId = request . user . sub ;
posExecutive . createdFullName = request . user . name ;
posExecutive . lastUpdateUserId = request . user . sub ;
posExecutive . lastUpdateFullName = request . user . name ;
posExecutive . createdAt = new Date ( ) ;
posExecutive . lastUpdatedAt = new Date ( ) ;
await this . posExecutiveRepo . save ( posExecutive ) ;
}
2025-03-10 09:52:50 +07:00
position . posExecutiveId = posExecutive == null ? _null : posExecutive.id ;
position . positionName = item . WORK_LINE_NAME == "" ? _null : item.WORK_LINE_NAME ;
2025-02-14 09:58:51 +07:00
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 ( ) ;
}
2025-02-26 15:45:45 +07:00
2025-03-04 15:29:08 +07:00
/ * *
* @summary เ ง ิ น เ ด ื อ น ข ้ า ร า ช ก า ร
* /
@Post ( "uploadProfileSalary-OfficerEntry" )
async UploadFileSQLSalaryEntry ( @Request ( ) request : { user : Record < string , any > } ) {
let rowCount = 0 ;
2025-03-10 09:52:50 +07:00
let _null : any = null ;
2025-03-04 15:29:08 +07:00
let sqlStatements : string [ ] = [ ] ;
const [ profiles , total ] = await AppDataSource . getRepository ( Profile )
. createQueryBuilder ( "profile" )
. select ( [ "profile.citizenId" , "profile.id" ] )
. orderBy ( "profile.citizenId" , "ASC" )
// .skip(0)
// .take(1000)
. getManyAndCount ( ) ;
const filePath = path . join ( __dirname , "salaryProfile1.csv" ) ;
// CSV Header
let csvData = ` "id","createdAt","createdUserId","lastUpdatedAt","lastUpdateUserId","createdFullName","lastUpdateFullName","profileId","profileEmployeeId","order","commandNo","commandYear","commandDateSign","commandDateAffect","commandCode","commandName","posNoAbb","posNo","positionName","positionType","positionLevel","positionCee","orgRoot","orgChild1","orgChild2","orgChild3","orgChild4","positionExecutive","amount","amountSpecial","positionSalaryAmount","mouthSalaryAmount","remark","dateGovernment","isGovernment","commandId","refId","isEntry" \ n ` ;
fs . appendFile ( filePath , csvData , ( err ) = > {
if ( err ) {
console . error ( "Error writing CSV file:" , err ) ;
} else {
console . log ( "Salary profiles successfully written to salaryProfile.csv" ) ;
}
} ) ;
// await Promise.all(
// profiles.map(async (_item) => {
for await ( const _item of profiles ) {
const existingProfile = await this . ProfileSalariesRepo . find ( {
where : { posNo : _item.citizenId } ,
order : {
Order : "ASC" ,
} ,
} ) ;
let order = 1 ;
// await Promise.all(
// existingProfile.map(async (item) => {
for await ( const item of existingProfile ) {
rowCount ++ ;
const profileSalary : any = new ProfileSalary ( ) ;
profileSalary . profileId = _item . id ;
profileSalary . order = item . Order ;
profileSalary . commandDateAffect =
item . Date == null
2025-03-10 09:52:50 +07:00
? _null
2025-03-04 15:29:08 +07:00
: new Date ( item . Date . setDate ( item . Date . getDate ( ) + 1 ) )
. toISOString ( )
. replace ( "T" , " " )
. substring ( 0 , 19 ) ;
profileSalary . remark = item . SalaryRef + item . PositionName ;
profileSalary . amount = item . Amount ;
profileSalary . positionSalaryAmount = item . PositionSalaryAmount ;
// const str = item.PosNoName;
// const parts = str.split(" ");
// if (parts.length > 1) {
// const posNo = parts.at(-1);
// const posNoAbb = parts.slice(0, -1).join(" ");
// profileSalary.posNoAbb = posNoAbb;
// profileSalary.posNo = posNo;
// }
profileSalary . posNo = item . PosNoName ;
profileSalary . positionLevel = item . PositionLevelName ;
profileSalary . positionCee = this . canConvertToInt ( item . PositionLevelName )
? item . PositionLevelName
2025-03-10 09:52:50 +07:00
: _null ;
2025-03-04 15:29:08 +07:00
profileSalary . positionType = item . PositionTypeName ;
profileSalary . isEntry = true ;
profileSalary . createdUserId = request . user . sub ;
profileSalary . createdFullName = request . user . name ;
profileSalary . lastUpdateUserId = request . user . sub ;
profileSalary . lastUpdateFullName = request . user . name ;
profileSalary . createdAt = new Date ( ) . toISOString ( ) . split ( "T" ) [ 0 ] ;
profileSalary . lastUpdatedAt = new Date ( ) . toISOString ( ) . split ( "T" ) [ 0 ] ;
// const result = uuidv7();
// profileSalary.id = result;
await this . salaryRepo . save ( profileSalary ) ;
// console.log(profileSalary.commandDateSign);
// csvData = `"${profileSalary.id || "NULL"}","${profileSalary.createdAt || "NULL"}","${profileSalary.createdUserId || "NULL"}","${profileSalary.lastUpdatedAt || "NULL"}","${profileSalary.lastUpdateUserId || "NULL"}","${profileSalary.createdFullName || "NULL"}","${profileSalary.lastUpdateFullName || "NULL"}","${profileSalary.profileId || "NULL"}","${profileSalary.profileEmployeeId || "NULL"}","${profileSalary.order || "NULL"}","${profileSalary.commandNo || "NULL"}","${profileSalary.commandYear || "NULL"}","${profileSalary.commandDateSign || "NULL"}","${profileSalary.commandDateAffect || "NULL"}","${profileSalary.commandCode || "NULL"}","${profileSalary.commandName || "NULL"}","${profileSalary.posNoAbb || "NULL"}","${profileSalary.posNo || "NULL"}","${profileSalary.positionName || "NULL"}","${profileSalary.positionType || "NULL"}","${profileSalary.positionLevel || "NULL"}","${profileSalary.positionCee || "NULL"}","${profileSalary.orgRoot || "NULL"}","${profileSalary.orgChild1 || "NULL"}","${profileSalary.orgChild2 || "NULL"}","${profileSalary.orgChild3 || "NULL"}","${profileSalary.orgChild4 || "NULL"}","${profileSalary.positionExecutive || "NULL"}","${profileSalary.amount || 0}","${profileSalary.amountSpecial || 0}","${profileSalary.positionSalaryAmount || 0}","${profileSalary.mouthSalaryAmount || 0}","${profileSalary.remark || "NULL"}","${profileSalary.dateGovernment || "NULL"}","${profileSalary.isGovernment || "NULL"}","${profileSalary.commandId || "NULL"}","${profileSalary.refId || "NULL"}","${profileSalary.isEntry || "NULL"}"\n`;
// fs.appendFile(filePath, csvData.replace('"NULL"', "NULL"), (err) => {
// if (err) {
// console.error("Error writing CSV file:", err);
// } else {
console . log ( "Salary profiles successfully written to salaryProfile.csv: " + rowCount ) ;
// }
// });
}
order = 1 ;
}
return new HttpSuccess ( ) ;
}
canConvertToInt ( str : string ) {
try {
const num = Number ( str ) ;
return Number . isInteger ( num ) ;
} catch ( error ) {
return null ;
}
}
2025-03-14 13:36:26 +07:00
/ * *
* @summary เ ง ิ น เ ด ื อ น ข ้ า ร า ช ก า ร
* /
@Post ( "mark-director" )
async UpdateMarkDirector ( @Request ( ) request : { user : Record < string , any > } ) {
let rowCount = 0 ;
const posMaster = await this . posMasterRepo . find ( {
where : { positions : { posExecutiveId : Not ( IsNull ( ) ) } } ,
} ) ;
for await ( const _item of posMaster ) {
rowCount ++ ;
_item . isDirector = true ;
await this . posMasterRepo . save ( _item ) ;
console . log ( rowCount ) ;
}
return new HttpSuccess ( ) ;
}
2025-03-17 15:42:48 +07:00
/ * *
* @summary เ ง ิ น เ ด ื อ น ข ้ า ร า ช ก า ร
* /
@Post ( "update-amount" )
async UpdateAmount ( @Request ( ) request : { user : Record < string , any > } ) {
let rowCount = 0 ;
2025-03-24 21:57:50 +07:00
const profile : any = await this . profileRepo . find ( { where : { amount : LessThanOrEqual ( 0 ) } } ) ;
2025-03-17 15:42:48 +07:00
for await ( const _item of profile ) {
2025-03-24 21:57:50 +07:00
const OFFICER = await this . OFFICERRepo . findOne ( {
select : [ "CIT" , "SALARY" ] ,
where : { CIT : _item.citizenId } ,
} ) ;
2025-03-17 15:42:48 +07:00
if ( OFFICER ) {
rowCount ++ ;
_item . amount = Number ( OFFICER . SALARY ) ;
await this . profileRepo . save ( _item ) ;
console . log ( rowCount ) ;
}
}
return new HttpSuccess ( ) ;
}
2025-03-24 21:57:50 +07:00
/ * *
* @summary เ ง ิ น เ ด ื อ น ข ้ า ร า ช ก า ร
* /
@Post ( "update-profileSalary" )
async UpdateProfileSalary ( @Request ( ) request : { user : Record < string , any > } ) {
let rowCount = 0 ;
2025-03-25 09:36:38 +07:00
const profileSalarys : any = await this . salaryRepo . find ( { where : { refId : Not ( IsNull ( ) ) } } ) ;
2025-03-24 21:57:50 +07:00
for await ( const _item of profileSalarys ) {
2025-03-25 09:36:38 +07:00
const OFFICER = await this . HR_POSITION_OFFICERRepo . findOne ( {
select : [ "id" , "POS_NUM_CODE_SIT" , "POS_NUM_CODE_SIT_ABB" ] ,
where : { id : _item.refId } ,
2025-03-24 21:57:50 +07:00
} ) ;
if ( OFFICER ) {
rowCount ++ ;
_item . posNumCodeSit = OFFICER . POS_NUM_CODE_SIT ;
_item . posNumCodeSitAbb = OFFICER . POS_NUM_CODE_SIT_ABB ;
await this . profileRepo . save ( _item ) ;
console . log ( rowCount ) ;
}
}
return new HttpSuccess ( ) ;
}
2024-06-06 11:15:26 +07:00
}