rabbitMQ command
This commit is contained in:
parent
cb4fc6defb
commit
608c8967bc
7 changed files with 440 additions and 37 deletions
|
|
@ -19,7 +19,7 @@ import HttpSuccess from "../interfaces/http-success";
|
|||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { Command } from "../entities/Command";
|
||||
import { Brackets, LessThan, MoreThan, Double, In } from "typeorm";
|
||||
import { Brackets, LessThan, MoreThan, Double, In, Between } from "typeorm";
|
||||
import { CommandType } from "../entities/CommandType";
|
||||
import { CommandSend } from "../entities/CommandSend";
|
||||
import { Profile } from "../entities/Profile";
|
||||
|
|
@ -42,6 +42,7 @@ import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
|||
import { ProfileDiscipline } from "../entities/ProfileDiscipline";
|
||||
import { ProfileDisciplineHistory } from "../entities/ProfileDisciplineHistory";
|
||||
import { PosMasterAct } from "../entities/PosMasterAct";
|
||||
import { sendToQueue } from "../services/rabbitmq";
|
||||
|
||||
@Route("api/v1/org/command")
|
||||
@Tags("Command")
|
||||
|
|
@ -125,12 +126,9 @@ export class CommandController extends Controller {
|
|||
new Brackets((qb) => {
|
||||
qb.where(keyword != null && keyword != "" ? "command.commandNo LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
}).orWhere(
|
||||
keyword != null && keyword != "" ? "command.issue LIKE :keyword" : "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
);
|
||||
}).orWhere(keyword != null && keyword != "" ? "command.issue LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
});
|
||||
}),
|
||||
)
|
||||
.orderBy("command.createdAt", "DESC")
|
||||
|
|
@ -900,12 +898,12 @@ export class CommandController extends Controller {
|
|||
.filter((x) => x.profileId != null)
|
||||
.map(async (x) => x.profileId);
|
||||
|
||||
await new CallAPI()
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti/profiles", {
|
||||
subject: `${command.issue}`,
|
||||
body: `${command.issue}`,
|
||||
receiverUserId: profiles,
|
||||
payload: "",//แนบไฟล์
|
||||
payload: "", //แนบไฟล์
|
||||
isSendMail: true,
|
||||
isSendInbox: true,
|
||||
receiveDate: command.commandExcecuteDate,
|
||||
|
|
@ -922,34 +920,86 @@ export class CommandController extends Controller {
|
|||
)
|
||||
) {
|
||||
command.status = "WAITING";
|
||||
command.lastUpdateUserId = request.user.sub;
|
||||
command.lastUpdateFullName = request.user.name;
|
||||
command.lastUpdatedAt = new Date();
|
||||
await this.commandRepository.save(command);
|
||||
} else {
|
||||
const path = this.commandTypePath(command.commandType.code);
|
||||
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
|
||||
|
||||
await new CallAPI()
|
||||
.PostData(request, path + "/excecute", {
|
||||
refIds: command.commandRecives
|
||||
.filter((x) => x.refId != null)
|
||||
.map((x) => ({
|
||||
refId: x.refId,
|
||||
commandAffectDate: command.commandAffectDate,
|
||||
commandNo: command.commandNo,
|
||||
commandYear: command.commandYear,
|
||||
templateDoc: command.positionDetail,
|
||||
amount: x.amount,
|
||||
positionSalaryAmount: x.positionSalaryAmount,
|
||||
mouthSalaryAmount: x.mouthSalaryAmount,
|
||||
})),
|
||||
})
|
||||
.then(async (res) => {
|
||||
command.status = "REPORTED";
|
||||
})
|
||||
.catch((e) => {});
|
||||
const msg = {
|
||||
data: {
|
||||
id: command.id,
|
||||
status: "REPORTED",
|
||||
lastUpdateUserId: request.user.sub,
|
||||
lastUpdateFullName: request.user.name,
|
||||
lastUpdatedAt: new Date(),
|
||||
},
|
||||
user: request.user,
|
||||
token: request.headers["authorization"],
|
||||
};
|
||||
sendToQueue(msg);
|
||||
}
|
||||
command.lastUpdateUserId = request.user.sub;
|
||||
command.lastUpdateFullName = request.user.name;
|
||||
command.lastUpdatedAt = new Date();
|
||||
await this.commandRepository.save(command);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
async cronjobCommand(@Request() request?: RequestWithUser) {
|
||||
console.log(request);
|
||||
const today = new Date();
|
||||
today.setHours(7, 0, 0, 0); //+7 เพื่อให้ตรง local time (อาจจะต้องใช้ moment)
|
||||
const tomorrow = new Date(today);
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
|
||||
const command = await this.commandRepository.find({
|
||||
relations: ["commandType", "commandRecives"],
|
||||
where:{
|
||||
commandExcecuteDate: Between(today, tomorrow),
|
||||
status: "WAITING"
|
||||
}
|
||||
});
|
||||
|
||||
const data = {
|
||||
client_id: "gettoken",
|
||||
client_secret: process.env.AUTH_ACCOUNT_SECRET,
|
||||
grant_type: "password",
|
||||
requested_token_type: "urn:ietf:params:oauth:token-type:refresh_token",
|
||||
username: process.env.USERNAME_,
|
||||
password: process.env.PASSWORD_,
|
||||
};
|
||||
let _data: any = null;
|
||||
await Promise.all([
|
||||
await new CallAPI()
|
||||
.PostDataKeycloak("/realms/bma-ehr/protocol/openid-connect/token", data)
|
||||
.then(async (x) => {
|
||||
_data = x;
|
||||
})
|
||||
.catch(async (x) => {
|
||||
throw new HttpError(HttpStatus.UNAUTHORIZED, "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง");
|
||||
}),
|
||||
]);
|
||||
if (_data == null) {
|
||||
return new HttpError(HttpStatus.UNAUTHORIZED, "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง");
|
||||
}
|
||||
|
||||
command.forEach(async (x) => {
|
||||
const path = this.commandTypePath(x.commandType.code);
|
||||
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
|
||||
const msg = {
|
||||
data: {
|
||||
id: x.id,
|
||||
status: "REPORTED",
|
||||
lastUpdateUserId: "system",
|
||||
lastUpdateFullName: "system",
|
||||
// lastUpdateUserId: _data.user.sub,
|
||||
// lastUpdateFullName: _data.user.name,
|
||||
lastUpdatedAt: new Date(),
|
||||
},
|
||||
user: _data.user,
|
||||
token: _data.access_token,
|
||||
};
|
||||
sendToQueue(msg);
|
||||
})
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -1067,7 +1117,7 @@ export class CommandController extends Controller {
|
|||
commandExcecuteDate?: Date | null;
|
||||
persons: {
|
||||
refId: string;
|
||||
profileId?: string|null;
|
||||
profileId?: string | null;
|
||||
citizenId: string;
|
||||
prefix: string;
|
||||
firstName: string;
|
||||
|
|
@ -2280,6 +2330,7 @@ export class CommandController extends Controller {
|
|||
) {
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
commandTypePath(commandCode: string) {
|
||||
switch (commandCode) {
|
||||
case "C-PM-01":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue