[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 { OrgRoot } from "../entities/OrgRoot";
|
||||
import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster";
|
||||
import { ProfileInsignia, CreateProfileInsignia } from "../entities/ProfileInsignia";
|
||||
import { ProfileInsigniaHistory } from "../entities/ProfileInsigniaHistory";
|
||||
@Route("api/v1/org/command")
|
||||
@Tags("Command")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -137,6 +139,8 @@ export class CommandController extends Controller {
|
|||
private profileFamilyFatherRepo = AppDataSource.getRepository(ProfileFamilyFather);
|
||||
private profileFamilyFatherHistoryRepo = AppDataSource.getRepository(ProfileFamilyFatherHistory);
|
||||
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
|
||||
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
|
||||
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
|
||||
|
||||
/**
|
||||
* API list รายการคำสั่ง
|
||||
|
|
@ -5463,10 +5467,59 @@ export class CommandController extends Controller {
|
|||
|
||||
let profile: any = await this.profileRepository.findOne({
|
||||
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.dateRetire = _dateRetire;
|
||||
profile.dateRetireLaw = _dateRetireLaw;
|
||||
|
|
@ -5490,7 +5543,6 @@ export class CommandController extends Controller {
|
|||
profile.amount = item.bodyProfile.amount ?? null;
|
||||
profile.amountSpecial = item.bodyProfile.amountSpecial ?? null;
|
||||
profile.isProbation = item.bodyProfile.isProbation;
|
||||
|
||||
//เพิ่มใหม่จากรับโอน
|
||||
profile.prefix = item.bodyProfile.prefix ?? null;
|
||||
profile.firstName = item.bodyProfile.firstName ?? null;
|
||||
|
|
@ -5509,90 +5561,133 @@ export class CommandController extends Controller {
|
|||
}
|
||||
//ขรก.ในระบบ หรือ ขรก.ในระบบที่สถานะพ้นจากราชการ
|
||||
else {
|
||||
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
|
||||
profile.keycloak =
|
||||
userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : "";
|
||||
profile.isProbation = item.bodyProfile.isProbation;
|
||||
profile.isLeave = item.bodyProfile.isLeave;
|
||||
profile.isRetirement = false;
|
||||
profile.isActive = true;
|
||||
profile.dateLeave = _null;
|
||||
profile.dateRetire = _dateRetire;
|
||||
profile.dateRetireLaw = _dateRetireLaw;
|
||||
profile.registrationProvinceId = registrationProvinceId
|
||||
? registrationProvinceId.id
|
||||
: _null;
|
||||
profile.registrationDistrictId = registrationDistrictId
|
||||
? registrationDistrictId.id
|
||||
: _null;
|
||||
profile.registrationSubDistrictId = registrationSubDistrictId
|
||||
? registrationSubDistrictId.id
|
||||
: _null;
|
||||
profile.currentProvinceId = currentProvinceId ? currentProvinceId.id : _null;
|
||||
profile.currentDistrictId = currentDistrictId ? currentDistrictId.id : _null;
|
||||
profile.currentSubDistrictId = currentSubDistrictId ? currentSubDistrictId.id : _null;
|
||||
profile.email = item.bodyProfile.email;
|
||||
profile.telephoneNumber = item.bodyProfile.telephoneNumber;
|
||||
profile.phone = item.bodyProfile.phone;
|
||||
profile.dateStart = item.bodyProfile.dateStart;
|
||||
profile.amount = item.bodyProfile.amount ?? null;
|
||||
profile.amountSpecial = item.bodyProfile.amountSpecial ?? null;
|
||||
profile.leaveCommandId = _null;
|
||||
profile.leaveCommandNo = _null;
|
||||
profile.leaveRemark = _null;
|
||||
profile.leaveDate = _null;
|
||||
profile.leaveType = _null;
|
||||
profile.leaveReason = _null;
|
||||
profile.lastUpdateUserId = req.user.sub;
|
||||
profile.lastUpdateFullName = req.user.name;
|
||||
profile.lastUpdatedAt = new Date();
|
||||
|
||||
//เพิ่มใหม่จากรับโอน
|
||||
profile.prefix =
|
||||
item.bodyProfile.prefix && item.bodyProfile.prefix != ""
|
||||
? 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.isLeave && ["PLACEMENT_TRANSFER", "RETIRE_RESIGN"].includes(profile.leaveType)) {
|
||||
if (profile.profileInsignias.length > 0) {
|
||||
_oldInsigniaIds = profile.profileInsignias.map((x:any) => x.id);
|
||||
}
|
||||
profile = Object.assign({ ...item.bodyProfile, ...meta });
|
||||
profile.dateRetire = _dateRetire;
|
||||
profile.dateRetireLaw = _dateRetireLaw;
|
||||
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
|
||||
profile.keycloak =
|
||||
userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : "";
|
||||
profile.registrationProvinceId = registrationProvinceId
|
||||
? registrationProvinceId.id
|
||||
: _null;
|
||||
profile.registrationDistrictId = registrationDistrictId
|
||||
? registrationDistrictId.id
|
||||
: _null;
|
||||
profile.registrationSubDistrictId = registrationSubDistrictId
|
||||
? registrationSubDistrictId.id
|
||||
: _null;
|
||||
profile.currentProvinceId = currentProvinceId ? currentProvinceId.id : _null;
|
||||
profile.currentDistrictId = currentDistrictId ? currentDistrictId.id : _null;
|
||||
profile.currentSubDistrictId = currentSubDistrictId ? currentSubDistrictId.id : _null;
|
||||
profile.email = item.bodyProfile.email;
|
||||
profile.dateStart = item.bodyProfile.dateStart;
|
||||
profile.amount = item.bodyProfile.amount ?? null;
|
||||
profile.amountSpecial = item.bodyProfile.amountSpecial ?? null;
|
||||
profile.isProbation = item.bodyProfile.isProbation;
|
||||
profile.prefix = item.bodyProfile.prefix ?? null;
|
||||
profile.firstName = item.bodyProfile.firstName ?? null;
|
||||
profile.lastName = item.bodyProfile.lastName ?? null;
|
||||
profile.birthDate = item.bodyProfile.birthDate ?? null;
|
||||
profile.gender = item.bodyProfile.gender ?? null;
|
||||
profile.relationship = item.bodyProfile.relationship ?? null;
|
||||
profile.religion = item.bodyProfile.religion ?? null;
|
||||
profile.ethnicity = item.bodyProfile.ethnicity;
|
||||
profile.nationality = item.bodyProfile.nationality ?? null;
|
||||
profile.bloodGroup = item.bodyProfile.bloodGroup ?? null;
|
||||
profile.phone = item.bodyProfile.phone ?? null;
|
||||
await this.profileRepository.save(profile);
|
||||
setLogDataDiff(req, { before, after: profile });
|
||||
}
|
||||
else {
|
||||
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
|
||||
profile.keycloak =
|
||||
userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : "";
|
||||
profile.isProbation = item.bodyProfile.isProbation;
|
||||
profile.isLeave = item.bodyProfile.isLeave;
|
||||
profile.isRetirement = false;
|
||||
profile.isActive = true;
|
||||
profile.dateLeave = _null;
|
||||
profile.dateRetire = _dateRetire;
|
||||
profile.dateRetireLaw = _dateRetireLaw;
|
||||
profile.registrationProvinceId = registrationProvinceId
|
||||
? registrationProvinceId.id
|
||||
: _null;
|
||||
profile.registrationDistrictId = registrationDistrictId
|
||||
? registrationDistrictId.id
|
||||
: _null;
|
||||
profile.registrationSubDistrictId = registrationSubDistrictId
|
||||
? registrationSubDistrictId.id
|
||||
: _null;
|
||||
profile.currentProvinceId = currentProvinceId ? currentProvinceId.id : _null;
|
||||
profile.currentDistrictId = currentDistrictId ? currentDistrictId.id : _null;
|
||||
profile.currentSubDistrictId = currentSubDistrictId ? currentSubDistrictId.id : _null;
|
||||
profile.email = item.bodyProfile.email;
|
||||
profile.telephoneNumber = item.bodyProfile.telephoneNumber;
|
||||
profile.phone = item.bodyProfile.phone;
|
||||
profile.dateStart = item.bodyProfile.dateStart;
|
||||
profile.amount = item.bodyProfile.amount ?? null;
|
||||
profile.amountSpecial = item.bodyProfile.amountSpecial ?? null;
|
||||
profile.leaveCommandId = _null;
|
||||
profile.leaveCommandNo = _null;
|
||||
profile.leaveRemark = _null;
|
||||
profile.leaveDate = _null;
|
||||
profile.leaveType = _null;
|
||||
profile.leaveReason = _null;
|
||||
profile.lastUpdateUserId = req.user.sub;
|
||||
profile.lastUpdateFullName = req.user.name;
|
||||
profile.lastUpdatedAt = new Date();
|
||||
//เพิ่มใหม่จากรับโอน
|
||||
profile.prefix =
|
||||
item.bodyProfile.prefix && item.bodyProfile.prefix != ""
|
||||
? 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) {
|
||||
|
|
@ -5786,6 +5881,40 @@ export class CommandController extends Controller {
|
|||
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