Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop
This commit is contained in:
commit
cd9f17867a
7 changed files with 434 additions and 28 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, Not } from "typeorm";
|
||||
import { Brackets, LessThan, MoreThan, Double, In, Not ,Between } from "typeorm";
|
||||
import { CommandType } from "../entities/CommandType";
|
||||
import { CommandSend } from "../entities/CommandSend";
|
||||
import { Profile, CreateProfileAllFields } from "../entities/Profile";
|
||||
|
|
@ -47,6 +47,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";
|
||||
import { PosLevel } from "../entities/PosLevel";
|
||||
import { PosType } from "../entities/PosType";
|
||||
import { addUserRoles, createUser, getRoles } from "../keycloak";
|
||||
|
|
@ -1038,34 +1039,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();
|
||||
}
|
||||
|
||||
|
|
@ -2704,6 +2757,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