set null ตำแหน่งติดเงื่อนไข

This commit is contained in:
mamoss 2025-06-26 11:58:44 +07:00
parent f307484707
commit dda4488409
4 changed files with 198 additions and 113 deletions

View file

@ -3083,6 +3083,7 @@ export class CommandController extends Controller {
}
posMaster.current_holderId = item.profileId;
posMaster.conditionReason = _null;
if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld);
await this.posMasterRepository.save(posMaster);
@ -3333,7 +3334,7 @@ export class CommandController extends Controller {
positionTypeNew?: string | null;
positionLevelNew?: string | null;
positionNameNew?: string | null;
posmasterId?: string| null;
posmasterId?: string | null;
posTypeNameNew?: string | null;
posLevelNameNew?: string | null;
posNoNew?: string | null;
@ -3403,7 +3404,7 @@ export class CommandController extends Controller {
}
let _commandYear = item.commandYear;
if (item.commandYear) {
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear+543
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543;
}
const returnWork = await checkReturnCommandType(String(item.commandId));
const dest_item = await this.salaryRepo.findOne({
@ -3424,7 +3425,7 @@ export class CommandController extends Controller {
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
if(!returnWork) {
if (!returnWork) {
Object.assign(data, { ...item, ...meta });
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
@ -3486,13 +3487,14 @@ export class CommandController extends Controller {
await this.positionRepository.save(clearPosition);
}
posMaster.current_holderId = profile.id;
posMaster.conditionReason = _null;
await this.posMasterRepository.save(posMaster);
const positionNew = await this.positionRepository.findOne({
where: {
posMasterId: posMaster.id,
},
});
if(positionNew) {
if (positionNew) {
positionNew.positionIsSelected = true;
await this.positionRepository.save(positionNew, { data: req });
}
@ -3523,7 +3525,7 @@ export class CommandController extends Controller {
commandName: item.commandName,
remark: item.remark,
};
Object.assign(data, {...newMapProfileSalary, ...meta});
Object.assign(data, { ...newMapProfileSalary, ...meta });
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
await this.salaryRepo.save(data);
@ -3552,10 +3554,15 @@ export class CommandController extends Controller {
// profile.birthDate.toISOString().slice(5, 7) +
// gregorianYear;
// password = formattedDate;
const _date = new Date(profile.birthDate.toDateString()).getDate().toString().padStart(2, "0");
const _month = (new Date(profile.birthDate.toDateString()).getMonth()+1).toString().padStart(2, "0");
const _year = (new Date(profile.birthDate.toDateString()).getFullYear()+543);
password = `${_date}${_month}${_year}`
const _date = new Date(profile.birthDate.toDateString())
.getDate()
.toString()
.padStart(2, "0");
const _month = (new Date(profile.birthDate.toDateString()).getMonth() + 1)
.toString()
.padStart(2, "0");
const _year = new Date(profile.birthDate.toDateString()).getFullYear() + 543;
password = `${_date}${_month}${_year}`;
}
userKeycloakId = await createUser(profile.citizenId, password, {
firstName: profile.firstName,
@ -3694,7 +3701,7 @@ export class CommandController extends Controller {
}
let _commandYear = item.commandYear;
if (item.commandYear) {
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear+543
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543;
}
const dest_item = await this.salaryRepo.findOne({
where: { profileEmployeeId: item.profileId },
@ -3861,7 +3868,7 @@ export class CommandController extends Controller {
}
let _commandYear = item.commandYear;
if (item.commandYear) {
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear+543
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543;
}
const dest_item = await this.salaryRepo.findOne({
where: { profileId: item.profileId },
@ -4167,7 +4174,7 @@ export class CommandController extends Controller {
body.data.map(async (item) => {
let _commandYear = item.commandYear;
if (item.commandYear) {
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear+543
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543;
}
if (item.profileType && item.profileType.trim().toUpperCase() == "OFFICER") {
const profile = await this.profileRepository.findOne({
@ -4679,7 +4686,7 @@ export class CommandController extends Controller {
}
let _commandYear = item.commandYear;
if (item.commandYear) {
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear+543
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543;
}
// const orgRevision = await this.orgRevisionRepo.findOne({
// where: {
@ -5161,7 +5168,7 @@ export class CommandController extends Controller {
}
let _commandYear = item.commandYear;
if (item.commandYear) {
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear+543
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543;
}
const _profile = await this.profileRepository.findOne({
where: { id: item.profileId },
@ -5457,10 +5464,15 @@ export class CommandController extends Controller {
// item.bodyProfile.birthDate.toISOString().slice(5, 7) +
// gregorianYear;
// password = formattedDate;
const _date = new Date(item.bodyProfile.birthDate.toDateString()).getDate().toString().padStart(2, "0");
const _month = (new Date(item.bodyProfile.birthDate.toDateString()).getMonth()+1).toString().padStart(2, "0");
const _year = (new Date(item.bodyProfile.birthDate.toDateString()).getFullYear()+543);
password = `${_date}${_month}${_year}`
const _date = new Date(item.bodyProfile.birthDate.toDateString())
.getDate()
.toString()
.padStart(2, "0");
const _month = (new Date(item.bodyProfile.birthDate.toDateString()).getMonth() + 1)
.toString()
.padStart(2, "0");
const _year = new Date(item.bodyProfile.birthDate.toDateString()).getFullYear() + 543;
password = `${_date}${_month}${_year}`;
}
userKeycloakId = await createUser(item.bodyProfile.citizenId, password, {
firstName: item.bodyProfile.firstName,
@ -5501,7 +5513,7 @@ export class CommandController extends Controller {
relations: ["roleKeycloaks", "profileInsignias"],
});
let _oldInsigniaIds: string[] = [];
if (!profile) {
if (!profile) {
//กรณีลูกจ้างประจำมาสอบเป็นข้าราชการ ต้อง update สถานะโปรไฟล์เดิม
let profileEmployee: any = await this.profileEmployeeRepository.findOne({
where: { citizenId: item.bodyProfile.citizenId },
@ -5525,14 +5537,14 @@ export class CommandController extends Controller {
const history = new ProfileSalaryHistory();
Object.assign(history, { ...profileEmpSalary, id: undefined });
profileEmpSalary.dateGovernment = meta.createdAt;
profileEmpSalary.profileId = _null,
await this.salaryRepo.save(profileEmpSalary, { data: req });
(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 (profileEmployee.profileInsignias.length > 0) {
_oldInsigniaIds = profileEmployee.profileInsignias.map((x:any) => x.id);
_oldInsigniaIds = profileEmployee.profileInsignias.map((x: any) => x.id);
}
await removeProfileInOrganize(profileEmployee.id, "EMPLOYEE");
if (profileEmployee.keycloak != null) {
@ -5593,9 +5605,12 @@ export class CommandController extends Controller {
//ขรก.ในระบบ หรือ ขรก.ในระบบที่สถานะพ้นจากราชการ
else {
//สร้างโปรไฟล์ใหม่ ถ้าสถานะพ้นราชการ คำสั่งโอนออกหรือคำสั่งขอลาออก
if (profile.isLeave && ["PLACEMENT_TRANSFER", "RETIRE_RESIGN"].includes(profile.leaveType)) {
if (
profile.isLeave &&
["PLACEMENT_TRANSFER", "RETIRE_RESIGN"].includes(profile.leaveType)
) {
if (profile.profileInsignias.length > 0) {
_oldInsigniaIds = profile.profileInsignias.map((x:any) => x.id);
_oldInsigniaIds = profile.profileInsignias.map((x: any) => x.id);
}
profile = Object.assign({ ...item.bodyProfile, ...meta });
profile.dateRetire = _dateRetire;
@ -5633,8 +5648,7 @@ export class CommandController extends Controller {
profile.phone = item.bodyProfile.phone ?? null;
await this.profileRepository.save(profile);
setLogDataDiff(req, { before, after: profile });
}
else {
} else {
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
profile.keycloak =
userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : "";
@ -5892,6 +5906,7 @@ export class CommandController extends Controller {
}
posMaster.current_holderId = profile.id;
posMaster.conditionReason = _null;
if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld);
await this.posMasterRepository.save(posMaster);
@ -5912,8 +5927,8 @@ export class CommandController extends Controller {
await this.positionRepository.save(positionNew, { data: req });
}
}
// Insignia
if(_oldInsigniaIds.length > 0) {
// Insignia
if (_oldInsigniaIds.length > 0) {
const _insignias = await this.insigniaRepo.find({
where: { id: In(_oldInsigniaIds) },
order: { createdAt: "ASC" },
@ -6277,10 +6292,15 @@ export class CommandController extends Controller {
// profile.birthDate.toISOString().slice(5, 7) +
// gregorianYear;
// password = formattedDate;
const _date = new Date(profile.birthDate.toDateString()).getDate().toString().padStart(2, "0");
const _month = (new Date(profile.birthDate.toDateString()).getMonth()+1).toString().padStart(2, "0");
const _year = (new Date(profile.birthDate.toDateString()).getFullYear()+543);
password = `${_date}${_month}${_year}`
const _date = new Date(profile.birthDate.toDateString())
.getDate()
.toString()
.padStart(2, "0");
const _month = (new Date(profile.birthDate.toDateString()).getMonth() + 1)
.toString()
.padStart(2, "0");
const _year = new Date(profile.birthDate.toDateString()).getFullYear() + 543;
password = `${_date}${_month}${_year}`;
}
const userKeycloakId = await createUser(profile.citizenId, password, {
firstName: profile.firstName,
@ -6606,7 +6626,9 @@ export class CommandController extends Controller {
: "-",
dateEnd: "-",
RemarkVertical: item.RemarkVertical ? Extension.ToThaiNumber(item.RemarkVertical) : "-",
RemarkHorizontal: item.RemarkHorizontal ? Extension.ToThaiNumber(item.RemarkHorizontal) : "-",
RemarkHorizontal: item.RemarkHorizontal
? Extension.ToThaiNumber(item.RemarkHorizontal)
: "-",
order:
posMasterAct.posMasterOrder == null
? "-"

View file

@ -4755,21 +4755,27 @@ export class ImportDataController extends Controller {
*/
@Post("tranferEntryToMain")
async tranferEntryToMain(@Request() request: { user: Record<string, any> }) {
const _profiles = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.profileSalary", "profileSalary")
.leftJoinAndSelect("profile.profileSalaryTemp", "profileSalaryTemp")
.where("profileSalary.isEntry = :isEntry", { isEntry: true })
.andWhere("profile.statusCheckEdit != :status", { status: "EDITED" })
.andWhere("profileSalaryTemp.id IS NULL") // 💥 filter ให้ profileSalaryTemp ว่าง
.orderBy("profileSalary.commandDateAffect", "ASC")
.addOrderBy("profileSalary.order", "ASC")
.getMany();
const profiles = await this.profileRepo.find({
where: {
citizenId: In([
"3860700270466",
"3909900758770",
"3309900659891",
"3100501312173",
"3360200140185",
"3101900524141",
"3102101307867",
]),
id: In(_profiles.map((x) => x.id)),
profileSalary: { isEntry: true },
statusCheckEdit: Not("EDITED"),
},
order: { profileSalary: { commandDateAffect: "ASC", order: "ASC" } },
relations: ["profileSalary"],
});
// console.log(profiles.lengthisDelete)
for await (const item of profiles) {
// 2. จัดกลุ่มข้อมูลตามวันที่คำสั่งมีผล
const groupedByDate = this.groupOrdersByDate(item.profileSalary);
@ -4780,7 +4786,7 @@ export class ImportDataController extends Controller {
if (orders.length == 1) {
num = num + 1;
//save
orders.isDelete = false;
orders[0].isDelete = false;
processedOrders.push(orders[0]);
continue;
}
@ -4819,7 +4825,7 @@ export class ImportDataController extends Controller {
const findCommandNo = _item.remark?.includes(
_item1.commandNo + "/" + (_item1.commandYear + 543),
);
if (findCommandNo && chkEditCommandNo == true && chkCanCommandNo == true) {
if (findCommandNo && (chkEditCommandNo == true || chkCanCommandNo == true)) {
_item.isDelete = true;
processedOrders.push(_item);
orders = orders.filter((x: ProfileSalary) => x.id != _item.id);
@ -4831,7 +4837,7 @@ export class ImportDataController extends Controller {
const _findCommandNo = _item.remark?.includes(
_item1.commandNo + "/" + (_item1.commandYear + 543).toString().slice(-2),
);
if (_findCommandNo && chkEditCommandNo == true && chkCanCommandNo == true) {
if (_findCommandNo && (chkEditCommandNo == true || chkCanCommandNo == true)) {
_item.isDelete = true;
processedOrders.push(_item);
orders = orders.filter((x: ProfileSalary) => x.id != _item.id);
@ -4938,15 +4944,15 @@ export class ImportDataController extends Controller {
async tranferEntryToMainEdit(@Request() request: { user: Record<string, any> }) {
const profiles = await this.salaryTempRepo.find({
where: {
profileId: In([
"529558c4-5c5d-431a-8b40-940cded51a41",
"649f2d08-2a01-48b1-afcc-8a4c99091b17",
"9ac31312-441a-4cdf-a778-974d9232ca55",
"9c6b5005-ee8e-432f-a83d-cd41fb199e56",
"c8c664de-e792-4fbd-85c1-fbeefdc860d4",
"c9639f3b-26d0-47fc-a53d-1a0e4926697e",
"e6d40cd6-c77b-4229-8e8d-a6df3f83394b",
]),
// profileId: In([
// "529558c4-5c5d-431a-8b40-940cded51a41",
// "649f2d08-2a01-48b1-afcc-8a4c99091b17",
// "9ac31312-441a-4cdf-a778-974d9232ca55",
// "9c6b5005-ee8e-432f-a83d-cd41fb199e56",
// "c8c664de-e792-4fbd-85c1-fbeefdc860d4",
// "c9639f3b-26d0-47fc-a53d-1a0e4926697e",
// "e6d40cd6-c77b-4229-8e8d-a6df3f83394b",
// ]),
isEntry: true,
isDelete: true,
},
@ -4975,6 +4981,45 @@ export class ImportDataController extends Controller {
}
return new HttpSuccess();
}
/**
* @summary entry
*/
@Post("tranferEntryToMainEditEntry")
async tranferEntryToMainEditEntry(@Request() request: { user: Record<string, any> }) {
const profiles = await this.salaryTempRepo.find({
where: {
// profileId: In([
// "529558c4-5c5d-431a-8b40-940cded51a41",
// "649f2d08-2a01-48b1-afcc-8a4c99091b17",
// "9ac31312-441a-4cdf-a778-974d9232ca55",
// "9c6b5005-ee8e-432f-a83d-cd41fb199e56",
// "c8c664de-e792-4fbd-85c1-fbeefdc860d4",
// "c9639f3b-26d0-47fc-a53d-1a0e4926697e",
// "e6d40cd6-c77b-4229-8e8d-a6df3f83394b",
// ]),
isEntry: true,
},
relations: ["profile"],
});
let num = 1;
for await (const item of profiles) {
console.log(num);
num += 1;
const existingProfile = await this.ProfileSalariesRepo.createQueryBuilder("profile")
.where("profile.posNo = :posNo", { posNo: item.profile.citizenId })
.andWhere("CONCAT(profile.SalaryRef, ' ', profile.PositionName) = :remark", {
remark: item.remark,
})
.getOne();
if (existingProfile) {
item.remark = existingProfile.SalaryRef;
await this.salaryTempRepo.save(item);
}
}
return new HttpSuccess();
}
// ฟังก์ชันจัดกลุ่มตามวันที่
groupOrdersByDate(orders: ProfileSalary[]) {
return orders.reduce((groups: any, order) => {

View file

@ -4688,6 +4688,8 @@ export class PositionController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
posMaster.current_holderId = body.profileId;
const _null: any = null;
posMaster.conditionReason = _null;
if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld);
await this.posMasterRepository.save(posMaster);