ปรับออกคำสั่งลงตำแหน่ง
This commit is contained in:
parent
c5e0fcc4f7
commit
e305ea7a88
20 changed files with 1317 additions and 1183 deletions
|
|
@ -20,7 +20,6 @@ import * as fs from "fs";
|
|||
import * as path from "path";
|
||||
const { createConnection } = require("typeorm");
|
||||
import csvParser from "csv-parser";
|
||||
import { HR_POSITION_OFFICER } from "../entities/HR_POSITION_OFFICER";
|
||||
import { HR_PERSONAL_OFFICER_FAMILY } from "../entities/HR_PERSONAL_OFFICER_FAMILY";
|
||||
|
||||
const BATCH_SIZE = 1000;
|
||||
|
|
@ -47,6 +46,7 @@ import { OrgRevision } from "../entities/OrgRevision";
|
|||
import { OFFICER } from "../entities/OFFICER";
|
||||
import { Position } from "../entities/Position";
|
||||
import { PosMaster } from "../entities/PosMaster";
|
||||
import { positionOfficer } from "../entities/positionOfficer";
|
||||
|
||||
@Route("api/v1/org/upload")
|
||||
@Tags("UPLOAD")
|
||||
|
|
@ -61,7 +61,7 @@ export class ImportDataController extends Controller {
|
|||
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||
private posLevelRepo = AppDataSource.getRepository(PosLevel);
|
||||
private posTypeRepo = AppDataSource.getRepository(PosType);
|
||||
private HR_POSITION_OFFICERRepo = AppDataSource.getRepository(HR_POSITION_OFFICER);
|
||||
private positionOfficerRepo = AppDataSource.getRepository(positionOfficer);
|
||||
private HR_PERSONAL_OFFICER_FAMILYRepo = AppDataSource.getRepository(HR_PERSONAL_OFFICER_FAMILY);
|
||||
private HR_EDUCATIONRepo = AppDataSource.getRepository(HR_EDUCATION);
|
||||
private HR_PERSONAL_OFFICER_ADDRESSRepo = AppDataSource.getRepository(
|
||||
|
|
@ -328,115 +328,133 @@ export class ImportDataController extends Controller {
|
|||
.createQueryBuilder("profile")
|
||||
.select(["profile.citizenId", "profile.id"])
|
||||
.orderBy("profile.citizenId", "ASC")
|
||||
.skip(20000)
|
||||
.take(10000)
|
||||
.where("profile.citizenId = '3101702379675'")
|
||||
// .skip(0)
|
||||
// .take(10000)
|
||||
.getManyAndCount();
|
||||
// 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();
|
||||
|
||||
await Promise.all(
|
||||
profiles.map(async (_item) => {
|
||||
console.log(">>>>>>>>>>>>>>>>>>>" + _item.citizenId);
|
||||
const existingProfile = await this.HR_POSITION_OFFICERRepo.find({
|
||||
where: { CIT: _item.citizenId, FLAG_PERSON_TYPE: "1" },
|
||||
select: [
|
||||
"CIT",
|
||||
"MP_POS_DATE",
|
||||
"SALARY",
|
||||
"MP_COMMAND_NUM",
|
||||
"POS_NUM_NAME",
|
||||
"POS_NUM_CODE",
|
||||
"FLAG_TO_NAME",
|
||||
"WORK_LINE_NAME",
|
||||
"SPECIALIST_NAME",
|
||||
"ADMIN_NAME",
|
||||
"REMARK",
|
||||
"ORDER_MOVE_POSITION",
|
||||
"SAL_POS_AMOUNT_1",
|
||||
"SAL_POS_AMOUNT_2",
|
||||
"SPECIAL_AMT",
|
||||
"MP_COMMAND_DATE",
|
||||
"FLAG_TO_NAME_CODE",
|
||||
"DEPARTMENT_NAME",
|
||||
"DIVISION_NAME",
|
||||
"SECTION_NAME",
|
||||
"JOB_NAME",
|
||||
"MP_CEE",
|
||||
"USER_CREATE",
|
||||
"USER_UPDATE",
|
||||
],
|
||||
const existingProfile = await this.positionOfficerRepo.find({
|
||||
where: { citizenId: _item.citizenId, flag_person_type: "1" },
|
||||
order: {
|
||||
mp_pos_date: "ASC",
|
||||
order_move_position: "ASC",
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
existingProfile.map(async (item) => {
|
||||
rowCount++;
|
||||
const profileSalary = new ProfileSalary();
|
||||
profileSalary.date = item.MP_POS_DATE
|
||||
? new Date(item.MP_POS_DATE.replace(" +0700 +07:00", ""))
|
||||
: null_;
|
||||
const SALARY: any =
|
||||
item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY);
|
||||
profileSalary.amount = SALARY;
|
||||
const SAL_POS_AMOUNT_1: any =
|
||||
item.SAL_POS_AMOUNT_1 == null || item.SAL_POS_AMOUNT_1 == ""
|
||||
? null_
|
||||
: Number(item.SAL_POS_AMOUNT_1);
|
||||
const SAL_POS_AMOUNT_2: any =
|
||||
item.SAL_POS_AMOUNT_2 == null || item.SAL_POS_AMOUNT_2 == ""
|
||||
? null_
|
||||
: Number(item.SAL_POS_AMOUNT_2);
|
||||
profileSalary.positionSalaryAmount = SAL_POS_AMOUNT_1 ?? SAL_POS_AMOUNT_2;
|
||||
const SPECIAL_AMT: any =
|
||||
item.SPECIAL_AMT == null || item.SPECIAL_AMT == "" ? null_ : Number(item.SPECIAL_AMT);
|
||||
profileSalary.amountSpecial = SPECIAL_AMT;
|
||||
const profileSalary: any = new ProfileSalary();
|
||||
profileSalary.profileId = _item.id;
|
||||
profileSalary.refCommandNo = item.MP_COMMAND_NUM;
|
||||
profileSalary.posNo = item.POS_NUM_NAME + item.POS_NUM_CODE;
|
||||
profileSalary.position = item.WORK_LINE_NAME;
|
||||
profileSalary.positionPathSide = item.SPECIALIST_NAME;
|
||||
profileSalary.positionExecutive = item.ADMIN_NAME;
|
||||
profileSalary.templateDoc = item.REMARK;
|
||||
profileSalary.refCommandDate =
|
||||
item.MP_COMMAND_DATE == ""
|
||||
? new Date(item.MP_COMMAND_DATE.replace(" +0700 +07:00", ""))
|
||||
: null_;
|
||||
profileSalary.refCommandCode = item.FLAG_TO_NAME_CODE;
|
||||
profileSalary.refCommandName = item.FLAG_TO_NAME;
|
||||
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.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;
|
||||
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 = "สูง";
|
||||
}
|
||||
profileSalary.mpCee = item.MP_CEE;
|
||||
const ORDER_MOVE_POSITION: any =
|
||||
item.ORDER_MOVE_POSITION == null || item.ORDER_MOVE_POSITION == ""
|
||||
var _type = await this.posTypeRepo.findOne({
|
||||
where: { posTypeName: positionType },
|
||||
});
|
||||
profileSalary.positionType = _type == null ? null_ : _type.id;
|
||||
if (_type != null) {
|
||||
var _level = await this.posLevelRepo.findOne({
|
||||
where: {
|
||||
posLevelName: positionLevel,
|
||||
posTypeId: _type.id,
|
||||
},
|
||||
});
|
||||
profileSalary.positionLevel = _level == null ? null_ : _level.id;
|
||||
}
|
||||
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 == ""
|
||||
? null_
|
||||
: Number(item.ORDER_MOVE_POSITION);
|
||||
profileSalary.order = ORDER_MOVE_POSITION;
|
||||
: Number(item.sal_pos_amount_1);
|
||||
const sal_pos_amount_2: any =
|
||||
item.sal_pos_amount_2 == null || item.sal_pos_amount_2 == ""
|
||||
? null_
|
||||
: Number(item.sal_pos_amount_2);
|
||||
profileSalary.positionSalaryAmount = sal_pos_amount_1 ?? sal_pos_amount_2;
|
||||
const special_amt: any =
|
||||
item.special_amt == null || item.special_amt == "" ? null_ : Number(item.special_amt);
|
||||
profileSalary.amountSpecial = special_amt;
|
||||
|
||||
profileSalary.createdUserId = request.user.sub;
|
||||
profileSalary.createdFullName = request.user.name;
|
||||
profileSalary.lastUpdateUserId = request.user.sub;
|
||||
profileSalary.lastUpdateFullName = request.user.name;
|
||||
profileSalary.createdAt =
|
||||
item.USER_CREATE == ""
|
||||
? new Date(item.USER_CREATE.replace(" +0700 +07:00", ""))
|
||||
: new Date();
|
||||
profileSalary.lastUpdatedAt =
|
||||
item.USER_UPDATE == ""
|
||||
? new Date(item.USER_UPDATE.replace(" +0700 +07:00", ""))
|
||||
: new Date();
|
||||
profileSalary.createdAt = new Date();
|
||||
profileSalary.lastUpdatedAt = new Date();
|
||||
console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
|
||||
await this.salaryRepo.save(profileSalary);
|
||||
// save to file
|
||||
// await this.salaryRepo.save(profileSalary);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
|
|
@ -457,115 +475,75 @@ export class ImportDataController extends Controller {
|
|||
.createQueryBuilder("profile")
|
||||
.select(["profile.citizenId", "profile.id"])
|
||||
.orderBy("profile.citizenId", "ASC")
|
||||
// .skip(0)
|
||||
// .take(20)
|
||||
.skip(0)
|
||||
.take(10000)
|
||||
.getManyAndCount();
|
||||
// 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();
|
||||
|
||||
await Promise.all(
|
||||
profiles.map(async (_item) => {
|
||||
const existingProfile = await this.HR_POSITION_OFFICERRepo.find({
|
||||
where: { CIT: _item.citizenId },
|
||||
select: [
|
||||
"CIT",
|
||||
"MP_POS_DATE",
|
||||
"SALARY",
|
||||
"MP_COMMAND_NUM",
|
||||
"POS_NUM_NAME",
|
||||
"POS_NUM_CODE",
|
||||
"FLAG_TO_NAME",
|
||||
"WORK_LINE_NAME",
|
||||
"SPECIALIST_NAME",
|
||||
"ADMIN_NAME",
|
||||
"REMARK",
|
||||
"ORDER_MOVE_POSITION",
|
||||
"SAL_POS_AMOUNT_1",
|
||||
"SAL_POS_AMOUNT_2",
|
||||
"SPECIAL_AMT",
|
||||
"MP_COMMAND_DATE",
|
||||
"FLAG_TO_NAME_CODE",
|
||||
"DEPARTMENT_NAME",
|
||||
"DIVISION_NAME",
|
||||
"SECTION_NAME",
|
||||
"JOB_NAME",
|
||||
"MP_CEE",
|
||||
"USER_CREATE",
|
||||
"USER_UPDATE",
|
||||
],
|
||||
const existingProfile = await this.positionOfficerRepo.find({
|
||||
where: { citizenId: _item.citizenId, flag_person_type: "7" },
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
existingProfile.map(async (item) => {
|
||||
rowCount++;
|
||||
const profileSalary = new ProfileSalary();
|
||||
profileSalary.date =
|
||||
item.MP_POS_DATE == ""
|
||||
? new Date(item.MP_POS_DATE.replace(" +0700 +07:00", ""))
|
||||
: null_;
|
||||
const SALARY: any =
|
||||
item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY);
|
||||
profileSalary.amount = SALARY;
|
||||
const SAL_POS_AMOUNT_1: any =
|
||||
item.SAL_POS_AMOUNT_1 == null || item.SAL_POS_AMOUNT_1 == ""
|
||||
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 == ""
|
||||
? null_
|
||||
: Number(item.SAL_POS_AMOUNT_1);
|
||||
const SAL_POS_AMOUNT_2: any =
|
||||
item.SAL_POS_AMOUNT_2 == null || item.SAL_POS_AMOUNT_2 == ""
|
||||
: Number(item.sal_pos_amount_1);
|
||||
const sal_pos_amount_2: any =
|
||||
item.sal_pos_amount_2 == null || item.sal_pos_amount_2 == ""
|
||||
? null_
|
||||
: Number(item.SAL_POS_AMOUNT_2);
|
||||
profileSalary.positionSalaryAmount = SAL_POS_AMOUNT_1 ?? SAL_POS_AMOUNT_2;
|
||||
const SPECIAL_AMT: any =
|
||||
item.SPECIAL_AMT == null || item.SPECIAL_AMT == "" ? null_ : Number(item.SPECIAL_AMT);
|
||||
profileSalary.amountSpecial = SPECIAL_AMT;
|
||||
profileSalary.profileEmployeeId = _item.id;
|
||||
profileSalary.refCommandNo = item.MP_COMMAND_NUM;
|
||||
profileSalary.posNo = item.POS_NUM_NAME + item.POS_NUM_CODE;
|
||||
profileSalary.position = item.WORK_LINE_NAME;
|
||||
profileSalary.positionPathSide = item.SPECIALIST_NAME;
|
||||
profileSalary.positionExecutive = item.ADMIN_NAME;
|
||||
profileSalary.templateDoc = item.REMARK;
|
||||
profileSalary.refCommandDate =
|
||||
item.MP_COMMAND_DATE == ""
|
||||
? new Date(item.MP_COMMAND_DATE.replace(" +0700 +07:00", ""))
|
||||
: null_;
|
||||
profileSalary.refCommandCode = item.FLAG_TO_NAME_CODE;
|
||||
profileSalary.refCommandName = item.FLAG_TO_NAME;
|
||||
profileSalary.orgRoot = item.DEPARTMENT_NAME;
|
||||
profileSalary.orgChild1 = item.DIVISION_NAME;
|
||||
profileSalary.orgChild2 = item.SECTION_NAME;
|
||||
profileSalary.orgChild3 = item.JOB_NAME;
|
||||
profileSalary.mpCee = item.MP_CEE;
|
||||
const ORDER_MOVE_POSITION: any =
|
||||
item.ORDER_MOVE_POSITION == null || item.ORDER_MOVE_POSITION == ""
|
||||
? null_
|
||||
: Number(item.ORDER_MOVE_POSITION);
|
||||
profileSalary.order = ORDER_MOVE_POSITION;
|
||||
: Number(item.sal_pos_amount_2);
|
||||
profileSalary.positionSalaryAmount = sal_pos_amount_1 ?? sal_pos_amount_2;
|
||||
const special_amt: any =
|
||||
item.special_amt == null || item.special_amt == "" ? null_ : Number(item.special_amt);
|
||||
profileSalary.amountSpecial = special_amt;
|
||||
|
||||
profileSalary.commandId;
|
||||
|
||||
profileSalary.createdUserId = request.user.sub;
|
||||
profileSalary.createdFullName = request.user.name;
|
||||
profileSalary.lastUpdateUserId = request.user.sub;
|
||||
profileSalary.lastUpdateFullName = request.user.name;
|
||||
profileSalary.createdAt =
|
||||
item.USER_CREATE == ""
|
||||
? new Date(item.USER_CREATE.replace(" +0700 +07:00", ""))
|
||||
: new Date();
|
||||
profileSalary.lastUpdatedAt =
|
||||
item.USER_UPDATE == ""
|
||||
? new Date(item.USER_UPDATE.replace(" +0700 +07:00", ""))
|
||||
: new Date();
|
||||
profileSalary.createdAt = new Date();
|
||||
profileSalary.lastUpdatedAt = new Date();
|
||||
console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
|
||||
await this.salaryRepo.save(profileSalary);
|
||||
// save to file
|
||||
// await this.salaryRepo.save(profileSalary);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
);
|
||||
// }
|
||||
console.log(rowCount);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -1472,12 +1450,12 @@ export class ImportDataController extends Controller {
|
|||
const allId = _profileOff.concat(_profileEmp);
|
||||
|
||||
for (var i = 1; i <= 1000; i++) {
|
||||
const HR_POSITION_OFFICER = await this.HR_POSITION_OFFICERRepo.find({
|
||||
where: { CIT: Not(In(allId)) },
|
||||
const positionOfficer = await this.positionOfficerRepo.find({
|
||||
where: { citizenId: Not(In(allId)) },
|
||||
take: 1000,
|
||||
skip: 0,
|
||||
});
|
||||
this.HR_POSITION_OFFICERRepo.remove(HR_POSITION_OFFICER);
|
||||
this.positionOfficerRepo.remove(positionOfficer);
|
||||
// const HR_PERSONAL_OFFICER_FAMILY = await this.HR_PERSONAL_OFFICER_FAMILYRepo.find({
|
||||
// where: { CIT: Not(In(allId)) },
|
||||
// take: 1000,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue