ปิดออกคำสั่ง fix root salary/gen

This commit is contained in:
AdisakKanthawilang 2025-05-01 10:19:19 +07:00
parent e95a299ab2
commit 5ac856fb18
2 changed files with 175 additions and 156 deletions

View file

@ -317,10 +317,19 @@ export class OrganizationUnauthorizeController extends Controller {
if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
}
const rootIds = [
"d7e98989-b5ce-47d6-93c3-ab63ed486348",
"e0545eca-5d0a-4a1c-8bbd-e3e25c2521db",
"7ff1fbf2-cc9e-4f53-b83c-334967c27967",
"26989ffa-d5ab-4bbd-ac97-130646cd1da6",
"6f9b30e1-757a-40d5-b053-61eb1b91c0f0",
"eaf65f33-25e9-4956-9dba-5d909f5eb595",
];
const [findPosMaster, total] = await AppDataSource.getRepository(viewPosMaster)
.createQueryBuilder("viewPosMaster")
.where({orgRevisionId: findRevision?.id})
.andWhere("viewPosMaster.rootId IN (:...rootIds)", { rootIds })
.andWhere(
new Brackets((qb) => {
qb.where(
@ -744,11 +753,21 @@ export class OrganizationUnauthorizeController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
}
const rootIds = [
"d7e98989-b5ce-47d6-93c3-ab63ed486348",
"e0545eca-5d0a-4a1c-8bbd-e3e25c2521db",
"7ff1fbf2-cc9e-4f53-b83c-334967c27967",
"26989ffa-d5ab-4bbd-ac97-130646cd1da6",
"6f9b30e1-757a-40d5-b053-61eb1b91c0f0",
"eaf65f33-25e9-4956-9dba-5d909f5eb595",
];
const [findPosMaster, total] = await AppDataSource.getRepository(viewEmployeePosMaster)
.createQueryBuilder("viewEmployeePosMaster")
.where({
orgRevisionId: findRevision?.id,
})
.andWhere("viewEmployeePosMaster.rootId IN (:...rootIds)", { rootIds })
.andWhere(
new Brackets((qb) => {
qb.where(

View file

@ -113,103 +113,16 @@ function createConsumer( //----> consumer
);
}
// async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
// //----> condition before process consumer
// const repo = AppDataSource.getRepository(Command);
// const { data, token, user } = JSON.parse(msg.content.toString());
// const { id, status, lastUpdateUserId, lastUpdateFullName, lastUpdatedAt } = data;
// const command = await repo.findOne({
// where: { id: id },
// relations: ["commandType", "commandRecives"],
// });
// if (!command) return true;
// if (user) {
// sendWebSocket(
// "send-command-notification",
// {
// success: true,
// message: `ระบบทำการออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543}`,
// payload: command,
// },
// { userId: user?.sub },
// ).catch(console.error);
// }
// const path = commandTypePath(command.commandType.code);
// if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
// return await new CallAPI()
// .PostData(
// {
// headers: { authorization: token },
// },
// path + "/excecute",
// {
// refIds: command.commandRecives
// .filter((x) => x.refId != null)
// .map((x) => ({
// refId: x.refId,
// commandNo: command.commandNo,
// commandYear: command.commandYear,
// commandId: command.id,
// remark: command.positionDetail,
// amount: x.amount,
// amountSpecial: x.amountSpecial,
// positionSalaryAmount: x.positionSalaryAmount,
// mouthSalaryAmount: x.mouthSalaryAmount,
// commandCode: command.commandType.commandCode,
// commandName: command.commandType.name,
// commandDateAffect: command.commandExcecuteDate,
// commandDateSign: command.commandAffectDate,
// })),
// },
// false,
// )
// .then(async (res) => {
// 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){
// sendWebSocket(
// "send-command-notification",
// {
// success: true,
// message: `ระบบออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543} เสร็จสิ้น`,
// payload: command,
// },
// { userId: user?.sub},
// ).catch(console.error);
// }
// return !!result;
// })
// .catch((e) => {
// console.error(e);
// if(user){
// sendWebSocket(
// "send-command-notification",
// {
// success: false,
// message: `ระบบออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543} ผิดพลาด`,
// payload: command,
// },
// { userId: user?.sub},
// ).catch(console.error);
// }
// return false;
// });
// }
async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
//----> condition before process consumer
const repo = AppDataSource.getRepository(Command);
const { data, token, user } = JSON.parse(msg.content.toString());
const { id, status, lastUpdateUserId, lastUpdateFullName, lastUpdatedAt } = data;
const command = await repo.findOne({
where: { id },
where: { id: id },
relations: ["commandType", "commandRecives"],
});
if (!command) return true;
if (user) {
sendWebSocket(
"send-command-notification",
@ -221,78 +134,165 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
{ userId: user?.sub },
).catch(console.error);
}
const path = commandTypePath(command.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
return await new CallAPI()
const recivers = command.commandRecives
.filter((x) => x.refId != null)
.map((x) => ({
refId: x.refId,
commandNo: command.commandNo,
commandYear: command.commandYear,
commandId: command.id,
remark: command.positionDetail,
amount: x.amount,
amountSpecial: x.amountSpecial,
positionSalaryAmount: x.positionSalaryAmount,
mouthSalaryAmount: x.mouthSalaryAmount,
commandCode: command.commandType.commandCode,
commandName: command.commandType.name,
commandDateAffect: command.commandExcecuteDate,
commandDateSign: command.commandAffectDate,
}));
const batchSize = 50;
const batches = Array.from({ length: Math.ceil(recivers.length / batchSize) }, (_, i) =>
recivers.slice(i * batchSize, i * batchSize + batchSize)
);
const api = new CallAPI();
try {
for (const batch of batches) {
await api.PostData(
{ headers: { authorization: token } },
path + "/excecute",
{ refIds: batch },
false
);
}
console.log("[AMQ] Excecute Command Success");
Object.assign(command, { status, lastUpdateUserId, lastUpdateFullName, lastUpdatedAt });
const result = await repo.save(command);
if (user) {
sendWebSocket(
"send-command-notification",
{
success: true,
message: `ระบบออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543} เสร็จสิ้น`,
payload: command,
},
{ userId: user?.sub },
).catch(console.error);
}
return !!result;
} catch (e) {
console.error(e);
if (user) {
sendWebSocket(
"send-command-notification",
{
success: false,
message: `ระบบออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543} ผิดพลาด`,
payload: command,
},
{ userId: user?.sub },
).catch(console.error);
}
return false;
}
.PostData(
{
headers: { authorization: token },
},
path + "/excecute",
{
refIds: command.commandRecives
.filter((x) => x.refId != null)
.map((x) => ({
refId: x.refId,
commandNo: command.commandNo,
commandYear: command.commandYear,
commandId: command.id,
remark: command.positionDetail,
amount: x.amount,
amountSpecial: x.amountSpecial,
positionSalaryAmount: x.positionSalaryAmount,
mouthSalaryAmount: x.mouthSalaryAmount,
commandCode: command.commandType.commandCode,
commandName: command.commandType.name,
commandDateAffect: command.commandExcecuteDate,
commandDateSign: command.commandAffectDate,
})),
},
false,
)
.then(async (res) => {
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){
sendWebSocket(
"send-command-notification",
{
success: true,
message: `ระบบออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543} เสร็จสิ้น`,
payload: command,
},
{ userId: user?.sub},
).catch(console.error);
}
return !!result;
})
.catch((e) => {
console.error(e);
if(user){
sendWebSocket(
"send-command-notification",
{
success: false,
message: `ระบบออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543} ผิดพลาด`,
payload: command,
},
{ userId: user?.sub},
).catch(console.error);
}
return false;
});
}
// async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
// const repo = AppDataSource.getRepository(Command);
// const { data, token, user } = JSON.parse(msg.content.toString());
// const { id, status, lastUpdateUserId, lastUpdateFullName, lastUpdatedAt } = data;
// const command = await repo.findOne({
// where: { id },
// relations: ["commandType", "commandRecives"],
// });
// if (!command) return true;
// if (user) {
// sendWebSocket(
// "send-command-notification",
// {
// success: true,
// message: `ระบบทำการออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543}`,
// payload: command,
// },
// { userId: user?.sub },
// ).catch(console.error);
// }
// const path = commandTypePath(command.commandType.code);
// if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
// const recivers = command.commandRecives
// .filter((x) => x.refId != null)
// .map((x) => ({
// refId: x.refId,
// commandNo: command.commandNo,
// commandYear: command.commandYear,
// commandId: command.id,
// remark: command.positionDetail,
// amount: x.amount,
// amountSpecial: x.amountSpecial,
// positionSalaryAmount: x.positionSalaryAmount,
// mouthSalaryAmount: x.mouthSalaryAmount,
// commandCode: command.commandType.commandCode,
// commandName: command.commandType.name,
// commandDateAffect: command.commandExcecuteDate,
// commandDateSign: command.commandAffectDate,
// }));
// const batchSize = 50;
// const batches = Array.from({ length: Math.ceil(recivers.length / batchSize) }, (_, i) =>
// recivers.slice(i * batchSize, i * batchSize + batchSize)
// );
// const api = new CallAPI();
// try {
// for (const batch of batches) {
// await api.PostData(
// { headers: { authorization: token } },
// path + "/excecute",
// { refIds: batch },
// false
// );
// }
// console.log("[AMQ] Excecute Command Success");
// Object.assign(command, { status, lastUpdateUserId, lastUpdateFullName, lastUpdatedAt });
// const result = await repo.save(command);
// if (user) {
// sendWebSocket(
// "send-command-notification",
// {
// success: true,
// message: `ระบบออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543} เสร็จสิ้น`,
// payload: command,
// },
// { userId: user?.sub },
// ).catch(console.error);
// }
// return !!result;
// } catch (e) {
// console.error(e);
// if (user) {
// sendWebSocket(
// "send-command-notification",
// {
// success: false,
// message: `ระบบออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543} ผิดพลาด`,
// payload: command,
// },
// { userId: user?.sub },
// ).catch(console.error);
// }
// return false;
// }
// }
async function handler_command_noti(msg: amqp.ConsumeMessage): Promise<boolean> {
const { data, token, user } = JSON.parse(msg.content.toString());
const { profiles, command } = data;