Merge branch 'develop'
This commit is contained in:
commit
5423d39568
13 changed files with 3669 additions and 120 deletions
|
|
@ -124,6 +124,7 @@ export class ApiKeyController extends Controller {
|
||||||
@Get("name")
|
@Get("name")
|
||||||
async listApiName() {
|
async listApiName() {
|
||||||
const apiName = await this.apiNameRepository.find({
|
const apiName = await this.apiNameRepository.find({
|
||||||
|
where: { isActive: true },
|
||||||
order: { createdAt: "DESC" },
|
order: { createdAt: "DESC" },
|
||||||
});
|
});
|
||||||
return new HttpSuccess(apiName);
|
return new HttpSuccess(apiName);
|
||||||
|
|
|
||||||
|
|
@ -125,19 +125,19 @@ export class OrganizationController extends Controller {
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
// CheckQueueInProgress
|
// CheckQueueInProgress
|
||||||
// const [isBusyDraft, isBusyPublish] = await Promise.all([
|
const [isBusyDraft, isBusyPublish] = await Promise.all([
|
||||||
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
|
checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
|
||||||
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
|
checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
|
||||||
// ]);
|
]);
|
||||||
// console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft);
|
// console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft);
|
||||||
// console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish);
|
// console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish);
|
||||||
// if (isBusyDraft || isBusyPublish) {
|
if (isBusyDraft || isBusyPublish) {
|
||||||
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
|
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
|
||||||
// throw new HttpError(
|
throw new HttpError(
|
||||||
// HttpStatusCode.CONFLICT,
|
HttpStatusCode.CONFLICT,
|
||||||
// "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
|
"ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
//new main revision
|
//new main revision
|
||||||
const before = null;
|
const before = null;
|
||||||
const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision;
|
const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision;
|
||||||
|
|
@ -3209,19 +3209,19 @@ export class OrganizationController extends Controller {
|
||||||
try {
|
try {
|
||||||
// CheckQueueInProgress
|
// CheckQueueInProgress
|
||||||
// console.log("🚀 ตรวจสอบว่ามีงานอยู่ในคิว");
|
// console.log("🚀 ตรวจสอบว่ามีงานอยู่ในคิว");
|
||||||
// const [isBusyDraft, isBusyPublish] = await Promise.all([
|
const [isBusyDraft, isBusyPublish] = await Promise.all([
|
||||||
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
|
checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
|
||||||
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
|
checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
|
||||||
// ]);
|
]);
|
||||||
// console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft);
|
// console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft);
|
||||||
// console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish);
|
// console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish);
|
||||||
// if (isBusyDraft || isBusyPublish) {
|
if (isBusyDraft || isBusyPublish) {
|
||||||
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
|
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
|
||||||
// throw new HttpError(
|
throw new HttpError(
|
||||||
// HttpStatusCode.CONFLICT,
|
HttpStatusCode.CONFLICT,
|
||||||
// "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
|
"ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
today.setHours(0, 0, 0, 0); // Set time to the beginning of the day
|
today.setHours(0, 0, 0, 0); // Set time to the beginning of the day
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import HttpStatus from "../interfaces/http-status";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import { Profile } from "../entities/Profile";
|
import { Profile } from "../entities/Profile";
|
||||||
import { Brackets, In, IsNull, Not } from "typeorm";
|
import { And, Between, Brackets, In, IsNull, Not } from "typeorm";
|
||||||
import { OrgRevision } from "../entities/OrgRevision";
|
import { OrgRevision } from "../entities/OrgRevision";
|
||||||
import { OrgRoot } from "../entities/OrgRoot";
|
import { OrgRoot } from "../entities/OrgRoot";
|
||||||
import { OrgChild1 } from "../entities/OrgChild1";
|
import { OrgChild1 } from "../entities/OrgChild1";
|
||||||
|
|
@ -4029,6 +4029,184 @@ export class OrganizationDotnetController extends Controller {
|
||||||
return new HttpSuccess(profile_);
|
return new HttpSuccess(profile_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 5. เอารายชื่อคนที่มีการ ,map keycloak id แล้ว
|
||||||
|
*
|
||||||
|
* @summary 5. เอารายชื่อคนที่มีการ ,map keycloak id แล้ว
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Post("keycloak-all-officer/date")
|
||||||
|
async PostProfileWithKeycloakAllOfficerDate(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body()
|
||||||
|
body: {
|
||||||
|
node: number;
|
||||||
|
nodeId: string;
|
||||||
|
isAll: boolean;
|
||||||
|
isRetirement?: boolean;
|
||||||
|
revisionId?: string;
|
||||||
|
startDate: Date;
|
||||||
|
endDate: Date;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
let typeCondition: any = {};
|
||||||
|
if (body.isAll == false) {
|
||||||
|
if (body.node === 0) {
|
||||||
|
typeCondition = {
|
||||||
|
orgRootId: body.nodeId,
|
||||||
|
orgChild1Id: IsNull(),
|
||||||
|
};
|
||||||
|
} else if (body.node === 1) {
|
||||||
|
typeCondition = {
|
||||||
|
orgChild1Id: body.nodeId,
|
||||||
|
orgChild2Id: IsNull(),
|
||||||
|
};
|
||||||
|
} else if (body.node === 2) {
|
||||||
|
typeCondition = {
|
||||||
|
orgChild2Id: body.nodeId,
|
||||||
|
orgChild3Id: IsNull(),
|
||||||
|
};
|
||||||
|
} else if (body.node === 3) {
|
||||||
|
typeCondition = {
|
||||||
|
orgChild3Id: body.nodeId,
|
||||||
|
orgChild4Id: IsNull(),
|
||||||
|
};
|
||||||
|
} else if (body.node === 4) {
|
||||||
|
typeCondition = {
|
||||||
|
orgChild4Id: body.nodeId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (body.node === 0) {
|
||||||
|
typeCondition = {
|
||||||
|
orgRootId: body.nodeId,
|
||||||
|
};
|
||||||
|
} else if (body.node === 1) {
|
||||||
|
typeCondition = {
|
||||||
|
orgChild1Id: body.nodeId,
|
||||||
|
};
|
||||||
|
} else if (body.node === 2) {
|
||||||
|
typeCondition = {
|
||||||
|
orgChild2Id: body.nodeId,
|
||||||
|
};
|
||||||
|
} else if (body.node === 3) {
|
||||||
|
typeCondition = {
|
||||||
|
orgChild3Id: body.nodeId,
|
||||||
|
};
|
||||||
|
} else if (body.node === 4) {
|
||||||
|
typeCondition = {
|
||||||
|
orgChild4Id: body.nodeId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let profile = await this.profileRepo.find({
|
||||||
|
where: { keycloak: Not(IsNull()) || Not(""), isLeave: false, current_holders: typeCondition },
|
||||||
|
relations: [
|
||||||
|
"posType",
|
||||||
|
"posLevel",
|
||||||
|
"current_holders",
|
||||||
|
"current_holders.orgRoot",
|
||||||
|
"current_holders.orgChild1",
|
||||||
|
"current_holders.orgChild2",
|
||||||
|
"current_holders.orgChild3",
|
||||||
|
"current_holders.orgChild4",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (body.isRetirement) {
|
||||||
|
profile = await this.profileRepo.find({
|
||||||
|
where: {
|
||||||
|
keycloak: Not(IsNull()) || Not(""),
|
||||||
|
// isLeave: false,
|
||||||
|
current_holders: typeCondition,
|
||||||
|
// isRetirement: true,
|
||||||
|
dateRetire: And(
|
||||||
|
Not(IsNull()),
|
||||||
|
Between(body.startDate, body.endDate)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
relations: [
|
||||||
|
"posType",
|
||||||
|
"posLevel",
|
||||||
|
"current_holders",
|
||||||
|
"current_holders.orgRoot",
|
||||||
|
"current_holders.orgChild1",
|
||||||
|
"current_holders.orgChild2",
|
||||||
|
"current_holders.orgChild3",
|
||||||
|
"current_holders.orgChild4",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let findRevision = await this.orgRevisionRepo.findOne({
|
||||||
|
where: { orgRevisionIsCurrent: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (body.revisionId) {
|
||||||
|
findRevision = await this.orgRevisionRepo.findOne({
|
||||||
|
where: { id: body.revisionId },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const profile_ = await Promise.all(
|
||||||
|
profile.map((item: Profile) => {
|
||||||
|
const shortName =
|
||||||
|
item.current_holders.length == 0
|
||||||
|
? null
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 !=
|
||||||
|
null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild3 != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild2 != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild1 != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
|
||||||
|
null &&
|
||||||
|
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgRoot != null
|
||||||
|
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: null;
|
||||||
|
const Oc =
|
||||||
|
item.current_holders.length == 0
|
||||||
|
? null
|
||||||
|
: body.node == 4 && item.current_holders[0].orgChild4 != null
|
||||||
|
? `${item.current_holders[0].orgChild4.orgChild4Name}/${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}`
|
||||||
|
: body.node == 3 && item.current_holders[0].orgChild3 != null
|
||||||
|
? `${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}`
|
||||||
|
: body.node == 2 && item.current_holders[0].orgChild2 != null
|
||||||
|
? `${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}`
|
||||||
|
: body.node == 1 && item.current_holders[0].orgChild1 != null
|
||||||
|
? `${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}`
|
||||||
|
: body.node == 0 && item.current_holders[0].orgRoot != null
|
||||||
|
? `${item.current_holders[0].orgRoot.orgRootName}`
|
||||||
|
: null;
|
||||||
|
return {
|
||||||
|
id: item.id,
|
||||||
|
prefix: item.prefix,
|
||||||
|
firstName: item.firstName,
|
||||||
|
lastName: item.lastName,
|
||||||
|
citizenId: item.citizenId,
|
||||||
|
keycloak: item.keycloak,
|
||||||
|
posNo: shortName,
|
||||||
|
position: item.position,
|
||||||
|
positionLevel: item.posLevel?.posLevelName ?? null,
|
||||||
|
positionType: item.posType?.posTypeName ?? null,
|
||||||
|
oc: Oc,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return new HttpSuccess(profile_);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 5. เอารายชื่อคน ขรก. (none-validate-keycloak)
|
* 5. เอารายชื่อคน ขรก. (none-validate-keycloak)
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1236,7 +1236,10 @@ export class PositionController extends Controller {
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request, "SYS_ORG");
|
await new permission().PermissionUpdate(request, "SYS_ORG");
|
||||||
const posMaster = await this.posMasterRepository.findOne({ where: { id: id } });
|
const posMaster = await this.posMasterRepository.findOne({
|
||||||
|
relations: ["positions", "orgRevision"],
|
||||||
|
where: { id: id },
|
||||||
|
});
|
||||||
if (!posMaster) {
|
if (!posMaster) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง");
|
||||||
}
|
}
|
||||||
|
|
@ -1391,34 +1394,57 @@ export class PositionController extends Controller {
|
||||||
posMaster.lastUpdatedAt = new Date();
|
posMaster.lastUpdatedAt = new Date();
|
||||||
await this.posMasterRepository.save(posMaster, { data: request });
|
await this.posMasterRepository.save(posMaster, { data: request });
|
||||||
setLogDataDiff(request, { before, after: posMaster });
|
setLogDataDiff(request, { before, after: posMaster });
|
||||||
await this.positionRepository.delete({ posMasterId: posMaster.id });
|
|
||||||
|
|
||||||
await Promise.all(
|
const result = await Promise.all(
|
||||||
requestBody.positions.map(async (x: any) => {
|
requestBody.positions.map(async (x: any) => {
|
||||||
const position = Object.assign(new Position());
|
const match = posMaster.positions.find((p: any) => p.id == x.id);
|
||||||
position.positionName = x.posDictName;
|
if (match) {
|
||||||
position.positionField = x.posDictField;
|
match.positionIsSelected = x.positionIsSelected ?? false;
|
||||||
position.posTypeId = x.posTypeId == "" ? null : x.posTypeId;
|
match.orderNo = x.orderNo ?? null;
|
||||||
position.posLevelId = x.posLevelId == "" ? null : x.posLevelId;
|
return match;
|
||||||
position.posExecutiveId = x.posExecutiveId == "" ? null : x.posExecutiveId;
|
} else {
|
||||||
position.positionExecutiveField = x.posDictExecutiveField;
|
x.id = x.id ?? undefined;
|
||||||
position.positionArea = x.posDictArea;
|
x.posMasterId = posMaster.id;
|
||||||
position.isSpecial = x.isSpecial;
|
x.orderNo = x.orderNo ?? null;
|
||||||
position.isOfficer = x.isOfficer;
|
x.positionName = x.posDictName;
|
||||||
position.isStaff = x.isStaff;
|
x.positionField = x.posDictField;
|
||||||
position.isDirector = x.isDirector;
|
x.posExecutiveId = x.posExecutiveId || null;
|
||||||
position.positionSign = x.positionSign;
|
x.createdUserId = request.user.sub;
|
||||||
position.positionIsSelected = x.positionIsSelected;
|
x.createdFullName = request.user.name;
|
||||||
position.posMasterId = posMaster.id;
|
x.lastUpdateUserId = request.user.sub;
|
||||||
position.createdUserId = request.user.sub;
|
x.lastUpdateFullName = request.user.name;
|
||||||
position.createdFullName = request.user.name;
|
x.createdAt = new Date();
|
||||||
position.lastUpdateUserId = request.user.sub;
|
x.lastUpdatedAt = new Date();
|
||||||
position.lastUpdateFullName = request.user.name;
|
return x;
|
||||||
position.createdAt = new Date();
|
}
|
||||||
position.lastUpdatedAt = new Date();
|
|
||||||
await this.positionRepository.save(position, { data: request });
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
await this.positionRepository.save(result, { data: request });
|
||||||
|
await Promise.all(
|
||||||
|
posMaster.positions.map(async (x: any) => {
|
||||||
|
const match = requestBody.positions.find((p: any) => p.id == x.id);
|
||||||
|
if (!match) {
|
||||||
|
//delete
|
||||||
|
await this.positionRepository.remove(x);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (posMaster.orgRevision?.orgRevisionIsCurrent == true) {
|
||||||
|
const _position = requestBody.positions.find((p) => p.positionIsSelected == true);
|
||||||
|
if (_position) {
|
||||||
|
const current_holderId: any = posMaster.current_holderId;
|
||||||
|
const _profile = await this.profileRepository.findOne({
|
||||||
|
where: { id: current_holderId },
|
||||||
|
});
|
||||||
|
if (_profile) {
|
||||||
|
_profile.position = _position.posDictName ?? _null;
|
||||||
|
_profile.posTypeId = _position.posTypeId;
|
||||||
|
_profile.posLevelId = _position.posLevelId;
|
||||||
|
await this.profileRepository.save(_profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return new HttpSuccess(posMaster.id);
|
return new HttpSuccess(posMaster.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1507,12 +1533,13 @@ export class PositionController extends Controller {
|
||||||
relations: ["posType", "posLevel", "posExecutive"],
|
relations: ["posType", "posLevel", "posExecutive"],
|
||||||
// order: { lastUpdatedAt: "ASC" },
|
// order: { lastUpdatedAt: "ASC" },
|
||||||
order: {
|
order: {
|
||||||
posType: {
|
// posType: {
|
||||||
posTypeRank: "ASC",
|
// posTypeRank: "ASC",
|
||||||
},
|
// },
|
||||||
posLevel: {
|
// posLevel: {
|
||||||
posLevelRank: "ASC",
|
// posLevelRank: "ASC",
|
||||||
},
|
// },
|
||||||
|
orderNo: "ASC",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const formattedData = {
|
const formattedData = {
|
||||||
|
|
@ -1530,6 +1557,7 @@ export class PositionController extends Controller {
|
||||||
positionSign: posMaster.positionSign,
|
positionSign: posMaster.positionSign,
|
||||||
positions: positions.map((position) => ({
|
positions: positions.map((position) => ({
|
||||||
id: position.id,
|
id: position.id,
|
||||||
|
orderNo: position.orderNo,
|
||||||
positionName: position.positionName,
|
positionName: position.positionName,
|
||||||
positionField: position.positionField,
|
positionField: position.positionField,
|
||||||
posTypeId: position.posTypeId,
|
posTypeId: position.posTypeId,
|
||||||
|
|
@ -2348,8 +2376,9 @@ export class PositionController extends Controller {
|
||||||
},
|
},
|
||||||
relations: ["posLevel", "posType", "posExecutive"],
|
relations: ["posLevel", "posType", "posExecutive"],
|
||||||
order: {
|
order: {
|
||||||
posType: { posTypeRank: "ASC" },
|
// posType: { posTypeRank: "ASC" },
|
||||||
posLevel: { posLevelRank: "ASC" },
|
// posLevel: { posLevelRank: "ASC" },
|
||||||
|
orderNo: "ASC",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -2959,8 +2988,9 @@ export class PositionController extends Controller {
|
||||||
//Check All Branch
|
//Check All Branch
|
||||||
const orgRevision = await this.orgRevisionRepository.findOne({
|
const orgRevision = await this.orgRevisionRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
orgRevisionIsDraft: true,
|
// orgRevisionIsDraft: true,
|
||||||
orgRevisionIsCurrent: false,
|
// orgRevisionIsCurrent: false,
|
||||||
|
id: posMaster.orgRevisionId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const _orgRoot = await this.orgRootRepository.find({
|
const _orgRoot = await this.orgRootRepository.find({
|
||||||
|
|
@ -3589,11 +3619,37 @@ export class PositionController extends Controller {
|
||||||
const _null: any = null;
|
const _null: any = null;
|
||||||
const before = null;
|
const before = null;
|
||||||
dataMaster.isSit = requestBody.isSit;
|
dataMaster.isSit = requestBody.isSit;
|
||||||
dataMaster.next_holderId = requestBody.profileId;
|
// dataMaster.next_holderId = requestBody.profileId;
|
||||||
dataMaster.lastUpdatedAt = new Date();
|
dataMaster.lastUpdatedAt = new Date();
|
||||||
//add on
|
//add on
|
||||||
dataMaster.conditionReason = _null;
|
dataMaster.conditionReason = _null;
|
||||||
dataMaster.isCondition = false;
|
dataMaster.isCondition = false;
|
||||||
|
//เช็คถ้า revision ปัจจุบันให้ปั๊มที่ profile
|
||||||
|
const chkRevision = await this.orgRevisionRepository.findOne({
|
||||||
|
where: { id: dataMaster.orgRevisionId },
|
||||||
|
});
|
||||||
|
if (chkRevision?.orgRevisionIsCurrent) {
|
||||||
|
const _profile = await this.profileRepository.findOne({
|
||||||
|
where: { id: requestBody.profileId },
|
||||||
|
});
|
||||||
|
if (_profile) {
|
||||||
|
let _position = await this.positionRepository.findOne({
|
||||||
|
where: { id: requestBody.position, posMasterId: requestBody.posMaster },
|
||||||
|
});
|
||||||
|
if (_position) {
|
||||||
|
_profile.position = _position.positionName;
|
||||||
|
_profile.posTypeId = _position.posTypeId;
|
||||||
|
_profile.posLevelId = _position.posLevelId;
|
||||||
|
await this.profileRepository.save(_profile);
|
||||||
|
setLogDataDiff(request, { before, after: _profile });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dataMaster.current_holderId = requestBody.profileId;
|
||||||
|
dataMaster.next_holderId = _null;
|
||||||
|
} else {
|
||||||
|
dataMaster.next_holderId = requestBody.profileId;
|
||||||
|
dataMaster.current_holderId = _null;
|
||||||
|
}
|
||||||
await this.posMasterRepository.save(dataMaster, { data: request });
|
await this.posMasterRepository.save(dataMaster, { data: request });
|
||||||
setLogDataDiff(request, { before, after: dataMaster });
|
setLogDataDiff(request, { before, after: dataMaster });
|
||||||
|
|
||||||
|
|
@ -3617,6 +3673,10 @@ export class PositionController extends Controller {
|
||||||
if (!dataMaster) {
|
if (!dataMaster) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
||||||
}
|
}
|
||||||
|
let _profileId: string = "";
|
||||||
|
if (dataMaster?.current_holderId) {
|
||||||
|
_profileId = dataMaster?.current_holderId;
|
||||||
|
}
|
||||||
await this.posMasterRepository.update(id, {
|
await this.posMasterRepository.update(id, {
|
||||||
isSit: false,
|
isSit: false,
|
||||||
next_holderId: null,
|
next_holderId: null,
|
||||||
|
|
@ -3629,7 +3689,24 @@ export class PositionController extends Controller {
|
||||||
positionIsSelected: false,
|
positionIsSelected: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
// //เช็คถ้า revision ปัจจุบันให้ปั๊มที่ profile
|
||||||
|
// const chkRevision = await this.orgRevisionRepository.findOne({
|
||||||
|
// where: { id: dataMaster.orgRevisionId },
|
||||||
|
// });
|
||||||
|
// if (chkRevision?.orgRevisionIsCurrent) {
|
||||||
|
// const _profile = await this.profileRepository.findOne({
|
||||||
|
// where: { id: _profileId }
|
||||||
|
// });
|
||||||
|
// if (_profile) {
|
||||||
|
// const _null: any = null;
|
||||||
|
// const before = null;
|
||||||
|
// _profile.position = _null
|
||||||
|
// _profile.posTypeId = _null
|
||||||
|
// _profile.posLevelId = _null
|
||||||
|
// await this.profileRepository.save(_profile);
|
||||||
|
// setLogDataDiff(request, { before, after: _profile });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3641,32 +3718,59 @@ export class PositionController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Post("dna")
|
@Post("dna")
|
||||||
async dna(
|
async dna(
|
||||||
@Body() requestBody: { draftPositionId: string; publishPositionId: string },
|
@Body()
|
||||||
|
requestBody: {
|
||||||
|
draftRevisionId?: string | null; //ใช้เฉพาะเคสสืบทอดจากโครงสร้างปัจจุบัน
|
||||||
|
draftPositionId: string; //ในเคสสืบทอดจากโครงสร้างปัจจุบันจะ "ตำแหน่งที่แบบร่าง" จะเป็น "ตำแหน่งปัจจุบัน" ใช้ draftRevisionId เพื่อเช็คว่าเป็นโครงสร้างปัจจุบันไหม
|
||||||
|
publishRevisionId?: string | null; //ใช้เฉพาะเคสสืบทอดจากโครงสร้างปัจจุบัน
|
||||||
|
publishPositionId: string; //ในเคสสืบทอดจากโครงสร้างปัจจุบันจะ "ตำแหน่งปัจจุบัน" จะเป็น "ตำแหน่งที่ต้องการจะสืบทอด" ตาม publishRevisionId ที่ส่งมา
|
||||||
|
},
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request, "SYS_ORG");
|
await new permission().PermissionUpdate(request, "SYS_ORG");
|
||||||
|
let whereConditionRevision: any = {};
|
||||||
|
|
||||||
|
// ถ้ามี draftRevisionId ค่อยเพิ่มเข้าไป
|
||||||
|
if (requestBody.draftRevisionId) {
|
||||||
|
whereConditionRevision.id = requestBody.draftRevisionId;
|
||||||
|
} else {
|
||||||
|
whereConditionRevision.orgRevisionIsDraft = true;
|
||||||
|
}
|
||||||
|
|
||||||
const findDraft = await this.orgRevisionRepository.findOne({
|
const findDraft = await this.orgRevisionRepository.findOne({
|
||||||
where: {
|
where: whereConditionRevision,
|
||||||
orgRevisionIsDraft: true,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
if (!findDraft) {
|
if (!findDraft) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างที่เผยแพร่");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างที่เผยแพร่");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let whereConditionPub: any = {};
|
||||||
|
// ถ้ามี publishPositionId ค่อยเพิ่มเข้าไป ***อันนี้อาจไม่ต้องทำเพราะใช้ publishPositionId where ได้โดยตรง (!!รอดูหน้าบ้าน!!)***
|
||||||
|
if (requestBody.publishRevisionId) {
|
||||||
|
whereConditionPub.id = requestBody.publishPositionId;
|
||||||
|
whereConditionPub.orgRevisionId = requestBody.publishRevisionId;
|
||||||
|
} else {
|
||||||
|
whereConditionPub.id = requestBody.publishPositionId;
|
||||||
|
}
|
||||||
const dataPublish = await this.posMasterRepository.findOne({
|
const dataPublish = await this.posMasterRepository.findOne({
|
||||||
where: {
|
//เคสโครงสร้างปัจจุบัน: ตัวที่ต้องการจะสืบทอด
|
||||||
id: requestBody.publishPositionId,
|
where: whereConditionPub,
|
||||||
},
|
|
||||||
});
|
});
|
||||||
if (!dataPublish) {
|
if (!dataPublish) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let whereConditionDraft: any = {};
|
||||||
|
// ถ้ามี publishPositionId ค่อยเพิ่มเข้าไป ***อันนี้อาจไม่ต้องทำเพราะใช้ draftPositionId where ได้โดยตรง (!!รอดูหน้าบ้าน!!)***
|
||||||
|
if (requestBody.draftRevisionId) {
|
||||||
|
whereConditionDraft.id = requestBody.draftPositionId;
|
||||||
|
whereConditionDraft.orgRevisionId = requestBody.draftRevisionId;
|
||||||
|
} else {
|
||||||
|
whereConditionDraft.id = requestBody.draftPositionId;
|
||||||
|
}
|
||||||
const dataDraft = await this.posMasterRepository.findOne({
|
const dataDraft = await this.posMasterRepository.findOne({
|
||||||
where: {
|
//เคสโครงสร้างปัจจุบัน: ตัวปัจจุบัน
|
||||||
id: requestBody.draftPositionId,
|
where: whereConditionDraft,
|
||||||
},
|
|
||||||
});
|
});
|
||||||
if (!dataDraft) {
|
if (!dataDraft) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
||||||
|
|
|
||||||
|
|
@ -6284,11 +6284,14 @@ export class ProfileController extends Controller {
|
||||||
"orgChild4.orgChild4ShortName",
|
"orgChild4.orgChild4ShortName",
|
||||||
"orgChild4.orgChild4Order",
|
"orgChild4.orgChild4Order",
|
||||||
])
|
])
|
||||||
.where(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", {
|
// .where(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", {
|
||||||
orgRevisionId:
|
// orgRevisionId:
|
||||||
node && nodeId
|
// node && nodeId
|
||||||
? (await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true } }))?.id
|
// ? (await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true } }))?.id
|
||||||
: undefined,
|
// : undefined,
|
||||||
|
// })
|
||||||
|
.where("current_holders.orgRevisionId = :orgRevisionId", {
|
||||||
|
orgRevisionId: (await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true } }))?.id
|
||||||
})
|
})
|
||||||
.andWhere(
|
.andWhere(
|
||||||
_data.root != undefined && _data.root != null
|
_data.root != undefined && _data.root != null
|
||||||
|
|
@ -6717,6 +6720,150 @@ export class ProfileController extends Controller {
|
||||||
return new HttpSuccess(mapData);
|
return new HttpSuccess(mapData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API ค้นหารายชื่อไปครองตำแหน่งจากโครงสร้างปัจจุบัน
|
||||||
|
*
|
||||||
|
* @summary ค้นหารายชื่อไปครองตำแหน่งจากโครงสร้างปัจจุบัน
|
||||||
|
*/
|
||||||
|
@Post("search/current/person")
|
||||||
|
async searchProfileCurrentPerson(
|
||||||
|
@Body()
|
||||||
|
requestBody: {
|
||||||
|
position?: string | null;
|
||||||
|
posLevelId?: string | null;
|
||||||
|
posTypeId?: string | null;
|
||||||
|
page: number;
|
||||||
|
pageSize: number;
|
||||||
|
keyword?: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const orgRevision = await this.orgRevisionRepo.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionIsCurrent: true,
|
||||||
|
orgRevisionIsDraft: false,
|
||||||
|
},
|
||||||
|
relations: ["posMasters"],
|
||||||
|
});
|
||||||
|
if (!orgRevision) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
|
||||||
|
}
|
||||||
|
const [profiles, total] = await this.profileRepo
|
||||||
|
.createQueryBuilder("profile")
|
||||||
|
.leftJoinAndSelect("profile.current_holders", "current_holders")
|
||||||
|
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||||
|
.leftJoinAndSelect("profile.posType", "posType")
|
||||||
|
.where(
|
||||||
|
requestBody.position != null && requestBody.position != ""
|
||||||
|
? "profile.position LIKE :position"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
position: `%${requestBody.position}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.andWhere("profile.isLeave IS FALSE")
|
||||||
|
.andWhere(
|
||||||
|
new Brackets((qb) => {
|
||||||
|
qb.where(
|
||||||
|
requestBody.keyword != null && requestBody.keyword != ""
|
||||||
|
? "profile.prefix LIKE :keyword"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${requestBody.keyword}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.orWhere(
|
||||||
|
requestBody.keyword != null && requestBody.keyword != ""
|
||||||
|
? "profile.firstName LIKE :keyword"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${requestBody.keyword}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.orWhere(
|
||||||
|
requestBody.keyword != null && requestBody.keyword != ""
|
||||||
|
? "profile.lastName LIKE :keyword"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${requestBody.keyword}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.orWhere(
|
||||||
|
requestBody.keyword != null && requestBody.keyword != ""
|
||||||
|
? "CONCAT(profile.prefix,profile.firstName,' ',profile.lastName) LIKE :keyword"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${requestBody.keyword}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.orWhere(
|
||||||
|
requestBody.keyword != null && requestBody.keyword != ""
|
||||||
|
? "CONCAT(profile.firstName,' ',profile.lastName) LIKE :keyword"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${requestBody.keyword}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.orWhere(
|
||||||
|
requestBody.keyword != null && requestBody.keyword != ""
|
||||||
|
? "profile.citizenId LIKE :keyword"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${requestBody.keyword}%`,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.andWhere(
|
||||||
|
requestBody.posTypeId != null && requestBody.posTypeId != ""
|
||||||
|
? "profile.posTypeId LIKE :posTypeId"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
posTypeId: `%${requestBody.posTypeId}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.andWhere(
|
||||||
|
requestBody.posLevelId != null && requestBody.posLevelId != ""
|
||||||
|
? "profile.posLevelId LIKE :posLevelId"
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
posLevelId: `%${requestBody.posLevelId}%`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.andWhere(
|
||||||
|
new Brackets((qb) => {
|
||||||
|
qb.where("profile.id NOT IN (:...ids)", {
|
||||||
|
ids:
|
||||||
|
orgRevision.posMasters
|
||||||
|
.filter((x) => x.current_holderId != null)
|
||||||
|
.map((x) => x.current_holderId).length == 0
|
||||||
|
? ["zxc"]
|
||||||
|
: orgRevision.posMasters
|
||||||
|
.filter((x) => x.current_holderId != null)
|
||||||
|
.map((x) => x.current_holderId),
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.skip((requestBody.page - 1) * requestBody.pageSize)
|
||||||
|
.take(requestBody.pageSize)
|
||||||
|
.orderBy("posType.posTypeRank", "ASC")
|
||||||
|
.addOrderBy("posLevel.posLevelRank", "ASC")
|
||||||
|
.getManyAndCount();
|
||||||
|
|
||||||
|
const data = profiles.map((_data) => ({
|
||||||
|
id: _data.id,
|
||||||
|
prefix: _data.prefix,
|
||||||
|
rank: _data.rank,
|
||||||
|
firstName: _data.firstName,
|
||||||
|
lastName: _data.lastName,
|
||||||
|
citizenId: _data.citizenId,
|
||||||
|
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
|
||||||
|
posType: _data.posType == null ? null : _data.posType.posTypeName,
|
||||||
|
position: _data.position,
|
||||||
|
}));
|
||||||
|
|
||||||
|
return new HttpSuccess({ data: data, total });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API ข้อมูลสิทธิ์การแก้ไขทะเบียนประวัติ
|
* API ข้อมูลสิทธิ์การแก้ไขทะเบียนประวัติ
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,9 @@ export class PosDict extends EntityBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreatePosDict {
|
export class CreatePosDict {
|
||||||
|
@Column()
|
||||||
|
id?: string | null;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
posDictName: string | null;
|
posDictName: string | null;
|
||||||
|
|
||||||
|
|
@ -101,9 +104,12 @@ export class CreatePosDict {
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
isSpecial: boolean;
|
isSpecial: boolean;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
positionIsSelected?: boolean | null;
|
positionIsSelected?: boolean | null;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
orderNo?: number | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreatePosDictExe {
|
export class CreatePosDictExe {
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,13 @@ export class Position extends EntityBase {
|
||||||
})
|
})
|
||||||
isSpecial: boolean;
|
isSpecial: boolean;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
comment: "ลำดับตำแหน่งภายใน 1 posMasterId",
|
||||||
|
nullable: true,
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
orderNo: number;
|
||||||
|
|
||||||
@ManyToOne(() => PosMaster, (posMaster) => posMaster)
|
@ManyToOne(() => PosMaster, (posMaster) => posMaster)
|
||||||
@JoinColumn({ name: "posMasterId" })
|
@JoinColumn({ name: "posMasterId" })
|
||||||
posMaster: PosMaster;
|
posMaster: PosMaster;
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ import { ProfileActposition } from "./ProfileActposition";
|
||||||
import { ProfileAssistance } from "./ProfileAssistance";
|
import { ProfileAssistance } from "./ProfileAssistance";
|
||||||
import { ProfileSalaryTemp } from "./ProfileSalaryTemp";
|
import { ProfileSalaryTemp } from "./ProfileSalaryTemp";
|
||||||
import { PositionSalaryEditHistory } from "./PositionSalaryEditHistory";
|
import { PositionSalaryEditHistory } from "./PositionSalaryEditHistory";
|
||||||
|
import { ProfileChangeName } from "./ProfileChangeName";
|
||||||
|
|
||||||
@Entity("profile")
|
@Entity("profile")
|
||||||
export class Profile extends EntityBase {
|
export class Profile extends EntityBase {
|
||||||
|
|
@ -522,6 +523,9 @@ export class Profile extends EntityBase {
|
||||||
@OneToMany(() => PositionSalaryEditHistory, (v) => v.profile)
|
@OneToMany(() => PositionSalaryEditHistory, (v) => v.profile)
|
||||||
positionSalaryEditHistory: PositionSalaryEditHistory[];
|
positionSalaryEditHistory: PositionSalaryEditHistory[];
|
||||||
|
|
||||||
|
@OneToMany(() => ProfileChangeName, (v) => v.profile)
|
||||||
|
profileChangeNames: ProfileChangeName[];
|
||||||
|
|
||||||
@ManyToOne(() => PosLevel, (posLevel) => posLevel.profiles)
|
@ManyToOne(() => PosLevel, (posLevel) => posLevel.profiles)
|
||||||
@JoinColumn({ name: "posLevelId" })
|
@JoinColumn({ name: "posLevelId" })
|
||||||
posLevel: PosLevel;
|
posLevel: PosLevel;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { Entity, Column, OneToMany, ManyToOne, JoinColumn } from "typeorm";
|
||||||
import { EntityBase } from "./base/Base";
|
import { EntityBase } from "./base/Base";
|
||||||
import { ProfileChangeNameHistory } from "./ProfileChangeNameHistory";
|
import { ProfileChangeNameHistory } from "./ProfileChangeNameHistory";
|
||||||
import { ProfileEmployee } from "./ProfileEmployee";
|
import { ProfileEmployee } from "./ProfileEmployee";
|
||||||
|
import { Profile } from "./Profile";
|
||||||
// import { ProfileChangeNameHistory } from "./ProfileChangeNameHistory";
|
// import { ProfileChangeNameHistory } from "./ProfileChangeNameHistory";
|
||||||
|
|
||||||
@Entity("profileChangeName")
|
@Entity("profileChangeName")
|
||||||
|
|
@ -85,6 +86,10 @@ export class ProfileChangeName extends EntityBase {
|
||||||
@ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileChangeNames)
|
@ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileChangeNames)
|
||||||
@JoinColumn({ name: "profileEmployeeId" })
|
@JoinColumn({ name: "profileEmployeeId" })
|
||||||
profileEmployee: ProfileEmployee;
|
profileEmployee: ProfileEmployee;
|
||||||
|
|
||||||
|
@ManyToOne(() => Profile, (Profile) => Profile.profileChangeNames)
|
||||||
|
@JoinColumn({ name: "profileId" })
|
||||||
|
profile: Profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateProfileChangeName {
|
export class CreateProfileChangeName {
|
||||||
|
|
|
||||||
|
|
@ -534,23 +534,23 @@ export function editLogSequence(req: RequestWithUser, index: number, data: LogSe
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkQueueInProgress(queueName: string) {
|
export async function checkQueueInProgress(queueName: string) {
|
||||||
// const axios = require('axios');
|
const axios = require('axios');
|
||||||
// console.log("Checking queue in progress");
|
// console.log("Checking queue in progress");
|
||||||
// const res = await axios.get(`${process.env.RABBIT_API_URL}/api/queues/%2F/${queueName}`, {
|
const res = await axios.get(`${process.env.RABBIT_API_URL}/api/queues/%2F/${queueName}`, {
|
||||||
// auth: { username: process.env.RABBIT_USER , password: process.env.RABBIT_PASS },
|
auth: { username: process.env.RABBIT_USER , password: process.env.RABBIT_PASS },
|
||||||
// });
|
});
|
||||||
|
|
||||||
// const q = res.data;
|
const q = res.data;
|
||||||
|
|
||||||
// console.log(`Queue "${queueName}" has:`);
|
// console.log(`Queue "${queueName}" has:`);
|
||||||
// console.log(` - ${q.messages_ready} messages ready`);
|
// console.log(` - ${q.messages_ready} messages ready`);
|
||||||
// console.log(` - ${q.messages_unacknowledged} messages in progress (unacked)`);
|
// console.log(` - ${q.messages_unacknowledged} messages in progress (unacked)`);
|
||||||
|
|
||||||
// if (q.messages_unacknowledged > 0) {
|
if (q.messages_unacknowledged > 0) {
|
||||||
// return true;
|
return true;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function chunkArray(array: any, size: number) {
|
export function chunkArray(array: any, size: number) {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
1538
src/migration/1755838437375-add_field_orderNo_in_table_position.ts
Normal file
1538
src/migration/1755838437375-add_field_orderNo_in_table_position.ts
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -246,7 +246,7 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
allRefIds.add(key);
|
allRefIds.add(key);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
refId: x.refId,
|
refId: x.refId,
|
||||||
commandNo: command.commandNo,
|
commandNo: command.commandNo,
|
||||||
|
|
@ -264,7 +264,7 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter(Boolean),
|
.filter(Boolean),
|
||||||
20
|
20,
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const chunk of chunks) {
|
for (const chunk of chunks) {
|
||||||
|
|
@ -272,7 +272,7 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
{ headers: { authorization: token } },
|
{ headers: { authorization: token } },
|
||||||
path + "/excecute",
|
path + "/excecute",
|
||||||
{ refIds: chunk },
|
{ refIds: chunk },
|
||||||
false
|
false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -289,7 +289,6 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
|
|
||||||
console.log("[AMQ] Excecute Command Success");
|
console.log("[AMQ] Excecute Command Success");
|
||||||
return !!result;
|
return !!result;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
if (user) {
|
if (user) {
|
||||||
|
|
@ -555,8 +554,15 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
const profile = await repoProfile.findOne({
|
const profile = await repoProfile.findOne({
|
||||||
where: { id: item.next_holderId == null ? "" : item.next_holderId },
|
where: { id: item.next_holderId == null ? "" : item.next_holderId },
|
||||||
});
|
});
|
||||||
const position = await item.positions.find((x) => x.positionIsSelected == true);
|
if (profile != null && item.positions.length > 0) {
|
||||||
if (profile != null) {
|
let position = await item.positions.find((x) => x.positionIsSelected == true);
|
||||||
|
if (position == null) {
|
||||||
|
position = await item.positions.find((x) => x.posLevelId == profile?.posLevelId);
|
||||||
|
if (position == null) {
|
||||||
|
position = await item.positions.sort((a, b) => a.orderNo - b.orderNo)[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
profile.posLevelId = position?.posLevelId ?? _null;
|
profile.posLevelId = position?.posLevelId ?? _null;
|
||||||
profile.posTypeId = position?.posTypeId ?? _null;
|
profile.posTypeId = position?.posTypeId ?? _null;
|
||||||
profile.position = position?.positionName ?? _null;
|
profile.position = position?.positionName ?? _null;
|
||||||
|
|
@ -622,24 +628,37 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
||||||
// ) {
|
// ) {
|
||||||
|
// _orgemployeePosMaster = orgemployeePosMaster.map((x) => ({
|
||||||
|
// ...x,
|
||||||
|
// ancestorDNA:
|
||||||
|
// x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||||
|
// ? x.id
|
||||||
|
// : x.ancestorDNA,
|
||||||
|
// }));
|
||||||
|
// await repoEmployeePosmaster.save(_orgemployeePosMaster);
|
||||||
|
const validProfileIds = new Set(
|
||||||
|
(await repoProfileEmployee.find({ select: ["id"] })).map((p) => p.id),
|
||||||
|
);
|
||||||
|
|
||||||
_orgemployeePosMaster = orgemployeePosMaster.map((x) => ({
|
_orgemployeePosMaster = orgemployeePosMaster.map((x) => ({
|
||||||
...x,
|
...x,
|
||||||
|
current_holderId:
|
||||||
|
x.current_holderId && validProfileIds.has(x.current_holderId) ? x.current_holderId : null,
|
||||||
ancestorDNA:
|
ancestorDNA:
|
||||||
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
|
!x.ancestorDNA || x.ancestorDNA === "00000000-0000-0000-0000-000000000000"
|
||||||
? x.id
|
? x.id
|
||||||
: x.ancestorDNA,
|
: x.ancestorDNA,
|
||||||
}));
|
}));
|
||||||
// await repoEmployeePosmaster.save(_orgemployeePosMaster);
|
|
||||||
await repoEmployeePosmaster
|
await repoEmployeePosmaster
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.insert()
|
.insert()
|
||||||
.into(EmployeePosMaster)
|
.into(EmployeePosMaster)
|
||||||
.values(_orgemployeePosMaster)
|
.values(_orgemployeePosMaster)
|
||||||
.orUpdate({
|
.orUpdate({
|
||||||
conflict_target: ['id'],
|
conflict_target: ["id"],
|
||||||
overwrite: ['ancestorDNA'],
|
overwrite: ["ancestorDNA"],
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
// }
|
// }
|
||||||
//หา dna posmaster ถ้าไม่มีให้เอาตัวเองเป็น dna
|
//หา dna posmaster ถ้าไม่มีให้เอาตัวเองเป็น dna
|
||||||
|
|
@ -664,17 +683,17 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
}));
|
}));
|
||||||
// await repoEmployeeTempPosmaster.save(_orgemployeeTempPosMaster);
|
// await repoEmployeeTempPosmaster.save(_orgemployeeTempPosMaster);
|
||||||
await repoEmployeeTempPosmaster
|
await repoEmployeeTempPosmaster
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.insert()
|
.insert()
|
||||||
.into(EmployeeTempPosMaster)
|
.into(EmployeeTempPosMaster)
|
||||||
.values(_orgemployeeTempPosMaster)
|
.values(_orgemployeeTempPosMaster)
|
||||||
.orUpdate({
|
.orUpdate({
|
||||||
conflict_target: ['id'],
|
conflict_target: ["id"],
|
||||||
overwrite: ['ancestorDNA'],
|
overwrite: ["ancestorDNA"],
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
//create org
|
//create org
|
||||||
orgRoot.forEach(async (x: any) => {
|
orgRoot.forEach(async (x: any) => {
|
||||||
var dataId = x.id;
|
var dataId = x.id;
|
||||||
|
|
@ -1481,7 +1500,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const employeePosMaster = await repoEmployeePosmaster.find({
|
const employeePosMaster = await repoEmployeePosmaster.find({
|
||||||
where: { orgRevisionId: orgRevisionDraft.id },
|
where: { orgRevisionId: orgRevisionDraft.id },
|
||||||
relations: ["positions", "positions.posLevel", "positions.posType"],
|
relations: ["positions", "positions.posLevel", "positions.posType"],
|
||||||
|
|
@ -2266,7 +2285,7 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
|
|
||||||
console.log("[AMQ] Create Draft Success");
|
console.log("[AMQ] Create Draft Success");
|
||||||
if (user) {
|
if (user) {
|
||||||
await sendWebSocket(
|
await sendWebSocket(
|
||||||
"send-create-draft-org",
|
"send-create-draft-org",
|
||||||
{
|
{
|
||||||
success: true,
|
success: true,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue