test job เกษียณ
This commit is contained in:
parent
e5dfed9312
commit
7ffb698252
2 changed files with 149 additions and 16 deletions
|
|
@ -62,7 +62,8 @@ async function main() {
|
|||
}
|
||||
});
|
||||
|
||||
const cronTime_Oct = "0 0 1 10 *";
|
||||
// const cronTime_Oct = "0 0 1 10 *";
|
||||
const cronTime_Oct = "0 0 2 10 *"; // test 2 ตุลาคม
|
||||
cron.schedule(cronTime_Oct, async () => {
|
||||
try {
|
||||
const commandController = new CommandController();
|
||||
|
|
|
|||
|
|
@ -1499,6 +1499,7 @@ export class CommandController extends Controller {
|
|||
const today = new Date();
|
||||
today.setUTCHours(0, 0, 0, 0);
|
||||
let type: string = "OFFICER";
|
||||
let _Date = new Date()
|
||||
try {
|
||||
const response_ = await axios.get(
|
||||
process.env.API_URL + `/retirement/update-status/${type}/${today.getFullYear()}`,
|
||||
|
|
@ -1510,23 +1511,46 @@ export class CommandController extends Controller {
|
|||
},
|
||||
},
|
||||
);
|
||||
if (response && response_.data.result.length > 0) {
|
||||
let profiles: Profile[] = [];
|
||||
if (response_ && response_.data.result) {
|
||||
let signDate:string = ""
|
||||
if (response_.data.result.signDate != null) {
|
||||
signDate = Extension.ToThaiShortDate_noPrefix(new Date(response_.data.result.signDate))
|
||||
}
|
||||
else {
|
||||
signDate = Extension.ToThaiShortDate_noPrefix(_Date)
|
||||
}
|
||||
// let profiles: Profile[] = [];
|
||||
await Promise.all(
|
||||
response_.data.result.map(async (x: any) => {
|
||||
response_.data.result.profiles.map(async (x: any) => {
|
||||
const _profile = await this.profileRepository.findOneBy({ id: x.profileId });
|
||||
if (_profile) {
|
||||
// console.log("1. บันทึกลงประวัติตำแหน่ง")
|
||||
await this.profileSalaryRetire(x.profileId, type, signDate, _Date);
|
||||
// console.log("2. ปลดออกจากโครงสร้าง")
|
||||
await this.posMasterRetire(x.profileId, type, _Date);
|
||||
// console.log("3. แก้ไขสถานะในทะเบียนประวัติ")
|
||||
_profile.isRetirement = true;
|
||||
_profile.isLeave = true;
|
||||
_profile.isActive = false
|
||||
_profile.leaveType = "RETIRE";
|
||||
_profile.leaveDate = new Date();
|
||||
_profile.dateLeave = new Date();
|
||||
_profile.lastUpdatedAt = new Date();
|
||||
profiles.push(_profile);
|
||||
_profile.leaveReason = "เกษียณอายุราชการ";
|
||||
_profile.leaveDate = _Date;
|
||||
_profile.dateLeave = _Date;
|
||||
_profile.lastUpdatedAt = _Date;
|
||||
if (_profile.keycloak != null && _profile.keycloak != "") {
|
||||
// console.log("4. disable keycloak/authen")
|
||||
const delUserKeycloak = await deleteUser(_profile.keycloak);
|
||||
if (delUserKeycloak) {
|
||||
_profile.keycloak = "";
|
||||
_profile.roleKeycloaks = [];
|
||||
}
|
||||
}
|
||||
// profiles.push(_profile);
|
||||
// console.log("5. save profile ",_profile)
|
||||
await this.profileRepository.save(_profile);
|
||||
}
|
||||
}),
|
||||
);
|
||||
await this.profileRepository.save(profiles);
|
||||
}
|
||||
} catch {}
|
||||
|
||||
|
|
@ -1542,29 +1566,137 @@ export class CommandController extends Controller {
|
|||
},
|
||||
},
|
||||
);
|
||||
if (response && response_.data.result.length > 0) {
|
||||
let profiles: ProfileEmployee[] = [];
|
||||
if (response_ && response_.data.result) {
|
||||
let signDate:string = ""
|
||||
if (response_.data.result.signDate != null) {
|
||||
signDate = Extension.ToThaiShortDate_noPrefix(new Date(response_.data.result.signDate))
|
||||
}
|
||||
else {
|
||||
signDate = Extension.ToThaiShortDate_noPrefix(_Date)
|
||||
}
|
||||
// let profiles: ProfileEmployee[] = [];
|
||||
await Promise.all(
|
||||
response_.data.result.map(async (x: any) => {
|
||||
const _profileEmp = await this.profileEmployeeRepository.findOneBy({ id: x.profileId });
|
||||
if (_profileEmp) {
|
||||
// บันทึกลงประวัติตำแหน่ง
|
||||
await this.profileSalaryRetire(x.profileId, type, signDate, _Date);
|
||||
// ปลดออกจากโครงสร้าง
|
||||
await this.posMasterRetire(x.profileId, type, _Date);
|
||||
// แก้ไขสถานะในทะเบียนประวัติ
|
||||
_profileEmp.isRetirement = true;
|
||||
_profileEmp.isLeave = true;
|
||||
_profileEmp.isActive = false
|
||||
_profileEmp.leaveType = "RETIRE";
|
||||
_profileEmp.leaveDate = new Date();
|
||||
_profileEmp.dateLeave = new Date();
|
||||
_profileEmp.lastUpdatedAt = new Date();
|
||||
profiles.push(_profileEmp);
|
||||
_profileEmp.leaveReason = "เกษียณอายุราชการ";
|
||||
_profileEmp.leaveDate = _Date;
|
||||
_profileEmp.dateLeave = _Date;
|
||||
_profileEmp.lastUpdatedAt = _Date;
|
||||
if (_profileEmp.keycloak != null && _profileEmp.keycloak != "") {
|
||||
// disable keycloak/authen
|
||||
const delUserKeycloak = await deleteUser(_profileEmp.keycloak);
|
||||
if (delUserKeycloak) {
|
||||
_profileEmp.keycloak = "";
|
||||
_profileEmp.roleKeycloaks = [];
|
||||
}
|
||||
}
|
||||
// profiles.push(_profileEmp);
|
||||
await this.profileEmployeeRepository.save(_profileEmp);
|
||||
}
|
||||
}),
|
||||
);
|
||||
await this.profileEmployeeRepository.save(profiles);
|
||||
}
|
||||
} catch {}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
async profileSalaryRetire(profileId: string, type: string, signDate: string, _Date: Date) {
|
||||
const whereKey = type == "OFFICER"
|
||||
? { profileId: profileId }
|
||||
: { profileEmployeeId: profileId };
|
||||
const maxOrder = await this.salaryRepo.findOne({
|
||||
select: { order: true },
|
||||
where: whereKey,
|
||||
order: { order: "DESC" },
|
||||
});
|
||||
const data: any = {
|
||||
order: maxOrder ? maxOrder.order + 1 : 1,
|
||||
amount: null,
|
||||
positionSalaryAmount: null,
|
||||
mouthSalaryAmount: null,
|
||||
profileId: profileId,
|
||||
posNo: null,
|
||||
positionExecutive: null,
|
||||
positionType: null,
|
||||
positionLevel: null,
|
||||
amountSpecial: null,
|
||||
orgRoot: null,
|
||||
orgChild1: null,
|
||||
orgChild2: null,
|
||||
orgChild3: null,
|
||||
orgChild4: null,
|
||||
commandYear: _Date.getFullYear() + 543,
|
||||
commandDateAffect: _Date,
|
||||
commandCode: "16",
|
||||
commandName: "พ้นจากราชการ",
|
||||
posNoAbb: null,
|
||||
isEntry: false,
|
||||
positionName: "เกษียณอายุราชการ",
|
||||
createdUserId: "",
|
||||
createdFullName: "System Administrator",
|
||||
lastUpdateUserId: "",
|
||||
lastUpdateFullName: "System Administrator",
|
||||
createdAt: _Date,
|
||||
lastUpdatedAt: _Date,
|
||||
remark: `ประกาศคณะอนุกรรมการสามัญข้าราชการกรุงเทพมหานครสามัญ ลว. ${signDate}`, // script เกษียณจริง ๆ ให้เอา “วันที่ประกาศเกษียณฉบับแรก” มาลงในเอกสารอ้างอิง
|
||||
isGovernment: false,
|
||||
};
|
||||
const history = new ProfileSalaryHistory();
|
||||
Object.assign(history, { ...data, id: undefined });
|
||||
data.dateGovernment = _Date;
|
||||
const savedData = await this.salaryRepo.save(data);
|
||||
history.profileSalaryId = savedData.id;
|
||||
await this.salaryHistoryRepo.save(history);
|
||||
}
|
||||
|
||||
async posMasterRetire(profileId: string, type: string, _Date: Date) {
|
||||
const orgRevision = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }
|
||||
});
|
||||
if (orgRevision) {
|
||||
let _posMaster:any = null;
|
||||
if (type == "OFFICER") {
|
||||
_posMaster = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
orgRevisionId: orgRevision.id,
|
||||
current_holderId: profileId,
|
||||
},
|
||||
});
|
||||
if (_posMaster) {
|
||||
_posMaster.current_holderId = null;
|
||||
_posMaster.lastUpdateFullName = "System Administrator";
|
||||
_posMaster.lastUpdatedAt = _Date;
|
||||
await this.posMasterRepository.save(_posMaster);
|
||||
}
|
||||
}
|
||||
else if (type == "EMPLOYEE") {
|
||||
_posMaster = await this.employeePosMasterRepository.findOne({
|
||||
where: {
|
||||
orgRevisionId: orgRevision.id,
|
||||
current_holderId: profileId,
|
||||
},
|
||||
});
|
||||
if (_posMaster) {
|
||||
_posMaster.current_holderId = null;
|
||||
_posMaster.lastUpdateFullName = "System Administrator";
|
||||
_posMaster.lastUpdatedAt = _Date;
|
||||
await this.employeePosMasterRepository.save(_posMaster);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Get("cornjob/cronjobUpdateRetirementStatus")
|
||||
async runCronjobUpdateRetirementStatus() {
|
||||
await this.cronjobUpdateRetirementStatus();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue