import emtry
This commit is contained in:
parent
53b6256c56
commit
175c105bed
2 changed files with 111 additions and 101 deletions
|
|
@ -52,7 +52,7 @@ import { EducationLevel } from "../entities/EducationLevel";
|
||||||
import { HR_FUND_COURSE_CODE } from "../entities/HR_FUND_COURSE_CODE";
|
import { HR_FUND_COURSE_CODE } from "../entities/HR_FUND_COURSE_CODE";
|
||||||
import { HR_MAJOR_CODE } from "../entities/HR_MAJOR_CODE";
|
import { HR_MAJOR_CODE } from "../entities/HR_MAJOR_CODE";
|
||||||
// import { uuidv7 } from "uuidv7";
|
// import { uuidv7 } from "uuidv7";
|
||||||
// import { ProfileSalaries } from "../entities/ProfileSalaries";
|
import { ProfileSalaries } from "../entities/ProfileSalaries";
|
||||||
@Route("api/v1/org/upload")
|
@Route("api/v1/org/upload")
|
||||||
@Tags("UPLOAD")
|
@Tags("UPLOAD")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -67,7 +67,7 @@ export class ImportDataController extends Controller {
|
||||||
private posLevelRepo = AppDataSource.getRepository(PosLevel);
|
private posLevelRepo = AppDataSource.getRepository(PosLevel);
|
||||||
private posTypeRepo = AppDataSource.getRepository(PosType);
|
private posTypeRepo = AppDataSource.getRepository(PosType);
|
||||||
private positionOfficerRepo = AppDataSource.getRepository(positionOfficer);
|
private positionOfficerRepo = AppDataSource.getRepository(positionOfficer);
|
||||||
// private ProfileSalariesRepo = AppDataSource.getRepository(ProfileSalaries);
|
private ProfileSalariesRepo = AppDataSource.getRepository(ProfileSalaries);
|
||||||
private HR_PERSONAL_OFFICER_FAMILYRepo = AppDataSource.getRepository(HR_PERSONAL_OFFICER_FAMILY);
|
private HR_PERSONAL_OFFICER_FAMILYRepo = AppDataSource.getRepository(HR_PERSONAL_OFFICER_FAMILY);
|
||||||
private HR_EDUCATIONRepo = AppDataSource.getRepository(HR_EDUCATION);
|
private HR_EDUCATIONRepo = AppDataSource.getRepository(HR_EDUCATION);
|
||||||
private HR_PERSONAL_OFFICER_ADDRESSRepo = AppDataSource.getRepository(
|
private HR_PERSONAL_OFFICER_ADDRESSRepo = AppDataSource.getRepository(
|
||||||
|
|
@ -2347,109 +2347,113 @@ export class ImportDataController extends Controller {
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * @summary เงินเดือน ข้าราชการ
|
* @summary เงินเดือน ข้าราชการ
|
||||||
// */
|
*/
|
||||||
// @Post("uploadProfileSalary-OfficerEntry")
|
@Post("uploadProfileSalary-OfficerEntry")
|
||||||
// async UploadFileSQLSalaryEntry(@Request() request: { user: Record<string, any> }) {
|
async UploadFileSQLSalaryEntry(@Request() request: { user: Record<string, any> }) {
|
||||||
// let rowCount = 0;
|
let rowCount = 0;
|
||||||
// let null_: any = null;
|
let null_: any = null;
|
||||||
// let sqlStatements: string[] = [];
|
let sqlStatements: string[] = [];
|
||||||
|
|
||||||
// const [profiles, total] = await AppDataSource.getRepository(Profile)
|
const [profiles, total] = await AppDataSource.getRepository(Profile)
|
||||||
// .createQueryBuilder("profile")
|
.createQueryBuilder("profile")
|
||||||
// .select(["profile.citizenId", "profile.id"])
|
.select(["profile.citizenId", "profile.id"])
|
||||||
// .orderBy("profile.citizenId", "ASC")
|
.orderBy("profile.citizenId", "ASC")
|
||||||
// // .where("profile.citizenId = '3101702379675'")
|
.where("profile.citizenId = '3101501190150'")
|
||||||
// .skip(10000)
|
// .skip(0)
|
||||||
// .take(20000)
|
// .take(1000)
|
||||||
// .getManyAndCount();
|
.getManyAndCount();
|
||||||
// var _profiles: ProfileSalary[] = [];
|
const filePath = path.join(__dirname, "salaryProfile1.csv");
|
||||||
// const filePath = path.join(__dirname, "salaryProfile1.csv");
|
// CSV Header
|
||||||
// // 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`;
|
||||||
// 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`;
|
|
||||||
|
|
||||||
// fs.appendFile(filePath, csvData, (err) => {
|
fs.appendFile(filePath, csvData, (err) => {
|
||||||
// if (err) {
|
if (err) {
|
||||||
// console.error("Error writing CSV file:", err);
|
console.error("Error writing CSV file:", err);
|
||||||
// } else {
|
} else {
|
||||||
// console.log("Salary profiles successfully written to salaryProfile.csv");
|
console.log("Salary profiles successfully written to salaryProfile.csv");
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
// await Promise.all(
|
// await Promise.all(
|
||||||
// profiles.map(async (_item) => {
|
// profiles.map(async (_item) => {
|
||||||
// const existingProfile = await this.ProfileSalariesRepo.find({
|
console.log("XXXXXXXXXXXXXXX");
|
||||||
// where: { ProfileId: _item.citizenId },
|
for await (const _item of profiles) {
|
||||||
// order: {
|
console.log("zzzzzzzzzzzzz");
|
||||||
// Order: "ASC",
|
const existingProfile = await this.ProfileSalariesRepo.find({
|
||||||
// },
|
where: { posNo: _item.citizenId },
|
||||||
// });
|
order: {
|
||||||
// let order = 1;
|
Order: "ASC",
|
||||||
// await Promise.all(
|
},
|
||||||
// existingProfile.map(async (item) => {
|
});
|
||||||
// rowCount++;
|
let order = 1;
|
||||||
// const profileSalary: any = new ProfileSalary();
|
// await Promise.all(
|
||||||
// profileSalary.profileId = _item.id;
|
// existingProfile.map(async (item) => {
|
||||||
// profileSalary.order = item.Order;
|
for await (const item of existingProfile) {
|
||||||
|
console.log("zzzzzzz4zzzzzz");
|
||||||
|
rowCount++;
|
||||||
|
const profileSalary: any = new ProfileSalary();
|
||||||
|
profileSalary.profileId = _item.id;
|
||||||
|
profileSalary.order = item.Order;
|
||||||
|
|
||||||
// profileSalary.commandDateAffect =
|
profileSalary.commandDateAffect =
|
||||||
// item.Date == null
|
item.Date == null
|
||||||
// ? null_
|
? null_
|
||||||
// : new Date(item.Date.setDate(item.Date.getDate() + 1))
|
: new Date(item.Date.setDate(item.Date.getDate() + 1))
|
||||||
// .toISOString()
|
.toISOString()
|
||||||
// .replace("T", " ")
|
.replace("T", " ")
|
||||||
// .substring(0, 19);
|
.substring(0, 19);
|
||||||
// profileSalary.remark = item.SalaryRef + item.PositionName;
|
profileSalary.remark = item.SalaryRef + item.PositionName;
|
||||||
// profileSalary.amount = item.Amount;
|
profileSalary.amount = item.Amount;
|
||||||
// profileSalary.positionSalaryAmount = item.PositionSalaryAmount;
|
profileSalary.positionSalaryAmount = item.PositionSalaryAmount;
|
||||||
// const str = item.PosNoName;
|
// const str = item.PosNoName;
|
||||||
// const parts = str.split(" ");
|
// const parts = str.split(" ");
|
||||||
// if (parts.length > 1) {
|
// if (parts.length > 1) {
|
||||||
// const posNo = parts.at(-1);
|
// const posNo = parts.at(-1);
|
||||||
// const posNoAbb = parts.slice(0, -1).join(" ");
|
// const posNoAbb = parts.slice(0, -1).join(" ");
|
||||||
// profileSalary.posNoAbb = posNoAbb;
|
// profileSalary.posNoAbb = posNoAbb;
|
||||||
// profileSalary.posNo = posNo;
|
// profileSalary.posNo = posNo;
|
||||||
// }
|
// }
|
||||||
// profileSalary.posLevel = this.canConvertToInt(item.PositionLevelName)
|
profileSalary.posNo = item.PosNoName;
|
||||||
// ? null_
|
profileSalary.positionLevel = item.PositionLevelName;
|
||||||
// : item.PositionLevelName;
|
profileSalary.positionCee = this.canConvertToInt(item.PositionLevelName)
|
||||||
// profileSalary.posCee = this.canConvertToInt(item.PositionLevelName)
|
? item.PositionLevelName
|
||||||
// ? item.PositionLevelName
|
: null_;
|
||||||
// : null_;
|
//xxxxxxxxxxxxxxxxx
|
||||||
// //xxxxxxxxxxxxxxxxx
|
profileSalary.positionType = item.PositionTypeName;
|
||||||
// profileSalary.posType = item.PositionTypeName;
|
profileSalary.isEntry = true;
|
||||||
// profileSalary.isEntry = true;
|
|
||||||
|
|
||||||
// profileSalary.createdUserId = request.user.sub;
|
profileSalary.createdUserId = request.user.sub;
|
||||||
// profileSalary.createdFullName = request.user.name;
|
profileSalary.createdFullName = request.user.name;
|
||||||
// profileSalary.lastUpdateUserId = request.user.sub;
|
profileSalary.lastUpdateUserId = request.user.sub;
|
||||||
// profileSalary.lastUpdateFullName = request.user.name;
|
profileSalary.lastUpdateFullName = request.user.name;
|
||||||
// profileSalary.createdAt = new Date().toISOString().split("T")[0];
|
profileSalary.createdAt = new Date().toISOString().split("T")[0];
|
||||||
// profileSalary.lastUpdatedAt = new Date().toISOString().split("T")[0];
|
profileSalary.lastUpdatedAt = new Date().toISOString().split("T")[0];
|
||||||
// // const result = uuidv7();
|
// const result = uuidv7();
|
||||||
// // profileSalary.id = result;
|
// profileSalary.id = result;
|
||||||
|
|
||||||
// console.log(profileSalary.commandDateSign);
|
await this.salaryRepo.save(profileSalary);
|
||||||
// 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`;
|
// 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) => {
|
// fs.appendFile(filePath, csvData.replace('"NULL"', "NULL"), (err) => {
|
||||||
// if (err) {
|
// if (err) {
|
||||||
// console.error("Error writing CSV file:", err);
|
// console.error("Error writing CSV file:", err);
|
||||||
// } else {
|
// } else {
|
||||||
// console.log(
|
console.log("Salary profiles successfully written to salaryProfile.csv: " + rowCount);
|
||||||
// "Salary profiles successfully written to salaryProfile.csv: " + rowCount,
|
// }
|
||||||
// );
|
// });
|
||||||
// }
|
}
|
||||||
// });
|
order = 1;
|
||||||
// }),
|
}
|
||||||
// );
|
return new HttpSuccess();
|
||||||
// order = 1;
|
}
|
||||||
// }),
|
canConvertToInt(str: string) {
|
||||||
// );
|
try {
|
||||||
// return new HttpSuccess();
|
const num = Number(str);
|
||||||
// }
|
return Number.isInteger(num);
|
||||||
// canConvertToInt(str: string) {
|
} catch (error) {
|
||||||
// const num = Number(str);
|
return null;
|
||||||
// return Number.isInteger(num);
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,12 @@ export class ProfileSalaries extends EntityBase {
|
||||||
})
|
})
|
||||||
Date: Date;
|
Date: Date;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
posNo: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
default: null,
|
default: null,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue