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