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")
|
||||
async listApiName() {
|
||||
const apiName = await this.apiNameRepository.find({
|
||||
where: { isActive: true },
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return new HttpSuccess(apiName);
|
||||
|
|
|
|||
|
|
@ -125,19 +125,19 @@ export class OrganizationController extends Controller {
|
|||
) {
|
||||
try {
|
||||
// CheckQueueInProgress
|
||||
// const [isBusyDraft, isBusyPublish] = await Promise.all([
|
||||
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
|
||||
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
|
||||
// ]);
|
||||
const [isBusyDraft, isBusyPublish] = await Promise.all([
|
||||
checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
|
||||
checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
|
||||
]);
|
||||
// console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft);
|
||||
// console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish);
|
||||
// if (isBusyDraft || isBusyPublish) {
|
||||
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
|
||||
// throw new HttpError(
|
||||
// HttpStatusCode.CONFLICT,
|
||||
// "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
|
||||
// );
|
||||
// }
|
||||
if (isBusyDraft || isBusyPublish) {
|
||||
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
|
||||
throw new HttpError(
|
||||
HttpStatusCode.CONFLICT,
|
||||
"ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
|
||||
);
|
||||
}
|
||||
//new main revision
|
||||
const before = null;
|
||||
const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision;
|
||||
|
|
@ -3209,19 +3209,19 @@ export class OrganizationController extends Controller {
|
|||
try {
|
||||
// CheckQueueInProgress
|
||||
// console.log("🚀 ตรวจสอบว่ามีงานอยู่ในคิว");
|
||||
// const [isBusyDraft, isBusyPublish] = await Promise.all([
|
||||
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
|
||||
// checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
|
||||
// ]);
|
||||
// console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft);
|
||||
// console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish);
|
||||
// if (isBusyDraft || isBusyPublish) {
|
||||
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
|
||||
// throw new HttpError(
|
||||
// HttpStatusCode.CONFLICT,
|
||||
// "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
|
||||
// );
|
||||
// }
|
||||
const [isBusyDraft, isBusyPublish] = await Promise.all([
|
||||
checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`),
|
||||
checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`),
|
||||
]);
|
||||
// console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft);
|
||||
// console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish);
|
||||
if (isBusyDraft || isBusyPublish) {
|
||||
// console.log("🚫 พบว่ามีงานอยู่ในคิว — error")
|
||||
throw new HttpError(
|
||||
HttpStatusCode.CONFLICT,
|
||||
"ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน",
|
||||
);
|
||||
}
|
||||
|
||||
const today = new Date();
|
||||
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 { RequestWithUser } from "../middlewares/user";
|
||||
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 { OrgRoot } from "../entities/OrgRoot";
|
||||
import { OrgChild1 } from "../entities/OrgChild1";
|
||||
|
|
@ -4029,6 +4029,184 @@ export class OrganizationDotnetController extends Controller {
|
|||
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)
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1236,7 +1236,10 @@ export class PositionController extends Controller {
|
|||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
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) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง");
|
||||
}
|
||||
|
|
@ -1391,34 +1394,57 @@ export class PositionController extends Controller {
|
|||
posMaster.lastUpdatedAt = new Date();
|
||||
await this.posMasterRepository.save(posMaster, { data: request });
|
||||
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) => {
|
||||
const position = Object.assign(new Position());
|
||||
position.positionName = x.posDictName;
|
||||
position.positionField = x.posDictField;
|
||||
position.posTypeId = x.posTypeId == "" ? null : x.posTypeId;
|
||||
position.posLevelId = x.posLevelId == "" ? null : x.posLevelId;
|
||||
position.posExecutiveId = x.posExecutiveId == "" ? null : x.posExecutiveId;
|
||||
position.positionExecutiveField = x.posDictExecutiveField;
|
||||
position.positionArea = x.posDictArea;
|
||||
position.isSpecial = x.isSpecial;
|
||||
position.isOfficer = x.isOfficer;
|
||||
position.isStaff = x.isStaff;
|
||||
position.isDirector = x.isDirector;
|
||||
position.positionSign = x.positionSign;
|
||||
position.positionIsSelected = x.positionIsSelected;
|
||||
position.posMasterId = posMaster.id;
|
||||
position.createdUserId = request.user.sub;
|
||||
position.createdFullName = request.user.name;
|
||||
position.lastUpdateUserId = request.user.sub;
|
||||
position.lastUpdateFullName = request.user.name;
|
||||
position.createdAt = new Date();
|
||||
position.lastUpdatedAt = new Date();
|
||||
await this.positionRepository.save(position, { data: request });
|
||||
const match = posMaster.positions.find((p: any) => p.id == x.id);
|
||||
if (match) {
|
||||
match.positionIsSelected = x.positionIsSelected ?? false;
|
||||
match.orderNo = x.orderNo ?? null;
|
||||
return match;
|
||||
} else {
|
||||
x.id = x.id ?? undefined;
|
||||
x.posMasterId = posMaster.id;
|
||||
x.orderNo = x.orderNo ?? null;
|
||||
x.positionName = x.posDictName;
|
||||
x.positionField = x.posDictField;
|
||||
x.posExecutiveId = x.posExecutiveId || null;
|
||||
x.createdUserId = request.user.sub;
|
||||
x.createdFullName = request.user.name;
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.createdAt = new Date();
|
||||
x.lastUpdatedAt = new Date();
|
||||
return x;
|
||||
}
|
||||
}),
|
||||
);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -1507,12 +1533,13 @@ export class PositionController extends Controller {
|
|||
relations: ["posType", "posLevel", "posExecutive"],
|
||||
// order: { lastUpdatedAt: "ASC" },
|
||||
order: {
|
||||
posType: {
|
||||
posTypeRank: "ASC",
|
||||
},
|
||||
posLevel: {
|
||||
posLevelRank: "ASC",
|
||||
},
|
||||
// posType: {
|
||||
// posTypeRank: "ASC",
|
||||
// },
|
||||
// posLevel: {
|
||||
// posLevelRank: "ASC",
|
||||
// },
|
||||
orderNo: "ASC",
|
||||
},
|
||||
});
|
||||
const formattedData = {
|
||||
|
|
@ -1530,6 +1557,7 @@ export class PositionController extends Controller {
|
|||
positionSign: posMaster.positionSign,
|
||||
positions: positions.map((position) => ({
|
||||
id: position.id,
|
||||
orderNo: position.orderNo,
|
||||
positionName: position.positionName,
|
||||
positionField: position.positionField,
|
||||
posTypeId: position.posTypeId,
|
||||
|
|
@ -2348,8 +2376,9 @@ export class PositionController extends Controller {
|
|||
},
|
||||
relations: ["posLevel", "posType", "posExecutive"],
|
||||
order: {
|
||||
posType: { posTypeRank: "ASC" },
|
||||
posLevel: { posLevelRank: "ASC" },
|
||||
// posType: { posTypeRank: "ASC" },
|
||||
// posLevel: { posLevelRank: "ASC" },
|
||||
orderNo: "ASC",
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -2959,8 +2988,9 @@ export class PositionController extends Controller {
|
|||
//Check All Branch
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({
|
||||
where: {
|
||||
orgRevisionIsDraft: true,
|
||||
orgRevisionIsCurrent: false,
|
||||
// orgRevisionIsDraft: true,
|
||||
// orgRevisionIsCurrent: false,
|
||||
id: posMaster.orgRevisionId,
|
||||
},
|
||||
});
|
||||
const _orgRoot = await this.orgRootRepository.find({
|
||||
|
|
@ -3589,11 +3619,37 @@ export class PositionController extends Controller {
|
|||
const _null: any = null;
|
||||
const before = null;
|
||||
dataMaster.isSit = requestBody.isSit;
|
||||
dataMaster.next_holderId = requestBody.profileId;
|
||||
// dataMaster.next_holderId = requestBody.profileId;
|
||||
dataMaster.lastUpdatedAt = new Date();
|
||||
//add on
|
||||
dataMaster.conditionReason = _null;
|
||||
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 });
|
||||
setLogDataDiff(request, { before, after: dataMaster });
|
||||
|
||||
|
|
@ -3617,6 +3673,10 @@ export class PositionController extends Controller {
|
|||
if (!dataMaster) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
||||
}
|
||||
let _profileId: string = "";
|
||||
if (dataMaster?.current_holderId) {
|
||||
_profileId = dataMaster?.current_holderId;
|
||||
}
|
||||
await this.posMasterRepository.update(id, {
|
||||
isSit: false,
|
||||
next_holderId: null,
|
||||
|
|
@ -3629,7 +3689,24 @@ export class PositionController extends Controller {
|
|||
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();
|
||||
}
|
||||
|
||||
|
|
@ -3641,32 +3718,59 @@ export class PositionController extends Controller {
|
|||
*/
|
||||
@Post("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,
|
||||
) {
|
||||
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({
|
||||
where: {
|
||||
orgRevisionIsDraft: true,
|
||||
},
|
||||
where: whereConditionRevision,
|
||||
});
|
||||
if (!findDraft) {
|
||||
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({
|
||||
where: {
|
||||
id: requestBody.publishPositionId,
|
||||
},
|
||||
//เคสโครงสร้างปัจจุบัน: ตัวที่ต้องการจะสืบทอด
|
||||
where: whereConditionPub,
|
||||
});
|
||||
if (!dataPublish) {
|
||||
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({
|
||||
where: {
|
||||
id: requestBody.draftPositionId,
|
||||
},
|
||||
//เคสโครงสร้างปัจจุบัน: ตัวปัจจุบัน
|
||||
where: whereConditionDraft,
|
||||
});
|
||||
if (!dataDraft) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
||||
|
|
|
|||
|
|
@ -6284,11 +6284,14 @@ export class ProfileController extends Controller {
|
|||
"orgChild4.orgChild4ShortName",
|
||||
"orgChild4.orgChild4Order",
|
||||
])
|
||||
.where(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", {
|
||||
orgRevisionId:
|
||||
node && nodeId
|
||||
? (await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true } }))?.id
|
||||
: undefined,
|
||||
// .where(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", {
|
||||
// orgRevisionId:
|
||||
// node && nodeId
|
||||
// ? (await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true } }))?.id
|
||||
// : undefined,
|
||||
// })
|
||||
.where("current_holders.orgRevisionId = :orgRevisionId", {
|
||||
orgRevisionId: (await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true } }))?.id
|
||||
})
|
||||
.andWhere(
|
||||
_data.root != undefined && _data.root != null
|
||||
|
|
@ -6717,6 +6720,150 @@ export class ProfileController extends Controller {
|
|||
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 ข้อมูลสิทธิ์การแก้ไขทะเบียนประวัติ
|
||||
*
|
||||
|
|
|
|||
|
|
@ -78,6 +78,9 @@ export class PosDict extends EntityBase {
|
|||
}
|
||||
|
||||
export class CreatePosDict {
|
||||
@Column()
|
||||
id?: string | null;
|
||||
|
||||
@Column()
|
||||
posDictName: string | null;
|
||||
|
||||
|
|
@ -101,9 +104,12 @@ export class CreatePosDict {
|
|||
|
||||
@Column()
|
||||
isSpecial: boolean;
|
||||
|
||||
|
||||
@Column()
|
||||
positionIsSelected?: boolean | null;
|
||||
|
||||
@Column()
|
||||
orderNo?: number | undefined;
|
||||
}
|
||||
|
||||
export class CreatePosDictExe {
|
||||
|
|
|
|||
|
|
@ -77,6 +77,13 @@ export class Position extends EntityBase {
|
|||
})
|
||||
isSpecial: boolean;
|
||||
|
||||
@Column({
|
||||
comment: "ลำดับตำแหน่งภายใน 1 posMasterId",
|
||||
nullable: true,
|
||||
default: null,
|
||||
})
|
||||
orderNo: number;
|
||||
|
||||
@ManyToOne(() => PosMaster, (posMaster) => posMaster)
|
||||
@JoinColumn({ name: "posMasterId" })
|
||||
posMaster: PosMaster;
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ import { ProfileActposition } from "./ProfileActposition";
|
|||
import { ProfileAssistance } from "./ProfileAssistance";
|
||||
import { ProfileSalaryTemp } from "./ProfileSalaryTemp";
|
||||
import { PositionSalaryEditHistory } from "./PositionSalaryEditHistory";
|
||||
import { ProfileChangeName } from "./ProfileChangeName";
|
||||
|
||||
@Entity("profile")
|
||||
export class Profile extends EntityBase {
|
||||
|
|
@ -522,6 +523,9 @@ export class Profile extends EntityBase {
|
|||
@OneToMany(() => PositionSalaryEditHistory, (v) => v.profile)
|
||||
positionSalaryEditHistory: PositionSalaryEditHistory[];
|
||||
|
||||
@OneToMany(() => ProfileChangeName, (v) => v.profile)
|
||||
profileChangeNames: ProfileChangeName[];
|
||||
|
||||
@ManyToOne(() => PosLevel, (posLevel) => posLevel.profiles)
|
||||
@JoinColumn({ name: "posLevelId" })
|
||||
posLevel: PosLevel;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { Entity, Column, OneToMany, ManyToOne, JoinColumn } from "typeorm";
|
|||
import { EntityBase } from "./base/Base";
|
||||
import { ProfileChangeNameHistory } from "./ProfileChangeNameHistory";
|
||||
import { ProfileEmployee } from "./ProfileEmployee";
|
||||
import { Profile } from "./Profile";
|
||||
// import { ProfileChangeNameHistory } from "./ProfileChangeNameHistory";
|
||||
|
||||
@Entity("profileChangeName")
|
||||
|
|
@ -85,6 +86,10 @@ export class ProfileChangeName extends EntityBase {
|
|||
@ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileChangeNames)
|
||||
@JoinColumn({ name: "profileEmployeeId" })
|
||||
profileEmployee: ProfileEmployee;
|
||||
|
||||
@ManyToOne(() => Profile, (Profile) => Profile.profileChangeNames)
|
||||
@JoinColumn({ name: "profileId" })
|
||||
profile: Profile;
|
||||
}
|
||||
|
||||
export class CreateProfileChangeName {
|
||||
|
|
|
|||
|
|
@ -534,23 +534,23 @@ export function editLogSequence(req: RequestWithUser, index: number, data: LogSe
|
|||
}
|
||||
|
||||
export async function checkQueueInProgress(queueName: string) {
|
||||
// const axios = require('axios');
|
||||
// console.log("Checking queue in progress");
|
||||
// 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 },
|
||||
// });
|
||||
const axios = require('axios');
|
||||
// console.log("Checking queue in progress");
|
||||
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 },
|
||||
});
|
||||
|
||||
// const q = res.data;
|
||||
const q = res.data;
|
||||
|
||||
// console.log(`Queue "${queueName}" has:`);
|
||||
// console.log(` - ${q.messages_ready} messages ready`);
|
||||
// console.log(` - ${q.messages_unacknowledged} messages in progress (unacked)`);
|
||||
// console.log(`Queue "${queueName}" has:`);
|
||||
// console.log(` - ${q.messages_ready} messages ready`);
|
||||
// console.log(` - ${q.messages_unacknowledged} messages in progress (unacked)`);
|
||||
|
||||
// if (q.messages_unacknowledged > 0) {
|
||||
// return true;
|
||||
// }
|
||||
if (q.messages_unacknowledged > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
allRefIds.add(key);
|
||||
|
||||
|
||||
return {
|
||||
refId: x.refId,
|
||||
commandNo: command.commandNo,
|
||||
|
|
@ -264,7 +264,7 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
};
|
||||
})
|
||||
.filter(Boolean),
|
||||
20
|
||||
20,
|
||||
);
|
||||
|
||||
for (const chunk of chunks) {
|
||||
|
|
@ -272,7 +272,7 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
{ headers: { authorization: token } },
|
||||
path + "/excecute",
|
||||
{ refIds: chunk },
|
||||
false
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -289,7 +289,6 @@ async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
|
||||
console.log("[AMQ] Excecute Command Success");
|
||||
return !!result;
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
if (user) {
|
||||
|
|
@ -555,8 +554,15 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
const profile = await repoProfile.findOne({
|
||||
where: { id: item.next_holderId == null ? "" : item.next_holderId },
|
||||
});
|
||||
const position = await item.positions.find((x) => x.positionIsSelected == true);
|
||||
if (profile != null) {
|
||||
if (profile != null && item.positions.length > 0) {
|
||||
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.posTypeId = position?.posTypeId ?? _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_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) => ({
|
||||
...x,
|
||||
current_holderId:
|
||||
x.current_holderId && validProfileIds.has(x.current_holderId) ? x.current_holderId : null,
|
||||
ancestorDNA:
|
||||
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
|
||||
!x.ancestorDNA || x.ancestorDNA === "00000000-0000-0000-0000-000000000000"
|
||||
? x.id
|
||||
: x.ancestorDNA,
|
||||
}));
|
||||
// await repoEmployeePosmaster.save(_orgemployeePosMaster);
|
||||
await repoEmployeePosmaster
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(EmployeePosMaster)
|
||||
.values(_orgemployeePosMaster)
|
||||
.orUpdate({
|
||||
conflict_target: ['id'],
|
||||
overwrite: ['ancestorDNA'],
|
||||
})
|
||||
.execute();
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(EmployeePosMaster)
|
||||
.values(_orgemployeePosMaster)
|
||||
.orUpdate({
|
||||
conflict_target: ["id"],
|
||||
overwrite: ["ancestorDNA"],
|
||||
})
|
||||
.execute();
|
||||
|
||||
// }
|
||||
//หา dna posmaster ถ้าไม่มีให้เอาตัวเองเป็น dna
|
||||
|
|
@ -664,17 +683,17 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
}));
|
||||
// await repoEmployeeTempPosmaster.save(_orgemployeeTempPosMaster);
|
||||
await repoEmployeeTempPosmaster
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(EmployeeTempPosMaster)
|
||||
.values(_orgemployeeTempPosMaster)
|
||||
.orUpdate({
|
||||
conflict_target: ['id'],
|
||||
overwrite: ['ancestorDNA'],
|
||||
})
|
||||
.execute();
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(EmployeeTempPosMaster)
|
||||
.values(_orgemployeeTempPosMaster)
|
||||
.orUpdate({
|
||||
conflict_target: ["id"],
|
||||
overwrite: ["ancestorDNA"],
|
||||
})
|
||||
.execute();
|
||||
// }
|
||||
|
||||
|
||||
//create org
|
||||
orgRoot.forEach(async (x: any) => {
|
||||
var dataId = x.id;
|
||||
|
|
@ -1481,7 +1500,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
});
|
||||
});
|
||||
// }
|
||||
|
||||
|
||||
const employeePosMaster = await repoEmployeePosmaster.find({
|
||||
where: { orgRevisionId: orgRevisionDraft.id },
|
||||
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");
|
||||
if (user) {
|
||||
await sendWebSocket(
|
||||
await sendWebSocket(
|
||||
"send-create-draft-org",
|
||||
{
|
||||
success: true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue