[Edit SIT บรรจุ แต่งตั้ง] กรณีลาออก หรือโอนออกไปแล้วกลับเข้ารับราชการใหม่ด้วยการสอบ #1341
This commit is contained in:
parent
7c4f6249b8
commit
9bd15c94b3
1 changed files with 216 additions and 87 deletions
|
|
@ -87,6 +87,8 @@ import { ProfileFamilyMother } from "../entities/ProfileFamilyMother";
|
||||||
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
|
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
|
||||||
import { OrgRoot } from "../entities/OrgRoot";
|
import { OrgRoot } from "../entities/OrgRoot";
|
||||||
import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster";
|
import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster";
|
||||||
|
import { ProfileInsignia, CreateProfileInsignia } from "../entities/ProfileInsignia";
|
||||||
|
import { ProfileInsigniaHistory } from "../entities/ProfileInsigniaHistory";
|
||||||
@Route("api/v1/org/command")
|
@Route("api/v1/org/command")
|
||||||
@Tags("Command")
|
@Tags("Command")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -137,6 +139,8 @@ export class CommandController extends Controller {
|
||||||
private profileFamilyFatherRepo = AppDataSource.getRepository(ProfileFamilyFather);
|
private profileFamilyFatherRepo = AppDataSource.getRepository(ProfileFamilyFather);
|
||||||
private profileFamilyFatherHistoryRepo = AppDataSource.getRepository(ProfileFamilyFatherHistory);
|
private profileFamilyFatherHistoryRepo = AppDataSource.getRepository(ProfileFamilyFatherHistory);
|
||||||
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
|
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
|
||||||
|
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
|
||||||
|
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API list รายการคำสั่ง
|
* API list รายการคำสั่ง
|
||||||
|
|
@ -5463,10 +5467,59 @@ export class CommandController extends Controller {
|
||||||
|
|
||||||
let profile: any = await this.profileRepository.findOne({
|
let profile: any = await this.profileRepository.findOne({
|
||||||
where: { citizenId: item.bodyProfile.citizenId /*, isActive: true */ },
|
where: { citizenId: item.bodyProfile.citizenId /*, isActive: true */ },
|
||||||
relations: ["roleKeycloaks"],
|
relations: ["roleKeycloaks", "profileInsignias"],
|
||||||
});
|
});
|
||||||
|
let _oldInsigniaIds: string[] = [];
|
||||||
|
if (!profile) {
|
||||||
|
//กรณีลูกจ้างประจำมาสอบเป็นข้าราชการ ต้อง update สถานะโปรไฟล์เดิม
|
||||||
|
let profileEmployee: any = await this.profileEmployeeRepository.findOne({
|
||||||
|
where: { citizenId: item.bodyProfile.citizenId },
|
||||||
|
relations: ["profileInsignias"],
|
||||||
|
});
|
||||||
|
if (profileEmployee) {
|
||||||
|
const _order = await this.salaryRepo.findOne({
|
||||||
|
where: { profileEmployeeId: profileEmployee.id },
|
||||||
|
order: { order: "DESC" },
|
||||||
|
});
|
||||||
|
const profileEmpSalary = new ProfileSalary();
|
||||||
|
profileEmpSalary.posNumCodeSit = _posNumCodeSit;
|
||||||
|
profileEmpSalary.posNumCodeSitAbb = _posNumCodeSitAbb;
|
||||||
|
profileEmpSalary.order = _order == null ? 1 : _order.order + 1;
|
||||||
|
Object.assign(profileEmpSalary, {
|
||||||
|
...item.bodySalarys,
|
||||||
|
...meta,
|
||||||
|
profileEmployeeId: profileEmployee.id,
|
||||||
|
profileId: undefined,
|
||||||
|
});
|
||||||
|
const history = new ProfileSalaryHistory();
|
||||||
|
Object.assign(history, { ...profileEmpSalary, id: undefined });
|
||||||
|
profileEmpSalary.dateGovernment = meta.createdAt;
|
||||||
|
profileEmpSalary.profileId = _null,
|
||||||
|
await this.salaryRepo.save(profileEmpSalary, { data: req });
|
||||||
|
setLogDataDiff(req, { before, after: profileEmpSalary });
|
||||||
|
history.profileSalaryId = profileEmpSalary.id;
|
||||||
|
await this.salaryHistoryRepo.save(history, { data: req });
|
||||||
|
|
||||||
if (!profile) {
|
if (profileEmployee.profileInsignias.length > 0) {
|
||||||
|
_oldInsigniaIds = profileEmployee.profileInsignias.map((x:any) => x.id);
|
||||||
|
}
|
||||||
|
await removeProfileInOrganize(profileEmployee.id, "EMPLOYEE");
|
||||||
|
if (profileEmployee.keycloak != null) {
|
||||||
|
const delUserKeycloak = await deleteUser(profileEmployee.keycloak);
|
||||||
|
if (delUserKeycloak) {
|
||||||
|
profileEmployee.keycloak = _null;
|
||||||
|
profileEmployee.roleKeycloaks = [];
|
||||||
|
profileEmployee.isActive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
profileEmployee.isLeave = true;
|
||||||
|
profileEmployee.leaveReason = "บรรจุข้าราชการ";
|
||||||
|
profileEmployee.lastUpdateUserId = req.user.sub;
|
||||||
|
profileEmployee.lastUpdateFullName = req.user.name;
|
||||||
|
profileEmployee.lastUpdatedAt = new Date();
|
||||||
|
await this.profileEmployeeRepository.save(profileEmployee);
|
||||||
|
setLogDataDiff(req, { before, after: profileEmployee });
|
||||||
|
}
|
||||||
profile = Object.assign({ ...item.bodyProfile, ...meta });
|
profile = Object.assign({ ...item.bodyProfile, ...meta });
|
||||||
profile.dateRetire = _dateRetire;
|
profile.dateRetire = _dateRetire;
|
||||||
profile.dateRetireLaw = _dateRetireLaw;
|
profile.dateRetireLaw = _dateRetireLaw;
|
||||||
|
|
@ -5490,7 +5543,6 @@ export class CommandController extends Controller {
|
||||||
profile.amount = item.bodyProfile.amount ?? null;
|
profile.amount = item.bodyProfile.amount ?? null;
|
||||||
profile.amountSpecial = item.bodyProfile.amountSpecial ?? null;
|
profile.amountSpecial = item.bodyProfile.amountSpecial ?? null;
|
||||||
profile.isProbation = item.bodyProfile.isProbation;
|
profile.isProbation = item.bodyProfile.isProbation;
|
||||||
|
|
||||||
//เพิ่มใหม่จากรับโอน
|
//เพิ่มใหม่จากรับโอน
|
||||||
profile.prefix = item.bodyProfile.prefix ?? null;
|
profile.prefix = item.bodyProfile.prefix ?? null;
|
||||||
profile.firstName = item.bodyProfile.firstName ?? null;
|
profile.firstName = item.bodyProfile.firstName ?? null;
|
||||||
|
|
@ -5509,90 +5561,133 @@ export class CommandController extends Controller {
|
||||||
}
|
}
|
||||||
//ขรก.ในระบบ หรือ ขรก.ในระบบที่สถานะพ้นจากราชการ
|
//ขรก.ในระบบ หรือ ขรก.ในระบบที่สถานะพ้นจากราชการ
|
||||||
else {
|
else {
|
||||||
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
|
//สร้างโปรไฟล์ใหม่ ถ้าสถานะพ้นราชการ คำสั่งโอนออกหรือคำสั่งขอลาออก
|
||||||
profile.keycloak =
|
if (profile.isLeave && ["PLACEMENT_TRANSFER", "RETIRE_RESIGN"].includes(profile.leaveType)) {
|
||||||
userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : "";
|
if (profile.profileInsignias.length > 0) {
|
||||||
profile.isProbation = item.bodyProfile.isProbation;
|
_oldInsigniaIds = profile.profileInsignias.map((x:any) => x.id);
|
||||||
profile.isLeave = item.bodyProfile.isLeave;
|
}
|
||||||
profile.isRetirement = false;
|
profile = Object.assign({ ...item.bodyProfile, ...meta });
|
||||||
profile.isActive = true;
|
profile.dateRetire = _dateRetire;
|
||||||
profile.dateLeave = _null;
|
profile.dateRetireLaw = _dateRetireLaw;
|
||||||
profile.dateRetire = _dateRetire;
|
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
|
||||||
profile.dateRetireLaw = _dateRetireLaw;
|
profile.keycloak =
|
||||||
profile.registrationProvinceId = registrationProvinceId
|
userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : "";
|
||||||
? registrationProvinceId.id
|
profile.registrationProvinceId = registrationProvinceId
|
||||||
: _null;
|
? registrationProvinceId.id
|
||||||
profile.registrationDistrictId = registrationDistrictId
|
: _null;
|
||||||
? registrationDistrictId.id
|
profile.registrationDistrictId = registrationDistrictId
|
||||||
: _null;
|
? registrationDistrictId.id
|
||||||
profile.registrationSubDistrictId = registrationSubDistrictId
|
: _null;
|
||||||
? registrationSubDistrictId.id
|
profile.registrationSubDistrictId = registrationSubDistrictId
|
||||||
: _null;
|
? registrationSubDistrictId.id
|
||||||
profile.currentProvinceId = currentProvinceId ? currentProvinceId.id : _null;
|
: _null;
|
||||||
profile.currentDistrictId = currentDistrictId ? currentDistrictId.id : _null;
|
profile.currentProvinceId = currentProvinceId ? currentProvinceId.id : _null;
|
||||||
profile.currentSubDistrictId = currentSubDistrictId ? currentSubDistrictId.id : _null;
|
profile.currentDistrictId = currentDistrictId ? currentDistrictId.id : _null;
|
||||||
profile.email = item.bodyProfile.email;
|
profile.currentSubDistrictId = currentSubDistrictId ? currentSubDistrictId.id : _null;
|
||||||
profile.telephoneNumber = item.bodyProfile.telephoneNumber;
|
profile.email = item.bodyProfile.email;
|
||||||
profile.phone = item.bodyProfile.phone;
|
profile.dateStart = item.bodyProfile.dateStart;
|
||||||
profile.dateStart = item.bodyProfile.dateStart;
|
profile.amount = item.bodyProfile.amount ?? null;
|
||||||
profile.amount = item.bodyProfile.amount ?? null;
|
profile.amountSpecial = item.bodyProfile.amountSpecial ?? null;
|
||||||
profile.amountSpecial = item.bodyProfile.amountSpecial ?? null;
|
profile.isProbation = item.bodyProfile.isProbation;
|
||||||
profile.leaveCommandId = _null;
|
profile.prefix = item.bodyProfile.prefix ?? null;
|
||||||
profile.leaveCommandNo = _null;
|
profile.firstName = item.bodyProfile.firstName ?? null;
|
||||||
profile.leaveRemark = _null;
|
profile.lastName = item.bodyProfile.lastName ?? null;
|
||||||
profile.leaveDate = _null;
|
profile.birthDate = item.bodyProfile.birthDate ?? null;
|
||||||
profile.leaveType = _null;
|
profile.gender = item.bodyProfile.gender ?? null;
|
||||||
profile.leaveReason = _null;
|
profile.relationship = item.bodyProfile.relationship ?? null;
|
||||||
profile.lastUpdateUserId = req.user.sub;
|
profile.religion = item.bodyProfile.religion ?? null;
|
||||||
profile.lastUpdateFullName = req.user.name;
|
profile.ethnicity = item.bodyProfile.ethnicity;
|
||||||
profile.lastUpdatedAt = new Date();
|
profile.nationality = item.bodyProfile.nationality ?? null;
|
||||||
|
profile.bloodGroup = item.bodyProfile.bloodGroup ?? null;
|
||||||
//เพิ่มใหม่จากรับโอน
|
profile.phone = item.bodyProfile.phone ?? null;
|
||||||
profile.prefix =
|
await this.profileRepository.save(profile);
|
||||||
item.bodyProfile.prefix && item.bodyProfile.prefix != ""
|
setLogDataDiff(req, { before, after: profile });
|
||||||
? item.bodyProfile.prefix
|
}
|
||||||
: profile.prefix;
|
else {
|
||||||
profile.firstName =
|
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
|
||||||
item.bodyProfile.firstName && item.bodyProfile.firstName != ""
|
profile.keycloak =
|
||||||
? item.bodyProfile.firstName
|
userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : "";
|
||||||
: profile.firstName;
|
profile.isProbation = item.bodyProfile.isProbation;
|
||||||
profile.lastName =
|
profile.isLeave = item.bodyProfile.isLeave;
|
||||||
item.bodyProfile.lastName && item.bodyProfile.lastName != ""
|
profile.isRetirement = false;
|
||||||
? item.bodyProfile.lastName
|
profile.isActive = true;
|
||||||
: profile.lastName;
|
profile.dateLeave = _null;
|
||||||
profile.birthDate = item.bodyProfile.birthDate
|
profile.dateRetire = _dateRetire;
|
||||||
? item.bodyProfile.birthDate
|
profile.dateRetireLaw = _dateRetireLaw;
|
||||||
: profile.birthDate;
|
profile.registrationProvinceId = registrationProvinceId
|
||||||
profile.gender =
|
? registrationProvinceId.id
|
||||||
item.bodyProfile.gender && item.bodyProfile.gender != ""
|
: _null;
|
||||||
? item.bodyProfile.gender
|
profile.registrationDistrictId = registrationDistrictId
|
||||||
: profile.gender;
|
? registrationDistrictId.id
|
||||||
profile.relationship =
|
: _null;
|
||||||
item.bodyProfile.relationship && item.bodyProfile.relationship != ""
|
profile.registrationSubDistrictId = registrationSubDistrictId
|
||||||
? item.bodyProfile.relationship
|
? registrationSubDistrictId.id
|
||||||
: profile.relationship;
|
: _null;
|
||||||
profile.religion =
|
profile.currentProvinceId = currentProvinceId ? currentProvinceId.id : _null;
|
||||||
item.bodyProfile.religion && item.bodyProfile.religion != ""
|
profile.currentDistrictId = currentDistrictId ? currentDistrictId.id : _null;
|
||||||
? item.bodyProfile.religion
|
profile.currentSubDistrictId = currentSubDistrictId ? currentSubDistrictId.id : _null;
|
||||||
: profile.religion;
|
profile.email = item.bodyProfile.email;
|
||||||
profile.ethnicity =
|
profile.telephoneNumber = item.bodyProfile.telephoneNumber;
|
||||||
item.bodyProfile.ethnicity && item.bodyProfile.ethnicity != ""
|
profile.phone = item.bodyProfile.phone;
|
||||||
? item.bodyProfile.ethnicity
|
profile.dateStart = item.bodyProfile.dateStart;
|
||||||
: profile.ethnicity;
|
profile.amount = item.bodyProfile.amount ?? null;
|
||||||
profile.nationality =
|
profile.amountSpecial = item.bodyProfile.amountSpecial ?? null;
|
||||||
item.bodyProfile.nationality && item.bodyProfile.nationality != ""
|
profile.leaveCommandId = _null;
|
||||||
? item.bodyProfile.nationality
|
profile.leaveCommandNo = _null;
|
||||||
: profile.nationality;
|
profile.leaveRemark = _null;
|
||||||
profile.bloodGroup =
|
profile.leaveDate = _null;
|
||||||
item.bodyProfile.bloodGroup && item.bodyProfile.bloodGroup != ""
|
profile.leaveType = _null;
|
||||||
? item.bodyProfile.bloodGroup
|
profile.leaveReason = _null;
|
||||||
: profile.bloodGroup;
|
profile.lastUpdateUserId = req.user.sub;
|
||||||
profile.phone =
|
profile.lastUpdateFullName = req.user.name;
|
||||||
item.bodyProfile.phone && item.bodyProfile.phone != ""
|
profile.lastUpdatedAt = new Date();
|
||||||
? item.bodyProfile.phone
|
//เพิ่มใหม่จากรับโอน
|
||||||
: profile.phone;
|
profile.prefix =
|
||||||
await this.profileRepository.save(profile);
|
item.bodyProfile.prefix && item.bodyProfile.prefix != ""
|
||||||
setLogDataDiff(req, { before, after: profile });
|
? item.bodyProfile.prefix
|
||||||
|
: profile.prefix;
|
||||||
|
profile.firstName =
|
||||||
|
item.bodyProfile.firstName && item.bodyProfile.firstName != ""
|
||||||
|
? item.bodyProfile.firstName
|
||||||
|
: profile.firstName;
|
||||||
|
profile.lastName =
|
||||||
|
item.bodyProfile.lastName && item.bodyProfile.lastName != ""
|
||||||
|
? item.bodyProfile.lastName
|
||||||
|
: profile.lastName;
|
||||||
|
profile.birthDate = item.bodyProfile.birthDate
|
||||||
|
? item.bodyProfile.birthDate
|
||||||
|
: profile.birthDate;
|
||||||
|
profile.gender =
|
||||||
|
item.bodyProfile.gender && item.bodyProfile.gender != ""
|
||||||
|
? item.bodyProfile.gender
|
||||||
|
: profile.gender;
|
||||||
|
profile.relationship =
|
||||||
|
item.bodyProfile.relationship && item.bodyProfile.relationship != ""
|
||||||
|
? item.bodyProfile.relationship
|
||||||
|
: profile.relationship;
|
||||||
|
profile.religion =
|
||||||
|
item.bodyProfile.religion && item.bodyProfile.religion != ""
|
||||||
|
? item.bodyProfile.religion
|
||||||
|
: profile.religion;
|
||||||
|
profile.ethnicity =
|
||||||
|
item.bodyProfile.ethnicity && item.bodyProfile.ethnicity != ""
|
||||||
|
? item.bodyProfile.ethnicity
|
||||||
|
: profile.ethnicity;
|
||||||
|
profile.nationality =
|
||||||
|
item.bodyProfile.nationality && item.bodyProfile.nationality != ""
|
||||||
|
? item.bodyProfile.nationality
|
||||||
|
: profile.nationality;
|
||||||
|
profile.bloodGroup =
|
||||||
|
item.bodyProfile.bloodGroup && item.bodyProfile.bloodGroup != ""
|
||||||
|
? item.bodyProfile.bloodGroup
|
||||||
|
: profile.bloodGroup;
|
||||||
|
profile.phone =
|
||||||
|
item.bodyProfile.phone && item.bodyProfile.phone != ""
|
||||||
|
? item.bodyProfile.phone
|
||||||
|
: profile.phone;
|
||||||
|
await this.profileRepository.save(profile);
|
||||||
|
setLogDataDiff(req, { before, after: profile });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profile && profile.id) {
|
if (profile && profile.id) {
|
||||||
|
|
@ -5786,6 +5881,40 @@ export class CommandController extends Controller {
|
||||||
await this.positionRepository.save(positionNew, { data: req });
|
await this.positionRepository.save(positionNew, { data: req });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Insignia
|
||||||
|
if(_oldInsigniaIds.length > 0) {
|
||||||
|
const _insignias = await this.insigniaRepo.find({
|
||||||
|
where: { id: In(_oldInsigniaIds) },
|
||||||
|
order: { createdAt: "ASC" },
|
||||||
|
});
|
||||||
|
for (const oldInsignia of _insignias) {
|
||||||
|
const newInsigniaData: CreateProfileInsignia = {
|
||||||
|
profileId: profile.id,
|
||||||
|
year: oldInsignia.year,
|
||||||
|
no: oldInsignia.no,
|
||||||
|
volume: oldInsignia.volume,
|
||||||
|
section: oldInsignia.section,
|
||||||
|
page: oldInsignia.page,
|
||||||
|
receiveDate: oldInsignia.receiveDate,
|
||||||
|
insigniaId: oldInsignia.insigniaId,
|
||||||
|
dateAnnounce: oldInsignia.dateAnnounce,
|
||||||
|
issue: oldInsignia.issue,
|
||||||
|
volumeNo: oldInsignia.volumeNo,
|
||||||
|
refCommandDate: oldInsignia.refCommandDate,
|
||||||
|
refCommandNo: oldInsignia.refCommandNo,
|
||||||
|
note: oldInsignia.note,
|
||||||
|
isUpload: oldInsignia.isUpload,
|
||||||
|
};
|
||||||
|
const insignia = new ProfileInsignia();
|
||||||
|
Object.assign(insignia, { ...newInsigniaData, ...meta });
|
||||||
|
const history = new ProfileInsigniaHistory();
|
||||||
|
Object.assign(history, { ...insignia, id: undefined });
|
||||||
|
await this.insigniaRepo.save(insignia, { data: req });
|
||||||
|
setLogDataDiff(req, { before, after: insignia });
|
||||||
|
history.profileInsigniaId = insignia.id;
|
||||||
|
await this.insigniaHistoryRepo.save(history, { data: req });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue