Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2025-06-26 15:58:53 +07:00
commit 434293418d
5 changed files with 274 additions and 121 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);

View file

@ -1050,18 +1050,20 @@ export class ProfileEmployeeTempController extends Controller {
}
/**
* API
* API
*
* @summary (ADMIN)
* @summary (ADMIN)
*
*/
@Get("temp")
async listProfileEmp() {
async listProfileEmp(@Request() request: RequestWithUser) {
let _dataOrg = await new permission().PermissionOrgList(request, "SYS_REGISTRY_TEMP");
const [record, total] = await this.profileRepo
.createQueryBuilder("profileEmployee")
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
.leftJoinAndSelect("profileEmployee.posType", "posType")
.leftJoinAndSelect("profileEmployee.current_holders", "current_holders")
.leftJoinAndSelect("profileEmployee.current_holderTemps", "current_holderTemps")
.leftJoinAndSelect("profileEmployee.profileEmployeeEmployment", "profileEmployeeEmployment")
.leftJoinAndSelect("current_holders.positions", "positions")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
@ -1069,8 +1071,63 @@ export class ProfileEmployeeTempController extends Controller {
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.leftJoinAndSelect("current_holderTemps.orgRoot", "orgRootTemp")
.leftJoinAndSelect("current_holderTemps.orgChild1", "orgChild1Temp")
.leftJoinAndSelect("current_holderTemps.orgChild2", "orgChild2Temp")
.leftJoinAndSelect("current_holderTemps.orgChild3", "orgChild3Temp")
.leftJoinAndSelect("current_holderTemps.orgChild4", "orgChild4Temp")
.andWhere("profileEmployee.employeeClass = :employeeClass", { employeeClass: "TEMP" })
.andWhere("profileEmployee.statusTemp = :statusTemp", { statusTemp: "PENDING" })
.andWhere(
_dataOrg.root != undefined && _dataOrg.root != null
? _dataOrg.root[0] != null
? `current_holderTemps.orgRootId IN (:...root)`
: `current_holderTemps.orgRootId is null`
: "1=1",
{
root: _dataOrg.root,
},
)
.andWhere(
_dataOrg.child1 != undefined && _dataOrg.child1 != null
? _dataOrg.child1[0] != null
? `current_holderTemps.orgChild1Id IN (:...child1)`
: `current_holderTemps.orgChild1Id is null`
: "1=1",
{
child1: _dataOrg.child1,
},
)
.andWhere(
_dataOrg.child2 != undefined && _dataOrg.child2 != null
? _dataOrg.child2[0] != null
? `current_holderTemps.orgChild2Id IN (:...child2)`
: `current_holderTemps.orgChild2Id is null`
: "1=1",
{
child2: _dataOrg.child2,
},
)
.andWhere(
_dataOrg.child3 != undefined && _dataOrg.child3 != null
? _dataOrg.child3[0] != null
? `current_holderTemps.orgChild3Id IN (:...child3)`
: `current_holderTemps.orgChild3Id is null`
: "1=1",
{
child3: _dataOrg.child3,
},
)
.andWhere(
_dataOrg.child4 != undefined && _dataOrg.child4 != null
? _dataOrg.child4[0] != null
? `current_holderTemps.orgChild4Id IN (:...child4)`
: `current_holderTemps.orgChild4Id is null`
: "1=1",
{
child4: _dataOrg.child4,
},
)
.getManyAndCount();
const data = await Promise.all(
record.map((_data) => {
@ -1409,9 +1466,9 @@ export class ProfileEmployeeTempController extends Controller {
}
/**
* API
* API
*
* @summary ORG_065 - (ADMIN) #70
* @summary ORG_065 - (ADMIN) #70
*
*/
@Get()
@ -1540,9 +1597,20 @@ export class ProfileEmployeeTempController extends Controller {
// : `profileEmployee.dateRetire IS NOT NULL`
// : "1=1",
// )
.andWhere("profileEmployee.employeeClass = :type", {
type: "TEMP",
})
.andWhere(
"profileEmployee.employeeClass = :type", {
type: type ? type.trim().toLocaleUpperCase() : "TEMP"
}
)
.orWhere(
`current_holderTemps.orgRootId is null AND current_holderTemps.orgChild1Id is null AND
current_holderTemps.orgChild2Id is null AND current_holderTemps.orgChild3Id is null AND
current_holderTemps.orgChild4Id is null AND profileEmployee.createdUserId = :keycloak AND
profileEmployee.employeeClass = :type`, {
keycloak: request.user.sub,
type: type ? type.trim().toLocaleUpperCase() : "TEMP",
}
)
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();

View file

@ -58,10 +58,10 @@ export async function init() {
console.log(channel ? "[AMQ] Create channel success" : "[AMQ] Create channel failed");
channel.assertQueue(queue, { durable: true }), //----> (1.5) assert queue and set durable (if "true" save to disk on RabbitMQ)
channel.assertQueue(queue_org, { durable: true }),
channel.assertQueue(queue_org_draft, { durable: true }),
channel.assertQueue(queue_command_noti, { durable: true }),
channel.prefetch(1);
channel.assertQueue(queue_org, { durable: true }),
channel.assertQueue(queue_org_draft, { durable: true }),
channel.assertQueue(queue_command_noti, { durable: true }),
channel.prefetch(1);
sendToQueue = (payload: any, persistent = true) => {
//----> (2) sendQueue To RabbitMQ and set persistent (if "true" redo the failed queue when server run again)
@ -84,7 +84,7 @@ export async function init() {
console.log("[AMQ] Listening for message...");
createConsumer(queue, channel, handler), //----> (3) Process Consumer
createConsumer(queue_org, channel, handler_org);
createConsumer(queue_org, channel, handler_org);
createConsumer(queue_org_draft, channel, handler_org_draft);
createConsumer(queue_command_noti, channel, handler_command_noti);
// createConsumer(queue2, channel, handler2);
@ -168,7 +168,7 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
console.log("[AMQ] Excecute Command Success");
Object.assign(command, { status, lastUpdateUserId, lastUpdateFullName, lastUpdatedAt });
const result = await repo.save(command).catch((e) => console.log(e));
if(user){
if (user) {
sendWebSocket(
"send-command-notification",
{
@ -176,14 +176,14 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
message: `ระบบออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543} เสร็จสิ้น`,
payload: command,
},
{ userId: user?.sub},
{ userId: user?.sub },
).catch(console.error);
}
return !!result;
})
.catch((e) => {
console.error(e);
if(user){
if (user) {
sendWebSocket(
"send-command-notification",
{
@ -191,7 +191,7 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
message: `ระบบออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543} ผิดพลาด`,
payload: command,
},
{ userId: user?.sub},
{ userId: user?.sub },
).catch(console.error);
}
return false;
@ -306,12 +306,12 @@ async function handler_command_noti(msg: amqp.ConsumeMessage): Promise<boolean>
subject: `${command.issue}`,
body: `${command.issue}`,
receiverUserIds: profiles,
payload: "",// แนบไฟล์ (ถ้าจำเป็น)
payload: "", // แนบไฟล์ (ถ้าจำเป็น)
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
},
false
false,
)
.catch((error) => {
if (error.response) {
@ -329,17 +329,18 @@ async function handler_command_noti(msg: amqp.ConsumeMessage): Promise<boolean>
console.error("Full error object:", error);
});
let profilesSend = command && command.commandSends.length > 0
? command.commandSends
.filter((x: any) => x.profileId != null)
.map((x: any) => ({
receiverUserId: x.profileId,
notiLink: "",
isSendMail: x.commandSendCCs.map((x: any) => x.name == "EMAIL").length > 0,
isSendInbox: x.commandSendCCs.map((x: any) => x.name == "INBOX").length > 0,
isSendNotification: true,
}))
: [];
let profilesSend =
command && command.commandSends.length > 0
? command.commandSends
.filter((x: any) => x.profileId != null)
.map((x: any) => ({
receiverUserId: x.profileId,
notiLink: "",
isSendMail: x.commandSendCCs.map((x: any) => x.name == "EMAIL").length > 0,
isSendInbox: x.commandSendCCs.map((x: any) => x.name == "INBOX").length > 0,
isSendNotification: true,
}))
: [];
const profilesSendRequest = new CallAPI()
.PostData(
@ -349,10 +350,11 @@ async function handler_command_noti(msg: amqp.ConsumeMessage): Promise<boolean>
subject: `${command.issue}`,
body: `${command.issue}`,
receiverUserIds: profilesSend,
payload: "", // แนบไฟล์ (ถ้าจำเป็น)
payload: "", // แนบไฟล์ (ถ้าจำเป็น)
},
false
).catch((error) => {
false,
)
.catch((error) => {
if (error.response) {
// Server ตอบกลับ (มี status code 4xx หรือ 5xx)
console.error("Error status:", error.response.status);
@ -372,14 +374,12 @@ async function handler_command_noti(msg: amqp.ConsumeMessage): Promise<boolean>
console.log("[AMQ] Send Notification Success");
return true;
} catch (error) {
console.error("[AMQ] Error:", error);
return false;
return false;
}
}
async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
//----> condition before process consume
const repoPosmaster = AppDataSource.getRepository(PosMaster);
@ -397,7 +397,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
const orgRevisionPublish = await repoOrgRevision
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false")
.where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne();
@ -406,12 +406,14 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
.where("orgRevision.orgRevisionIsDraft = true")
.andWhere("orgRevision.orgRevisionIsCurrent = false")
.getOne();
if (orgRevisionPublish) { //เข้าเงื่อนไขจะเปลี่ยนสถานะ orgRevisionPublish เป็นไม่ใช่ current และไม่เป็น daft
if (orgRevisionPublish) {
//เข้าเงื่อนไขจะเปลี่ยนสถานะ orgRevisionPublish เป็นไม่ใช่ current และไม่เป็น daft
orgRevisionPublish.orgRevisionIsDraft = false;
orgRevisionPublish.orgRevisionIsCurrent = false;
await repoOrgRevision.save(orgRevisionPublish);
}
if (orgRevisionDraft) { //เข้าเงื่อนไขจะเปลี่ยนสถานะ orgRevisionDraft เป็นไม่ใช่ daft และเป็น current
if (orgRevisionDraft) {
//เข้าเงื่อนไขจะเปลี่ยนสถานะ orgRevisionDraft เป็นไม่ใช่ daft และเป็น current
orgRevisionDraft.orgRevisionIsCurrent = true;
orgRevisionDraft.orgRevisionIsDraft = false;
await repoOrgRevision.save(orgRevisionDraft);
@ -449,7 +451,8 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
}
}
item.current_holderId = item.next_holderId;
if(item.current_holderId){
item.conditionReason = _null;
if (item.current_holderId) {
item.conditionReason = _null;
}
item.next_holderId = null;
@ -461,7 +464,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
if (orgRevisionPublish != null && orgRevisionDraft != null) {
//new main revision
const before = null;
//ทุก orgRoot และ orgChild ข้างล่างนี้จะเป็นตัวเก่าที่ไม่ได้เป็น current revision
//cone tree
// if (
@ -475,7 +478,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
const orgRoot = await orgRootRepository.find({
where: { orgRevisionId: orgRevisionPublish.id },
});
const orgChild1 = await child1Repository.find({
where: { orgRevisionId: orgRevisionPublish.id },
});
@ -537,11 +540,11 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
}));
await repoEmployeeTempPosmaster.save(_orgemployeeTempPosMaster);
// }
//create org
orgRoot.forEach(async (x: any) => {
var dataId = x.id;
const orgRootCurrent = await orgRootRepository.find({
where: { orgRevisionId: orgRevisionDraft.id },
});
@ -549,18 +552,20 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
const matchedOrgRoot = orgRootCurrent.find((i: OrgRoot) => {
if (
x.ancestorDNA === x.id || // ถ้า ancestorDNA ถูกตั้งเป็น id ตัวเอง
x.ancestorDNA === null ||
x.ancestorDNA === null ||
x.ancestorDNA === "00000000-0000-0000-0000-000000000000"
) {
return i.ancestorDNA === null || i.ancestorDNA === "00000000-0000-0000-0000-000000000000";
return (
i.ancestorDNA === null || i.ancestorDNA === "00000000-0000-0000-0000-000000000000"
);
}
return i.ancestorDNA === x.ancestorDNA;
});
// if (
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
// ) {
//create employeePosmaster
@ -590,7 +595,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
// }
// employeePosMaster.current_holderId = null;
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
employeePosMaster.createdUserId = "";
employeePosMaster.createdFullName = "System Administrator";
employeePosMaster.createdAt = new Date();
@ -697,10 +702,12 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
const matchedOrgChild1 = orgChild1Current.find((i: OrgChild1) => {
if (
x.ancestorDNA === x.id || // ถ้า ancestorDNA ถูกตั้งเป็น id ตัวเอง
x.ancestorDNA === null ||
x.ancestorDNA === null ||
x.ancestorDNA === "00000000-0000-0000-0000-000000000000"
) {
return i.ancestorDNA === null || i.ancestorDNA === "00000000-0000-0000-0000-000000000000";
return (
i.ancestorDNA === null || i.ancestorDNA === "00000000-0000-0000-0000-000000000000"
);
}
return i.ancestorDNA === x.ancestorDNA;
});
@ -782,7 +789,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
.map(async (item: any) => {
delete item.id;
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
employeeTempPosMaster.positions = [];
employeeTempPosMaster.positions = [];
// if (
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
@ -846,14 +853,17 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
const orgChild2Current = await child2Repository.find({
where: { orgRevisionId: orgRevisionDraft.id },
});
const matchedOrgChild2 = orgChild2Current.find((i: OrgChild2) => {
if (
x.ancestorDNA === x.id || // ถ้า ancestorDNA ถูกตั้งเป็น id ตัวเอง
x.ancestorDNA === null ||
x.ancestorDNA === null ||
x.ancestorDNA === "00000000-0000-0000-0000-000000000000"
) {
return i.ancestorDNA === null || i.ancestorDNA === "00000000-0000-0000-0000-000000000000";
return (
i.ancestorDNA === null ||
i.ancestorDNA === "00000000-0000-0000-0000-000000000000"
);
}
return i.ancestorDNA === x.ancestorDNA;
});
@ -1007,14 +1017,17 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
const orgChild3Current = await child3Repository.find({
where: { orgRevisionId: orgRevisionDraft.id },
});
const matchedOrgChild3 = orgChild3Current.find((i: OrgChild3) => {
if (
x.ancestorDNA === x.id || // ถ้า ancestorDNA ถูกตั้งเป็น id ตัวเอง
x.ancestorDNA === null ||
x.ancestorDNA === null ||
x.ancestorDNA === "00000000-0000-0000-0000-000000000000"
) {
return i.ancestorDNA === null || i.ancestorDNA === "00000000-0000-0000-0000-000000000000";
return (
i.ancestorDNA === null ||
i.ancestorDNA === "00000000-0000-0000-0000-000000000000"
);
}
return i.ancestorDNA === x.ancestorDNA;
});
@ -1171,14 +1184,17 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
const orgChild4Current = await child4Repository.find({
where: { orgRevisionId: orgRevisionDraft.id },
});
const matchedOrgChild4 = orgChild4Current.find((i: OrgChild4) => {
if (
x.ancestorDNA === x.id || // ถ้า ancestorDNA ถูกตั้งเป็น id ตัวเอง
x.ancestorDNA === null ||
x.ancestorDNA === null ||
x.ancestorDNA === "00000000-0000-0000-0000-000000000000"
) {
return i.ancestorDNA === null || i.ancestorDNA === "00000000-0000-0000-0000-000000000000";
return (
i.ancestorDNA === null ||
i.ancestorDNA === "00000000-0000-0000-0000-000000000000"
);
}
return i.ancestorDNA === x.ancestorDNA;
});
@ -1560,7 +1576,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
)
) {
posMaster.next_holderId = item.current_holderId;
if(posMaster.next_holderId){
if (posMaster.next_holderId) {
posMaster.conditionReason = _null;
}
} else {
@ -1655,7 +1671,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
)
) {
posMaster.next_holderId = item.current_holderId;
if(posMaster.next_holderId){
if (posMaster.next_holderId) {
posMaster.conditionReason = _null;
}
} else {
@ -1752,7 +1768,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
)
) {
posMaster.next_holderId = item.current_holderId;
if(posMaster.next_holderId){
if (posMaster.next_holderId) {
posMaster.conditionReason = _null;
}
} else {
@ -1851,7 +1867,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
)
) {
posMaster.next_holderId = item.current_holderId;
if(posMaster.next_holderId){
if (posMaster.next_holderId) {
posMaster.conditionReason = _null;
}
} else {
@ -1953,7 +1969,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
)
) {
posMaster.next_holderId = item.current_holderId;
if(posMaster.next_holderId){
if (posMaster.next_holderId) {
posMaster.conditionReason = _null;
}
} else {
@ -2024,7 +2040,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
}
//ลบ daft เก่าที่ค้างแล้วยังไม่ได้เผยแพร่
const _orgRevisions = await orgRevisionRepository.find({
where: [{ orgRevisionIsDraft: true, id: Not(revision.id) }],
where: [{ orgRevisionIsDraft: true, id: Not(revision.id) }],
});
const _roots = await orgRootRepository.find({
where: [{ orgRevisionId: In(_orgRevisions.map((x) => x.id)) }],